koblog/bl-kernel/boot/admin.php

109 lines
3.4 KiB
PHP
Raw Normal View History

2015-05-05 03:00:01 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
// Start the session
2020-11-01 11:55:34 +01:00
// If the session is not started the admin area is not available
Session::start();
if (Session::started()===false) {
exit('Bludit CMS. Session initialization failed.');
}
2020-11-01 11:55:34 +01:00
// The login object contains the authentication system and/or the current user logged
2018-09-11 23:37:45 +02:00
$login = new Login();
2020-11-01 11:55:34 +01:00
// Initialize plugins
include(PATH_RULES.'60.plugins.php');
// Parameters for the controller and view
// For example "title" keeps the HTML tag <title>
2015-05-05 03:00:01 +02:00
$layout = array(
'controller'=>null,
'view'=>null,
'template'=>'index.php',
'slug'=>null,
2020-05-22 23:55:22 +02:00
'plugin'=>false,
2015-07-07 00:22:03 +02:00
'parameters'=>null,
'title'=>'Bludit'
2015-05-05 03:00:01 +02:00
);
2020-11-01 11:55:34 +01:00
// Get from the URL the controller and view
$explodeSlug = $url->explodeSlug();
2017-09-15 21:26:06 +02:00
$layout['controller'] = $layout['view'] = $layout['slug'] = empty($explodeSlug[0])?'dashboard':$explodeSlug[0];
2015-05-05 03:00:01 +02:00
unset($explodeSlug[0]);
2020-11-01 11:55:34 +01:00
// Check if the user want to get access to an admin controller or view from a plugin
// To get access to a plugin controller or view the URL should be: http://localhost/admin/plugin/<PLUGIN NAME>
// $explodeSlug = [0=>'<PLUGIN NAME>']
2020-05-22 23:55:22 +02:00
if ($layout['controller'] === 'plugin' && !empty($explodeSlug)) {
// Lowercase plugins class name to search by case-insensitive
$pluginsLowerCases = array_change_key_case($pluginsInstalled);
$pluginName = Text::lowercase(array_shift($explodeSlug));
if (isset($pluginsLowerCases[$pluginName])) {
$layout['plugin'] = $pluginsLowerCases[$pluginName];
}
2020-05-22 23:55:22 +02:00
}
// Get the URL parameters
$layout['parameters'] = implode('/', $explodeSlug);
2018-05-08 00:15:40 +02:00
// --- AJAX ---
2017-07-13 22:39:04 +02:00
if ($layout['slug']==='ajax') {
if ($login->isLogged()) {
2016-09-26 04:30:06 +02:00
// Rules: Security check CSRF
include(PATH_RULES.'99.security.php');
2017-07-13 22:39:04 +02:00
// Load the ajax file
if (Sanitize::pathFile(PATH_AJAX.$layout['parameters'].'.php')) {
2015-08-18 04:02:19 +02:00
include(PATH_AJAX.$layout['parameters'].'.php');
}
2015-08-17 04:33:49 +02:00
}
2018-06-24 13:37:45 +02:00
header('HTTP/1.1 401 User not logged.');
2018-05-08 00:15:40 +02:00
exit(0);
2015-05-05 03:00:01 +02:00
}
2020-11-01 11:55:34 +01:00
// Boot rules
include(PATH_RULES.'69.pages.php');
include(PATH_RULES.'99.header.php');
include(PATH_RULES.'99.paginator.php');
include(PATH_RULES.'99.themes.php');
include(PATH_RULES.'99.security.php');
// Define layout login-form for:
// - User not logged
// - Page not found
// - Slug is login. http://localhost/admin/login
if ($url->notFound() || !$login->isLogged() || ($url->slug()==='login') ) {
$layout['controller'] = 'login';
$layout['view'] = 'login';
$layout['template'] = 'login.php';
// Generate the tokenCSRF for the user not logged, when the user log-in the token will change
$security->generateTokenCSRF();
}
2017-05-17 18:48:51 +02:00
2020-11-01 11:55:34 +01:00
// Define global variables
$ADMIN_CONTROLLER = $layout['controller'];
$ADMIN_VIEW = $layout['view'];
2015-08-08 02:39:10 +02:00
2020-11-01 11:55:34 +01:00
// Execute plugins before load the admin area
execPluginsByHook('beforeAdminLoad');
2015-05-05 03:00:01 +02:00
2020-11-01 11:55:34 +01:00
// Load init.php if the theme has one
if (Sanitize::pathFile(PATH_ADMIN_THEMES.$site->adminTheme().DS.'init.php')) {
2020-11-01 11:55:34 +01:00
include(PATH_ADMIN_THEMES.$site->adminTheme().DS.'init.php');
}
2015-05-05 03:00:01 +02:00
2020-11-01 11:55:34 +01:00
// Load controller
if (Sanitize::pathFile(PATH_ADMIN_CONTROLLERS.$layout['controller'].'.php')) {
2020-11-01 11:55:34 +01:00
include(PATH_ADMIN_CONTROLLERS.$layout['controller'].'.php');
} elseif ($layout['plugin'] && method_exists($layout['plugin'], 'adminController')) {
$layout['plugin']->adminController();
}
2015-08-08 02:39:10 +02:00
2020-11-01 11:55:34 +01:00
// Load view and theme
if (Sanitize::pathFile(PATH_ADMIN_THEMES.$site->adminTheme().DS.$layout['template'])) {
2020-11-01 11:55:34 +01:00
include(PATH_ADMIN_THEMES.$site->adminTheme().DS.$layout['template']);
2018-06-24 13:37:45 +02:00
}
2020-11-01 11:55:34 +01:00
// Execute plugins after the admin area is loaded
execPluginsByHook('afterAdminLoad');