diff --git a/.gitignore b/.gitignore index 81bfaf3..04e92a0 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/ +.vs/ errors.log _sakura/config/config.ini BingSiteAuth.xml @@ -12,3 +13,4 @@ ehthumbs.db Desktop.ini $RECYCLE.BIN/ .DS_Store +*.phpproj diff --git a/_sakura/components/Forum.php b/_sakura/components/Forum.php index df4a7e7..5f2be81 100644 --- a/_sakura/components/Forum.php +++ b/_sakura/components/Forum.php @@ -11,5 +11,4 @@ namespace Sakura; */ class Forum { - } diff --git a/_sakura/components/Permissions.php b/_sakura/components/Permissions.php index c221629..db45871 100755 --- a/_sakura/components/Permissions.php +++ b/_sakura/components/Permissions.php @@ -162,7 +162,7 @@ class Permissions $userPerms = Database::fetch('permissions', false, ['rank_id' => [0, '='], 'user_id' => [$user->id(), '=']]); // Get their rank permissions - $rankPerms = self::getRankPermissions(json_decode($user->ranks(), true)); + $rankPerms = self::getRankPermissions($user->ranks()); // Just return the rank permissions if no special ones are set if (empty($userPerms)) { diff --git a/_sakura/components/User.php b/_sakura/components/User.php index 729259e..0e73d7d 100755 --- a/_sakura/components/User.php +++ b/_sakura/components/User.php @@ -12,7 +12,29 @@ namespace Sakura; class User { // User data - private $data = []; + private $data = [ + 'user_id' => 0, + 'username' => 'User', + 'username_clean' => 'user', + 'password_hash' => '', + 'password_salt' => '', + 'password_algo' => 'nologin', + 'password_iter' => 0, + 'password_chan' => 0, + 'password_new' => '', + 'email' => 'sakura@localhost', + 'rank_main' => 0, + 'user_ranks' => '[0]', + 'user_colour' => '', + 'register_ip' => '127.0.0.1', + 'last_ip' => '127.0.0.1', + 'user_title' => '', + 'user_registered' => 0, + 'user_last_online' => 0, + 'user_birthday' => '', + 'user_country' => 'XX', + 'user_data' => '[]', + ]; private $ranks = []; private $mainRank = []; @@ -20,7 +42,7 @@ class User public function __construct($uid) { // Get the user database row - $this->data = Database::fetch( + $getUser = Database::fetch( 'users', false, [ @@ -30,17 +52,17 @@ class User ); // Check if the user actually exists - if (empty($this->data)) { + if (!empty($getUser)) { // If not assign as the fallback user - $this->data = Users::$emptyUser; + $this->data = $getUser; } // Decode the json in the user_data column $this->data['user_data'] = json_decode(!empty($this->data['user_data']) ? $this->data['user_data'] : '[]', true); - $this->data['ranks'] = json_decode($this->data['user_ranks'], true); + $this->data['user_ranks'] = json_decode($this->data['user_ranks'], true); // Get the rows for all the ranks - foreach ($this->data['ranks'] as $rank) { + foreach ($this->data['user_ranks'] as $rank) { // Store the database row in the array $this->ranks[$rank] = new Rank($rank); } @@ -169,11 +191,33 @@ class User return $times; } - // Check if the user has the specified ranks - public function checkIfUserHasRanks($ranks) - { + // Set the main rank of this user + public function setMainRank($rank) + { + // Only allow this if this rank is actually present in their set of ranks + if (!in_array($rank, $this->ranks())) { + return false; + } + + // If it does exist update their row + Database::update('user', [ + [ + 'rank_main' => $rank, + ], + [ + 'user_id' => [$this->id(), '='], + ], + ]); + + // Return true if everything was successful + return true; + } + + // Check if this user has the specified ranks + public function hasRanks($ranks) + { // Check if the main rank is the specified rank - if ($this->mainRank->id() === $ranks) { + if (in_array($this->mainRank->id(), $ranks)) { return true; } @@ -187,6 +231,12 @@ class User // If all fails return false return false; + } + + // For compatibility, too lazy to update the references right now! + public function checkIfUserHasRanks($ranks) + { + return $this->hasRanks($ranks); } // Add a new friend @@ -308,12 +358,12 @@ class User // If there's nothing just return null if (!count($profileFields)) { - return; + return []; } // Once again if nothing was returned just return null if (empty($this->data['user_data']['profileFields'])) { - return; + return []; } // Create output array @@ -374,12 +424,12 @@ class User // If there's nothing just return null if (!count($optionFields)) { - return; + return []; } // Once again if nothing was returned just return null if (empty($this->data['user_data']['userOptions'])) { - return; + return []; } // Create output array @@ -670,4 +720,23 @@ class User // Return success return [1, 'SUCCESS']; } + + // Update a user's userData + public function setUserData($data) { + // Merge the arrays + $data = array_merge($this->userData(), $data); + + // Encode it + $data = json_encode($data); + + // Save it in the database + Database::update('users', [ + [ + 'user_data' => $data, + ], + [ + 'user_id' => [$this->id(), '='], + ], + ]); + } } diff --git a/_sakura/components/Users.php b/_sakura/components/Users.php index 228ea3b..f71c68e 100755 --- a/_sakura/components/Users.php +++ b/_sakura/components/Users.php @@ -11,31 +11,6 @@ namespace Sakura; */ class Users { - // Empty user template - public static $emptyUser = [ - 'user_id' => 0, - 'username' => 'User', - 'username_clean' => 'user', - 'password_hash' => '', - 'password_salt' => '', - 'password_algo' => 'nologin', - 'password_iter' => 1000, - 'password_chan' => 0, - 'password_new' => '', - 'email' => 'sakura@localhost', - 'rank_main' => 0, - 'user_ranks' => '[0]', - 'user_colour' => '', - 'register_ip' => '127.0.0.1', - 'last_ip' => '127.0.0.1', - 'user_title' => '', - 'user_registered' => 0, - 'user_last_online' => 0, - 'user_birthday' => '', - 'user_country' => 'XX', - 'user_data' => '[]', - ]; - // Empty rank template public static $emptyRank = [ 'rank_id' => 0, @@ -695,34 +670,12 @@ class Users // Set the default rank of a user public static function setDefaultRank($uid, $rid, $userIdIsUserData = false) { - // Get the specified user - $user = new User($uid); - - // Check if the rank we're trying to set is actually there - if (!in_array($rid, $user->ranks())) { - return false; - } - - // Update the row - Database::update('users', [ - [ - 'rank_main' => $rid, - ], - [ - 'user_id' => [$uid, '='], - ], - ]); - - // Return true if everything was successful - return true; + return (new User($uid))->setMainRank($rid); } // Add a rank to a user public static function addRanksToUser($ranks, $uid, $userIdIsUserData = false) { - // Get the specified user - $user = new User($uid); - // Define $current $current = []; @@ -757,6 +710,8 @@ class Users // Get the specified user $user = new User($uid); + $current = $user->ranks(); + // Check the current ranks for ranks in the set array foreach ($current as $key => $rank) { // Unset the rank @@ -853,103 +808,6 @@ class Users return $fields; } - // Get user's profile fields - public static function getUserProfileFields($id, $inputIsData = false) - { - // Get profile fields - $profileFields = Database::fetch('profilefields'); - - // If there's nothing just return null - if (!count($profileFields)) { - return null; - } - - // Assign the profileData variable - $profileData = ($inputIsData ? $id : (new User($id))->userData()); - - // Once again if nothing was returned just return null - if (count($profileData) < 1 || $profileData == null || empty($profileData['profileFields'])) { - return null; - } - - // Redeclare profileData - $profileData = $profileData['profileFields']; - - // 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, $profileData)) { - continue; - } - - // Assign field to output with value - $profile[$fieldName] = []; - $profile[$fieldName]['name'] = $field['name']; - $profile[$fieldName]['value'] = $profileData[$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 }}', $profileData[$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, $profileData)) { - continue; - } - - // Assign field to output with value - $profile[$fieldName][$subName] = $profileData[$subName]; - } - } - } - - // Return appropiate profile data - return $profile; - } - - // Updating the profile data of a user - public static function updateUserDataField($id, $data) - { - // We retrieve the current content from the database - $current = (new User($id))->userData(); - - // Merge the arrays - $data = array_merge($current, $data); - - // Encode the json - $data = json_encode($data); - - // Store it in the database - Database::update('users', [ - [ - 'user_data' => $data, - ], - [ - 'user_id' => [$id, '='], - ], - ]); - } - - // Check if a user is online - public static function checkUserOnline($id) - { - return (new User($id))->checkOnline(); - } - // Get all online users public static function checkAllOnline() { @@ -1094,7 +952,7 @@ class Users // Go over all users and check if they have the rank id foreach ($users as $user) { // If so store the user's row in the array - if (self::checkIfUserHasRanks([$rankId], $user, true) + if (self::checkIfUserHasRanks([$rankId], $user->id()) && ($excludeAbyss ? $user->password()['password_algo'] != 'nologin' : true)) { $rank[] = $user; } @@ -1270,7 +1128,7 @@ class Users // Check each user foreach ($friends as $key => $friend) { $friends[ - self::checkUserOnline($getData ? $friend['user']->id() : $friend) ? 'online' : 'offline' + (new User($getData ? $friend['user']->id() : $friend))->checkOnline() ? 'online' : 'offline' ][] = $friend; } } diff --git a/_sakura/sakura.php b/_sakura/sakura.php index a5f1c26..294e83c 100755 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20151107'); +define('SAKURA_VERSION', '20151108'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); diff --git a/_sakura/templates/yuuno/elements/indexPanel.tpl b/_sakura/templates/yuuno/elements/indexPanel.tpl index ee11ce8..1fa4539 100755 --- a/_sakura/templates/yuuno/elements/indexPanel.tpl +++ b/_sakura/templates/yuuno/elements/indexPanel.tpl @@ -25,7 +25,7 @@ {% endif %}