mirror of
https://github.com/flextype/flextype.git
synced 2025-08-12 16:14:16 +02:00
Admin Panel - Slim Integration - next round of integration
This commit is contained in:
@@ -13,17 +13,18 @@ namespace Flextype;
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flextype\Component\I18n\I18n;
|
||||
use Flextype\Component\Http\Http;
|
||||
use Flextype\Component\Event\Event;
|
||||
use Flextype\Component\Registry\Registry;
|
||||
use Flextype\Component\Notification\Notification;
|
||||
use Flextype\Component\I18n\I18n;
|
||||
use function Flextype\Component\I18n\__;
|
||||
use Flextype\Component\Arr\Arr;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
//
|
||||
// If isAdminArea
|
||||
//
|
||||
if (Admin::isAdminArea()) {
|
||||
|
||||
$uri = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER));
|
||||
$uri = explode('/', $uri->getPath());
|
||||
|
||||
if (isset($uri) && isset($uri[0]) && $uri[0] == 'admin') {
|
||||
|
||||
// Ensure vendor libraries exist
|
||||
!is_file($autoload = __DIR__ . '/vendor/autoload.php') and exit("Please run: <i>composer install</i>");
|
||||
@@ -31,147 +32,40 @@ if (Admin::isAdminArea()) {
|
||||
// Register The Auto Loader
|
||||
$loader = require_once $autoload;
|
||||
|
||||
//
|
||||
// Add listner for onCurrentPageBeforeLoaded event
|
||||
//
|
||||
Event::addListener('onCurrentEntryBeforeProcessed', function() {
|
||||
|
||||
// Add navigation links
|
||||
NavigationManager::addItem('content', 'entries', '<i class="far fa-newspaper"></i>' . __('admin_entries', Registry::get('settings.locale')), Http::getBaseUrl() . '/admin/entries', ['class' => 'nav-link']);
|
||||
NavigationManager::addItem('extends', 'fieldsets', '<i class="fas fa-list"></i>' . __('admin_fieldsets', Registry::get('settings.locale')), Http::getBaseUrl() . '/admin/fieldsets', ['class' => 'nav-link']);
|
||||
NavigationManager::addItem('extends', 'templates', '<i class="fas fa-layer-group"></i>' . __('admin_templates', Registry::get('settings.locale')), Http::getBaseUrl() . '/admin/templates', ['class' => 'nav-link']);
|
||||
NavigationManager::addItem('extends', 'snippets', '<i class="far fa-file-code"></i>' . __('admin_snippets', Registry::get('settings.locale')), Http::getBaseUrl() . '/admin/snippets', ['class' => 'nav-link']);
|
||||
NavigationManager::addItem('extends', 'plugins', '<i class="fas fa-plug"></i>' . __('admin_plugins', Registry::get('settings.locale')), Http::getBaseUrl() . '/admin/plugins', ['class' => 'nav-link']);
|
||||
NavigationManager::addItem('settings', 'settings', '<i class="fas fa-cog"></i>' . __('admin_settings', Registry::get('settings.locale')), Http::getBaseUrl() . '/admin/settings', ['class' => 'nav-link']);
|
||||
NavigationManager::addItem('settings', 'infomation', '<i class="fas fa-info"></i>' . __('admin_information', Registry::get('settings.locale')), Http::getBaseUrl() . '/admin/information', ['class' => 'nav-link']);
|
||||
// Set Default Admin locale
|
||||
I18n::$locale = $flextype->registry->get('settings.locale');
|
||||
|
||||
if (Registry::get('settings.locale') == 'ru') {
|
||||
NavigationManager::addItem('help', 'documentation', '<i class="far fa-question-circle"></i>' . __('admin_getting_help', Registry::get('settings.locale')), 'http://flextype.org/ru/documentation/guide/basics/getting-help', ['class' => 'nav-link', 'target' => '_blank']);
|
||||
include_once 'classes/UsersManager.php';
|
||||
include_once 'classes/PluginsManager.php';
|
||||
|
||||
addItem('content', 'entries', '<i class="far fa-newspaper"></i>' . __('admin_entries'), '/admin/entries', ['class' => 'nav-link'], $flextype);
|
||||
addItem('extends', 'fieldsets', '<i class="fas fa-list"></i>' . __('admin_fieldsets'), '/admin/fieldsets', ['class' => 'nav-link'], $flextype);
|
||||
addItem('extends', 'templates', '<i class="fas fa-layer-group"></i>' . __('admin_templates'), '/admin/templates', ['class' => 'nav-link'], $flextype);
|
||||
addItem('extends', 'snippets', '<i class="far fa-file-code"></i>' . __('admin_snippets'), '/admin/snippets', ['class' => 'nav-link'], $flextype);
|
||||
addItem('extends', 'plugins', '<i class="fas fa-plug"></i>' . __('admin_plugins'), '/admin/plugins', ['class' => 'nav-link'], $flextype);
|
||||
addItem('settings', 'settings', '<i class="fas fa-cog"></i>' . __('admin_settings'), '/admin/settings', ['class' => 'nav-link'], $flextype);
|
||||
addItem('help', 'infomation', '<i class="fas fa-info"></i>' . __('admin_information'), '/admin/information', ['class' => 'nav-link'], $flextype);
|
||||
|
||||
|
||||
if (UsersManager::isLoggedIn()) {
|
||||
//$app->redirect('/', $app->getContainer()->get('router')->pathFor('root'));
|
||||
} else {
|
||||
if (UsersManager::isUsersExists()) {
|
||||
//header('HTTP/1.1 301 Moved Permanently');
|
||||
//header('Location: '.$app->getContainer()->get('request')->getUri());
|
||||
//$app->redirect($app->getContainer()->get('request')->getUri(), $app->getContainer()->get('router')->pathFor('login'));
|
||||
} else {
|
||||
NavigationManager::addItem('help', 'documentation', '<i class="far fa-question-circle"></i>' . __('admin_getting_help', Registry::get('settings.locale')), 'http://flextype.org/en/documentation/guide/basics/getting-help', ['class' => 'nav-link', 'target' => '_blank']);
|
||||
//$app->redirect('/', $app->getContainer()->get('router')->pathFor('redirect'));
|
||||
}
|
||||
|
||||
// Initializes the Notification service.
|
||||
Notification::init();
|
||||
|
||||
// Get Admin Instance
|
||||
Admin::getInstance();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Admin
|
||||
function addItem(string $area, string $item, string $title, string $link, array $attributes = [], $flextype) : void
|
||||
{
|
||||
/**
|
||||
* An instance of the Admin class
|
||||
*
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Private clone method to enforce singleton behavior.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Private wakeup method to enforce singleton behavior.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function __wakeup()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Private construct method to enforce singleton behavior.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
Admin::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init Flextype Admin
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private static function init() : void
|
||||
{
|
||||
// Set Default Admin locale
|
||||
I18n::$locale = Registry::get('settings.locale');
|
||||
|
||||
if (UsersManager::isLoggedIn()) {
|
||||
Admin::getAdminArea();
|
||||
} else {
|
||||
if (UsersManager::isUsersExists()) {
|
||||
UsersManager::getAuthPage();
|
||||
} else {
|
||||
UsersManager::getRegistrationPage();
|
||||
}
|
||||
}
|
||||
|
||||
// Event: onBeforeRequestShutdown
|
||||
Event::dispatch('onBeforeRequestShutdown');
|
||||
|
||||
// Shutdown request
|
||||
Http::requestShutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flextype Admin Area
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private static function getAdminArea() : void
|
||||
{
|
||||
|
||||
// Event: onAdminArea
|
||||
Event::dispatch('onAdminArea');
|
||||
|
||||
// Route the Uri
|
||||
Http::getUriSegment(1) == '' and DashboardManager::getDashboardManager();
|
||||
Http::getUriSegment(1) == 'entries' and EntriesManager::getEntriesManager();
|
||||
Http::getUriSegment(1) == 'fieldsets' and FieldsetsManager::getFieldsetsManager();
|
||||
Http::getUriSegment(1) == 'templates' and TemplatesManager::getTemplatesManager();
|
||||
Http::getUriSegment(1) == 'snippets' and SnippetsManager::getSnippetsManager();
|
||||
Http::getUriSegment(1) == 'plugins' and PluginsManager::getPluginsManager();
|
||||
Http::getUriSegment(1) == 'information' and InformationManager::getInformationManager();
|
||||
Http::getUriSegment(1) == 'settings' and SettingsManager::getSettingsManager();
|
||||
Http::getUriSegment(1) == 'profile' and UsersManager::getProfileManager();
|
||||
Http::getUriSegment(1) == 'logout' and UsersManager::logout();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check is Admin Area
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public static function isAdminArea()
|
||||
{
|
||||
return (Http::getUriSegment(0) == 'admin') ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Admin instance.
|
||||
*
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(Admin::$instance)) {
|
||||
Admin::$instance = new self;
|
||||
}
|
||||
|
||||
return Admin::$instance;
|
||||
}
|
||||
$flextype->registry->set("admin_navigation.{$area}.{$item}.area", $area);
|
||||
$flextype->registry->set("admin_navigation.{$area}.{$item}.item", $item);
|
||||
$flextype->registry->set("admin_navigation.{$area}.{$item}.title", $title);
|
||||
$flextype->registry->set("admin_navigation.{$area}.{$item}.link", $link);
|
||||
$flextype->registry->set("admin_navigation.{$area}.{$item}.attributes", $attributes);
|
||||
}
|
||||
|
Reference in New Issue
Block a user