summaryrefslogtreecommitdiff
path: root/handler/admin/AutoEdit.php
diff options
context:
space:
mode:
Diffstat (limited to 'handler/admin/AutoEdit.php')
-rw-r--r--handler/admin/AutoEdit.php130
1 files changed, 0 insertions, 130 deletions
diff --git a/handler/admin/AutoEdit.php b/handler/admin/AutoEdit.php
deleted file mode 100644
index ba6a7d8..0000000
--- a/handler/admin/AutoEdit.php
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php
-
-namespace handler\admin;
-
-use csrf;
-use pages;
-use posts;
-use Response;
-
-class AutoEdit extends AutoAddOrEdit {
-
- public function get(): Response {
- list($short_name, $saved) = $this->input('short_name, b:saved');
-
- $post = posts::getPostByName($short_name);
- if ($post) {
- $tags = $post->getTags();
- return $this->_get_postEdit($post,
- title: $post->title,
- text: $post->md,
- tags: $post->getTags(),
- visible: $post->visible,
- toc: $post->toc,
- short_name: $post->shortName,
- saved: $saved,
- );
- }
-
- $page = pages::getPageByName($short_name);
- if ($page) {
- return $this->_get_pageEdit($page,
- title: $page->title,
- text: $page->md,
- saved: $saved,
- visible: $page->visible,
- );
- }
-
- throw new \NotFoundException();
- }
-
- public function post(): Response {
- list($short_name) = $this->input('short_name');
-
- $post = posts::getPostByName($short_name);
- if ($post) {
- csrf::check('editpost'.$post->id);
-
- list($text, $title, $tags, $visible, $toc, $short_name)
- = $this->input('text, title, tags, b:visible, b:toc, new_short_name');
-
- $tags = posts::splitStringToTags($tags);
- $error_code = null;
-
- if (!$title) {
- $error_code = 'no_title';
- } else if (!$text) {
- $error_code = 'no_text';
- } else if (empty($tags)) {
- $error_code = 'no_tags';
- } else if (empty($short_name)) {
- $error_code = 'no_short_name';
- }
-
- if ($error_code)
- $this->_get_postEdit($post,
- title: $title,
- text: $text,
- tags: $tags,
- visible: $visible,
- toc: $toc,
- short_name: $short_name,
- error_code: $error_code
- );
-
- $post->edit([
- 'title' => $title,
- 'md' => $text,
- 'visible' => (int)$visible,
- 'toc' => (int)$toc,
- 'short_name' => $short_name
- ]);
- $tag_ids = posts::getTagIds($tags);
- $post->setTagIds($tag_ids);
-
- return new \RedirectResponse($post->getUrl().'edit/?saved=1');
- }
-
- $page = pages::getPageByName($short_name);
- if ($page) {
- csrf::check('editpage'.$page->shortName);
-
- list($text, $title, $visible, $short_name)
- = $this->input('text, title, b:visible, new_short_name');
-
- $text = trim($text);
- $title = trim($title);
- $error_code = null;
-
- if (!$title) {
- $error_code = 'no_title';
- } else if (!$text) {
- $error_code = 'no_text';
- } else if (!$short_name) {
- $error_code = 'no_short_name';
- }
-
- if ($error_code) {
- return $this->_get_pageEdit($page,
- title: $title,
- text: $text,
- visible: $visible,
- error_code: $error_code
- );
- }
-
- $page->edit([
- 'title' => $title,
- 'md' => $text,
- 'visible' => (int)$visible,
- 'short_name' => $short_name,
- ]);
-
- return new \RedirectResponse($page->getUrl().'edit/?saved=1');
- }
-
- throw new \NotFoundException();
- }
-
-} \ No newline at end of file