File:  [mozdev] / conkeror / www / index.php
Revision 1.27: download - view: text, annotated - select for diffs - revision graph
Mon Jan 14 22:15:49 2008 UTC (10 years, 9 months ago) by jjfoerch
Branches: MAIN
CVS tags: HEAD

www: current development branch is now `master'

<?php

define ('CONKEROR_CURRENT_DEV_BRANCH', 'master');

function echoln ($str) {
    echo $str;
    echo "\n";
}

class DocumentService {
    function run () {
        trigger_error ('Subclasses of DocumentService must override run().');
    }
}

class Redirect extends DocumentService {
    var $url;

    function Redirect ($doc, $absolute = false) {
        if ($absolute) {
            $this->url = $doc;
        } else {

        }
    }

    function run () {
        header ("Location: $this->url");
    }
}

class XhtmlTemplate extends DocumentService {
    var $content;
    var $title;

    function XhtmlTemplate ($title, $content) {
        $this->title = $title;
        $this->content = $content;
    }

    function before_content () {
        header ("Content-Type: application/xhtml+xml; charset=utf-8");
        echoln ('<?xml version="1.0" encoding="utf-8" ?'.'>');
        echoln ("<!DOCTYPE html");
        echoln ('  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
        echoln ('  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
        echoln ('<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">');
        echoln ('<head>');
        echoln ("  <title>$this->title</title>");
        echoln ('  <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />');
        echoln ('  <link rel="stylesheet" type="text/css" href="basic.css" />');
        echoln ('</head>');
        echoln ('<body>');
    }

    function after_content () {
        echoln ('</body>');
        echoln ('</html>');
    }

    function run () {
        $this->before_content ();
        $this->content->run ();
        $this->after_content ();
    }
}


class Http404 extends XhtmlTemplate {
    function Http404 () {
        parent::XhtmlTemplate ("Conkeror 404 Not Found", null);
    }

    function run () {
        header ("HTTP/1.0 404 Not Found");
        $this->before_content ();
        echoln ('<h1>Error 404 Not Found</h1>');
        $this->after_content ();
    }
}


class StaticDoc extends DocumentService {
    var $contentfile;

    function StaticDoc ($contentfile) {
        $this->contentfile = $contentfile;
    }

    function run () {
        include ($this->contentfile);
    }
}


class Append extends DocumentService {
    var $content1;
    var $content2;

    function Append ($content1, $content2) {
        $this->content1 = $content1;
        $this->content2 = $content2;
    }

    function run () {
        $this->content1->run();
        $this->content2->run();
    }
}

$primary_path_mode = 'query';
$primary_path_query_key = 'doc';

if ($primary_path_mode == 'query') {
    $primary_path = $_REQUEST[$primary_path_query_key];
}

$buttons = new StaticDoc ('buttons.html');
$documents = array (
    '{^$}'              => new XhtmlTemplate ('Conkeror', new Append (new StaticDoc ('main.html'), $buttons)), # main page
    '{install}'         => new XhtmlTemplate ('Conkeror Installation', new Append (new StaticDoc ('install.html'), $buttons)),
    '{install/nix}'     => new XhtmlTemplate ('Conkeror Installation under *nix', new Append (new StaticDoc ('install-nix.html'), $buttons)),
    '{install/windows}' => new XhtmlTemplate ('Conkeror Installation under Windows', new Append (new StaticDoc ('install-windows.html'), $buttons))
    );

$document = null;
foreach ($documents as $key => $value) {
    if (preg_match ($key, $primary_path)) {
        $document = $value;
        break;
    }
}

if  ($document == null) {
    $document = new Http404 ();
}

$document->run();

?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>