Make WordPress Core


Ignore:
Timestamp:
07/25/2006 06:36:10 AM (20 years ago)
Author:
ryan
Message:

Category Ajax improvements from mdawaffe. fixes #2803

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r4035 r4041  
    685685// Dandy new recursive multiple category stuff.
    686686function cat_rows($parent = 0, $level = 0, $categories = 0) {
    687     global $wpdb, $class;
    688 
    689687    if (!$categories)
    690688        $categories = get_categories('hide_empty=0');
     
    693691        foreach ($categories as $category) {
    694692            if ($category->category_parent == $parent) {
    695                 $category->cat_name = wp_specialchars($category->cat_name,'double');
    696                 $pad = str_repeat('— ', $level);
    697                 if ( current_user_can('manage_categories') ) {
    698                     $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>";
    699                     $default_cat_id = get_option('default_category');
    700                     $default_link_cat_id = get_option('default_link_category');
    701 
    702                     if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) )
    703                         $edit .= "<td><a href='" . wp_nonce_url("categories.php?action=delete&amp;cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf(__("You are about to delete the category &quot;%s&quot;.\\nAll of its posts will go into the default category of &quot;%s&quot;\\nAll of its bookmarks will go into the default category of &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), js_escape($category->cat_name), js_escape(get_catname($default_cat_id)), js_escape(get_catname($default_link_cat_id))) . "' );\" class='delete'>".__('Delete')."</a>";
    704                     else
    705                         $edit .= "<td style='text-align:center'>".__("Default");
    706                 }
    707                 else
    708                     $edit = '';
    709 
    710                 $class = ('alternate' == $class) ? '' : 'alternate';
    711                
    712                 $category->category_count = number_format( $category->category_count );
    713                 $category->link_count = number_format( $category->link_count );
    714                 echo "<tr id='cat-$category->cat_ID' class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td>
    715                                 <td>$category->category_description</td>
    716                                 <td align='center'>$category->category_count</td>
    717                                 <td align='center'>$category->link_count</td>
    718                                 <td>$edit</td>
    719                                 </tr>";
     693                echo "\t" . _cat_row( $category, $level );
    720694                cat_rows($category->cat_ID, $level +1, $categories);
    721695            }
     
    724698        return false;
    725699    }
     700}
     701
     702function _cat_row( $category, $level, $name_override = false ) {
     703    global $class;
     704
     705    $pad = str_repeat('&#8212; ', $level);
     706    if ( current_user_can('manage_categories') ) {
     707        $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>";
     708        $default_cat_id = get_option('default_category');
     709        $default_link_cat_id = get_option('default_link_category');
     710
     711        if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) )
     712            $edit .= "<td><a href='" . wp_nonce_url("categories.php?action=delete&amp;cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf(__("You are about to delete the category &quot;%s&quot;.\\nAll of its posts will go into the default category of &quot;%s&quot;\\nAll of its bookmarks will go into the default category of &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), js_escape($category->cat_name), js_escape(get_catname($default_cat_id)), js_escape(get_catname($default_link_cat_id))) . "' );\" class='delete'>".__('Delete')."</a>";
     713        else
     714            $edit .= "<td style='text-align:center'>".__("Default");
     715    } else
     716        $edit = '';
     717
     718    $class = ( ( defined('DOING_AJAX') && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
     719
     720    $category->category_count = number_format( $category->category_count );
     721    $category->link_count = number_format( $category->link_count );
     722    return "<tr id='cat-$category->cat_ID'$class>
     723        <th scope='row'>$category->cat_ID</th>
     724        <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->cat_name ) . "</td>
     725        <td>$category->category_description</td>
     726        <td align='center'>$category->category_count</td>
     727        <td align='center'>$category->link_count</td>
     728        <td>$edit</td>\n\t</tr>\n";
    726729}
    727730
Note: See TracChangeset for help on using the changeset viewer.