Changeset 8103

Show
Ignore:
Timestamp:
06/16/08 21:08:49 (5 months ago)
Author:
mdawaffe
Message:

crazyhorse: merge with trunk [8072:8102]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/crazyhorse/wp-admin/categories.php

    r7883 r8103  
    135135 
    136136<div class="tablenav"> 
     137 
     138<?php 
     139$pagenum = absint( $_GET['pagenum'] ); 
     140if ( empty($pagenum) ) 
     141    $pagenum = 1; 
     142if( !$catsperpage || $catsperpage < 0 ) 
     143    $catsperpage = 20; 
     144 
     145$page_links = paginate_links( array( 
     146    'base' => add_query_arg( 'pagenum', '%#%' ), 
     147    'format' => '', 
     148    'total' => ceil(wp_count_terms('category') / $catsperpage), 
     149    'current' => $pagenum 
     150)); 
     151 
     152if ( $page_links ) 
     153    echo "<div class='tablenav-pages'>$page_links</div>"; 
     154?> 
    137155 
    138156<div class="alignleft"> 
     
    157175    <tbody id="the-list" class="list:cat"> 
    158176<?php 
    159 cat_rows(); 
     177cat_rows(0, 0, 0, $pagenum, $catsperpage); 
    160178?> 
    161179    </tbody> 
     
    164182 
    165183<div class="tablenav"> 
     184 
     185<?php 
     186if ( $page_links ) 
     187    echo "<div class='tablenav-pages'>$page_links</div>"; 
     188?> 
    166189<br class="clear" /> 
    167190</div> 
  • branches/crazyhorse/wp-admin/css/press-this.css

    r8071 r8103  
    450450    padding-bottom: 2px; 
    451451} 
     452#photo_saving { 
     453margin-bottom: 8px; 
     454} 
  • branches/crazyhorse/wp-admin/edit-pages.php

    r7998 r8103  
    118118 
    119119<div class="tablenav"> 
     120 
     121<?php 
     122$pagenum = absint( $_GET['pagenum'] ); 
     123if ( empty($pagenum) ) 
     124    $pagenum = 1; 
     125if( !$per_page || $pre_page < 0 ) 
     126    $per_page = 20; 
     127 
     128$num_pages = ceil(count($posts) / $per_page); 
     129$page_links = paginate_links( array( 
     130    'base' => add_query_arg( 'pagenum', '%#%' ), 
     131    'format' => '', 
     132    'total' => $num_pages, 
     133    'current' => $pagenum 
     134)); 
     135 
     136if ( $page_links ) 
     137    echo "<div class='tablenav-pages'>$page_links</div>"; 
     138?> 
    120139 
    121140<div class="alignleft"> 
     
    152171  </thead> 
    153172  <tbody> 
    154   <?php page_rows($posts); ?> 
     173  <?php page_rows($posts, $pagenum, $per_page); ?> 
    155174  </tbody> 
    156175</table> 
     
    170189 
    171190<div class="tablenav"> 
     191<?php 
     192if ( $page_links ) 
     193    echo "<div class='tablenav-pages'>$page_links</div>"; 
     194?> 
    172195<br class="clear" /> 
    173196</div> 
  • branches/crazyhorse/wp-admin/gears-manifest.php

    r8066 r8103  
    8888{ 
    8989"betaManifestVersion" : 1, 
    90 "version" : "<?php echo $man_version; ?>_20080606", 
     90"version" : "<?php echo $man_version; ?>_20080613", 
    9191"entries" : [ 
    9292<?php echo $defaults; ?> 
     
    178178{ "url" : "../wp-includes/js/tinymce/plugins/paste/css/blank.css?ver=3091" }, 
    179179{ "url" : "../wp-includes/js/tinymce/plugins/wpeditimage/css/editimage.css?ver=3091" }, 
     180{ "url" : "../wp-includes/js/tinymce/plugins/wpeditimage/css/editimage-rtl.css?ver=3091" }, 
    180181{ "url" : "../wp-includes/js/tinymce/wordpress.css?ver=3091" }, 
    181182 
  • branches/crazyhorse/wp-admin/import/wp-cat2tag.php

    r7897 r8103  
    2525 
    2626    function populate_cats() { 
    27         global $wpdb; 
    2827 
    2928        $categories = get_categories('get=all'); 
    3029        foreach ( $categories as $category ) { 
    3130            $this->all_categories[] = $category; 
    32             if ( tag_exists( $wpdb->escape($category->name) ) ) 
     31            if ( is_term( $category->slug, 'post_tag' ) ) 
    3332                $this->hybrids_ids[] = $category->term_id; 
    3433        } 
     
    3635 
    3736    function populate_tags() { 
    38         global $wpdb; 
    3937 
    4038        $tags = get_terms( array('post_tag'), 'get=all' ); 
    4139        foreach ( $tags as $tag ) { 
    4240            $this->all_tags[] = $tag; 
    43             if ( $this->_category_exists($tag->term_id) ) 
     41            if ( is_term( $tag->slug, 'category' ) ) 
    4442                $this->hybrids_ids[] = $tag->term_id; 
    4543        } 
     
    5351 
    5452        if ( $cat_num > 0 ) { 
    55             echo '<h2>Convert Categories (' . $cat_num . ') to Tags.</h2>'; 
     53            echo '<h2>' . sprintf( __ngettext( 'Convert Category to Tag.', 'Convert Categories (%d) to Tags.', $cat_num ), $cat_num ) . '</h2>'; 
    5654            echo '<div class="narrow">'; 
    5755            echo '<p>' . __('Hey there. Here you can selectively converts existing categories to tags. To get started, check the categories you wish to be converted, then click the Convert button.') . '</p>'; 
     
    5957 
    6058            $this->categories_form(); 
    61         } elseif ( $hyb_num > 0 ) { 
    62              echo '<p>' . __('You have no categories that can be converted. However some of your categories are both a tag and a category.') . '</p>'; 
    6359        } else { 
    6460            echo '<p>'.__('You have no categories to convert!').'</p>'; 
     
    9389 
    9490<form name="catlist" id="catlist" action="admin.php?import=wp-cat2tag&amp;step=2" method="post"> 
    95 <p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_rows()"
     91<p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_rows()" /
    9692<?php wp_nonce_field('import-cat2tag'); ?></p> 
    9793<ul style="list-style:none"> 
    98 <?php 
    99       $hier = _get_term_hierarchy('category'); 
     94 
     95<?php $hier = _get_term_hierarchy('category'); 
    10096 
    10197        foreach ($this->all_categories as $category) { 
    10298            $category = sanitize_term( $category, 'category', 'display' ); 
    10399 
    104             if ( (int) $category->parent == 0 ) { 
    105                 if ( in_array( intval($category->term_id),  $this->hybrids_ids ) ) { 
    106 ?> 
    107     <li style="color:#777;padding-left:1.3em;"><?php echo $category->name . ' (' . $category->count . ') *'; ?></li> 
    108 <?php 
    109                 } else { 
    110 ?> 
     100            if ( (int) $category->parent == 0 ) { ?> 
     101 
    111102    <li><label><input type="checkbox" name="cats_to_convert[]" value="<?php echo intval($category->term_id); ?>" /> <?php echo $category->name . ' (' . $category->count . ')'; ?></label><?php 
    112103 
    113                     if ( isset($hier[$category->term_id]) ) 
    114                         $this->_category_children($category, $hier); 
    115 ?></li> 
    116 <?php 
    117                 } 
    118             } 
    119         } 
    120 ?> 
     104                 if ( in_array( intval($category->term_id),  $this->hybrids_ids ) ) 
     105                    echo ' <a href="#note"> * </a>'; 
     106                 
     107                if ( isset($hier[$category->term_id]) ) 
     108                    $this->_category_children($category, $hier); ?></li> 
     109<?php       } 
     110        } ?> 
    121111</ul> 
    122112 
    123 <?php 
    124         if ( ! empty($this->hybrids_ids) ) { 
    125             echo '<p>' . __('* This category is also a tag. It cannot be convert again.') . '</p>'; 
    126         } 
    127 ?> 
     113<?php   if ( ! empty($this->hybrids_ids) ) 
     114            echo '<p><a name="note"></a>' . __('* This category is also a tag. Converting it will add that tag to all posts that are currently in the category.') . '</p>'; ?> 
     115 
    128116<p class="submit"><input type="submit" name="submit" class="button" value="<?php _e('Convert Categories to Tags'); ?>" /></p> 
    129117</form> 
    130118 
    131 <?php 
    132     } 
     119<?php } 
    133120 
    134121    function tags_tab() { 
     
    139126 
    140127        if ( $tags_num > 0 ) { 
    141             echo '<h2>Convert Tags (' . $tags_num . ') to Categories.</h2>'; 
     128            echo '<h2>' . sprintf( __ngettext( 'Convert Tag to Category.', 'Convert Tags (%d) to Categories.', $tags_num ), $tags_num ) . '</h2>'; 
    142129            echo '<div class="narrow">'; 
    143130            echo '<p>' . __('Here you can selectively converts existing tags to categories. To get started, check the tags you wish to be converted, then click the Convert button.') . '</p>'; 
    144131            echo '<p>' . __('The newly created categories will still be associated with the same posts.') . '</p></div>'; 
    145              
    146              
     132 
    147133            $this->tags_form(); 
    148         } elseif ( $hyb_num > 0 ) { 
    149              echo '<p>' . __('You have no tags that can be converted. However some of your tags are both a tag and a category.') . '</p>'; 
    150134        } else { 
    151135            echo '<p>'.__('You have no tags to convert!').'</p>'; 
     
    180164 
    181165<form name="taglist" id="taglist" action="admin.php?import=wp-cat2tag&amp;step=4" method="post"> 
    182 <p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_tagrows()"
     166<p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_tagrows()" /
    183167<?php wp_nonce_field('import-cat2tag'); ?></p> 
    184168<ul style="list-style:none"> 
    185 <?php 
    186         foreach ( $this->all_tags as $tag ) { 
    187             if ( in_array( intval($tag->term_id),  $this->hybrids_ids ) ) { 
    188 ?> 
    189     <li style="color:#777;padding-left:1.3em;"><?php echo attribute_escape($tag->name) . ' (' . $tag->count . ') *'; ?></li> 
    190 <?php 
    191             } else { 
    192 ?> 
    193     <li><label><input type="checkbox" name="tags_to_convert[]" value="<?php echo intval($tag->term_id); ?>" /> <?php echo attribute_escape($tag->name) . ' (' . $tag->count . ')'; ?></label></li> 
    194  
    195 <?php 
    196             } 
    197         } 
    198 ?> 
     169 
     170<?php   foreach ( $this->all_tags as $tag ) { ?> 
     171    <li><label><input type="checkbox" name="tags_to_convert[]" value="<?php echo intval($tag->term_id); ?>" /> <?php echo attribute_escape($tag->name) . ' (' . $tag->count . ')'; ?></label><?php if ( in_array( intval($tag->term_id),  $this->hybrids_ids ) ) echo ' <a href="#note"> * </a>'; ?></li> 
     172 
     173<?php   } ?> 
    199174</ul> 
    200175 
    201 <?php    
    202         if ( ! empty($this->hybrids_ids) ) 
    203             echo '<p>' . __('* This tag is also a category. It cannot be converted again.') . '</p>'; 
    204 ?> 
     176<?php   if ( ! empty($this->hybrids_ids) ) 
     177            echo '<p><a name="note"></a>' . __('* This tag is also a category. When converted, all posts associated with the tag will also be in the category.') . '</p>'; ?> 
    205178 
    206179<p class="submit"><input type="submit" name="submit_tags" class="button" value="<?php _e('Convert Tags to Categories'); ?>" /></p> 
    207180</form> 
    208181 
    209 <?php 
    210     } 
    211  
    212     function _category_children($parent, $hier) { 
    213 ?> 
     182<?php } 
     183 
     184    function _category_children($parent, $hier) { ?> 
    214185 
    215186        <ul style="list-style:none"> 
    216 <?php 
    217         foreach ($hier[$parent->term_id] as $child_id) { 
    218             $child =& get_category($child_id); 
    219              
    220             if ( in_array( intval($child->term_id), $this->hybrids_ids ) ) { 
    221 ?> 
    222         <li style="color:#777;padding-left:1.3em;"><?php echo $child->name . ' (' . $child->count . ') *'; ?></li> 
    223 <?php 
    224             } else { 
    225 ?> 
    226         <li><label><input type="checkbox" name="cats_to_convert[]" value="<?php echo intval($child->term_id); ?>" /> <?php echo $child->name . ' (' . $child->count . ')'; ?></label> 
    227 <?php 
     187<?php   foreach ($hier[$parent->term_id] as $child_id) { 
     188            $child =& get_category($child_id); ?> 
     189        <li><label><input type="checkbox" name="cats_to_convert[]" value="<?php echo intval($child->term_id); ?>" /> <?php echo $child->name . ' (' . $child->count . ')'; ?></label><?php 
     190 
     191            if ( in_array( intval($child->term_id), $this->hybrids_ids ) ) 
     192                echo ' <a href="#note"> * </a>'; 
    228193 
    229194            if ( isset($hier[$child->term_id]) ) 
    230                 $this->_category_children($child, $hier); 
    231 ?>      </li> 
    232 <?php 
    233             } 
    234         } 
    235 ?> 
    236         </ul> 
    237 <?php 
     195                $this->_category_children($child, $hier); ?></li> 
     196<?php   } ?> 
     197        </ul><?php 
    238198    } 
    239199 
     
    253213        global $wpdb; 
    254214 
    255         if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) { 
    256             echo '<div class="narrow">'; 
    257             echo '<p>' . sprintf(__('Uh, oh. Something didn&#8217;t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag') . '</p>'; 
    258             echo '</div>'; 
    259           return; 
     215        if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) { ?> 
     216            <div class="narrow"> 
     217            <p><?php printf(__('Uh, oh. Something didn&#8217;t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag'); ?></p> 
     218            </div> 
     219<?php     return; 
    260220        } 
    261221 
    262222        if ( empty($this->categories_to_convert) ) 
    263223            $this->categories_to_convert = $_POST['cats_to_convert']; 
     224 
    264225        $hier = _get_term_hierarchy('category'); 
     226        $hybrid_cats = $clear_parents = $parents = false; 
     227        $clean_term_cache = $clean_cat_cache = array(); 
     228        $default_cat = get_option('default_category'); 
    265229 
    266230        echo '<ul>'; 
     
    269233            $cat_id = (int) $cat_id; 
    270234 
    271             echo '<li>' . sprintf(__('Converting category #%s ... '),  $cat_id); 
    272  
    273             if (!$this->_category_exists($cat_id)) { 
    274                 _e('Category doesn\'t exist!'); 
     235            if ( ! $this->_category_exists($cat_id) ) { 
     236                echo '<li>' . sprintf( __('Category %s doesn\'t exist!'),  $cat_id ) . "</li>\n"; 
    275237            } else { 
    276238                $category =& get_category($cat_id); 
    277  
    278                 if ( tag_exists($wpdb->escape($category->name)) ) { 
    279                     _e('Category is already a tag.'); 
    280                     echo '</li>'; 
     239                echo '<li>' . sprintf(__('Converting category <strong>%s</strong> ... '),  $category->name); 
     240 
     241                // If the category is the default, leave category in place and create tag. 
     242                if ( $default_cat == $category->term_id ) { 
     243 
     244                    if ( ! ($id = is_term( $category->slug, 'post_tag' ) ) ) 
     245                        $id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug)); 
     246                     
     247                    $id = $id['term_taxonomy_id']; 
     248                    $posts = get_objects_in_term($category->term_id, 'category'); 
     249                    $term_order = 0; 
     250 
     251                    foreach ( $posts as $post ) { 
     252                        $values[] = $wpdb->prepare( "(%d, %d, %d)", $post, $id, $term_order); 
     253                        clean_post_cache($post); 
     254                    } 
     255                     
     256                    if ( $values ) { 
     257                        $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); 
     258 
     259                        $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $category->count, $category->term_id) ); 
     260                    } 
     261 
     262                    echo __('Converted successfully.') . "</li>\n"; 
    281263                    continue; 
    282264                } 
    283  
    284                 // If the category is the default, leave category in place and create tag. 
    285                 if ( get_option('default_category') == $category->term_id ) { 
    286                     $id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug)); 
    287                     $id = $id['term_taxonomy_id']; 
    288                     $posts = get_objects_in_term($category->term_id, 'category'); 
    289                     foreach ( $posts as $post ) { 
    290                         if ( !$wpdb->get_var( $wpdb->prepare("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $post, $id) ) ) 
    291                             $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (%d, %d)", $post, $id) ); 
     265                 
     266                // if tag already exists, add it to all posts in the category 
     267                if ( $tag_ttid = $wpdb->get_var( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $category->term_id) ) ) { 
     268                    $objects_ids = get_objects_in_term($category->term_id, 'category'); 
     269                    $tag_ttid = (int) $tag_ttid; 
     270                    $term_order = 0; 
     271 
     272                    foreach ( $objects_ids as $object_id ) 
     273                        $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tag_ttid, $term_order); 
     274 
     275                    if ( $values ) { 
     276                        $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); 
     277 
     278                        $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag_ttid) ); 
     279                        $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $count, $category->term_id) ); 
     280                    } 
     281                    echo __('Tag added to all posts in this category.') . " *</li>\n"; 
     282 
     283                    $hybrid_cats = true; 
     284                    $clean_term_cache[] = $category->term_id; 
     285                    $clean_cat_cache[] = $category->term_id; 
     286 
     287                    continue; 
     288                } 
     289 
     290                $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 
     291                if ( $tt_ids ) { 
     292                    $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); 
     293                    foreach ( (array) $posts as $post ) 
    292294                        clean_post_cache($post); 
    293                     } 
    294                 } else { 
    295                     $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 
    296                     if ( $tt_ids ) { 
    297                         $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); 
    298                         foreach ( (array) $posts as $post ) 
    299                             clean_post_cache($post); 
    300                     } 
    301  
    302                     // Change the category to a tag. 
    303                     $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 
    304  
    305                     $terms = $wpdb->get_col( $wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); 
    306                     foreach ( (array) $terms as $term ) 
    307                         clean_category_cache($term); 
    308  
    309                     // Set all parents to 0 (root-level) if their parent was the converted tag 
    310                     $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); 
    311295                } 
    312                 // Clean the cache 
    313                 clean_category_cache($category->term_id); 
    314  
    315                 _e('Converted successfully.'); 
     296 
     297                // Change the category to a tag. 
     298                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 
     299 
     300                // Set all parents to 0 (root-level) if their parent was the converted tag 
     301                $parents = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); 
     302 
     303                if ( $parents ) $clear_parents = true; 
     304                $clean_cat_cache[] = $category->term_id; 
     305                echo __('Converted successfully.') . "</li>\n"; 
    316306            } 
    317  
    318             echo '</li>'; 
    319         } 
    320  
     307        } 
    321308        echo '</ul>'; 
     309 
     310        if ( ! empty($clean_term_cache) ) { 
     311            $clean_term_cache = array_unique(array_values($clean_term_cache)); 
     312            foreach ( $clean_term_cache as $id ) 
     313                wp_cache_delete($id, 'post_tag'); 
     314        } 
     315 
     316        if ( ! empty($clean_cat_cache) ) { 
     317            $clean_cat_cache = array_unique(array_values($clean_cat_cache)); 
     318            foreach ( $clean_cat_cache as $id ) 
     319                wp_cache_delete($id, 'category'); 
     320        } 
     321 
     322        if ( $clear_parents ) delete_option('category_children'); 
     323 
     324        if ( $hybrid_cats ) 
     325            echo '<p>' . sprintf( __('* This category is also a tag. The converter has added that tag to all posts currently in the category. If you want to remove it, please confirm that all tags were added successfully, then delete it from the <a href="%s">Manage Categories</a> page.'), 'categories.php') . '</p>'; 
    322326        echo '<p>' . sprintf( __('We&#8217;re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag' ) . '</p>'; 
    323327    } 
     
    333337        } 
    334338 
    335         if ( empty($this->categories_to_convert) ) 
     339        if ( empty($this->tags_to_convert) ) 
    336340            $this->tags_to_convert = $_POST['tags_to_convert']; 
    337341 
    338         $clean_cache = array(); 
     342        $hybrid_tags = $clear_parents = false; 
     343        $clean_cat_cache = $clean_term_cache = array(); 
     344        $default_cat = get_option('default_category'); 
    339345        echo '<ul>'; 
    340346 
     
    342348            $tag_id = (int) $tag_id; 
    343349 
    344             echo '<li>' . sprintf(__('Converting tag #%s ... '),  $tag_id); 
    345  
    346             if ( ! is_term($tag_id, 'post_tag') ) { 
    347                 _e('Tag doesn\'t exist!'); 
    348             } else { 
    349  
    350                 if ( is_term($tag_id, 'category') ) { 
    351                     _e('This Tag is already a Category.'); 
    352                     echo '</li>'; 
     350            if ( $tag = get_term( $tag_id, 'post_tag' ) ) { 
     351                printf('<li>' . __('Converting tag <strong>%s</strong> ... '),  $tag->name); 
     352 
     353                if ( $cat_ttid = $wpdb->get_var( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $tag->term_id) ) ) { 
     354                    $objects_ids = get_objects_in_term($tag->term_id, 'post_tag'); 
     355                    $cat_ttid = (int) $cat_ttid; 
     356                    $term_order = 0; 
     357 
     358                    foreach ( $objects_ids as $object_id ) { 
     359                        $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $cat_ttid, $term_order); 
     360                        clean_post_cache($object_id); 
     361                    } 
     362 
     363                    if ( $values ) { 
     364                        $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); 
     365 
     366                        if ( $default_cat != $tag->term_id ) { 
     367                            $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag->term_id) ); 
     368                            $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'category'", $count, $tag->term_id) ); 
     369                        } 
     370                    } 
     371 
     372                    $hybrid_tags = true; 
     373                    $clean_term_cache[] = $tag->term_id; 
     374                    $clean_cat_cache[] = $tag->term_id; 
     375                    echo __('All posts were added to the category with the same name.') . " *</li>\n"; 
     376 
    353377                    continue; 
    354378                } 
    355379 
    356                 $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); 
    357                 if ( $tt_ids ) { 
    358                         $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); 
    359                     foreach ( (array) $posts as $post ) 
    360                         clean_post_cache($post); 
    361                 } 
    362  
    363380                // Change the tag to a category. 
    364                 $parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); 
    365                 if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) 
     381                $parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) ); 
     382                if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) { 
    366383                    $reset_parent = ''; 
    367                 else $reset_parent = ", parent = '0'"; 
    368  
    369                 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'category' $reset_parent WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); 
    370  
    371                 // Clean the cache 
    372                 $clean_cache[] = $tag_id; 
    373  
    374                 _e('Converted successfully.'); 
     384                    $clear_parents = true; 
     385                } else 
     386                    $reset_parent = ", parent = '0'"; 
     387 
     388                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'category' $reset_parent WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) ); 
     389 
     390                $clean_term_cache[] = $tag->term_id; 
     391                $clean_cat_cache[] = $cat['term_id']; 
     392                echo __('Converted successfully.') . "</li>\n"; 
     393 
     394            } else { 
     395                printf( '<li>' . __('Tag #%s doesn\'t exist!') . "</li>\n",  $tag_id ); 
    375396            } 
    376  
    377             echo '</li>'; 
    378         } 
    379  
    380         clean_term_cache( $clean_cache, 'post_tag' ); 
    381         delete_option('category_children'); 
    382          
     397        } 
     398 
     399        if ( ! empty($clean_term_cache) ) { 
     400            $clean_term_cache = array_unique(array_values($clean_term_cache)); 
     401            foreach ( $clean_term_cache as $id ) 
     402                wp_cache_delete($id, 'post_tag'); 
     403        } 
     404 
     405        if ( ! empty($clean_cat_cache) ) { 
     406            $clean_cat_cache = array_unique(array_values($clean_cat_cache)); 
     407            foreach ( $clean_cat_cache as $id ) 
     408                wp_cache_delete($id, 'category'); 
     409        } 
     410 
     411        if ( $clear_parents ) delete_option('category_children'); 
     412 
    383413        echo '</ul>'; 
     414        if ( $hybrid_tags ) 
     415            echo '<p>' . sprintf( __('* This tag is also a category. The converter has added all posts from it to the category. If you want to remove it, please confirm that all posts were added successfully, then delete it from the <a href="%s">Manage Tags</a> page.'), 'edit-tags.php') . '</p>'; 
    384416        echo '<p>' . sprintf( __('We&#8217;re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag&amp;step=3' ) . '</p>'; 
    385417    } 
     
    402434                    $this->convert_categories(); 
    403435                break; 
    404                  
     436 
    405437                case 3 : 
    406438                    $this->tags_tab(); 
    407439                break; 
    408                  
     440 
    409441                case 4 : 
    410442                    check_admin_referer('import-cat2tag'); 
  • branches/crazyhorse/wp-admin/includes/dashboard.php

    r8016 r8103  
    316316    @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP ); 
    317317    $rss = @fetch_rss( $url ); 
    318     if ( isset($rss->items) && 1 < count($rss->items) )  {// Technorati returns a 1-item feed when it has no results 
     318    if ( isset($rss->items) && 0 < count($rss->items) )  { 
    319319 
    320320        echo "<ul>\n"; 
  • branches/crazyhorse/wp-admin/includes/file.php

    r8053 r8103  
    4141 
    4242    return $real_file; 
     43} 
     44//$folder = Full path to folder 
     45//$levels = Levels of folders to follow, Default: 100 (PHP Loop limit) 
     46function list_files( $folder = '', $levels = 100 ) { 
     47    if( empty($folder) ) 
     48        return false; 
     49 
     50    if( ! $levels ) 
     51        return false; 
     52 
     53    $files = array(); 
     54    if ( $dir = @opendir( $folder ) ) { 
     55        while (($file = readdir( $dir ) ) !== false ) { 
     56            if ( in_array($file, array('.', '..') ) ) 
     57                continue; 
     58            if ( is_dir( $folder . '/' . $file ) ) { 
     59                $files2 = list_files( $folder . '/' . $file, $levels - 1); 
     60                if( $files2 ) 
     61                    $files = array_merge($files, $files2 ); 
     62                else 
     63                    $files[] = $folder . '/' . $file . '/'; 
     64            } else { 
     65                $files[] = $folder . '/' . $file; 
     66            } 
     67        } 
     68    } 
     69    @closedir( $dir ); 
     70    return $files; 
    4371} 
    4472 
  • branches/crazyhorse/wp-admin/includes/plugin.php

    r8068 r8103  
    137137} 
    138138 
    139 //Replaces reactivate_all_plugins() / deactivate_all_plugins()  = 'deactivated_plugins' is now useless 
    140139function activate_plugins($plugins, $redirect = '') { 
    141140    if ( !is_array($plugins) ) 
     
    168167 
    169168    ob_start(); 
    170     $url = wp_nonce_url('plugins.php?action=delete-selected&' . implode('&', $checked), 'mass-manage-plugins'); 
     169    $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-manage-plugins'); 
    171170    if ( false === ($credentials = request_filesystem_credentials($url)) ) { 
    172171        $data = ob_get_contents(); 
     
    244243    // plugins. 
    245244    foreach ( $check_plugins as $check_plugin ) { 
    246         if ( !file_exists(WP_PLUGIN_DIR . '/' . $check_plugin) ) { 
    247             $current = get_option('active_plugins'); 
    248             $key = array_search($check_plugin, $current); 
    249             if ( false !== $key && NULL !== $key ) { 
    250                 unset($current[$key]); 
    251                 update_option('active_plugins', $current); 
    252             } 
     245        $result = validate_plugin($check_plugin); 
     246        if ( is_wp_error( $result ) ) { 
     247            deactivate_plugins( $check_plugin, true); 
    253248        } 
    254249    } 
  • branches/crazyhorse/wp-admin/includes/template.php

    r7956 r8103  
    55// 
    66 
    7 // Dandy new recursive multiple category stuff. 
    8 function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { 
    9     if ( !$categories ) { 
     7// Ugly recursive category stuff. 
     8function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) { 
     9    $count = 0; 
     10    _cat_rows($categories, $count, $parent, $level, $page, $per_page); 
     11
     12 
     13function _cat_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20 ) { 
     14    if ( empty($categories) ) { 
    1015        $args = array('hide_empty' => 0); 
    1116        if ( !empty($_GET['s']) ) 
     
    1419    } 
    1520 
     21    if ( !$categories ) 
     22        return false; 
     23 
    1624    $children = _get_term_hierarchy('category'); 
    1725 
    18     if ( $categories ) { 
    19         ob_start(); 
    20         foreach ( $categories as $category ) { 
    21             if ( $category->parent == $parent) { 
    22                 echo "\t" . _cat_row( $category, $level ); 
    23                 if ( isset($children[$category->term_id]) ) 
    24                     cat_rows( $category->term_id, $level +1, $categories ); 
     26    $start = ($page - 1) * $per_page; 
     27    $end = $start + $per_page; 
     28    $i = -1; 
     29    ob_start(); 
     30    foreach ( $categories as $category ) { 
     31        if ( $count >= $end ) 
     32            break; 
     33 
     34        $i++; 
     35 
     36        if ( $category->parent != $parent ) 
     37            continue; 
     38 
     39        // If the page starts in a subtree, print the parents. 
     40        if ( $count == $start && $category->parent > 0 ) { 
     41            $my_parents = array(); 
     42            $my_parent = $category->parent; 
     43            while ( $my_parent) { 
     44                $my_parent = get_category($my_parent); 
     45                $my_parents[] = $my_parent; 
     46                if ( !$my_parent->parent ) 
     47                    break; 
     48                $my_parent = $my_parent->parent; 
    2549            } 
    26         } 
    27         $output = ob_get_contents(); 
    28         ob_end_clean(); 
    29  
    30         $output = apply_filters('cat_rows', $output); 
    31  
    32         echo $output; 
    33     } else { 
    34         return false; 
    35     } 
     50            $num_parents = count($my_parents); 
     51            while( $my_parent = array_pop($my_parents) ) { 
     52                echo "\t" . _cat_row( $my_parent, $level - $num_parents ); 
     53                $num_parents--; 
     54            } 
     55        } 
     56 
     57        if ( $count >= $start ) 
     58            echo "\t" . _cat_row( $category, $level ); 
     59 
     60        unset($categories[$i]); // Prune the working set         
     61        $count++; 
     62 
     63        if ( isset($children[$category->term_id]) ) 
     64            _cat_rows( $categories, $count, $category->term_id, $level + 1, $page, $per_page ); 
     65 
     66    } 
     67 
     68    $output = ob_get_contents(); 
     69    ob_end_clean(); 
     70 
     71    $output = apply_filters('cat_rows', $output); 
     72 
     73    echo $output; 
    3674} 
    3775 
     
    361399 * otherwise, display the row and its children in subsequent rows 
    362400 */ 
    363 function display_page_row( $page, &$children_pages, $level = 0 ) { 
     401function display_page_row( $page, $level = 0 ) { 
    364402    global $post; 
    365403    static $class; 
     
    485523 
    486524<?php 
    487  
    488     if ( ! $children_pages ) 
    489         return true; 
    490  
    491     for ( $i = 0; $i < count($children_pages); $i++ ) { 
    492  
    493         $child = $children_pages[$i]; 
    494  
    495         if ( $child->post_parent == $id ) { 
    496             array_splice($children_pages, $i, 1); 
    497             display_page_row($child, $children_pages, $level+1); 
    498             $i = -1; //as numeric keys in $children_pages are not preserved after splice 
    499         } 
    500     } 
    501525} 
    502526 
     
    504528 * displays pages in hierarchical order 
    505529 */ 
    506 function page_rows( $pages ) { 
    507     if ( ! $pages ) 
     530 
     531function page_rows($pages, $pagenum = 1, $per_page = 20) { 
     532    $level = 0; 
     533 
     534    if ( ! $pages ) { 
    508535        $pages = get_pages( array('sort_column' => 'menu_order') ); 
    509536 
    510     if ( ! $pages ) 
    511         return false; 
     537        if ( ! $pages ) 
     538            return false; 
     539    } 
    512540 
    513541    // splice pages into two parts: those without parent and those with parent 
    514  
    515542    $top_level_pages = array(); 
    516543    $children_pages  = array(); 
    517544 
     545    // If searching, ignore hierarchy and treat everything as top level, otherwise split 
     546    // into top level and children 
     547    if ( empty($_GET['s']) )  { 
     548        foreach ( $pages as $page ) { 
     549            // catch and repair bad pages 
     550            if ( $page->post_parent == $page->ID ) { 
     551                $page->post_parent = 0;