WordPress.org

Make WordPress Core

Changeset 7491


Ignore:
Timestamp:
03/23/2008 05:02:11 PM (12 years ago)
Author:
ryan
Message:

Taxonomy queries and urls. Props andy. see #6357

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r7485 r7491  
    12261226add_action('admin_head_media_upload_library_form', 'media_admin_css');
    12271227
    1228 
    1229 register_taxonomy(
    1230     'image_tags',
    1231     'attachment:image',
    1232     array(
    1233         'label' => __('Tags'),
    1234         'template' => __('Tags: %l'),
    1235         'sort' => false,
    1236     )
    1237 );
    1238 
    1239 // Any 'attachment' taxonomy will be included in the description input form for the multi uploader
    1240 // Example:
    1241 /*
    1242 register_taxonomy(
    1243     'image_people',
    1244     'attachment:image',
    1245     array(
    1246         'label' => __('People'),
    1247         'template' => __('People: %l'),
    1248         'helps' => __('Left to right, top to bottom.'),
    1249         'sort' => true,
    1250         'args' => array(
    1251             'orderby' => 'term_order'
    1252         )
    1253     )
    1254 );
    1255 */
    1256 /*
    1257 register_taxonomy('movie_director', 'attachment:video', array('label'=>__('Directors'), 'template'=>__('Directed by %l.')));
    1258 register_taxonomy('movie_producer', 'attachment:video', array('label'=>__('Producers'), 'template'=>__('Produced by %l.')));
    1259 register_taxonomy('movie_screenwriter', 'attachment:video', array('label'=>__('Screenwriter'), 'template'=>__('Screenplay by %l.')));
    1260 register_taxonomy('movie_actor', 'attachment:video', array('label'=>__('Cast'), 'template'=>array(__('Cast: %l.')));
    1261 register_taxonomy('movie_crew', 'attachment:video', array('label'=>__('Crew'), 'template'=>array(__('Crew: %l.')));
    1262 */
    1263 
    12641228?>
  • trunk/wp-includes/classes.php

    r7454 r7491  
    22
    33class 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', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term');
    55
    66    var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm');
  • trunk/wp-includes/default-filters.php

    r6985 r7491  
    107107add_filter('the_content', 'convert_chars');
    108108add_filter('the_content', 'wpautop');
     109add_filter('the_content', 'prepend_attachment');
    109110
    110111add_filter('the_excerpt', 'wptexturize');
  • trunk/wp-includes/post-template.php

    r7404 r7491  
    502502
    503503function prepend_attachment($content) {
     504    global $post;
     505
     506    if ( empty($post->post_type) || $post->post_type != 'attachment' )
     507        return;
     508
    504509    $p = '<p class="attachment">';
    505510    // show the medium sized image representation of the attachment if available, and link to the raw file
  • trunk/wp-includes/query.php

    r7109 r7491  
    115115
    116116    if ( in_array( $tag_obj->slug, $slug ) )
     117        return true;
     118
     119    return false;
     120}
     121
     122function is_tax( $slug = '' ) {
     123    global $wp_query;
     124   
     125    if ( !$wp_query->is_tax )
     126        return false;
     127
     128    if ( empty($slug) )
     129        return true;
     130
     131    $term = $wp_query->get_queried_object();
     132
     133    $slug = (array) $slug;
     134
     135    if ( in_array( $term->slug, $slug ) )
    117136        return true;
    118137
     
    371390    var $is_category = false;
    372391    var $is_tag = false;
     392    var $is_tax = false;
    373393    var $is_search = false;
    374394    var $is_feed = false;
     
    396416        $this->is_category = false;
    397417        $this->is_tag = false;
     418        $this->is_tax = false;
    398419        $this->is_search = false;
    399420        $this->is_feed = false;
     
    658679            }
    659680
     681            if ( empty($qv['taxonomy']) || empty($qv['term']) ) {
     682                $this->is_tax = false;
     683            } else {
     684                $this->is_tax = true;
     685            }
     686
    660687            if ( empty($qv['author']) || ($qv['author'] == '0') ) {
    661688                $this->is_author = false;
     
    841868        if ( $q['m'] ) {
    842869            $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
    843             $where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4);
     870            $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4);
    844871            if (strlen($q['m'])>5)
    845                 $where .= ' AND MONTH(post_date)=' . substr($q['m'], 4, 2);
     872                $where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2);
    846873            if (strlen($q['m'])>7)
    847                 $where .= ' AND DAYOFMONTH(post_date)=' . substr($q['m'], 6, 2);
     874                $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2);
    848875            if (strlen($q['m'])>9)
    849                 $where .= ' AND HOUR(post_date)=' . substr($q['m'], 8, 2);
     876                $where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2);
    850877            if (strlen($q['m'])>11)
    851                 $where .= ' AND MINUTE(post_date)=' . substr($q['m'], 10, 2);
     878                $where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2);
    852879            if (strlen($q['m'])>13)
    853                 $where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2);
     880                $where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2);
    854881        }
    855882
    856883        if ( '' !== $q['hour'] )
    857             $where .= " AND HOUR(post_date)='" . $q['hour'] . "'";
     884            $where .= " AND HOUR($wpdb->posts.post_date)='" . $q['hour'] . "'";
    858885
    859886        if ( '' !== $q['minute'] )
    860             $where .= " AND MINUTE(post_date)='" . $q['minute'] . "'";
     887            $where .= " AND MINUTE($wpdb->posts.post_date)='" . $q['minute'] . "'";
    861888
    862889        if ( '' !== $q['second'] )
    863             $where .= " AND SECOND(post_date)='" . $q['second'] . "'";
     890            $where .= " AND SECOND($wpdb->posts.post_date)='" . $q['second'] . "'";
    864891
    865892        if ( $q['year'] )
    866             $where .= " AND YEAR(post_date)='" . $q['year'] . "'";
     893            $where .= " AND YEAR($wpdb->posts.post_date)='" . $q['year'] . "'";
    867894
    868895        if ( $q['monthnum'] )
    869             $where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'";
     896            $where .= " AND MONTH($wpdb->posts.post_date)='" . $q['monthnum'] . "'";
    870897
    871898        if ( $q['day'] )
    872             $where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'";
     899            $where .= " AND DAYOFMONTH($wpdb->posts.post_date)='" . $q['day'] . "'";
    873900
    874901        if ('' != $q['name']) {
    875902            $q['name'] = sanitize_title($q['name']);
    876             $where .= " AND post_name = '" . $q['name'] . "'";
     903            $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'";
    877904        } else if ('' != $q['pagename']) {
    878905            if ( isset($this->queried_object_id) )
     
    904931            $q['attachment'] = sanitize_title(basename($attach_paths));
    905932            $q['name'] = $q['attachment'];
    906             $where .= " AND post_name = '" . $q['attachment'] . "'";
     933            $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'";
    907934        }
    908935
    909936        if ( $q['w'] )
    910             $where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'";
     937            $where .= " AND WEEK($wpdb->posts.post_date, 1)='" . $q['w'] . "'";
    911938
    912939        if ( intval($q['comments_popup']) )
     
    942969            foreach((array)$q['search_terms'] as $term) {
    943970                $term = addslashes_gpc($term);
    944                 $search .= "{$searchand}((post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}'))";
     971                $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
    945972                $searchand = ' AND ';
    946973            }
    947974            $term = $wpdb->escape($q['s']);
    948975            if (!$q['sentence'] && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] )
    949                 $search .= " OR (post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}')";
     976                $search .= " OR ($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}')";
    950977
    951978            if ( !empty($search) )
     
    11131140        }
    11141141
     1142        // Taxonomies
     1143        if ( $this->is_tax ) {
     1144            $terms = get_terms($q['taxonomy'], array('slug'=>$q['term']));
     1145            foreach ( $terms as $term )
     1146                $term_ids[] = $term->term_id;
     1147            $post_ids = get_objects_in_term($term_ids, $q['taxonomy']);
     1148
     1149            if ( count($post_ids) ) {
     1150                $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") ";
     1151                $post_type = 'any';
     1152                $q['post_status'] = 'publish';
     1153                $post_status_join = true;
     1154            } else {
     1155                $whichcat = " AND 0 = 1";
     1156            }
     1157        }
     1158
    11151159        // Author/user stuff
    11161160
     
    11301174            }
    11311175            $author_array = preg_split('/[,\s]+/', $q['author']);
    1132             $whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]);
     1176            $whichauthor .= " AND ($wpdb->posts.post_author ".$eq.' '.intval($author_array[0]);
    11331177            for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
    1134                 $whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]);
     1178                $whichauthor .= ' '.$andor." $wpdb->posts.post_author ".$eq.' '.intval($author_array[$i]);
    11351179            }
    11361180            $whichauthor .= ')';
     
    11501194            $q['author_name'] = sanitize_title($q['author_name']);
    11511195            $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'");
    1152             $whichauthor .= ' AND (post_author = '.intval($q['author']).')';
     1196            $whichauthor .= " AND ($wpdb->posts.post_author = ".intval($q['author']).')';
    11531197        }
    11541198
     
    11651209        // Order by
    11661210        if ( empty($q['orderby']) ) {
    1167             $q['orderby'] = 'post_date '.$q['order'];
     1211            $q['orderby'] = "$wpdb->posts.post_date ".$q['order'];
    11681212        } else {
    11691213            // Used to filter values
     
    11811225                    case 'menu_order':
    11821226                    case 'ID':
     1227                        $orderby = "$wpdb->posts.ID";
    11831228                        break;
    11841229                    case 'rand':
     
    11861231                        break;
    11871232                    default:
    1188                         $orderby = 'post_' . $orderby;
     1233                        $orderby = "$wpdb->posts.post_" . $orderby;
    11891234                }
    11901235                if ( in_array($orderby_array[$i], $allowed_keys) )
     
    11961241
    11971242            if ( empty($q['orderby']) )
    1198                 $q['orderby'] = 'post_date '.$q['order'];
     1243                $q['orderby'] = "$wpdb->posts.post_date ".$q['order'];
    11991244        }
    12001245
    12011246        if ( $this->is_attachment ) {
    1202             $where .= " AND post_type = 'attachment'";
     1247            $where .= " AND $wpdb->posts.post_type = 'attachment'";
    12031248        } elseif ($this->is_page) {
    1204             $where .= " AND post_type = 'page'";
     1249            $where .= " AND $wpdb->posts.post_type = 'page'";
    12051250        } elseif ($this->is_single) {
    1206             $where .= " AND post_type = 'post'";
     1251            $where .= " AND $wpdb->posts.post_type = 'post'";
    12071252        } elseif ( 'any' == $post_type ) {
    12081253            $where .= '';
    12091254        } else {
    1210             $where .= " AND post_type = '$post_type'";
     1255            $where .= " AND $wpdb->posts.post_type = '$post_type'";
    12111256        }
    12121257
    12131258        if ( isset($q['post_status']) && '' != $q['post_status'] ) {
     1259            $statuswheres = array();
    12141260            $q_status = explode(',', $q['post_status']);
    12151261            $r_status = array();
    12161262            $p_status = array();
    12171263            if ( in_array( 'draft'  , $q_status ) )
    1218                 $r_status[] = "post_status = 'draft'";
     1264                $r_status[] = "$wpdb->posts.post_status = 'draft'";
    12191265            if ( in_array( 'pending', $q_status ) )
    1220                 $r_status[] = "post_status = 'pending'";
     1266                $r_status[] = "$wpdb->posts.post_status = 'pending'";
    12211267            if ( in_array( 'future' , $q_status ) )
    1222                 $r_status[] = "post_status = 'future'";
     1268                $r_status[] = "$wpdb->posts.post_status = 'future'";
    12231269            if ( in_array( 'inherit' , $q_status ) )
    1224                 $r_status[] = "post_status = 'inherit'";
     1270                $r_status[] = "$wpdb->posts.post_status = 'inherit'";
    12251271            if ( in_array( 'private', $q_status ) )
    1226                 $p_status[] = "post_status = 'private'";
     1272                $p_status[] = "$wpdb->posts.post_status = 'private'";
    12271273            if ( in_array( 'publish', $q_status ) )
    1228                 $r_status[] = "post_status = 'publish'";
     1274                $r_status[] = "$wpdb->posts.post_status = 'publish'";
    12291275
    12301276            if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) {
     
    12351281            if ( !empty($r_status) ) {
    12361282                if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can("edit_others_{$post_type}s") )
    1237                     $where .= " AND (post_author = $user_ID " .  "AND (" . join( ' OR ', $r_status ) . "))";
     1283                    $statuswheres[] = "($wpdb->posts.post_author = $user_ID " .  "AND (" . join( ' OR ', $r_status ) . "))";
    12381284                else
    1239                     $where .= " AND (" . join( ' OR ', $r_status ) . ")";
     1285                    $statuswheres[] = "(" . join( ' OR ', $r_status ) . ")";
    12401286            }
    12411287            if ( !empty($p_status) ) {
    12421288                if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can("read_private_{$post_type}s") )
    1243                     $where .= " AND (post_author = $user_ID " .  "AND (" . join( ' OR ', $p_status ) . "))";
     1289                    $statuswheres[] = "($wpdb->posts.post_author = $user_ID " .  "AND (" . join( ' OR ', $p_status ) . "))";
    12441290                else
    1245                     $where .= " AND (" . join( ' OR ', $p_status ) . ")";
    1246             }
     1291                    $statuswheres[] = "(" . join( ' OR ', $p_status ) . ")";
     1292            }
     1293            if ( $post_status_join ) {
     1294                $join .= " INNER JOIN $wpdb->posts AS p2 ON ($wpdb->posts.post_parent = p2.ID) ";
     1295                foreach ( $statuswheres as $index => $statuswhere )
     1296                    $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))";
     1297            }
     1298            foreach ( $statuswheres as $statuswhere )
     1299                $where .= " AND $statuswhere";
    12471300        } elseif ( !$this->is_singular ) {
    1248             $where .= " AND (post_status = 'publish'";
     1301            $where .= " AND ($wpdb->posts.post_status = 'publish'";
    12491302
    12501303            if ( is_admin() )
    1251                 $where .= " OR post_status = 'future' OR post_status = 'draft' OR post_status = 'pending'";
     1304                $where .= " OR $wpdb->posts.post_status = 'future' OR $wpdb->posts.post_status = 'draft' OR $wpdb->posts.post_status = 'pending'";
    12521305
    12531306            if ( is_user_logged_in() ) {
    1254                 $where .= current_user_can( "read_private_{$post_type}s" ) ? " OR post_status = 'private'" : " OR post_author = $user_ID AND post_status = 'private'";
     1307                $where .= current_user_can( "read_private_{$post_type}s" ) ? " OR $wpdb->posts.post_status = 'private'" : " OR $wpdb->posts.post_author = $user_ID AND $wpdb->posts.post_status = 'private'";
    12551308            }
    12561309
     
    15051558            $this->queried_object = &$tag;
    15061559            $this->queried_object_id = (int) $tag_id;
     1560        } else if ($this->is_tax) {
     1561            $tax = $this->get('taxonomy');
     1562            $slug = $this->get('term');
     1563            $term = &get_terms($tax, array('slug'=>$slug));
     1564            if ( is_wp_error($term) )
     1565                return $term;
     1566            $this->queried_object = $term;
     1567            $this->queried_object_id = $term->term_id;
    15071568        } else if ($this->is_posts_page) {
    15081569            $this->queried_object = & get_page(get_option('page_for_posts'));
  • trunk/wp-includes/rewrite.php

    r6964 r7491  
    831831        $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
    832832
     833        // Extra permastructs
     834        $extra_rewrite = array();
     835        foreach ( $this->extra_permastructs as $permastruct )
     836            $extra_rewrite = array_merge($extra_rewrite, $this->generate_rewrite_rules($permastruct, EP_NONE));
     837
    833838        // Put them together.
    834839        if ( $this->use_verbose_page_rules )
    835             $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);
     840            $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);
    836841        else
    837             $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);
     842            $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);
    838843
    839844        do_action_ref_array('generate_rewrite_rules', array(&$this));
     
    949954    }
    950955
     956    function add_permastruct($struct, $with_front = true) {
     957        if ( $with_front )
     958            $struct = $this->front . $struct;
     959        $this->extra_permastructs[] = $struct;
     960    }
     961
    951962    function flush_rules() {
    952963        delete_option('rewrite_rules');
  • trunk/wp-includes/taxonomy.php

    r7481 r7491  
    146146 */
    147147function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
    148     global $wp_taxonomies;
     148    global $wp_taxonomies, $wp_rewrite;
    149149
    150150    $defaults = array('hierarchical' => false, 'update_count_callback' => '');
    151151    $args = wp_parse_args($args, $defaults);
     152
     153    if ( !empty( $args['rewrite'] ) ) {
     154        if ( !is_array($args['rewrite']) )
     155            $args['rewrite'] = array();
     156        if ( !isset($args['rewrite']['slug']) )
     157            $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%");
     160    }
    152161
    153162    $args['name'] = $taxonomy;
  • trunk/wp-includes/template-loader.php

    r6483 r7491  
    2525        return;
    2626    } else if ( is_attachment() && $template = get_attachment_template() ) {
     27        remove_filter('the_content', 'prepend_attachment');
    2728        include($template);
    2829        return;
    2930    } else if ( is_single() && $template = get_single_template() ) {
    30         if ( is_attachment() )
    31             add_filter('the_content', 'prepend_attachment');
    3231        include($template);
    3332        return;
    3433    } else if ( is_page() && $template = get_page_template() ) {
    35         if ( is_attachment() )
    36             add_filter('the_content', 'prepend_attachment');
    3734        include($template);
    3835        return;
     
    4138        return;
    4239    } else if ( is_tag() && $template = get_tag_template()) {
     40        include($template);
     41        return;
     42    } else if ( is_tax() && $template = get_taxonomy_template()) {
    4343        include($template);
    4444        return;
     
    5959        return;
    6060    } else if ( file_exists(TEMPLATEPATH . "/index.php") ) {
    61         if ( is_attachment() )
    62             add_filter('the_content', 'prepend_attachment');
    6361        include(TEMPLATEPATH . "/index.php");
    6462        return;
  • trunk/wp-includes/theme.php

    r7224 r7491  
    382382}
    383383
     384function get_taxonomy_template() {
     385    $template = '';
     386    $taxonomy = get_query_var('taxonomy');
     387    $term = get_query_var('term');
     388    if ( $taxonomy && $term && file_exists(TEMPLATEPATH . "/taxonomy-$taxonomy-$term.php") )
     389        $template = TEMPLATEPATH . "/taxonomy-$taxonomy-$term.php";
     390    elseif ( $taxonomy && file_exists(TEMPLATEPATH . "/taxonomy-$taxonomy.php") )
     391        $template = TEMPLATEPATH . "/taxonomy-$taxonomy.php";
     392    elseif ( file_exists(TEMPLATEPATH . "/taxonomy.php") )
     393        $template = TEMPLATEPATH . "/taxonomy.php";
     394
     395    return apply_filters('taxonomy_template', $template);
     396}
    384397
    385398function get_date_template() {
Note: See TracChangeset for help on using the changeset viewer.