summaryrefslogtreecommitdiff
path: root/handler/admin/PageAdd.php
diff options
context:
space:
mode:
Diffstat (limited to 'handler/admin/PageAdd.php')
-rw-r--r--handler/admin/PageAdd.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/handler/admin/PageAdd.php b/handler/admin/PageAdd.php
new file mode 100644
index 0000000..8754f0f
--- /dev/null
+++ b/handler/admin/PageAdd.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace handler\admin;
+
+use csrf;
+use NotFoundException;
+use pages;
+use RedirectResponse;
+use Response;
+
+class PageAdd extends AutoAddOrEdit {
+
+ public function get(): Response {
+ list($name) = $this->input('short_name');
+ $page = pages::getPageByName($name);
+ if ($page)
+ throw new NotFoundException();
+
+ return $this->_get_pageAdd($name);
+ }
+
+ public function post(): Response {
+ csrf::check('addpage');
+
+ list($name) = $this->input('short_name');
+ $page = pages::getPageByName($name);
+ if ($page)
+ throw new NotFoundException();
+
+ $text = trim($_POST['text'] ?? '');
+ $title = trim($_POST['title'] ?? '');
+ $error_code = null;
+
+ if (!$title) {
+ $error_code = 'no_title';
+ } else if (!$text) {
+ $error_code = 'no_text';
+ }
+
+ if ($error_code) {
+ return $this->_get_pageAdd(
+ name: $name,
+ text: $text,
+ title: $title,
+ error_code: $error_code
+ );
+ }
+
+ if (!pages::add([
+ 'short_name' => $name,
+ 'title' => $title,
+ 'md' => $text
+ ])) {
+ return $this->_get_pageAdd(
+ name: $name,
+ text: $text,
+ title: $title,
+ error_code: 'db_err'
+ );
+ }
+
+ $page = pages::getPageByName($name);
+ return new RedirectResponse($page->getUrl());
+ }
+
+} \ No newline at end of file