summaryrefslogtreecommitdiff
path: root/lib/pages.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pages.php')
-rw-r--r--lib/pages.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/pages.php b/lib/pages.php
new file mode 100644
index 0000000..281ee52
--- /dev/null
+++ b/lib/pages.php
@@ -0,0 +1,32 @@
+<?php
+
+class pages {
+
+ public static function add(array $data): ?int {
+ $db = getDb();
+ $data['ts'] = time();
+ $data['html'] = markup::markdownToHtml($data['md']);
+ if (!$db->insert('pages', $data))
+ return null;
+ return $db->insertId();
+ }
+
+ public static function delete(Page $page): void {
+ getDb()->query("DELETE FROM pages WHERE short_name=?", $page->shortName);
+ }
+
+ public static function getPageByName(string $short_name): ?Page {
+ $db = getDb();
+ $q = $db->query("SELECT * FROM pages WHERE short_name=?", $short_name);
+ return $db->numRows($q) ? new Page($db->fetch($q)) : null;
+ }
+
+ /**
+ * @return Page[]
+ */
+ public static function getAll(): array {
+ $db = getDb();
+ return array_map('Page::create_instance', $db->fetchAll($db->query("SELECT * FROM pages")));
+ }
+
+} \ No newline at end of file