improve/src/Backend.php

81 lines
2.3 KiB
PHP
Raw Normal View History

2021-09-01 23:35:23 +00:00
<?php
/**
* @brief improve, a plugin for Dotclear 2
*
2021-09-01 23:35:23 +00:00
* @package Dotclear
2021-09-06 21:36:50 +00:00
* @subpackage Plugin
*
2021-09-01 23:35:23 +00:00
* @author Jean-Christian Denis and contributors
*
2021-09-01 23:35:23 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
2022-12-21 14:41:27 +00:00
namespace Dotclear\Plugin\improve;
/* dotclear */
use dcAdmin;
use dcCore;
use dcPage;
use dcFavorites;
2023-01-20 20:54:14 +00:00
use dcNsProcess;
/* clearbricks */
use Clearbricks;
use files;
/**
* Improve admin class
*
* Add menu and dashboard icons, load Improve action modules.
*/
2023-01-21 16:04:14 +00:00
class Backend extends dcNsProcess
2021-09-01 23:35:23 +00:00
{
2022-12-21 14:41:27 +00:00
public static function init(): bool
{
2022-12-21 14:41:27 +00:00
if (defined('DC_CONTEXT_ADMIN')) {
self::$init = true;
}
return self::$init;
}
2023-01-20 20:54:14 +00:00
public static function process(): bool
{
2022-12-21 14:41:27 +00:00
if (!self::$init) {
return false;
}
2022-12-01 09:51:56 +00:00
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
$favs->register(
'improve',
[
2022-12-01 10:09:24 +00:00
'title' => __('improve'),
2022-12-21 14:41:27 +00:00
'url' => dcCore::app()->adminurl->get('admin.plugin.' . Core::id()),
'small-icon' => dcPage::getPF(Core::id() . '/icon.svg'),
'large-icon' => dcPage::getPF(Core::id() . '/icon.svg'),
2022-12-01 09:51:56 +00:00
//'permissions' => null,
]
);
});
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('improve'),
2022-12-21 14:41:27 +00:00
dcCore::app()->adminurl->get('admin.plugin.' . Core::id()),
dcPage::getPF(Core::id() . '/icon.svg'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . Core::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin()
);
2023-01-20 20:54:14 +00:00
foreach (files::scandir(Utils::getActionsDir()) as $file) {
if (is_file(Utils::getActionsDir() . $file) && '.php' == substr($file, -4)) {
Clearbricks::lib()->autoload([Utils::getActionsNS() . substr($file, 0, -4) => Utils::getActionsDir() . $file]);
dcCore::app()->addBehavior('improveAddAction', [Utils::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */
}
}
2023-01-20 20:54:14 +00:00
return true;
}
}