Changeset 7520
- Timestamp:
- 03/26/2008 06:37:19 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/media.php
r7510 r7520 425 425 426 426 return wp_iframe( 'media_upload_library_form', $errors ); 427 }428 429 function get_attachment_taxonomies($attachment) {430 if ( is_int( $attachment ) )431 $attachment = get_post($attachment);432 else if ( is_array($attachment) )433 $attachment = (object) $attachment;434 435 if ( ! is_object($attachment) )436 return array();437 438 $filename = basename($attachment->guid);439 440 $objects = array('attachment');441 442 if ( false !== strpos($filename, '.') )443 $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1);444 if ( !empty($attachment->post_mime_type) ) {445 $objects[] = 'attachment:' . $attachment->post_mime_type;446 if ( false !== strpos($attachment->post_mime_type, '/') )447 foreach ( explode('/', $attachment->post_mime_type) as $token )448 if ( !empty($token) )449 $objects[] = "attachment:$token";450 }451 452 $taxonomies = array();453 foreach ( $objects as $object )454 if ( $taxes = get_object_taxonomies($object) )455 $taxonomies = array_merge($taxonomies, $taxes);456 457 return array_unique($taxonomies);458 427 } 459 428 -
trunk/wp-content/themes/default/image.php
r7222 r7520 24 24 This entry was posted on <?php the_time('l, F jS, Y') ?> at <?php the_time() ?> 25 25 and is filed under <?php the_category(', ') ?>. 26 <?php the_taxonomies(); ?> 26 27 You can follow any responses to this entry through the <?php post_comments_feed_link('RSS 2.0'); ?> feed. 27 28 -
trunk/wp-includes/category-template.php
r7505 r7520 476 476 477 477 function get_the_tags( $id = 0 ) { 478 return apply_filters( 'get_the_tags', get_the_terms($id, 'post_tag') ); 479 } 480 481 function get_the_tag_list( $before = '', $sep = '', $after = '' ) { 482 return apply_filters( 'the_tags', get_the_term_list(0, 'post_tag', $before, $sep, $after) ); 483 } 484 485 function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) { 486 return the_terms( 0, 'post_tag', $before, $sep, $after ); 487 } 488 489 function get_the_terms( $id = 0, $taxonomy ) { 478 490 global $post; 479 491 … … 486 498 $id = (int) $post->ID; 487 499 488 $tags = get_object_term_cache($id, 'post_tag'); 489 if ( false === $tags ) 490 $tags = wp_get_object_terms($id, 'post_tag'); 491 492 $tags = apply_filters( 'get_the_tags', $tags ); 493 if ( empty( $tags ) ) 500 $terms = get_object_term_cache($id, $taxonomy); 501 if ( false === $terms ) 502 $terms = wp_get_object_terms($id, $taxonomy); 503 504 if ( empty( $terms ) ) 494 505 return false; 495 return $tags; 496 } 497 498 function get_the_tag_list( $before = '', $sep = '', $after = '' ) { 499 $tags = get_the_tags(); 500 501 if ( empty( $tags ) ) 506 507 return $terms; 508 } 509 510 function get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '' ) { 511 $terms = get_the_terms($id, $taxonomy); 512 513 if ( is_wp_error($terms) ) 514 return $terms; 515 516 if ( empty( $terms ) ) 502 517 return false; 503 518 504 $tag_list = $before; 505 foreach ( $tags as $tag ) { 506 $link = get_tag_link($tag->term_id); 519 foreach ( $terms as $term ) { 520 $link = get_term_link($term, $taxonomy); 507 521 if ( is_wp_error( $link ) ) 508 522 return $link; 509 $tag_links[] = '<a href="' . $link . '" rel="tag">' . $tag->name . '</a>'; 510 } 511 512 $tag_links = join( $sep, $tag_links ); 513 $tag_links = apply_filters( 'the_tags', $tag_links ); 514 $tag_list .= $tag_links; 515 516 $tag_list .= $after; 517 518 return $tag_list; 519 } 520 521 function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) { 522 $return = get_the_tag_list($before, $sep, $after); 523 $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>'; 524 } 525 526 $term_links = apply_filters( "term_links-$taxonomy", $term_links ); 527 528 return $before . join($sep, $term_links) . $after; 529 } 530 531 function the_terms( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { 532 $return = get_the_term_list($id, $taxonomy, $before, $sep, $after); 523 533 if ( is_wp_error( $return ) ) 524 534 return false; -
trunk/wp-includes/classes.php
r7503 r7520 15 15 16 16 function add_query_var($qv) { 17 $this->public_query_vars[] = $qv; 17 if ( !in_array($qv, $this->public_query_vars) ) 18 $this->public_query_vars[] = $qv; 18 19 } 19 20 -
trunk/wp-includes/formatting.php
r7497 r7520 1377 1377 $result = array_shift($args); 1378 1378 if ( count($args) == 1 ) 1379 $result .= $l['between_ two'] . array_shift($args);1379 $result .= $l['between_only_two'] . array_shift($args); 1380 1380 // Loop when more than two args 1381 1381 while ( count($args) ) { -
trunk/wp-includes/media.php
r7516 r7520 439 439 } 440 440 441 function get_attachment_taxonomies($attachment) { 442 if ( is_int( $attachment ) ) 443 $attachment = get_post($attachment); 444 else if ( is_array($attachment) ) 445 $attachment = (object) $attachment; 446 447 if ( ! is_object($attachment) ) 448 return array(); 449 450 $filename = basename($attachment->guid); 451 452 $objects = array('attachment'); 453 454 if ( false !== strpos($filename, '.') ) 455 $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1); 456 if ( !empty($attachment->post_mime_type) ) { 457 $objects[] = 'attachment:' . $attachment->post_mime_type; 458 if ( false !== strpos($attachment->post_mime_type, '/') ) 459 foreach ( explode('/', $attachment->post_mime_type) as $token ) 460 if ( !empty($token) ) 461 $objects[] = "attachment:$token"; 462 } 463 464 $taxonomies = array(); 465 foreach ( $objects as $object ) 466 if ( $taxes = get_object_taxonomies($object) ) 467 $taxonomies = array_merge($taxonomies, $taxes); 468 469 return array_unique($taxonomies); 470 } 471 441 472 ?> -
trunk/wp-includes/query.php
r7511 r7520 681 681 if ( empty($qv['taxonomy']) || empty($qv['term']) ) { 682 682 $this->is_tax = false; 683 foreach ( $GLOBALS['wp_taxonomies'] as $t ) { 684 if ( isset($t->query_var) && '' != $qv[$t->query_var] ) { 685 $this->is_tax = true; 686 break; 687 } 688 } 683 689 } else { 684 690 $this->is_tax = true; … … 1147 1153 // Taxonomies 1148 1154 if ( $this->is_tax ) { 1149 $terms = get_terms($q['taxonomy'], array('slug'=>$q['term'])); 1150 foreach ( $terms as $term ) 1151 $term_ids[] = $term->term_id; 1152 $post_ids = get_objects_in_term($term_ids, $q['taxonomy']); 1153 1154 if ( count($post_ids) ) { 1155 $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") "; 1156 $post_type = 'any'; 1157 $q['post_status'] = 'publish'; 1158 $post_status_join = true; 1155 if ( '' != $q['taxonomy'] ) { 1156 $taxonomy = $q['taxonomy']; 1157 $tt[$taxonomy] = $q['term']; 1158 $terms = get_terms($q['taxonomy'], array('slug'=>$q['term'])); 1159 1159 } else { 1160 $whichcat = " AND 0 = 1"; 1160 foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) { 1161 if ( isset($t->query_var) && '' != $q[$t->query_var] ) { 1162 $terms = get_terms($taxonomy, array('slug'=>$q[$t->query_var])); 1163 if ( !is_wp_error($terms) ) 1164 break; 1165 } 1166 } 1167 } 1168 if ( is_wp_error($terms) || empty($terms) ) { 1169 $whichcat = " AND 0 "; 1170 } else { 1171 foreach ( $terms as $term ) 1172 $term_ids[] = $term->term_id; 1173 $post_ids = get_objects_in_term($term_ids, $taxonomy); 1174 if ( !is_wp_error($post_ids) && count($post_ids) ) { 1175 $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") "; 1176 $post_type = 'any'; 1177 $q['post_status'] = 'publish'; 1178 $post_status_join = true; 1179 } else { 1180 $whichcat = " AND 0 "; 1181 } 1161 1182 } 1162 1183 } … … 1297 1318 } 1298 1319 if ( $post_status_join ) { 1299 $join .= " INNERJOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) ";1320 $join .= " LEFT JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) "; 1300 1321 foreach ( $statuswheres as $index => $statuswhere ) 1301 1322 $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))"; -
trunk/wp-includes/rewrite.php
r7493 r7520 462 462 } 463 463 464 function get_extra_permastruct($name) { 465 if ( isset($this->extra_permastructs[$name]) ) 466 return $this->extra_permastructs[$name]; 467 return false; 468 } 469 464 470 function get_author_permastruct() { 465 471 if (isset($this->author_structure)) { … … 833 839 834 840 // Extra permastructs 835 $extra_rewrite = array();836 841 foreach ( $this->extra_permastructs as $permastruct ) 837 $ extra_rewrite = array_merge($extra_rewrite, $this->generate_rewrite_rules($permastruct, EP_NONE));842 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, EP_NONE)); 838 843 839 844 // Put them together. 840 845 if ( $this->use_verbose_page_rules ) 841 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $ extra_rewrite, $this->extra_rules);846 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules); 842 847 else 843 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $ extra_rewrite, $page_rewrite, $this->extra_rules);848 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules); 844 849 845 850 do_action_ref_array('generate_rewrite_rules', array(&$this)); … … 955 960 } 956 961 957 function add_permastruct($ struct, $with_front = true) {962 function add_permastruct($name, $struct, $with_front = true) { 958 963 if ( $with_front ) 959 964 $struct = $this->front . $struct; 960 $this->extra_permastructs[ ] = $struct;965 $this->extra_permastructs[$name] = $struct; 961 966 } 962 967 -
trunk/wp-includes/taxonomy.php
r7507 r7520 35 35 * @uses $wp_taxonomies 36 36 * 37 * @param array|string $object_type Name of the type of taxonomy object37 * @param array|string|object $object Name of the type of taxonomy object, or an object (row from posts) 38 38 * @return array The names of all taxonomy of $object_type. 39 39 */ 40 function get_object_taxonomies($object _type) {40 function get_object_taxonomies($object) { 41 41 global $wp_taxonomies; 42 43 if ( is_object($object) ) { 44 if ( $object->post_type == 'attachment' ) 45 return get_attachment_taxonomies($object); 46 $object = $object->post_type; 47 } 48 49 $object = (array) $object; 42 50 43 51 $taxonomies = array(); 44 52 foreach ( $wp_taxonomies as $taxonomy ) { 45 if ( in_array($object_type, (array) $taxonomy->object_type) )53 if ( array_intersect($object, (array) $taxonomy->object_type) ) 46 54 $taxonomies[] = $taxonomy->name; 47 55 } … … 120 128 121 129 /** 122 * register_taxonomy() - Create or modify a taxonomy object. 130 * register_taxonomy() - Create or modify a taxonomy object. Do not use before init. 123 131 * 124 132 * A simple function for creating or modifying a taxonomy object based on the parameters given. … … 126 134 * taxonomy name and another string for the object type. 127 135 * 128 * The function keeps a default set, allowing for the $args to be optional but allow the other129 * functions to still work. It is possible to overwrite the default set, which contains two130 * keys: hierarchical and update_count_callback.131 *132 136 * Nothing is returned, so expect error maybe or use is_taxonomy() to check whether taxonomy exists. 133 137 * … … 135 139 * hierarachical - has some defined purpose at other parts of the API and is a boolean value. 136 140 * update_count_callback - works much like a hook, in that it will be called when the count is updated. 141 * rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize permastruct; default will use $taxonomy as slug 142 * query_var - false to prevent queries, or string to customize query var (?$query_var=$term); default will use $taxonomy as query var 137 143 * 138 144 * @package WordPress … … 140 146 * @since 2.3 141 147 * @uses $wp_taxonomies Inserts new taxonomy object into the list 148 * @uses $wp_rewrite Adds rewrite tags and permastructs 149 * @uses $wp Adds query vars 142 150 * 143 151 * @param string $taxonomy Name of taxonomy object … … 146 154 */ 147 155 function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 148 global $wp_taxonomies, $wp_rewrite ;149 150 $defaults = array('hierarchical' => false, 'update_count_callback' => '' );156 global $wp_taxonomies, $wp_rewrite, $wp; 157 158 $defaults = array('hierarchical' => false, 'update_count_callback' => '', 'rewrite' => true, 'query_var' => true); 151 159 $args = wp_parse_args($args, $defaults); 152 160 153 if ( !empty( $args['rewrite'] ) ) { 161 if ( false !== $args['query_var'] ) { 162 if ( empty($args['query_var']) ) 163 $args['query_var'] = $taxonomy; 164 $args['query_var'] = sanitize_title_with_dashes($args['query_var']); 165 $wp->add_query_var($args['query_var']); 166 } 167 168 if ( false !== $args['rewrite'] ) { 154 169 if ( !is_array($args['rewrite']) ) 155 170 $args['rewrite'] = array(); 156 171 if ( !isset($args['rewrite']['slug']) ) 157 172 $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy); 158 $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', "taxonomy=$taxonomy&term=");159 $wp_rewrite->add_permastruct( "{$args['rewrite']['slug']}/%$taxonomy%");173 $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=$term"); 174 $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%"); 160 175 } 161 176 … … 1037 1052 $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all'); 1038 1053 $args = wp_parse_args( $args, $defaults ); 1054 1055 $terms = array(); 1056 if ( count($taxonomies) > 1 ) { 1057 foreach ( $taxonomies as $index => $taxonomy ) { 1058 $t = get_taxonomy($taxonomy); 1059 if ( is_array($t->args) && $args != array_merge($args, $t->args) ) { 1060 unset($taxonomies[$index]); 1061 $terms = array_merge($terms, wp_get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args))); 1062 } 1063 } 1064 } else { 1065 $t = get_taxonomy($taxonomies[0]); 1066 if ( is_array($t->args) ) 1067 $args = array_merge($args, $t->args); 1068 } 1069 1039 1070 extract($args, EXTR_SKIP); 1040 1071 … … 1068 1099 1069 1100 if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 1070 $terms = $wpdb->get_results($query);1101 $terms = array_merge($terms, $wpdb->get_results($query)); 1071 1102 update_term_cache($terms); 1072 1103 } else if ( 'ids' == $fields || 'names' == $fields ) { 1073 $terms = $wpdb->get_col($query);1104 $terms = array_merge($terms, $wpdb->get_col($query)); 1074 1105 } else if ( 'tt_ids' == $fields ) { 1075 1106 $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) ORDER BY tr.term_taxonomy_id $order"); … … 1900 1931 } 1901 1932 1933 /** 1934 * get_term_link() - Generates a permalink for a taxonomy term archive 1935 * 1936 * @param object|int|string $term 1937 * @param string $taxonomy 1938 * @return string HTML link to taxonomy term archive 1939 */ 1940 function get_term_link( $term, $taxonomy ) { 1941 global $wp_rewrite; 1942 1943 $termlink = $wp_rewrite->get_extra_permastruct($taxonomy); 1944 1945 if ( !is_object($term) ) { 1946 if ( is_int($term) ) { 1947 $term = &get_term($term, $taxonomy); 1948 } else { 1949 $term = &get_term_by('slug', $term, $taxonomy); 1950 } 1951 } 1952 if ( is_wp_error( $term ) ) 1953 return $term; 1954 1955 $slug = $term->slug; 1956 1957 if ( empty($termlink) ) { 1958 $file = get_option('home') . '/'; 1959 $t = get_taxonomy($taxonomy); 1960 if ( $t->query_var ) 1961 $termlink = "$file?$t->query_var=$slug"; 1962 else 1963 $termlink = "$file?taxonomy=$taxonomy&term=$slug"; 1964 } else { 1965 $termlink = str_replace("%$taxonomy%", $slug, $termlink); 1966 $termlink = get_option('home') . user_trailingslashit($termlink, 'category'); 1967 } 1968 return apply_filters('term_link', $termlink, $term, $taxonomy); 1969 } 1970 1971 function the_taxonomies($args = array()) { 1972 $defaults = array( 1973 'post' => 0, 1974 'before' => '', 1975 'sep' => ' ', 1976 'after' => '', 1977 ); 1978 1979 $r = wp_parse_args( $args, $defaults ); 1980 extract( $r, EXTR_SKIP ); 1981 1982 echo $before . join($sep, get_the_taxonomies($post)) . $after; 1983 } 1984 1985 function get_the_taxonomies($post = 0) { 1986 if ( is_int($post) ) 1987 $post =& get_post($post); 1988 elseif ( !is_object($post) ) 1989 $post =& $GLOBALS['post']; 1990 1991 $taxonomies = array(); 1992 1993 if ( !$post ) 1994 return $taxonomies; 1995 1996 $_template = '%s: %l.'; 1997 1998 foreach ( get_object_taxonomies($post) as $taxonomy ) { 1999 $t = (array) get_taxonomy($taxonomy); 2000 if ( empty($t['label']) ) 2001 $t['label'] = $taxonomy; 2002 if ( empty($t['args']) ) 2003 $t['args'] = array(); 2004 if ( empty($t['template']) ) 2005 $t['template'] = $_template; 2006 2007 $terms = get_object_term_cache($post->ID, $taxonomy); 2008 if ( empty($terms) ) 2009 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); 2010 2011 $links = array(); 2012 2013 foreach ( $terms as $term ) 2014 $links[] = "<a href='" . attribute_escape(get_term_link($term, $taxonomy)) . "'>$term->name</a>"; 2015 2016 if ( $links ) 2017 $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms); 2018 } 2019 return $taxonomies; 2020 } 2021 2022 function get_post_taxonomies($post = 0) { 2023 $post =& get_post($post); 2024 2025 return get_object_taxonomies($post); 2026 } 2027 1902 2028 ?>
Note: See TracChangeset
for help on using the changeset viewer.