mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-22 07:22:01 +01:00
Category Ajax improvements from mdawaffe. fixes #2803
git-svn-id: http://svn.automattic.com/wordpress/trunk@4041 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d983ff8fda
commit
c2a613422c
@ -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 ) )
|
||||
|
@ -108,7 +108,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) )
|
||||
|
@ -684,39 +684,13 @@ function dropdown_link_categories($default = 0) {
|
||||
|
||||
// Dandy new recursive multiple category stuff.
|
||||
function cat_rows($parent = 0, $level = 0, $categories = 0) {
|
||||
global $wpdb, $class;
|
||||
|
||||
if (!$categories)
|
||||
$categories = get_categories('hide_empty=0');
|
||||
|
||||
if ($categories) {
|
||||
foreach ($categories as $category) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -725,6 +699,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;
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user