2016-03-28 01:18:59 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Holds the appearance section controller.
|
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura\Controllers\Settings;
|
|
|
|
|
2016-09-10 15:05:54 +00:00
|
|
|
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;
|
|
|
|
|
2016-03-28 01:18:59 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-03-28 01:18:59 +00:00
|
|
|
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)) {
|
2016-09-10 15:05:54 +00:00
|
|
|
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-03-28 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 02:35:37 +00:00
|
|
|
/**
|
|
|
|
* Renders the signature changing page.
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-03-28 01:18:59 +00:00
|
|
|
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)) {
|
2016-09-10 15:05:54 +00:00
|
|
|
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'));
|
2016-03-28 01:18:59 +00:00
|
|
|
}
|
|
|
|
}
|