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/app/Controllers/Settings/AppearanceController.php

93 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/**
* Holds the appearance section controller.
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
2016-08-07 14:10:27 +00:00
use Sakura\CurrentSession;
2016-04-03 21:29:46 +00:00
use Sakura\DB;
use Sakura\Perms\Site;
/**
* Appearance settings.
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class AppearanceController extends Controller
{
2016-08-05 02:35:37 +00:00
/**
* Renders the userpage editing page.
*/
public function userpage()
{
2016-04-03 21:29:46 +00:00
// Check permission
if (!(
2016-08-07 14:10:27 +00:00
CurrentSession::$user->page
&& CurrentSession::$user->permission(Site::CHANGE_USERPAGE)
) && !CurrentSession::$user->permission(Site::CREATE_USERPAGE)) {
throw new HttpMethodNotAllowedException();
2016-04-03 21:29:46 +00:00
}
$userpage = $_POST['userpage'] ?? null;
2016-08-02 20:35:12 +00:00
$maxLength = config('user.page_max');
2016-04-03 21:29:46 +00:00
2016-08-02 20:35:12 +00:00
if (session_check() && $userpage) {
$redirect = route('settings.appearance.userpage');
2016-04-03 21:29:46 +00:00
if (strlen($userpage) > $maxLength) {
$message = 'Your userpage is too long, shorten it a little!';
2016-08-02 20:35:12 +00:00
} else {
DB::table('users')
2016-08-07 14:10:27 +00:00
->where('user_id', CurrentSession::$user->id)
2016-08-02 20:35:12 +00:00
->update([
'user_page' => $userpage,
]);
2016-04-03 21:29:46 +00:00
2016-08-02 20:35:12 +00:00
$message = 'Updated your userpage!';
}
2016-04-03 21:29:46 +00:00
2016-08-02 20:35:12 +00:00
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
2016-08-02 20:35:12 +00:00
return view('settings/appearance/userpage', compact('maxLength'));
}
2016-08-05 02:35:37 +00:00
/**
* Renders the signature changing page.
* @return string
*/
public function signature()
{
2016-04-03 21:29:46 +00:00
// Check permission
2016-08-07 14:10:27 +00:00
if (!CurrentSession::$user->permission(Site::CHANGE_SIGNATURE)) {
throw new HttpMethodNotAllowedException();
2016-04-03 21:29:46 +00:00
}
$signature = $_POST['signature'] ?? null;
2016-08-02 20:35:12 +00:00
$maxLength = config('user.signature_max');
2016-04-03 21:29:46 +00:00
2016-08-02 20:35:12 +00:00
if (session_check() && $signature) {
$redirect = route('settings.appearance.signature');
2016-04-03 21:29:46 +00:00
if (strlen($signature) > $maxLength) {
$message = 'Your signature is too long, shorten it a little!';
2016-08-02 20:35:12 +00:00
} else {
DB::table('users')
2016-08-07 14:10:27 +00:00
->where('user_id', CurrentSession::$user->id)
2016-08-02 20:35:12 +00:00
->update([
'user_signature' => $signature,
]);
2016-04-03 21:29:46 +00:00
2016-08-02 20:35:12 +00:00
$message = 'Updated your signature!';
}
2016-04-03 21:29:46 +00:00
2016-08-02 20:35:12 +00:00
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
2016-08-02 20:35:12 +00:00
return view('settings/appearance/signature', compact('maxLength'));
}
}