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 @@