all repos — pakuauk @ ee1e2a5b7e8fca4942e568450b95cbc1baaeb4b3

index.php (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
<?php

define('TEMPLATES', sprintf("%s%s", "template", DIRECTORY_SEPARATOR));
define('DATADIR', sprintf("%s%s", "data", DIRECTORY_SEPARATOR));
define('PAGEDIR', sprintf("%s%s", "page", DIRECTORY_SEPARATOR));
define('ORG_JSON', sprintf("%s%s", DATADIR, 'organisation.json'));
define('SITE_JSON', sprintf("%s%s", DATADIR, 'site.json'));
define('SOCIAL_JSON', sprintf("%s%s", DATADIR, 'social.json'));
define('RESOURCES_JSON', sprintf("%s%s", DATADIR, 'resources.json'));
define('CONTACT_JSON', sprintf("%s%s", DATADIR, 'contact.json'));
define('NAV_JSON', sprintf("%s%s", DATADIR, 'navigation.json'));

define('HEADER_TMPL', sprintf("%s%s", TEMPLATES, 'header.php'));
define('FOOTER_TMPL', sprintf("%s%s", TEMPLATES, 'footer.php'));

class Page {
    public $name;
    public $meta;
    private $nav;
    private $targetfile;
    private $sourcefile;
    private $external;

    public function __construct($name, $meta) {
        global $SITE;
        global $NAVIGATION;
        $this->name = $name;
        $this->targetfile = sprintf("%s.html", $this->name);
        $this->sourcefile = sprintf("%s%s.php", TEMPLATES, $this->name);
        $stat = array(
            'mtime' => time(),
            'ctime' => time()
        );
        if(is_file($this->sourcefile)) {
            $stat = stat($this->sourcefile);
        }
        $defaults = array(
            "@context" => "http=>//schema.org",
            "@type" => "Article",
            "inLanguage" => "en",
            "keywords" => $SITE['keywords'],
            "author" => &$SITE['author'],
            "publisher" => &$SITE['publisher'],
            "dateModified" => date("c", $stat['mtime']),
            "datePublished" => date("c", $stat['ctime']),
            "copyrightYear" => date("Y", $stat['mtime']),
            "identifier" => $name
        );
        $this->meta = array_merge($defaults, $meta);
        if(!isset($this->meta['url'])) {
            $this->meta["url"] = sprintf("%s/%s.html", $SITE['url'], $this->name);
            $this->meta['mainEntityOfPage'] = sprintf("%s#main", $this->meta['url']);
            $this->external = False;
        }
        else {
            $this->external = True;
        }

    }

    public function render() {
        ob_start();

        global $PAGE;
        $PAGE = $this->meta;
        include(HEADER_TMPL);
        $f = sprintf("%s%s.html", PAGEDIR, $this->name);
        if (file_exists($f)) {
            include($f);
        }
        include(FOOTER_TMPL);

        $r = ob_get_clean();
        return $r;
    }

    public function save() {
        if (!$this->external) {
            file_put_contents($this->targetfile, $this->render());
        }
    }
}

$ORG = json_decode(file_get_contents(ORG_JSON), TRUE);

$SITE = json_decode(file_get_contents(SITE_JSON), TRUE);
$SITE['author'] = &$ORG;
$SITE['publisher'] = &$ORG;
$SITE['url'] = sprintf("%s/", rtrim($SITE['url'], '/'));

$SOCIAL = json_decode(file_get_contents(SOCIAL_JSON), TRUE);
$RESOURCES = json_decode(file_get_contents(RESOURCES_JSON), TRUE);
$CONTACT = json_decode(file_get_contents(CONTACT_JSON), TRUE);

$NAVIGATION = json_decode(file_get_contents(NAV_JSON), TRUE);
$build = array();

foreach($NAVIGATION as $navname => $navmeta) {
    $e = new Page($navname, $navmeta);
    $NAVIGATION[$navname] = &$e->meta;
    array_push($build, $e);
}

foreach($build as $e) {
    $e->save();
}

header("HTTP/1.1 301 Moved Permanently");
header("Location: index.html");
exit();