From 9da8a4d84aba9766c0dc4f8e050654f1d9c6b7af Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 27 Jun 2015 21:29:37 +0200 Subject: [PATCH] half forum half bird --- _sakura/changelog.json | 20 +++ _sakura/components/Configuration.php | 65 ++++++-- _sakura/components/Forum.php | 147 ++++++++++++++++--- _sakura/components/Main.php | 2 +- _sakura/templates/yuuno/forum/forum.tpl | 35 +++++ _sakura/templates/yuuno/forum/forumEntry.tpl | 41 ++++++ _sakura/templates/yuuno/forum/index.tpl | 39 +---- _sakura/templates/yuuno/forum/topicEntry.tpl | 19 +++ _sakura/templates/yuuno/forum/viewforum.tpl | 7 + content/data/yuuno/css/yuuno.css | 49 +++++++ main/.htaccess | 3 +- main/index.php | 18 ++- main/viewforum.php | 52 +++++++ main/viewtopic.php | 1 - 14 files changed, 418 insertions(+), 80 deletions(-) create mode 100644 _sakura/templates/yuuno/forum/forum.tpl create mode 100644 _sakura/templates/yuuno/forum/forumEntry.tpl create mode 100644 _sakura/templates/yuuno/forum/topicEntry.tpl create mode 100644 _sakura/templates/yuuno/forum/viewforum.tpl diff --git a/_sakura/changelog.json b/_sakura/changelog.json index ba51c70..c5f3f91 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -1301,6 +1301,26 @@ { "type": "UPD", "change": "Put the Forum Listing and Front Page in the same PHP file as they both request nearly identical info (only difference is probably news post/forum posts)." + }, + { + "type": "UPD", + "change": "Changed the die() in the version checker to a trigger_error()." + }, + { + "type": "FIX", + "change": "Fixed an error in the password reset process." + }, + { + "type": "FIX", + "change": "Made some of the functions in the Configuration class more readable." + }, + { + "type": "ADD", + "change": "Added support for infinite subforums." + }, + { + "type": "ADD", + "change": "Added very basic topic list support." } ] diff --git a/_sakura/components/Configuration.php b/_sakura/components/Configuration.php index b6a9969..fb6017a 100644 --- a/_sakura/components/Configuration.php +++ b/_sakura/components/Configuration.php @@ -15,18 +15,27 @@ class Configuration { public static function init($local) { // Check if the configuration file exists - if(!file_exists($local)) + if(!file_exists($local)) { + trigger_error('Local configuration file does not exist', E_USER_ERROR); + } + // Attempt to load the configuration file $local = parse_ini_file($local, true); // Check if $local is an array and then store it in $_LCNF - if(is_array($local)) + if(is_array($local)) { + self::$_LCNF = $local; - else // Otherwise trigger an error + + } else { + + // Otherwise trigger an error trigger_error('Failed to load local configuration file, check the structure of the file to see if you made mistake somewhere', E_USER_ERROR); + } + } /* @@ -42,9 +51,13 @@ class Configuration { // Create variable to temporarily store values in $_DBCN = array(); - foreach($_DATA as $_CONF) // Properly sort the values + // Properly sort the values + foreach($_DATA as $_CONF) { + $_DBCN[$_CONF[0]] = $_CONF[1]; + } + // Assign the temporary array to the static one self::$_DCNF = $_DBCN; @@ -55,13 +68,25 @@ class Configuration { // Check if the key that we're looking for exists if(array_key_exists($key, self::$_LCNF)) { - if($subkey) // If we also have a subkey return the proper shit + + if($subkey) { + + // If we also have a subkey return the proper data return self::$_LCNF[$key][$subkey]; - else // else we just return the default value + + } else { + + // else we just return the default value return self::$_LCNF[$key]; - } else // If it doesn't exist trigger an error to avoid explosions + + } + + } else {// If it doesn't exist trigger an error to avoid explosions + trigger_error('Unable to get local configuration value!', E_USER_ERROR); + } + } // Dynamically set local configuration values, does not update the configuration file @@ -71,25 +96,39 @@ class Configuration { if($subkey) { // If we do we make sure that the parent key is an array - if(!isset(self::$_LCNF[$key])) + if(!isset(self::$_LCNF[$key])) { + self::$_LCNF[$key] = array(); + } + // And then assign the value self::$_LCNF[$key][$subkey] = $value; - } else // Otherwise we just straight up assign it + } else { + + // Otherwise we just straight up assign it self::$_LCNF[$key] = $value; + } + } // Get values from the configuration in the database public static function getConfig($key) { // Check if the key that we're looking for exists - if(array_key_exists($key, self::$_DCNF)) - return self::$_DCNF[$key]; // Then return the value - else // If it doesn't exist trigger an error to avoid explosions - trigger_error('Unable to get configuration value!', E_USER_ERROR); + if(array_key_exists($key, self::$_DCNF)) { + + // Then return the value + return self::$_DCNF[$key]; + + } else { + + // Then return the value + trigger_error('Unable to get configuration value', E_USER_ERROR); + + } } diff --git a/_sakura/components/Forum.php b/_sakura/components/Forum.php index aedcdf7..d30d92a 100644 --- a/_sakura/components/Forum.php +++ b/_sakura/components/Forum.php @@ -7,8 +7,22 @@ namespace Sakura; class Forum { - // Getting the board list - public static function getBoardList() { + // Empty forum template + public static $emptyForum = [ + 'forum_id' => 0, + 'forum_name' => 'Forum', + 'forum_desc' => '', + 'forum_link' => '', + 'forum_category' => 0, + 'forum_type' => 1, + 'forum_posts' => 0, + 'forum_topics' => 0, + 'forum_last_post_id' => 0, + 'forum_last_poster_id' => 0 + ]; + + // Getting the forum list + public static function getForumList() { // Get the content from the database $forums = Database::fetch('forums'); @@ -16,18 +30,7 @@ class Forum { // Create return array $return = [ 0 => [ - 'data' => [ - 'forum_id' => 0, - 'forum_name' => 'Forum', - 'forum_desc' => '', - 'forum_link' => '', - 'forum_category' => 0, - 'forum_type' => 1, - 'forum_posts' => 0, - 'forum_topics' => 0, - 'forum_last_post_id' => 0, - 'forum_last_poster_id' => 0 - ], + 'forum' => self::$emptyForum, 'forums' => [] ] ]; @@ -36,16 +39,20 @@ class Forum { foreach($forums as $forum) { // If the forum type is a category create a new one - if($forum['forum_type'] == 1) - $return[$forum['forum_id']]['data'] = $forum; - else { + if($forum['forum_type'] == 1) { + + $return[$forum['forum_id']]['forum'] = $forum; + + } else { // For link and reg. forum add it to the category $return[$forum['forum_category']]['forums'][$forum['forum_id']] = $forum; // Add last poster data and the details about the post as well - $return[$forum['forum_category']]['forums'][$forum['forum_id']]['last_poster_data'] = ($_LAST_POSTER = Users::getUser($forum['forum_last_poster_id'])); - $return[$forum['forum_category']]['forums'][$forum['forum_id']]['last_poster_rank'] = Users::getRank($_LAST_POSTER['rank_main']); + $return[$forum['forum_category']]['forums'][$forum['forum_id']]['last_poster'] = [ + 'user' => ($_LAST_POSTER = Users::getUser($forum['forum_last_poster_id'])), + 'rank' => Users::getRank($_LAST_POSTER['rank_main']) + ]; } @@ -56,8 +63,108 @@ class Forum { } + // Get a forum or category + public static function getForum($id) { + + // Get the forumlist from the database + $forums = Database::fetch('forums'); + + // Sneak the template in the array + $forums['fb'] = self::$emptyForum; + + // Create an array to store the forum once we found it + $forum = []; + + // Try to find the requested forum + foreach($forums as $list) { + + // Once found set $forum to $list and break the loop + if($list['forum_id'] == $id) { + + $forum['forum'] = $list; + break; + + } + + } + + // If $forum is still empty after the foreach return false + if(empty($forum)) + return false; + + // Create conditions for fetching the forums + $conditions['forum_category'] = [$id, '=']; + + // If the current category is 0 (the built in fallback) prevent getting categories + if($id == 0) + $conditions['forum_type'] = ['1', '!=']; + + // Check if this forum/category has any subforums + $forum['forums'] = Database::fetch('forums', true, $conditions); + + // Get the userdata related to last posts + foreach($forum['forums'] as $key => $sub) { + + $forum['forums'][$key]['last_poster'] = [ + 'user' => ($_LAST_POSTER = Users::getUser($sub['forum_last_poster_id'])), + 'rank' => Users::getRank($_LAST_POSTER['rank_main']) + ]; + + } + + // Lastly grab the topics for this forum + $forum['topics'] = Database::fetch('topics', true, [ + 'forum_id' => [$id, '='] + ]); + + // Get the userdata related to first and last posts + foreach($forum['topics'] as $key => $topic) { + + $forum['topics'][$key]['first_poster'] = [ + 'user' => ($_FIRST_POSTER = Users::getUser($topic['topic_first_poster_id'])), + 'rank' => Users::getRank($_FIRST_POSTER['rank_main']) + ]; + + $forum['topics'][$key]['last_poster'] = [ + 'user' => ($_LAST_POSTER = Users::getUser($topic['topic_last_poster_id'])), + 'rank' => Users::getRank($_LAST_POSTER['rank_main']) + ]; + + } + + // Return the forum/category + return $forum; + + } + + // Getting all topics from a forum + public static function getTopics($id) { + + $topics = Database::fetch('topics', true, [ + 'forum_id' => [$id, '='] + ]); + + // Get the userdata related to last posts + foreach($topics as $key => $topic) { + + $topics[$key]['first_poster'] = [ + 'user' => ($_FIRST_POSTER = Users::getUser($topic['topic_first_poster_id'])), + 'rank' => Users::getRank($_FIRST_POSTER['rank_main']) + ]; + + $topics[$key]['last_poster'] = [ + 'user' => ($_LAST_POSTER = Users::getUser($topic['topic_last_poster_id'])), + 'rank' => Users::getRank($_LAST_POSTER['rank_main']) + ]; + + } + + return $topics; + + } + // Creating a new post - public static function createPost($subject, $text, $enableMD, $enableSig, $forum, $topic = 0, $type = 0, $status = 0) { + public static function createPost($subject, $text, $enableMD, $enableSig, $forum, $type = 0, $status = 0) { // Check if this post is OP if(!$topic) { diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index fa4bddc..8acd0de 100644 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -18,7 +18,7 @@ class Main { // Stop the execution if the PHP Version is older than 5.4.0 if(version_compare(phpversion(), '5.4.0', '<')) - die('

Upgrade your PHP Version to at least PHP 5.4!

'); + trigger_error('Sakura requires at least PHP 5.4.0, please upgrade to a newer PHP version.'); // Configuration Management and local configuration Configuration::init($config); diff --git a/_sakura/templates/yuuno/forum/forum.tpl b/_sakura/templates/yuuno/forum/forum.tpl new file mode 100644 index 0000000..7e777ef --- /dev/null +++ b/_sakura/templates/yuuno/forum/forum.tpl @@ -0,0 +1,35 @@ +
Forums{% if board.viewforum %} / {{ board.forums[0].forum.forum_name }}{% endif %}
+ + + {% for category in board.forums %} + {% include 'forum/forumEntry.tpl' %} + {% endfor %} + +
+{% if board.viewforum %} + + + + + + + + + + + + + + + + + + + + + {% for topic in board.topics %} + {% include 'forum/topicEntry.tpl' %} + {% endfor %} + +
TopicAuthorLast post
TopicAuthorLast post
+{% endif %} diff --git a/_sakura/templates/yuuno/forum/forumEntry.tpl b/_sakura/templates/yuuno/forum/forumEntry.tpl new file mode 100644 index 0000000..c51d601 --- /dev/null +++ b/_sakura/templates/yuuno/forum/forumEntry.tpl @@ -0,0 +1,41 @@ +{% if category.forums|length and category.forum|length %} + + {% if category.forum.forum_type != 1 %}Subforums{% else %}{{ category.forum.forum_name }}{% endif %} + + {% for forum in category.forums %} + + +
+ + +
{{ forum.forum_name }}
+
+ {{ forum.forum_desc }} + {% if board.forums[forum.forum_id]|length %} +
+ Subforums: + {% for forum in board.forums[forum.forum_id].forums %} + {{ forum.forum_name }} + {% endfor %} +
+ {% endif %} +
+ + {% if forum.forum_type != 2 %} + +
{{ forum.forum_topics }}
+
{{ forum.forum_posts }}
+ + +
+ {% if forum.forum_last_post_id %} + Last post in Thread with an obnoxiously long fucking title
12 years ago by {{ forum.last_poster.user.username }} + {% else %} + There are no posts in this forum.
  + {% endif %} +
+ + {% endif %} + + {% endfor %} +{% endif %} diff --git a/_sakura/templates/yuuno/forum/index.tpl b/_sakura/templates/yuuno/forum/index.tpl index c9aefeb..eed9a21 100644 --- a/_sakura/templates/yuuno/forum/index.tpl +++ b/_sakura/templates/yuuno/forum/index.tpl @@ -4,44 +4,7 @@ {% include 'elements/indexPanel.tpl' %}
-
Forums
- - - {% for category in page.boards %} - {% if category.forums|length %} - - - - {% for forum in category.forums %} - - - - {% if forum.forum_type != 2 %} - - - {% endif %} - - {% endfor %} - {% endif %} - {% endfor %} - -
{{ category.data.forum_name }}
-
-
- -
{{ forum.forum_desc }}
-
-
{{ forum.forum_topics }}
-
{{ forum.forum_posts }}
-
-
- {% if forum.forum_last_post_id %} - Last post in Thread with an obnoxiously long fucking title
12 years ago by {{ forum.last_poster_data.username }} - {% else %} - There are no posts in this forum.
  - {% endif %} -
-
+ {% include 'forum/forum.tpl' %}
diff --git a/_sakura/templates/yuuno/forum/topicEntry.tpl b/_sakura/templates/yuuno/forum/topicEntry.tpl new file mode 100644 index 0000000..88fb59b --- /dev/null +++ b/_sakura/templates/yuuno/forum/topicEntry.tpl @@ -0,0 +1,19 @@ + + +
+ + + {{ topic.topic_title }} + + + {{ topic.first_poster.user.username }} + + +
{{ topic.topic_replies }}
+
{{ topic.topic_views }}
+ + + {{ topic.last_poster.user.username }}
+ 2000 years ago + + \ No newline at end of file diff --git a/_sakura/templates/yuuno/forum/viewforum.tpl b/_sakura/templates/yuuno/forum/viewforum.tpl new file mode 100644 index 0000000..53f5eaf --- /dev/null +++ b/_sakura/templates/yuuno/forum/viewforum.tpl @@ -0,0 +1,7 @@ +{% include 'global/header.tpl' %} +
+
+ {% include 'forum/forum.tpl' %} +
+
+{% include 'global/footer.tpl' %} diff --git a/content/data/yuuno/css/yuuno.css b/content/data/yuuno/css/yuuno.css index 4e26f5b..30ff589 100644 --- a/content/data/yuuno/css/yuuno.css +++ b/content/data/yuuno/css/yuuno.css @@ -331,6 +331,8 @@ a.gotop.exit { .content-left .head, .news .head, .donate .head, +.viewforum .head, +.viewtopic .head, .loginPage > .loginCont .head, .messages .head { margin: -1px -2px; @@ -1558,3 +1560,50 @@ textarea.inputStyling { .forum .forumList .forumForum .forumTitleColumn div { padding-left: 5px; } + +.forum .topicList { + width: 100%; + border-spacing: 0; + margin-top: 2px; +} + +.forum .topicList thead, +.forum .topicList tfoot { + background: #C2AFFE; + font-weight: 700; +} + +.forum .topicList tbody td { + height: 40px; +} + +.forum .topicList tbody .topicIcon { + width: 40px; + text-align: center; +} + +.forum .topicList tbody .topicAuthor { + width: 150px; + text-align: center; +} + +.forum .topicList tbody .topicCounts { + text-align: center; +} + +.forum .topicList tbody .topicCounts .replies { + font-size: 1.3em; + color: #111; + line-height: 1.3em; +} + +.forum .topicList tbody .topicCounts .views { + font-size: .8em; + color: #555; + line-height: 1em; +} + +.forum .topicList tbody .topicLast { + width: 250px; + text-align: center; +} diff --git a/main/.htaccess b/main/.htaccess index fdc457d..94e713d 100644 --- a/main/.htaccess +++ b/main/.htaccess @@ -71,8 +71,9 @@ RewriteRule ^bg/([0-9]+)$|bg/([0-9]+).png$ imageserve.php?m=background&u=$1 [L,Q # Forum RewriteRule ^forum/?$ index.php?forums=true [L,QSA] -RewriteRule ^forum/([0-9]+)/?$ viewforum.php?id=$2 [L,QSA] +RewriteRule ^forum/([0-9]+)/?$ viewforum.php?id=$1 [L,QSA] RewriteRule ^forum/(thread|topic|[0-9+])/([0-9]+)/?$ viewtopic.php?id=$2 [L,QSA] +RewriteRule ^forum/post/([0-9]+)/?$ viewtopic.php?pid=$1 [L,QSA] # Management RewriteRule ^manage/?$ manage.php [L,QSA] diff --git a/main/index.php b/main/index.php index 67581ea..7a38db1 100644 --- a/main/index.php +++ b/main/index.php @@ -15,15 +15,21 @@ $forumMode = isset($_GET['forums']) ? ($_GET['forums'] == true) : false; // Add page specific things $renderData['newsPosts'] = ($forumMode ? null : Main::getNewsPosts(3)); + $renderData['page'] = [ - 'title' => ($forumMode ? 'Forum Listing' : Configuration::getConfig('sitename')), - 'boards' => ($forumMode ? Forum::getBoardList() : null) + 'title' => ($forumMode ? 'Forum Listing' : Configuration::getConfig('sitename')) ]; + +$renderData['board'] = [ + 'forums' => ($forumMode ? Forum::getForumList() : null), + 'viewforum' => false +]; + $renderData['stats'] = [ - 'userCount' => ($_INDEX_USER_COUNT = count($_INDEX_USERS = Users::getAllUsers(false))) .' user'. ($_INDEX_USER_COUNT == 1 ? '' : 's'), - 'newestUser' => ($_INDEX_NEWEST_USER = max($_INDEX_USERS)), - 'lastRegDate' => ($_INDEX_LAST_REGDATE = date_diff(date_create(date('Y-m-d', $_INDEX_NEWEST_USER['regdate'])), date_create(date('Y-m-d')))->format('%a')) .' day'. ($_INDEX_LAST_REGDATE == 1 ? '' : 's'), - 'chatOnline' => ($_INDEX_CHAT_ONLINE = count(SockChat::getOnlineUsers())) .' user'. ($_INDEX_CHAT_ONLINE == 1 ? '' : 's'), + 'userCount' => ($_INDEX_USER_COUNT = count($_INDEX_USERS = Users::getAllUsers(false))) .' user'. ($_INDEX_USER_COUNT == 1 ? '' : 's'), + 'newestUser' => ($_INDEX_NEWEST_USER = max($_INDEX_USERS)), + 'lastRegDate' => ($_INDEX_LAST_REGDATE = date_diff(date_create(date('Y-m-d', $_INDEX_NEWEST_USER['regdate'])), date_create(date('Y-m-d')))->format('%a')) .' day'. ($_INDEX_LAST_REGDATE == 1 ? '' : 's'), + 'chatOnline' => ($_INDEX_CHAT_ONLINE = count(SockChat::getOnlineUsers())) .' user'. ($_INDEX_CHAT_ONLINE == 1 ? '' : 's'), 'onlineUsers' => Users::checkAllOnline(), 'topicCount' => '0 topics', 'postCount' => '0 posts' diff --git a/main/viewforum.php b/main/viewforum.php index 15a7460..a86f285 100644 --- a/main/viewforum.php +++ b/main/viewforum.php @@ -8,3 +8,55 @@ namespace Sakura; // Include components require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) .'_sakura/sakura.php'; + +// Get the forum's data +$forum = Forum::getForum(isset($_GET['id']) ? $_GET['id'] : 0); + +// Check if the forum exists +if(!$forum) { + + // Set render data + $renderData['page'] = [ + 'title' => 'Information', + 'message' => 'The subforum you tried to access does not exist.' + ]; + + // Print template + print Templates::render('errors/information.tpl', $renderData); + exit; + +} + +// Check if the forum isn't a link +if($forum['forum']['forum_type'] === 2) { + + // Set render data + $renderData['page'] = [ + 'title' => 'Information', + 'message' => 'The forum you tried to access is a link. You\'re being redirected.', + 'redirect' => $forum['forum']['forum_link'] + ]; + + // Print template + print Templates::render('errors/information.tpl', $renderData); + exit; + +} + +$renderData['page'] = [ + 'title' => 'Forums / '. $forum['forum']['forum_name'] +]; + +$renderData['board'] = [ + 'forums' => [ + $forum + ], + 'topics' => Forum::getTopics($forum['forum']['forum_id']), + 'viewforum' => true +]; + +//header('Content-Type: text/plain'); +//print_r($renderData['board']['topics']);exit; + +// Print page contents +print Templates::render('forum/viewforum.tpl', $renderData); diff --git a/main/viewtopic.php b/main/viewtopic.php index 2a2d105..8e08629 100644 --- a/main/viewtopic.php +++ b/main/viewtopic.php @@ -8,4 +8,3 @@ namespace Sakura; // Include components require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) .'_sakura/sakura.php'; -print 'THIS IS VIEWTOPIC'; \ No newline at end of file