Changeset 543

Show
Ignore:
Timestamp:
05/15/06 03:19:56 (2 years ago)
Author:
matt
Message:

Lots and lots of changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/README.txt

    r535 r543  
    33 
    44WordPress MU is a multi user version of WordPress. 
     5 
    56If you're not comfortable editing PHP code, taking care of a complex 
    67webserver and database system and being pro-active about following 
     
    89http://wordpress.com/ and sign yourself and your friends up to free blogs. 
    910It's easier in the long run and you'll save yourself a lot of pain 
    10 and angst. 
     11and angst. ;) 
    1112 
    1213Install 
     
    3334=== 
    3435For security reasons, it's very important that PHP be configured as follows: 
     36 
    35371. Don't display error messages to the browser. This is almost always 
    3638turned off but sometimes when you're testing you turn this on and forget 
    3739to reset it. 
     40 
    38412. GLOBAL variables must be turned off. This is one of the first things 
    3942any security aware admin will do. These days the default is for it to 
    4043be off! 
     44 
     453. If you want to restrict blog signups, set the restrict domain email  
     46setting in the admin. 
    4147 
    4248The easiest way of configuring it is via the .htaccess file that is 
     
    6066don't have access to it as it requires root or administrator privileges 
    6167to change. 
     68 
    6269If you do have root access, try "locate php.ini" or check in: 
     70 
    6371/etc/php4/apache2/php.ini 
    6472/usr/local/lib/php.ini 
     73 
    6574Once you have opened your php.ini, look for the sections related to  
    6675register_globals and display_errors. Make sure both are Off like so: 
     76 
    6777display_errors = Off 
    6878register_globals = Off 
     
    7282 
    7383Support Forum: 
     84 
    7485http://mu.wordpress.org/forums/ 
    7586 
  • trunk/htaccess.dist

    r515 r543  
    6262RewriteRule ^([_0-9a-zA-Z-]+)/wp-sidebar.php(.*)                BASE/wp-inst/wp-sidebar.php [L] 
    6363RewriteRule ^([_0-9a-zA-Z-]+)/wp-trackback.php(.*)              BASE/wp-inst/wp-trackback.php [L] 
     64RewriteRule ^([_0-9a-zA-Z-]+)/wp-cron.php(.*)                   BASE/wp-inst/wp-cron.php [L] 
    6465RewriteRule ^([_0-9a-zA-Z-]+)/xmlrpc.php(.*)                    BASE/wp-inst/xmlrpc.php [L]    
    6566RewriteRule ^([_0-9a-zA-Z-]+)/maintenance.php                   BASE/wp-inst/maintenance.php [L]    
     
    6869RewriteRule ^([_0-9a-zA-Z-]+)/wp-includes/js/(.*)               BASE/wp-inst/wp-includes/js/$2 [L] 
    6970 
    70 RewriteRule ^wp-newblog.php$                                    BASE/wp-inst/wp-newblog.php [L] 
     71RewriteRule ^wp-signup.php$                                     BASE/wp-inst/wp-signup.php [L] 
     72RewriteRule ^wp-activate.php$                                   /wp-inst/wp-activate.php [L] 
    7173RewriteRule ^wp-login.php                                       BASE/wp-inst/wp-login.php [L] 
    7274RewriteRule ^wp-admin/(.*)                                      BASE/wp-inst/wp-admin/$1 [L] 
  • trunk/index.php

    r513 r543  
    2323        } 
    2424         
    25         h1
     25        h1, h2
    2626                color: #006; 
    2727                font-size: 18px; 
    2828                font-weight: lighter; 
    29         } 
    30          
    31         h2 { 
    32                 font-size: 16px; 
    3329        } 
    3430         
     
    6258<body> 
    6359 
    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> 
    6661'; 
    6762} 
    6863 
    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>"; 
     64function 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 />"; 
    7467        return false; 
    75     } 
    76     else 
    77     { 
    78         if( $ret == true ) 
    79         { 
     68    } else { 
     69        if( $ret == true ) { 
    8070            return true; 
    81         } 
    82         else 
    83         { 
     71        } else { 
    8472            return false; 
    8573        } 
     
    138126            } 
    139127            fclose( $fp ); 
    140             $htaccess = str_replace( "REALPATH", $realpath, $htaccess ); 
    141128            $htaccess = str_replace( "BASE", $base, $htaccess ); 
    142             $htaccess = str_replace( "HOST", $url, $htaccess ); 
    143129            if( touch( $newfilename ) ) { 
    144130                    $fp = fopen( $newfilename, "w" ); 
     
    212198 
    213199function 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&micro;</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."; 
    216204    if( checkdirs() == false ) { 
    217205        return false; 
    218206    } 
    219207 
    220     // Create default template cache dirs 
    221     @mkdir( dirname(__FILE__) . "/wp-inst/wp-content/smarty-cache" , 0777 ); 
    222     @mkdir( dirname(__FILE__) . "/wp-inst/wp-content/smarty-templates_c" , 0777 ); 
    223  
    224208    // Create Blogs living area. 
    225209    @mkdir( dirname(__FILE__) . "/wp-inst/wp-content/blogs.dir", 0777 ); 
    226210 
    227211 
    228     $url = "http://".$_SERVER["SERVER_NAME"] . dirname( $_SERVER[ "SCRIPT_NAME" ] ); 
     212    $url = stripslashes( "http://".$_SERVER["SERVER_NAME"] . dirname( $_SERVER[ "SCRIPT_NAME" ] ) ); 
    229213    if( substr( $url, -1 ) == '/' ) 
    230214        $url = substr( $url, 0, -1 ); 
    231     $base = dirname( $_SERVER["SCRIPT_NAME"] ); 
     215    $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) ); 
    232216    if( $base != "/") 
    233217    { 
     
    236220    $realpath = dirname(__FILE__); 
    237221 
    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     } 
    255222    return true; 
    256223} 
     
    260227    <form method='post' action='index.php'>  
    261228    <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&nbsp;&nbsp;<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> 
    278235 
    279236  <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'>  
    281238    <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>   
    285241    </tr>  
    286242    <tr>  
    287243      <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>  
    290245    </tr>  
    291246    <tr>  
    292247      <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>  
    295249    </tr>  
    296250    <tr>  
    297251      <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>  
    300253    </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>  
    306254  </table>  
    307   <input name='submit' type='submit' value='Submit' />  
     255  <p class='submit'><input name='submit' type='submit' value='Submit' /> </p> 
    308256</form> "; 
    309257} 
     
    315263    $dbhost  = $_POST['dbhost']; 
    316264    $vhost   = $_POST['vhost' ];  
    317     $prefix  = $_POST['prefix']
    318     if (empty($prefix)) $prefix = 'wp_'
     265    $prefix  = 'wp_'
     266       $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) )
    319267 
    320268    // Test the db connection. 
     
    359307            fwrite($handle, $line); 
    360308        } 
     309        $line = str_replace( "BASE", $base, $line ); 
    361310    } 
    362311    fclose($handle); 
     
    390339function step3() { 
    391340    global $wpdb; 
    392     $base = dirname( $_SERVER["SCRIPT_NAME"] ); 
     341    $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) ); 
    393342    if( $base != "/") 
    394343    { 
     
    430379    $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!' )" ); 
    431380 
    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>"; 
    456387} 
    457388 
    458389switch( $_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; 
    485417} 
    486418?> 
    487419<br /><br /> 
    488420<div align='center'> 
    489 <a href="http://mu.wordpress.org/">WPMU</a> | <a href="http://mu.wordpress.org/forums/">Support Forums</a> 
     421<a href="http://mu.wordpress.org/">WordPress &micro;</a> | <a href="http://mu.wordpress.org/forums/">Support Forums</a> 
    490422</div> 
    491423</body> 
  • trunk/wp-inst/wp-admin/admin-db.php

    r528 r543  
    9595        $cat_name = wp_specialchars($cat_name); 
    9696 
     97        if ( !$update && category_exists($cat_name) ) 
     98                return 0; 
     99 
    97100        if (empty ($category_nicename)) 
    98101                $category_nicename = sanitize_title($cat_name); 
     
    106109                $category_parent = 0; 
    107110 
     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 
    108121        if (!$update) { 
    109122                $maxcat = $wpdb->get_var( "SELECT max(cat_ID) FROM {$wpdb->categories}" ); 
    110123                $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'"); 
    114127        } 
    115128 
     
    130143        $cat_ID = apply_filters( "cat_id_filter", $cat_ID ); 
    131144 
    132         update_option( 'categories_last_updated', time() ); 
    133  
    134145        return $cat_ID; 
    135146} 
     
    158169 
    159170        // Don't delete the default cat. 
    160         if (1 == $cat_ID
     171        if ( $cat_ID == get_option('default_category')
    161172                return 0; 
    162173 
     174        if ( $cat_ID == get_option('default_link_category') ) 
     175                return 0; 
     176 
    163177        $category = get_category($cat_ID); 
    164178 
     
    166180 
    167181        // 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; 
    169184 
    170185        // Update children to point to new parent. 
    171186        $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); 
    172187 
    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         
    176211        wp_cache_delete($cat_ID, 'category'); 
    177212        wp_cache_delete('all_category_ids', 'category'); 
    178         update_option( 'categories_last_updated', time() ); 
    179213 
    180214        do_action('delete_category', $cat_ID); 
     
    245279} 
    246280 
     281function wp_revoke_user($id) { 
     282        $id = (int) $id; 
     283         
     284        $user = new WP_User($id); 
     285        $user->remove_all_caps();        
     286} 
     287 
    247288function get_link($link_id, $output = OBJECT) { 
    248289        global $wpdb; 
    249290 
    250291        $link = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = '$link_id'"); 
     292        $link->link_category = wp_get_link_cats($link_id); 
    251293 
    252294        if ( $output == OBJECT ) { 
     
    285327                $link_notes = ''; 
    286328 
     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 
    287334        if ( $update ) { 
    288335                $wpdb->query("UPDATE $wpdb->links SET link_url='$link_url', 
    289336                        link_name='$link_name', link_image='$link_image', 
    290                         link_target='$link_target', link_category='$link_category', 
     337                        link_target='$link_target', 
    291338                        link_visible='$link_visible', link_description='$link_description', 
    292339                        link_rating='$link_rating', link_rel='$link_rel', 
     
    294341                        WHERE link_id='$link_id'"); 
    295342        } 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')"); 
    297344                $link_id = $wpdb->insert_id; 
    298345        } 
     346 
     347        wp_set_link_cats($link_id, $link_category); 
    299348 
    300349        if ( $update ) 
     
    316365        $link = add_magic_quotes($link); 
    317366 
     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 
    318374        // Merge old and new fields with new fields overwriting old ones. 
    319375        $linkdata = array_merge($link, $linkdata); 
     376        $linkdata['link_category'] = $link_cats; 
    320377 
    321378        return wp_insert_link($linkdata); 
     
    326383 
    327384        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'"); 
    328395        return $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'"); 
    329396} 
     397 
     398function 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 
     414function 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() 
    330466 
    331467function post_exists($title, $content = '', $post_date = '') { 
     
    351487} 
    352488 
     489function 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 
     532function 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 
    353568?> 
  • trunk/wp-inst/wp-admin/admin-functions.php

    r538 r543  
    5656        } else { 
    5757                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 
     97function 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. 
     105function 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