2016-02-04 20:56:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Holds the user page controllers.
|
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura\Controllers;
|
|
|
|
|
2016-03-31 20:03:25 +00:00
|
|
|
use Sakura\ActiveUser;
|
2016-02-04 20:56:40 +00:00
|
|
|
use Sakura\Config;
|
2016-02-18 23:28:44 +00:00
|
|
|
use Sakura\DB;
|
2016-03-26 16:36:58 +00:00
|
|
|
use Sakura\Perms\Site;
|
2016-02-05 11:20:33 +00:00
|
|
|
use Sakura\Rank;
|
2016-03-13 20:35:51 +00:00
|
|
|
use Sakura\Router;
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Everything that is just for serving user data.
|
|
|
|
* @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-08-05 02:35:37 +00:00
|
|
|
* @param int $id
|
|
|
|
* @return string
|
2016-02-04 20:56:40 +00:00
|
|
|
*/
|
2016-02-14 22:46:07 +00:00
|
|
|
public function profile($id = 0)
|
2016-02-04 20:56:40 +00:00
|
|
|
{
|
|
|
|
// 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')
|
2016-04-01 21:44:31 +00:00
|
|
|
->where('username_old_clean', clean_string($id, true, true))
|
2016-02-25 16:06:29 +00:00
|
|
|
->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) {
|
2016-03-27 21:18:57 +00:00
|
|
|
$message = "This user changed their username! Redirecting you to their new profile.";
|
|
|
|
$redirect = Router::route('user.profile', $check[0]->user_id);
|
|
|
|
|
|
|
|
Template::vars(compact('message', 'redirect'));
|
2016-02-04 20:56:40 +00:00
|
|
|
|
|
|
|
// Print page contents
|
|
|
|
return Template::render('global/information');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set parse variables
|
2016-03-27 21:18:57 +00:00
|
|
|
Template::vars(compact('profile'));
|
2016-02-04 20:56:40 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-08-04 15:34:25 +00:00
|
|
|
return Template::render((isset($_GET['new']) ? '@aitemu/' : '') . 'user/profile');
|
2016-02-04 20:56:40 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 11:20:33 +00:00
|
|
|
/**
|
|
|
|
* Display the memberlist.
|
2016-08-05 02:35:37 +00:00
|
|
|
* @param int $rank
|
|
|
|
* @return string
|
2016-02-05 11:20:33 +00:00
|
|
|
*/
|
2016-02-27 16:46:16 +00:00
|
|
|
public function members($rank = null)
|
2016-02-04 20:56:40 +00:00
|
|
|
{
|
|
|
|
// Check permission
|
2016-03-31 20:03:25 +00:00
|
|
|
if (!ActiveUser::$user->permission(Site::VIEW_MEMBERLIST)) {
|
2016-02-04 20:56:40 +00:00
|
|
|
return Template::render('global/restricted');
|
|
|
|
}
|
|
|
|
|
2016-02-27 16:46:16 +00:00
|
|
|
// Get all ranks
|
|
|
|
$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
|
2016-07-26 17:29:53 +00:00
|
|
|
$rank = array_key_exists($rank, $ranks) ? $rank : ($rank ? 0 : intval(config("rank.regular")));
|
2016-02-27 16:46:16 +00:00
|
|
|
|
2016-03-27 21:18:57 +00:00
|
|
|
// Get members per page
|
2016-07-26 17:29:53 +00:00
|
|
|
$membersPerPage = 30;
|
2016-03-27 21:18:57 +00:00
|
|
|
|
2016-02-04 20:56:40 +00:00
|
|
|
// Set parse variables
|
2016-03-27 21:18:57 +00:00
|
|
|
Template::vars(compact('ranks', 'rank', 'membersPerPage'));
|
2016-02-04 20:56:40 +00:00
|
|
|
|
|
|
|
// Render the template
|
2016-03-28 14:47:43 +00:00
|
|
|
return Template::render('user/members');
|
2016-03-26 16:36:58 +00:00
|
|
|
}
|
2016-04-01 21:44:31 +00:00
|
|
|
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* Report a user.
|
|
|
|
* @param int $id
|
|
|
|
*/
|
2016-04-01 21:44:31 +00:00
|
|
|
public function report($id = 0)
|
|
|
|
{
|
|
|
|
return Template::render('user/report');
|
|
|
|
}
|
2016-02-04 20:56:40 +00:00
|
|
|
}
|