From f5483f42694f648a4c798b9aa3ae77757d80d925 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 20 Mar 2016 17:37:59 +0100 Subject: [PATCH] Added direct post linking back. --- libraries/BBcode.php | 7 +-- libraries/Controllers/ForumController.php | 53 +++++++++++++++++++++++ libraries/Forum/Post.php | 13 ++++-- public/posting.php | 5 +-- routes.php | 8 ++++ sakura.php | 2 +- templates/yuuno/forum/forumEntry.twig | 2 +- templates/yuuno/forum/topicEntry.twig | 2 +- templates/yuuno/forum/viewtopic.twig | 2 +- templates/yuuno/main/resetpassword.twig | 52 ++++++++++++++++++++++ 10 files changed, 131 insertions(+), 15 deletions(-) create mode 100644 templates/yuuno/main/resetpassword.twig diff --git a/libraries/BBcode.php b/libraries/BBcode.php index 63ad4d1..64c479e 100644 --- a/libraries/BBcode.php +++ b/libraries/BBcode.php @@ -7,9 +7,9 @@ namespace Sakura; -use JBBCode\Parser; -use JBBCode\DefaultCodeDefinitionSet; use JBBCode\CodeDefinitionBuilder; +use JBBCode\DefaultCodeDefinitionSet; +use JBBCode\Parser; /** * Sakura wrapper for JBBCode. @@ -102,9 +102,6 @@ class BBcode // Add special definitions (PHP files MUST have the same name as the definition class foreach (glob(ROOT . 'libraries/BBcodeDefinitions/*.php') as $ext) { - // Include the class - require_once $ext; - // Clean the file path $ext = str_replace(ROOT . 'libraries/', '', $ext); $ext = str_replace('.php', '', $ext); diff --git a/libraries/Controllers/ForumController.php b/libraries/Controllers/ForumController.php index df622ca..f23c9b2 100644 --- a/libraries/Controllers/ForumController.php +++ b/libraries/Controllers/ForumController.php @@ -10,6 +10,7 @@ namespace Sakura\Controllers; use Sakura\Config; use Sakura\DB; use Sakura\Forum\Forum; +use Sakura\Forum\Post; use Sakura\Forum\Thread; use Sakura\Perms\Forum as ForumPerms; use Sakura\Router; @@ -355,4 +356,56 @@ class ForumController extends Controller // Print page contents return Template::render('global/information'); } + + public function post($id = 0) + { + global $currentUser; + + // Attempt to get the post + $post = new Post($id); + + // And attempt to get the forum + $thread = new Thread($post->thread); + + // And attempt to get the forum + $forum = new Forum($thread->forum); + + // Check if the forum exists + if ($post->id == 0 || $thread->id == 0 || !$forum->permission(ForumPerms::VIEW, $currentUser->id)) { + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'This post doesn\'t exist or you don\'t have access to it!', + 'redirect' => Router::route('forums.index'), + ], + ]); + + // Print page contents + return Template::render('global/information'); + } + + // Generate link + $threadLink = Router::route('forums.thread', $thread->id); + + // Get all post ids from the database + $postIds = DB::table('posts') + ->where('topic_id', $thread->id) + ->get(['post_id']); + $postIds = array_column($postIds, 'post_id'); + + // Find in array + $postAt = ceil(array_search($post->id, $postIds) / 10); + + // Only append the page variable if it's more than 1 + if ($postAt > 1) { + $threadLink .= "?page={$postAt}"; + } + + return header("Location: {$threadLink}#p{$post->id}"); + } + + protected function postingBase($title, $text, $forum, $thread = 0, $post = 0) + { + + } } diff --git a/libraries/Forum/Post.php b/libraries/Forum/Post.php index 7e83ce1..16d2665 100644 --- a/libraries/Forum/Post.php +++ b/libraries/Forum/Post.php @@ -7,11 +7,11 @@ namespace Sakura\Forum; -use Sakura\DB; -use Sakura\User; use Sakura\BBcode; use Sakura\Config; +use Sakura\DB; use Sakura\Net; +use Sakura\User; /** * Used to serve, create and update posts. @@ -116,7 +116,7 @@ class Post $postRow = DB::table('posts') ->where('post_id', $postId) ->get(); - + // Assign data if a row was returned if ($postRow) { $postRow = $postRow[0]; @@ -226,4 +226,11 @@ class Post // Return a new post object return new Post($this->id); } + + public function delete() + { + DB::table('posts') + ->where('post_id', $this->id) + ->delete(); + } } diff --git a/public/posting.php b/public/posting.php index b89032b..fa8a10f 100644 --- a/public/posting.php +++ b/public/posting.php @@ -229,8 +229,7 @@ if ($mode != 'f') { exit; // Return to previous page } else { - // (haven't (re)implemented post linking yet) - header('Location: ' . $urls->format('FORUM_POST', [$_POST['post_id']])); + header('Location: ' . Router::route('forums.post', $_POST['post_id'])); exit; } } @@ -282,7 +281,7 @@ if (isset($_POST['post'])) { // Add page specific things $renderData['page'] = [ - 'redirect' => $post ? $urls->format('FORUM_POST', [$post->id]) . '#p' . $post->id : '', + 'redirect' => $post ? Router::route('forums.post', $post->id) : '', 'message' => $post ? 'Made the post!' : 'Something is wrong with your post!', 'success' => $post ? 1 : 0, ]; diff --git a/routes.php b/routes.php index 78182db..2374897 100644 --- a/routes.php +++ b/routes.php @@ -33,16 +33,24 @@ Router::group(['prefix' => 'news'], function () { // Forum Router::group(['prefix' => 'forum'], function () { + // Post + Router::group(['prefix' => 'post'], function () { + Router::get('/{id:i}', 'ForumController@post', 'forums.post'); + Router::get('/{id:i}/reply', 'ForumController@postReply', 'forums.post.reply'); + }); + // Thread Router::group(['prefix' => 'thread'], function () { Router::get('/{id:i}', 'ForumController@thread', 'forums.thread'); Router::post('/{id:i}/mod', 'ForumController@threadModerate', 'forums.thread.mod'); + Router::post('/{id:i}/reply', 'ForumController@threadReply', 'forums.thread.reply'); }); // Forum Router::get('/', 'ForumController@index', 'forums.index'); Router::get('/{id:i}', 'ForumController@forum', 'forums.forum'); Router::get('/{id:i}/mark', 'ForumController@markForumRead', 'forums.mark'); + Router::get('/{id:i}/new', 'ForumController@newThread', 'forums.new'); }); // Members diff --git a/sakura.php b/sakura.php index 363ec62..69e2835 100644 --- a/sakura.php +++ b/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20160319'); +define('SAKURA_VERSION', '20160320'); // Define Sakura Path define('ROOT', __DIR__ . '/'); diff --git a/templates/yuuno/forum/forumEntry.twig b/templates/yuuno/forum/forumEntry.twig index d384e2e..67685bb 100644 --- a/templates/yuuno/forum/forumEntry.twig +++ b/templates/yuuno/forum/forumEntry.twig @@ -24,7 +24,7 @@
{% if forum.lastPost.id %} {{ forum.lastPost.subject|slice(0, 30) }}{% if forum.lastPost.subject|length > 30 %}...{% endif %}
- by {% if forum.lastPost.poster.id %}{{ forum.lastPost.poster.username }}{% else %}[deleted user]{% endif %} + by {% if forum.lastPost.poster.id %}{{ forum.lastPost.poster.username }}{% else %}[deleted user]{% endif %} {% else %} There are no posts in this forum.
  {% endif %} diff --git a/templates/yuuno/forum/topicEntry.twig b/templates/yuuno/forum/topicEntry.twig index 0c3024d..f84aac3 100644 --- a/templates/yuuno/forum/topicEntry.twig +++ b/templates/yuuno/forum/topicEntry.twig @@ -21,7 +21,7 @@ {{ thread.lastPost.poster.username }} {% else %} [deleted user] - {% endif %}
+ {% endif %}
diff --git a/templates/yuuno/forum/viewtopic.twig b/templates/yuuno/forum/viewtopic.twig index f4b41dc..3bcc33e 100644 --- a/templates/yuuno/forum/viewtopic.twig +++ b/templates/yuuno/forum/viewtopic.twig @@ -101,7 +101,7 @@ {{ post.subject|slice(0, 50) }}{% if post.subject|length > 50 %}...{% endif %}
- #{{ post.id }} - + #{{ post.id }} -
diff --git a/templates/yuuno/main/resetpassword.twig b/templates/yuuno/main/resetpassword.twig new file mode 100644 index 0000000..b4bd14d --- /dev/null +++ b/templates/yuuno/main/resetpassword.twig @@ -0,0 +1,52 @@ +{% extends 'global/master.twig' %} + +{% block title %}Reset Password{% endblock %} + +{% block content %} + {% if sakura.lockAuth %} +

Resetting password is disabled because of security checkups!

+ {% else %} +
+
+
+ Reset Password +
+
+ + {% if get.u is defined and get.k is defined %} + + +
+ +
+
+ +
+
+ +
+ {% else %} +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + {% endif %} +
+
+
+ {% endif %} +{% endblock %}