summaryrefslogtreecommitdiff
path: root/model/Page.php
blob: 6711a2c3542bd13921e7d1e2421492e68fb6c84c (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
37
38
39
40
41
42
43
44
<?php

class Page extends Model {

    const DB_TABLE = 'pages';
    const DB_KEY = 'short_name';

    public string $title;
    public string $md;
    public string $html;
    public int $ts;
    public int $updateTs;
    public bool $visible;
    public string $shortName;

    public function edit(array $data) {
        $data['update_ts'] = time();
        if ($data['md'] != $this->md)
            $data['html'] = markup::markdownToHtml($data['md']);
        parent::edit($data);
    }

    public function isUpdated(): bool {
        return $this->updateTs && $this->updateTs != $this->ts;
    }

    public function getHtml(bool $retina): string {
        $html = $this->html;
        if ($retina)
            $html = markup::htmlRetinaFix($html);
        return $html;
    }

    public function getUrl(): string {
        return "/{$this->shortName}/";
    }

    public function updateHtml() {
        $html = markup::markdownToHtml($this->md);
        $this->html = $html;
        getDb()->query("UPDATE pages SET html=? WHERE short_name=?", $html, $this->shortName);
    }

}