Ticket #3130: quickcategories-002.diff
File quickcategories-002.diff, 8.6 KB (added by , 19 years ago) |
---|
-
wp-admin/admin-ajax.php
106 106 } 107 107 die('0'); 108 108 break; 109 case 'add-quickcategory' : // On the Fly 110 if ( !current_user_can( 'manage_categories' ) ) 111 die('-1'); 112 $names = explode(',', $_POST['newcat']); 113 $x = new WP_Ajax_Response(); 114 foreach ( $names as $hierarchical_cat_name ) { 115 $cat_names = explode('>', $hierarchical_cat_name); 116 $parents = array(); 117 $depth = count($cat_names) - 1; 118 foreach ( $cat_names as $cat_name ) { 119 $cat_name = trim($cat_name); 120 if ( !$category_nicename = sanitize_title($cat_name) ) 121 die('0'); 122 if ( $parents ) { 123 $n = count($parents); 124 $category_parent = $parents[count($parents) - 1]['cat_ID']; 125 } else { 126 $n = 0; 127 $category_parent = 0; 128 } 129 if ( !$cat_ID = category_exists( $cat_name ) ) { 130 if ( current_user_can( 'manage_categories' ) ) { 131 $cat_ID = wp_create_category($cat_name, $category_parent); 132 } else { 133 die('-1'); 134 } 135 } 136 $cat_name = wp_specialchars(stripslashes($cat_name)); 137 $category = compact('cat_name', 'cat_ID'); 138 if ( $depth == $n ) { 139 $li = get_quickadd_category($category, $parents, true); 140 $x->add( array( 141 'what' => 'quickcategory', 142 'id' => $cat_ID, 143 'data' => $li 144 ) ); 145 } else { 146 $parents[] = $category; 147 } 148 } 149 } 150 $x->send(); 151 break; 152 case 'delete-quickcategory' : 153 if ( !current_user_can( 'manage_categories') ) 154 die('-1'); 155 break; 109 156 case 'add-category' : // On the Fly 110 157 if ( !current_user_can( 'manage_categories' ) ) 111 158 die('-1'); -
wp-admin/wp-admin.css
1073 1073 background-position: 0 -28px; 1074 1074 } 1075 1075 1076 #moremeta h4 { 1077 margin: 0; 1078 background: #eee; 1079 position: relative; 1080 left: -5px; 1081 width: 182px; 1082 text-indent: 10px; 1083 color: #444; 1084 display: none; 1085 } 1086 1076 1087 #categorychecklist { 1077 1088 margin-right: 6px; 1078 1089 } 1079 1090 1091 #categorylist { 1092 font-size: 10px; 1093 color: #333; 1094 list-style: none; 1095 } 1096 1097 #categorylist a { 1098 color: #f00; 1099 border-bottom: 0; 1100 } 1101 1102 #categorylist b { 1103 color: #000; 1104 } 1105 1106 #categorylist span { 1107 display: block; 1108 position: absolute; 1109 left: -15px; 1110 color: #888; 1111 } 1112 1113 #categorylist li { 1114 left: -20px; 1115 position: relative; 1116 width: 155px; 1117 } 1118 1080 1119 /* additional clone styles */ 1081 1120 .dbx-clone { 1082 1121 opacity: 0.8; -
wp-admin/admin-functions.php
712 712 write_nested_categories(get_nested_link_categories($default)); 713 713 } 714 714 715 function quickadd_categories($default = 0) { 716 write_nested_quickadd_categories(get_nested_categories($default)); 717 } 718 719 // $categories is the array to expand 720 // $parents is an array of the parents of $categories, with the first element in the array being the top level parent, and so forth 721 function write_nested_quickadd_categories($categories, $parents = array()) { 722 foreach ( (array) $categories as $category ) { 723 if ( $category['checked'] ) 724 write_quickadd_category($category, $parents); 725 if ( $category['children'] ) { 726 $newparents = $parents; 727 $newparents[] = array('cat_name' => $category['cat_name']); 728 write_nested_quickadd_categories($category['children'], $newparents); 729 } 730 } 731 } 732 733 function write_quickadd_category($category, $parents = array()) { 734 echo get_quickadd_category($category, $parents); 735 } 736 737 function get_quickadd_category($category, $parents = array(), $with_input = false) { 738 $return = ''; 739 $return .= "<li id='quickcategory-{$category['cat_ID']}'><span>[<a href='#' onclick='quickCatRemove({$category['cat_ID']}); return false;'>x</a>]</span> "; 740 foreach ( (array) $parents as $parent ) 741 $return .= $parent['cat_name'] . ' » '; 742 $return .= "<b>{$category['cat_name']}</b>"; 743 if ( $with_input ) 744 $return .= "<input value='{$category['cat_ID']}' type='hidden' id='quickcat-hidden-{$category['cat_ID']}' name='post_category[]' />"; 745 $return .= "</li>\n\n"; 746 return $return; 747 } 748 715 749 // Dandy new recursive multiple category stuff. 716 750 function cat_rows($parent = 0, $level = 0, $categories = 0) { 717 751 if (!$categories) -
wp-admin/admin-db.php
217 217 return 1; 218 218 } 219 219 220 function wp_create_category($cat_name ) {221 $cat_array = compact('cat_name' );220 function wp_create_category($cat_name, $category_parent = 0) { 221 $cat_array = compact('cat_name', 'category_parent'); 222 222 return wp_insert_category($cat_array); 223 223 } 224 224 -
wp-admin/edit-form-advanced.php
71 71 <div id="moremeta"> 72 72 <div id="grabit" class="dbx-group"> 73 73 74 <fieldset id=" categorydiv" class="dbx-box">75 <h3 class="dbx-handle"><?php _e(' Categories') ?></h3>74 <fieldset id="quickcategorydiv" class="dbx-box" style="display: none;"> 75 <h3 class="dbx-handle"><?php _e('Quick Categories') ?></h3> 76 76 <div class="dbx-content"> 77 77 <p id="jaxcat"></p> 78 <ul id="categorychecklist"><?php dropdown_categories(get_option('default_category')); ?></ul></div> 78 <h4>Assigned categories</h4> 79 <ul id="categorylist"> 80 <?php quickadd_categories(get_option('default_category')); ?> 81 </ul> 82 <!-- 83 <li id="quickcategory-1"><span>[<a href="#">x</a>]</span> <b>Category name</b></li> 84 <li id="quickcategory-2"><span>[<a href="#">x</a>]</span> Parent » <b>Child</b></li> 85 <li id="quickcategory-3"><span>[<a href="#">x</a>]</span> Another Category » With » <b>a grandchild</b></li> 86 --> 87 </div> 79 88 </fieldset> 89 <script type="text/javascript"> 90 <!-- 91 document.getElementByID('quickcategorydiv').style.display = 'auto'; 92 //--> 93 </script> 80 94 95 <fieldset id="categorydiv" class="dbx-box"> 96 <h3 class="dbx-handle"><?php _e('Category Tree') ?></h3> 97 <div class="dbx-content"> 98 <ul id="categorychecklist"><?php dropdown_categories(get_option('default_category')); ?></ul> 99 </div> 100 </fieldset> 101 81 102 <fieldset id="commentstatusdiv" class="dbx-box"> 82 103 <h3 class="dbx-handle"><?php _e('Discussion') ?></h3> 83 104 <div class="dbx-content"> -
wp-admin/cat-js.php
2 2 require_once('../wp-config.php'); 3 3 cache_javascript_headers(); 4 4 ?> 5 addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.topAdder=1;catList.alt=0;catList.showLink=0;}); 5 addLoadEvent(function(){quickCatList=new listMan('categorylist');quickCatList.ajaxRespEl='jaxcat';quickCatList.topAdder=1;quickCatList.alt=0;quickCatList.showLink=0;}); 6 addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.topAdder=0;catList.alt=0;catList.showLink=0;}); 6 7 addLoadEvent(newCatAddIn); 7 8 function newCatAddIn() { 8 9 var jaxcat = $('jaxcat'); 9 10 if ( !jaxcat ) 10 11 return false; 11 12 jaxcat.update('<span id="ajaxcat"><input type="text" name="newcat" id="newcat" size="16" autocomplete="off"/><input type="button" name="Button" id="catadd" value="<?php _e('Add'); ?>"/><span id="howto"><?php _e('Separate multiple categories with commas.'); ?></span></span>'); 12 $('newcat').onkeypress = function(e) { return killSubmit("catList.ajaxAdder('category','jaxcat');", e); }; 13 $('catadd').onclick = function() { catList.ajaxAdder('category', 'jaxcat'); }; 13 14 /* 15 killSubmit("catList.ajaxAdder('category','jaxcat');", e); 16 catList.ajaxAdder('category', 'jaxcat'); 17 18 I'm having problems sending both ajaxAdder() calls. The first one works, but the second has an error. 19 I think it is because the first one is "taking" the input field and blanking it and the second one gets 20 blank data. No idea how to fix it. 21 */ 22 $('newcat').onkeypress = function(e) { return killSubmit("quickCatList.ajaxAdder('quickcategory','jaxcat');", e); }; 23 $('catadd').onclick = function() { quickCatList.ajaxAdder('quickcategory', 'jaxcat'); }; 14 24 } 25 26 function quickCatAdd(id) { 27 // Later 28 } 29 30 function quickCatRemove(id) { 31 if ( document.getElementById('quickcat-hidden-' + id) ) 32 document.getElementById('quickcat-hidden-' + id).value = ''; 33 quickCatList.ajaxDelete('quickcategory', id); 34 if ( document.getElementById('in-category-' + id) ) 35 document.getElementById('in-category-' + id).checked = false; 36 } 37 No newline at end of file