Ticket #6357: 6357-the_taxonomies.diff
File 6357-the_taxonomies.diff, 12.4 KB (added by , 16 years ago) |
---|
-
wp-includes/taxonomy.php
34 34 * 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 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; 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 } 48 56 … … 156 164 if ( !isset($args['rewrite']['slug']) ) 157 165 $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy); 158 166 $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', "taxonomy=$taxonomy&term="); 159 $wp_rewrite->add_permastruct( "{$args['rewrite']['slug']}/%$taxonomy%");167 $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%"); 160 168 } 161 169 162 170 $args['name'] = $taxonomy; … … 1036 1044 1037 1045 $defaults = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all'); 1038 1046 $args = wp_parse_args( $args, $defaults ); 1047 1048 $terms = array(); 1049 if ( count($taxonomies) > 1 ) { 1050 foreach ( $taxonomies as $index => $taxonomy ) { 1051 $t = get_taxonomy($taxonomy); 1052 if ( is_array($t->args) && $args != array_merge($args, $t->args) ) { 1053 unset($taxonomies[$index]); 1054 $terms = array_merge($terms, wp_get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args))); 1055 } 1056 } 1057 } else { 1058 $t = get_taxonomy($taxonomies[0]); 1059 if ( is_array($t->args) ) 1060 $args = array_merge($args, $t->args); 1061 } 1062 1039 1063 extract($args, EXTR_SKIP); 1040 1064 1041 1065 if ( 'count' == $orderby ) … … 1067 1091 $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) ORDER BY $orderby $order"; 1068 1092 1069 1093 if ( 'all' == $fields || 'all_with_object_id' == $fields ) { 1070 $terms = $wpdb->get_results($query);1094 $terms = array_merge($terms, $wpdb->get_results($query)); 1071 1095 update_term_cache($terms); 1072 1096 } else if ( 'ids' == $fields || 'names' == $fields ) { 1073 $terms = $wpdb->get_col($query);1097 $terms = array_merge($terms, $wpdb->get_col($query)); 1074 1098 } else if ( 'tt_ids' == $fields ) { 1075 1099 $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"); 1076 1100 } … … 1899 1923 } 1900 1924 } 1901 1925 1926 /** 1927 * get_term_link() - Generates a permalink for a taxonomy term archive 1928 * 1929 * @param object|int|string $term 1930 * @param string $taxonomy 1931 * @return string HTML link to taxonomy term archive 1932 */ 1933 function get_term_link( $term, $taxonomy ) { 1934 global $wp_rewrite; 1935 1936 $termlink = $wp_rewrite->get_extra_permastruct($taxonomy); 1937 1938 if ( !is_object($term) ) { 1939 if ( is_int($term) ) { 1940 $term = &get_term($term, $taxonomy); 1941 } else { 1942 $term = &get_term_by('slug', $term, $taxonomy); 1943 if ( is_wp_error($term) ) 1944 return $term; 1945 } 1946 } 1947 if ( is_wp_error( $term ) ) 1948 return $term; 1949 1950 $slug = $term->slug; 1951 1952 if ( empty($termlink) ) { 1953 $file = get_option('home') . '/'; 1954 $termlink = "$file?taxonomy=$taxonomy&term=$slug"; 1955 } else { 1956 $termlink = str_replace("%$taxonomy%", $slug, $termlink); 1957 $termlink = get_option('home') . user_trailingslashit($termlink, 'category'); 1958 } 1959 return apply_filters('term_link', $termlink, $term, $taxonomy); 1960 } 1961 1962 function the_taxonomies($post = 0) { 1963 echo join(' ', get_the_taxonomies($post)); 1964 } 1965 1966 function get_the_taxonomies($post = 0) { 1967 if ( is_int($post) ) 1968 $post =& get_post($post); 1969 elseif ( !is_object($post) ) 1970 $post =& $GLOBALS['post']; 1971 1972 $taxonomies = array(); 1973 1974 if ( !$post ) 1975 return $taxonomies; 1976 1977 $_template = '%2$s: %1$l.'; 1978 1979 foreach ( get_object_taxonomies($post) as $taxonomy ) { 1980 $t = (array) get_taxonomy($taxonomy); 1981 if ( empty($t['label']) ) 1982 $t['label'] = $taxonomy; 1983 if ( empty($t['args']) ) 1984 $t['args'] = array(); 1985 if ( empty($t['template']) ) 1986 $t['template'] = $_template; 1987 1988 $terms = get_object_term_cache($post->ID, $taxonomy); 1989 if ( empty($terms) ) 1990 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); 1991 1992 $links = array(); 1993 1994 foreach ( $terms as $term ) 1995 $links[] = "<a href='" . attribute_escape(get_term_link($term, $taxonomy)) . "'>$term->name</a>"; 1996 1997 if ( $links ) 1998 $taxonomies[$taxonomy] = wp_sprintf($t['template'], $links, $t['label']); 1999 } 2000 return $taxonomies; 2001 } 1902 2002 ?> -
wp-includes/media.php
437 437 echo wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true); 438 438 } 439 439 440 function get_attachment_taxonomies($attachment) { 441 if ( is_int( $attachment ) ) 442 $attachment = get_post($attachment); 443 else if ( is_array($attachment) ) 444 $attachment = (object) $attachment; 445 446 if ( ! is_object($attachment) ) 447 return array(); 448 449 $filename = basename($attachment->guid); 450 451 $objects = array('attachment'); 452 453 if ( false !== strpos($filename, '.') ) 454 $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1); 455 if ( !empty($attachment->post_mime_type) ) { 456 $objects[] = 'attachment:' . $attachment->post_mime_type; 457 if ( false !== strpos($attachment->post_mime_type, '/') ) 458 foreach ( explode('/', $attachment->post_mime_type) as $token ) 459 if ( !empty($token) ) 460 $objects[] = "attachment:$token"; 461 } 462 463 $taxonomies = array(); 464 foreach ( $objects as $object ) 465 if ( $taxes = get_object_taxonomies($object) ) 466 $taxonomies = array_merge($taxonomies, $taxes); 467 468 return array_unique($taxonomies); 469 } 470 440 471 ?> -
wp-includes/query.php
1147 1147 $term_ids[] = $term->term_id; 1148 1148 $post_ids = get_objects_in_term($term_ids, $q['taxonomy']); 1149 1149 1150 if ( count($post_ids) ) {1150 if ( !is_wp_error($post_ids) && count($post_ids) ) { 1151 1151 $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") "; 1152 1152 $post_type = 'any'; 1153 1153 $q['post_status'] = 'publish'; … … 1292 1292 $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")"; 1293 1293 } 1294 1294 if ( $post_status_join ) { 1295 $join .= " INNERJOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) ";1295 $join .= " LEFT JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) "; 1296 1296 foreach ( $statuswheres as $index => $statuswhere ) 1297 1297 $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))"; 1298 1298 } -
wp-includes/formatting.php
1376 1376 $args = (array) $args; 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) ) { 1382 1382 $arg = array_shift($args); -
wp-includes/rewrite.php
461 461 return $this->tag_structure; 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)) { 466 472 return $this->author_structure; … … 832 838 $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite); 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)); 846 851 $this->rules = apply_filters('rewrite_rules_array', $this->rules); … … 954 959 $wp->add_query_var($name); 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 963 968 function flush_rules() { -
wp-content/themes/default/image.php
23 23 <small> 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 28 29 <?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) { -
wp-admin/includes/media.php
426 426 return wp_iframe( 'media_upload_library_form', $errors ); 427 427 } 428 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 }459 460 429 function image_attachment_fields_to_edit($form_fields, $post) { 461 430 if ( substr($post->post_mime_type, 0, 5) == 'image' ) { 462 431 $form_fields['post_title']['required'] = true;