Make WordPress Core

Changeset 1752


Ignore:
Timestamp:
10/06/2004 02:18:37 AM (20 years ago)
Author:
rboren
Message:

Page/subpage URIs.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r1747 r1752  
    486486}
    487487
     488function save_mod_rewrite_rules() {
     489    global $is_apache;
     490    $home = get_settings('home');
     491    if ( $home != '' && $home != get_settings('siteurl') ) {
     492        $home_path = parse_url($home);
     493        $home_path = $home_root['path'];
     494        $root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["PATH_TRANSLATED"]);
     495        $home_path = $root . $home_path . "/";
     496    } else {
     497        $home_path = ABSPATH;
     498    }
     499
     500    if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') )
     501        $writable = true;
     502    else
     503        $writable = false;
     504
     505    $permalink_structure = get_settings('permalink_structure');
     506
     507    if ( strstr($permalink_structure, 'index.php') ) // If they're using
     508        $usingpi = true;
     509    else
     510        $usingpi = false;
     511
     512    if ( $writable && !$usingpi && $is_apache ) {
     513        $rules = explode("\n", mod_rewrite_rules($permalink_structure));
     514        insert_with_markers($home_path.'.htaccess', 'WordPress', $rules);
     515    }
     516}
     517
     518function generate_page_rewrite_rules() {
     519    global $wpdb;
     520    $posts = $wpdb->get_results("SELECT ID, post_name FROM $wpdb->posts WHERE post_status = 'static'");
     521
     522    $page_rewrite_rules = array();
     523
     524    foreach ($posts as $post) {
     525        // URI => page name
     526        $uri = get_page_uri($post->ID);
     527
     528        $page_rewrite_rules[$uri] = $post->post_name;
     529    }
     530
     531    update_option('page_uris', $page_rewrite_rules);
     532
     533    save_mod_rewrite_rules();
     534}
     535
    488536function the_quicktags () {
    489537// Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP
     
    708756}
    709757
    710 function parent_dropdown($parent = 0, $level = 0) {
     758function parent_dropdown($default = 0, $parent = 0, $level = 0) {
    711759    global $wpdb;
    712760    $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");
     
    714762        foreach ($items as $item) {
    715763            $pad = str_repeat(' ', $level * 3);
    716             if ($item->ID == $current)
     764            if ($item->ID == $default)
    717765                $current = ' selected="selected"';
    718766            else
     
    720768
    721769            echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</a></option>";
    722                 parent_dropdown($item->ID, $level + 1);
     770            parent_dropdown($default, $item->ID, $level + 1);
    723771        }
    724772    } else {
  • trunk/wp-admin/edit-page-form.php

    r1747 r1752  
    5353      <div><select name="parent_id">
    5454        <option value='0'>Main Page (no parent)</option>
    55             <?php parent_dropdown(); ?>
     55            <?php parent_dropdown($post_parent); ?>
    5656        </select>
    5757      </div>
  • trunk/wp-admin/edit-pages.php

    r1747 r1752  
    6868    $ping_status = get_settings('default_ping_status');
    6969    $post_pingback = get_settings('default_pingback_flag');
     70    $post_parent = 0;
    7071
    7172    include('edit-page-form.php');
  • trunk/wp-admin/options-permalink.php

    r1689 r1752  
    3232}
    3333
     34generate_page_rewrite_rules();
     35
    3436if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') )
    3537    $writable = true;
     
    4244    $usingpi = false;
    4345
    44 if ( $writable && !$usingpi && $is_apache ) {
    45     $rules = explode("\n", mod_rewrite_rules($permalink_structure));
    46     insert_with_markers($home_path.'.htaccess', 'WordPress', $rules);
    47 }
     46save_mod_rewrite_rules();
    4847?>
    4948
  • trunk/wp-admin/post.php

    r1751 r1752  
    5757        $post_status = $_POST['post_status'];
    5858        $post_name = $_POST['post_name'];
     59        $post_parent = 0;
     60        if (isset($_POST['parent_id'])) {
     61            $post_parent = $_POST['parent_id'];
     62        }
    5963
    6064        if (empty($post_status)) $post_status = 'draft';
     
    109113
    110114    $postquery ="INSERT INTO $wpdb->posts
    111             (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)
     115            (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)
    112116            VALUES
    113             ('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt')
     117            ('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')
    114118            ";
    115119
     
    195199    } // end if publish
    196200
     201    if ($post_status = 'static') {
     202        generate_page_rewrite_rules();
     203    }
     204
    197205    exit();
    198206    break;
     
    223231        $pinged = $postdata->pinged;
    224232        $post_name = $postdata->post_name;
    225 
    226         if ($post_status == 'static') {
    227             include('edit-page-form.php');
    228         } else {
    229             include('edit-form-advanced.php');
    230         }
     233        $post_parent = $postdata->post_parent;
     234
     235        if ($post_status == 'static') {
     236            include('edit-page-form.php');
     237        } else {
     238            include('edit-form-advanced.php');
     239        }
    231240
    232241        $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = '$post_ID'");
     
    287296        if (empty($post_name)) {
    288297          $post_name = $post_title;
     298        }
     299
     300        $post_parent = 0;
     301        if (isset($_POST['parent_id'])) {
     302            $post_parent = $_POST['parent_id'];
    289303        }
    290304
     
    354368            to_ping = '$trackback',
    355369            post_modified = '$now',
    356             post_modified_gmt = '$now_gmt'
     370            post_modified_gmt = '$now_gmt',
     371      post_parent = '$post_parent'
    357372        WHERE ID = $post_ID ");
    358373
     
    421436        }
    422437    } // end if publish
     438
     439    if ($post_status = 'static') {
     440        generate_page_rewrite_rules();
     441    }
    423442
    424443    do_action('edit_post', $post_ID);
  • trunk/wp-admin/upgrade-schema.php

    r1749 r1752  
    212212    add_option('stylesheet', 'default');
    213213    add_option('comment_whitelist', 0);
     214    add_option('page_uris');
    214215
    215216    // Delete unused options
  • trunk/wp-includes/functions.php

    r1746 r1752  
    12161216}
    12171217
     1218function get_page_uri($page) {
     1219    global $wpdb;
     1220    $page = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$page'");
     1221
     1222    $uri = $page->post_name;
     1223
     1224    while ($page->post_parent != 0) {
     1225        $page = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$page->post_parent'");
     1226        $uri = $page->post_name . "/" . $uri;
     1227    }
     1228
     1229    return $uri;
     1230}
     1231
     1232function page_rewrite_rules() {
     1233    $uris = get_settings('page_uris');
     1234
     1235    $rewrite_rules = array();
     1236    foreach ($uris as $uri => $pagename) {
     1237        $rewrite_rules += array($uri . '/?$' => "index.php?pagename=$pagename");
     1238    }
     1239
     1240    return $rewrite_rules;
     1241}
     1242
    12181243function generate_rewrite_rules($permalink_structure = '', $matches = '') {
    12191244    $rewritecode =
     
    14101435    $page_rewrite = generate_rewrite_rules($page_structure, $matches);
    14111436
     1437        // Pages
     1438        $pages_rewrite = page_rewrite_rules();
     1439
    14121440    // Put them together.
    1413     $rewrite = $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite;
     1441    $rewrite = $pages_rewrite + $site_rewrite + $page_rewrite + $search_rewrite + $category_rewrite + $author_rewrite;
    14141442
    14151443    // Add on archive rewrite rules if needed.
  • trunk/wp-includes/template-functions-links.php

    r1695 r1752  
    5050    }
    5151
     52    if ($idpost->post_status == 'static') {
     53        return get_page_link();
     54    }
     55   
    5256    $permalink = get_settings('permalink_structure');
    5357
    5458    if ('' != $permalink) {
    55         if ($idpost->post_status == 'static')
    56             $permalink = page_permastruct();
    57 
    5859        $unixtime = strtotime($idpost->post_date);
    5960
     
    7980    } else { // if they're not using the fancy permalink option
    8081        $permalink = get_settings('home') . '/' . get_settings('blogfilename') . '?p=' . $idpost->ID;
    81         if ($idpost->post_status == 'static')
    82             $permalink .=  '&static=1';
    8382        return $permalink;
    8483    }
     84}
     85
     86function get_page_link($id = false) {
     87    global $post;
     88
     89    if (! $id) {
     90        $id = $post->ID;
     91    }
     92
     93    $permalink = get_settings('permalink_structure');
     94
     95    if ('' != $permalink) {
     96        $link = get_page_uri($id);
     97        $link = get_settings('home') . "/$link/";
     98    } else {
     99        $link = get_settings('home') . "/index.php?p=$id&static=1";
     100    }
     101
     102    return $link;
    85103}
    86104
Note: See TracChangeset for help on using the changeset viewer.