2021-09-01 23:35:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief improve, a plugin for Dotclear 2
|
2021-11-01 21:08:56 +00:00
|
|
|
*
|
2021-09-01 23:35:23 +00:00
|
|
|
* @package Dotclear
|
2021-09-06 21:36:50 +00:00
|
|
|
* @subpackage Plugin
|
2021-11-01 21:08:56 +00:00
|
|
|
*
|
2021-09-01 23:35:23 +00:00
|
|
|
* @author Jean-Christian Denis and contributors
|
2021-11-01 21:08:56 +00:00
|
|
|
*
|
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
|
|
|
|
*/
|
2021-11-13 21:57:51 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace plugins\improve;
|
|
|
|
|
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dotclear */
|
2022-11-12 21:58:44 +00:00
|
|
|
use dcAdmin;
|
2021-11-13 21:57:51 +00:00
|
|
|
use dcCore;
|
|
|
|
use dcPage;
|
|
|
|
use dcFavorites;
|
|
|
|
|
|
|
|
/* clearbricks */
|
2022-11-12 21:58:44 +00:00
|
|
|
use Clearbricks;
|
2021-11-13 21:57:51 +00:00
|
|
|
use files;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Improve admin class
|
|
|
|
*
|
|
|
|
* Add menu and dashboard icons, load Improve action modules.
|
|
|
|
*/
|
|
|
|
class admin
|
2021-09-01 23:35:23 +00:00
|
|
|
{
|
2022-11-12 21:58:44 +00:00
|
|
|
public static function process(): void
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2022-11-12 21:58:44 +00:00
|
|
|
self::addSettingsNamespace();
|
|
|
|
self::addAdminBehaviors();
|
|
|
|
self::addAdminMenu();
|
|
|
|
self::addImproveActions();
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function addSettingsNamespace(): void
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->blog->settings->addNamespace('improve');
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function addAdminBehaviors(): void
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2022-12-01 09:51:56 +00:00
|
|
|
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
|
|
|
|
$favs->register(
|
|
|
|
'improve',
|
|
|
|
[
|
|
|
|
'title' => __('improve'),
|
|
|
|
'url' => dcCore::app()->adminurl->get('admin.plugin.improve'),
|
|
|
|
'small-icon' => dcPage::getPF('improve/icon.svg'),
|
|
|
|
'large-icon' => dcPage::getPF('improve/icon.svg'),
|
|
|
|
//'permissions' => null,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
});
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function addAdminMenu(): void
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
2021-11-13 21:57:51 +00:00
|
|
|
__('improve'),
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->adminurl->get('admin.plugin.improve'),
|
2022-11-26 20:29:15 +00:00
|
|
|
dcPage::getPF('improve/icon.svg'),
|
2022-11-12 21:58:44 +00:00
|
|
|
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.improve')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
|
|
|
dcCore::app()->auth->isSuperAdmin()
|
2021-11-13 21:57:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
private static function addImproveActions(): void
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
|
|
|
foreach (files::scandir(prepend::getActionsDir()) as $file) {
|
|
|
|
if (is_file(prepend::getActionsDir() . $file) && '.php' == substr($file, -4)) {
|
2022-11-12 21:58:44 +00:00
|
|
|
Clearbricks::lib()->autoload([prepend::getActionsNS() . substr($file, 0, -4) => prepend::getActionsDir() . $file]);
|
|
|
|
dcCore::app()->addBehavior('improveAddAction', [prepend::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-01 21:08:56 +00:00
|
|
|
}
|
2021-11-13 21:57:51 +00:00
|
|
|
|
|
|
|
/* process */
|
2022-11-12 21:58:44 +00:00
|
|
|
admin::process();
|