summaryrefslogtreecommitdiff
path: root/common.php
blob: d1cd758e9795c0c0c8c990956087cb8cab0c7f29 (plain)
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
<?php

define("SRCDIR", realpath(__DIR__ . "/src/"));

function assetver(string $path): string {
    $path = SRCDIR . "/" . $path;
    if (!is_file($path))
        return "0";
    return md5_file($path);
}

function hzcom_expand(string $pageContents): string {
    $params = [];
    $page = SRCDIR . "/pages/" . bin2hex(random_bytes(8)) . ".tmp";
    file_put_contents($page, preg_replace_callback(
        "/<param:(?'paramName'[a-z][a-z0-9_-]*?)\s*>" .
            "(?'paramValue'.*?)<\/param:\\1\s*>/s",
        function(array $matches) use (&$params) {
            $params[$matches['paramName']] = $matches['paramValue'];
            return "";
        },
        $pageContents
    ));
    unset($pageContents);

    ob_start();
    include SRCDIR . "/template.php";
    $output = ob_get_clean();
    if ($output === false)
        $output = "";

    if (is_file($page))
        unlink($page);

    return $output;
}