Example #1
0
<?php

list($name, $representation) = name_and_representation_in_url();
$page = new Page($name);
$page_exists = $page->exists();
// Don't allow unsafe page names
if (!$page->has_safe_name()) {
    header('HTTP/1.0 404 Not Found');
    exit('The page name can only contain dashes, dots and alphanumerical characters.');
}
// /{pagename}.{representation}
if ($representation != '') {
    if (!$page_exists) {
        header('HTTP/1.0 404 Not Found');
        die("Page not found: <a href=" . EDITH_URI . "/" . $page->name . ">Create me!</a>");
    }
    if (!in_array($representation, $REPRESENTATIONS)) {
        header('HTTP/1.0 404 Not Found');
        die('Representation can only be one of: ' . implode($REPRESENTATIONS, ', '));
    }
    switch ($_SERVER['REQUEST_METHOD']) {
        case 'GET':
        case 'HEAD':
            $page->load();
            require "templates/{$representation}.php";
            exit;
        case 'POST':
        case 'PUT':
        case 'PATCH':
        case 'DELETE':
            header('HTTP/1.0 405 Method Not Allowed');