diff --git a/admin/pages/news.php b/admin/pages/news.php index 36f3fc52..4ac807ed 100644 --- a/admin/pages/news.php +++ b/admin/pages/news.php @@ -32,19 +32,20 @@ const ARTICLE_TEXT_LIMIT = 300; const ARTICLE_IMAGE_LIMIT = 100; $name = $p_title = ''; +$action = $_POST['action'] ?? ''; if(!empty($action)) { - $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; - $p_title = isset($_REQUEST['title']) ? $_REQUEST['title'] : null; - $body = isset($_REQUEST['body']) ? stripslashes($_REQUEST['body']) : null; - $comments = isset($_REQUEST['comments']) ? $_REQUEST['comments'] : null; - $type = isset($_REQUEST['type']) ? (int)$_REQUEST['type'] : null; - $category = isset($_REQUEST['category']) ? (int)$_REQUEST['category'] : null; - $player_id = isset($_REQUEST['player_id']) ? (int)$_REQUEST['player_id'] : null; - $article_text = isset($_REQUEST['article_text']) ? $_REQUEST['article_text'] : null; - $article_image = isset($_REQUEST['article_image']) ? $_REQUEST['article_image'] : null; - $forum_section = isset($_REQUEST['forum_section']) ? $_REQUEST['forum_section'] : null; - $errors = array(); + $id = $_POST['id'] ?? null; + $p_title = $_POST['title'] ?? null; + $body = isset($_POST['body']) ? stripslashes($_POST['body']) : null; + $comments = $_POST['comments'] ?? null; + $type = isset($_POST['type']) ? (int)$_POST['type'] : 1; + $category = isset($_POST['category']) ? (int)$_POST['category'] : null; + $player_id = isset($_POST['player_id']) ? (int)$_POST['player_id'] : null; + $article_text = $_POST['article_text'] ?? null; + $article_image = $_POST['article_image'] ?? null; + $forum_section = $_POST['forum_section'] ?? null; + $errors = []; if($action == 'new') { if(isset($forum_section) && $forum_section != '-1') { @@ -92,7 +93,7 @@ if(!empty($action)) } else if($action == 'hide') { if (News::toggleHidden($id, $errors, $status)) { - success(($status == 1 ? 'Show' : 'Hide') . ' successful.'); + success(($status == 1 ? 'Hide' : 'Show') . ' successful.'); } } @@ -119,12 +120,10 @@ if($action == 'edit' || $action == 'new') { $account_players->orderBy('group_id', POT::ORDER_DESC); $twig->display('admin.news.form.html.twig', array( 'action' => $action, - 'news_link' => getLink(PAGE), - 'news_link_form' => '?p=news&action=' . ($action == 'edit' ? 'edit' : 'new'), 'news_id' => $id ?? null, 'title' => $p_title ?? '', 'body' => isset($body) ? escapeHtml($body) : '', - 'type' => $type ?? null, + 'type' => $type, 'player' => isset($player) && $player->isLoaded() ? $player : null, 'player_id' => $player_id ?? null, 'account_players' => $account_players, diff --git a/system/pages/news.php b/system/pages/news.php index 5f30454f..521017c9 100644 --- a/system/pages/news.php +++ b/system/pages/news.php @@ -13,6 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); require_once LIBS . 'forum.php'; require_once LIBS . 'news.php'; +$canEdit = hasFlag(FLAG_CONTENT_NEWS) || superAdmin(); if(isset($_GET['archive'])) { $title = 'News Archive'; @@ -57,9 +58,14 @@ if(isset($_GET['archive'])) } } + $admin_options = ''; + if($canEdit) { + $admin_options = $twig->render('admin.links.html.twig', ['page' => 'news', 'id' => $news['id'], 'hidden' => $news['hidden']]); + } + $twig->display('news.html.twig', array( 'title' => stripslashes($news['title']), - 'content' => $content_, + 'content' => $content_ . $admin_options, 'date' => $news['date'], 'icon' => $categories[$news['category']]['icon_id'], 'author' => setting('core.news_author') ? $author : '', @@ -81,7 +87,7 @@ if(isset($_GET['archive'])) foreach($news_DB as $news) { $newses[] = array( - 'link' => getLink('news') . '/archive/' . $news['id'], + 'link' => getLink('news') . '/' . $news['id'], 'icon_id' => $categories[$news['category']]['icon_id'], 'title' => stripslashes($news['title']), 'date' => $news['date'] @@ -99,7 +105,6 @@ header('X-XSS-Protection: 0'); $title = 'Latest News'; $cache = Cache::getInstance(); -$canEdit = hasFlag(FLAG_CONTENT_NEWS) || superAdmin(); $news_cached = false; if($cache->enabled()) @@ -180,18 +185,8 @@ if(!$news_cached) } $admin_options = ''; - if($canEdit) - { - $admin_options = '

- Edit - - - Delete - - - - ' . ($news['hidden'] != 1 ? 'Hide' : 'Show') . ' - '; + if($canEdit) { + $admin_options = $twig->render('admin.links.html.twig', ['page' => 'news', 'id' => $news['id'], 'hidden' => $news['hidden']]); } $content_ = $news['body']; diff --git a/system/templates/admin.links.html.twig b/system/templates/admin.links.html.twig new file mode 100644 index 00000000..986133c3 --- /dev/null +++ b/system/templates/admin.links.html.twig @@ -0,0 +1,22 @@ +

+ +
+ {{ csrf() }} + + + +
+ +
+ {{ csrf() }} + + + +
+ +
+ {{ csrf() }} + + + +
diff --git a/system/templates/admin.news.form.html.twig b/system/templates/admin.news.form.html.twig index e1fca8f9..a0acaf9e 100644 --- a/system/templates/admin.news.form.html.twig +++ b/system/templates/admin.news.form.html.twig @@ -1,10 +1,11 @@ {% if action %}
-
{% if action == 'edit' %}Edit{% else %}Add{% endif %} news
+
{% if action == 'edit' %}Edit{% else %}Add{% endif %} {% if type == constant('NEWS') %}News{% elseif type == constant('TICKER') %}Ticker{% else %}Article{% endif %}
-
+ {{ csrf() }} +
{% if action == 'edit' %} @@ -23,9 +24,9 @@
@@ -86,7 +87,7 @@
diff --git a/system/templates/admin.news.html.twig b/system/templates/admin.news.html.twig index 0eb16d3f..c2931398 100644 --- a/system/templates/admin.news.html.twig +++ b/system/templates/admin.news.html.twig @@ -1,136 +1,6 @@ -
-
-
News: - New -
-
- -
- - - - - - - - - - - - {% for news in newses[constant('NEWS')] %} - - - - - - - - {% endfor %} - -
IDTitleDatePlayerOptions
{{ news.id|raw }}{{ news.title }}{{ news.date|date(setting('core.news_date_format')) }}{{ news.player_name }} - -
-
-
- -
-
-
Tickers: - New -
-
- -
- - - - - - - - - - - - {% for ticker in newses[constant('TICKER')] %} - - - - - - - - {% endfor %} - -
IDTitleDatePlayerOptions
{{ ticker.id|raw }}{{ ticker.title }}{{ ticker.date|date(setting('core.news_date_format')) }}{{ ticker.player_name }} - -
-
-
- -
-
-
Articles: New -
-
- -
- - - - - - - - - - - - {% for article in newses[constant('ARTICLE')] %} - - - - - - - - {% endfor %} - -
IDTitleDatePlayerOptions
{{ article.id|raw }}{{ article.title }}{{ article.date|date(setting('core.news_date_format')) }}{{ article.player_name }} - -
-
-
+{{ include('admin.news.table.html.twig', {type: 1, title: 'News'}) }} +{{ include('admin.news.table.html.twig', {type: 2, title: 'Tickers'}) }} +{{ include('admin.news.table.html.twig', {type: 3, title: 'Articles'}) }}