postWidgetText/src/Backend.php

97 lines
4.0 KiB
PHP
Raw Normal View History

2021-09-10 19:06:49 +00:00
<?php
2021-09-10 19:18:51 +00:00
/**
* @brief postWidgetText, a plugin for Dotclear 2
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @author Jean-Christian Denis and Contributors
2021-11-06 15:11:19 +00:00
*
2021-09-10 19:18:51 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2023-04-24 18:28:05 +00:00
declare(strict_types=1);
2021-09-10 19:06:49 +00:00
2023-04-24 18:28:05 +00:00
namespace Dotclear\Plugin\postWidgetText;
2021-09-10 19:06:49 +00:00
2023-04-24 18:28:05 +00:00
use dcAdmin;
use dcCore;
use dcPage;
use dcNsProcess;
2021-09-10 19:06:49 +00:00
2023-04-24 18:28:05 +00:00
class Backend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& My::phpCompliant()
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
return static::$init;
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
// nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false;
}
// backend sidebar menu icon
if (dcCore::app()->blog->settings->get(My::id())->get('active')) {
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
dcPage::getPF(My::id() . '/icon.svg'),
preg_match('/' . preg_quote((string) dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)
);
// backend user dashboard favorites icon
dcCore::app()->addBehavior('adminDashboardFavoritesV2', [BackendBehaviors::class, 'adminDashboardFavoritesV2']);
}
// backend pwt management
dcCore::app()->addBehaviors([
// user pref
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
// post
'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'],
'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'],
'adminAfterPostCreate' => [BackendBehaviors::class, 'adminAfterPostSave'],
'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
// Plugin "pages"
'adminPageHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
'adminPageFormItems' => [BackendBehaviors::class, 'adminPostFormItems'],
'adminAfterPageUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'],
'adminAfterPageCreate' => [BackendBehaviors::class, 'adminAfterPostSave'],
'adminBeforePageDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
// widgets registration
'initWidgets' => [Widgets::class, 'initWidgets'],
]);
// add plugin "importExport" features
if (!is_null(dcCore::app()->blog) && dcCore::app()->blog->settings->get(My::id())->get('importexport_active')) {
dcCore::app()->addBehaviors([
'exportFullV2' => [ImportExport::class, 'exportFullV2'],
'exportSingleV2' => [ImportExport::class, 'exportSingleV2'],
'importInitV2' => [ImportExport::class, 'importInitV2'],
'importSingleV2' => [ImportExport::class, 'importSingleV2'],
'importFullV2' => [ImportExport::class, 'importFullV2'],
]);
}
return true;
}
2021-11-06 15:11:19 +00:00
}