Users.php delete soon

This commit is contained in:
flash 2016-02-05 12:20:33 +01:00
parent 7bf64954ec
commit 264fe683d5
4 changed files with 109 additions and 103 deletions

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Holds the user page controllers. * Holds the user page controllers.
* *
* @package Sakura * @package Sakura
*/ */
@ -9,23 +9,24 @@ namespace Sakura\Controllers;
use Sakura\Config; use Sakura\Config;
use Sakura\Database; use Sakura\Database;
use Sakura\Rank;
use Sakura\Template; use Sakura\Template;
use Sakura\User as UserContext; use Sakura\User as UserContext;
use Sakura\Utils; use Sakura\Utils;
/** /**
* Everything that is just for serving user data. * Everything that is just for serving user data.
* *
* @package Sakura * @package Sakura
* @author Julian van de Groep <me@flash.moe> * @author Julian van de Groep <me@flash.moe>
*/ */
class User class User
{ {
/** /**
* Display the profile of a user * Display the profile of a user.
* *
* @param mixed $id The user ID. * @param mixed $id The user ID.
* *
* @return bool|string The profile page. * @return bool|string The profile page.
*/ */
public static function profile($id = 0) public static function profile($id = 0)
@ -39,7 +40,7 @@ class User
if ($profile->id == 0) { if ($profile->id == 0) {
// Fetch from username_history // Fetch from username_history
$check = Database::fetch('username_history', false, ['username_old_clean' => [Utils::cleanString(isset($_GET['u']) ? $_GET['u'] : 0, true, true), '=']]); $check = Database::fetch('username_history', false, ['username_old_clean' => [Utils::cleanString(isset($_GET['u']) ? $_GET['u'] : 0, true, true), '=']]);
// Redirect if so // Redirect if so
if ($check) { if ($check) {
Template::vars([ Template::vars([
@ -85,6 +86,13 @@ class User
return Template::render('main/profile'); return Template::render('main/profile');
} }
/**
* Display the memberlist.
*
* @param int $rank Optional rank ID.
*
* @return bool|string The memberlist.
*/
public static function members($rank = 0) public static function members($rank = 0)
{ {
global $currentUser; global $currentUser;
@ -99,7 +107,7 @@ class User
'memberlist' => [ 'memberlist' => [
'ranks' => ($_MEMBERLIST_RANKS = \Sakura\Users::getAllRanks()), 'ranks' => ($_MEMBERLIST_RANKS = \Sakura\Users::getAllRanks()),
'active' => ($_MEMBERLIST_ACTIVE = (array_key_exists($rank, $_MEMBERLIST_RANKS) ? $rank : 0)), 'active' => ($_MEMBERLIST_ACTIVE = (array_key_exists($rank, $_MEMBERLIST_RANKS) ? $rank : 0)),
'users' => ($_MEMBERLIST_ACTIVE ? \Sakura\Users::getUsersInRank($_MEMBERLIST_ACTIVE) : \Sakura\Users::getAllUsers(false)), 'users' => ($_MEMBERLIST_ACTIVE ? Rank::construct($_MEMBERLIST_ACTIVE)->users() : \Sakura\Users::getAllUsers(false)),
'membersPerPage' => Config::get('members_per_page'), 'membersPerPage' => Config::get('members_per_page'),
] ]
]); ]);

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Holds the rank object class. * Holds the rank object class.
* *
* @package Sakura * @package Sakura
*/ */
@ -12,7 +12,7 @@ use Sakura\Perms\Site;
/** /**
* Serves Rank data. * Serves Rank data.
* *
* @package Sakura * @package Sakura
* @author Julian van de Groep <me@flash.moe> * @author Julian van de Groep <me@flash.moe>
*/ */
@ -20,80 +20,80 @@ class Rank
{ {
/** /**
* ID of the rank. * ID of the rank.
* *
* @var int * @var int
*/ */
public $id = 0; public $id = 0;
/** /**
* Name of the rank. * Name of the rank.
* *
* @var string * @var string
*/ */
public $name = 'Rank'; public $name = 'Rank';
/** /**
* Global hierarchy of the rank. * Global hierarchy of the rank.
* *
* @var int * @var int
*/ */
public $hierarchy = 0; public $hierarchy = 0;
/** /**
* Text that should be append to the name to make it address multiple. * Text that should be append to the name to make it address multiple.
* *
* @var string * @var string
*/ */
public $multiple = ''; public $multiple = '';
/** /**
* The rank's username colour. * The rank's username colour.
* *
* @var string * @var string
*/ */
public $colour = 'inherit'; public $colour = 'inherit';
/** /**
* Description of the rank. * Description of the rank.
* *
* @var string * @var string
*/ */
public $description = ''; public $description = '';
/** /**
* User title of the rank. * User title of the rank.
* *
* @var string * @var string
*/ */
public $title = ''; public $title = '';
/** /**
* Indicates if this rank should be hidden. * Indicates if this rank should be hidden.
* *
* @var bool * @var bool
*/ */
private $hidden = true; private $hidden = true;
/** /**
* Permission container. * Permission container.
* *
* @var Perms * @var Perms
*/ */
private $permissions; private $permissions;
/** /**
* Instance cache container. * Instance cache container.
* *
* @var array * @var array
*/ */
protected static $_rankCache = []; protected static $_rankCache = [];
/** /**
* Cached constructor. * Cached constructor.
* *
* @param int $rid ID of the rank. * @param int $rid ID of the rank.
* @param bool $forceRefresh Force a cache refresh. * @param bool $forceRefresh Force a cache refresh.
* *
* @return Rank The requested rank object. * @return Rank The requested rank object.
*/ */
public static function construct($rid, $forceRefresh = false) public static function construct($rid, $forceRefresh = false)
@ -110,7 +110,7 @@ class Rank
/** /**
* Constructor. * Constructor.
* *
* @param int $rid ID of the rank that should be constructed. * @param int $rid ID of the rank that should be constructed.
*/ */
private function __construct($rid) private function __construct($rid)
@ -143,9 +143,9 @@ class Rank
/** /**
* Get the name of the rank. * Get the name of the rank.
* *
* @param bool $multi Should the multiple sense be appended? * @param bool $multi Should the multiple sense be appended?
* *
* @return string The rank's name. * @return string The rank's name.
*/ */
public function name($multi = false) public function name($multi = false)
@ -155,7 +155,7 @@ class Rank
/** /**
* Indicates if the rank is hidden. * Indicates if the rank is hidden.
* *
* @return bool Hidden status. * @return bool Hidden status.
*/ */
public function hidden() public function hidden()
@ -165,9 +165,9 @@ class Rank
/** /**
* Check permissions. * Check permissions.
* *
* @param int $flag Permission flag that should be checked. * @param int $flag Permission flag that should be checked.
* *
* @return bool Success indicator. * @return bool Success indicator.
*/ */
public function permission($flag) public function permission($flag)
@ -177,7 +177,36 @@ class Rank
// Bitwise OR it with the permissions for this forum // Bitwise OR it with the permissions for this forum
$perm = $perm | $this->permissions->rank($this->id); $perm = $perm | $this->permissions->rank($this->id);
return $this->permissions->check($flag, $perm); return $this->permissions->check($flag, $perm);
} }
/**
* Returns all users that are part of this rank.
*
* @param bool $justIds Makes this function only return the user ids when set to a positive value.
*
* @return array Either just the user IDs of the users or with objects.
*/
public function users($justIds = false)
{
// Fetch all users part of this rank
$userIds = array_column(Database::fetch('user_ranks', true, ['rank_id' => [$this->id, '=']]), 'user_id');
// Just return that if we were asked for just the ids
if ($justIds) {
return $userIds;
}
// Create the storage array
$users = [];
// Create User objects and store
foreach ($userIds as $id) {
$users[$id] = User::construct($id);
}
// Return the array
return $users;
}
} }

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Holds various functions to interface with users. * Holds various functions to interface with users.
* *
* @package Sakura * @package Sakura
*/ */
@ -11,7 +11,7 @@ use Sakura\Perms\Site;
/** /**
* User management * User management
* *
* @package Sakura * @package Sakura
* @author Julian van de Groep <me@flash.moe> * @author Julian van de Groep <me@flash.moe>
*/ */
@ -19,10 +19,10 @@ class Users
{ {
/** /**
* Check if a user is logged in * Check if a user is logged in
* *
* @param int $uid The user ID. * @param int $uid The user ID.
* @param string $sid The session ID. * @param string $sid The session ID.
* *
* @return array|bool Either false or the ID and session in an array. * @return array|bool Either false or the ID and session in an array.
*/ */
public static function checkLogin($uid = null, $sid = null) public static function checkLogin($uid = null, $sid = null)
@ -103,12 +103,12 @@ class Users
/** /**
* Log in to an account. * Log in to an account.
* *
* @param string $username The username. * @param string $username The username.
* @param string $password The password. * @param string $password The password.
* @param bool $remember Stay logged in "forever"? * @param bool $remember Stay logged in "forever"?
* @param bool $cookies Set cookies? * @param bool $cookies Set cookies?
* *
* @return array Return the status. * @return array Return the status.
*/ */
public static function login($username, $password, $remember = false, $cookies = true) public static function login($username, $password, $remember = false, $cookies = true)
@ -191,7 +191,7 @@ class Users
/** /**
* Logout * Logout
* *
* @return bool Was the logout successful? * @return bool Was the logout successful?
*/ */
public static function logout() public static function logout()
@ -226,7 +226,7 @@ class Users
/** /**
* Register a new account. * Register a new account.
* *
* @param string $username The username. * @param string $username The username.
* @param string $password The password. * @param string $password The password.
* @param string $confirmpass The password, again. * @param string $confirmpass The password, again.
@ -234,7 +234,7 @@ class Users
* @param bool $tos Agreeing to the ToS. * @param bool $tos Agreeing to the ToS.
* @param string $captcha Captcha. * @param string $captcha Captcha.
* @param string $regkey Registration key (unused). * @param string $regkey Registration key (unused).
* *
* @return array Status. * @return array Status.
*/ */
public static function register($username, $password, $confirmpass, $email, $tos, $captcha = null, $regkey = null) public static function register($username, $password, $confirmpass, $email, $tos, $captcha = null, $regkey = null)
@ -320,10 +320,10 @@ class Users
/** /**
* Send password forgot e-mail * Send password forgot e-mail
* *
* @param string $username The username. * @param string $username The username.
* @param string $email The e-mail. * @param string $email The e-mail.
* *
* @return array The status. * @return array The status.
*/ */
public static function sendPasswordForgot($username, $email) public static function sendPasswordForgot($username, $email)
@ -382,12 +382,12 @@ class Users
/** /**
* Reset a password. * Reset a password.
* *
* @param string $verk The e-mail verification key. * @param string $verk The e-mail verification key.
* @param int $uid The user id. * @param int $uid The user id.
* @param string $newpass New pass. * @param string $newpass New pass.
* @param string $verpass Again. * @param string $verpass Again.
* *
* @return array Status. * @return array Status.
*/ */
public static function resetPassword($verk, $uid, $newpass, $verpass) public static function resetPassword($verk, $uid, $newpass, $verpass)
@ -439,10 +439,10 @@ class Users
/** /**
* Resend activation e-mail. * Resend activation e-mail.
* *
* @param string $username Username. * @param string $username Username.
* @param string $email E-mail. * @param string $email E-mail.
* *
* @return array Status * @return array Status
*/ */
public static function resendActivationMail($username, $email) public static function resendActivationMail($username, $email)
@ -483,10 +483,10 @@ class Users
/** /**
* Send activation e-mail. * Send activation e-mail.
* *
* @param mixed $uid User ID. * @param mixed $uid User ID.
* @param mixed $customKey Key. * @param mixed $customKey Key.
* *
* @return bool Always true. * @return bool Always true.
*/ */
public static function sendActivationMail($uid, $customKey = null) public static function sendActivationMail($uid, $customKey = null)
@ -535,11 +535,11 @@ class Users
/** /**
* Activate a user. * Activate a user.
* *
* @param int $uid The ID. * @param int $uid The ID.
* @param bool $requireKey Require a key. * @param bool $requireKey Require a key.
* @param string $key The key. * @param string $key The key.
* *
* @return array Status. * @return array Status.
*/ */
public static function activateUser($uid, $requireKey = false, $key = null) public static function activateUser($uid, $requireKey = false, $key = null)
@ -567,7 +567,7 @@ class Users
return [0, 'INVALID_CODE']; return [0, 'INVALID_CODE'];
} }
} }
// Add normal user, remove deactivated and set normal as default // Add normal user, remove deactivated and set normal as default
$user->addRanks([2]); $user->addRanks([2]);
$user->removeRanks([1]); $user->removeRanks([1]);
@ -579,10 +579,10 @@ class Users
/** /**
* Check if a user exists. * Check if a user exists.
* *
* @param mixed $user The Username or ID. * @param mixed $user The Username or ID.
* @param bool $id Use id instead. * @param bool $id Use id instead.
* *
* @return mixed Returns the ID if it exists, false otherwise. * @return mixed Returns the ID if it exists, false otherwise.
*/ */
public static function userExists($user, $id = true) public static function userExists($user, $id = true)
@ -599,7 +599,7 @@ class Users
/** /**
* Get all available profile fields. * Get all available profile fields.
* *
* @return array|null The fields. * @return array|null The fields.
*/ */
public static function getProfileFields() public static function getProfileFields()
@ -628,7 +628,7 @@ class Users
/** /**
* Get all available option fields. * Get all available option fields.
* *
* @return array|null The fields. * @return array|null The fields.
*/ */
public static function getOptionFields() public static function getOptionFields()
@ -661,7 +661,7 @@ class Users
/** /**
* Get all online users. * Get all online users.
* *
* @return array Array containing User instances. * @return array Array containing User instances.
*/ */
public static function checkAllOnline() public static function checkAllOnline()
@ -684,10 +684,10 @@ class Users
/** /**
* Add premium time to a user. * Add premium time to a user.
* *
* @param int $id The user ID. * @param int $id The user ID.
* @param int $seconds The amount of extra seconds. * @param int $seconds The amount of extra seconds.
* *
* @return array|double|int The new expiry date. * @return array|double|int The new expiry date.
*/ */
public static function addUserPremium($id, $seconds) public static function addUserPremium($id, $seconds)
@ -725,7 +725,7 @@ class Users
/** /**
* Process premium meta data. * Process premium meta data.
* *
* @param int $id The user ID. * @param int $id The user ID.
*/ */
public static function updatePremiumMeta($id) public static function updatePremiumMeta($id)
@ -762,9 +762,9 @@ class Users
/** /**
* Get all users that registered from a certain IP. * Get all users that registered from a certain IP.
* *
* @param string $ip The IP. * @param string $ip The IP.
* *
* @return array The users. * @return array The users.
*/ */
public static function getUsersByIP($ip) public static function getUsersByIP($ip)
@ -782,43 +782,12 @@ class Users
return $users; return $users;
} }
/**
* Get users from a rank.
*
* @param int $rankId The rank ID.
* @param mixed $users Array with users.
* @param mixed $excludeAbyss Unused.
*
* @return array Users.
*/
public static function getUsersInRank($rankId, $users = null, $excludeAbyss = true)
{
// Get all users (or use the supplied user list to keep server load down)
if (!$users) {
$users = self::getAllUsers();
}
// Make output array
$rank = [];
// 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 ($user->hasRanks([$rankId], $user->id)) {
$rank[] = $user;
}
}
// Then return the array with the user rows
return $rank;
}
/** /**
* Get all users. * Get all users.
* *
* @param mixed $includeInactive include deactivated users. * @param mixed $includeInactive include deactivated users.
* @param mixed $includeRestricted include restricted users. * @param mixed $includeRestricted include restricted users.
* *
* @return array The users. * @return array The users.
*/ */
public static function getAllUsers($includeInactive = true, $includeRestricted = false) public static function getAllUsers($includeInactive = true, $includeRestricted = false)
@ -852,7 +821,7 @@ class Users
/** /**
* Get all ranks. * Get all ranks.
* *
* @return array All ranks. * @return array All ranks.
*/ */
public static function getAllRanks() public static function getAllRanks()
@ -874,12 +843,12 @@ class Users
/** /**
* Get a user's notifications. * Get a user's notifications.
* *
* @param int $uid The user id. * @param int $uid The user id.
* @param int $timediff The maximum difference in time. * @param int $timediff The maximum difference in time.
* @param bool $excludeRead Exclude notifications that were already read. * @param bool $excludeRead Exclude notifications that were already read.
* @param bool $markRead Automatically mark as read. * @param bool $markRead Automatically mark as read.
* *
* @return array The notifications. * @return array The notifications.
*/ */
public static function getNotifications($uid = null, $timediff = 0, $excludeRead = true, $markRead = false) public static function getNotifications($uid = null, $timediff = 0, $excludeRead = true, $markRead = false)
@ -919,8 +888,8 @@ class Users
/** /**
* Mark a notification as read * Mark a notification as read
* *
* @param mixed $id The notification's ID. * @param mixed $id The notification's ID.
* @param mixed $mode Read or unread. * @param mixed $mode Read or unread.
*/ */
public static function markNotificationRead($id, $mode = true) public static function markNotificationRead($id, $mode = true)
@ -938,7 +907,7 @@ class Users
/** /**
* Create a new notification. * Create a new notification.
* *
* @param int $user The user id. * @param int $user The user id.
* @param string $title The notification title. * @param string $title The notification title.
* @param string $text The rest of the text. * @param string $text The rest of the text.
@ -968,7 +937,7 @@ class Users
/** /**
* Get the newest member's ID. * Get the newest member's ID.
* *
* @return int The user ID. * @return int The user ID.
*/ */
public static function getNewestUserId() public static function getNewestUserId()

View file

@ -8,7 +8,7 @@
namespace Sakura; namespace Sakura;
// Define Sakura version // Define Sakura version
define('SAKURA_VERSION', '20160204'); define('SAKURA_VERSION', '20160205');
define('SAKURA_VLABEL', 'Amethyst'); define('SAKURA_VLABEL', 'Amethyst');
define('SAKURA_COLOUR', '#9966CC'); define('SAKURA_COLOUR', '#9966CC');
@ -26,8 +26,8 @@ set_time_limit(0);
mb_internal_encoding('utf-8'); mb_internal_encoding('utf-8');
// Stop the execution if the PHP Version is older than 5.4.0 // Stop the execution if the PHP Version is older than 5.4.0
if (version_compare(phpversion(), '5.4.0', '<')) { if (version_compare(phpversion(), '5.5.0', '<')) {
die('Sakura requires at least PHP 5.4.0, please upgrade to a newer PHP version.'); die('Sakura requires at least PHP 5.5.0, please upgrade to a newer PHP version.');
} }
// Include third-party libraries // Include third-party libraries