summaryrefslogtreecommitdiff
path: root/model/Page.php
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-09 19:40:17 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-09 19:40:17 +0300
commitf7bfdf58def6aadc922e1632f407d1418269a0d7 (patch)
treed7a0b2819e6a26c11d40ee0b27267ea827fbb345 /model/Page.php
initial
Diffstat (limited to 'model/Page.php')
-rw-r--r--model/Page.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/model/Page.php b/model/Page.php
new file mode 100644
index 0000000..6711a2c
--- /dev/null
+++ b/model/Page.php
@@ -0,0 +1,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);
+ }
+
+}