Page/subpage URIs.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1752 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-10-06 02:18:37 +00:00
parent c1f391ae7e
commit 96a0b41202
8 changed files with 136 additions and 22 deletions

View File

@ -485,6 +485,54 @@ function extract_from_markers($filename, $marker) {
return $result; return $result;
} }
function save_mod_rewrite_rules() {
global $is_apache;
$home = get_settings('home');
if ( $home != '' && $home != get_settings('siteurl') ) {
$home_path = parse_url($home);
$home_path = $home_root['path'];
$root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["PATH_TRANSLATED"]);
$home_path = $root . $home_path . "/";
} else {
$home_path = ABSPATH;
}
if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') )
$writable = true;
else
$writable = false;
$permalink_structure = get_settings('permalink_structure');
if ( strstr($permalink_structure, 'index.php') ) // If they're using
$usingpi = true;
else
$usingpi = false;
if ( $writable && !$usingpi && $is_apache ) {
$rules = explode("\n", mod_rewrite_rules($permalink_structure));
insert_with_markers($home_path.'.htaccess', 'WordPress', $rules);
}
}
function generate_page_rewrite_rules() {
global $wpdb;
$posts = $wpdb->get_results("SELECT ID, post_name FROM $wpdb->posts WHERE post_status = 'static'");
$page_rewrite_rules = array();
foreach ($posts as $post) {
// URI => page name
$uri = get_page_uri($post->ID);
$page_rewrite_rules[$uri] = $post->post_name;
}
update_option('page_uris', $page_rewrite_rules);
save_mod_rewrite_rules();
}
function the_quicktags () { function the_quicktags () {
// Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP // Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP
if ( !strstr($_SERVER['HTTP_USER_AGENT'], 'Safari') ) : if ( !strstr($_SERVER['HTTP_USER_AGENT'], 'Safari') ) :
@ -707,19 +755,19 @@ function validate_current_theme() {
return true; return true;
} }
function parent_dropdown($parent = 0, $level = 0) { function parent_dropdown($default = 0, $parent = 0, $level = 0) {
global $wpdb; global $wpdb;
$items = $wpdb->get_results("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_status = 'static' ORDER BY menu_order"); $items = $wpdb->get_results("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_status = 'static' ORDER BY menu_order");
if ($items) { if ($items) {
foreach ($items as $item) { foreach ($items as $item) {
$pad = str_repeat(' ', $level * 3); $pad = str_repeat(' ', $level * 3);
if ($item->ID == $current) if ($item->ID == $default)
$current = ' selected="selected"'; $current = ' selected="selected"';
else else
$current = ''; $current = '';
echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</a></option>"; echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</a></option>";
parent_dropdown($item->ID, $level + 1); parent_dropdown($default, $item->ID, $level + 1);
} }
} else { } else {
return false; return false;

View File

@ -52,7 +52,7 @@ window.onload = focusit;
<legend><?php _e('Page Parent') ?></a></legend> <legend><?php _e('Page Parent') ?></a></legend>
<div><select name="parent_id"> <div><select name="parent_id">
<option value='0'>Main Page (no parent)</option> <option value='0'>Main Page (no parent)</option>
<?php parent_dropdown(); ?> <?php parent_dropdown($post_parent); ?>
</select> </select>
</div> </div>
</fieldset> </fieldset>

View File

@ -67,6 +67,7 @@ if ($user_level > 0) {
$comment_status = get_settings('default_comment_status'); $comment_status = get_settings('default_comment_status');
$ping_status = get_settings('default_ping_status'); $ping_status = get_settings('default_ping_status');
$post_pingback = get_settings('default_pingback_flag'); $post_pingback = get_settings('default_pingback_flag');
$post_parent = 0;
include('edit-page-form.php'); include('edit-page-form.php');
} }

View File

@ -31,6 +31,8 @@ if (isset($_POST['submit'])) {
$category_base = get_settings('category_base'); $category_base = get_settings('category_base');
} }
generate_page_rewrite_rules();
if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') ) if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') )
$writable = true; $writable = true;
else else
@ -41,10 +43,7 @@ if ( strstr($permalink_structure, 'index.php') ) // If they're using
else else
$usingpi = false; $usingpi = false;
if ( $writable && !$usingpi && $is_apache ) { save_mod_rewrite_rules();
$rules = explode("\n", mod_rewrite_rules($permalink_structure));
insert_with_markers($home_path.'.htaccess', 'WordPress', $rules);
}
?> ?>
<?php if (isset($_POST['submit'])) : ?> <?php if (isset($_POST['submit'])) : ?>

View File

@ -56,6 +56,10 @@ case 'post':
$post_categories = $_POST['post_category']; $post_categories = $_POST['post_category'];
$post_status = $_POST['post_status']; $post_status = $_POST['post_status'];
$post_name = $_POST['post_name']; $post_name = $_POST['post_name'];
$post_parent = 0;
if (isset($_POST['parent_id'])) {
$post_parent = $_POST['parent_id'];
}
if (empty($post_status)) $post_status = 'draft'; if (empty($post_status)) $post_status = 'draft';
// Double-check // Double-check
@ -108,9 +112,9 @@ case 'post':
if ('' != $_POST['savepage']) $post_status = 'static'; if ('' != $_POST['savepage']) $post_status = 'static';
$postquery ="INSERT INTO $wpdb->posts $postquery ="INSERT INTO $wpdb->posts
(ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt) (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent)
VALUES VALUES
('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt') ('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt', '$post_parent')
"; ";
$result = $wpdb->query($postquery); $result = $wpdb->query($postquery);
@ -194,6 +198,10 @@ case 'post':
} // end if publish } // end if publish
if ($post_status = 'static') {
generate_page_rewrite_rules();
}
exit(); exit();
break; break;
@ -222,6 +230,7 @@ case 'edit':
$to_ping = $postdata->to_ping; $to_ping = $postdata->to_ping;
$pinged = $postdata->pinged; $pinged = $postdata->pinged;
$post_name = $postdata->post_name; $post_name = $postdata->post_name;
$post_parent = $postdata->post_parent;
if ($post_status == 'static') { if ($post_status == 'static') {
include('edit-page-form.php'); include('edit-page-form.php');
@ -288,6 +297,11 @@ case 'editpost':
$post_name = $post_title; $post_name = $post_title;
} }
$post_parent = 0;
if (isset($_POST['parent_id'])) {
$post_parent = $_POST['parent_id'];
}
if (empty($post_name)) { if (empty($post_name)) {
if (! empty($post_title)) { if (! empty($post_title)) {
$post_name = sanitize_title($post_title, $post_ID); $post_name = sanitize_title($post_title, $post_ID);
@ -353,7 +367,8 @@ $now_gmt = current_time('mysql', 1);
post_name = '$post_name', post_name = '$post_name',
to_ping = '$trackback', to_ping = '$trackback',
post_modified = '$now', post_modified = '$now',
post_modified_gmt = '$now_gmt' post_modified_gmt = '$now_gmt',
post_parent = '$post_parent'
WHERE ID = $post_ID "); WHERE ID = $post_ID ");
// Meta Stuff // Meta Stuff
@ -421,6 +436,10 @@ $now_gmt = current_time('mysql', 1);
} }
} // end if publish } // end if publish
if ($post_status = 'static') {
generate_page_rewrite_rules();
}
do_action('edit_post', $post_ID); do_action('edit_post', $post_ID);
exit(); exit();
break; break;

