Changeset 543
- Timestamp:
- 05/15/06 03:19:56 (2 years ago)
- Files:
-
- trunk/Changelog-old.txt (deleted)
- trunk/README.txt (modified) (5 diffs)
- trunk/htaccess.dist (modified) (2 diffs)
- trunk/index.php (modified) (10 diffs)
- trunk/release.sh (deleted)
- trunk/wp-inst/wp-activate.php (added)
- trunk/wp-inst/wp-admin/admin-db.php (modified) (11 diffs)
- trunk/wp-inst/wp-admin/admin-functions.php (modified) (32 diffs)
- trunk/wp-inst/wp-admin/categories.php (modified) (12 diffs)
- trunk/wp-inst/wp-admin/edit-link-form.php (modified) (2 diffs)
- trunk/wp-inst/wp-admin/link-add.php (modified) (3 diffs)
- trunk/wp-inst/wp-admin/link-import.php (modified) (4 diffs)
- trunk/wp-inst/wp-admin/link-manager.php (modified) (2 diffs)
- trunk/wp-inst/wp-admin/upgrade-functions.php (modified) (2 diffs)
- trunk/wp-inst/wp-admin/upgrade-schema.php (modified) (5 diffs)
- trunk/wp-inst/wp-admin/wp-admin.css (modified) (10 diffs)
- trunk/wp-inst/wp-admin/wpmu-upgrade.inc.php (deleted)
- trunk/wp-inst/wp-config-sample.php (modified) (1 diff)
- trunk/wp-inst/wp-content/blogs.php (modified) (1 diff)
- trunk/wp-inst/wp-content/mu-plugins/blogs-header.php (deleted)
- trunk/wp-inst/wp-content/mu-plugins/doc_referers.php (deleted)
- trunk/wp-inst/wp-content/mu-plugins/invites.php (deleted)
- trunk/wp-inst/wp-content/mu-plugins/wp-hashcash.php (deleted)
- trunk/wp-inst/wp-content/themes/home/header.php (modified) (1 diff)
- trunk/wp-inst/wp-content/themes/home/home.php (modified) (1 diff)
- trunk/wp-inst/wp-includes/cache.php (modified) (1 diff)
- trunk/wp-inst/wp-includes/capabilities.php (modified) (9 diffs)
- trunk/wp-inst/wp-includes/classes.php (modified) (8 diffs)
- trunk/wp-inst/wp-includes/comment-template.php (added)
- trunk/wp-inst/wp-includes/comment.php (added)
- trunk/wp-inst/wp-includes/default-filters.php (modified) (1 diff)
- trunk/wp-inst/wp-includes/deprecated.php (added)
- trunk/wp-inst/wp-includes/functions-compat.php (modified) (2 diffs)
- trunk/wp-inst/wp-includes/functions-formatting.php (modified) (4 diffs)
- trunk/wp-inst/wp-includes/functions-post.php (modified) (4 diffs)
- trunk/wp-inst/wp-includes/functions.php (modified) (31 diffs)
- trunk/wp-inst/wp-includes/kses.php (modified) (3 diffs)
- trunk/wp-inst/wp-includes/locale.php (modified) (1 diff)
- trunk/wp-inst/wp-includes/pluggable-functions.php (modified) (5 diffs)
- trunk/wp-inst/wp-includes/query.php (modified) (4 diffs)
- trunk/wp-inst/wp-includes/registration-functions.php (modified) (3 diffs)
- trunk/wp-inst/wp-includes/rewrite.php (modified) (2 diffs)
- trunk/wp-inst/wp-includes/rss-functions.php (modified) (12 diffs)
- trunk/wp-inst/wp-includes/template-functions-bookmarks.php (modified) (1 diff)
- trunk/wp-inst/wp-includes/template-functions-category.php (modified) (3 diffs)
- trunk/wp-inst/wp-includes/template-functions-general.php (modified) (16 diffs)
- trunk/wp-inst/wp-includes/template-functions-links.php (modified) (6 diffs)
- trunk/wp-inst/wp-includes/template-functions-post.php (modified) (5 diffs)
- trunk/wp-inst/wp-includes/template-loader.php (modified) (2 diffs)
- trunk/wp-inst/wp-includes/theme.php (added)
- trunk/wp-inst/wp-includes/vars.php (modified) (2 diffs)
- trunk/wp-inst/wp-includes/version.php (modified) (1 diff)
- trunk/wp-inst/wp-includes/wpmu-functions.php (modified) (20 diffs)
- trunk/wp-inst/wp-login.php (modified) (1 diff)
- trunk/wp-inst/wp-newblog.inc.php (deleted)
- trunk/wp-inst/wp-newblog.php (deleted)
- trunk/wp-inst/wp-settings.php (modified) (8 diffs)
- trunk/wp-inst/wp-signup.php (added)
- trunk/wp-inst/wpmu-settings.php (added)
- trunk/wp-inst/wpmu-settings.php.dist (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/README.txt
r535 r543 3 3 4 4 WordPress MU is a multi user version of WordPress. 5 5 6 If you're not comfortable editing PHP code, taking care of a complex 6 7 webserver and database system and being pro-active about following … … 8 9 http://wordpress.com/ and sign yourself and your friends up to free blogs. 9 10 It's easier in the long run and you'll save yourself a lot of pain 10 and angst. 11 and angst. ;) 11 12 12 13 Install … … 33 34 === 34 35 For security reasons, it's very important that PHP be configured as follows: 36 35 37 1. Don't display error messages to the browser. This is almost always 36 38 turned off but sometimes when you're testing you turn this on and forget 37 39 to reset it. 40 38 41 2. GLOBAL variables must be turned off. This is one of the first things 39 42 any security aware admin will do. These days the default is for it to 40 43 be off! 44 45 3. If you want to restrict blog signups, set the restrict domain email 46 setting in the admin. 41 47 42 48 The easiest way of configuring it is via the .htaccess file that is … … 60 66 don't have access to it as it requires root or administrator privileges 61 67 to change. 68 62 69 If you do have root access, try "locate php.ini" or check in: 70 63 71 /etc/php4/apache2/php.ini 64 72 /usr/local/lib/php.ini 73 65 74 Once you have opened your php.ini, look for the sections related to 66 75 register_globals and display_errors. Make sure both are Off like so: 76 67 77 display_errors = Off 68 78 register_globals = Off … … 72 82 73 83 Support Forum: 84 74 85 http://mu.wordpress.org/forums/ 75 86 trunk/htaccess.dist
r515 r543 62 62 RewriteRule ^([_0-9a-zA-Z-]+)/wp-sidebar.php(.*) BASE/wp-inst/wp-sidebar.php [L] 63 63 RewriteRule ^([_0-9a-zA-Z-]+)/wp-trackback.php(.*) BASE/wp-inst/wp-trackback.php [L] 64 RewriteRule ^([_0-9a-zA-Z-]+)/wp-cron.php(.*) BASE/wp-inst/wp-cron.php [L] 64 65 RewriteRule ^([_0-9a-zA-Z-]+)/xmlrpc.php(.*) BASE/wp-inst/xmlrpc.php [L] 65 66 RewriteRule ^([_0-9a-zA-Z-]+)/maintenance.php BASE/wp-inst/maintenance.php [L] … … 68 69 RewriteRule ^([_0-9a-zA-Z-]+)/wp-includes/js/(.*) BASE/wp-inst/wp-includes/js/$2 [L] 69 70 70 RewriteRule ^wp-newblog.php$ BASE/wp-inst/wp-newblog.php [L] 71 RewriteRule ^wp-signup.php$ BASE/wp-inst/wp-signup.php [L] 72 RewriteRule ^wp-activate.php$ /wp-inst/wp-activate.php [L] 71 73 RewriteRule ^wp-login.php BASE/wp-inst/wp-login.php [L] 72 74 RewriteRule ^wp-admin/(.*) BASE/wp-inst/wp-admin/$1 [L] trunk/index.php
r513 r543 23 23 } 24 24 25 h1 {25 h1, h2 { 26 26 color: #006; 27 27 font-size: 18px; 28 28 font-weight: lighter; 29 }30 31 h2 {32 font-size: 16px;33 29 } 34 30 … … 62 58 <body> 63 59 64 <div align="center"><img src="wp-inst/wp-includes/images/wordpress-mu.png"></div><br> 65 Welcome to WordPress MU, the Multi User Weblog System built on WordPress.<br><br> 60 <h1><img src="wp-inst/wp-includes/images/wordpress-mu.png" alt="WordPress MU" /></h1> 66 61 '; 67 62 } 68 63 69 function check_writeable_dir( $dir, $ret ) 70 { 71 if( is_writeable( $dir ) == false ) 72 { 73 print $dir." : <b style='color: #f55'>FAILED</b><br>Quick Fix: <code>chmod 777 $dir</code><br>"; 64 function check_writeable_dir( $dir, $ret ) { 65 if( is_writeable( $dir ) == false ) { 66 print $dir." : <b style='color: #f55'>FAILED</b><br />Quick Fix: <code>chmod 777 $dir</code><br />"; 74 67 return false; 75 } 76 else 77 { 78 if( $ret == true ) 79 { 68 } else { 69 if( $ret == true ) { 80 70 return true; 81 } 82 else 83 { 71 } else { 84 72 return false; 85 73 } … … 138 126 } 139 127 fclose( $fp ); 140 $htaccess = str_replace( "REALPATH", $realpath, $htaccess );141 128 $htaccess = str_replace( "BASE", $base, $htaccess ); 142 $htaccess = str_replace( "HOST", $url, $htaccess );143 129 if( touch( $newfilename ) ) { 144 130 $fp = fopen( $newfilename, "w" ); … … 212 198 213 199 function step1() { 214 print "<h1>Welcome to WPMU</h1>"; 215 print "<p>Please make sure mod_rewrite is installed as it will be activated at the end of this install.</p><p>If mod_rewrite is disabled ask your administrator to enable that module, or look at the <a href='http://httpd.apache.org/docs/mod/mod_rewrite.html'>Apache documentation</a> or <a href='http://www.google.com/search?q=apache+mod_rewrite'>elsewhere</a> for help setting it up.</p>"; 200 print "<h2>Installing WPµ</h2>"; 201 print "<p>Please make sure <code>mod_rewrite</code> is installed as it will be activated at the end of this install.</p> 202 <p>If the <code>mod_rewrite</code> module is disabled ask your administrator to enable that module, or look at the <a href='http://httpd.apache.org/docs/mod/mod_rewrite.html'>Apache documentation</a> or <a href='http://www.google.com/search?q=apache+mod_rewrite'>elsewhere</a> for help setting it up.</p> 203 <p>WPMU <strong>must be installed in the root directory of a domain</strong>, otherwise it won't work."; 216 204 if( checkdirs() == false ) { 217 205 return false; 218 206 } 219 207 220 // Create default template cache dirs221 @mkdir( dirname(__FILE__) . "/wp-inst/wp-content/smarty-cache" , 0777 );222 @mkdir( dirname(__FILE__) . "/wp-inst/wp-content/smarty-templates_c" , 0777 );223 224 208 // Create Blogs living area. 225 209 @mkdir( dirname(__FILE__) . "/wp-inst/wp-content/blogs.dir", 0777 ); 226 210 227 211 228 $url = "http://".$_SERVER["SERVER_NAME"] . dirname( $_SERVER[ "SCRIPT_NAME" ]);212 $url = stripslashes( "http://".$_SERVER["SERVER_NAME"] . dirname( $_SERVER[ "SCRIPT_NAME" ] ) ); 229 213 if( substr( $url, -1 ) == '/' ) 230 214 $url = substr( $url, 0, -1 ); 231 $base = dirname( $_SERVER["SCRIPT_NAME"]);215 $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) ); 232 216 if( $base != "/") 233 217 { … … 236 220 $realpath = dirname(__FILE__); 237 221 238 if( is_file( dirname(__FILE__) . "./wp-inst/wpmu-settings.php" ) == false )239 {240 $configfile = '';241 $fp = fopen( "./wp-inst/wpmu-settings.php.dist", "r" );242 if( $fp )243 {244 while( !feof( $fp ) )245 {246 $configfile .= fgets( $fp, 4096 );247 }248 fclose( $fp );249 }250 $configfile = str_replace( "BASE", $base, $configfile );251 $fp = fopen( "./wp-inst/wpmu-settings.php", "w" );252 fwrite( $fp, $configfile );253 fclose( $fp );254 }255 222 return true; 256 223 } … … 260 227 <form method='post' action='index.php'> 261 228 <input type='hidden' name='action' value='step2'> 262 <h1>Virtual Server Support</h1> 263 <p>Each blog on your site will have their own hostname or 'sub domain'. Your blog addresses will appear like <span class='fakelink'>http://joesblog.example.com/</span> instead of <span class='fakelink'>http://www.example.com/joesblog/</span> but you need to do a few more things to Apache and your DNS settings before it'll work.</p> 264 <p>Apache will have to have a <q>wildcard</q> alias configured in the virtual server definition of your server. You'll have to add a wildcard DNS record for your domain too. That's usually as easy as adding a <q>*</q> hostname in your online dns software.</p> 265 <p>Virtual Server Support: <input type='radio' name='vhost' value='yes'> Yes <input type='radio' name='vhost' value='no' checked>No</p> 266 <p>More: <ul><li> <a href='http://codewalkers.com/archives/general_admin/234.html'>Sub-domain catch-all with Apache</a> via <a href='http://www.google.com/search?q=apache+wildcard+alias'>Google Search: apache wildcard alias</a></li><li> <a href='http://photomatt.net/2003/10/10/wildcard-dns-and-sub-domains/'>Wildcard dns and sub domains</a> via <a href='http://www.google.com/search?q=dns+wildcard+sub+domain'>Google Search: dns wildcard sub domain</a></li><li><a href='http://mu.wordpress.org/forums/topic/126#post-677'>mu forums: how to setup vhosts</a></li></ul></p> 267 <br /> 268 <h1>Database</h1> 269 <p>We need some information on the database. You will need to know the following items before proceeding.</p> 270 <ol> 271 <li>Database name</li> 272 <li>Database username</li> 273 <li>Database password</li> 274 <li>Database host</li> 275 <li>Table prefix (if you want to run more than one WordPress in a single database) </li> 276 </ol> 277 <p><strong>If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open <code>wp-config-sample.php</code> in a text editor, fill in your information, and save it as <code>wp-config.php</code>. </strong></p> 229 <h2>Blog Addresses</h2> 230 <p>Please choose whether you would like blogs for the MU install to use sub-domains or sub-directories. You can not change this later. We recommend sub-domains.</p> 231 <p><label><input type='radio' name='vhost' value='yes' /> Sub-domains (like <code>blog1.example.com</code>)</label><br /> 232 <label><input type='radio' name='vhost' value='no' /> Sub-directories (like <code>example.com/blog1</code></label></p> 233 234 <h2>Database</h2> 278 235 279 236 <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p> 280 <table >237 <table cellpadding='5'> 281 238 <tr> 282 <th scope='row'>Database Name</th> 283 <td><input name='dbname' type='text' size='45' value='".$dbname."' /></td> 284 <td>The name of the database you want to run WP in. </td> 239 <th scope='row' width='33%'>Database Name</th> 240 <td><input name='dbname' type='text' size='45' value='$dbname' /></td> 285 241 </tr> 286 242 <tr> 287 243 <th scope='row'>User Name</th> 288 <td><input name='uname' type='text' size='45' value='".$uname."' /></td> 289 <td>Your MySQL username</td> 244 <td><input name='uname' type='text' size='45' value='$uname' /></td> 290 245 </tr> 291 246 <tr> 292 247 <th scope='row'>Password</th> 293 <td><input name='pwd' type='text' size='45' value='".$pwd."' /></td> 294 <td>...and MySQL password.</td> 248 <td><input name='pwd' type='text' size='45' value='$pwd' /></td> 295 249 </tr> 296 250 <tr> 297 251 <th scope='row'>Database Host</th> 298 <td><input name='dbhost' type='text' size='45' value='".$dbhost."' /></td> 299 <td>99% chance you won't need to change this value.</td> 252 <td><input name='dbhost' type='text' size='45' value='$dbhost' /></td> 300 253 </tr> 301 <tr>302 <th scope='row'>Table Prefix</th>303 <td><input name='prefix' type='text' id='prefix' value='".$prefix."' size='45' /></td>304 <td>If you want to run multiple WordPress installations in a single database, change this.</td>305 </tr>306 254 </table> 307 < input name='submit' type='submit' value='Submit' />255 <p class='submit'><input name='submit' type='submit' value='Submit' /> </p> 308 256 </form> "; 309 257 } … … 315 263 $dbhost = $_POST['dbhost']; 316 264 $vhost = $_POST['vhost' ]; 317 $prefix = $_POST['prefix'];318 if (empty($prefix)) $prefix = 'wp_';265 $prefix = 'wp_'; 266 $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) ); 319 267 320 268 // Test the db connection. … … 359 307 fwrite($handle, $line); 360 308 } 309 $line = str_replace( "BASE", $base, $line ); 361 310 } 362 311 fclose($handle); … … 390 339 function step3() { 391 340 global $wpdb; 392 $base = dirname( $_SERVER["SCRIPT_NAME"]);341 $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) ); 393 342 if( $base != "/") 394 343 { … … 430 379 $wpdb->query( "INSERT INTO ".$wpdb->sitemeta." (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'first_post', 'Welcome to <a href=\"SITE_URL\">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' )" ); 431 380 432 $res = createBlog( $domain, $base, 'admin', $weblog_title, $email ); 433 if( $res == 'ok' ) { 434 $url = "http://".$_SERVER["HTTP_HOST"] . $base; 435 update_option( "template", "home" ); 436 update_option( "stylesheet", "home" ); 437 add_site_option( "allowed_themes", 'a:2:{s:17:"WordPress Classic";b:1;s:17:"WordPress Default";b:1;}' ); 438 $realpath = dirname(__FILE__); 439 do_htaccess( "htaccess.dist", ".htaccess", $realpath, $base, $url ); 440 do_htaccess( "wp-inst/htaccess.dist", "wp-inst/.htaccess", $realpath, $base, $url ); 441 442 $illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator", "blog" ); 443 add_site_option( "illegal_names", $illegal_names ); 444 445 print "<p>Well Done! Your blog has been set up and you have been sent details of your login and password in an email.</p>"; 446 print "<p>You may view your new blog by visiting <a href='".$url."'>".$url."</a>!</p>"; 447 } else { 448 if( $res == 'error: problem creating blog entry' ) { 449 print "The <q>main</q> blog has already been created. Edit your blogs table and delete the entry for this domain!"; 450 } elseif( $res == 'error: username used' ) { 451 print "The username you chose is already in use, please select another one."; 452 } 453 print "<br>result: $res<br>"; 454 printuserdetailsform( $_POST[ 'weblog_title' ], $_POST[ 'username' ], $_POST[ 'email' ] ); 455 } 381 $pass = substr( md5( rand() ), 5, 12 ); 382 $user_id = wpmu_create_user( 'admin', $pass, $email); 383 wpmu_create_blog( $domain, $base, $weblog_title, $user_id, array() ); 384 update_blog_option( 1, 'template', 'home'); 385 update_blog_option( 1, 'stylesheet', 'home'); 386 print "<p>Congrats! Your blog has been set up and you have been sent details of your login and password in an email.</p>"; 456 387 } 457 388 458 389 switch( $_POST[ 'action' ] ) { 459 case "step2": 460 // get blog username 461 // create wp-inst/wp-config.php 462 step2(); 463 printuserdetailsform(); 464 break; 465 case "step3": 466 // call createBlog(); 467 // create .htaccess 468 // print login info and links. 469 require_once('./wp-inst/wp-config.php'); 470 require_once('./wp-inst/wp-admin/upgrade-functions.php'); 471 make_db_current_silent(); 472 populate_options(); 473 printheader(); 474 step3(); 475 break; 476 default: 477 // check that directories are writeable. 478 // create wp-inst/wpmu-settings.php 479 // get db auth info. 480 printheader(); 481 if( step1() ) { 482 printstep1form(); 483 } 484 break; 390 case "step2": 391 // get blog username 392 // create wp-inst/wp-config.php 393 step2(); 394 printuserdetailsform(); 395 break; 396 case "step3": 397 // call createBlog(); 398 // create .htaccess 399 // print login info and links. 400 require_once('./wp-inst/wp-config.php'); 401 require_once('./wp-inst/wp-admin/upgrade-functions.php'); 402 make_db_current_silent(); 403 populate_options(); 404 do_htaccess( 'htaccess.dist', '.htaccess', '/', '/', ''); 405 printheader(); 406 step3(); 407 break; 408 default: 409 // check that directories are writeable. 410 // create wp-inst/wpmu-settings.php 411 // get db auth info. 412 printheader(); 413 if( step1() ) { 414 printstep1form(); 415 } 416 break; 485 417 } 486 418 ?> 487 419 <br /><br /> 488 420 <div align='center'> 489 <a href="http://mu.wordpress.org/">W PMU</a> | <a href="http://mu.wordpress.org/forums/">Support Forums</a>421 <a href="http://mu.wordpress.org/">WordPress µ</a> | <a href="http://mu.wordpress.org/forums/">Support Forums</a> 490 422 </div> 491 423 </body> trunk/wp-inst/wp-admin/admin-db.php
r528 r543 95 95 $cat_name = wp_specialchars($cat_name); 96 96 97 if ( !$update && category_exists($cat_name) ) 98 return 0; 99 97 100 if (empty ($category_nicename)) 98 101 $category_nicename = sanitize_title($cat_name); … … 106 109 $category_parent = 0; 107 110 111 if ( isset($posts_private) ) 112 $posts_private = (int) $posts_private; 113 else 114 $posts_private = 0; 115 116 if ( isset($links_private) ) 117 $links_private = (int) $links_private; 118 else 119 $links_private = 0; 120 108 121 if (!$update) { 109 122 $maxcat = $wpdb->get_var( "SELECT max(cat_ID) FROM {$wpdb->categories}" ); 110 123 $cat_ID = mt_rand( $maxcat+100, $maxcat+4000 ); 111 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent ) VALUES ('$cat_ID', '$cat_name', '$category_nicename', '$category_description', '$category_parent')");112 } else { 113 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' WHERE cat_ID = '$cat_ID'");124 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private) VALUES ('$cat_ID', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private')"); 125 } else { 126 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private' WHERE cat_ID = '$cat_ID'"); 114 127 } 115 128 … … 130 143 $cat_ID = apply_filters( "cat_id_filter", $cat_ID ); 131 144 132 update_option( 'categories_last_updated', time() );133 134 145 return $cat_ID; 135 146 } … … 158 169 159 170 // Don't delete the default cat. 160 if ( 1 == $cat_ID)171 if ( $cat_ID == get_option('default_category') ) 161 172 return 0; 162 173 174 if ( $cat_ID == get_option('default_link_category') ) 175 return 0; 176 163 177 $category = get_category($cat_ID); 164 178 … … 166 180 167 181 // Delete the category. 168 $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); 182 if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") ) 183 return 0; 169 184 170 185 // Update children to point to new parent. 171 186 $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); 172 187 173 // TODO: Only set categories to general if they're not in another category already 174 $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'"); 175 188 // Only set posts and links to the default category if they're not in another category already. 189 $default_cat = get_option('default_category'); 190 $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'"); 191 if ( is_array($posts) ) foreach ($posts as $post_id) { 192 $cats = wp_get_post_cats('', $post_id); 193 if ( 1 == count($cats) ) 194 $cats = array($default_cat); 195 else 196 $cats = array_diff($cats, array($cat_ID)); 197 wp_set_post_cats('', $post_id, $cats); 198 } 199 200 $default_link_cat = get_option('default_link_category'); 201 $links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id='$cat_ID'"); 202 if ( is_array($links) ) foreach ($links as $link_id) { 203 $cats = wp_get_link_cats($link_id); 204 if ( 1 == count($cats) ) 205 $cats = array($default_link_cat); 206 else 207 $cats = array_diff($cats, array($cat_ID)); 208 wp_set_link_cats($link_id, $cats); 209 } 210 176 211 wp_cache_delete($cat_ID, 'category'); 177 212 wp_cache_delete('all_category_ids', 'category'); 178 update_option( 'categories_last_updated', time() );179 213 180 214 do_action('delete_category', $cat_ID); … … 245 279 } 246 280 281 function wp_revoke_user($id) { 282 $id = (int) $id; 283 284 $user = new WP_User($id); 285 $user->remove_all_caps(); 286 } 287 247 288 function get_link($link_id, $output = OBJECT) { 248 289 global $wpdb; 249 290 250 291 $link = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = '$link_id'"); 292 $link->link_category = wp_get_link_cats($link_id); 251 293 252 294 if ( $output == OBJECT ) { … … 285 327 $link_notes = ''; 286 328 329 // Make sure we set a valid category 330 if (0 == count($link_category) || !is_array($link_category)) { 331 $link_category = array(get_option('default_link_category')); 332 } 333 287 334 if ( $update ) { 288 335 $wpdb->query("UPDATE $wpdb->links SET link_url='$link_url', 289 336 link_name='$link_name', link_image='$link_image', 290 link_target='$link_target', link_category='$link_category',337 link_target='$link_target', 291 338 link_visible='$link_visible', link_description='$link_description', 292 339 link_rating='$link_rating', link_rel='$link_rel', … … 294 341 WHERE link_id='$link_id'"); 295 342 } else { 296 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_ category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_category', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')");343 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')"); 297 344 $link_id = $wpdb->insert_id; 298 345 } 346 347 wp_set_link_cats($link_id, $link_category); 299 348 300 349 if ( $update ) … … 316 365 $link = add_magic_quotes($link); 317 366 367 // Passed link category list overwrites existing category list if not empty. 368 if ( isset($linkdata['link_category']) && is_array($linkdata['link_category']) 369 && 0 != count($linkdata['link_category']) ) 370 $link_cats = $linkdata['link_category']; 371 else 372 $link_cats = $link['link_category']; 373 318 374 // Merge old and new fields with new fields overwriting old ones. 319 375 $linkdata = array_merge($link, $linkdata); 376 $linkdata['link_category'] = $link_cats; 320 377 321 378 return wp_insert_link($linkdata); … … 326 383 327 384 do_action('delete_link', $link_id); 385 386 $categories = wp_get_link_cats($link_id); 387 if( is_array( $categories ) ) { 388 foreach ( $categories as $category ) { 389 $wpdb->query("UPDATE $wpdb->categories SET link_count = link_count - 1 WHERE cat_ID = '$category'"); 390 wp_cache_delete($category, 'category'); 391 } 392 } 393 394 $wpdb->query("DELETE FROM $wpdb->link2cat WHERE link_id = '$link_id'"); 328 395 return $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'"); 329 396 } 397 398 function wp_get_link_cats($link_ID = 0) { 399 global $wpdb; 400 401 $sql = "SELECT category_id 402 FROM $wpdb->link2cat 403 WHERE link_id = $link_ID 404 ORDER BY category_id"; 405 406 $result = $wpdb->get_col($sql); 407 408 if ( !$result ) 409 $result = array(); 410 411 return array_unique($result); 412 } 413 414 function wp_set_link_cats($link_ID = 0, $link_categories = array()) { 415 global $wpdb; 416 // If $link_categories isn't already an array, make it one: 417 if (!is_array($link_categories) || 0 == count($link_categories)) 418 $link_categories = array(get_option('default_link_category')); 419 420 $link_categories = array_unique($link_categories); 421 422 // First the old categories 423 $old_categories = $wpdb->get_col(" 424 SELECT category_id 425 FROM $wpdb->link2cat 426 WHERE link_id = $link_ID"); 427 428 if (!$old_categories) { 429 $old_categories = array(); 430 } else { 431 $old_categories = array_unique($old_categories); 432 } 433 434 // Delete any? 435 $delete_cats = array_diff($old_categories,$link_categories); 436 437 if ($delete_cats) { 438 foreach ($delete_cats as $del) { 439 $wpdb->query(" 440 DELETE FROM $wpdb->link2cat 441 WHERE category_id = $del 442 AND link_id = $link_ID 443 "); 444 } 445 } 446 447 // Add any? 448 $add_cats = array_diff($link_categories, $old_categories); 449 450 if ($add_cats) { 451 foreach ($add_cats as $new_cat) { 452 $wpdb->query(" 453 INSERT INTO $wpdb->link2cat (link_id, category_id) 454 VALUES ($link_ID, $new_cat)"); 455 } 456 } 457 458 // Update category counts. 459 $all_affected_cats = array_unique(array_merge($link_categories, $old_categories)); 460 foreach ( $all_affected_cats as $cat_id ) { 461 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'"); 462 $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); 463 wp_cache_delete($cat_id, 'category'); 464 } 465 } // wp_set_link_cats() 330 466 331 467 function post_exists($title, $content = '', $post_date = '') { … … 351 487 } 352 488 489 function wpmu_delete_blog($blog_id, $drop = false) { 490 global $wpdb, $wpmuBaseTablePrefix; 491 492 if ( $blog_id != $wpdb->blogid ) { 493 $switch = true; 494 switch_to_blog($blog_id); 495 } 496 497 do_action('delete_blog', $blog_id, $drop); 498 499 $users = get_users_of_blog($blog_id); 500 501 // Remove users from this blog. 502 if ( !empty($users) ) foreach ($users as $user) { 503 remove_user_from_blog($user->user_id, $blog_id); 504 } 505 506 update_blog_status( $wpdb->blogid, 'deleted', 1 ); 507 508 if ( $drop ) { 509 $drop_tables = array( $wpmuBaseTablePrefix . $blog_id . "_categories", 510 $wpmuBaseTablePrefix . $blog_id . "_comments", 511 $wpmuBaseTablePrefix . $blog_id . "_linkcategories", 512 $wpmuBaseTablePrefix . $blog_id . "_links", 513 $wpmuBaseTablePrefix . $blog_id . "_link2cat", 514 $wpmuBaseTablePrefix . $blog_id . "_options", 515 $wpmuBaseTablePrefix . $blog_id . "_post2cat", 516 $wpmuBaseTablePrefix . $blog_id . "_postmeta", 517 $wpmuBaseTablePrefix . $blog_id . "_posts", 518 $wpmuBaseTablePrefix . $blog_id . "_referer_visitLog", 519 $wpmuBaseTablePrefix . $blog_id . "_referer_blacklist" ); 520 reset( $drop_tables ); 521 522 while( list( $key, $val ) = each( $drop_tables ) ) 523 $wpdb->query( "DROP TABLE IF EXISTS $val" ); 524 525 $wpdb->query( "DELETE FROM $wpdb->blogs WHERE blog_id = '$blog_id'" ); 526 } 527 528 if ( $switch ) 529 restore_current_blog(); 530 } 531 532 function wpmu_delete_user($id) { 533 global $wpdb; 534 535 $id = (int) $id; 536 $user = get_userdata($id); 537 538 do_action('wpmu_delete_user', $id); 539 540 $blogs = get_blogs_of_user($id); 541 542 if ( ! empty($blogs) ) foreach ($blogs as $blog) { 543 switch_to_blog($blog->userblog_id); 544 remove_user_from_blog($id, $blog->userblog_id); 545 546 $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id"); 547 548 if ($post_ids) { 549 foreach ($post_ids as $post_id) 550 wp_delete_post($post_id); 551 } 552 553 // Clean links 554 $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id"); 555 556 restore_current_blog(); 557 } 558 559 $wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id"); 560 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$id'"); 561 562 wp_cache_delete($id, 'users'); 563 wp_cache_delete($user->user_login, 'userlogins'); 564 565 return true; 566 } 567 353 568 ?> trunk/wp-inst/wp-admin/admin-functions.php
r538 r543 56 56 } else { 57 57 if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts')) 58 $_POST['post_status'] = 'draft'; 59 } 60 61 if (!isset ($_POST['comment_status'])) 62 $_POST['comment_status'] = 'closed'; 63 64 if (!isset ($_POST['ping_status'])) 65 $_POST['ping_status'] = 'closed'; 66 67 if (!empty ($_POST['edit_date'])) { 68 $aa = $_POST['aa']; 69 $mm = $_POST['mm']; 70 $jj = $_POST['jj']; 71 $hh = $_POST['hh']; 72 $mn = $_POST['mn']; 73 $ss = $_POST['ss']; 74 $jj = ($jj > 31) ? 31 : $jj; 75 $hh = ($hh > 23) ? $hh -24 : $hh; 76 $mn = ($mn > 59) ? $mn -60 : $mn; 77 $ss = ($ss > 59) ? $ss -60 : $ss; 78 $_POST['post_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss); 79 $_POST['post_date_gmt'] = get_gmt_from_date($_POST['post_date']); 80 } 81 82 // Create the post. 83 $post_ID = wp_insert_post($_POST); 84 add_meta($post_ID); 85 86 // Reunite any orphaned attachments with their parent 87 if ( $_POST['temp_ID'] ) 88 relocate_children($_POST['temp_ID'], $post_ID); 89 90 // Now that we have an ID we can fix any attachment anchor hrefs 91 fix_attachment_links($post_ID); 92 93 return $post_ID; 94 } 95 96 // Move child posts to a new parent 97 function relocate_children($old_ID, $new_ID) { 98 global $wpdb; 99 $old_ID = (int) $old_ID; 100 $new_ID = (int) $new_ID; 101 return $wpdb->query("UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID"); 102 } 103 104 // Replace hrefs of attachment anchors with up-to-date permalinks. 105 function fix_attachment_links($post_ID) { 106 global $wp_rewrite; 107 108 $post = & get_post($post_ID, ARRAY_A); 109 110 $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; 111 112 // See if we have any rel="attachment" links 113 if ( 0 == preg_match_all($search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER) ) 114 return; 115 116 $i = 0; 117 $search = "# id=(\"|')p(\d+)\\1#i"; 118 foreach ( $anchor_matches[0] as $anchor ) { 119 if ( 0 == preg_match($search, $anchor, $id_matches) ) 120 continue; 121 122 $id = $id_matches[2]; 123 124 // While we have the attachment ID, let's adopt any orphans. 125 $attachment = & get_post($id, ARRAY_A); 126 if ( ! empty($attachment) && ! is_object(get_post($attachment['post_parent'])) ) { 127 $attachment['post_parent'] = $post_ID; 128 // Escape data pulled from DB. 129 $attachment = add_magic_quotes($attachment); 130 wp_update_post($attachment); 131 } 132 133 $post_search[$i] = $anchor; 134 $post_replace[$i] = preg_replace("#href=(\"|')[^'\"]*\\1#e", "stripslashes('href=\\1').get_attachment_link($id).stripslashes('\\1')", $anchor); 135 ++$i; 136 } 137 138 $post['post_content'] = str_replace($post_search, $post_replace, $post['post_content']); 139 140 // Escape data pulled from DB. 141 $post = add_magic_quotes($post); 142 143 return wp_update_post($post); 144 } 145 146 // Update
