From b7507cf495c961271ac4b2acfac5fdb7d7e764e2 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 26 May 2018 22:33:05 +0200 Subject: [PATCH] finishing touches for the baseline (nowhere near done tho) --- assets/less/mio/classes/forum/listing.less | 47 +++++++++++++---- assets/less/mio/classes/forum/post.less | 50 +++++++++++++++++-- assets/less/mio/classes/forum/topics.less | 35 ++++++++++--- assets/less/mio/classes/pagination.less | 2 +- .../2018_05_16_155840_initial_structure.php | 8 +-- .../2018_05_17_000055_forum_structure.php | 2 +- misuzu.php | 3 +- public/forum/forum.php | 3 +- public/forum/posting.php | 20 ++++---- public/forum/topic.php | 6 +-- public/index.php | 1 - public/news.php | 12 ++--- public/not-found.php | 2 +- public/settings.php | 3 +- utility.php | 11 ++++ views/mio/forum/macros.twig | 28 ++++++----- 16 files changed, 162 insertions(+), 71 deletions(-) diff --git a/assets/less/mio/classes/forum/listing.less b/assets/less/mio/classes/forum/listing.less index fe0c4cf3..a3133331 100644 --- a/assets/less/mio/classes/forum/listing.less +++ b/assets/less/mio/classes/forum/listing.less @@ -1,4 +1,4 @@ -@mio-forum-listing-mobile: 500px; +@mio-forum-listing-mobile: 700px; .forum__listing { &__forums { @@ -69,6 +69,14 @@ } } + &__stats, + &__activity { + display: flex; + flex-shrink: 0; + flex-grow: 0; + border-left: 1px solid #9475b2; + } + &__stats { text-align: center; justify-content: center; @@ -76,7 +84,10 @@ flex-direction: column; @media (max-width: @mio-forum-listing-mobile) { - display: none; + min-width: initial; + border-left-width: 0; + align-self: flex-end; + align-items: flex-end; } } @@ -90,18 +101,34 @@ color: #555; } + @media (max-width: @mio-forum-listing-mobile) { + &__topics, + &__posts { + font-size: 1em; + margin: 0 4px; + } + } + &__activity { min-width: 270px; min-height: 50px; align-items: center; @media (max-width: @mio-forum-listing-mobile) { - display: none; + min-width: 150px; + + &--empty { + display: none; + } } &__title { line-height: 1.4em; margin-bottom: 2px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + width: 200px; &__link { color: inherit; @@ -148,14 +175,14 @@ flex-grow: 1; flex-shrink: 1; } - } - &__stats, - &__activity { - display: flex; - flex-shrink: 0; - flex-grow: 0; - border-left: 1px solid #9475b2; + @media (max-width: @mio-forum-listing-mobile) { + &__title, + &__info, + &__none { + width: 90px; + } + } } } } diff --git a/assets/less/mio/classes/forum/post.less b/assets/less/mio/classes/forum/post.less index b10be898..bd5749f9 100644 --- a/assets/less/mio/classes/forum/post.less +++ b/assets/less/mio/classes/forum/post.less @@ -1,3 +1,5 @@ +@mio-forum-post-mobile: 700px; + .forum__post { display: flex; border: 1px solid #9475b2; @@ -5,6 +7,10 @@ background-color: #fbeeff; margin: 2px 0; + @media (max-width: @mio-forum-post-mobile) { + flex-direction: column; + } + &__content { display: flex; flex-direction: column; @@ -16,6 +22,12 @@ &__text { margin: 2px; line-height: 1.2em; + + @media (max-width: @mio-forum-post-mobile) { + margin: 4px; + font-size: 1.2em; + line-height: 1.3em; + } } &__info { @@ -42,15 +54,32 @@ text-align: center; flex-grow: 0; flex-shrink: 0; - min-width: 150px; + min-width: 170px; display: flex; flex-direction: column; align-items: center; + @media (max-width: @mio-forum-post-mobile) { + border-right-width: 0; + border: 1px solid #9475b2; + flex-direction: row; + border-bottom-width: 2px; + } + &__joined { flex-grow: 1; flex-shrink: 1; margin: 5px; + max-width: 170px; + + // somewhat temporary? + // more stuff will be added eventually which this will be mixed in with + display: flex; + flex-direction: column-reverse; + + @media (max-width: @mio-forum-post-mobile) { + display: none; + } } &__link { @@ -59,21 +88,34 @@ text-decoration: none; flex-grow: 0; flex-shrink: 0; + + @media (max-width: @mio-forum-post-mobile) { + display: flex; + align-items: center; + margin: 5px; + flex-grow: 1; + } } &__avatar { width: 120px; height: 120px; box-shadow: 0 1px 2px #9475b2; + + @media (max-width: @mio-forum-post-mobile) { + width: 40px; + height: 40px; + margin-right: 5px; + } } &__username { font-size: 1.5em; line-height: 1.7em; + } - &:hover { - text-decoration: underline; - } + &:not(&--deleted) &__username:hover { + text-decoration: underline; } } } diff --git a/assets/less/mio/classes/forum/topics.less b/assets/less/mio/classes/forum/topics.less index 326bd6cb..bcf12658 100644 --- a/assets/less/mio/classes/forum/topics.less +++ b/assets/less/mio/classes/forum/topics.less @@ -1,3 +1,5 @@ +@mio-forum-topics-mobile: 700px; + .forum__topics { &__listing { margin: 1px; @@ -35,6 +37,14 @@ overflow: hidden; } + &__stats, + &__activity { + display: flex; + flex-shrink: 0; + flex-grow: 0; + border-left: 1px solid #9475b2; + } + &__info, &__activity { &__datetime, @@ -83,6 +93,11 @@ font-size: 0.8em; color: #555; } + + @media (max-width: @mio-forum-topics-mobile) { + font-size: 1em; + margin: 0 4px; + } } &__stats { @@ -91,6 +106,13 @@ min-width: 70px; flex-direction: column; justify-content: center; + + @media (max-width: @mio-forum-topics-mobile) { + min-width: initial; + border-left-width: 0; + align-self: flex-end; + align-items: flex-end; + } } &__activity { @@ -98,6 +120,11 @@ padding-left: 3px; align-items: center; + @media (max-width: @mio-forum-topics-mobile) { + min-width: initial; + width: 120px; + } + &__info { flex-grow: 1; flex-shrink: 1; @@ -112,13 +139,5 @@ margin-right: 2px; } } - - &__stats, - &__activity { - display: flex; - flex-shrink: 0; - flex-grow: 0; - border-left: 1px solid #9475b2; - } } } diff --git a/assets/less/mio/classes/pagination.less b/assets/less/mio/classes/pagination.less index 2ad47210..78e0ee59 100644 --- a/assets/less/mio/classes/pagination.less +++ b/assets/less/mio/classes/pagination.less @@ -26,7 +26,7 @@ @media (max-width: @mio-news-mobile) { height: 30px; - width: 30px; + min-width: 30px; font-size: 1.5em; line-height: 1.5em; } diff --git a/database/2018_05_16_155840_initial_structure.php b/database/2018_05_16_155840_initial_structure.php index 519867aa..a89b6586 100644 --- a/database/2018_05_16_155840_initial_structure.php +++ b/database/2018_05_16_155840_initial_structure.php @@ -26,8 +26,8 @@ function migrate_up(PDO $conn): void `username` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NULL DEFAULT NULL, `email` VARCHAR(255) NOT NULL, - `register_ip` BLOB NOT NULL, - `last_ip` BLOB NOT NULL, + `register_ip` VARBINARY(16) NOT NULL, + `last_ip` VARBINARY(16) NOT NULL, `user_country` CHAR(2) NOT NULL DEFAULT 'XX', `user_chat_key` VARCHAR(32) NULL DEFAULT NULL, `created_at` TIMESTAMP NULL DEFAULT NULL, @@ -82,7 +82,7 @@ function migrate_up(PDO $conn): void `session_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` INT(10) UNSIGNED NOT NULL, `session_key` VARCHAR(255) NOT NULL, - `session_ip` BLOB NOT NULL, + `session_ip` VARBINARY(16) NOT NULL, `user_agent` VARCHAR(255) NULL DEFAULT NULL, `expires_on` TIMESTAMP NULL DEFAULT NULL, `created_at` TIMESTAMP NULL DEFAULT NULL, @@ -102,7 +102,7 @@ function migrate_up(PDO $conn): void CREATE TABLE `msz_login_attempts` ( `attempt_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `was_successful` TINYINT(1) NOT NULL, - `attempt_ip` BLOB NOT NULL, + `attempt_ip` VARBINARY(16) NOT NULL, `attempt_country` CHAR(2) NOT NULL DEFAULT 'XX', `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, `created_at` TIMESTAMP NULL DEFAULT NULL, diff --git a/database/2018_05_17_000055_forum_structure.php b/database/2018_05_17_000055_forum_structure.php index 17f996a7..03b977f5 100644 --- a/database/2018_05_17_000055_forum_structure.php +++ b/database/2018_05_17_000055_forum_structure.php @@ -57,7 +57,7 @@ function migrate_up(PDO $conn): void `topic_id` INT(10) UNSIGNED NOT NULL, `forum_id` INT(10) UNSIGNED NOT NULL, `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `post_ip` BLOB NOT NULL, + `post_ip` VARBINARY(16) NOT NULL, `post_text` TEXT NOT NULL, `post_parse` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0', `post_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/misuzu.php b/misuzu.php index 4dac1672..97d375ad 100644 --- a/misuzu.php +++ b/misuzu.php @@ -75,8 +75,7 @@ if (PHP_SAPI !== 'cli') { if ($manage_mode) { if ($app->getUserId() !== 1) { - http_response_code(403); - echo $app->getTemplating()->render('errors.403'); + echo render_error(403); exit; } diff --git a/public/forum/forum.php b/public/forum/forum.php index 218a586b..87d0b9a5 100644 --- a/public/forum/forum.php +++ b/public/forum/forum.php @@ -16,8 +16,7 @@ $templating = $app->getTemplating(); $forum = forum_fetch($forumId); if (empty($forum) || ($forum['forum_type'] == MSZ_FORUM_TYPE_LINK && empty($forum['forum_link']))) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } diff --git a/public/forum/posting.php b/public/forum/posting.php index b899cdef..1e35f91b 100644 --- a/public/forum/posting.php +++ b/public/forum/posting.php @@ -8,8 +8,7 @@ $db = Database::connection(); $templating = $app->getTemplating(); if (!$app->hasActiveSession()) { - http_response_code(403); - echo $templating->render('errors.403'); + echo render_error(403); return; } @@ -25,8 +24,7 @@ if ($postRequest) { } if (empty($postId) && empty($topicId) && empty($forumId)) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } @@ -69,24 +67,26 @@ if (!empty($forumId)) { } if (empty($forum)) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } if ($forum['forum_type'] != MSZ_FORUM_TYPE_DISCUSSION) { - http_response_code(400); - echo $templating->render('errors.400'); + echo render_error(400); return; } if ($forum['forum_archived'] || !empty($topic['topic_locked'])) { - http_response_code(403); - echo $templating->render('errors.403'); + echo render_error(403); return; } if ($postRequest) { + if (!tmp_csrf_verify($_POST['csrf'] ?? '')) { + echo 'Could not verify request.'; + return; + } + $topicTitle = $_POST['post']['title'] ?? ''; $topicTitleValidate = forum_validate_title($topicTitle); $postText = $_POST['post']['text'] ?? ''; diff --git a/public/forum/topic.php b/public/forum/topic.php index d0d0dc0d..66c079f9 100644 --- a/public/forum/topic.php +++ b/public/forum/topic.php @@ -20,16 +20,14 @@ if ($topicId < 1 && $postId > 0) { $topic = forum_topic_fetch($topicId); if (!$topic) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } $posts = forum_post_listing($topic['topic_id'], $postsOffset, $postsRange); if (!$posts) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } diff --git a/public/index.php b/public/index.php index 407e8c9f..c1921365 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,5 @@ execute() ? $getPost->fetch() : false; if ($post === false) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } @@ -57,8 +56,7 @@ if ($category_id !== null) { $category = $getCategory->execute() ? $getCategory->fetch() : false; if ($category === false || $posts_offset < 0 || $posts_offset >= $category['posts_count']) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } @@ -124,8 +122,7 @@ $postsCount = (int)$db->query(' $templating->var('posts_count', $postsCount); if ($posts_offset < 0 || $posts_offset >= $postsCount) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } @@ -152,8 +149,7 @@ $getPosts->bindValue('take', $posts_take); $posts = $getPosts->execute() ? $getPosts->fetchAll() : []; if (!$posts) { - http_response_code(404); - echo $templating->render('errors.404'); + echo render_error(404); return; } diff --git a/public/not-found.php b/public/not-found.php index 59033598..a699ece9 100644 --- a/public/not-found.php +++ b/public/not-found.php @@ -1,4 +1,4 @@ getTemplating()->render('errors.404'); +echo render_error(404); diff --git a/public/settings.php b/public/settings.php index 023a74d1..d6124a5f 100644 --- a/public/settings.php +++ b/public/settings.php @@ -11,8 +11,7 @@ $query_offset = (int)($_GET['o'] ?? 0); $query_take = 15; if (!$app->hasActiveSession()) { - http_response_code(403); - echo $templating->render('errors.403'); + echo render_error(403); return; } diff --git a/utility.php b/utility.php index fd83563d..05dbc502 100644 --- a/utility.php +++ b/utility.php @@ -230,3 +230,14 @@ function parse_bbcode(string $text): string { return \Misuzu\Parsers\BBCode\BBCodeParser::getOrCreateInstance()->parseText($text); } + +function render_error(int $code, string $template = 'errors.%d'): string +{ + http_response_code($code); + + try { + return \Misuzu\Application::getInstance()->getTemplating()->render(sprintf($template, $code)); + } catch (Exception $ex) { + return ''; + } +} diff --git a/views/mio/forum/macros.twig b/views/mio/forum/macros.twig index 041efbb6..e535cbe9 100644 --- a/views/mio/forum/macros.twig +++ b/views/mio/forum/macros.twig @@ -72,15 +72,15 @@
{{ forum.forum_link_clicks|number_format }}
{% endif %} - {% else %} + {% elseif forum.forum_type != 1 %}
{{ 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 == 0 or forum.forum_link_clicks is not null %} +
{% if forum.forum_type != 2 %} {% if forum.recent_topic_id is null %}
@@ -91,7 +91,7 @@
- {{ forum.recent_topic_title|slice(0, 30) ~ (forum.recent_topic_title|length > 30 ? '...' : '') }} + {{ forum.recent_topic_title }}
@@ -250,8 +250,8 @@ {% set is_original_poster = is_original_poster|default(false) %}
-