From 1ab8659a213b9a98e3a2c0d62be7c8ca5f2d114c Mon Sep 17 00:00:00 2001 From: "E. S." Date: Sat, 9 Mar 2024 03:00:48 +0000 Subject: [PATCH] fixes --- handler/AdminHandler.php | 19 +++--- handler/MainHandler.php | 143 +++++++++++++++++++-------------------- lib/admin.php | 2 - lib/posts.php | 2 +- lib/stored_config.php | 14 ---- skin/admin.phps | 2 +- 6 files changed, 79 insertions(+), 103 deletions(-) delete mode 100644 lib/stored_config.php diff --git a/handler/AdminHandler.php b/handler/AdminHandler.php index 5ff555b..f3d842c 100644 --- a/handler/AdminHandler.php +++ b/handler/AdminHandler.php @@ -393,20 +393,19 @@ class AdminHandler extends request_handler { } - function GET_auto_edit() { + function GET_page_edit() { list($short_name, $saved) = input('short_name, b:saved'); $page = pages::getByName($short_name); - if ($page) { - return $this->_get_pageEdit($page, - title: $page->title, - text: $page->md, - saved: $saved, - visible: $page->visible, - ); - } + if (!$page) + not_found(); - not_found(); + return $this->_get_pageEdit($page, + title: $page->title, + text: $page->md, + saved: $saved, + visible: $page->visible, + ); } function POST_auto_edit() { diff --git a/handler/MainHandler.php b/handler/MainHandler.php index 14199bc..8d407b6 100644 --- a/handler/MainHandler.php +++ b/handler/MainHandler.php @@ -15,21 +15,32 @@ class MainHandler extends request_handler { list($name) = input('name'); $page = pages::getByName($name); - if ($page) - return $this->renderPage($page); - - if (is_admin()) { - set_title($name); - render('admin/pageNew', - short_name: $name); + if (!$page) { + if (is_admin()) { + set_title($name); + render('admin/pageNew', + short_name: $name); + } + not_found(); } + if (!is_admin() && !$page->visible) + not_found(); + + if ($page->shortName == 'info') + set_skin_opts(['head_section' => 'about']); + + set_title($page ? $page->title : '???'); + render('main/page', + unsafe_html: $page->getHtml(is_retina(), getUserTheme()), + page_url: $page->getUrl(), + short_name: $page->shortName); + not_found(); } function GET_post() { global $config; - ensure_admin(); list($name, $input_lang) = input('name, lang'); @@ -46,74 +57,56 @@ class MainHandler extends request_handler { $lang = PostLanguage::getDefault(); $post = posts::getByName($name); - - if ($post) { - if ($lang == PostLanguage::getDefault() && $input_lang == $lang->value) - redirect($post->getUrl()); - if (!$post->hasLang($lang)) - not_found('no text for language '.$lang->name); - if (!$post->visible && !is_admin()) - not_found(); - - $pt = $post->getText($lang); - - $other_langs = []; - foreach (PostLanguage::cases() as $pl) { - if ($pl == $lang) - continue; - if ($post->hasLang($pl)) - $other_langs[] = $pl->value; - } - - add_meta( - ['property' => 'og:title', 'content' => $pt->title], - ['property' => 'og:url', 'content' => $config['domain'].$post->getUrl()] - ); - if (($img = $pt->getFirstImage()) !== null) - add_meta(['property' => 'og:image', 'content' => $img->getDirectUrl()]); - - add_meta([ - 'name' => 'description', - 'property' => 'og:description', - 'content' => $pt->getDescriptionPreview(155) - ]); - - set_skin_opts(['articles_lang' => $lang->value]); - - set_title($pt->title); - - if ($pt->hasTableOfContents()) - set_skin_opts(['wide' => true]); - - render('main/post', - title: $pt->title, - id: $post->id, - unsafe_html: $pt->getHtml(is_retina(), getUserTheme()), - unsafe_toc_html: $pt->getTableOfContentsHtml(), - date: $post->getFullDate(), - visible: $post->visible, - url: $post->getUrl(), - lang: $lang->value, - other_langs: $other_langs); - } - - not_found(); - } - - protected function renderPage(Page $page) { - global $config; - - if (!is_admin() && !$page->visible && $page->get_id() != $config['index_page_id']) + if (!$post) not_found(); - if ($page->shortName == 'info') - set_skin_opts(['head_section' => 'about']); + if ($lang == PostLanguage::getDefault() && $input_lang == $lang->value) + redirect($post->getUrl()); + if (!$post->hasLang($lang)) + not_found('no text for language '.$lang->name); + if (!$post->visible && !is_admin()) + not_found(); - set_title($page ? $page->title : '???'); - render('main/page', - unsafe_html: $page->getHtml(is_retina(), getUserTheme()), - page_url: $page->getUrl(), - short_name: $page->shortName); + $pt = $post->getText($lang); + + $other_langs = []; + foreach (PostLanguage::cases() as $pl) { + if ($pl == $lang) + continue; + if ($post->hasLang($pl)) + $other_langs[] = $pl->value; + } + + add_meta( + ['property' => 'og:title', 'content' => $pt->title], + ['property' => 'og:url', 'content' => $config['domain'].$post->getUrl()] + ); + if (($img = $pt->getFirstImage()) !== null) + add_meta(['property' => 'og:image', 'content' => $img->getDirectUrl()]); + + add_meta([ + 'name' => 'description', + 'property' => 'og:description', + 'content' => $pt->getDescriptionPreview(155) + ]); + + set_skin_opts(['articles_lang' => $lang->value]); + + set_title($pt->title); + + if ($pt->hasTableOfContents()) + set_skin_opts(['wide' => true]); + + render('main/post', + title: $pt->title, + id: $post->id, + unsafe_html: $pt->getHtml(is_retina(), getUserTheme()), + unsafe_toc_html: $pt->getTableOfContentsHtml(), + date: $post->getFullDate(), + visible: $post->visible, + url: $post->getUrl(), + lang: $lang->value, + other_langs: $other_langs); } function GET_rss() { @@ -125,10 +118,10 @@ class MainHandler extends request_handler { return [ 'title' => $pt->title, 'link' => $post->getUrl(), - 'pub_date' => date(DATE_RSS, $post->ts), + 'pub_date' => date(DATE_RSS, $post->getTimestamp()), 'description' => $pt->getDescriptionPreview(500) ]; - }, posts::getList(0, 20, filter_by_lang: $lagn)); + }, is_admin() ? posts::getList(0, 20, filter_by_lang: $lang) : []); $ctx = new SkinContext('\\skin\\rss'); $body = $ctx->atom( diff --git a/lib/admin.php b/lib/admin.php index a929156..062d16d 100644 --- a/lib/admin.php +++ b/lib/admin.php @@ -1,7 +1,5 @@ date))->getTimestamp(); } diff --git a/lib/stored_config.php b/lib/stored_config.php deleted file mode 100644 index 2e7dc8a..0000000 --- a/lib/stored_config.php +++ /dev/null @@ -1,14 +0,0 @@ -query("SELECT value FROM config WHERE name=?", $key); - if (!$db->numRows($q)) - return null; - return $db->result($q); -} - -function scSet($key, $value) { - $db = DB(); - return $db->query("REPLACE INTO config (name, value) VALUES (?, ?)", $key, $value); -} diff --git a/skin/admin.phps b/skin/admin.phps index ada8617..2db7329 100644 --- a/skin/admin.phps +++ b/skin/admin.phps @@ -314,7 +314,7 @@ HTML; $js_params = json_encode(['pages' => true, 'edit' => $is_edit]); $js = <<