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);
|
|
|
|
|
2022-12-21 14:41:27 +00:00
|
|
|
namespace Dotclear\Plugin\improve;
|
2021-11-13 21:57:51 +00:00
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
use dcAdmin;
|
2021-11-13 21:57:51 +00:00
|
|
|
use dcCore;
|
|
|
|
use dcPage;
|
|
|
|
use dcFavorites;
|
2023-01-20 20:54:14 +00:00
|
|
|
use dcNsProcess;
|
2023-04-06 20:11:28 +00:00
|
|
|
use Dotclear\Helper\File\Files;
|
2021-11-13 21:57:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2023-03-19 23:33:44 +00:00
|
|
|
static::$init = defined('DC_CONTEXT_ADMIN')
|
|
|
|
&& dcCore::app()->auth->isSuperAdmin()
|
|
|
|
&& My::phpCompliant();
|
2022-12-21 14:41:27 +00:00
|
|
|
|
2023-03-19 23:33:44 +00:00
|
|
|
return static::$init;
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
|
2023-01-20 20:54:14 +00:00
|
|
|
public static function process(): bool
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
2023-03-19 23:33:44 +00:00
|
|
|
if (!static::$init) {
|
2022-12-21 14:41:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-01 09:51:56 +00:00
|
|
|
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
|
|
|
|
$favs->register(
|
2023-03-18 22:04:27 +00:00
|
|
|
My::id(),
|
2022-12-01 09:51:56 +00:00
|
|
|
[
|
2023-03-18 22:04:27 +00:00
|
|
|
'title' => My::name(),
|
|
|
|
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
|
|
|
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
|
|
|
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
2022-12-01 09:51:56 +00:00
|
|
|
//'permissions' => null,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
});
|
2021-11-13 21:57:51 +00:00
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
2023-03-18 22:04:27 +00:00
|
|
|
My::name(),
|
|
|
|
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
|
|
|
dcPage::getPF(My::id() . '/icon.svg'),
|
|
|
|
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->auth->isSuperAdmin()
|
2021-11-13 21:57:51 +00:00
|
|
|
);
|
|
|
|
|
2023-04-06 20:44:35 +00:00
|
|
|
$dir = __DIR__ . DIRECTORY_SEPARATOR . 'module' . DIRECTORY_SEPARATOR;
|
|
|
|
$ns = __NAMESPACE__ . '\\Module\\';
|
|
|
|
|
|
|
|
dcCore::app()->autoload->addNamespace($ns, $dir);
|
|
|
|
|
|
|
|
foreach (Files::scandir($dir) as $file) {
|
|
|
|
if (str_ends_with($file, '.php') && is_file($dir . $file)) {
|
|
|
|
dcCore::app()->addBehavior('improveAddAction', [$ns . basename($file, '.php'), 'create']); /* @phpstan-ignore-line */
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-20 20:54:14 +00:00
|
|
|
|
|
|
|
return true;
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
2021-11-01 21:08:56 +00:00
|
|
|
}
|