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/public/manage.php

314 lines
9.7 KiB
PHP
Raw Normal View History

2015-04-30 14:12:49 +00:00
<?php
/*
* Sakura Management
*/
// Declare Namespace
namespace Sakura;
2015-05-05 06:24:19 +00:00
2015-12-29 21:52:19 +00:00
use Sakura\Perms\Site;
use Sakura\Perms\Manage;
2015-04-30 23:01:01 +00:00
// Define that we are in Management mode
define('SAKURA_MANAGE', true);
2015-04-30 14:12:49 +00:00
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
2015-04-30 23:01:01 +00:00
2015-08-18 13:13:40 +00:00
// Make sure user has the permissions to view this
2015-12-29 21:52:19 +00:00
if (!$currentUser->permission(Manage::USE_MANAGE, Perms::MANAGE)) {
// Set parse variables
2016-02-04 20:56:40 +00:00
Template::vars($renderData);
// Print page contents
2016-02-04 20:56:40 +00:00
echo Template::render('global/restricted');
2015-08-18 13:13:40 +00:00
exit;
}
// Modes
$pages = [
'general' => [
'title' => 'General',
'modes' => [
'dashboard' => [
'title' => 'Dashboard',
'description' => [
'Welcome to the Broomcloset! Here\'s a quick overview of the site.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'info' => [
'title' => 'Info pages',
'description' => [
'Manage and edit the info pages.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
],
2015-05-03 16:25:57 +00:00
],
'config' => [
'title' => 'Configuration',
'modes' => [
'general' => [
'title' => 'General',
'description' => [
'Manages the appearance of the site and most other options that don\'t need their own category.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'uploads' => [
'title' => 'Uploads',
'description' => [
'Settings regarding uploads like avatars and backgrounds.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'premium' => [
'title' => 'Premium',
'description' => [
'Alters the way the premium system works.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'user' => [
'title' => 'User',
'description' => [
'Settings regarding users such as registration.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'mail' => [
'title' => 'Mail',
'description' => [
'How will Sakura send e-mails.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
],
],
'forums' => [
'title' => 'Forums',
'modes' => [
'manage' => [
'title' => 'Manage',
'description' => [
'Change the forums.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'settings' => [
'title' => 'Settings',
'description' => [
'Alter settings specific to the forum.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
],
2015-12-09 20:21:08 +00:00
],
'comments' => [
'title' => 'Comments',
'modes' => [
'manage' => [
'title' => 'Manage',
'description' => [
'View all the comment categories.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
],
],
'users' => [
'title' => 'Users',
'modes' => [
'manage-users' => [
'title' => 'Manage users',
'description' => [
'View and change users.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'manage-ranks' => [
'title' => 'Manage ranks',
'description' => [
'View and change ranks.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'profile-fields' => [
'title' => 'Profile fields',
'description' => [
'Manage the custom profile fields.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'option-fields' => [
'title' => 'Option fields',
'description' => [
'Manage the custom option fields.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'bans' => [
'title' => 'Bans',
'description' => [
'Banning users.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'warnings' => [
'title' => 'Warnings',
'description' => [
'Warn users.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
],
],
'permissions' => [
'title' => 'Permissions',
'modes' => [
'site' => [
'title' => 'Manage site',
'description' => [
'Alter the global site perms.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'management' => [
'title' => 'Manage management',
'description' => [
'Alter the management/moderation perms.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'forum' => [
'title' => 'Manage forums',
'description' => [
'Alter the perms of the forums.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
],
],
'logs' => [
'title' => 'Logs',
'modes' => [
'actions' => [
'title' => 'Actions',
'description' => [
'Viewing the global action logs.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'management' => [
'title' => 'Management',
'description' => [
'Viewing the management actions taken by staff.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
'errors' => [
'title' => 'Errors',
'description' => [
'Viewing the PHP error logs Sakura was able to log.',
],
2015-12-29 21:52:19 +00:00
'access' => !$currentUser->permission(Site::DEACTIVATED),
'menu' => true,
],
],
],
2015-04-30 23:01:01 +00:00
];
// Current settings page
$category = isset($_GET['cat']) ? (
array_key_exists($_GET['cat'], $pages) ? $_GET['cat'] : false
) : array_keys($pages)[0];
$mode = false;
// Only continue setting mode if $category is true
if ($category) {
$mode = isset($_GET['mode']) && $category ? (
array_key_exists($_GET['mode'], $pages[$category]['modes']) ? $_GET['mode'] : false
) : array_keys($pages[$category]['modes'])[0];
}
2015-04-30 23:01:01 +00:00
// Not found
if (!$category
|| empty($category)
|| !$mode
|| empty($mode)
|| !$pages[$category]['modes'][$mode]['access']) {
header('HTTP/1.0 404 Not Found');
// Set parse variables
2016-02-04 20:56:40 +00:00
Template::vars($renderData);
// Print page contents
2016-02-04 20:56:40 +00:00
echo Template::render('global/notfound');
exit;
}
// Set templates directory
$renderData['templates'] = 'manage';
// Render data
$renderData['current'] = $category . '.' . $mode;
// Settings pages
$renderData['pages'] = $pages;
// Page data
$renderData['page'] = [
'category' => $pages[$category]['title'],
'mode' => $pages[$category]['modes'][$mode]['title'],
'description' => $pages[$category]['modes'][$mode]['description'],
];
// Add special variables
switch ($category . '.' . $mode) {
case 'general.dashboard':
$renderData = array_merge($renderData, [
'stats' => [
'postcount' => Database::count('posts')[0],
'threadcount' => Database::count('topics')[0],
'commentcount' => Database::count('comments')[0],
'userscount' => Database::count('users')[0],
'bancount' => Database::count('bans')[0],
'uploadcount' => count(glob(ROOT . Config::get('user_uploads') . '/*')) - 1,
2015-12-27 04:37:57 +00:00
],
]);
break;
2015-12-09 20:21:08 +00:00
case 'logs.errors':
$errorLog = Database::fetch('error_log', true, null, ['error_id', true]);
$renderData = array_merge($renderData, ['errors' => $errorLog]);
break;
}
2015-04-30 14:12:49 +00:00
// Set parse variables
2016-02-04 20:56:40 +00:00
Template::vars($renderData);
2015-04-30 14:12:49 +00:00
// Print page contents
2016-02-04 20:56:40 +00:00
echo Template::render('main/settings');