2015-05-05 06:24:19 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Sakura User Settings
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Declare Namespace
|
|
|
|
namespace Sakura;
|
|
|
|
|
2015-12-29 21:52:19 +00:00
|
|
|
use Sakura\Perms\Site;
|
2016-03-19 15:29:47 +00:00
|
|
|
use Sakura\Router;
|
2016-03-27 22:15:51 +00:00
|
|
|
|
|
|
|
// Legacy support!!!!!!!!!
|
|
|
|
$renderData = [];
|
2015-12-29 21:52:19 +00:00
|
|
|
|
2015-07-30 01:12:53 +00:00
|
|
|
// If this we're requesting notifications this page won't require templating
|
2015-09-14 20:51:23 +00:00
|
|
|
if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications']) {
|
2015-07-30 01:12:53 +00:00
|
|
|
define('SAKURA_NO_TPL', true);
|
|
|
|
}
|
|
|
|
|
2015-05-05 06:24:19 +00:00
|
|
|
// Include components
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
2015-05-05 06:24:19 +00:00
|
|
|
|
2016-03-26 16:36:58 +00:00
|
|
|
// Notifications (decommissioned)
|
2015-09-14 20:51:23 +00:00
|
|
|
if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications']) {
|
2015-05-09 00:56:55 +00:00
|
|
|
// Create the notification container array
|
2015-10-18 19:06:30 +00:00
|
|
|
$notifications = [];
|
2015-05-09 00:56:55 +00:00
|
|
|
|
|
|
|
// Check if the user is logged in
|
2015-09-14 21:41:43 +00:00
|
|
|
if (Users::checkLogin()
|
|
|
|
&& isset($_REQUEST['time'])
|
|
|
|
&& $_REQUEST['time'] > (time() - 1000)
|
|
|
|
&& isset($_REQUEST['session']) && $_REQUEST['session'] == session_id()) {
|
2015-05-09 00:56:55 +00:00
|
|
|
// Get the user's notifications from the past forever but exclude read notifications
|
2016-03-26 16:36:58 +00:00
|
|
|
$alerts = $currentUser->notifications();
|
2015-05-09 00:56:55 +00:00
|
|
|
|
|
|
|
// Add the proper values to the array
|
2016-03-26 16:36:58 +00:00
|
|
|
foreach ($alerts as $alert) {
|
2015-05-11 22:20:19 +00:00
|
|
|
// Add the notification to the display array
|
2016-03-26 16:36:58 +00:00
|
|
|
$notifications[$alert->id] = [
|
|
|
|
'read' => $alert->read,
|
|
|
|
'title' => $alert->title,
|
|
|
|
'text' => $alert->text,
|
|
|
|
'link' => $alert->link,
|
|
|
|
'img' => $alert->image,
|
|
|
|
'timeout' => $alert->timeout,
|
|
|
|
'sound' => $alert->sound,
|
2015-05-11 22:20:19 +00:00
|
|
|
];
|
2016-03-26 16:36:58 +00:00
|
|
|
|
|
|
|
$alert->toggleRead();
|
|
|
|
$alert->save();
|
2015-05-09 00:56:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 00:30:22 +00:00
|
|
|
// Check if friendOnline is set (so it doesn't tell you all your friends all online on first visit)
|
2015-11-11 21:54:56 +00:00
|
|
|
$onlineFriends = isset($_SESSION['friendsOnline']) ? $_SESSION['friendsOnline'] : [];
|
|
|
|
$onlineNotify = isset($_SESSION['friendsOnline']);
|
2015-11-11 00:30:22 +00:00
|
|
|
|
2015-11-12 17:29:14 +00:00
|
|
|
// Set friendsOnline
|
|
|
|
if (!$onlineNotify) {
|
|
|
|
$_SESSION['friendsOnline'] = [];
|
|
|
|
}
|
|
|
|
|
2015-11-11 00:30:22 +00:00
|
|
|
// Populate the array
|
|
|
|
foreach ($currentUser->friends(1) as $friend) {
|
|
|
|
// Online status
|
|
|
|
$online = $friend->isOnline();
|
|
|
|
|
|
|
|
// If true check if they're already in the array
|
2016-01-17 01:58:31 +00:00
|
|
|
if ($online && !in_array($friend->id, $onlineFriends)) {
|
2015-11-11 00:30:22 +00:00
|
|
|
// Add user to the online array
|
2016-01-17 01:58:31 +00:00
|
|
|
$_SESSION['friendsOnline'][$friend->id] = $friend->id;
|
2015-11-11 00:30:22 +00:00
|
|
|
|
|
|
|
// Add the notification to the display array
|
2015-11-11 21:56:03 +00:00
|
|
|
if ($onlineNotify) {
|
2015-11-11 21:54:56 +00:00
|
|
|
$notifications[] = [
|
|
|
|
'read' => 0,
|
2016-01-17 01:58:31 +00:00
|
|
|
'title' => $friend->username . ' is online.',
|
2015-11-11 21:54:56 +00:00
|
|
|
'text' => '',
|
|
|
|
'link' => '',
|
2016-03-26 16:36:58 +00:00
|
|
|
'img' => Router::route('file.avatar', $friend->id),
|
2015-11-11 21:54:56 +00:00
|
|
|
'timeout' => 2000,
|
|
|
|
'sound' => false,
|
|
|
|
];
|
|
|
|
}
|
2016-01-17 01:58:31 +00:00
|
|
|
} elseif (!$online && in_array($friend->id, $onlineFriends)) {
|
2015-11-11 00:30:22 +00:00
|
|
|
// Remove the person from the array
|
2016-01-17 01:58:31 +00:00
|
|
|
unset($_SESSION['friendsOnline'][$friend->id]);
|
2015-11-11 00:30:22 +00:00
|
|
|
|
|
|
|
// Add the notification to the display array
|
2015-11-11 21:56:03 +00:00
|
|
|
if ($onlineNotify) {
|
2015-11-11 21:54:56 +00:00
|
|
|
$notifications[] = [
|
|
|
|
'read' => 0,
|
2016-01-17 01:58:31 +00:00
|
|
|
'title' => $friend->username . ' is offline.',
|
2015-11-11 21:54:56 +00:00
|
|
|
'text' => '',
|
|
|
|
'link' => '',
|
2016-03-26 16:36:58 +00:00
|
|
|
'img' => Router::route('file.avatar', $friend->id),
|
2015-11-11 21:54:56 +00:00
|
|
|
'timeout' => 2000,
|
|
|
|
'sound' => false,
|
|
|
|
];
|
|
|
|
}
|
2015-11-11 00:30:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-09 00:56:55 +00:00
|
|
|
// Set header, convert the array to json, print it and exit
|
2015-12-08 22:42:50 +00:00
|
|
|
echo json_encode($notifications, JSON_NUMERIC_CHECK);
|
2015-05-09 00:56:55 +00:00
|
|
|
exit;
|
2015-11-04 21:26:58 +00:00
|
|
|
} elseif (isset($_REQUEST['comment-action']) && $_REQUEST['comment-action']) {
|
2015-09-18 21:56:54 +00:00
|
|
|
// Referrer
|
2016-03-19 15:29:47 +00:00
|
|
|
$redirect = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('main.index'));
|
2015-09-18 21:56:54 +00:00
|
|
|
|
|
|
|
// Continue
|
|
|
|
$continue = true;
|
|
|
|
|
2015-11-04 21:26:58 +00:00
|
|
|
// Match session ids for the same reason
|
|
|
|
if (!Users::checkLogin()) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You must be logged in to do that!',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
// Prevent
|
|
|
|
$continue = false;
|
|
|
|
}
|
|
|
|
|
2015-09-18 21:56:54 +00:00
|
|
|
// Match session ids for the same reason
|
|
|
|
if (!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Invalid session, please try again.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
// Prevent
|
|
|
|
$continue = false;
|
|
|
|
}
|
|
|
|
|
2015-10-10 15:51:24 +00:00
|
|
|
// Match session ids for the same reason
|
|
|
|
if (!isset($_REQUEST['category'])) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'No category was set.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
// Prevent
|
|
|
|
$continue = false;
|
|
|
|
}
|
|
|
|
|
2015-09-18 21:56:54 +00:00
|
|
|
// Select the right action
|
|
|
|
if ($continue) {
|
2015-10-10 15:51:24 +00:00
|
|
|
$comments = new Comments($_REQUEST['category']);
|
|
|
|
|
2015-09-18 21:56:54 +00:00
|
|
|
switch (isset($_REQUEST['mode']) ? $_REQUEST['mode'] : false) {
|
2015-10-10 21:17:50 +00:00
|
|
|
case 'vote':
|
|
|
|
$comment = $comments->getComment(isset($_REQUEST['id']) ? $_REQUEST['id'] : 0);
|
|
|
|
|
|
|
|
// Check if the comment was actually made by the current user
|
|
|
|
if (!$comment) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'The requested comment does not exist.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the user can delete comments
|
2015-12-29 21:52:19 +00:00
|
|
|
if (!$currentUser->permission(Site::VOTE_COMMENTS)) {
|
2015-10-10 21:17:50 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You aren\'t allowed to vote on comments.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$comments->makeVote(
|
2016-01-17 01:58:31 +00:00
|
|
|
$currentUser->id,
|
2015-10-10 21:17:50 +00:00
|
|
|
isset($_REQUEST['id']) ? $_REQUEST['id'] : 0,
|
|
|
|
isset($_REQUEST['state']) && $_REQUEST['state'] ? '1' : '0'
|
|
|
|
);
|
|
|
|
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Your vote has been cast!',
|
|
|
|
'success' => 1,
|
|
|
|
];
|
2015-09-18 21:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
2015-10-10 15:51:24 +00:00
|
|
|
$comment = $comments->getComment(isset($_REQUEST['id']) ? $_REQUEST['id'] : 0);
|
|
|
|
|
|
|
|
// Check if the comment was actually made by the current user
|
|
|
|
if (!$comment) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'The requested comment does not exist.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the user can delete comments
|
2015-12-29 21:52:19 +00:00
|
|
|
if (!$currentUser->permission(Site::DELETE_COMMENTS)) {
|
2015-10-10 15:51:24 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
2015-10-10 21:17:50 +00:00
|
|
|
'message' => 'You aren\'t allowed to delete comments.',
|
2015-10-10 15:51:24 +00:00
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the comment was actually made by the current user
|
2016-01-17 01:58:31 +00:00
|
|
|
if ($comment['comment_poster'] !== $currentUser->id) {
|
2015-10-10 15:51:24 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You can\'t delete the comments of others.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$comments->removeComment(isset($_REQUEST['id']) ? $_REQUEST['id'] : 0);
|
|
|
|
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'The comment has been deleted!',
|
|
|
|
'success' => 1,
|
|
|
|
];
|
2015-10-06 19:51:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'comment':
|
2015-10-10 15:51:24 +00:00
|
|
|
// Check if the user can delete comments
|
2015-12-29 21:52:19 +00:00
|
|
|
if (!$currentUser->permission(Site::CREATE_COMMENTS)) {
|
2015-10-10 15:51:24 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You aren\'t allowed to comment.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-06 19:51:07 +00:00
|
|
|
// Attempt to make a new comment
|
2016-01-17 01:58:31 +00:00
|
|
|
$comment = $comments->makeComment($currentUser->id, $_POST['replyto'], $_POST['comment']);
|
2015-10-06 19:51:07 +00:00
|
|
|
|
|
|
|
// Messages
|
|
|
|
$messages = [
|
|
|
|
'TOO_SHORT' => 'The comment you\'re trying to make is too short!',
|
|
|
|
'TOO_LONG' => 'The comment you\'re trying to make is too long!',
|
|
|
|
'SUCCESS' => 'Posted!',
|
|
|
|
];
|
2015-09-18 21:56:54 +00:00
|
|
|
|
2015-10-06 19:51:07 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => $messages[$comment[1]],
|
|
|
|
'success' => $comment[0],
|
|
|
|
];
|
2015-09-18 21:56:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
2015-10-06 19:51:07 +00:00
|
|
|
'message' => 'Unknown action.',
|
2015-09-18 21:56:54 +00:00
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print page contents or if the AJAX request is set only display the render data
|
2015-11-06 22:36:05 +00:00
|
|
|
if (isset($_REQUEST['ajax'])) {
|
|
|
|
echo $renderData['page']['message'] . '|' .
|
|
|
|
$renderData['page']['success'] . '|' .
|
|
|
|
$renderData['page']['redirect'];
|
|
|
|
} else {
|
|
|
|
// If not allowed print the restricted page
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2015-11-06 22:36:05 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2015-11-06 22:36:05 +00:00
|
|
|
}
|
2015-09-18 21:56:54 +00:00
|
|
|
exit;
|
2015-09-14 20:51:23 +00:00
|
|
|
} elseif (isset($_REQUEST['friend-action']) && $_REQUEST['friend-action'] && Users::checkLogin()) {
|
2015-06-20 16:06:07 +00:00
|
|
|
// Continue
|
|
|
|
$continue = true;
|
|
|
|
|
|
|
|
// Referrer
|
2016-03-19 15:29:47 +00:00
|
|
|
$redirect = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('main.index'));
|
2015-06-20 16:06:07 +00:00
|
|
|
|
|
|
|
// Compare time and session so we know the link isn't forged
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!isset($_REQUEST['add']) && !isset($_REQUEST['remove'])) {
|
|
|
|
if (!isset($_REQUEST['ajax'])) {
|
|
|
|
header('Location: ' . $redirect);
|
2015-06-20 19:25:41 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2015-06-20 16:06:07 +00:00
|
|
|
$renderData['page'] = [
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'One of the required operators isn\'t set.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-20 16:06:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Prevent
|
|
|
|
$continue = false;
|
2015-06-19 23:44:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-20 16:06:07 +00:00
|
|
|
// Compare time and session so we know the link isn't forged
|
2016-01-17 01:58:31 +00:00
|
|
|
if ($continue && $_REQUEST[(isset($_REQUEST['add']) ? 'add' : 'remove')] == $currentUser->id) {
|
2015-06-20 16:06:07 +00:00
|
|
|
$renderData['page'] = [
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You can\'t be friends with yourself, stop trying to bend reality.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-20 16:06:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Prevent
|
|
|
|
$continue = false;
|
2015-06-19 23:44:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-20 16:06:07 +00:00
|
|
|
// Compare time and session so we know the link isn't forged
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!isset($_REQUEST['time']) || $_REQUEST['time'] < time() - 1000) {
|
2015-06-20 16:06:07 +00:00
|
|
|
$renderData['page'] = [
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Timestamps differ too much, refresh the page and try again.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-20 16:06:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Prevent
|
|
|
|
$continue = false;
|
2015-06-19 23:44:16 +00:00
|
|
|
}
|
2015-06-20 16:06:07 +00:00
|
|
|
|
|
|
|
// Match session ids for the same reason
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) {
|
2015-06-20 16:06:07 +00:00
|
|
|
$renderData['page'] = [
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Invalid session, please try again.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-06-20 16:06:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Prevent
|
|
|
|
$continue = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue if nothing fucked up
|
2015-09-14 20:51:23 +00:00
|
|
|
if ($continue) {
|
2015-06-20 16:06:07 +00:00
|
|
|
// Execute the action
|
2015-09-14 21:41:43 +00:00
|
|
|
$action = (isset($_REQUEST['add']) ?
|
2015-10-12 18:25:37 +00:00
|
|
|
$currentUser->addFriend($_REQUEST['add']) :
|
|
|
|
$currentUser->removeFriend($_REQUEST['remove'], true));
|
2015-06-20 16:06:07 +00:00
|
|
|
|
|
|
|
// Set the messages
|
|
|
|
$messages = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'USER_NOT_EXIST' => 'The user you tried to add doesn\'t exist.',
|
|
|
|
'ALREADY_FRIENDS' => 'You are already friends with this person!',
|
|
|
|
'FRIENDS' => 'You are now mutual friends!',
|
|
|
|
'NOT_MUTUAL' => 'A friend request has been sent to this person.',
|
|
|
|
'ALREADY_REMOVED' => 'You aren\'t friends with this person.',
|
|
|
|
'REMOVED' => 'Removed this person from your friends list.',
|
2015-06-20 16:06:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Notification strings
|
|
|
|
$notifStrings = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'FRIENDS' => ['%s accepted your friend request!', 'You can now do mutual friend things!'],
|
|
|
|
'NOT_MUTUAL' => ['%s added you as a friend!', 'Click here to add them as well.'],
|
|
|
|
'REMOVED' => ['%s removed you from their friends.', 'You can no longer do friend things now ;_;'],
|
2015-06-20 16:06:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Add page specific things
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => $messages[$action[1]],
|
|
|
|
'success' => $action[0],
|
2015-06-20 16:06:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Create a notification
|
2015-09-14 20:51:23 +00:00
|
|
|
if (array_key_exists($action[1], $notifStrings)) {
|
2015-06-20 16:06:07 +00:00
|
|
|
// Get the current user's profile data
|
2016-01-17 01:58:31 +00:00
|
|
|
$user = User::construct($currentUser->id);
|
2016-03-26 16:36:58 +00:00
|
|
|
$friend = User::construct($_REQUEST[(isset($_REQUEST['add']) ? 'add' : 'remove')]);
|
|
|
|
|
|
|
|
$alert = new Notification;
|
|
|
|
|
|
|
|
$alert->user = $friend->id;
|
|
|
|
$alert->time = time();
|
|
|
|
$alert->sound = true;
|
|
|
|
$alert->title = sprintf($notifStrings[$action[1]][0], $user->username);
|
|
|
|
$alert->text = $notifStrings[$action[1]][1];
|
|
|
|
$alert->image = Router::route('file.avatar', $user->id);
|
|
|
|
$alert->timeout = 60000;
|
|
|
|
$alert->link = Router::route('user.profile', $user->id);
|
2015-06-20 16:06:07 +00:00
|
|
|
|
2016-03-26 16:36:58 +00:00
|
|
|
$alert->save();
|
2015-06-20 16:06:07 +00:00
|
|
|
}
|
2015-06-19 23:44:16 +00:00
|
|
|
}
|
2015-06-20 16:06:07 +00:00
|
|
|
|
|
|
|
// Print page contents or if the AJAX request is set only display the render data
|
2015-11-06 22:36:05 +00:00
|
|
|
if (isset($_REQUEST['ajax'])) {
|
|
|
|
echo $renderData['page']['message'] . '|' .
|
|
|
|
$renderData['page']['success'] . '|' .
|
|
|
|
$renderData['page']['redirect'];
|
|
|
|
} else {
|
|
|
|
// If not allowed print the restricted page
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2015-11-06 22:36:05 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2015-11-06 22:36:05 +00:00
|
|
|
}
|
2015-06-19 23:44:16 +00:00
|
|
|
exit;
|
2015-09-14 20:51:23 +00:00
|
|
|
} elseif (isset($_POST['submit']) && isset($_POST['submit'])) {
|
2015-08-08 00:37:56 +00:00
|
|
|
$continue = true;
|
|
|
|
|
2015-09-05 16:11:04 +00:00
|
|
|
// Set redirector
|
|
|
|
$redirect = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('SETTINGS_INDEX');
|
|
|
|
|
2015-08-08 00:37:56 +00:00
|
|
|
// Check if the user is logged in
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!Users::checkLogin() || !$continue) {
|
2015-08-08 00:37:56 +00:00
|
|
|
$renderData['page'] = [
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => '/authenticate',
|
|
|
|
'message' => 'You must be logged in to edit your settings.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-08-08 00:37:56 +00:00
|
|
|
];
|
|
|
|
|
2015-09-16 20:34:36 +00:00
|
|
|
$continue = false;
|
2015-08-08 00:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check session variables
|
2016-01-17 01:58:31 +00:00
|
|
|
if (!isset($_POST['timestamp'])
|
|
|
|
|| !isset($_POST['mode'])
|
|
|
|
|| $_POST['timestamp'] < time() - 1000
|
|
|
|
|| !isset($_POST['sessid'])
|
|
|
|
|| $_POST['sessid'] != session_id()
|
2015-09-14 21:41:43 +00:00
|
|
|
|| !$continue) {
|
2015-08-08 00:37:56 +00:00
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Your session has expired, please refresh the page and try again.',
|
|
|
|
'success' => 0,
|
2015-08-08 00:37:56 +00:00
|
|
|
];
|
|
|
|
|
2015-09-16 20:34:36 +00:00
|
|
|
$continue = false;
|
2015-08-08 00:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Change settings
|
2015-09-14 20:51:23 +00:00
|
|
|
if ($continue) {
|
2015-08-08 00:37:56 +00:00
|
|
|
// Switch to the correct mode
|
2015-09-14 20:51:23 +00:00
|
|
|
switch ($_POST['mode']) {
|
2015-08-10 19:09:47 +00:00
|
|
|
// Avatar & Background
|
2015-08-09 18:26:01 +00:00
|
|
|
case 'avatar':
|
2015-08-10 19:09:47 +00:00
|
|
|
case 'background':
|
2016-01-17 01:58:31 +00:00
|
|
|
case 'header':
|
2015-08-10 19:09:47 +00:00
|
|
|
// Assign $_POST['mode'] to a $mode variable because I ain't typin that more than once
|
|
|
|
$mode = $_POST['mode'];
|
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Assign the correct column and title to a variable
|
2015-09-14 20:51:23 +00:00
|
|
|
switch ($mode) {
|
2015-08-10 19:09:47 +00:00
|
|
|
case 'background':
|
2016-03-13 20:35:51 +00:00
|
|
|
$column = 'user_background';
|
2015-09-14 20:51:23 +00:00
|
|
|
$msgTitle = 'Background';
|
2016-01-17 01:58:31 +00:00
|
|
|
$current = $currentUser->background;
|
|
|
|
$permission = $currentUser->permission(Site::CHANGE_BACKGROUND);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'header':
|
2016-03-13 20:35:51 +00:00
|
|
|
$column = 'user_header';
|
2016-01-17 01:58:31 +00:00
|
|
|
$msgTitle = 'Header';
|
|
|
|
$current = $currentUser->header;
|
|
|
|
$permission = $currentUser->permission(Site::CHANGE_HEADER);
|
2015-08-10 19:09:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'avatar':
|
|
|
|
default:
|
2016-03-13 20:35:51 +00:00
|
|
|
$column = 'user_avatar';
|
2015-09-14 20:51:23 +00:00
|
|
|
$msgTitle = 'Avatar';
|
2016-01-17 01:58:31 +00:00
|
|
|
$current = $currentUser->avatar;
|
2015-12-29 21:52:19 +00:00
|
|
|
$permission = $currentUser->permission(Site::CHANGE_AVATAR);
|
2015-08-21 22:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the user has the permissions to go ahead
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!$permission) {
|
2015-08-21 22:07:45 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You are not allowed to alter your ' . strtolower($msgTitle) . '.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
break;
|
2015-08-10 19:09:47 +00:00
|
|
|
}
|
2015-08-09 18:26:01 +00:00
|
|
|
|
|
|
|
// Set path variables
|
2016-01-17 01:58:31 +00:00
|
|
|
$filename = strtolower($msgTitle) . '_' . $currentUser->id;
|
2015-08-09 18:26:01 +00:00
|
|
|
|
|
|
|
// Check if $_FILES is set
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!isset($_FILES[$mode]) && empty($_FILES[$mode])) {
|
2015-08-09 18:26:01 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'No file was uploaded.',
|
|
|
|
'success' => 0,
|
2015-08-09 18:26:01 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the upload went properly
|
2015-09-14 20:51:23 +00:00
|
|
|
if ($_FILES[$mode]['error'] !== UPLOAD_ERR_OK && $_FILES[$mode]['error'] !== UPLOAD_ERR_NO_FILE) {
|
2015-08-09 18:26:01 +00:00
|
|
|
// Get the error in text
|
2015-09-14 20:51:23 +00:00
|
|
|
switch ($_FILES[$mode]['error']) {
|
2015-08-09 18:26:01 +00:00
|
|
|
case UPLOAD_ERR_INI_SIZE:
|
|
|
|
case UPLOAD_ERR_FORM_SIZE:
|
|
|
|
$msg = 'The uploaded file exceeds the maximum filesize!';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UPLOAD_ERR_PARTIAL:
|
|
|
|
$msg = 'The upload was interrupted!';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UPLOAD_ERR_NO_TMP_DIR:
|
|
|
|
case UPLOAD_ERR_CANT_WRITE:
|
|
|
|
$msg = 'Unable to save file to temporary location, contact the administrator!';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UPLOAD_ERR_EXTENSION:
|
|
|
|
default:
|
|
|
|
$msg = 'An unknown exception occurred!';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => $msg,
|
|
|
|
'success' => 0,
|
2015-08-09 18:26:01 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Check if we're not in removal mode
|
2015-09-14 20:51:23 +00:00
|
|
|
if ($_FILES[$mode]['error'] != UPLOAD_ERR_NO_FILE) {
|
2015-08-21 22:07:45 +00:00
|
|
|
// Get the meta data
|
|
|
|
$metadata = getimagesize($_FILES[$mode]['tmp_name']);
|
2015-08-09 18:26:01 +00:00
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Check if the image is actually an image
|
2016-02-27 17:28:45 +00:00
|
|
|
if (!$metadata) {
|
2015-08-21 22:07:45 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Uploaded file is not an image.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
];
|
2015-08-09 18:26:01 +00:00
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-08-09 18:26:01 +00:00
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Check if the image is an allowed filetype
|
2015-09-14 21:41:43 +00:00
|
|
|
if ((($metadata[2] !== IMAGETYPE_GIF)
|
|
|
|
&& ($metadata[2] !== IMAGETYPE_JPEG)
|
|
|
|
&& ($metadata[2] !== IMAGETYPE_PNG))) {
|
2015-08-21 22:07:45 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'This filetype is not allowed.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
2015-08-09 18:26:01 +00:00
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Check if the image is too large
|
2015-12-04 14:19:10 +00:00
|
|
|
if (($metadata[0] > Config::get($mode . '_max_width')
|
|
|
|
|| $metadata[1] > Config::get($mode . '_max_height'))) {
|
2015-08-21 22:07:45 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'The resolution of this picture is too big.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
2015-08-09 18:26:01 +00:00
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Check if the image is too small
|
2015-12-04 14:19:10 +00:00
|
|
|
if (($metadata[0] < Config::get($mode . '_min_width')
|
|
|
|
|| $metadata[1] < Config::get($mode . '_min_height'))) {
|
2015-08-21 22:07:45 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'The resolution of this picture is too small.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
2015-08-09 18:26:01 +00:00
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Check if the file is too large
|
2015-12-04 14:19:10 +00:00
|
|
|
if ((filesize($_FILES[$mode]['tmp_name']) > Config::get($mode . '_max_fsize'))) {
|
2015-08-21 22:07:45 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'The filesize of this file is too large.',
|
|
|
|
'success' => 0,
|
2015-08-21 22:07:45 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
2015-08-09 18:26:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Open the old file and remove it
|
|
|
|
$oldFile = new File($current);
|
|
|
|
$oldFile->delete();
|
|
|
|
unset($oldFile);
|
|
|
|
$fileId = 0;
|
2015-08-09 19:19:11 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
if ($_FILES[$mode]['error'] != UPLOAD_ERR_NO_FILE) {
|
2015-08-21 22:07:45 +00:00
|
|
|
// Append extension to filename
|
|
|
|
$filename .= image_type_to_extension($metadata[2]);
|
2015-08-09 18:26:01 +00:00
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Store the file
|
|
|
|
$file = File::create(file_get_contents($_FILES[$mode]['tmp_name']), $filename, $currentUser);
|
2015-08-09 18:26:01 +00:00
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Assign the file id to a variable
|
|
|
|
$fileId = $file->id;
|
2015-08-19 19:44:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Update table
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('users')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->update([
|
|
|
|
$column => $fileId,
|
|
|
|
]);
|
2015-08-09 18:26:01 +00:00
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Updated your ' . strtolower($msgTitle) . '!',
|
|
|
|
'success' => 1,
|
2015-08-09 18:26:01 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2015-08-08 00:37:56 +00:00
|
|
|
// Profile
|
|
|
|
case 'profile':
|
|
|
|
// Get profile fields and create storage var
|
|
|
|
$fields = Users::getProfileFields();
|
|
|
|
|
2016-03-13 20:35:51 +00:00
|
|
|
// Delete all profile fields
|
|
|
|
DB::table('user_profilefields')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->delete();
|
|
|
|
|
2015-08-08 00:37:56 +00:00
|
|
|
// Go over each field
|
2015-09-14 20:51:23 +00:00
|
|
|
foreach ($fields as $field) {
|
2015-08-08 00:37:56 +00:00
|
|
|
// Add to the store array
|
2015-10-10 21:17:50 +00:00
|
|
|
if (isset($_POST['profile_' . $field['field_identity']]) && !empty($_POST['profile_' . $field['field_identity']])) {
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('user_profilefields')
|
|
|
|
->insert([
|
|
|
|
'user_id' => $currentUser->id,
|
|
|
|
'field_name' => $field['field_identity'],
|
|
|
|
'field_value' => $_POST['profile_' . $field['field_identity']],
|
|
|
|
]);
|
2015-08-08 00:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if there's additional values we should keep in mind
|
2015-10-10 21:17:50 +00:00
|
|
|
if (isset($field['field_additional']) && !empty($field['field_additional'])) {
|
2015-08-08 00:37:56 +00:00
|
|
|
// Go over each additional value
|
2015-10-10 21:17:50 +00:00
|
|
|
foreach ($field['field_additional'] as $addKey => $addVal) {
|
2015-08-08 00:37:56 +00:00
|
|
|
// Add to the array
|
2016-01-17 01:58:31 +00:00
|
|
|
$store = (isset($_POST['profile_additional_' . $addKey]) || !empty($_POST['profile_additional_' . $addKey])) ? $_POST['profile_additional_' . $addKey] : false;
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('user_profilefields')
|
|
|
|
->insert([
|
|
|
|
'user_id' => $currentUser->id,
|
|
|
|
'field_name' => $addKey,
|
|
|
|
'field_value' => $store,
|
|
|
|
]);
|
2015-08-08 00:37:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Your profile has been updated!',
|
|
|
|
'success' => 1,
|
2015-08-08 00:37:56 +00:00
|
|
|
];
|
|
|
|
|
2015-09-08 21:57:33 +00:00
|
|
|
// Birthdays
|
2015-09-14 21:41:43 +00:00
|
|
|
if (isset($_POST['birthday_day'])
|
|
|
|
&& isset($_POST['birthday_month'])
|
|
|
|
&& isset($_POST['birthday_year'])) {
|
2015-09-08 21:57:33 +00:00
|
|
|
// Check if the values aren't fucked with
|
2015-09-14 21:41:43 +00:00
|
|
|
if ($_POST['birthday_day'] < 0
|
|
|
|
|| $_POST['birthday_day'] > 31
|
|
|
|
|| $_POST['birthday_month'] < 0
|
|
|
|
|| $_POST['birthday_month'] > 12
|
|
|
|
|| (
|
|
|
|
$_POST['birthday_year'] != 0
|
|
|
|
&& $_POST['birthday_year'] < (date("Y") - 100)
|
|
|
|
)
|
|
|
|
|| $_POST['birthday_year'] > date("Y")) {
|
2015-09-08 21:57:33 +00:00
|
|
|
$renderData['page']['message'] = 'Your birthdate is invalid.';
|
|
|
|
$renderData['page']['success'] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the values aren't fucked with
|
2015-09-14 21:41:43 +00:00
|
|
|
if ((
|
|
|
|
$_POST['birthday_day'] < 1
|
|
|
|
&& $_POST['birthday_month'] > 0
|
|
|
|
)
|
|
|
|
|| (
|
|
|
|
$_POST['birthday_day'] > 0
|
|
|
|
&& $_POST['birthday_month'] < 1)
|
|
|
|
) {
|
2015-09-08 21:57:33 +00:00
|
|
|
$renderData['page']['message'] = 'Only setting a day or month is disallowed.';
|
|
|
|
$renderData['page']['success'] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the values aren't fucked with
|
2015-09-14 21:41:43 +00:00
|
|
|
if ($_POST['birthday_year'] > 0
|
|
|
|
&& (
|
|
|
|
$_POST['birthday_day'] < 1
|
|
|
|
|| $_POST['birthday_month'] < 1
|
|
|
|
)
|
|
|
|
) {
|
2015-09-08 21:57:33 +00:00
|
|
|
$renderData['page']['message'] = 'Only setting a year is disallowed.';
|
|
|
|
$renderData['page']['success'] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-14 21:41:43 +00:00
|
|
|
$birthdate = implode(
|
|
|
|
'-',
|
|
|
|
[$_POST['birthday_year'], $_POST['birthday_month'], $_POST['birthday_day']]
|
|
|
|
);
|
2015-09-08 21:57:33 +00:00
|
|
|
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('users')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->update([
|
|
|
|
'user_birthday' => $birthdate,
|
|
|
|
]);
|
2015-09-08 21:57:33 +00:00
|
|
|
}
|
2015-08-08 00:37:56 +00:00
|
|
|
break;
|
|
|
|
|
2015-09-16 20:34:36 +00:00
|
|
|
// Site Options
|
2015-08-21 22:07:45 +00:00
|
|
|
case 'options':
|
|
|
|
// Get profile fields and create storage var
|
|
|
|
$fields = Users::getOptionFields();
|
|
|
|
|
2016-03-13 20:35:51 +00:00
|
|
|
// Delete all option fields for this user
|
|
|
|
DB::table('user_optionfields')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->delete();
|
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Go over each field
|
2015-09-14 20:51:23 +00:00
|
|
|
foreach ($fields as $field) {
|
2015-08-23 22:08:36 +00:00
|
|
|
// Make sure the user has sufficient permissions to complete this action
|
2015-12-29 21:52:19 +00:00
|
|
|
if (!$currentUser->permission(constant('Sakura\Perms\Site::' . $field['option_permission']))) {
|
2015-08-23 22:08:36 +00:00
|
|
|
continue;
|
2015-08-21 22:07:45 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
if (isset($_POST['option_' . $field['option_id']])
|
2016-03-13 20:35:51 +00:00
|
|
|
&& !empty($_POST['option_' . $field['option_id']])) {
|
|
|
|
DB::table('user_optionfields')
|
|
|
|
->insert([
|
|
|
|
'user_id' => $currentUser->id,
|
|
|
|
'field_name' => $field['option_id'],
|
|
|
|
'field_value' => $_POST['option_' . $field['option_id']],
|
|
|
|
]);
|
2016-01-17 01:58:31 +00:00
|
|
|
}
|
2015-08-21 22:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Changed your options!',
|
|
|
|
'success' => 1,
|
2015-08-21 22:07:45 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2015-09-16 20:34:36 +00:00
|
|
|
// Usertitle
|
|
|
|
case 'usertitle':
|
|
|
|
// Check permissions
|
2015-12-29 21:52:19 +00:00
|
|
|
if (!$currentUser->permission(Site::CHANGE_USERTITLE)) {
|
2015-09-16 20:34:36 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You aren\'t allowed to change your usertitle.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check length
|
|
|
|
if (isset($_POST['usertitle']) ? (strlen($_POST['usertitle']) > 64) : false) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Your usertitle is too long.',
|
|
|
|
'success' => 0,
|
|
|
|
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update database
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('users')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->update([
|
|
|
|
'user_title' => (isset($_POST['usertitle']) ? $_POST['usertitle'] : null),
|
|
|
|
]);
|
2015-09-16 20:34:36 +00:00
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Updated your usertitle!',
|
|
|
|
'success' => 1,
|
|
|
|
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2015-09-23 20:45:42 +00:00
|
|
|
// Username changing
|
|
|
|
case 'username':
|
|
|
|
// Check permissions
|
2015-12-29 21:52:19 +00:00
|
|
|
if (!$currentUser->permission(Site::CHANGE_USERNAME)) {
|
2015-09-23 20:45:42 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You aren\'t allowed to change your username.',
|
|
|
|
'success' => 0,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt username change
|
|
|
|
$userNameChange = $currentUser->setUsername(isset($_POST['username']) ? $_POST['username'] : '');
|
|
|
|
|
|
|
|
// Messages
|
|
|
|
$messages = [
|
|
|
|
'TOO_SHORT' => 'Your new name is too short!',
|
|
|
|
'TOO_LONG' => 'Your new name is too long!',
|
|
|
|
'TOO_RECENT' => 'The username you tried to use is reserved, try again later.',
|
|
|
|
'IN_USE' => 'Someone already has this username!',
|
|
|
|
'SUCCESS' => 'Successfully changed your username!',
|
|
|
|
];
|
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => $messages[$userNameChange[1]],
|
|
|
|
'success' => $userNameChange[0],
|
|
|
|
|
|
|
|
];
|
2015-09-26 16:12:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// E-mail changing
|
|
|
|
case 'email':
|
|
|
|
// Check permissions
|
2015-12-29 21:52:19 +00:00
|
|
|
if (!$currentUser->permission(Site::CHANGE_EMAIL)) {
|
2015-09-26 16:12:42 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You aren\'t allowed to change your e-mail address.',
|
|
|
|
'success' => 0,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt e-mail change
|
|
|
|
$emailChange = $currentUser->setEMailAddress(isset($_POST['email']) ? $_POST['email'] : '');
|
|
|
|
|
|
|
|
// Messages
|
|
|
|
$messages = [
|
|
|
|
'INVALID' => 'Your e-mail isn\'t considered valid!',
|
|
|
|
'IN_USE' => 'This e-mail address has already been used!',
|
|
|
|
'SUCCESS' => 'Successfully changed your e-mail address!',
|
|
|
|
];
|
2015-09-23 20:45:42 +00:00
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => $messages[$emailChange[1]],
|
|
|
|
'success' => $emailChange[0],
|
|
|
|
|
|
|
|
];
|
2015-09-23 20:45:42 +00:00
|
|
|
break;
|
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
// Password changing
|
|
|
|
case 'password':
|
|
|
|
// Check permissions
|
2015-12-29 21:52:19 +00:00
|
|
|
if (!$currentUser->permission(Site::CHANGE_PASSWORD)) {
|
2015-09-26 16:12:42 +00:00
|
|
|
$renderData['page'] = [
|
2015-08-10 19:09:47 +00:00
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You aren\'t allowed to change your password.',
|
|
|
|
'success' => 0,
|
2015-08-10 19:09:47 +00:00
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
];
|
2015-08-10 19:09:47 +00:00
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-08-10 19:09:47 +00:00
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
// Attempt password change
|
|
|
|
$passChange = $currentUser->setPassword(isset($_POST['oldpassword']) ? $_POST['oldpassword'] : '', isset($_POST['newpassword']) ? $_POST['newpassword'] : '', isset($_POST['newpasswordconfirm']) ? $_POST['newpasswordconfirm'] : '');
|
2015-08-10 19:09:47 +00:00
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
// Messages
|
|
|
|
$messages = [
|
|
|
|
'NO_LOGIN' => 'How are you even logged in right now?',
|
|
|
|
'INCORRECT_PASSWORD' => 'The password you provided is incorrect!',
|
|
|
|
'PASS_TOO_SHIT' => 'Your password isn\'t strong enough!',
|
|
|
|
'PASS_NOT_MATCH' => 'Your new passwords don\'t match!',
|
|
|
|
'SUCCESS' => 'Successfully changed your password!',
|
|
|
|
];
|
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => $messages[$passChange[1]],
|
|
|
|
'success' => $passChange[0],
|
2015-08-10 19:09:47 +00:00
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Userpage
|
|
|
|
case 'userpage':
|
|
|
|
if (!isset($_POST['userpage'])) {
|
|
|
|
// Set render data
|
2015-09-26 16:12:42 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
2016-01-17 01:58:31 +00:00
|
|
|
'message' => 'No userpage was supplied.',
|
2015-09-26 16:12:42 +00:00
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Update database
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('users')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->update([
|
|
|
|
'user_page' => $_POST['userpage'],
|
|
|
|
]);
|
2016-01-17 01:58:31 +00:00
|
|
|
|
2015-09-26 16:12:42 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
2016-01-17 01:58:31 +00:00
|
|
|
'message' => 'Your userpage has been updated!',
|
2015-09-26 16:12:42 +00:00
|
|
|
'success' => 1,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Signature
|
|
|
|
case 'signature':
|
|
|
|
if (!isset($_POST['signature'])) {
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'No signature was supplied.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
}
|
2015-09-26 16:12:42 +00:00
|
|
|
|
|
|
|
// Update database
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('users')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->update([
|
|
|
|
'user_signature' => $_POST['signature'],
|
|
|
|
]);
|
2015-09-26 16:12:42 +00:00
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
2016-01-17 01:58:31 +00:00
|
|
|
'message' => 'Your signature has been updated!',
|
2015-09-26 16:12:42 +00:00
|
|
|
'success' => 1,
|
|
|
|
];
|
|
|
|
break;
|
2015-08-10 19:09:47 +00:00
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Ranks
|
|
|
|
case 'ranks':
|
|
|
|
// Check submit data
|
|
|
|
if (!isset($_POST['rank'])) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'No rank was set.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
2015-10-24 08:55:45 +00:00
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Check if the user is part of the rank
|
|
|
|
if (!$currentUser->hasRanks([$_POST['rank']])) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You are not in this rank.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leaving
|
|
|
|
if (isset($_POST['remove'])) {
|
|
|
|
// Check if we're not trying to leave hardranks
|
|
|
|
if ($_POST['rank'] <= 2) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You can\'t remove this rank.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the rank
|
|
|
|
$currentUser->removeRanks([$_POST['rank']]);
|
|
|
|
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Removed the rank from your account.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set as default
|
|
|
|
$currentUser->setMainRank($_POST['rank']);
|
2015-10-24 08:55:45 +00:00
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2016-01-17 01:58:31 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Changed your main rank!',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
2015-10-24 08:55:45 +00:00
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
// Sessions
|
|
|
|
case 'sessions':
|
|
|
|
// Check if sessionid is set
|
|
|
|
if (!isset($_POST['sessionid'])) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'A required field wasn\'t set.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if sessionid is set to all
|
|
|
|
if ($_POST['sessionid'] === 'all') {
|
|
|
|
// Delete all sessions assigned to the current user
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('sessions')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->delete();
|
2016-01-17 01:58:31 +00:00
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Killed all active sessions!',
|
|
|
|
'success' => 1,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the session is owned by the current user
|
2016-03-13 20:35:51 +00:00
|
|
|
$us = DB::table('sessions')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->where('session_id', $_POST['sessionid'])
|
|
|
|
->count();
|
|
|
|
if (!$us) {
|
2016-01-17 01:58:31 +00:00
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'The session you tried to kill doesn\'t exist.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the session
|
2016-03-13 20:35:51 +00:00
|
|
|
DB::table('sessions')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->where('session_id', $_POST['sessionid'])
|
|
|
|
->delete();
|
2016-01-17 01:58:31 +00:00
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-10-24 08:55:45 +00:00
|
|
|
'redirect' => $redirect,
|
2016-01-17 01:58:31 +00:00
|
|
|
'message' => 'Killed the session!',
|
2015-10-24 08:55:45 +00:00
|
|
|
'success' => 1,
|
2016-01-17 01:58:31 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Deactivation
|
|
|
|
case 'deactivate':
|
|
|
|
// Check permissions
|
|
|
|
if (!$currentUser->permission(Site::DEACTIVATE_ACCOUNT)) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'You aren\'t allowed to deactivate your account.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check fields
|
|
|
|
if (!isset($_POST['username'])
|
|
|
|
|| !isset($_POST['password'])
|
|
|
|
|| !isset($_POST['email'])
|
|
|
|
|| !isset($_POST['sensitive'])) {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'One or more forms wasn\'t set.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check values
|
|
|
|
if ($_POST['username'] !== $currentUser->username
|
|
|
|
|| !Hashing::validatePassword($_POST['password'], [$currentUser->passwordAlgo, $currentUser->passwordIter, $currentUser->passwordSalt, $currentUser->passwordHash])
|
|
|
|
|| $_POST['email'] !== $currentUser->email
|
|
|
|
|| md5($_POST['sensitive']) !== '81df445067d92dd02db9098ba82b0167') {
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'One or more forms wasn\'t correct.',
|
|
|
|
'success' => 0,
|
|
|
|
];
|
2015-10-24 08:55:45 +00:00
|
|
|
|
2016-01-17 01:58:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deactivate account
|
|
|
|
$currentUser->removeRanks(array_keys($currentUser->ranks));
|
|
|
|
$currentUser->addRanks([1]);
|
|
|
|
$currentUser->setMainRank(1);
|
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'Your account has been deactivated!',
|
|
|
|
'success' => 1,
|
2015-10-24 08:55:45 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2015-08-08 00:37:56 +00:00
|
|
|
// Fallback
|
|
|
|
default:
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
'redirect' => $redirect,
|
|
|
|
'message' => 'The requested method does not exist.',
|
|
|
|
'success' => 0,
|
2015-08-08 00:37:56 +00:00
|
|
|
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print page contents or if the AJAX request is set only display the render data
|
2015-11-06 22:36:05 +00:00
|
|
|
if (isset($_REQUEST['ajax'])) {
|
|
|
|
echo $renderData['page']['message'] . '|' .
|
|
|
|
$renderData['page']['success'] . '|' .
|
|
|
|
$renderData['page']['redirect'];
|
|
|
|
} else {
|
|
|
|
// If not allowed print the restricted page
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2015-11-06 22:36:05 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2015-11-06 22:36:05 +00:00
|
|
|
}
|
2015-08-08 00:37:56 +00:00
|
|
|
exit;
|
2015-05-09 00:56:55 +00:00
|
|
|
}
|
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
if (Users::checkLogin()) {
|
2015-06-20 19:25:41 +00:00
|
|
|
// Settings page list
|
|
|
|
$pages = [
|
2015-08-23 22:08:36 +00:00
|
|
|
'general' => [
|
|
|
|
'title' => 'General',
|
|
|
|
'modes' => [
|
|
|
|
'home' => [
|
|
|
|
'title' => 'Home',
|
|
|
|
'description' => [
|
|
|
|
|
2015-09-14 21:41:43 +00:00
|
|
|
'Welcome to the Settings Panel.
|
|
|
|
From here you can monitor, view and update your profile and preferences.',
|
2015-08-23 22:08:36 +00:00
|
|
|
|
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => !$currentUser->permission(Site::DEACTIVATED),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'profile' => [
|
|
|
|
'title' => 'Edit Profile',
|
|
|
|
'description' => [
|
2015-09-14 21:41:43 +00:00
|
|
|
'These are the external account links etc.
|
|
|
|
on your profile, shouldn\'t need any additional explanation for this one.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::ALTER_PROFILE),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'options' => [
|
|
|
|
'title' => 'Site Options',
|
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'These are a few personalisation options for the site while you\'re logged in.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => !$currentUser->permission(Site::DEACTIVATED),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-12-10 20:55:51 +00:00
|
|
|
],
|
2015-09-14 20:51:23 +00:00
|
|
|
],
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'friends' => [
|
|
|
|
'title' => 'Friends',
|
|
|
|
'modes' => [
|
|
|
|
'listing' => [
|
|
|
|
'title' => 'Listing',
|
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'Manage your friends.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::MANAGE_FRIENDS),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'requests' => [
|
|
|
|
'title' => 'Requests',
|
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'Handle friend requests.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::MANAGE_FRIENDS),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
|
|
|
],
|
|
|
|
],
|
2016-01-18 20:21:08 +00:00
|
|
|
]/*,
|
2015-08-23 22:08:36 +00:00
|
|
|
'messages' => [
|
2016-03-13 20:35:51 +00:00
|
|
|
'title' => 'Messages',
|
|
|
|
'modes' => [
|
|
|
|
'inbox' => [
|
|
|
|
'title' => 'Inbox',
|
|
|
|
'description' => [
|
|
|
|
'The list of messages you\'ve received.',
|
|
|
|
],
|
|
|
|
'access' => $currentUser->permission(Site::USE_MESSAGES),
|
|
|
|
'menu' => true,
|
|
|
|
],
|
|
|
|
'sent' => [
|
|
|
|
'title' => 'Sent',
|
|
|
|
'description' => [
|
|
|
|
'The list of messages you\'ve sent to other users.',
|
|
|
|
],
|
|
|
|
'access' => $currentUser->permission(Site::USE_MESSAGES),
|
|
|
|
'menu' => true,
|
|
|
|
],
|
|
|
|
'compose' => [
|
|
|
|
'title' => 'Compose',
|
|
|
|
'description' => [
|
|
|
|
'Write a new message.',
|
|
|
|
],
|
|
|
|
'access' => $currentUser->permission(Site::SEND_MESSAGES),
|
|
|
|
'menu' => true,
|
|
|
|
],
|
|
|
|
'read' => [
|
|
|
|
'title' => 'Read',
|
|
|
|
'description' => [
|
|
|
|
'Read a message.',
|
|
|
|
],
|
|
|
|
'access' => $currentUser->permission(Site::USE_MESSAGES),
|
|
|
|
'menu' => false,
|
|
|
|
],
|
|
|
|
],
|
2016-01-18 20:21:08 +00:00
|
|
|
]*/,
|
2015-08-23 22:08:36 +00:00
|
|
|
'notifications' => [
|
|
|
|
'title' => 'Notifications',
|
|
|
|
'modes' => [
|
|
|
|
'history' => [
|
|
|
|
'title' => 'History',
|
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'The history of notifications that have been sent to you in the last month.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => !$currentUser->permission(Site::DEACTIVATED),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
|
|
|
],
|
|
|
|
],
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'appearance' => [
|
|
|
|
'title' => 'Appearance',
|
|
|
|
'modes' => [
|
|
|
|
'avatar' => [
|
|
|
|
'title' => 'Avatar',
|
|
|
|
'description' => [
|
|
|
|
'Your avatar which is displayed all over the site and on your profile.',
|
2015-09-14 21:41:43 +00:00
|
|
|
'Maximum image size is {{ avatar.max_width }}x{{ avatar.max_height }},
|
|
|
|
minimum image size is {{ avatar.min_width }}x{{ avatar.min_height }},
|
|
|
|
maximum file size is {{ avatar.max_size_view }}.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::CHANGE_AVATAR),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'background' => [
|
|
|
|
'title' => 'Background',
|
|
|
|
'description' => [
|
|
|
|
'The background that is displayed on your profile.',
|
2015-09-14 21:41:43 +00:00
|
|
|
'Maximum image size is {{ background.max_width }}x{{ background.max_height }},
|
|
|
|
minimum image size is {{ background.min_width }}x{{ background.min_height }},
|
|
|
|
maximum file size is {{ background.max_size_view }}.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2016-01-17 01:58:31 +00:00
|
|
|
'access' => $currentUser->permission(Site::CHANGE_BACKGROUND),
|
|
|
|
'menu' => true,
|
|
|
|
],
|
|
|
|
'header' => [
|
|
|
|
'title' => 'Header',
|
|
|
|
'description' => [
|
|
|
|
'The header that is displayed on your profile.',
|
|
|
|
'Maximum image size is {{ header.max_width }}x{{ header.max_height }},
|
|
|
|
minimum image size is {{ header.min_width }}x{{ header.min_height }},
|
|
|
|
maximum file size is {{ header.max_size_view }}.',
|
|
|
|
],
|
|
|
|
'access' => $currentUser->permission(Site::CHANGE_HEADER),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'userpage' => [
|
|
|
|
'title' => 'Userpage',
|
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'The custom text that is displayed on your profile.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-09-14 21:41:43 +00:00
|
|
|
'access' => (
|
2016-01-17 01:58:31 +00:00
|
|
|
$currentUser->page
|
2015-12-29 21:52:19 +00:00
|
|
|
&& $currentUser->permission(Site::CHANGE_USERPAGE)
|
|
|
|
) || $currentUser->permission(Site::CREATE_USERPAGE),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
|
|
|
],
|
2015-10-10 21:17:50 +00:00
|
|
|
'signature' => [
|
|
|
|
'title' => 'Signature',
|
|
|
|
'description' => [
|
|
|
|
'This signature is displayed at the end of all your posts (unless you choose not to show it).',
|
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::CHANGE_SIGNATURE),
|
2015-10-10 21:17:50 +00:00
|
|
|
'menu' => true,
|
|
|
|
],
|
2015-09-14 20:51:23 +00:00
|
|
|
],
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'account' => [
|
|
|
|
'title' => 'Account',
|
|
|
|
'modes' => [
|
|
|
|
'email' => [
|
|
|
|
'title' => 'E-mail Address',
|
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'You e-mail address is used for password recovery and stuff like that, we won\'t spam you ;).',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::CHANGE_EMAIL),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'username' => [
|
|
|
|
'title' => 'Username',
|
|
|
|
'description' => [
|
|
|
|
'Probably the biggest part of your identity on a site.',
|
2015-09-14 20:51:23 +00:00
|
|
|
'<b>You can only change this once every 30 days so choose wisely.</b>',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::CHANGE_USERNAME),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'usertitle' => [
|
2015-09-16 20:34:36 +00:00
|
|
|
'title' => 'Usertitle',
|
2015-08-23 22:08:36 +00:00
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'That little piece of text displayed under your username on your profile.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::CHANGE_USERTITLE),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'password' => [
|
|
|
|
'title' => 'Password',
|
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'Used to authenticate with the site and certain related services.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::CHANGE_PASSWORD),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'ranks' => [
|
|
|
|
'title' => 'Ranks',
|
|
|
|
'description' => [
|
2015-09-14 21:41:43 +00:00
|
|
|
'Manage what ranks you\'re in and what is set as your main rank.
|
|
|
|
Your main rank is highlighted.
|
|
|
|
You get the permissions of all of the ranks you\'re in combined.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::ALTER_RANKS),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
|
|
|
],
|
|
|
|
],
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'advanced' => [
|
|
|
|
'title' => 'Advanced',
|
|
|
|
'modes' => [
|
|
|
|
'sessions' => [
|
|
|
|
'title' => 'Sessions',
|
|
|
|
'description' => [
|
2015-09-14 21:41:43 +00:00
|
|
|
'Session keys are a way of identifying yourself with the system without keeping
|
|
|
|
your password in memory.',
|
|
|
|
'If someone finds one of your session keys they could possibly compromise your account,
|
|
|
|
if you see any sessions here that shouldn\'t be here hit the Kill button to kill the
|
|
|
|
selected session.',
|
|
|
|
'If you get logged out after clicking one you\'ve most likely killed your current session,
|
|
|
|
to make it easier to avoid this from happening your current session is highlighted.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::MANAGE_SESSIONS),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
|
|
|
'deactivate' => [
|
|
|
|
'title' => 'Deactivate Account',
|
|
|
|
'description' => [
|
2015-09-14 20:51:23 +00:00
|
|
|
'You can deactivate your account here if you want to leave :(.',
|
2015-08-23 22:08:36 +00:00
|
|
|
],
|
2015-12-29 21:52:19 +00:00
|
|
|
'access' => $currentUser->permission(Site::DEACTIVATE_ACCOUNT),
|
2015-09-14 20:51:23 +00:00
|
|
|
'menu' => true,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2015-06-20 19:25:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Current settings page
|
2015-09-14 21:41:43 +00:00
|
|
|
$category = isset($_GET['cat']) ? (
|
|
|
|
array_key_exists($_GET['cat'], $pages) ? $_GET['cat'] : false
|
|
|
|
) : array_keys($pages)[0];
|
2015-09-14 20:51:23 +00:00
|
|
|
$mode = false;
|
2015-09-03 19:44:14 +00:00
|
|
|
|
|
|
|
// Only continue setting mode if $category is true
|
2015-09-14 20:51:23 +00:00
|
|
|
if ($category) {
|
2015-09-14 21:41:43 +00:00
|
|
|
$mode = isset($_GET['mode']) && $category ? (
|
|
|
|
array_key_exists($_GET['mode'], $pages[$category]['modes']) ? $_GET['mode'] : false
|
|
|
|
) : array_keys($pages[$category]['modes'])[0];
|
2015-09-03 19:44:14 +00:00
|
|
|
}
|
2015-08-23 22:08:36 +00:00
|
|
|
|
|
|
|
// Not found
|
2015-09-14 21:41:43 +00:00
|
|
|
if (!$category
|
|
|
|
|| empty($category)
|
|
|
|
|| !$mode
|
|
|
|
|| empty($mode)
|
|
|
|
|| !$pages[$category]['modes'][$mode]['access']) {
|
2015-08-23 22:08:36 +00:00
|
|
|
header('HTTP/1.0 404 Not Found');
|
2015-11-06 22:30:37 +00:00
|
|
|
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2015-11-06 22:30:37 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/notfound');
|
2015-08-23 22:08:36 +00:00
|
|
|
exit;
|
|
|
|
}
|
2015-06-20 19:25:41 +00:00
|
|
|
|
2015-12-12 17:57:34 +00:00
|
|
|
// Set templates directory
|
|
|
|
$renderData['templates'] = 'settings';
|
|
|
|
|
2015-06-20 19:25:41 +00:00
|
|
|
// Render data
|
2015-09-14 20:51:23 +00:00
|
|
|
$renderData['current'] = $category . '.' . $mode;
|
2015-08-23 22:08:36 +00:00
|
|
|
|
|
|
|
// Settings pages
|
|
|
|
$renderData['pages'] = $pages;
|
|
|
|
|
|
|
|
// Page data
|
2015-06-20 19:25:41 +00:00
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'category' => $pages[$category]['title'],
|
|
|
|
'mode' => $pages[$category]['modes'][$mode]['title'],
|
|
|
|
'description' => $pages[$category]['modes'][$mode]['description'],
|
2015-06-20 19:25:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Section specific
|
2015-09-14 20:51:23 +00:00
|
|
|
switch ($category . '.' . $mode) {
|
2015-06-27 11:03:11 +00:00
|
|
|
// Profile
|
2015-08-23 22:08:36 +00:00
|
|
|
case 'general.profile':
|
2015-06-27 11:03:11 +00:00
|
|
|
$renderData['profile'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'fields' => Users::getProfileFields(),
|
|
|
|
'months' => [
|
|
|
|
1 => 'January',
|
|
|
|
2 => 'February',
|
|
|
|
3 => 'March',
|
|
|
|
4 => 'April',
|
|
|
|
5 => 'May',
|
|
|
|
6 => 'June',
|
|
|
|
7 => 'July',
|
|
|
|
8 => 'August',
|
|
|
|
9 => 'September',
|
|
|
|
10 => 'October',
|
|
|
|
11 => 'November',
|
|
|
|
12 => 'December',
|
|
|
|
],
|
2015-08-21 22:07:45 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Options
|
2015-08-23 22:08:36 +00:00
|
|
|
case 'general.options':
|
2015-08-21 22:07:45 +00:00
|
|
|
$renderData['options'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'fields' => Users::getOptionFields(),
|
2015-06-27 11:03:11 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2015-08-23 22:08:36 +00:00
|
|
|
// PM inbox
|
|
|
|
case 'messages.inbox':
|
2015-11-10 20:03:29 +00:00
|
|
|
$renderData['messages'] = [];
|
2015-08-23 22:08:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Avatar and background sizes
|
|
|
|
case 'appearance.avatar':
|
|
|
|
case 'appearance.background':
|
2016-01-17 01:58:31 +00:00
|
|
|
case 'appearance.header':
|
2015-08-23 22:08:36 +00:00
|
|
|
$renderData[$mode] = [
|
2015-12-04 14:19:10 +00:00
|
|
|
'max_width' => Config::get($mode . '_max_width'),
|
|
|
|
'max_height' => Config::get($mode . '_max_height'),
|
|
|
|
'min_width' => Config::get($mode . '_min_width'),
|
|
|
|
'min_height' => Config::get($mode . '_min_height'),
|
|
|
|
'max_size' => Config::get($mode . '_max_fsize'),
|
2016-01-17 01:58:31 +00:00
|
|
|
'max_size_view' => Utils::getByteSymbol(Config::get($mode . '_max_fsize')),
|
2015-08-23 22:08:36 +00:00
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2016-01-14 20:43:33 +00:00
|
|
|
// Sessions
|
|
|
|
case 'advanced.sessions':
|
2016-03-13 20:35:51 +00:00
|
|
|
$sessions = DB::table('sessions')
|
|
|
|
->where('user_id', $currentUser->id)
|
|
|
|
->get();
|
2016-02-18 23:28:44 +00:00
|
|
|
|
2016-03-13 20:35:51 +00:00
|
|
|
$renderData['sessions'] = $sessions;
|
2016-01-14 20:43:33 +00:00
|
|
|
break;
|
2015-06-20 19:25:41 +00:00
|
|
|
}
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2015-11-06 22:30:37 +00:00
|
|
|
|
2015-06-20 19:25:41 +00:00
|
|
|
// Print page contents
|
2016-03-28 14:47:43 +00:00
|
|
|
echo Template::render('meta/settings');
|
2015-06-20 19:25:41 +00:00
|
|
|
} else {
|
2015-09-07 20:53:47 +00:00
|
|
|
// If not allowed print the restricted page
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2015-11-06 22:30:37 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/restricted');
|
2015-06-20 19:25:41 +00:00
|
|
|
}
|