From 1962ff99a62b41dc51ee8202dcc419e607f4c320 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 28 Mar 2016 16:47:43 +0200 Subject: [PATCH] takin out the trash --- libraries/Bans.php | 60 --------- libraries/Comment.php | 30 ++++- libraries/Controllers/CommentsController.php | 38 ++++++ libraries/Controllers/FileController.php | 5 +- libraries/Controllers/ForumController.php | 6 +- libraries/Controllers/MetaController.php | 45 ++----- libraries/Controllers/NewsController.php | 64 ++++++++++ .../Controllers/NotificationsController.php | 71 +++++++++++ libraries/Controllers/PremiumController.php | 4 +- libraries/Controllers/UserController.php | 55 +------- libraries/News.php | 76 ----------- libraries/News/Category.php | 47 ++++++- libraries/News/Post.php | 118 +++++++++++++++++- libraries/Notification.php | 9 -- libraries/Template.php | 18 --- libraries/User.php | 28 +++-- public/settings.php | 2 +- routes.php | 61 ++++----- sakura.php | 31 +---- templates/misaki/main/profile.twig | 2 - templates/yuuno/elements/comment.twig | 20 +-- templates/yuuno/elements/newsPost.twig | 13 +- templates/yuuno/forum/elements/forumBase.twig | 55 ++++++++ .../yuuno/forum/{ => elements}/forumBtns.twig | 2 +- .../forum/{ => elements}/forumEntry.twig | 0 .../yuuno/forum/{ => elements}/forumMod.twig | 0 .../yuuno/forum/{ => elements}/replyForm.twig | 0 .../forum/{ => elements}/topicEntry.twig | 0 templates/yuuno/forum/forum.twig | 68 +++------- templates/yuuno/forum/index.twig | 2 +- .../forum/{viewtopic.twig => thread.twig} | 6 +- templates/yuuno/forum/viewforum.twig | 17 --- templates/yuuno/global/master.twig | 32 ++--- templates/yuuno/main/news.twig | 56 --------- templates/yuuno/main/supporttracker.twig | 61 --------- templates/yuuno/{main => meta}/banned.twig | 0 templates/yuuno/{main => meta}/faq.twig | 0 templates/yuuno/{main => meta}/index.twig | 2 +- templates/yuuno/{main => meta}/infopage.twig | 0 templates/yuuno/{main => meta}/report.twig | 0 templates/yuuno/{main => meta}/search.twig | 0 templates/yuuno/{main => meta}/settings.twig | 0 templates/yuuno/news/category.twig | 33 +++++ templates/yuuno/news/post.twig | 20 +++ .../complete.twig} | 0 .../{main/support.twig => premium/index.twig} | 0 templates/yuuno/profile/comments.twig | 2 +- templates/yuuno/template.ini | 14 --- .../memberlist.twig => user/members.twig} | 0 templates/yuuno/{main => user}/profile.twig | 4 +- 50 files changed, 585 insertions(+), 592 deletions(-) delete mode 100644 libraries/Bans.php create mode 100644 libraries/Controllers/CommentsController.php create mode 100644 libraries/Controllers/NewsController.php create mode 100644 libraries/Controllers/NotificationsController.php delete mode 100644 libraries/News.php create mode 100644 templates/yuuno/forum/elements/forumBase.twig rename templates/yuuno/forum/{ => elements}/forumBtns.twig (94%) rename templates/yuuno/forum/{ => elements}/forumEntry.twig (100%) rename templates/yuuno/forum/{ => elements}/forumMod.twig (100%) rename templates/yuuno/forum/{ => elements}/replyForm.twig (100%) rename templates/yuuno/forum/{ => elements}/topicEntry.twig (100%) rename templates/yuuno/forum/{viewtopic.twig => thread.twig} (98%) delete mode 100644 templates/yuuno/forum/viewforum.twig delete mode 100644 templates/yuuno/main/news.twig delete mode 100644 templates/yuuno/main/supporttracker.twig rename templates/yuuno/{main => meta}/banned.twig (100%) rename templates/yuuno/{main => meta}/faq.twig (100%) rename templates/yuuno/{main => meta}/index.twig (90%) rename templates/yuuno/{main => meta}/infopage.twig (100%) rename templates/yuuno/{main => meta}/report.twig (100%) rename templates/yuuno/{main => meta}/search.twig (100%) rename templates/yuuno/{main => meta}/settings.twig (100%) create mode 100644 templates/yuuno/news/category.twig create mode 100644 templates/yuuno/news/post.twig rename templates/yuuno/{main/premiumcomplete.twig => premium/complete.twig} (100%) rename templates/yuuno/{main/support.twig => premium/index.twig} (100%) delete mode 100644 templates/yuuno/template.ini rename templates/yuuno/{main/memberlist.twig => user/members.twig} (100%) rename templates/yuuno/{main => user}/profile.twig (98%) diff --git a/libraries/Bans.php b/libraries/Bans.php deleted file mode 100644 index 436e13d..0000000 --- a/libraries/Bans.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -class Bans -{ - /** - * Checks if a user is banned. - * - * @param int $uid The ID of the user that is being checked. - * - * @return array|bool Either false or an array containing information about the ban. - */ - public static function checkBan($uid) - { - - // Attempt to get a ban from this user - $bans = DB::table('bans') - ->where('user_id', $uid) - ->get(); - - // Reverse the array so new bans are listed first - $bans = array_reverse($bans); - - // Go over each ban - foreach ($bans as $ban) { - // Check if it hasn't expired - if ($ban->ban_end != 0 && $ban->ban_end < time()) { - // If it has delete the entry and continue - DB::table('bans') - ->where('ban_id', $ban->ban_id) - ->delete(); - continue; - } - - // Return the ban if all checks were passed - return [ - 'user' => $ban->user_id, - 'issuer' => $ban->ban_moderator, - 'issued' => $ban->ban_begin, - 'expires' => $ban->ban_end, - 'reason' => $ban->ban_reason, - ]; - } - - // Else just return false - return false; - } -} diff --git a/libraries/Comment.php b/libraries/Comment.php index 89396bf..0a8ad3d 100644 --- a/libraries/Comment.php +++ b/libraries/Comment.php @@ -24,6 +24,7 @@ class Comment public $upvotes = 0; public $downvotes = 0; private $replyCache = []; + private $parsedCache = ""; public function __construct($id = 0) { @@ -69,6 +70,19 @@ class Comment } } + public function delete() + { + foreach ($this->replies() as $reply) { + $reply->delete(); + } + + DB::table('comments') + ->where('comment_id', $this->id) + ->delete(); + + $this->id = 0; + } + private function getVotes() { $votes = DB::table('comment_votes') @@ -77,20 +91,30 @@ class Comment foreach ($votes as $vote) { if ($vote->vote_state) { - $upvotes += 1; + $this->upvotes += 1; } else { - $downvotes += 1; + $this->downvotes += 1; } } } + public function parsed() + { + if (!$this->parsedCache) { + $this->parsedCache = BBcode::parseEmoticons(Utils::cleanString($this->text)); + } + + return $this->parsedCache; + } + public function replies() { if (!$this->replyCache) { $commentIds = DB::table('comments') ->where('comment_reply_to', $this->id) + ->orderBy('comment_id', 'desc') ->get(['comment_id']); - $commentIds = array_column($comments, 'comment_id'); + $commentIds = array_column($commentIds, 'comment_id'); foreach ($commentIds as $comment) { $this->replyCache[$comment] = new Comment($comment); diff --git a/libraries/Controllers/CommentsController.php b/libraries/Controllers/CommentsController.php new file mode 100644 index 0000000..eec2ad8 --- /dev/null +++ b/libraries/Controllers/CommentsController.php @@ -0,0 +1,38 @@ + + */ +class CommentsController extends Controller +{ + public function post($category = '', $reply = 0) + { + global $currentUser; + + // todo: make not shit + + $text = isset($_POST['text']) ? $_POST['text'] : ''; + + $comment = new Comment; + + $comment->category = $category; + $comment->time = time(); + $comment->reply = (int) $reply; + $comment->user = $currentUser->id; + $comment->text = $text; + + $comment->save(); + } +} diff --git a/libraries/Controllers/FileController.php b/libraries/Controllers/FileController.php index c4617b3..0a80162 100644 --- a/libraries/Controllers/FileController.php +++ b/libraries/Controllers/FileController.php @@ -85,8 +85,7 @@ class FileController extends Controller return $this->serve($deactive['data'], $deactive['mime'], $deactive['name']); } - if ($user->checkBan() - || $user->permission(Site::RESTRICTED)) { + if ($user->permission(Site::RESTRICTED)) { return $this->serve($banned['data'], $banned['mime'], $banned['name']); } @@ -126,7 +125,6 @@ class FileController extends Controller $user = User::construct($id); if ($user->permission(Site::DEACTIVATED) - || $user->checkBan() || $user->permission(Site::RESTRICTED) || !$user->background) { return $this->serve($none['data'], $none['mime'], $none['name']); @@ -164,7 +162,6 @@ class FileController extends Controller $user = User::construct($id); if ($user->permission(Site::DEACTIVATED) - || $user->checkBan() || $user->permission(Site::RESTRICTED) || !$user->header) { return $this->serve($none['data'], $none['mime'], $none['name']); diff --git a/libraries/Controllers/ForumController.php b/libraries/Controllers/ForumController.php index 63d59e9..52a69ae 100644 --- a/libraries/Controllers/ForumController.php +++ b/libraries/Controllers/ForumController.php @@ -184,7 +184,7 @@ class ForumController extends Controller ]); // Print page contents - return Template::render('forum/viewforum'); + return Template::render('forum/forum'); } /** @@ -295,7 +295,7 @@ class ForumController extends Controller Template::vars(compact('forum', 'thread')); // Print page contents - return Template::render('forum/viewtopic'); + return Template::render('forum/thread'); } /** @@ -699,7 +699,7 @@ class ForumController extends Controller Template::vars(compact('forum')); - return Template::render('forum/viewtopic'); + return Template::render('forum/thread'); } /** diff --git a/libraries/Controllers/MetaController.php b/libraries/Controllers/MetaController.php index 98f7487..d2b3fa3 100644 --- a/libraries/Controllers/MetaController.php +++ b/libraries/Controllers/MetaController.php @@ -9,7 +9,7 @@ namespace Sakura\Controllers; use Sakura\Config; use Sakura\DB; -use Sakura\News; +use Sakura\News\Category; use Sakura\Template; use Sakura\User; @@ -60,10 +60,12 @@ class MetaController extends Controller $onlineUsers[$user->id] = $user; } + // Get news + $news = new Category(Config::get('site_news_category')); + // Merge index specific stuff with the global render data Template::vars([ - 'news' => new News(Config::get('site_news_category')), - 'newsCount' => Config::get('front_page_news_posts'), + 'news' => $news->posts(Config::get('front_page_news_posts')), 'stats' => [ 'userCount' => DB::table('users') ->where('password_algo', '!=', 'disabled') @@ -81,36 +83,7 @@ class MetaController extends Controller ]); // Return the compiled page - return Template::render('main/index'); - } - - /** - * Handles the news pages. - * - * @return mixed HTML for the correct news section. - */ - public function news() - { - // Get arguments - $args = func_get_args(); - $category = isset($args[0]) && !is_numeric($args[0]) ? $args[0] : Config::get('site_news_category'); - $post = isset($args[1]) && is_numeric($args[1]) ? $args[1] : ( - isset($args[0]) && is_numeric($args[0]) ? $args[0] : 0 - ); - - // Create news object - $news = new News($category); - - // Set parse variables - Template::vars([ - 'news' => $news, - 'postsPerPage' => Config::get('news_posts_per_page'), - 'viewPost' => $post != 0, - 'postExists' => $news->postExists($post), - ]); - - // Print page contents - return Template::render('main/news'); + return Template::render('meta/index'); } /** @@ -134,7 +107,7 @@ class MetaController extends Controller ]); // Print page contents - return Template::render('main/faq'); + return Template::render('meta/faq'); } /** @@ -174,7 +147,7 @@ class MetaController extends Controller } // Return the compiled page - return Template::render('main/infopage'); + return Template::render('meta/infopage'); } /** @@ -184,6 +157,6 @@ class MetaController extends Controller */ public function search() { - return Template::render('main/search'); + return Template::render('meta/search'); } } diff --git a/libraries/Controllers/NewsController.php b/libraries/Controllers/NewsController.php new file mode 100644 index 0000000..e16f7dc --- /dev/null +++ b/libraries/Controllers/NewsController.php @@ -0,0 +1,64 @@ + + */ +class NewsController extends Controller +{ + public function category($category = '') + { + // Check if the category is set + if ($category === '') { + // Fetch the default category from the config + $category = Config::get('site_news_category'); + } + + // Create the category object + $category = new Category($category); + + if (!$category->posts()) { + $message = "This news category doesn't exist!"; + + Template::vars(compact('message')); + + return Template::render('global/information'); + } + + Template::vars(compact('category')); + + return Template::render('news/category'); + } + + public function post($id = 0) + { + // Create the post object + $post = new Post($id); + + if (!$post->id) { + $message = "This news post doesn't exist!"; + + Template::vars(compact('message')); + + return Template::render('global/information'); + } + + Template::vars(compact('post')); + + return Template::render('news/post'); + } +} diff --git a/libraries/Controllers/NotificationsController.php b/libraries/Controllers/NotificationsController.php new file mode 100644 index 0000000..ea430ee --- /dev/null +++ b/libraries/Controllers/NotificationsController.php @@ -0,0 +1,71 @@ + + */ +class NotificationsController extends Controller +{ + /** + * Get the notification JSON object for the currently authenticated user. + * + * @return string The JSON object. + */ + public function notifications() + { + // TODO: add friend on/offline messages + global $currentUser; + + // Set json content type + header('Content-Type: application/json; charset=utf-8'); + + return json_encode( + $currentUser->notifications(), + JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK | JSON_BIGINT_AS_STRING + ); + } + + /** + * Mark a notification as read. + * + * @param int The ID of the notification. + * + * @return string Not entirely set on this one yet but 1 for success and 0 for fail. + */ + public function mark($id = 0) + { + global $currentUser; + + // Check permission + if ($currentUser->permission(Site::DEACTIVATED)) { + return '0'; + } + + // Create the notification object + $alert = new Notification($id); + + // Verify that the currently authed user is the one this alert is for + if ($alert->user !== $currentUser->id) { + return '0'; + } + + // Toggle the read status and save + $alert->toggleRead(); + $alert->save(); + + return '1'; + } +} diff --git a/libraries/Controllers/PremiumController.php b/libraries/Controllers/PremiumController.php index ba886df..124501f 100644 --- a/libraries/Controllers/PremiumController.php +++ b/libraries/Controllers/PremiumController.php @@ -49,7 +49,7 @@ class PremiumController extends Controller Template::vars(compact('price', 'amountLimit')); - return Template::render('main/support'); + return Template::render('premium/index'); } /** @@ -180,6 +180,6 @@ class PremiumController extends Controller */ public function complete() { - return Template::render('main/premiumcomplete'); + return Template::render('premium/complete'); } } diff --git a/libraries/Controllers/UserController.php b/libraries/Controllers/UserController.php index 57bc04f..02c7eaa 100644 --- a/libraries/Controllers/UserController.php +++ b/libraries/Controllers/UserController.php @@ -9,7 +9,6 @@ namespace Sakura\Controllers; use Sakura\Config; use Sakura\DB; -use Sakura\Notification; use Sakura\Perms\Site; use Sakura\Rank; use Sakura\Router; @@ -63,7 +62,7 @@ class UserController extends Controller Template::vars(compact('profile')); // Print page contents - return Template::render('main/profile'); + return Template::render('user/profile'); } /** @@ -107,56 +106,6 @@ class UserController extends Controller Template::vars(compact('ranks', 'rank', 'membersPerPage')); // Render the template - return Template::render('main/memberlist'); - } - - /** - * Get the notification JSON object for the currently authenticated user. - * - * @return string The JSON object. - */ - public function notifications() - { - // TODO: add friend on/offline messages - global $currentUser; - - // Set json content type - header('Content-Type: application/json; charset=utf-8'); - - return json_encode( - $currentUser->notifications(), - JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK | JSON_BIGINT_AS_STRING - ); - } - - /** - * Mark a notification as read. - * - * @param int The ID of the notification. - * - * @return string Not entirely set on this one yet but 1 for success and 0 for fail. - */ - public function markNotification($id = 0) - { - global $currentUser; - - // Check permission - if ($currentUser->permission(Site::DEACTIVATED)) { - return '0'; - } - - // Create the notification object - $alert = new Notification($id); - - // Verify that the currently authed user is the one this alert is for - if ($alert->user !== $currentUser->id) { - return '0'; - } - - // Toggle the read status and save - $alert->toggleRead(); - $alert->save(); - - return '1'; + return Template::render('user/members'); } } diff --git a/libraries/News.php b/libraries/News.php deleted file mode 100644 index ce5d601..0000000 --- a/libraries/News.php +++ /dev/null @@ -1,76 +0,0 @@ - - */ -class News -{ - /** - * Array containing news posts. - * - * @var array - */ - public $posts = []; - - /** - * Constructor - * - * @param mixed $category ID of the category that should be constructed. - */ - public function __construct($category) - { - - // Get the news posts and assign them to $posts - $posts = DB::table('news') - ->where('news_category', $category) - ->orderBy('news_id', 'desc') - ->get(); - - // Attach poster data - foreach ($posts as $post) { - // See Comments.php - $post = get_object_vars($post); - - // Attach the poster - $post['news_poster'] = User::construct($post['user_id']); - - // Load comments - $post['news_comments'] = $this->comments = new Comments('news-' . $category . '-' . $post['news_id']); - - // Add post to posts array - $this->posts[$post['news_id']] = $post; - } - } - - /** - * Get the amount of news posts. - * - * @return int Number of posts. - */ - public function getCount() - { - return count($this->posts); - } - - /** - * Check if a post exists in this category. - * - * @param int $pid The ID of the post. - * - * @return int If true the post it gets returns, else 0. - */ - public function postExists($pid) - { - return array_key_exists($pid, $this->posts) ? $pid : 0; - } -} diff --git a/libraries/News/Category.php b/libraries/News/Category.php index 66ce400..dafa3dc 100644 --- a/libraries/News/Category.php +++ b/libraries/News/Category.php @@ -1 +1,46 @@ -donderdag + + */ +class Category +{ + public $name = ""; + + public function __construct($name) + { + $this->name = $name; + } + + public function posts($limit = 0) + { + $postIds = DB::table('news') + ->where('news_category', $this->name) + ->orderBy('news_id', 'desc'); + if ($limit) { + $postIds->limit($limit); + } + $postIds = $postIds->get(['news_id']); + $postIds = array_column($postIds, 'news_id'); + + $posts = []; + + foreach ($postIds as $post) { + $posts[$post] = new Post($post); + } + + return $posts; + } +} diff --git a/libraries/News/Post.php b/libraries/News/Post.php index 746397b..3958d8b 100644 --- a/libraries/News/Post.php +++ b/libraries/News/Post.php @@ -1 +1,117 @@ -vrijdag + + */ +class Post +{ + const COMMENT_CATEGORY_FORMAT = "news-%s-%u"; + + public $id = 0; + public $category = ""; + public $user = 0; + public $time = 0; + public $title = ""; + public $text = ""; + private $commentCountCache = 0; + private $commentsCache = []; + + public function __construct($id = 0) + { + // Get comment data from the database + $data = DB::table('news') + ->where('news_id', $id) + ->get(); + + // Check if anything was returned and assign data + if ($data) { + $data = $data[0]; + + $this->id = $data->news_id; + $this->category = $data->news_category; + $this->user = $data->user_id; + $this->time = $data->news_timestamp; + $this->title = $data->news_title; + $this->text = $data->news_content; + } + } + + public function save() + { + // Create submission data, insert and update take the same format + $data = [ + 'news_category' => $this->category, + 'user_id' => $this->user, + 'news_timestamp' => $this->time, + 'news_title' => $this->title, + 'news_content' => $this->text, + ]; + + // Update if id isn't 0 + if ($this->id) { + DB::table('news') + ->where('news_id', $this->id) + ->update($data); + } else { + $this->id = DB::table('news') + ->insertGetId($data); + } + } + + public function delete() + { + DB::table('news') + ->where('news_id', $this->id) + ->delete(); + + $this->id = 0; + } + + public function userData() + { + return User::construct($this->user); + } + + public function commentCount() + { + if (!$this->commentCountCache) { + $this->commentCountCache = DB::table('comments') + ->where('comment_category', sprintf(self::COMMENT_CATEGORY_FORMAT, $this->category, $this->id)) + ->count(); + } + + return $this->commentCountCache; + } + + public function comments() + { + if (!$this->commentsCache) { + $commentIds = DB::table('comments') + ->where('comment_category', sprintf(self::COMMENT_CATEGORY_FORMAT, $this->category, $this->id)) + ->orderBy('comment_id', 'desc') + ->where('comment_reply_to', 0) + ->get(['comment_id']); + $commentIds = array_column($commentIds, 'comment_id'); + + foreach ($commentIds as $comment) { + $this->commentsCache[$comment] = new Comment($comment); + } + } + + return $this->commentsCache; + } +} diff --git a/libraries/Notification.php b/libraries/Notification.php index 15aca3f..68d0387 100644 --- a/libraries/Notification.php +++ b/libraries/Notification.php @@ -73,15 +73,6 @@ class Notification } } - public function delete() - { - DB::table('comments') - ->where('comment_id', $this->id) - ->delete(); - - $this->id = 0; - } - public function toggleRead() { // Set read to the negative value of itself diff --git a/libraries/Template.php b/libraries/Template.php index e11d177..cefbada 100644 --- a/libraries/Template.php +++ b/libraries/Template.php @@ -41,13 +41,6 @@ class Template */ private static $templateName; - /** - * The template options. - * - * @var array - */ - private static $templateOptions; - /** * The file extension used by template files */ @@ -60,17 +53,6 @@ class Template */ public static function set($name) { - // Assign config path to a variable so we don't have to type it out twice - $confPath = ROOT . 'templates/' . $name . '/template.ini'; - - // Check if the configuration file exists - if (!file_exists($confPath)) { - trigger_error('Template configuration does not exist', E_USER_ERROR); - } - - // Parse and store the configuration - self::$templateOptions = parse_ini_file($confPath, true); - // Set variables self::$templateName = $name; diff --git a/libraries/User.php b/libraries/User.php index 47c2fd5..773b5cd 100644 --- a/libraries/User.php +++ b/libraries/User.php @@ -741,16 +741,6 @@ class User return $objects; } - /** - * Check if the user is banned. - * - * @return array|bool Ban status. - */ - public function checkBan() - { - return Bans::checkBan($this->id); - } - /** * Check if the user has a certaing permission flag. * @@ -774,12 +764,26 @@ class User } /** - * Get the comments from the user's profile. + * Get the comments from the user's profile. + * * @return Comments */ public function profileComments() { - return new Comments('profile-' . $this->id); + $commentIds = DB::table('comments') + ->where('comment_category', "profile-{$this->id}") + ->orderBy('comment_id', 'desc') + ->where('comment_reply_to', 0) + ->get(['comment_id']); + $commentIds = array_column($commentIds, 'comment_id'); + + $comments = []; + + foreach ($commentIds as $comment) { + $comments[$comment] = new Comment($comment); + } + + return $comments; } /** diff --git a/public/settings.php b/public/settings.php index 3975d00..afc8cb6 100644 --- a/public/settings.php +++ b/public/settings.php @@ -1528,7 +1528,7 @@ if (Users::checkLogin()) { Template::vars($renderData); // Print page contents - echo Template::render('main/settings'); + echo Template::render('meta/settings'); } else { // If not allowed print the restricted page Template::vars($renderData); diff --git a/routes.php b/routes.php index 3f95bfb..e60955b 100644 --- a/routes.php +++ b/routes.php @@ -56,9 +56,8 @@ Router::group(['before' => 'loginCheck'], function () { // News Router::group(['prefix' => 'news'], function () { - Router::get('/', 'MetaController@news', 'news.index'); - Router::get('/{category}', 'MetaController@news', 'news.category'); - Router::get('/{category}/{id}', 'MetaController@news', 'news.post'); + Router::get('/{category:c}?', 'NewsController@category', 'news.category'); + Router::get('/post/{id:i}', 'NewsController@post', 'news.post'); }); // Forum @@ -66,8 +65,8 @@ Router::group(['prefix' => 'forum'], function () { // Post Router::group(['prefix' => 'post'], function () { Router::get('/{id:i}', 'ForumController@post', 'forums.post'); - Router::get('/{id:i}/raw', 'ForumController@postRaw', 'forums.post.raw'); Router::group(['before' => 'loginCheck'], function () { + Router::get('/{id:i}/raw', 'ForumController@postRaw', 'forums.post.raw'); Router::get('/{id:i}/delete', 'ForumController@deletePost', 'forums.post.delete'); Router::post('/{id:i}/delete', 'ForumController@deletePost', 'forums.post.delete'); Router::post('/{id:i}/edit', 'ForumController@editPost', 'forums.post.edit'); @@ -84,13 +83,15 @@ Router::group(['prefix' => 'forum'], function () { // 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@createThread', 'forums.new'); - Router::post('/{id:i}/new', 'ForumController@createThread', 'forums.new'); + Router::group(['before' => 'loginCheck'], function () { + Router::get('/{id:i}/mark', 'ForumController@markForumRead', 'forums.mark'); + Router::get('/{id:i}/new', 'ForumController@createThread', 'forums.new'); + Router::post('/{id:i}/new', 'ForumController@createThread', 'forums.new'); + }); }); // Members -Router::group(['prefix' => 'members'], function () { +Router::group(['prefix' => 'members', 'before' => 'loginCheck'], function () { Router::get('/', 'UserController@members', 'members.index'); Router::get('/{rank:i}', 'UserController@members', 'members.rank'); }); @@ -98,8 +99,17 @@ Router::group(['prefix' => 'members'], function () { // User Router::get('/u/{id}', 'UserController@profile', 'user.profile'); Router::get('/u/{id}/header', 'FileController@header', 'user.header'); -Router::get('/notifications', 'UserController@notifications', 'user.notifications'); -Router::get('/notifications/{id}/mark', 'UserController@markNotification', 'user.notifications.mark'); + +// Notifications +Router::group(['prefix' => 'notifications'], function () { + Router::get('/', 'NotificationsController@notifications', 'notifications.get'); + Router::get('/{id}/mark', 'NotificationsController@mark', 'notifications.mark'); +}); + +// Comments +Router::group(['prefix' => 'comments', 'before' => 'loginCheck'], function () { + Router::post('/{category:c}/post/{reply:i}?', 'CommentsController@post', 'comments.post'); +}); // Files Router::get('/a/{id}', 'FileController@avatar', 'file.avatar'); @@ -116,7 +126,7 @@ Router::group(['prefix' => 'support', 'before' => 'loginCheck'], function () { // Helpers Router::group(['prefix' => 'helper'], function () { // BBcode - Router::group(['prefix' => 'bbcode'], function () { + Router::group(['prefix' => 'bbcode', 'before' => 'loginCheck'], function () { Router::post('/parse', 'HelperController@bbcodeParse', 'helper.bbcode.parse'); }); }); @@ -211,35 +221,6 @@ Router::group(['prefix' => 'settings', 'before' => 'loginCheck'], function () { Router::get('/deactivate', 'Settings.AdvancedController@deactivate', 'settings.advanced.deactivate'); }); }); -/* - * General - * - Home (make this not worthless while you're at it) - * - Edit Profile - * - Site Options - * Friends - * - Listing - * - Requests - * Groups - * - Listing - * - Invites - * Notifications (will probably deprecate this entire section at some point but not relevant yet) - * - History - * Appearance (possibly combine ava, bg and header down into one menu as well as userpage and signature maybe) - * - Avatar - * - Background - * - Header - * - Userpage - * - Signature - * Account (also down to one section maybe) - * - E-mail - * - Username - * - Usertitle - * - Password - * - Ranks (except this one i guess) - * Advanced - * - Session manager - * - Deactivate account - */ // Management /* diff --git a/sakura.php b/sakura.php index 4fe1eb8..4b794fd 100644 --- a/sakura.php +++ b/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', 20160327); +define('SAKURA_VERSION', 20160328); // Define Sakura Path define('ROOT', __DIR__ . '/'); @@ -104,11 +104,7 @@ $currentUser = User::construct($authCheck[0]); $urls = new Urls(); // Prepare the name of the template to load -$templateName = -!defined('SAKURA_MANAGE') -&& isset($currentUser->optionFields()['useMisaki']) -&& $currentUser->optionFields()['useMisaki'] ? -'misaki' : Config::get('site_style'); +$templateName = Config::get('site_style'); if (!defined('SAKURA_NO_TPL')) { // Start templating engine @@ -181,32 +177,11 @@ if (!defined('SAKURA_NO_TPL')) { if (Config::get('site_closed')) { // Set parse variables Template::vars([ - 'page' => [ - 'message' => Config::get('site_closed_reason'), - ], + 'message' => Config::get('site_closed_reason'), ]); // Print page contents echo Template::render('global/information'); exit; } - - // Ban checking - if ($authCheck - && !in_array($_SERVER['PHP_SELF'], [$urls->format('AUTH_ACTION', [], false)]) - && $ban = Bans::checkBan($currentUser->id)) { - // Additional render data - Template::vars([ - 'ban' => [ - 'reason' => $ban['reason'], - 'issued' => $ban['issued'], - 'expires' => $ban['expires'], - 'issuer' => (User::construct($ban['issuer'])), - ], - ]); - - // Print page contents - echo Template::render('main/banned'); - exit; - } } diff --git a/templates/misaki/main/profile.twig b/templates/misaki/main/profile.twig index 05d62a2..414a18d 100644 --- a/templates/misaki/main/profile.twig +++ b/templates/misaki/main/profile.twig @@ -145,8 +145,6 @@
Account Standing
{% if profileHidden %}
Unknown
- {% elseif profile.checkBan %} -

Banned

{% elseif profile.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) %}

Restricted

{% else %} diff --git a/templates/yuuno/elements/comment.twig b/templates/yuuno/elements/comment.twig index 5fd1a9e..8b12986 100644 --- a/templates/yuuno/elements/comment.twig +++ b/templates/yuuno/elements/comment.twig @@ -1,28 +1,28 @@ -
  • +
  • - {{ comment.comment_poster.username }} + {{ comment.userData.username }}
    - {{ comment.comment_text|raw|nl2br }} + {{ comment.parsed|raw|nl2br }}
    diff --git a/templates/yuuno/elements/newsPost.twig b/templates/yuuno/elements/newsPost.twig index 0caae65..c329dde 100644 --- a/templates/yuuno/elements/newsPost.twig +++ b/templates/yuuno/elements/newsPost.twig @@ -1,16 +1,17 @@ -{% if not (viewPost and postExists) %}{{ post.news_title }}{% endif %} +{% if newsHideTitle is not defined %}{{ post.title }}{% endif %}
    - +
    - {{ post.news_poster.username }} -

    {{ post.news_poster.username }}

    + {{ post.userData.username }} +

    {{ post.userData.username }}

    - {{ post.news_content|raw }} + {{ post.text|raw }}
    - Posted {% if not (viewPost and postExists) %} {{ post.news_comments.count }} comment{% if post.news_comments.count != 1 %}s{% endif %}{% endif %} + Posted + {% if newsHideCommentCount is not defined %}{{ post.commentCount }} comment{% if post.commentCount != 1 %}s{% endif %}{% endif %}
    diff --git a/templates/yuuno/forum/elements/forumBase.twig b/templates/yuuno/forum/elements/forumBase.twig new file mode 100644 index 0000000..82a5f5d --- /dev/null +++ b/templates/yuuno/forum/elements/forumBase.twig @@ -0,0 +1,55 @@ +
    {{ title }}
    +
    + {% for forum in forum.forums %} + {% if forum.type == 1 %} + {% if forum.forums|length and forum.permission(constant('Sakura\\Perms\\Forum::VIEW'), user.id) %} +
    + {% if forum.type != 1 %}Subforums{% else %}{{ forum.name }}{% endif %} +
    + {% for forum in forum.forums %} + {% include 'forum/elements/forumEntry.twig' %} + {% endfor %} + {% endif %} + {% else %} + {% include 'forum/elements/forumEntry.twig' %} + {% endif %} + {% endfor %} +
    +{% if not forum.type and forum.id > 0 %} + {% set threads = forum.threads|batch(25) %} + + {% set paginationPages = threads %} + {% set paginationUrl %}{{ route('forums.forum', forum.id) }}{% endset %} + + {% include 'forum/elements/forumBtns.twig' %} + {% if forum.threads %} + + + + + + + + + + + + + + + + + + + + + {% for thread in threads[get.page|default(1) - 1] %} + {% include 'forum/elements/topicEntry.twig' %} + {% endfor %} + +
    TopicAuthorLast post
    TopicAuthorLast post
    + {% else %} +

    There are no posts in this forum!

    + {% endif %} + {% include 'forum/elements/forumBtns.twig' %} +{% endif %} diff --git a/templates/yuuno/forum/forumBtns.twig b/templates/yuuno/forum/elements/forumBtns.twig similarity index 94% rename from templates/yuuno/forum/forumBtns.twig rename to templates/yuuno/forum/elements/forumBtns.twig index 46a24bf..a5f45d2 100644 --- a/templates/yuuno/forum/forumBtns.twig +++ b/templates/yuuno/forum/elements/forumBtns.twig @@ -15,7 +15,7 @@ Mark as Read {% endif %} {% if thread.id and showMod %} - {% include 'forum/forumMod.twig' %} + {% include 'forum/elements/forumMod.twig' %} {% endif %} {% include 'elements/pagination.twig' %} diff --git a/templates/yuuno/forum/forumEntry.twig b/templates/yuuno/forum/elements/forumEntry.twig similarity index 100% rename from templates/yuuno/forum/forumEntry.twig rename to templates/yuuno/forum/elements/forumEntry.twig diff --git a/templates/yuuno/forum/forumMod.twig b/templates/yuuno/forum/elements/forumMod.twig similarity index 100% rename from templates/yuuno/forum/forumMod.twig rename to templates/yuuno/forum/elements/forumMod.twig diff --git a/templates/yuuno/forum/replyForm.twig b/templates/yuuno/forum/elements/replyForm.twig similarity index 100% rename from templates/yuuno/forum/replyForm.twig rename to templates/yuuno/forum/elements/replyForm.twig diff --git a/templates/yuuno/forum/topicEntry.twig b/templates/yuuno/forum/elements/topicEntry.twig similarity index 100% rename from templates/yuuno/forum/topicEntry.twig rename to templates/yuuno/forum/elements/topicEntry.twig diff --git a/templates/yuuno/forum/forum.twig b/templates/yuuno/forum/forum.twig index fd609d4..668354a 100644 --- a/templates/yuuno/forum/forum.twig +++ b/templates/yuuno/forum/forum.twig @@ -1,55 +1,17 @@ -
    {{ title }}
    -
    - {% for forum in forum.forums %} - {% if forum.type == 1 %} - {% if forum.forums|length and forum.permission(constant('Sakura\\Perms\\Forum::VIEW'), user.id) %} -
    - {% if forum.type != 1 %}Subforums{% else %}{{ forum.name }}{% endif %} -
    - {% for forum in forum.forums %} - {% include 'forum/forumEntry.twig' %} - {% endfor %} - {% endif %} - {% else %} - {% include 'forum/forumEntry.twig' %} - {% endif %} - {% endfor %} -
    -{% if not forum.type and forum.id > 0 %} - {% set threads = forum.threads|batch(25) %} +{% extends 'global/master.twig' %} - {% set paginationPages = threads %} - {% set paginationUrl %}{{ route('forums.forum', forum.id) }}{% endset %} +{% set title %}Forums / {{ forum.name }}{% endset %} - {% include 'forum/forumBtns.twig' %} - {% if forum.threads %} - - - - - - - - - - - - - - - - - - - - - {% for thread in threads[get.page|default(1) - 1] %} - {% include 'forum/topicEntry.twig' %} - {% endfor %} - -
    TopicAuthorLast post
    TopicAuthorLast post
    - {% else %} -

    There are no posts in this forum!

    - {% endif %} - {% include 'forum/forumBtns.twig' %} -{% endif %} +{% set forumBackLink %}{{ route('forums.index') }}{% endset %} +{% set forumNewLink %}{{ route('forums.new', forum.id) }}{% endset %} +{% set forumMarkRead %}{{ route('forums.mark', forum.id) }}?s={{ session_id() }}{% endset %} + +{% block title %}{{ title }}{% endblock %} + +{% block content %} +
    +
    + {% include 'forum/elements/forumBase.twig' %} +
    +
    +{% endblock %} diff --git a/templates/yuuno/forum/index.twig b/templates/yuuno/forum/index.twig index 9d47259..d702feb 100644 --- a/templates/yuuno/forum/index.twig +++ b/templates/yuuno/forum/index.twig @@ -61,7 +61,7 @@
    - {% include 'forum/forum.twig' %} + {% include 'forum/elements/forumBase.twig' %}
    diff --git a/templates/yuuno/forum/viewtopic.twig b/templates/yuuno/forum/thread.twig similarity index 98% rename from templates/yuuno/forum/viewtopic.twig rename to templates/yuuno/forum/thread.twig index d2da5ef..555d401 100644 --- a/templates/yuuno/forum/viewtopic.twig +++ b/templates/yuuno/forum/thread.twig @@ -70,7 +70,7 @@
    {{ forum.name }} / {{ thread.title }}
    - {% include 'forum/forumBtns.twig' %} + {% include 'forum/elements/forumBtns.twig' %} {% if thread is defined %} {% set textCache = session.replyText['t' ~ thread.id] %} @@ -162,9 +162,9 @@ {% endif %}
    {% if forumReplyLink is defined or thread is not defined %} - {% include 'forum/replyForm.twig' %} + {% include 'forum/elements/replyForm.twig' %} {% endif %} - {% include 'forum/forumBtns.twig' %} + {% include 'forum/elements/forumBtns.twig' %}
    {% endblock %} diff --git a/templates/yuuno/forum/viewforum.twig b/templates/yuuno/forum/viewforum.twig deleted file mode 100644 index bf26401..0000000 --- a/templates/yuuno/forum/viewforum.twig +++ /dev/null @@ -1,17 +0,0 @@ -{% extends 'global/master.twig' %} - -{% set title %}Forums / {{ forum.name }}{% endset %} - -{% set forumBackLink %}{{ route('forums.index') }}{% endset %} -{% set forumNewLink %}{{ route('forums.new', forum.id) }}{% endset %} -{% set forumMarkRead %}{{ route('forums.mark', forum.id) }}?s={{ session_id() }}{% endset %} - -{% block title %}{{ title }}{% endblock %} - -{% block content %} -
    -
    - {% include 'forum/forum.twig' %} -
    -
    -{% endblock %} diff --git a/templates/yuuno/global/master.twig b/templates/yuuno/global/master.twig index c5618a0..a156ccc 100644 --- a/templates/yuuno/global/master.twig +++ b/templates/yuuno/global/master.twig @@ -84,7 +84,7 @@ diff --git a/templates/yuuno/main/news.twig b/templates/yuuno/main/news.twig deleted file mode 100644 index 8853576..0000000 --- a/templates/yuuno/main/news.twig +++ /dev/null @@ -1,56 +0,0 @@ -{% extends 'global/master.twig' %} - -{% set newsPosts = viewPost and postExists ? [news.posts[postExists]] : news.posts|batch(postsPerPage)[get.page|default(1) - 1] %} - -{% if viewPost and postExists %} - {% set commentsCategory = 'news-' ~ newsPosts[0].news_category ~ '-' ~ newsPosts[0].news_id %} - {% set comments = newsPosts[0].news_comments.comments %} -{% else %} - {% set paginationPages = news.posts|batch(postsPerPage) %} - {% set paginationUrl %}{{ route('news.index') }}{% endset %} -{% endif %} - -{% set title %} -{% if not (viewPost ? postExists : newsPosts|length) %}Post does not exist!{% elseif viewPost and postExists %}{{ newsPosts[0].news_title }}{% else %}News{% endif %} -{% endset %} - -{% block title %}{{ title }}{% endblock %} - -{% block css %} - -{% endblock %} - -{% block content %} -
    -
    -
    {{ title }}
    - {% if (viewPost ? postExists : newsPosts|length) %} - {% for post in newsPosts %} - {% include 'elements/newsPost.twig' %} - {% if viewPost and postExists %} - {% include 'elements/comments.twig' %} - {% endif %} - {% endfor %} - {% if not (viewPost and postExists) and news.posts|batch(postsPerPage)|length > 1 %} -
    - {% include 'elements/pagination.twig' %} -
    -
    - {% endif %} - {% else %} -
    -

    The requested news post does not exist!

    - There are a few possible reasons for this; -
      -
    • The post may have been deleted due to irrelevancy.
    • -
    • The post never existed.
    • -
    -
    - {% endif %} -
    -
    -{% endblock %} diff --git a/templates/yuuno/main/supporttracker.twig b/templates/yuuno/main/supporttracker.twig deleted file mode 100644 index 592a738..0000000 --- a/templates/yuuno/main/supporttracker.twig +++ /dev/null @@ -1,61 +0,0 @@ -{% extends 'global/master.twig' %} - -{% block title %}Donation Tracker{% endblock %} - -{% set paginationPages = tracker.table|batch(20) %} -{% set paginationUrl %}{{ route('premium.tracker') }}{% endset %} - -{% block css %} - -{% endblock %} - -{% block content %} -
    -
    Donation Tracker
    -

    Our current overall balance is €{{ tracker.balance|number_format(2) }}

    -
    - Donation Log -
    - - - - - - - - - - - - - - - - - {% for supporter in tracker.table|batch(20)[get.page|default(1) - 1] %} - - - - - - {% endfor %} - -
    SupporterAmountAction
    SupporterAmountAction
    - {{ tracker.users[supporter.user_id].username }} - - €{{ supporter.transaction_amount|number_format(2) }} - - {{ supporter.transaction_comment }} -
    - {% if tracker.table|batch(20)|length > 1 %} -
    - {% include 'elements/pagination.twig' %} -
    -
    - {% endif %} -
    -{% endblock %} diff --git a/templates/yuuno/main/banned.twig b/templates/yuuno/meta/banned.twig similarity index 100% rename from templates/yuuno/main/banned.twig rename to templates/yuuno/meta/banned.twig diff --git a/templates/yuuno/main/faq.twig b/templates/yuuno/meta/faq.twig similarity index 100% rename from templates/yuuno/main/faq.twig rename to templates/yuuno/meta/faq.twig diff --git a/templates/yuuno/main/index.twig b/templates/yuuno/meta/index.twig similarity index 90% rename from templates/yuuno/main/index.twig rename to templates/yuuno/meta/index.twig index 3f063bd..c3f2db3 100644 --- a/templates/yuuno/main/index.twig +++ b/templates/yuuno/meta/index.twig @@ -7,7 +7,7 @@
    News
    - {% for post in news.posts|batch(newsCount)[0] %} + {% for post in news %} {% include 'elements/newsPost.twig' %} {% endfor %}
    diff --git a/templates/yuuno/main/infopage.twig b/templates/yuuno/meta/infopage.twig similarity index 100% rename from templates/yuuno/main/infopage.twig rename to templates/yuuno/meta/infopage.twig diff --git a/templates/yuuno/main/report.twig b/templates/yuuno/meta/report.twig similarity index 100% rename from templates/yuuno/main/report.twig rename to templates/yuuno/meta/report.twig diff --git a/templates/yuuno/main/search.twig b/templates/yuuno/meta/search.twig similarity index 100% rename from templates/yuuno/main/search.twig rename to templates/yuuno/meta/search.twig diff --git a/templates/yuuno/main/settings.twig b/templates/yuuno/meta/settings.twig similarity index 100% rename from templates/yuuno/main/settings.twig rename to templates/yuuno/meta/settings.twig diff --git a/templates/yuuno/news/category.twig b/templates/yuuno/news/category.twig new file mode 100644 index 0000000..2c54453 --- /dev/null +++ b/templates/yuuno/news/category.twig @@ -0,0 +1,33 @@ +{% extends 'global/master.twig' %} + +{% block title %}News{% endblock %} + +{% block css %} + +{% endblock %} + +{% set posts = category.posts|batch(3) %} + +{% set paginationPages = posts|keys %} +{% set paginationUrl %}{{ route('news.category', category.name) }}{% endset %} + +{% block content %} +
    +
    +
    News
    + {% for post in posts[get.page|default(1) - 1] %} + {% include 'elements/newsPost.twig' %} + {% endfor %} + {% if posts|length > 1 %} +
    + {% include 'elements/pagination.twig' %} +
    +
    + {% endif %} +
    +
    +{% endblock %} diff --git a/templates/yuuno/news/post.twig b/templates/yuuno/news/post.twig new file mode 100644 index 0000000..85c5ce5 --- /dev/null +++ b/templates/yuuno/news/post.twig @@ -0,0 +1,20 @@ +{% extends 'global/master.twig' %} + +{% block title %}{{ post.title }}{% endblock %} + +{% set commentsCategory = 'news-' ~ post.category ~ '-' ~ post.id %} +{% set comments = post.comments %} + +{% set newsHideTitle = true %} +{% set newsHideCommentCount = true %} + +{% block content %} +
    +
    +
    {{ post.title }}
    + {% include 'elements/newsPost.twig' %} + {% include 'elements/comments.twig' %} +
    +
    +{% endblock %} + diff --git a/templates/yuuno/main/premiumcomplete.twig b/templates/yuuno/premium/complete.twig similarity index 100% rename from templates/yuuno/main/premiumcomplete.twig rename to templates/yuuno/premium/complete.twig diff --git a/templates/yuuno/main/support.twig b/templates/yuuno/premium/index.twig similarity index 100% rename from templates/yuuno/main/support.twig rename to templates/yuuno/premium/index.twig diff --git a/templates/yuuno/profile/comments.twig b/templates/yuuno/profile/comments.twig index d125229..c468a7d 100644 --- a/templates/yuuno/profile/comments.twig +++ b/templates/yuuno/profile/comments.twig @@ -1,4 +1,4 @@ -{% set comments = profile.profileComments.comments %} +{% set comments = profile.profileComments %} {% set commentsCategory = 'profile-' ~ profile.id %}

    Comments

    diff --git a/templates/yuuno/template.ini b/templates/yuuno/template.ini deleted file mode 100644 index d338f21..0000000 --- a/templates/yuuno/template.ini +++ /dev/null @@ -1,14 +0,0 @@ -; Sakura Template Configuration - -[meta] -; Display name of the style, only used in the admin section of the management panel. -name = Yuuno -; Author of this template. -author = Flashwave -; If you set a URL below your name becomes a clickable link in the management panel. -author_url = https://flash.moe - -[manage] -; This defines whether the template is intended for the management panel. -; When it's incorrect Sakura will halt execution of the script. -mode = 0 diff --git a/templates/yuuno/main/memberlist.twig b/templates/yuuno/user/members.twig similarity index 100% rename from templates/yuuno/main/memberlist.twig rename to templates/yuuno/user/members.twig diff --git a/templates/yuuno/main/profile.twig b/templates/yuuno/user/profile.twig similarity index 98% rename from templates/yuuno/main/profile.twig rename to templates/yuuno/user/profile.twig index 30ff581..992900a 100644 --- a/templates/yuuno/main/profile.twig +++ b/templates/yuuno/user/profile.twig @@ -207,10 +207,8 @@ Account Standing {% if profile.permission(constant('Sakura\\Perms\\Site::DEACTIVATED')) %}

    Deactivated

    - {% elseif profile.checkBan %} -

    Banned

    {% elseif profile.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) %} -

    Restricted

    +

    Restricted

    {% elseif profile.getWarnings %}

    Bad

    {% else %}