Make WordPress Core

Changeset 4041


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

Category Ajax improvements from mdawaffe. fixes #2803

Location:
trunk/wp-admin
Files:
4 edited

Legend:

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

    r3863 r4041  
    145145        if ( !$cat = get_category( $cat ) )
    146146                die('0');
    147         $pad = 0;
     147        $level = 0;
     148        $cat_full_name = $cat->cat_name;
    148149        $_cat = $cat;
    149150        while ( $_cat->category_parent ) {
    150151                $_cat = get_category( $_cat->category_parent );
    151                 $pad++;
    152         }
    153         $pad = str_repeat('— ', $pad);
     152                $cat_full_name = $_cat->cat_name . ' — ' . $cat_full_name;
     153                $level++;
     154        }
     155        $cat_full_name = wp_specialchars( $cat_full_name, 1 );
    154156
    155157        $r  = "<?xml version='1.0' standalone='yes'?><ajaxresponse>";
    156         $r .= "<cat><id>$cat->cat_ID</id><newitem><![CDATA[<table><tbody>";
    157         $r .= "<tr id='cat-$cat->cat_ID'><th scope='row'>$cat->cat_ID</th><td>$pad $cat->cat_name</td>";
    158         $r .= "<td>$cat->category_description</td><td>$cat->category_count</td><td>$cat->link_count</td>";
    159         $r .= "<td><a href='categories.php?action=edit&amp;cat_ID=$cat->cat_ID' class='edit'>" . __('Edit') . "</a></td>";
    160         $r .= "<td><a href='categories.php?action=delete&amp;cat_ID=$cat->cat_ID' onclick='return deleteSomething( \"cat\", $cat->cat_ID, \"";
    161         $r .= sprintf(__('You are about to delete the category \"%s\".  All of its posts and bookmarks will go to the default categories.\\n\"OK\" to delete, \"Cancel\" to stop.'), addslashes($cat->cat_name));
    162         $r .= "\" );' class='delete'>".__('Delete')."</a></td></tr>";
     158        $r .= "<cat><id>$cat->cat_ID</id><name>$cat_full_name</name><newitem><![CDATA[<table><tbody>";
     159        $r .= _cat_row( $cat, $level, $cat_full_name );
    163160        $r .= "</tbody></table>]]></newitem></cat></ajaxresponse>";
    164161        header('Content-type: text/xml');
    165162        die($r);
    166 
    167163        break;
    168164case 'add-meta' :
  • trunk/wp-admin/admin-db.php

    r4022 r4041  
    109109
    110110        $category_parent = (int) $category_parent;
    111         if (empty ($category_parent))
     111        if ( empty($category_parent) || !get_category( $category_parent ) )
    112112                $category_parent = 0;
    113113
  • 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('&#8212; ', $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
  • trunk/wp-admin/categories.js

    r3684 r4041  
    1 addLoadEvent(newCategoryAddIn);
    2 function newCategoryAddIn() {
     1addLoadEvent(function() {
    32        if (!theList.theList) return false;
    43        document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); };
    5 }
     4        theList.addComplete = function(what, where, update) {
     5                var name = getNodeValue(theList.ajaxAdd.responseXML, 'name');
     6                var id = getNodeValue(theList.ajaxAdd.responseXML, 'id');
     7                var options = document.forms['addcat'].category_parent.options;
     8                options[options.length] = new Option(name, id);
     9        };
     10        theList.delComplete = function(what, id) {
     11                var options = document.forms['addcat'].category_parent.options;
     12                for ( var o = 0; o < options.length; o++ )
     13                        if ( id == options[o].value )
     14                                options[o] = null;
     15        };
     16});
Note: See TracChangeset for help on using the changeset viewer.