diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 80b29bb..032d7de 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -43,7 +43,8 @@ "20150811", "20150812", "20150813", - "20150818" + "20150818", + "20150819" ] @@ -2032,6 +2033,36 @@ "user": "Flashwave" } + ], + + "20150819": [ + + { + "type": "UPD", + "change": "Only make the SQL library fetch an associative array since the numbered one is not used anywhere.", + "user": "Flashwave" + }, + { + "type": "FIX", + "change": "Fixed the lie in the previous change changing the __only__ use of it to associative.", + "user": "Flashwave" + }, + { + "type": "ADD", + "change": "Begin work on a User class (different from the Users class) to easily get a user's data in a usable state.", + "user": "Flashwave" + }, + { + "type": "FIX", + "change": "Fixed incorrect counting on the List view in the memberlist (how did I miss this for 4 months?).", + "user": "Flashwave" + }, + { + "type": "UPD", + "change": "Converted most of profile.php to the new user API.", + "user": "Flashwave" + } + ] } diff --git a/_sakura/components/Configuration.php b/_sakura/components/Configuration.php index 2b3c175..534edca 100644 --- a/_sakura/components/Configuration.php +++ b/_sakura/components/Configuration.php @@ -54,7 +54,7 @@ class Configuration { // Properly sort the values foreach($_DATA as $_CONF) { - $_DBCN[$_CONF[0]] = $_CONF[1]; + $_DBCN[$_CONF['config_name']] = $_CONF['config_value']; } diff --git a/_sakura/components/User.php b/_sakura/components/User.php index 96cdb8b..f9e27c2 100644 --- a/_sakura/components/User.php +++ b/_sakura/components/User.php @@ -8,20 +8,153 @@ namespace Sakura; class User { // User data - public $user = []; - private $ranks = []; + public $data = []; + public $ranks = []; + public $mainRank = []; - // Initialise the user - function __contruct($id) { + // Initialise the user object + function __construct($id) { // Get the user database row - $this->user = Database::fetch('users', false, ['id' => [$id, '=']]); + $this->data = Database::fetch('users', false, ['id' => [$id, '=']]); + + // Check if the user actually exists + if(empty($this->data)) { + + // If not assign as the fallback user + $this->data = Users::$emptyUser; + + } + + // Decode the json in the userData column + $this->data['userData'] = json_decode(!empty($this->data['userData']) ? $this->data['userData'] : '[]', true); // Decode the ranks json array - $ranks = json_decode($this->user['ranks'], true); + $ranks = json_decode($this->data['ranks'], true); // Get the rows for all the ranks - $this->ranks[] = Database::fetch('ranks', false, ['id' => [$id, '=']]); + foreach($ranks as $rank) { + + // Store the database row in the array + $this->ranks[$rank] = Database::fetch('ranks', false, ['id' => [$rank, '=']]); + + } + + // Check if ranks were set + if(empty($this->ranks)) { + + // If not assign the fallback rank + $this->ranks[0] = Users::$emptyRank; + + } + + // Assign the user's main rank to a special variable since we'll use it a lot + $this->mainRank = $this->ranks[array_key_exists($this->data['rank_main'], $this->ranks) ? $this->data['rank_main'] : array_keys($this->ranks)[0]]; + + } + + // Get the user's colour + public function colour() { + + return empty($this->data['name_colour']) ? $this->mainRank['colour'] : $this->data['name_colour']; + + } + + // Get the user's title + public function userTitle() { + + return empty($this->data['usertitle']) ? $this->mainRank['title'] : $this->data['usertitle']; + + } + + // Get the user's long and short country names + public function country() { + + return [ + + 'long' => Main::getCountryName($this->data['country']), + 'short' => $this->data['country'] + + ]; + + } + + // Get the user's profile fields + public function profileFields() { + + // Get profile fields + $profileFields = Database::fetch('profilefields'); + + // If there's nothing just return null + if(!count($profileFields)) { + + return; + + } + + // Once again if nothing was returned just return null + if(empty($this->data['userData']['profileFields'])) { + + return; + + } + + // Create output array + $profile = []; + + // Check if profile fields aren't fake + foreach($profileFields as $field) { + + // Completely strip all special characters from the field name + $fieldName = Main::cleanString($field['name'], true, true); + + // Check if the user has the current field set otherwise continue + if(!array_key_exists($fieldName, $this->data['userData']['profileFields'])) { + + continue; + + } + + // Assign field to output with value + $profile[$fieldName] = array(); + $profile[$fieldName]['name'] = $field['name']; + $profile[$fieldName]['value'] = $this->data['userData']['profileFields'][$fieldName]; + $profile[$fieldName]['islink'] = $field['islink']; + + // If the field is set to be a link add a value for that as well + if($field['islink']) { + + $profile[$fieldName]['link'] = str_replace('{{ VAL }}', $this->data['userData']['profileFields'][$fieldName], $field['linkformat']); + + } + + // Check if we have additional options as well + if($field['additional'] != null) { + + // Decode the json of the additional stuff + $additional = json_decode($field['additional'], true); + + // Go over all additional forms + foreach($additional as $subName => $subField) { + + // Check if the user has the current field set otherwise continue + if(!array_key_exists($subName, $this->data['userData']['profileFields'])) { + + continue; + + } + + // Assign field to output with value + $profile[$fieldName][$subName] = $this->data['userData']['profileFields'][$subName]; + + } + + } + + } + + // Return appropiate profile data + return $profile; } diff --git a/_sakura/components/database/mysql.php b/_sakura/components/database/mysql.php index c19d355..6a14b0a 100644 --- a/_sakura/components/database/mysql.php +++ b/_sakura/components/database/mysql.php @@ -19,7 +19,7 @@ class MySQL { // Constructor function __construct() { - + if(!extension_loaded('PDO')) { // Return error and die trigger_error('PDO extension not loaded.', E_USER_ERROR); @@ -51,25 +51,25 @@ class MySQL { // Regular IP/Hostname connection method prepare function private function prepareHost($dbHost, $dbName, $dbPort = 3306) { - + $DSN = 'mysql:host=' . $dbHost . ';port=' . $dbPort . ';dbname=' . $dbName; return $DSN; - + } // Unix Socket connection method prepare function private function prepareSock($dbHost, $dbName) { - + $DSN = 'mysql:unix_socket=' . $dbHost . ';dbname=' . $dbName; return $DSN; - + } // Initialise connection using default PDO stuff private function initConnect($DSN, $dbUname, $dbPword) { - + try { // Connect to SQL server using PDO $this->sql = new PDO($DSN, $dbUname, $dbPword, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING)); @@ -77,9 +77,9 @@ class MySQL { // Catch connection errors trigger_error('SQL Driver: '. $e->getMessage(), E_USER_ERROR); } - + return true; - + } // Fetch array from database @@ -124,7 +124,7 @@ class MySQL { $prepare .= ' ORDER BY `'. $order[0] .'`'. (!empty($order[1]) && $order[1] ? ' DESC' : ''); } - + // If $limit is set and is an array continue if(is_array($limit)) { @@ -163,7 +163,7 @@ class MySQL { $query->execute(); // Return the output - return $fetchAll ? $query->fetchAll(PDO::FETCH_BOTH) : $query->fetch(PDO::FETCH_BOTH); + return $fetchAll ? $query->fetchAll(PDO::FETCH_ASSOC) : $query->fetch(PDO::FETCH_ASSOC); } diff --git a/_sakura/sakura.php b/_sakura/sakura.php index 1a47efc..17ebe5d 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20150818'); +define('SAKURA_VERSION', '20150819'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); diff --git a/_sakura/templates/yuuno/main/memberlist.tpl b/_sakura/templates/yuuno/main/memberlist.tpl index 8a35d3e..68110ee 100644 --- a/_sakura/templates/yuuno/main/memberlist.tpl +++ b/_sakura/templates/yuuno/main/memberlist.tpl @@ -48,7 +48,7 @@