From c0dc531ebefd8912819f3b6c8bda1fed3c7e750c Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Wed, 31 Jan 2024 06:11:00 +0300 Subject: make it simple, but not simpler --- handler/admin/AutoEdit.php | 130 --------------------------------------------- 1 file changed, 130 deletions(-) delete mode 100644 handler/admin/AutoEdit.php (limited to 'handler/admin/AutoEdit.php') 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 @@ -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 -- cgit v1.2.3