This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/libraries/Controllers/Settings/AppearanceController.php

173 lines
5.2 KiB
PHP
Raw Normal View History

<?php
/**
* Holds the appearance section controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
2016-04-03 21:29:46 +00:00
use Sakura\ActiveUser;
use Sakura\DB;
use Sakura\Perms\Site;
use Sakura\Router;
use Sakura\Template;
/**
* Appearance settings.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class AppearanceController extends Controller
{
public function avatar()
{
2016-04-03 21:29:46 +00:00
// Check permission
if (!ActiveUser::$user->permission(Site::CHANGE_AVATAR)) {
$message = "You aren't allowed to change your avatar.";
$redirect = Router::route('settings.general.home');
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
2016-04-09 01:59:54 +00:00
return Template::render('settings/appearance/avatar');
}
public function background()
{
2016-04-03 21:29:46 +00:00
// Check permission
if (!ActiveUser::$user->permission(Site::CHANGE_BACKGROUND)) {
$message = "You aren't allowed to change your background.";
$redirect = Router::route('settings.general.home');
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
2016-04-09 01:59:54 +00:00
return Template::render('settings/appearance/background');
}
public function header()
{
2016-04-03 21:29:46 +00:00
// Check permission
if (!ActiveUser::$user->permission(Site::CHANGE_HEADER)) {
$message = "You aren't allowed to change your profile header.";
$redirect = Router::route('settings.general.home');
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
$session = $_POST['session'] ?? null;
$header = $_POST['header'] ?? null;
return Template::render('settings/appearance/header');
}
public function userpage()
{
2016-04-03 21:29:46 +00:00
// Check permission
if (!(
ActiveUser::$user->page
&& ActiveUser::$user->permission(Site::CHANGE_USERPAGE)
) || !ActiveUser::$user->permission(Site::CREATE_USERPAGE)) {
$message = "You aren't allowed to change your userpage.";
$redirect = Router::route('settings.general.home');
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
$session = $_POST['session'] ?? null;
$userpage = $_POST['userpage'] ?? null;
$maxLength = 65535;
if ($session && $userpage) {
$redirect = Router::route('settings.appearance.userpage');
if ($session !== session_id()) {
$message = 'Your session expired!';
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
if (strlen($userpage) > $maxLength) {
$message = 'Your userpage is too long, shorten it a little!';
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
// Update database
DB::table('users')
->where('user_id', ActiveUser::$user->id)
->update([
'user_page' => $userpage,
]);
$message = 'Updated your userpage!';
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
Template::vars(compact('maxLength'));
return Template::render('settings/appearance/userpage');
}
public function signature()
{
2016-04-03 21:29:46 +00:00
// Check permission
if (!ActiveUser::$user->permission(Site::CHANGE_SIGNATURE)) {
$message = "You aren't allowed to change your signature.";
$redirect = Router::route('settings.general.home');
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
$session = $_POST['session'] ?? null;
$signature = $_POST['signature'] ?? null;
$maxLength = 500;
if ($session && $signature) {
$redirect = Router::route('settings.appearance.signature');
if ($session !== session_id()) {
$message = 'Your session expired!';
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
if (strlen($signature) > $maxLength) {
$message = 'Your signature is too long, shorten it a little!';
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
// Update database
DB::table('users')
->where('user_id', ActiveUser::$user->id)
->update([
'user_signature' => $signature,
]);
$message = 'Updated your signature!';
Template::vars(compact('message', 'redirect'));
return Template::render('global/information');
}
Template::vars(compact('maxLength'));
return Template::render('settings/appearance/signature');
}
}