2016-02-04 20:56:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Holds the user page controllers.
|
2016-02-05 11:20:33 +00:00
|
|
|
*
|
2016-02-04 20:56:40 +00:00
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura\Controllers;
|
|
|
|
|
|
|
|
use Sakura\Config;
|
2016-02-18 23:28:44 +00:00
|
|
|
use Sakura\DB;
|
2016-02-05 11:20:33 +00:00
|
|
|
use Sakura\Rank;
|
2016-02-04 20:56:40 +00:00
|
|
|
use Sakura\Template;
|
2016-02-27 17:28:45 +00:00
|
|
|
use Sakura\User;
|
2016-02-04 20:56:40 +00:00
|
|
|
use Sakura\Utils;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Everything that is just for serving user data.
|
2016-02-05 11:20:33 +00:00
|
|
|
*
|
2016-02-04 20:56:40 +00:00
|
|
|
* @package Sakura
|
|
|
|
* @author Julian van de Groep <me@flash.moe>
|
|
|
|
*/
|
2016-02-27 16:46:16 +00:00
|
|
|
class UserController extends Controller
|
2016-02-04 20:56:40 +00:00
|
|
|
{
|
|
|
|
/**
|
2016-02-05 11:20:33 +00:00
|
|
|
* Display the profile of a user.
|
|
|
|
*
|
2016-02-04 20:56:40 +00:00
|
|
|
* @param mixed $id The user ID.
|
2016-02-05 11:20:33 +00:00
|
|
|
*
|
2016-02-04 20:56:40 +00:00
|
|
|
* @return bool|string The profile page.
|
|
|
|
*/
|
2016-02-14 22:46:07 +00:00
|
|
|
public function profile($id = 0)
|
2016-02-04 20:56:40 +00:00
|
|
|
{
|
|
|
|
global $currentUser;
|
|
|
|
|
|
|
|
// Get the user's context
|
2016-02-27 17:28:45 +00:00
|
|
|
$profile = User::construct($id);
|
2016-02-04 20:56:40 +00:00
|
|
|
|
|
|
|
// If the user id is zero check if there was a namechange
|
|
|
|
if ($profile->id == 0) {
|
|
|
|
// Fetch from username_history
|
2016-02-25 16:06:29 +00:00
|
|
|
$check = DB::table('username_history')
|
|
|
|
->where('username_old_clean', Utils::cleanString($id, true, true))
|
|
|
|
->orderBy('change_id', 'desc')
|
|
|
|
->get();
|
2016-02-05 11:20:33 +00:00
|
|
|
|
2016-02-04 20:56:40 +00:00
|
|
|
// Redirect if so
|
|
|
|
if ($check) {
|
|
|
|
Template::vars([
|
2016-02-18 23:28:44 +00:00
|
|
|
'page' => [
|
|
|
|
'message' => 'The user this profile belongs to changed their username, you are being redirected.',
|
2016-02-25 16:06:29 +00:00
|
|
|
'redirect' => (new \Sakura\Urls)->format('USER_PROFILE', [$check[0]->user_id]),
|
2016-02-18 23:28:44 +00:00
|
|
|
],
|
2016-02-04 20:56:40 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
return Template::render('global/information');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we're trying to restrict
|
|
|
|
if (isset($_GET['restrict']) && $_GET['restrict'] == session_id() && $currentUser->permission(\Sakura\Perms\Manage::CAN_RESTRICT_USERS, \Sakura\Perms::MANAGE)) {
|
|
|
|
// Check restricted status
|
|
|
|
$restricted = $profile->permission(\Sakura\Perms\Site::RESTRICTED);
|
|
|
|
|
|
|
|
if ($restricted) {
|
|
|
|
$profile->removeRanks([Config::get('restricted_rank_id')]);
|
|
|
|
$profile->addRanks([2]);
|
|
|
|
} else {
|
|
|
|
$profile->addRanks([Config::get('restricted_rank_id')]);
|
|
|
|
$profile->removeRanks(array_keys($profile->ranks));
|
|
|
|
}
|
|
|
|
|
|
|
|
Template::vars([
|
|
|
|
'page' => [
|
|
|
|
'message' => 'Toggled the restricted status of the user.',
|
|
|
|
'redirect' => (new \Sakura\Urls)->format('USER_PROFILE', [$profile->id]),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
return Template::render('global/information');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set parse variables
|
|
|
|
Template::vars([
|
|
|
|
'profile' => $profile,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
return Template::render('main/profile');
|
|
|
|
}
|
|
|
|
|
2016-02-05 11:20:33 +00:00
|
|
|
/**
|
|
|
|
* Display the memberlist.
|
|
|
|
*
|
|
|
|
* @param int $rank Optional rank ID.
|
|
|
|
*
|
|
|
|
* @return bool|string The memberlist.
|
|
|
|
*/
|
2016-02-27 16:46:16 +00:00
|
|
|
public function members($rank = null)
|
2016-02-04 20:56:40 +00:00
|
|
|
{
|
|
|
|
global $currentUser;
|
|
|
|
|
|
|
|
// Check permission
|
|
|
|
if (!$currentUser->permission(\Sakura\Perms\Site::VIEW_MEMBERLIST)) {
|
|
|
|
return Template::render('global/restricted');
|
|
|
|
}
|
|
|
|
|
2016-02-27 16:46:16 +00:00
|
|
|
// Get all ranks
|
|
|
|
|
|
|
|
// Execute query
|
|
|
|
$getRanks = DB::table('ranks')
|
|
|
|
->get(['rank_id']);
|
|
|
|
|
|
|
|
// Define variable
|
|
|
|
$ranks = [];
|
|
|
|
|
|
|
|
// Add the empty rank
|
|
|
|
$ranks[0] = Rank::construct(0);
|
|
|
|
|
|
|
|
// Reorder shit
|
|
|
|
foreach ($getRanks as $sortRank) {
|
|
|
|
$ranks[$sortRank->rank_id] = Rank::construct($sortRank->rank_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the active rank
|
|
|
|
$rank = array_key_exists($rank, $ranks) ? $rank : ($rank ? 0 : 2);
|
|
|
|
|
2016-02-04 20:56:40 +00:00
|
|
|
// Set parse variables
|
|
|
|
Template::vars([
|
2016-02-27 16:46:16 +00:00
|
|
|
'ranks' => $ranks,
|
|
|
|
'rank' => $rank,
|
|
|
|
'membersPerPage' => Config::get('members_per_page'),
|
2016-02-04 20:56:40 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
// Render the template
|
|
|
|
return Template::render('main/memberlist');
|
|
|
|
}
|
|
|
|
}
|