From 4c366ce454695e0d12af8f9714813218b200c9e5 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 22 May 2018 04:09:53 +0200 Subject: [PATCH] login checks and some minor javascriptery --- assets/less/mio/classes/container.less | 6 ++ public/forum/forum.php | 12 +++- public/forum/index.php | 2 +- public/forum/posting.php | 34 +++++++--- views/mio/errors/400.twig | 8 +++ views/mio/forum/forum.twig | 2 +- views/mio/forum/macros.twig | 90 +++++++++++++++----------- views/mio/forum/topic.twig | 13 +++- views/mio/master.twig | 43 ++++++++++++ 9 files changed, 156 insertions(+), 54 deletions(-) create mode 100644 views/mio/errors/400.twig diff --git a/assets/less/mio/classes/container.less b/assets/less/mio/classes/container.less index 60b20010..34661357 100644 --- a/assets/less/mio/classes/container.less +++ b/assets/less/mio/classes/container.less @@ -8,6 +8,12 @@ background-color: #23172a; } + &--hidden { + .container__content { + display: none; + } + } + &__title { display: block; text-decoration: none; diff --git a/public/forum/forum.php b/public/forum/forum.php index 7c0e7b1b..c67cd6d7 100644 --- a/public/forum/forum.php +++ b/public/forum/forum.php @@ -18,7 +18,7 @@ $templating = $app->getTemplating(); if ($forumId > 0) { $getForum = $db->prepare(' SELECT - `forum_id`, `forum_name`, `forum_type`, `forum_link`, `forum_parent`, + `forum_id`, `forum_name`, `forum_type`, `forum_link`, `forum_link_clicks`, `forum_parent`, ( SELECT COUNT(`topic_id`) FROM `msz_forum_topics` @@ -38,6 +38,16 @@ if (empty($forum) || ($forum['forum_type'] == 2 && empty($forum['forum_link']))) } if ($forum['forum_type'] == 2) { + if ($forum['forum_link_clicks'] !== null) { + $incrementLinkClicks = $db->prepare(' + UPDATE `msz_forum_categories` + SET `forum_link_clicks` = `forum_link_clicks` + 1 + WHERE `forum_id` = :forum_id + '); + $incrementLinkClicks->bindValue('forum_id', $forum['forum_id']); + $incrementLinkClicks->execute(); + } + header('Location: ' . $forum['forum_link']); return; } diff --git a/public/forum/index.php b/public/forum/index.php index 35b2babd..fc09ae7f 100644 --- a/public/forum/index.php +++ b/public/forum/index.php @@ -31,7 +31,7 @@ $categories = array_merge([ $getSubCategories = $db->prepare(' SELECT - f.`forum_id`, f.`forum_name`, f.`forum_description`, f.`forum_type`, f.`forum_link`, + f.`forum_id`, f.`forum_name`, f.`forum_description`, f.`forum_type`, f.`forum_link`, f.`forum_link_clicks`, t.`topic_id` as `recent_topic_id`, p.`post_id` as `recent_post_id`, t.`topic_title` as `recent_topic_title`, p.`post_created` as `recent_post_created`, diff --git a/public/forum/posting.php b/public/forum/posting.php index 65719ef3..47d386b3 100644 --- a/public/forum/posting.php +++ b/public/forum/posting.php @@ -4,21 +4,17 @@ use Misuzu\Net\IPAddress; require_once __DIR__ . '/../../misuzu.php'; +$db = Database::connection(); +$templating = $app->getTemplating(); + if (!$app->hasActiveSession()) { - header('Location: /'); + http_response_code(403); + echo $templating->render('errors.403'); return; } $postRequest = $_SERVER['REQUEST_METHOD'] === 'POST'; -$db = Database::connection(); -$templating = $app->getTemplating(); - -// ORDER OF CHECKING -// - $postId non-zero: enter quote mode -// - $topicId non-zero: enter reply mode -// - $forumId non-zero: enter create mode -// - all zero: enter explode mode if ($postRequest) { $topicId = max(0, (int)($_POST['post']['topic'] ?? 0)); $forumId = max(0, (int)($_POST['post']['forum'] ?? 0)); @@ -28,6 +24,12 @@ if ($postRequest) { $forumId = max(0, (int)($_GET['f'] ?? 0)); } +if (empty($postId) && empty($topicId) && empty($forumId)) { + http_response_code(404); + echo $templating->render('errors.404'); + return; +} + if (!empty($postId)) { $getPost = $db->prepare(' SELECT `post_id`, `topic_id` @@ -58,7 +60,7 @@ if (!empty($topicId)) { if (!empty($forumId)) { $getForum = $db->prepare(' - SELECT `forum_id`, `forum_name` + SELECT `forum_id`, `forum_name`, `forum_type` FROM `msz_forum_categories` WHERE `forum_id` = :forum_id '); @@ -66,6 +68,18 @@ if (!empty($forumId)) { $forum = $getForum->execute() ? $getForum->fetch() : false; } +if (empty($forum)) { + http_response_code(404); + echo $templating->render('errors.404'); + return; +} + +if ($forum['forum_type'] != 0) { + http_response_code(400); + echo $templating->render('errors.400'); + return; +} + if ($postRequest) { $createPost = $db->prepare(' INSERT INTO `msz_forum_posts` diff --git a/views/mio/errors/400.twig b/views/mio/errors/400.twig new file mode 100644 index 00000000..34f9627d --- /dev/null +++ b/views/mio/errors/400.twig @@ -0,0 +1,8 @@ +{% extends '@mio/errors/master.twig' %} + +{% set error_code = 400 %} +{% set error_text = 'Bad Request' %} + +{% block error_message %} +

