diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 61d68c327..45f821cf9 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -485,6 +485,54 @@ function extract_from_markers($filename, $marker) { 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 () { // 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') ) : @@ -707,19 +755,19 @@ function validate_current_theme() { return true; } -function parent_dropdown($parent = 0, $level = 0) { +function parent_dropdown($default = 0, $parent = 0, $level = 0) { 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"); if ($items) { foreach ($items as $item) { $pad = str_repeat(' ', $level * 3); - if ($item->ID == $current) + if ($item->ID == $default) $current = ' selected="selected"'; else $current = ''; echo "\n\t"; - parent_dropdown($item->ID, $level + 1); + parent_dropdown($default, $item->ID, $level + 1); } } else { return false; diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php index bfc5f71e2..a94f8afe8 100644 --- a/wp-admin/edit-page-form.php +++ b/wp-admin/edit-page-form.php @@ -52,7 +52,7 @@ window.onload = focusit;
diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php index d69da60c1..8dc093112 100644 --- a/wp-admin/edit-pages.php +++ b/wp-admin/edit-pages.php @@ -67,6 +67,7 @@ if ($user_level > 0) { $comment_status = get_settings('default_comment_status'); $ping_status = get_settings('default_ping_status'); $post_pingback = get_settings('default_pingback_flag'); + $post_parent = 0; include('edit-page-form.php'); } diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php index 1288b26fd..9a146ba9a 100644 --- a/wp-admin/options-permalink.php +++ b/wp-admin/options-permalink.php @@ -31,6 +31,8 @@ if (isset($_POST['submit'])) { $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') ) $writable = true; else @@ -41,10 +43,7 @@ if ( strstr($permalink_structure, 'index.php') ) // If they're using else $usingpi = false; -if ( $writable && !$usingpi && $is_apache ) { - $rules = explode("\n", mod_rewrite_rules($permalink_structure)); - insert_with_markers($home_path.'.htaccess', 'WordPress', $rules); -} +save_mod_rewrite_rules(); ?> diff --git a/wp-admin/post.php b/wp-admin/post.php index c0eece3b1..aa5b217a9 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -56,6 +56,10 @@ case 'post': $post_categories = $_POST['post_category']; $post_status = $_POST['post_status']; $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'; // Double-check @@ -108,9 +112,9 @@ case 'post': if ('' != $_POST['savepage']) $post_status = 'static'; $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 - ('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); @@ -194,6 +198,10 @@ case 'post': } // end if publish + if ($post_status = 'static') { + generate_page_rewrite_rules(); + } + exit(); break; @@ -222,12 +230,13 @@ case 'edit': $to_ping = $postdata->to_ping; $pinged = $postdata->pinged; $post_name = $postdata->post_name; + $post_parent = $postdata->post_parent; - if ($post_status == 'static') { - include('edit-page-form.php'); - } else { - include('edit-form-advanced.php'); - } + if ($post_status == 'static') { + include('edit-page-form.php'); + } else { + include('edit-form-advanced.php'); + } $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = '$post_ID'"); ?> @@ -288,6 +297,11 @@ case 'editpost': $post_name = $post_title; } + $post_parent = 0; + if (isset($_POST['parent_id'])) { + $post_parent = $_POST['parent_id']; + } + if (empty($post_name)) { if (! empty($post_title)) { $post_name = sanitize_title($post_title, $post_ID); @@ -353,7 +367,8 @@ $now_gmt = current_time('mysql', 1); post_name = '$post_name', to_ping = '$trackback', post_modified = '$now', - post_modified_gmt = '$now_gmt' + post_modified_gmt = '$now_gmt', + post_parent = '$post_parent' WHERE ID = $post_ID "); // Meta Stuff @@ -421,6 +436,10 @@ $now_gmt = current_time('mysql', 1); } } // end if publish + if ($post_status = 'static') { + generate_page_rewrite_rules(); + } + do_action('edit_post', $post_ID); exit(); break; diff --git a/wp-admin/upgrade-schema.php b/wp-admin/upgrade-schema.php index 6985567f3..72a3afbb8 100644 --- a/wp-admin/upgrade-schema.php +++ b/wp-admin/upgrade-schema.php @@ -211,6 +211,7 @@ function populate_options() { add_option('template', 'default'); add_option('stylesheet', 'default'); add_option('comment_whitelist', 0); + add_option('page_uris'); // 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'); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 0af58c2b8..0cfa04061 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1215,6 +1215,31 @@ function page_permastruct() { 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 = '') { $rewritecode = array( @@ -1409,8 +1434,11 @@ function rewrite_rules($matches = '', $permalink_structure = '') { $page_structure = $prefix . 'site/%pagename%'; $page_rewrite = generate_rewrite_rules($page_structure, $matches); + // Pages + $pages_rewrite = page_rewrite_rules(); + // 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. if ($doarchive) { diff --git a/wp-includes/template-functions-links.php b/wp-includes/template-functions-links.php index 144ce3c49..7f54b48eb 100644 --- a/wp-includes/template-functions-links.php +++ b/wp-includes/template-functions-links.php @@ -49,12 +49,13 @@ function get_permalink($id = false) { $idpost = $post; } + if ($idpost->post_status == 'static') { + return get_page_link(); + } + $permalink = get_settings('permalink_structure'); if ('' != $permalink) { - if ($idpost->post_status == 'static') - $permalink = page_permastruct(); - $unixtime = strtotime($idpost->post_date); $cats = get_the_category($idpost->ID); @@ -78,12 +79,29 @@ function get_permalink($id = false) { return get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink); } else { // if they're not using the fancy permalink option $permalink = get_settings('home') . '/' . get_settings('blogfilename') . '?p=' . $idpost->ID; - if ($idpost->post_status == 'static') - $permalink .= '&static=1'; 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) { global $querystring_start, $querystring_equal; if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));