get_page_by_path. Some page uri cleanups.
git-svn-id: http://svn.automattic.com/wordpress/trunk@3511 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f812294867
commit
67968a6127
|
@ -367,23 +367,11 @@ class WP_Query {
|
||||||
$q['name'] = sanitize_title($q['name']);
|
$q['name'] = sanitize_title($q['name']);
|
||||||
$where .= " AND post_name = '" . $q['name'] . "'";
|
$where .= " AND post_name = '" . $q['name'] . "'";
|
||||||
} else if ('' != $q['pagename']) {
|
} else if ('' != $q['pagename']) {
|
||||||
|
$reqpage = get_page_by_path($q['pagename']);
|
||||||
$q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
|
$q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
|
||||||
$page_paths = '/' . trim($q['pagename'], '/');
|
$page_paths = '/' . trim($q['pagename'], '/');
|
||||||
$q['pagename'] = sanitize_title(basename($page_paths));
|
$q['pagename'] = sanitize_title(basename($page_paths));
|
||||||
$q['name'] = $q['pagename'];
|
$q['name'] = $q['pagename'];
|
||||||
$page_paths = explode('/', $page_paths);
|
|
||||||
foreach($page_paths as $pathdir)
|
|
||||||
$page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
|
|
||||||
|
|
||||||
$all_page_ids = get_all_page_ids();
|
|
||||||
$reqpage = 0;
|
|
||||||
if (is_array($all_page_ids)) { foreach ( $all_page_ids as $page_id ) {
|
|
||||||
$page = get_page($page_id);
|
|
||||||
if ( $page->fullpath == $page_path ) {
|
|
||||||
$reqpage = $page_id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} }
|
|
||||||
|
|
||||||
$where .= " AND (ID = '$reqpage')";
|
$where .= " AND (ID = '$reqpage')";
|
||||||
} elseif ('' != $q['attachment']) {
|
} elseif ('' != $q['attachment']) {
|
||||||
|
@ -1412,7 +1400,7 @@ class WP_Rewrite {
|
||||||
}
|
}
|
||||||
|
|
||||||
function flush_rules() {
|
function flush_rules() {
|
||||||
generate_page_rewrite_rules();
|
generate_page_uri_index();
|
||||||
delete_option('rewrite_rules');
|
delete_option('rewrite_rules');
|
||||||
$this->wp_rewrite_rules();
|
$this->wp_rewrite_rules();
|
||||||
if ( function_exists('save_mod_rewrite_rules') )
|
if ( function_exists('save_mod_rewrite_rules') )
|
||||||
|
|
|
@ -792,7 +792,7 @@ function get_page_hierarchy($posts, $parent = 0) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate_page_rewrite_rules() {
|
function generate_page_uri_index() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
//get pages in order of hierarchy, i.e. children after parents
|
//get pages in order of hierarchy, i.e. children after parents
|
||||||
|
@ -800,8 +800,8 @@ function generate_page_rewrite_rules() {
|
||||||
//now reverse it, because we need parents after children for rewrite rules to work properly
|
//now reverse it, because we need parents after children for rewrite rules to work properly
|
||||||
$posts = array_reverse($posts, true);
|
$posts = array_reverse($posts, true);
|
||||||
|
|
||||||
$page_rewrite_rules = array();
|
$page_uris = array();
|
||||||
$page_attachment_rewrite_rules = array();
|
$page_attachment_uris = array();
|
||||||
|
|
||||||
if ($posts) {
|
if ($posts) {
|
||||||
|
|
||||||
|
@ -813,17 +813,17 @@ function generate_page_rewrite_rules() {
|
||||||
if ( $attachments ) {
|
if ( $attachments ) {
|
||||||
foreach ( $attachments as $attachment ) {
|
foreach ( $attachments as $attachment ) {
|
||||||
$attach_uri = get_page_uri($attachment->ID);
|
$attach_uri = get_page_uri($attachment->ID);
|
||||||
$page_attachment_rewrite_rules[$attach_uri] = $attachment->post_name;
|
$page_attachment_uris[$attach_uri] = $attachment->ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$page_rewrite_rules[$uri] = $post;
|
$page_uris[$uri] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_option('page_uris', $page_rewrite_rules);
|
update_option('page_uris', $page_uris);
|
||||||
|
|
||||||
if ( $page_attachment_rewrite_rules )
|
if ( $page_attachment_uris )
|
||||||
update_option('page_attachment_uris', $page_attachment_rewrite_rules);
|
update_option('page_attachment_uris', $page_attachment_uris);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -665,6 +665,36 @@ function set_page_path($page) {
|
||||||
return $page;
|
return $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_page_by_path($page_path) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$page_path = str_replace('%2F', '/', urlencode(urldecode($page_path)));
|
||||||
|
$page_paths = '/' . trim($page_path, '/');
|
||||||
|
$leaf_path = sanitize_title(basename($page_paths));
|
||||||
|
$page_paths = explode('/', $page_paths);
|
||||||
|
foreach($page_paths as $pathdir)
|
||||||
|
$full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
|
||||||
|
|
||||||
|
$pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = '$leaf_path'");
|
||||||
|
|
||||||
|
if ( empty($pages) )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$path = '/' . $leaf_path;
|
||||||
|
$curpage = $page;
|
||||||
|
while ($curpage->post_parent != 0) {
|
||||||
|
$curpage = $wpdb->get_row("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = '$curpage->post_parent'");
|
||||||
|
$path = '/' . $curpage->post_name . $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $path == $full_path )
|
||||||
|
return $page->ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieves page data given a page ID or page object.
|
// Retrieves page data given a page ID or page object.
|
||||||
// Handles page caching.
|
// Handles page caching.
|
||||||
function &get_page(&$page, $output = OBJECT) {
|
function &get_page(&$page, $output = OBJECT) {
|
||||||
|
|
Loading…
Reference in New Issue