Make WordPress Core

Changeset 3511


Ignore:
Timestamp:
02/10/2006 12:54:16 AM (21 years ago)
Author:
ryan
Message:

get_page_by_path. Some page uri cleanups.

Location:
trunk/wp-includes
Files:
3 edited

Legend:

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

    r3510 r3511  
    368368                        $where .= " AND post_name = '" . $q['name'] . "'";
    369369                } else if ('' != $q['pagename']) {
     370                        $reqpage = get_page_by_path($q['pagename']);
    370371                        $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
    371372                        $page_paths = '/' . trim($q['pagename'], '/');
    372373                        $q['pagename'] = sanitize_title(basename($page_paths));
    373374                        $q['name'] = $q['pagename'];
    374                         $page_paths = explode('/', $page_paths);
    375                         foreach($page_paths as $pathdir)
    376                                 $page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
    377                                
    378                         $all_page_ids = get_all_page_ids();
    379                         $reqpage = 0;
    380                         if (is_array($all_page_ids)) { foreach ( $all_page_ids as $page_id ) {
    381                                 $page = get_page($page_id);
    382                                 if ( $page->fullpath == $page_path ) {
    383                                         $reqpage = $page_id;
    384                                         break;
    385                                 }
    386                         } }
    387375                       
    388376                        $where .= " AND (ID = '$reqpage')";
     
    14131401
    14141402        function flush_rules() {
    1415                 generate_page_rewrite_rules();
     1403                generate_page_uri_index();
    14161404                delete_option('rewrite_rules');
    14171405                $this->wp_rewrite_rules();
  • trunk/wp-includes/functions-post.php

    r3510 r3511  
    793793}
    794794
    795 function generate_page_rewrite_rules() {
     795function generate_page_uri_index() {
    796796        global $wpdb;
    797797       
     
    801801        $posts = array_reverse($posts, true);
    802802
    803         $page_rewrite_rules = array();
    804         $page_attachment_rewrite_rules = array();
     803        $page_uris = array();
     804        $page_attachment_uris = array();
    805805
    806806        if ($posts) {
     
    814814                                foreach ( $attachments as $attachment ) {
    815815                                        $attach_uri = get_page_uri($attachment->ID);
    816                                         $page_attachment_rewrite_rules[$attach_uri] = $attachment->post_name;
     816                                        $page_attachment_uris[$attach_uri] = $attachment->ID;
    817817                                }
    818818                        }
    819819
    820                         $page_rewrite_rules[$uri] = $post;
    821                 }
    822 
    823                 update_option('page_uris', $page_rewrite_rules);
     820                        $page_uris[$uri] = $id;
     821                }
     822
     823                update_option('page_uris', $page_uris);
    824824               
    825                 if ( $page_attachment_rewrite_rules )
    826                         update_option('page_attachment_uris', $page_attachment_rewrite_rules);
     825                if ( $page_attachment_uris )
     826                        update_option('page_attachment_uris', $page_attachment_uris);
    827827        }
    828828}
  • trunk/wp-includes/functions.php

    r3510 r3511  
    664664
    665665        return $page;
     666}
     667
     668function get_page_by_path($page_path) {
     669        global $wpdb;
     670
     671        $page_path = str_replace('%2F', '/', urlencode(urldecode($page_path)));
     672        $page_paths = '/' . trim($page_path, '/');
     673        $leaf_path  = sanitize_title(basename($page_paths));
     674        $page_paths = explode('/', $page_paths);
     675        foreach($page_paths as $pathdir)
     676                $full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
     677
     678        $pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = '$leaf_path'");
     679
     680        if ( empty($pages) )
     681                return 0;
     682
     683        foreach ($pages as $page) {
     684                $path = '/' . $leaf_path;
     685                $curpage = $page;
     686                while ($curpage->post_parent != 0) {
     687                        $curpage = $wpdb->get_row("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = '$curpage->post_parent'");
     688                        $path = '/' . $curpage->post_name . $path;
     689                }
     690
     691                if ( $path == $full_path )
     692                        return $page->ID;
     693        }
     694
     695        return 0;
    666696}
    667697
Note: See TracChangeset for help on using the changeset viewer.