Changeset 5289
- Timestamp:
- 04/19/07 22:26:52 (1 year ago)
- Files:
-
- branches/2.2/wp-admin/admin-db.php (modified) (5 diffs)
- branches/2.2/wp-admin/admin-functions.php (modified) (4 diffs)
- branches/2.2/wp-admin/categories.php (modified) (1 diff)
- branches/2.2/wp-admin/edit-form-advanced.php (modified) (1 diff)
- branches/2.2/wp-admin/import/utw.php (deleted)
- branches/2.2/wp-admin/import/wp-cat2tag.php (deleted)
- branches/2.2/wp-admin/options-permalink.php (modified) (2 diffs)
- branches/2.2/wp-admin/upgrade-schema.php (modified) (3 diffs)
- branches/2.2/wp-admin/wp-admin.css (modified) (2 diffs)
- branches/2.2/wp-content/themes/classic/index.php (modified) (1 diff)
- branches/2.2/wp-content/themes/default/archive.php (modified) (2 diffs)
- branches/2.2/wp-content/themes/default/index.php (modified) (1 diff)
- branches/2.2/wp-content/themes/default/search.php (modified) (1 diff)
- branches/2.2/wp-content/themes/default/single.php (modified) (1 diff)
- branches/2.2/wp-includes/category-template.php (modified) (2 diffs)
- branches/2.2/wp-includes/category.php (modified) (4 diffs)
- branches/2.2/wp-includes/classes.php (modified) (1 diff)
- branches/2.2/wp-includes/functions.php (modified) (5 diffs)
- branches/2.2/wp-includes/link-template.php (modified) (1 diff)
- branches/2.2/wp-includes/post.php (modified) (7 diffs)
- branches/2.2/wp-includes/query.php (modified) (8 diffs)
- branches/2.2/wp-includes/rewrite.php (modified) (10 diffs)
- branches/2.2/wp-includes/template-loader.php (modified) (1 diff)
- branches/2.2/wp-includes/theme.php (modified) (1 diff)
- branches/2.2/xmlrpc.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.2/wp-admin/admin-db.php
r5272 r5289 122 122 $links_private = 0; 123 123 124 if ( empty($type) )125 $type = TAXONOMY_CATEGORY;126 127 // Let's check if we have this category already, if so just do an update128 if ( !$update && $cat_ID = category_object_exists( $category_nicename ) )129 $update = true;130 131 124 if (!$update) { 132 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private , type) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private', '$type')");125 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private')"); 133 126 $cat_ID = (int) $wpdb->insert_id; 134 127 } else { 135 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private' , type = '$type'WHERE cat_ID = '$cat_ID'");128 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private' WHERE cat_ID = '$cat_ID'"); 136 129 } 137 130 … … 199 192 $parent = $category->category_parent; 200 193 201 // Delete the category if it is not also a tag. 202 if ( 0 == ($category->type & TAXONOMY_TAG) ) { 203 if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") ) 204 return 0; 205 } else { 206 $wpdb->query("UPDATE $wpdb->categories SET type = type & ~" . TAXONOMY_CATEGORY . " WHERE cat_ID = '$cat_ID'"); 207 } 194 // Delete the category 195 if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") ) 196 return 0; 197 208 198 // Update children to point to new parent 209 199 $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); 210 200 211 201 // Only set posts and links to the default category if they're not in another category already 212 $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID' AND rel_type = 'category'");202 $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'"); 213 203 foreach ( (array) $posts as $post_id ) { 214 204 $cats = wp_get_post_categories($post_id); … … 236 226 237 227 function wp_create_category($cat_name) { 238 if ( $id = category_exists($cat_name) ) 239 return $id; 240 $cat_array = array('cat_name' => $cat_name, 'type' => TAXONOMY_CATEGORY); 241 242 if ( $id = category_object_exists($cat_name) ) { 243 $category = get_category($id); 244 $cat_array['type'] = $category->type | $cat_array['type']; 245 $cat_array['cat_ID'] = $id; 246 return wp_update_category($cat_array); 247 } else { 248 return wp_insert_category($cat_array); 249 } 228 $cat_array = compact('cat_name'); 229 return wp_insert_category($cat_array); 250 230 } 251 231 … … 266 246 } 267 247 268 function category_ object_exists($cat_name) {248 function category_exists($cat_name) { 269 249 global $wpdb; 270 250 if (!$category_nicename = sanitize_title($cat_name)) … … 272 252 273 253 return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'"); 274 }275 276 function category_exists($cat_name) {277 global $wpdb;278 if (!$category_nicename = sanitize_title($cat_name))279 return 0;280 281 return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename' AND ( type & " . TAXONOMY_CATEGORY . " != 0 )");282 }283 284 function tag_exists($tag_name) {285 global $wpdb;286 if (! $tag_nicename = sanitize_title($tag_name))287 return 0;288 289 return (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$tag_nicename' AND ( type & " . TAXONOMY_TAG . " != 0 )");290 }291 292 function wp_create_tag($tag_name) {293 if ( $id = tag_exists($tag_name) )294 return $id;295 $tag_array = array('cat_name' => $tag_name, 'type' => TAXONOMY_TAG);296 297 if ( $id = category_object_exists($tag_name) ) {298 $category = get_category($id);299 $tag_array['type'] = $category->type | $tag_array['type'];300 $tag_array['cat_ID'] = $id;301 $id = wp_update_category($tag_array);302 return $id;303 } else {304 return wp_insert_category($tag_array);305 }306 254 } 307 255 branches/2.2/wp-admin/admin-functions.php
r5259 r5289 648 648 function return_categories_list( $parent = 0 ) { 649 649 global $wpdb; 650 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( type & " . TAXONOMY_CATEGORY . " != 0 ) AND ( link_count = 0 OR category_count != 0) ORDER BY category_count DESC" );650 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( link_count = 0 OR category_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY category_count DESC" ); 651 651 } 652 652 … … 658 658 } 659 659 660 function get_tags_to_edit( $post_id ) {661 global $wpdb;662 663 $post_id = (int) $post_id;664 if ( !$post_id )665 return false;666 667 $tags = $wpdb->get_results( "668 SELECT category_id, cat_name669 FROM $wpdb->categories, $wpdb->post2cat670 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_id' AND rel_type = 'tag'671 " );672 if ( !$tags )673 return false;674 675 foreach ( $tags as $tag )676 $tag_names[] = $tag->cat_name;677 $tags_to_edit = join( ', ', $tag_names );678 $tags_to_edit = attribute_escape( $tags_to_edit );679 $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit );680 return $tags_to_edit;681 }682 683 660 function get_nested_categories( $default = 0, $parent = 0 ) { 684 661 global $post_ID, $link_id, $mode, $wpdb; … … 688 665 SELECT category_id 689 666 FROM $wpdb->categories, $wpdb->post2cat 690 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' AND rel_type = 'category'667 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' 691 668 " ); 692 669 … … 745 722 function return_link_categories_list( $parent = 0 ) { 746 723 global $wpdb; 747 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( type & " . TAXONOMY_CATEGORY . " != 0 ) AND ( category_count = 0 OR link_count != 0) ORDER BY link_count DESC" );724 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( category_count = 0 OR link_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY link_count DESC" ); 748 725 } 749 726 branches/2.2/wp-admin/categories.php
r5217 r5289 119 119 120 120 <?php include('edit-category-form.php'); ?> 121 122 <div class="wrap">123 <h3><?php _e('Importers & Converters'); ?></h3>124 125 <ul>126 <li><a href="admin.php?import=wp-cat2tag"><?php _e('Selectively convert categories to tags'); ?></a></li>127 <li><a href="admin.php?import=utw"><?php _e('Import Ultimate Tag Warrior tags'); ?></a></li>128 </ul>129 </div>130 121 <?php endif; ?> 131 122 branches/2.2/wp-admin/edit-form-advanced.php
r5257 r5289 160 160 <?php echo $form_prevstatus ?> 161 161 162 <fieldset id="tagdiv">163 <legend><?php _e('Tags (separate multiple tags with commas: cats, pet food, dogs)'); ?></legend>164 <div><input type="text" name="tags_input" id="tags-input" size="30" tabindex="3" value="<?php echo get_tags_to_edit( $post_ID ); ?>" /></div>165 </fieldset>166 162 167 163 <p class="submit"> branches/2.2/wp-admin/options-permalink.php
r5150 r5289 74 74 $wp_rewrite->set_category_base($category_base); 75 75 } 76 77 if ( isset($_POST['tag_base']) ) {78 $tag_base = $_POST['tag_base'];79 if (! empty($tag_base) )80 $tag_base = preg_replace('#/+#', '/', '/' . $_POST['tag_base']);81 $wp_rewrite->set_tag_base($tag_base);82 }83 76 } 84 77 85 78 $permalink_structure = get_option('permalink_structure'); 86 79 $category_base = get_option('category_base'); 87 $tag_base = get_option( 'tag_base' );88 80 89 81 if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') ) … … 168 160 <p> 169 161 <?php _e('Category base'); ?>: <input name="category_base" type="text" class="code" value="<?php echo attribute_escape($category_base); ?>" size="30" /> 170 </p>171 <p>172 <?php _e('Tag base'); ?>: <input name="tag_base" type="text" class="code" value="<?php echo attribute_escape($tag_base); ?>" size="30" />173 162 </p> 174 163 <p class="submit"> branches/2.2/wp-admin/upgrade-schema.php
r5184 r5289 19 19 category_count bigint(20) NOT NULL default '0', 20 20 link_count bigint(20) NOT NULL default '0', 21 tag_count bigint(20) NOT NULL default '0',22 21 posts_private tinyint(1) NOT NULL default '0', 23 22 links_private tinyint(1) NOT NULL default '0', 24 type tinyint NOT NULL default '1',25 23 PRIMARY KEY (cat_ID), 26 24 KEY category_nicename (category_nicename) … … 91 89 post_id bigint(20) NOT NULL default '0', 92 90 category_id bigint(20) NOT NULL default '0', 93 rel_type varchar(64) NOT NULL default 'category',94 91 PRIMARY KEY (rel_id), 95 92 KEY post_id (post_id,category_id) … … 244 241 add_option('show_on_front', 'posts'); 245 242 246 // 2.2247 add_option('tag_base');248 249 243 // Delete unused options 250 244 $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing'); branches/2.2/wp-admin/wp-admin.css
r5256 r5289 539 539 } 540 540 541 #postdiv, #titlediv, #guiddiv , #tagdiv{541 #postdiv, #titlediv, #guiddiv { 542 542 margin: 0 8px 0 0; 543 543 padding: 0; … … 559 559 } 560 560 561 #titlediv input, #guiddiv input , #tagdiv input{561 #titlediv input, #guiddiv input { 562 562 margin: 0; 563 563 width: 100%; branches/2.2/wp-content/themes/classic/index.php
r5168 r5289 9 9 <div class="post" id="post-<?php the_ID(); ?>"> 10 10 <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> 11 <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> — <?php the_ tags(__('Tags: '), ', ', ' — '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>11 <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> — <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div> 12 12 13 13 <div class="storycontent"> branches/2.2/wp-content/themes/default/archive.php
r5250 r5289 2 2 3 3 <div id="content" class="narrowcolumn"> 4 <?php is_tag(); ?> 4 5 5 <?php if (have_posts()) : ?> 6 6 7 <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>8 <?php /* If this is a category archive */ if (is_category()) { ?>7 <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?> 8 <?php /* If this is a category archive */ if (is_category()) { ?> 9 9 <h2 class="pagetitle">Archive for the ‘<?php single_cat_title(); ?>’ Category</h2> 10 <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?> 11 <h2 class="pagetitle">Posts Tagged ‘<?php single_cat_title(); ?>’</h2> 10 12 11 <?php /* If this is a daily archive */ } elseif (is_day()) { ?> 13 12 <h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2> 14 <?php /* If this is a monthly archive */ } elseif (is_month()) { ?> 13 14 <?php /* If this is a monthly archive */ } elseif (is_month()) { ?> 15 15 <h2 class="pagetitle">Archive for <?php the_time('F, Y'); ?></h2> 16 <?php /* If this is a yearly archive */ } elseif (is_year()) { ?> 16 17 <?php /* If this is a yearly archive */ } elseif (is_year()) { ?> 17 18 <h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2> 19 18 20 <?php /* If this is an author archive */ } elseif (is_author()) { ?> 19 21 <h2 class="pagetitle">Author Archive</h2> 20 <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?> 22 23 <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?> 21 24 <h2 class="pagetitle">Blog Archives</h2> 22 <?php } ?> 25 26 <?php } ?> 23 27 24 28 … … 37 41 </div> 38 42 39 <p class="postmetadata"> <?php the_tags('Tags: ', ', ', '<br />'); ?>Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>43 <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> 40 44 41 45 </div> branches/2.2/wp-content/themes/default/index.php
r5111 r5289 15 15 </div> 16 16 17 <p class="postmetadata"> <?php the_tags('Tags: ', ', ', '<br />'); ?>Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>17 <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> 18 18 </div> 19 19 branches/2.2/wp-content/themes/default/search.php
r5149 r5289 19 19 <small><?php the_time('l, F jS, Y') ?></small> 20 20 21 <p class="postmetadata"> <?php the_tags('Tags: ', ', ', '<br />'); ?>Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>21 <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> 22 22 </div> 23 23 branches/2.2/wp-content/themes/default/single.php
r5147 r5289 17 17 18 18 <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?> 19 <?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>20 19 21 20 <p class="postmetadata alt"> branches/2.2/wp-includes/category-template.php
r5265 r5289 273 273 } 274 274 275 function wp_tag_cloud( $args = '' ) {276 $defaults = array(277 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,278 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',279 'exclude' => '', 'include' => ''280 );281 $args = wp_parse_args( $args, $defaults );282 283 $tags = get_tags( array_merge($args, array('orderby' => 'count', 'order' => 'DESC')) ); // Always query top tags284 285 if ( empty($tags) )286 return;287 288 $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args289 echo apply_filters( 'wp_tag_cloud', $return, $args );290 }291 292 // $tags = prefetched tag array ( get_tags() )293 // $args['format'] = 'flat' => whitespace separated, 'list' => UL, 'array' => array()294 // $args['orderby'] = 'name', 'count'295 function wp_generate_tag_cloud( $tags, $args = '' ) {296 global $wp_rewrite;297 $defaults = array(298 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,299 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC'300 );301 $args = wp_parse_args( $args, $defaults );302 extract($args);303 304 if ( !$tags )305 return;306 $counts = $tag_links = array();307 foreach ( (array) $tags as $tag ) {308 $counts[$tag->cat_name] = $tag->tag_count;309 $tag_links[$tag->cat_name] = get_tag_link( $tag->cat_ID );310 }311 312 $min_count = min($counts);313 $spread = max($counts) - $min_count;314 if ( $spread <= 0 )315 $spread = 1;316 $font_spread = $largest - $smallest;317 if ( $font_spread <= 0 )318 $font_spread = 1;319 $font_step = $font_spread / $spread;320 321 // SQL cannot save you; this is a second (potentially different) sort on a subset of data.322 if ( 'name' == $orderby )323 uksort($counts, 'strnatcasecmp');324 else325 asort($counts);326 327 if ( 'DESC' == $order )328 $counts = array_reverse( $tag_counts, true );329 330 $a = array();331 332 $rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';333 334 foreach ( $counts as $tag => $count ) {335 $tag_link = clean_url($tag_links[$tag]);336 $tag = str_replace(' ', ' ', wp_specialchars( $tag ));337 $a[] = "<a href='$tag_link' title='" . attribute_escape( sprintf( __('%d topics'), $count ) ) . "'$rel style='font-size: " .338 ( $smallest + ( ( $count - $min_count ) * $font_step ) )339 . "$unit;'>$tag</a>";340 }341 342 switch ( $format ) :343 case 'array' :344 $return =& $a;345 break;346 case 'list' :347 $return = "<ul class='wp-tag-cloud'>\n\t<li>";348 $return .= join("</li>\n\t<li>", $a);349 $return .= "</li>\n</ul>\n";350 break;351 default :352 $return = join("\n", $a);353 break;354 endswitch;355 356 return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );357 }358 359 275 // 360 276 // Helper functions … … 373 289 } 374 290 375 //376 // Tags377 //378 379 function get_tag_link( $tag_id ) {380 global $wp_rewrite;381 $catlink = $wp_rewrite->get_tag_permastruct();382 383 $category = &get_category($tag_id);384 $category_nicename = $category->category_nicename;385 386 if ( empty($catlink) ) {387 $file = get_option('home') . '/';388 $catlink = $file . '?tag=' . $category_nicename;389 } else {390 391 $catlink = str_replace('%tag%', $category_nicename, $catlink);392 $catlink = get_option('home') . user_trailingslashit($catlink, 'category');393 }394 return apply_filters('tag_link', $catlink, $tag_id);395 }396 397 function get_the_tags( $id = 0 ) {398 global $post;399 400 $id = (int) $id;401 402 if ( ! $id && ! in_the_loop() )403 return false; // in-the-loop function404 405 if ( !$id )406 $id = (int) $post->ID;407 408 $tags = wp_get_post_tags( $id );409 $tags = apply_filters( 'get_the_tags', $tags );410 if ( empty( $tags ) )411 return false;412 return $tags;413 }414 415 function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) {416 $tags = get_the_tags();417 418 if ( empty( $tags ) )419 return false;420 421 $tag_list = $before;422 foreach ( $tags as $tag )423 $tag_links[] = '<a href="' . get_tag_link($tag->cat_ID) . '">' . $tag->cat_name . '</a>';424 425 $tag_links = join( $sep, $tag_links );426 $tag_links = apply_filters( 'the_tags', $tag_links );427 $tag_list .= $tag_links;428 429 $tag_list .= $after;430 431 echo $tag_list;432 }433 434 291 ?> branches/2.2/wp-includes/category.php
r5248 r5289 1 1 <?php 2 3 define('TAXONOMY_CATEGORY', 1);4 define('TAXONOMY_TAG', 2);5 2 6 3 function get_all_category_ids() { … … 81 78 else 82 79 $where .= ' AND category_count > 0'; 83 } else { 84 $where .= ' AND ( type & ' . TAXONOMY_CATEGORY . ' != 0 ) '; 85 } 86 87 80 } 88 81 89 82 if ( !empty($number) ) … … 214 207 } 215 208 216 function get_category_by_slug( $slug ) {217 global $wpdb;218 $slug = sanitize_title( $slug );219 if ( empty( $slug ) )220 return false;221 $category = $wpdb->get_var( "SELECT * FROM $wpdb->categories WHERE category_nicename = '$slug' " );222 return get_category( $category );223 }224 225 209 // Get the ID of a category from its name 226 210 function get_cat_ID($cat_name='General') { … … 345 329 return $children; 346 330 } 347 348 // Tags349 350 function &get_tags($args = '') {351 global $wpdb, $category_links;352 353 $defaults = array('orderby' => 'name', 'order' => 'ASC',354 'hide_empty' => true, 'exclude' => '', 'include' => '',355 'number' => '');356 $args = wp_parse_args( $args, $defaults );357 if ( 'count' == $args['orderby'] )358 $args['orderby'] = 'tag_count';359 else360 $args['orderby'] = "cat_" . $args['orderby']; // restricts order by to cat_ID and cat_name fields361 $args['number'] = (int) $args['number'];362 extract($args);363 364 $key = md5( serialize( $args ) );365 if ( $cache = wp_cache_get( 'get_tags', 'category' ) )366 if ( isset( $cache[ $key ] ) )367 return apply_filters('get_tags', $cache[$key], $args);368 369 $where = 'cat_ID > 0';370 $inclusions = '';371 if ( !empty($include) ) {372 $child_of = 0; //ignore child_of and exclude params if using include373 $exclude = '';374 $incategories = preg_split('/[\s,]+/',$include);375 if ( count($incategories) ) {376 foreach ( $incategories as $incat ) {377 if (empty($inclusions))378 $inclusions = ' AND ( cat_ID = ' . intval($incat) . ' ';379 else380 $inclusions .= ' OR cat_ID = ' . intval($incat) . ' ';381 }382 }383 }384 385 if (!empty($inclusions))386 $inclusions .= ')';387 $where .= $inclusions;388 389 $exclusions = '';390 if ( !empty($exclude) ) {391 $excategories = preg_split('/[\s,]+/',$exclude);392 if ( count($excategories) ) {393 foreach ( $excategories as $excat ) {394 if (empty($exclusions))395 $exclusions = ' AND ( cat_ID <> ' . intval($excat) . ' ';396 else397 $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';398 }399 }400 }401 402 if (!empty($exclusions))403 $exclusions .= ')';404 $exclusions = apply_filters('list_tags_exclusions', $exclusions, $args );405 $where .= $exclusions;406 407 if ( $hide_empty )408 $where .= ' AND tag_count > 0';409 410 $where .= ' AND ( type & ' . TAXONOMY_TAG . ' != 0 ) ';411 412 if ( !empty($number) )413 $number = 'LIMIT ' . $number;414 else415 $number = '';416 417 $tags = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE $where ORDER BY $orderby $order $number");418 419 if ( empty($tags) )420 return array();421 422 $cache[ $key ] = $tags;423 wp_cache_set( 'get_tags', $cache, 'category' );424 425 $tags = apply_filters('get_tags', $tags, $args);426 return $tags;427 }428 429 331 ?> branches/2.2/wp-includes/classes.php
r5164 r5289 2 2 3 3 class WP { 4 var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', ' tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots');4 var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots'); 5 5 6 6 var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type'); branches/2.2/wp-includes/functions.php
r5284 r5289 603 603 604 604 function clean_post_cache($id) { 605 global $post_cache, $post_meta_cache, $category_cache, $ tag_cache, $blog_id;605 global $post_cache, $post_meta_cache, $category_cache, $blog_id; 606 606 607 607 if ( isset( $post_cache[$blog_id][$id] ) ) … … 613 613 if ( isset( $category_cache[$blog_id][$id]) ) 614 614 unset ( $category_cache[$blog_id][$id] ); 615 616 if ( isset( $tag_cache[$blog_id][$id]) )617 unset ( $tag_cache[$blog_id][$id] );618 615 } 619 616 … … 642 639 643 640 function update_post_category_cache($post_ids) { 644 global $wpdb, $category_cache, $ tag_cache, $blog_id;641 global $wpdb, $category_cache, $blog_id; 645 642 646 643 if ( empty($post_ids) ) … … 663 660 $post_id_list = join( ',', $post_id_array ); // with already cached stuff removed 664 661 665 $dogs = $wpdb->get_results("SELECT post_id, category_id , rel_typeFROM $wpdb->post2cat WHERE post_id IN ($post_id_list)");662 $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_id_list)"); 666 663 667 664 if ( empty($dogs) ) 668 665 return; 669 666 670 foreach ($dogs as $catt) { 671 if ( 'category' == $catt->rel_type ) 672 $category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 673 elseif ( 'tag' == $catt->rel_type ) 674 $tag_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 675 } 667 foreach ($dogs as $catt) 668 $category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id); 676 669 } 677 670 678 671 function update_post_caches(&$posts) { 679 global $post_cache, $category_cache, $post_meta_cache , $tag_cache;672 global $post_cache, $category_cache, $post_meta_cache; 680 673 global $wpdb, $blog_id; 681 674 … … 1476 1469 } 1477 1470 1478 function wp_parse_args( $args, $defaults = '' ) {1479 if ( is_array($args) ) :1480 $r =& $args;1481 else :1482 parse_str( $args, $r );1483 if ( get_magic_quotes_gpc() )1484 $r = stripslashes_deep( $r );1485 endif;1486 1487 if ( is_array($defaults) ) :1488 extract($defaults);1489 extract($r);1490 return compact(array_keys($defaults)); // only those options defined in $defaults1491 else :1492 return $r;1493 endif;1494 }1495 1496 1471 ?> branches/2.2/wp-includes/link-template.php
r5282 r5289 60 60 '%post_id%', 61 61 '%category%', 62 '%tag%',63 62 '%author%', 64 63 '%pagename%' branches/2.2/wp-includes/post.php
r5271 r5289 459 459 } 460 460 461 function wp_get_post_tags( $post_id = 0 ) {462 global $tag_cache, $blog_id;463 464 $post_id = (int) $post_id;465 466 if ( !isset( $tag_cache[$blog_id][$post_id] ) )467 update_post_category_cache( $post_id ); // loads $tag_cache468 469 return $tag_cache[$blog_id][$post_id];470 }471 472 461 function wp_get_recent_posts($num = 10) { 473 462 global $wpdb; … … 531 520 $comment_status = apply_filters('comment_status_pre', $comment_status); 532 521 $ping_status = apply_filters('ping_status_pre', $ping_status); 533 $tags_input = apply_filters('tags_input_pre', $tags_input);534 522 } 535 523 … … 666 654 } 667 655 668 wp_set_post_categories( $post_ID, $post_category ); 669 wp_set_post_tags( $post_ID, $tags_input ); 656 wp_set_post_categories($post_ID, $post_category); 670 657 671 658 if ( 'page' == $post_type ) { … … 785 772 } 786 773 787 function wp_add_post_tags($post_id = 0, $tags = '') {788 return wp_set_post_tags($post_id, $tags, true);789 }790 791 function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {792 /* $append - true = don't delete existing tags, just add on, false = replace the tags with the new tags */793 global $wpdb;794 795 $post_id = (int) $post_id;796 797 if ( !$post_id )798 return false;799 800 // prevent warnings for unintialized variables801 $tag_ids = array();802 803 if ( empty($tags) )804 $tags = array();805 $tags = (is_array($tags)) ? $tags : explode( ',', $tags );806 807 foreach ( $tags as $tag ) {808 $tag = trim( $tag );809 if ( !$tag_slug = sanitize_title( $tag ) )810 continue; // discard811 if ( !$tag_id = tag_exists( $tag ) )812 $tag_id = wp_create_tag( $tag );813 $tag_ids[] = $tag_id;814 }815 816 if ( empty($tag_ids) && ( !empty($tags) || $append ) )817 return false;818 819 $tag_ids = array_unique( $tag_ids );820 821 // First the old tags822 $old_tags = $wpdb->get_col("823 SELECT category_id824 FROM $wpdb->post2cat825 WHERE post_id = '$post_id' AND rel_type = 'tag'");826 827 if ( !$old_tags ) {828 $old_tags = array();829 } else {830 $old_tags = array_unique( $old_tags );831 }832 833 // Delete any?834 $delete_tags = array_diff( $old_tags, $tag_ids);835 if ( $delete_tags && !$append ) {836 foreach ( $delete_tags as $del ) {837 $wpdb->query("838 DELETE FROM $wpdb->post2cat839 WHERE category_id = '$del'840 AND post_id = '$post_id'841 AND rel_type = 'tag'842 ");843 }844 }845 846 // Add any?847 $add_tags = array_diff( $tag_ids, $old_tags );848 if ( $add_tags ) {849 foreach ( $add_tags as $new_tag ) {850 $new_tag = (int) $new_tag;851 if ( !empty($new_tag) )852 $wpdb->query("853 INSERT INTO $wpdb->post2cat (post_id, category_id, rel_type)854 VALUES ('$post_id', '$new_tag', 'tag')");855 }856 }857 858 // Update category counts.859 $all_affected_tags = array_unique( array_merge( $tag_ids, $old_tags ) );860 foreach ( $all_affected_tags as $tag_id ) {861 $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status = 'publish' AND post_type = 'post' AND category_id = '$tag_id' AND rel_type = 'tag'" );862 $wpdb->query( "UPDATE $wpdb->categories SET tag_count = '$count', type = type | " . TAXONOMY_TAG . " WHERE cat_ID = '$tag_id'" );863 if ( $count == 0 )864 $wpdb->query( "UPDATE $wpdb->categories SET type = type & ~". TAXONOMY_TAG . " WHERE cat_ID = '$tag_id'" );865 clean_category_cache( $tag_id );866 do_action( 'edit_category', $tag_id );867 do_action( 'edit_tag', $tag_id );868 }869 }870 871 774 function wp_set_post_categories($post_ID = 0, $post_categories = array()) { 872 775 global $wpdb; … … 883 786 SELECT category_id 884 787 FROM $wpdb->post2cat 885 WHERE post_id = '$post_ID' AND rel_type = 'category'");788 WHERE post_id = '$post_ID'"); 886 789 887 790 if (!$old_categories) { … … 899 802 DELETE FROM $wpdb->post2cat 900 803 WHERE category_id = '$del' 901 AND post_id = '$post_ID' AND rel_type = 'category'804 AND post_id = '$post_ID' 902 805 "); 903 806 } … … 920 823 $all_affected_
