diff options
Diffstat (limited to 'wp-admin')
-rw-r--r-- | wp-admin/admin-ajax.php | 18 | ||||
-rw-r--r-- | wp-admin/admin-db.php | 2 | ||||
-rw-r--r-- | wp-admin/admin-functions.php | 55 | ||||
-rw-r--r-- | wp-admin/categories.js | 17 |
4 files changed, 52 insertions, 40 deletions
diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 088ce31..9c5ac65 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -144,26 +144,22 @@ case 'add-cat' : // From Manage->Categories die('0'); if ( !$cat = get_category( $cat ) ) die('0'); - $pad = 0; + $level = 0; + $cat_full_name = $cat->cat_name; $_cat = $cat; while ( $_cat->category_parent ) { $_cat = get_category( $_cat->category_parent ); - $pad++; + $cat_full_name = $_cat->cat_name . ' — ' . $cat_full_name; + $level++; } - $pad = str_repeat('— ', $pad); + $cat_full_name = wp_specialchars( $cat_full_name, 1 ); $r = "<?xml version='1.0' standalone='yes'?><ajaxresponse>"; - $r .= "<cat><id>$cat->cat_ID</id><newitem><![CDATA[<table><tbody>"; - $r .= "<tr id='cat-$cat->cat_ID'><th scope='row'>$cat->cat_ID</th><td>$pad $cat->cat_name</td>"; - $r .= "<td>$cat->category_description</td><td>$cat->category_count</td><td>$cat->link_count</td>"; - $r .= "<td><a href='categories.php?action=edit&cat_ID=$cat->cat_ID' class='edit'>" . __('Edit') . "</a></td>"; - $r .= "<td><a href='categories.php?action=delete&cat_ID=$cat->cat_ID' onclick='return deleteSomething( \"cat\", $cat->cat_ID, \""; - $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)); - $r .= "\" );' class='delete'>".__('Delete')."</a></td></tr>"; + $r .= "<cat><id>$cat->cat_ID</id><name>$cat_full_name</name><newitem><![CDATA[<table><tbody>"; + $r .= _cat_row( $cat, $level, $cat_full_name ); $r .= "</tbody></table>]]></newitem></cat></ajaxresponse>"; header('Content-type: text/xml'); die($r); - break; case 'add-meta' : if ( !current_user_can( 'edit_post', $id ) ) diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php index ea9c5e2..1f7c952 100644 --- a/wp-admin/admin-db.php +++ b/wp-admin/admin-db.php @@ -111,7 +111,7 @@ function wp_insert_category($catarr) { $category_description = apply_filters('pre_category_description', $category_description); $category_parent = (int) $category_parent; - if (empty ($category_parent)) + if ( empty($category_parent) || !get_category( $category_parent ) ) $category_parent = 0; if ( isset($posts_private) ) diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 8fa5184..9ab92cb 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -700,31 +700,7 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) { continue; } if ($category->category_parent == $parent) { - $category->cat_name = wp_specialchars($category->cat_name,'double'); - $pad = str_repeat('— ', $level); - if ( current_user_can('manage_categories') ) { - $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>"; - $default_cat_id = get_option('default_category'); - $default_link_cat_id = get_option('default_link_category'); - - if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) ) - $edit .= "<td><a href='" . wp_nonce_url("categories.php?action=delete&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 "%s".\\nAll of its posts will go into the default category of "%s"\\nAll of its bookmarks will go into the default category of "%s".\\n"OK" to delete, "Cancel" 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>"; - else - $edit .= "<td style='text-align:center'>".__("Default"); - } - else - $edit = ''; - - $class = ('alternate' == $class) ? '' : 'alternate'; - - $category->category_count = number_format( $category->category_count ); - $category->link_count = number_format( $category->link_count ); - echo "<tr id='cat-$category->cat_ID' class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td> - <td>$category->category_description</td> - <td align='center'>$category->category_count</td> - <td align='center'>$category->link_count</td> - <td>$edit</td> - </tr>"; + echo "\t" . _cat_row( $category, $level ); cat_rows($category->cat_ID, $level +1, $categories); } } @@ -733,6 +709,35 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) { } } +function _cat_row( $category, $level, $name_override = false ) { + global $class; + + $pad = str_repeat('— ', $level); + if ( current_user_can('manage_categories') ) { + $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>"; + $default_cat_id = get_option('default_category'); + $default_link_cat_id = get_option('default_link_category'); + + if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) ) + $edit .= "<td><a href='" . wp_nonce_url("categories.php?action=delete&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 "%s".\\nAll of its posts will go into the default category of "%s"\\nAll of its bookmarks will go into the default category of "%s".\\n"OK" to delete, "Cancel" 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>"; + else + $edit .= "<td style='text-align:center'>".__("Default"); + } else + $edit = ''; + + $class = ( ( defined('DOING_AJAX') && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; + + $category->category_count = number_format( $category->category_count ); + $category->link_count = number_format( $category->link_count ); + return "<tr id='cat-$category->cat_ID'$class> + <th scope='row'>$category->cat_ID</th> + <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->cat_name ) . "</td> + <td>$category->category_description</td> + <td align='center'>$category->category_count</td> + <td align='center'>$category->link_count</td> + <td>$edit</td>\n\t</tr>\n"; +} + function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) { global $wpdb, $class, $post; diff --git a/wp-admin/categories.js b/wp-admin/categories.js index 46ae62f..a636961 100644 --- a/wp-admin/categories.js +++ b/wp-admin/categories.js @@ -1,5 +1,16 @@ -addLoadEvent(newCategoryAddIn);
-function newCategoryAddIn() {
+addLoadEvent(function() {
if (!theList.theList) return false;
document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); };
-}
+ theList.addComplete = function(what, where, update) {
+ var name = getNodeValue(theList.ajaxAdd.responseXML, 'name');
+ var id = getNodeValue(theList.ajaxAdd.responseXML, 'id');
+ var options = document.forms['addcat'].category_parent.options;
+ options[options.length] = new Option(name, id);
+ };
+ theList.delComplete = function(what, id) {
+ var options = document.forms['addcat'].category_parent.options;
+ for ( var o = 0; o < options.length; o++ )
+ if ( id == options[o].value )
+ options[o] = null;
+ };
+});
|