fix news adding, rename const to NEWS_*

This commit is contained in:
slawkens 2023-02-06 19:35:00 +01:00
parent ea09b6a91b
commit c1eb7d4f52
2 changed files with 10 additions and 10 deletions

View File

@ -23,8 +23,8 @@ if (!hasFlag(FLAG_CONTENT_PAGES) && !superAdmin()) {
header('X-XSS-Protection:0'); header('X-XSS-Protection:0');
// some constants, used mainly by database (cannot by modified without schema changes) // some constants, used mainly by database (cannot by modified without schema changes)
define('TITLE_LIMIT', 100); define('NEWS_TITLE_LIMIT', 100);
define('BODY_LIMIT', 65535); // maximum news body length define('NEWS_BODY_LIMIT', 65535); // maximum news body length
define('ARTICLE_TEXT_LIMIT', 300); define('ARTICLE_TEXT_LIMIT', 300);
define('ARTICLE_IMAGE_LIMIT', 100); define('ARTICLE_IMAGE_LIMIT', 100);
@ -43,12 +43,12 @@ if(!empty($action))
$forum_section = isset($_REQUEST['forum_section']) ? $_REQUEST['forum_section'] : null; $forum_section = isset($_REQUEST['forum_section']) ? $_REQUEST['forum_section'] : null;
$errors = array(); $errors = array();
if($action == 'add') { if($action == 'new') {
if(isset($forum_section) && $forum_section != '-1') { if(isset($forum_section) && $forum_section != '-1') {
$forum_add = Forum::add_thread($p_title, $body, $forum_section, $player_id, $account_logged->getId(), $errors); $forum_add = Forum::add_thread($p_title, $body, $forum_section, $player_id, $account_logged->getId(), $errors);
} }
if(News::add($p_title, $body, $type, $category, $player_id, isset($forum_add) && $forum_add != 0 ? $forum_add : 0, $article_text, $article_image, $errors)) { if(isset($p_title) && News::add($p_title, $body, $type, $category, $player_id, isset($forum_add) && $forum_add != 0 ? $forum_add : 0, $article_text, $article_image, $errors)) {
$p_title = $body = $comments = $article_text = $article_image = ''; $p_title = $body = $comments = $article_text = $article_image = '';
$type = $category = $player_id = 0; $type = $category = $player_id = 0;
@ -115,7 +115,7 @@ if($action == 'edit' || $action == 'new') {
$twig->display('admin.news.form.html.twig', array( $twig->display('admin.news.form.html.twig', array(
'action' => $action, 'action' => $action,
'news_link' => getLink(PAGE), 'news_link' => getLink(PAGE),
'news_link_form' => '?p=news&action=' . ($action == 'edit' ? 'edit' : 'add'), 'news_link_form' => '?p=news&action=' . ($action == 'edit' ? 'edit' : 'new'),
'news_id' => isset($id) ? $id : null, 'news_id' => isset($id) ? $id : null,
'title' => isset($p_title) ? $p_title : '', 'title' => isset($p_title) ? $p_title : '',
'body' => isset($body) ? escapeHtml($body) : '', 'body' => isset($body) ? escapeHtml($body) : '',

View File

@ -8,12 +8,12 @@ class News
$errors[] = 'Please fill all inputs.'; $errors[] = 'Please fill all inputs.';
return false; return false;
} }
if(strlen($title) > TITLE_LIMIT) { if(strlen($title) > NEWS_TITLE_LIMIT) {
$errors[] = 'News title cannot be longer than ' . TITLE_LIMIT . ' characters.'; $errors[] = 'News title cannot be longer than ' . NEWS_TITLE_LIMIT . ' characters.';
return false; return false;
} }
if(strlen($body) > BODY_LIMIT) { if(strlen($body) > NEWS_BODY_LIMIT) {
$errors[] = 'News content cannot be longer than ' . BODY_LIMIT . ' characters.'; $errors[] = 'News content cannot be longer than ' . NEWS_BODY_LIMIT . ' characters.';
return false; return false;
} }
if(strlen($article_text) > ARTICLE_TEXT_LIMIT) { if(strlen($article_text) > ARTICLE_TEXT_LIMIT) {
@ -138,4 +138,4 @@ class News
} }
} }
} }
} }