Make WordPress Core


Ignore:
Timestamp:
12/04/2007 12:19:10 AM (19 years ago)
Author:
ryan
Message:

Don't save page and attachemtn uris to page_uris and page_attachment_uris. This is not needed. Add an option to use wildcard page rewrite rules instead of per-page rules. see #3614

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/rewrite.php

    r5959 r6351  
    186186        var $endpoints;
    187187        var $use_verbose_rules = false;
     188        var $use_verbose_page_rules = true;
    188189        var $rewritecode =
    189190                array(
     
    278279        }
    279280
     281        function page_uri_index() {
     282                global $wpdb;
     283
     284                //get pages in order of hierarchy, i.e. children after parents
     285                $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'"));
     286                //now reverse it, because we need parents after children for rewrite rules to work properly
     287                $posts = array_reverse($posts, true);
     288
     289                $page_uris = array();
     290                $page_attachment_uris = array();
     291
     292                if ( !$posts )
     293                        return array( array(), array() );
     294       
     295
     296                foreach ($posts as $id => $post) {
     297                        // URL => page name
     298                        $uri = get_page_uri($id);
     299                        $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ));
     300                        if ( $attachments ) {
     301                                foreach ( $attachments as $attachment ) {
     302                                        $attach_uri = get_page_uri($attachment->ID);
     303                                        $page_attachment_uris[$attach_uri] = $attachment->ID;
     304                                }
     305                        }
     306
     307                        $page_uris[$uri] = $id;
     308                }
     309
     310                return array( $page_uris, $page_attachment_uris );
     311        }
     312
    280313        function page_rewrite_rules() {
    281                 $uris = get_option('page_uris');
    282                 $attachment_uris = get_option('page_attachment_uris');
     314                global $wpdb;
    283315
    284316                $rewrite_rules = array();
    285317                $page_structure = $this->get_page_permastruct();
     318
     319                if ( ! $this->use_verbose_page_rules ) {
     320                        $this->add_rewrite_tag('%pagename%', "(.+)", 'pagename=');
     321                        $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
     322                        return $rewrite_rules;
     323                }
     324
     325                $page_uris = $this->page_uri_index();
     326                $uris = $page_uris[0];
     327                $attachment_uris = $page_uris[1];
     328
     329
    286330                if( is_array( $attachment_uris ) ) {
    287331                        foreach ($attachment_uris as $uri => $pagename) {
     
    786830
    787831                // Put them together.
    788                 $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);
     832                if ( $this->use_verbose_page_rules )
     833                        $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);
     834                else
     835                        $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);
    789836
    790837                do_action_ref_array('generate_rewrite_rules', array(&$this));
     
    901948
    902949        function flush_rules() {
    903                 generate_page_uri_index();
    904950                delete_option('rewrite_rules');
    905951                $this->wp_rewrite_rules();
Note: See TracChangeset for help on using the changeset viewer.