Whatever you tried to do, you probably shouldn't.

+{% endblock %} diff --git a/views/mio/forum/forum.twig b/views/mio/forum/forum.twig index 7b375deb..c3b6c118 100644 --- a/views/mio/forum/forum.twig +++ b/views/mio/forum/forum.twig @@ -13,7 +13,7 @@ {% endif %} {% if forum_info.forum_type == 0 %} - {% set fcbuttons = forum_category_buttons(forum_info) %} + {% set fcbuttons = app.hasActiveSession ? forum_category_buttons(forum_info) : '' %} {% set fcpagination = pagination(forum_info.forum_topic_count, forum_range, forum_offset, canonical_url) %} {{ fcbuttons }} diff --git a/views/mio/forum/macros.twig b/views/mio/forum/macros.twig index b9230c80..2ca11407 100644 --- a/views/mio/forum/macros.twig +++ b/views/mio/forum/macros.twig @@ -63,50 +63,62 @@ {% endif %} -
-
{{ forum.forum_topic_count|number_format }}
-
{{ forum.forum_post_count|number_format }}
-
- -
- {% if forum.recent_topic_id is null %} -
- There are no posts in this forum yet. + {% if forum.forum_type == 2 %} + {% if forum.forum_link_clicks is not null %} +
+
{{ forum.forum_link_clicks|number_format }}
- {% else %} -
-
- - {{ forum.recent_topic_title|slice(0, 30) ~ (forum.recent_topic_title|length > 30 ? '...' : '') }} - -
-
- {% if forum.recent_post_user_id is not null %} - by {{ forum.recent_post_username }}, - {% endif %} - {{ forum.recent_post_created }} -
-
- - {% if forum.recent_post_user_id is not null %} - - - {% endif %} {% endif %} -
+ {% else %} +
+
{{ forum.forum_topic_count|number_format }}
+
{{ forum.forum_post_count|number_format }}
+
+ {% endif %} + + {% if forum.forum_type != 2 or forum.forum_link_clicks is not null %} +
+ {% if forum.forum_type != 2 %} + {% if forum.recent_topic_id is null %} +
+ There are no posts in this forum yet. +
+ {% else %} +
+
+ + {{ forum.recent_topic_title|slice(0, 30) ~ (forum.recent_topic_title|length > 30 ? '...' : '') }} + +
+
+ {% if forum.recent_post_user_id is not null %} + by {{ forum.recent_post_username }}, + {% endif %} + {{ forum.recent_post_created }} +
+
+ + {% if forum.recent_post_user_id is not null %} + + + {% endif %} + {% endif %} + {% endif %} +
+ {% endif %}
{% endmacro %} {% macro forum_topic_buttons(topic) %}
- Reply + Reply
{% endmacro %} @@ -258,7 +270,7 @@ {% macro forum_posting_form(title, target_id, is_reply, element_id) %} {% set is_reply = is_reply ? true : false %} -
@@ -266,7 +278,7 @@ {{ title }} -
+
{% if not is_reply %} diff --git a/views/mio/forum/topic.twig b/views/mio/forum/topic.twig index bb2b4e20..361ee4d4 100644 --- a/views/mio/forum/topic.twig +++ b/views/mio/forum/topic.twig @@ -6,7 +6,7 @@ {% set base_url = '/forum/topic.php?t=' ~ topic_info.topic_id %} {% set canonical_url = base_url %} -{% set ftbuttons = forum_topic_buttons(topic_info) %} +{% set ftbuttons = app.hasActiveSession ? forum_topic_buttons(topic_info) : '' %} {% set ftpagination = pagination(topic_info.topic_post_count, topic_range, topic_offset, base_url) %} {% block content %} @@ -23,7 +23,16 @@ {{ forum_post_listing(topic_posts, topic_info.topic_first_post_id) }} {{ ftpagination }} - {{ forum_posting_form('Reply', topic_info.topic_id, true, 'reply') }} + {% if app.hasActiveSession %} + {{ forum_posting_form('Reply', topic_info.topic_id, true, 'reply', true) }} + + + {% endif %} {{ navigation(mio_navigation, '/forum/') }} {% endblock %} diff --git a/views/mio/master.twig b/views/mio/master.twig index fa215ba2..0096ec72 100644 --- a/views/mio/master.twig +++ b/views/mio/master.twig @@ -77,5 +77,48 @@
+