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('
+ | Topic | +Author | ++ | Last post | +
---|---|---|---|---|
+ | Topic | +Author | ++ | Last post | +
{{ category.data.forum_name }} | -|||||
- - | -
-
- {{ forum.forum_desc }}
- |
- {% 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_data.username }} - {% else %} - There are no posts in this forum. - {% endif %} - |
- {% endif %}
-