View File

@ -211,6 +211,7 @@ function populate_options() {
add_option('template', 'default'); add_option('template', 'default');
add_option('stylesheet', 'default'); add_option('stylesheet', 'default');
add_option('comment_whitelist', 0); add_option('comment_whitelist', 0);
add_option('page_uris');
// Delete unused options // Delete unused options
$unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'rss_language', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl'); $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'rss_language', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl');

View File

@ -1215,6 +1215,31 @@ function page_permastruct() {
return '/' . $prefix . 'site/%pagename%'; return '/' . $prefix . 'site/%pagename%';
} }
function get_page_uri($page) {
global $wpdb;
$page = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$page'");
$uri = $page->post_name;
while ($page->post_parent != 0) {
$page = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$page->post_parent'");
$uri = $page->post_name . "/" . $uri;
}
return $uri;
}
function page_rewrite_rules() {
$uris = get_settings('page_uris');
$rewrite_rules = array();
foreach ($uris as $uri => $pagename) {
$rewrite_rules += array($uri . '/?$' => "index.php?pagename=$pagename");
}
return $rewrite_rules;
}
function generate_rewrite_rules($permalink_structure = '', $matches = '') { function generate_rewrite_rules($permalink_structure = '', $matches = '') {
$rewritecode = $rewritecode =
array( array(
@ -1409,8 +1434,11 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
$page_structure = $prefix . 'site/%pagename%'; $page_structure = $prefix . 'site/%pagename%';
$page_rewrite = generate_rewrite_rules($page_structure, $matches); $page_rewrite = generate_rewrite_rules($page_structure, $matches);
// Pages
$pages_rewrite = page_rewrite_rules();
// Put them together. // Put them together.
$rewrite = $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite; $rewrite = $pages_rewrite + $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite;
// Add on archive rewrite rules if needed. // Add on archive rewrite rules if needed.
if ($doarchive) { if ($doarchive) {

View File

@ -49,12 +49,13 @@ function get_permalink($id = false) {
$idpost = $post; $idpost = $post;
} }
if ($idpost->post_status == 'static') {
return get_page_link();
}
$permalink = get_settings('permalink_structure'); $permalink = get_settings('permalink_structure');
if ('' != $permalink) { if ('' != $permalink) {
if ($idpost->post_status == 'static')
$permalink = page_permastruct();
$unixtime = strtotime($idpost->post_date); $unixtime = strtotime($idpost->post_date);
$cats = get_the_category($idpost->ID); $cats = get_the_category($idpost->ID);
@ -78,12 +79,29 @@ function get_permalink($id = false) {
return get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink); return get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink);
} else { // if they're not using the fancy permalink option } else { // if they're not using the fancy permalink option
$permalink = get_settings('home') . '/' . get_settings('blogfilename') . '?p=' . $idpost->ID; $permalink = get_settings('home') . '/' . get_settings('blogfilename') . '?p=' . $idpost->ID;
if ($idpost->post_status == 'static')
$permalink .= '&static=1';
return $permalink; return $permalink;
} }
} }
function get_page_link($id = false) {
global $post;
if (! $id) {
$id = $post->ID;
}
$permalink = get_settings('permalink_structure');
if ('' != $permalink) {
$link = get_page_uri($id);
$link = get_settings('home') . "/$link/";
} else {
$link = get_settings('home') . "/index.php?p=$id&static=1";
}
return $link;
}
function get_month_link($year, $month) { function get_month_link($year, $month) {
global $querystring_start, $querystring_equal; global $querystring_start, $querystring_equal;
if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600)); if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));