Changeset 6588
- Timestamp:
- 01/10/2008 09:39:35 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r6584 r6588 158 158 die('-1'); 159 159 $names = explode(',', $_POST['newcat']); 160 if ( 0 > $parent = (int) $_POST['newcat_parent'] ) 161 $parent = 0; 162 163 $checked_categories = array_map( 'absint', (array) $_POST['post_category'] ); 164 160 165 $x = new WP_Ajax_Response(); 161 166 foreach ( $names as $cat_name ) { … … 164 169 if ( '' === $category_nicename ) 165 170 continue; 166 $cat_id = wp_create_category( $cat_name ); 167 $cat_name = wp_specialchars(stripslashes($cat_name)); 171 $cat_id = wp_create_category( $cat_name, $parent ); 172 $checked_categories[] = $cat_id; 173 if ( $parent ) // Do these all at once in a second 174 continue; 175 $category = get_category( $cat_id ); 176 $category->_is_checked = true; 177 ob_start(); 178 dropdown_categories( 0, $category ); 179 $data = ob_get_contents(); 180 ob_end_clean(); 168 181 $x->add( array( 169 182 'what' => 'category', 170 183 'id' => $cat_id, 171 'data' => "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>",184 'data' => $data, 172 185 'position' => -1 173 186 ) ); 187 } 188 if ( $parent ) { // Foncy - replace the parent and all its children 189 $parent = get_category( $parent ); 190 ob_start(); 191 dropdown_categories( 0, $parent ); 192 $data = ob_get_contents(); 193 ob_end_clean(); 194 $x->add( array( 195 'what' => 'category', 196 'id' => $parent->term_id, 197 'old_id' => $parent->term_id, 198 'data' => $data, 199 'position' => -1 200 ) ); 201 174 202 } 175 203 $x->send(); -
trunk/wp-admin/admin-header.php
r6548 r6588 3 3 if (!isset($_GET["page"])) require_once('admin.php'); 4 4 if ( $editing ) { 5 if ( current_user_can('manage_categories') )6 wp_enqueue_script( 'ajaxcat' );7 5 if ( user_can_richedit() ) 8 6 wp_enqueue_script( 'wp_tiny_mce' ); -
trunk/wp-admin/edit-form-advanced.php
r6584 r6588 122 122 <h3><?php _e('Categories') ?></h3> 123 123 <div class="inside"> 124 <p id="jaxcat"><?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?></p> 125 <ul id="categorychecklist" class="list:category"><?php dropdown_categories(); ?></ul> 124 125 <div id="category-adder" class="wp-hidden-children"> 126 <h4><a id="category-add-toggle" href="#category-add"><?php _e( '+ Add New Category' ); ?></a></h4> 127 <p id="category-add" class="wp-hidden-child"> 128 <input type="text" name="newcat" id="newcat" class="form-required" value="<?php _e( 'New category name' ); ?>" /> 129 <?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) ); ?> 130 <a id="category-add-sumbit" class="add:categorychecklist:categorydiv button" href="<?php echo wp_nonce_url( '', 'add-category' ); ?>"><?php _e( 'Add' ); ?></a> 131 <span id="category-ajax-response"></span> 132 </p> 133 </div> 134 135 <ul id="category-tabs"> 136 <li class="ui-tabs-selected"><a href="#categories-all"><?php _e( 'All Categories' ); ?></a></li> 137 <li><a href="#categories-pop"><?php _e( 'Most Used' ); ?></a></li> 138 </ul> 139 140 <div id="categories-all" class="ui-tabs-panel"> 141 <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 142 <?php dropdown_categories(); ?> 143 </ul> 144 </div> 145 146 <div id="categories-pop" class="ui-tabs-panel"> 147 <ul id="categorychecklist-pop" class="categorychecklist form-no-clear"> 148 <?php wp_popular_categories_checklist(); ?> 149 </ul> 150 </div> 151 126 152 </div> 127 153 </div> -
trunk/wp-admin/includes/taxonomy.php
r6363 r6588 17 17 } 18 18 19 function wp_create_category( $cat_name) {19 function wp_create_category( $cat_name, $parent = 0 ) { 20 20 if ( $id = category_exists($cat_name) ) 21 21 return $id; 22 22 23 return wp_insert_category( array('cat_name' => $cat_name ) );23 return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) ); 24 24 } 25 25 -
trunk/wp-admin/includes/template.php
r6570 r6588 119 119 } 120 120 121 function get_nested_categories( $default = 0, $parent = 0 ) {121 function wp_set_checked_post_categories( $default = 0 ) { 122 122 global $post_ID, $checked_categories; 123 123 … … 135 135 } 136 136 137 $cats = get_categories("parent=$parent&hide_empty=0&fields=ids"); 138 139 $result = array (); 140 if ( is_array( $cats ) ) { 141 foreach ( $cats as $cat) { 142 $result[$cat]['children'] = get_nested_categories( $default, $cat); 143 $result[$cat]['cat_ID'] = $cat; 144 $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 145 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); 137 } 138 function get_nested_categories( $default = 0, $parent = 0 ) { 139 global $checked_categories; 140 141 wp_set_checked_post_categories( $default = 0 ); 142 143 if ( is_object($parent) ) { // Hack: if passed a category object, will return nested cats with parent as root 144 $root = array( 145 'children' => get_nested_categories( $default, $parent->term_id ), 146 'cat_ID' => $parent->term_id, 147 'checked' => isset($parent->_is_checked) && $parent->_is_checked, 148 'cat_name' => get_the_category_by_ID( $parent->term_id ) 149 ); 150 $result = array( $parent->term_id => $root ); 151 } else { 152 $parent = (int) $parent; 153 154 $cats = get_categories("parent=$parent&hide_empty=0&fields=ids"); 155 156 $result = array(); 157 if ( is_array( $cats ) ) { 158 foreach ( $cats as $cat ) { 159 $result[$cat]['children'] = get_nested_categories( $default, $cat ); 160 $result[$cat]['cat_ID'] = $cat; 161 $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 162 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat ); 163 } 146 164 } 147 165 } … … 166 184 } 167 185 168 function dropdown_categories( $default = 0 ) { 169 write_nested_categories( get_nested_categories( $default) ); 186 function dropdown_categories( $default = 0, $parent = 0 ) { 187 write_nested_categories( get_nested_categories( $default, $parent ) ); 188 } 189 190 function wp_popular_categories_checklist( $default = 0, $number = 10 ) { 191 global $checked_categories; 192 193 wp_set_checked_post_categories( $default ); 194 195 $categories = get_categories( array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) ); 196 197 foreach ( (array) $categories as $category ) { 198 $id = "popular-category-$category->term_id"; 199 $checked = in_array( $category->term_id, $checked_categories ) ? ' checked="checked"' : ''; 200 ?> 201 202 <li id="<?php echo $id; ?>"> 203 <label class="selectit" for="in-<?php echo $id; ?>"> 204 <input id="in-<?php echo $id; ?>" type="checkbox" name="post_category[]" value="<?php echo (int) $category->term_id; ?>"<?php echo $checked; ?> /> 205 <?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?> 206 </label> 207 </li> 208 209 <?php 210 } 170 211 } 171 212 -
trunk/wp-admin/js/post.js
r6584 r6588 91 91 // postboxes 92 92 add_postbox_toggles(); 93 94 // category tabs 95 var categoryTabs =jQuery('#category-tabs').tabs(); 96 97 // Ajax Cat 98 var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ) } ); 99 jQuery('#category-add-sumbit').click( function() { newCat.focus(); } ); 100 var catAddAfter = function( r, s ) { 101 jQuery(s.what + ' response_data', r).each( function() { 102 var t = jQuery(jQuery(this).text()); 103 var o = jQuery( '<option value="' + parseInt( t.find(':input').val(), 10 ) + '"></option>' ); 104 o.text( jQuery.trim( t.text() ) ); 105 jQuery('#newcat_parent').prepend( o ); 106 } ); 107 }; 108 jQuery('#categorychecklist').wpList( { 109 alt: '', 110 response: 'category-ajax-response', 111 addAfter: catAddAfter 112 } ); 113 jQuery('#category-add-toggle').click( function() { 114 jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' ); 115 categoryTabs.tabsClick( 1 ); 116 return false; 117 } ); 93 118 }); -
trunk/wp-admin/wp-admin.css
r6582 r6588 688 688 } 689 689 690 #categorydiv ul {691 list-style: none;692 padding: 0;693 margin-left: 10px;694 }695 696 #categorychecklist {697 height: 12em;698 overflow: auto;699 margin-top: 8px;700 }701 702 #categorychecklist li {703 margin: 0;704 padding: 0;705 }706 707 #ajaxcat input {708 border: 1px solid #ccc;709 }710 711 690 #your-profile #rich_editing { 712 691 border: none; … … 738 717 } 739 718 740 741 742 #newcat {743 width: 120px;744 margin-right: 5px;745 }746 747 input #catadd {748 background: #a4a4a4;749 border-bottom: 1px solid #898989;750 border-left: 1px solid #bcbcbc;751 border-right: 1px solid #898989;752 border-top: 1px solid #bcbcbc;753 color: #fff;754 font-size: 10px;755 padding: 0;756 margin: 0;757 font-weight: bold;758 height: 20px;759 margin-bottom: 2px;760 text-align: center;761 width: 37px;762 }763 764 719 #howto { 765 720 font-size: 11px; 766 721 margin: 0 5px; 767 722 display: block; 768 }769 770 #jaxcat {771 margin: 0;772 padding: 0;773 723 } 774 724 … … 1280 1230 background-position: 4px 18px; 1281 1231 } 1232 1233 /* Categories */ 1234 1235 #categorydiv #category-adder { 1236 margin-left: 120px; 1237 padding: 4px 0; 1238 } 1239 1240 #category-add input, #category-add select { 1241 width: 30%; 1242 } 1243 1244 #categorydiv ul#category-tabs { 1245 float: left; 1246 width: 120px; 1247 text-align: right; 1248 /* Negative margin for the sake of those without JS: all tabs display */ 1249 margin: 0 -120px 0 0; 1250 padding: 0; 1251 } 1252 1253 ul#category-tabs li { 1254 padding: 8px; 1255 } 1256 1257 ul#category-tabs li.ui-tabs-selected { 1258 background-color: #CEE1EF; 1259 } 1260 1261 div.ui-tabs-panel { 1262 margin: 0 0 0 120px; 1263 padding: .5em .9em; 1264 height: 12em; 1265 overflow: auto; 1266 border: 4px solid #CEE1EF; 1267 } 1268 1269 #categorydiv ul { 1270 list-style: none; 1271 padding: 0; 1272 margin: 0; 1273 } 1274 1275 #categorydiv ul.categorychecklist ul { 1276 margin-left: 18px; 1277 } 1278 1279 ul.categorychecklist li { 1280 margin: 0; 1281 padding: 0; 1282 } 1283 1284 /* Global classes */ 1285 .wp-hidden-children .wp-hidden-child { display: none; } 1286 .ui-tabs-hide { display: none; } -
trunk/wp-includes/js/wp-lists.js
r6582 r6588 310 310 var b = e.css( 'background-color' ); 311 311 if ( b == 'transparent' ) { b = ''; } 312 313 $('#' + s.element).css('background-color', s.addColor).animate( { backgroundColor: '#fff' }, 300 ); 312 e.css('background-color', s.addColor).animate( { backgroundColor: '#fff' }, 300 ); 314 313 } 315 314 list.each( function() { this.wpList.process( e ); } ); … … 322 321 if ( list.wpList && e.parents( '#' + list.id ).size() ) { return; } 323 322 e.find(':input').each( function() { 323 if ( $(this).parents('.form-no-clear').size() ) 324 return; 324 325 var t = this.type.toLowerCase(); var tag = this.tagName.toLowerCase(); 325 326 if ( 'text' == t || 'password' == t || 'textarea' == tag ) { this.value = ''; } -
trunk/wp-includes/script-loader.php
r6587 r6588 61 61 ) ); 62 62 63 $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('jquery'), '200 71101' );63 $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('jquery'), '20080109' ); 64 64 $this->localize( 'wp-lists', 'wpListL10n', array( 65 65 'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' … … 85 85 $this->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20'); 86 86 $this->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array('jquery'), '3.1'); 87 88 $this->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui.tabs.js', array('jquery'), '3' ); 87 89 88 90 if ( is_admin() ) { … … 107 109 $this->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' ); 108 110 $this->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' ); 109 $this->add( 'post', '/wp-admin/js/post.js', array('suggest' ), '20080102' );111 $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists'), '20080109' ); 110 112 $this->localize( 'post', 'postL10n', array( 111 113 'tagsUsed' => __('Tags used on this post:'), … … 138 140 'confirmText' => __("Are you sure you want to delete the file '%title%'?\nClick ok to delete or cancel to go back.") 139 141 ) ); 140 $this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), mt_rand());142 $this->add( 'admin-widgets', '/wp-admin/js/widgets.js', array( 'interface' ), '20080109' ); 141 143 } 142 144 }
Note: See TracChangeset
for help on using the changeset viewer.