Spec: SEO friendly URLs + subpages [4.7]

  • Drafter: Sander Thijsen
  • Version 1, March 6 2009
  • Status: implemented, but not using this draft.

Introduction

Currently, pluck pages are stored as "kop1.php", "kop2.php", "kop3.php", etc. Because of this, implementing SEO friendly URLs is almost imposible.

Pluck will have to save pages with their title as filename (for example home.php, contact.php or about-us.php), and create a cache-file that defines the order of the pages. Then, implementing SEO friendly URLs shouldn't be difficult.

The new blog module in pluck 4.6 will also contain this approach, so we can use large parts code when this module is finished (see blueprint new-blog-module). Sander Thijsen: this is not the case, because we also need to implement sub pages support.

While we're busy reorganizing the page system, we can also implement sub pages.

The blueprint of this spec is located at Launchpad. There, you can also track the progress of implementation.

Specification

This is a first rough concept of what could become the new page ordering system. In short, the proposal can be summarized as follows:

  • Pages will all be saved in data/settings/pages, as done also in 4.6.
  • Pages will be named after their title. For example, a page with title "Nice page" will have filename "nice-page.php".
  • The order and hierarchy of pages is stored in a XML-file. This file will contain also the title and filenames of the pages.

The page index file (XML)

As noted before, this file will contain the order of the pages, and also will define the hierarchy of those pages. The file will also contain the filename of the page and the title. The latter should be included, because then we don't need to include all pages when generating a menu, like we are doing now. The only file we then need to access to generate a menu, is the XML-file.

Why XML? Because XML is easy to read, easy to understand and easily convertable to and from a PHP-array.

An XML-file could look this:

<?xml version="1.0" encoding="UTF-8"?>
<pages>
<page>
    <name>Homepage</name>
    <filename>homepage.php</filename>
    <page>
        <name>Subpage 1</name>
        <filename>subpage-1.php</filename>
    </page>
    <page>
        <name>Subpage 2</name>
        <filename>subpage-2.php</filename>
        <page>
            <name>Subpage 2-1</name>
             <filename>subpage-2-1.php</filename>
        </page>
    </page>
</page>
<page>
    <name>Another page</name>
    <filename>another-page.php</filename>
</page>
<page>
    <name>Yet Another page</name>
    <filename>yet-another-page.php</filename>
</page>
</pages>

When converting this example to a PHP-array, this is the result (the function used can be found on Bin-Co):

Array
(
    [pages] => Array
        (
            [page] => Array
                (
                    [0] => Array
                        (
                            [name] => Homepage
                            [filename] => homepage.php
                            [page] => Array
                                (
                                    [0] => Array
                                        (
                                            [name] => Subpage 1
                                            [filename] => subpage-1.php
                                        )
 
                                    [1] => Array
                                        (
                                            [name] => Subpage 2
                                            [filename] => subpage-2.php
                                            [page] => Array
                                                (
                                                    [name] => Subpage 2-1
                                                    [filename] => subpage-2-1.php
                                                )
 
                                        )
 
                                )
 
                        )
 
                    [1] => Array
                        (
                            [name] => Another page
                            [filename] => another-page.php
                        )
 
                    [2] => Array
                        (
                            [name] => Yet Another page
                            [filename] => yet-another-page.php
                        )
 
                )
 
        )
 
)

This is a quite complex, multi-dimensional array. I however think it's the only way to properly create a page-ordering system with an unlimited amount of dimensions for subpages. With this system, every page can contain a subpage, or even a subsubpage or subsubsubsubpage.

Functions

I propose the following functions to be created or adjusted:

  • save_page() - already exists. Should be adjusted to the new way of naming the pages. It should not add a page to the page index XML-file.
  • page_add_index() - adds a page to the page index XML-file. It should also be able to add pages as subpage of another page, and to add a page in a specific order (for example, as the 3rd page).
  • page_delete_index() - deletes a page from the index XML-file.
  • xml2array() - converts the XML structure to a PHP-array. The function from Bin-Co is great, and BSD-licensed.
  • array2xml() - converts a PHP-array back to an XML structure.
  • theme_menu() - already exists. Should be adjusted to make it able to display the main pages, or subpages of the page that is requested. And of course, this function needs a complete rewrite to make it work with the page index file.

Maybe it's also an idea to add the following two functions too. They could use the xml2array() to read out the XML-file.

  • list_pages() - lists all main pages in a PHP-array.
  • list_subpages() - lists all subpages of a given page in a PHP-array.

Conclusion

This only a first rough concept, and there may still be things that need to be worked out. Feel free to add suggestions to this page, or mail them to the development mailing list. If needed, I will make a second (updated) version of the draft, or create an entirely new draft.

 
devarea/specs/4.7/seo-friendly-urls-and-subpages.txt · Last modified: 2009/05/25 23:24 by sander
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki