fixes
This commit is contained in:
parent
34d0ca59a6
commit
1ab8659a21
@ -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() {
|
||||
|
@ -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(
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
require_once 'lib/stored_config.php';
|
||||
|
||||
const ADMIN_SESSION_TIMEOUT = 86400 * 14;
|
||||
const ADMIN_COOKIE_NAME = 'admin_key';
|
||||
const ADMIN_LOGIN_MAX_LENGTH = 32;
|
||||
|
@ -92,7 +92,7 @@ class Post extends model {
|
||||
return $buf;
|
||||
}
|
||||
|
||||
protected function getTimestamp(): int {
|
||||
public function getTimestamp(): int {
|
||||
return (new DateTime($this->date))->getTimestamp();
|
||||
}
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
function scGet(string $key) {
|
||||
$db = DB();
|
||||
$q = $db->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);
|
||||
}
|
@ -314,7 +314,7 @@ HTML;
|
||||
|
||||
$js_params = json_encode(['pages' => true, 'edit' => $is_edit]);
|
||||
$js = <<<JS
|
||||
AdminWriteForm.init({$js_params});
|
||||
cur.form = new AdminWriteEditForm({$js_params});
|
||||
JS;
|
||||
|
||||
return [$html, $js];
|
||||
|
Loading…
x
Reference in New Issue
Block a user