Users.php delete soon
This commit is contained in:
parent
7bf64954ec
commit
264fe683d5
4 changed files with 109 additions and 103 deletions
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds the user page controllers.
|
||||
*
|
||||
*
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
|
@ -9,23 +9,24 @@ namespace Sakura\Controllers;
|
|||
|
||||
use Sakura\Config;
|
||||
use Sakura\Database;
|
||||
use Sakura\Rank;
|
||||
use Sakura\Template;
|
||||
use Sakura\User as UserContext;
|
||||
use Sakura\Utils;
|
||||
|
||||
/**
|
||||
* Everything that is just for serving user data.
|
||||
*
|
||||
*
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* Display the profile of a user
|
||||
*
|
||||
* Display the profile of a user.
|
||||
*
|
||||
* @param mixed $id The user ID.
|
||||
*
|
||||
*
|
||||
* @return bool|string The profile page.
|
||||
*/
|
||||
public static function profile($id = 0)
|
||||
|
@ -39,7 +40,7 @@ class User
|
|||
if ($profile->id == 0) {
|
||||
// Fetch from username_history
|
||||
$check = Database::fetch('username_history', false, ['username_old_clean' => [Utils::cleanString(isset($_GET['u']) ? $_GET['u'] : 0, true, true), '=']]);
|
||||
|
||||
|
||||
// Redirect if so
|
||||
if ($check) {
|
||||
Template::vars([
|
||||
|
@ -85,6 +86,13 @@ class User
|
|||
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)
|
||||
{
|
||||
global $currentUser;
|
||||
|
@ -99,7 +107,7 @@ class User
|
|||
'memberlist' => [
|
||||
'ranks' => ($_MEMBERLIST_RANKS = \Sakura\Users::getAllRanks()),
|
||||
'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'),
|
||||
]
|
||||
]);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds the rank object class.
|
||||
*
|
||||
*
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
|
@ -12,7 +12,7 @@ use Sakura\Perms\Site;
|
|||
|
||||
/**
|
||||
* Serves Rank data.
|
||||
*
|
||||
*
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
|
@ -20,80 +20,80 @@ class Rank
|
|||
{
|
||||
/**
|
||||
* ID of the rank.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $id = 0;
|
||||
|
||||
/**
|
||||
* Name of the rank.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'Rank';
|
||||
|
||||
/**
|
||||
* Global hierarchy of the rank.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $hierarchy = 0;
|
||||
|
||||
/**
|
||||
* Text that should be append to the name to make it address multiple.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $multiple = '';
|
||||
|
||||
/**
|
||||
* The rank's username colour.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $colour = 'inherit';
|
||||
|
||||
/**
|
||||
* Description of the rank.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description = '';
|
||||
|
||||
/**
|
||||
* User title of the rank.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title = '';
|
||||
|
||||
/**
|
||||
* Indicates if this rank should be hidden.
|
||||
*
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $hidden = true;
|
||||
|
||||
/**
|
||||
* Permission container.
|
||||
*
|
||||
*
|
||||
* @var Perms
|
||||
*/
|
||||
private $permissions;
|
||||
|
||||
/**
|
||||
* Instance cache container.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_rankCache = [];
|
||||
|
||||
|
||||
/**
|
||||
* Cached constructor.
|
||||
*
|
||||
*
|
||||
* @param int $rid ID of the rank.
|
||||
* @param bool $forceRefresh Force a cache refresh.
|
||||
*
|
||||
*
|
||||
* @return Rank The requested rank object.
|
||||
*/
|
||||
public static function construct($rid, $forceRefresh = false)
|
||||
|
@ -110,7 +110,7 @@ class Rank
|
|||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*
|
||||
* @param int $rid ID of the rank that should be constructed.
|
||||
*/
|
||||
private function __construct($rid)
|
||||
|
@ -143,9 +143,9 @@ class Rank
|
|||
|
||||
/**
|
||||
* Get the name of the rank.
|
||||
*
|
||||
*
|
||||
* @param bool $multi Should the multiple sense be appended?
|
||||
*
|
||||
*
|
||||
* @return string The rank's name.
|
||||
*/
|
||||
public function name($multi = false)
|
||||
|
@ -155,7 +155,7 @@ class Rank
|
|||
|
||||
/**
|
||||
* Indicates if the rank is hidden.
|
||||
*
|
||||
*
|
||||
* @return bool Hidden status.
|
||||
*/
|
||||
public function hidden()
|
||||
|
@ -165,9 +165,9 @@ class Rank
|
|||
|
||||
/**
|
||||
* Check permissions.
|
||||
*
|
||||
*
|
||||
* @param int $flag Permission flag that should be checked.
|
||||
*
|
||||
*
|
||||
* @return bool Success indicator.
|
||||
*/
|
||||
public function permission($flag)
|
||||
|
@ -177,7 +177,36 @@ class Rank
|
|||
|
||||
// Bitwise OR it with the permissions for this forum
|
||||
$perm = $perm | $this->permissions->rank($this->id);
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds various functions to interface with users.
|
||||
*
|
||||
*
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
|
@ -11,7 +11,7 @@ use Sakura\Perms\Site;
|
|||
|
||||
/**
|
||||
* User management
|
||||
*
|
||||
*
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
|
@ -19,10 +19,10 @@ class Users
|
|||
{
|
||||
/**
|
||||
* Check if a user is logged in
|
||||
*
|
||||
*
|
||||
* @param int $uid The user ID.
|
||||
* @param string $sid The session ID.
|
||||
*
|
||||
*
|
||||
* @return array|bool Either false or the ID and session in an array.
|
||||
*/
|
||||
public static function checkLogin($uid = null, $sid = null)
|
||||
|
@ -103,12 +103,12 @@ class Users
|
|||
|
||||
/**
|
||||
* Log in to an account.
|
||||
*
|
||||
*
|
||||
* @param string $username The username.
|
||||
* @param string $password The password.
|
||||
* @param bool $remember Stay logged in "forever"?
|
||||
* @param bool $cookies Set cookies?
|
||||
*
|
||||
*
|
||||
* @return array Return the status.
|
||||
*/
|
||||
public static function login($username, $password, $remember = false, $cookies = true)
|
||||
|
@ -191,7 +191,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Logout
|
||||
*
|
||||
*
|
||||
* @return bool Was the logout successful?
|
||||
*/
|
||||
public static function logout()
|
||||
|
@ -226,7 +226,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Register a new account.
|
||||
*
|
||||
*
|
||||
* @param string $username The username.
|
||||
* @param string $password The password.
|
||||
* @param string $confirmpass The password, again.
|
||||
|
@ -234,7 +234,7 @@ class Users
|
|||
* @param bool $tos Agreeing to the ToS.
|
||||
* @param string $captcha Captcha.
|
||||
* @param string $regkey Registration key (unused).
|
||||
*
|
||||
*
|
||||
* @return array Status.
|
||||
*/
|
||||
public static function register($username, $password, $confirmpass, $email, $tos, $captcha = null, $regkey = null)
|
||||
|
@ -320,10 +320,10 @@ class Users
|
|||
|
||||
/**
|
||||
* Send password forgot e-mail
|
||||
*
|
||||
*
|
||||
* @param string $username The username.
|
||||
* @param string $email The e-mail.
|
||||
*
|
||||
*
|
||||
* @return array The status.
|
||||
*/
|
||||
public static function sendPasswordForgot($username, $email)
|
||||
|
@ -382,12 +382,12 @@ class Users
|
|||
|
||||
/**
|
||||
* Reset a password.
|
||||
*
|
||||
*
|
||||
* @param string $verk The e-mail verification key.
|
||||
* @param int $uid The user id.
|
||||
* @param string $newpass New pass.
|
||||
* @param string $verpass Again.
|
||||
*
|
||||
*
|
||||
* @return array Status.
|
||||
*/
|
||||
public static function resetPassword($verk, $uid, $newpass, $verpass)
|
||||
|
@ -439,10 +439,10 @@ class Users
|
|||
|
||||
/**
|
||||
* Resend activation e-mail.
|
||||
*
|
||||
*
|
||||
* @param string $username Username.
|
||||
* @param string $email E-mail.
|
||||
*
|
||||
*
|
||||
* @return array Status
|
||||
*/
|
||||
public static function resendActivationMail($username, $email)
|
||||
|
@ -483,10 +483,10 @@ class Users
|
|||
|
||||
/**
|
||||
* Send activation e-mail.
|
||||
*
|
||||
*
|
||||
* @param mixed $uid User ID.
|
||||
* @param mixed $customKey Key.
|
||||
*
|
||||
*
|
||||
* @return bool Always true.
|
||||
*/
|
||||
public static function sendActivationMail($uid, $customKey = null)
|
||||
|
@ -535,11 +535,11 @@ class Users
|
|||
|
||||
/**
|
||||
* Activate a user.
|
||||
*
|
||||
*
|
||||
* @param int $uid The ID.
|
||||
* @param bool $requireKey Require a key.
|
||||
* @param string $key The key.
|
||||
*
|
||||
*
|
||||
* @return array Status.
|
||||
*/
|
||||
public static function activateUser($uid, $requireKey = false, $key = null)
|
||||
|
@ -567,7 +567,7 @@ class Users
|
|||
return [0, 'INVALID_CODE'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add normal user, remove deactivated and set normal as default
|
||||
$user->addRanks([2]);
|
||||
$user->removeRanks([1]);
|
||||
|
@ -579,10 +579,10 @@ class Users
|
|||
|
||||
/**
|
||||
* Check if a user exists.
|
||||
*
|
||||
*
|
||||
* @param mixed $user The Username or ID.
|
||||
* @param bool $id Use id instead.
|
||||
*
|
||||
*
|
||||
* @return mixed Returns the ID if it exists, false otherwise.
|
||||
*/
|
||||
public static function userExists($user, $id = true)
|
||||
|
@ -599,7 +599,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Get all available profile fields.
|
||||
*
|
||||
*
|
||||
* @return array|null The fields.
|
||||
*/
|
||||
public static function getProfileFields()
|
||||
|
@ -628,7 +628,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Get all available option fields.
|
||||
*
|
||||
*
|
||||
* @return array|null The fields.
|
||||
*/
|
||||
public static function getOptionFields()
|
||||
|
@ -661,7 +661,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Get all online users.
|
||||
*
|
||||
*
|
||||
* @return array Array containing User instances.
|
||||
*/
|
||||
public static function checkAllOnline()
|
||||
|
@ -684,10 +684,10 @@ class Users
|
|||
|
||||
/**
|
||||
* Add premium time to a user.
|
||||
*
|
||||
*
|
||||
* @param int $id The user ID.
|
||||
* @param int $seconds The amount of extra seconds.
|
||||
*
|
||||
*
|
||||
* @return array|double|int The new expiry date.
|
||||
*/
|
||||
public static function addUserPremium($id, $seconds)
|
||||
|
@ -725,7 +725,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Process premium meta data.
|
||||
*
|
||||
*
|
||||
* @param int $id The user ID.
|
||||
*/
|
||||
public static function updatePremiumMeta($id)
|
||||
|
@ -762,9 +762,9 @@ class Users
|
|||
|
||||
/**
|
||||
* Get all users that registered from a certain IP.
|
||||
*
|
||||
* @param string $ip The IP.
|
||||
*
|
||||
*
|
||||
* @param string $ip The IP.
|
||||
*
|
||||
* @return array The users.
|
||||
*/
|
||||
public static function getUsersByIP($ip)
|
||||
|
@ -782,43 +782,12 @@ class 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.
|
||||
*
|
||||
*
|
||||
* @param mixed $includeInactive include deactivated users.
|
||||
* @param mixed $includeRestricted include restricted users.
|
||||
*
|
||||
*
|
||||
* @return array The users.
|
||||
*/
|
||||
public static function getAllUsers($includeInactive = true, $includeRestricted = false)
|
||||
|
@ -852,7 +821,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Get all ranks.
|
||||
*
|
||||
*
|
||||
* @return array All ranks.
|
||||
*/
|
||||
public static function getAllRanks()
|
||||
|
@ -874,12 +843,12 @@ class Users
|
|||
|
||||
/**
|
||||
* Get a user's notifications.
|
||||
*
|
||||
*
|
||||
* @param int $uid The user id.
|
||||
* @param int $timediff The maximum difference in time.
|
||||
* @param bool $excludeRead Exclude notifications that were already read.
|
||||
* @param bool $markRead Automatically mark as read.
|
||||
*
|
||||
*
|
||||
* @return array The notifications.
|
||||
*/
|
||||
public static function getNotifications($uid = null, $timediff = 0, $excludeRead = true, $markRead = false)
|
||||
|
@ -919,8 +888,8 @@ class Users
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static function markNotificationRead($id, $mode = true)
|
||||
|
@ -938,7 +907,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Create a new notification.
|
||||
*
|
||||
*
|
||||
* @param int $user The user id.
|
||||
* @param string $title The notification title.
|
||||
* @param string $text The rest of the text.
|
||||
|
@ -968,7 +937,7 @@ class Users
|
|||
|
||||
/**
|
||||
* Get the newest member's ID.
|
||||
*
|
||||
*
|
||||
* @return int The user ID.
|
||||
*/
|
||||
public static function getNewestUserId()
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Sakura;
|
||||
|
||||
// Define Sakura version
|
||||
define('SAKURA_VERSION', '20160204');
|
||||
define('SAKURA_VERSION', '20160205');
|
||||
define('SAKURA_VLABEL', 'Amethyst');
|
||||
define('SAKURA_COLOUR', '#9966CC');
|
||||
|
||||
|
@ -26,8 +26,8 @@ set_time_limit(0);
|
|||
mb_internal_encoding('utf-8');
|
||||
|
||||
// Stop the execution if the PHP Version is older than 5.4.0
|
||||
if (version_compare(phpversion(), '5.4.0', '<')) {
|
||||
die('Sakura requires at least PHP 5.4.0, please upgrade to a newer PHP version.');
|
||||
if (version_compare(phpversion(), '5.5.0', '<')) {
|
||||
die('Sakura requires at least PHP 5.5.0, please upgrade to a newer PHP version.');
|
||||
}
|
||||
|
||||
// Include third-party libraries
|
||||
|
|
Reference in a new issue