enhancePostContent/src/Backend.php

143 lines
6.0 KiB
PHP
Raw Normal View History

2021-08-23 23:55:52 +00:00
<?php
2021-09-02 18:35:25 +00:00
/**
* @brief enhancePostContent, a plugin for Dotclear 2
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @author Jean-Christian Denis and Contributors
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2023-04-09 08:17:36 +00:00
declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent;
2021-08-23 23:55:52 +00:00
2023-04-09 08:17:36 +00:00
use ArrayObject;
use dcAdmin;
use dcCore;
use dcPage;
use dcFavorites;
use dcNsProcess;
use dcSettings;
2023-04-09 09:36:32 +00:00
use Dotclear\Helper\Html\Form\{
Checkbox,
Input,
Label,
Para
};
2021-08-23 23:55:52 +00:00
2023-04-09 08:17:36 +00:00
class Backend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& My::phpCompliant()
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
2021-08-23 23:55:52 +00:00
2023-04-09 08:17:36 +00:00
return static::$init;
}
2022-11-25 22:27:50 +00:00
2023-04-09 08:17:36 +00:00
public static function process(): bool
{
if (!static::$init) {
return false;
}
2022-11-25 22:27:50 +00:00
2023-04-09 08:17:36 +00:00
# Admin menu
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(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)
);
2021-08-23 23:55:52 +00:00
2023-04-09 08:17:36 +00:00
dcCore::app()->addBehaviors([
# Dashboard favorites
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
$favs->register(My::id(), [
'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'),
'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]),
]);
},
# Preference form
'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings):void {
$active = (bool) $blog_settings->get(My::id())->get('active');
$allowedtplvalues = Epc::blogAllowedTplValues();
$allowedpubpages = Epc::blogAllowedPubPages();
2021-08-23 23:55:52 +00:00
2023-04-09 08:17:36 +00:00
echo
'<div class="fieldset"><h4 id="epc_params">' . My::name() . '</h4>' .
'<div class="two-cols">' .
'<div class="col">' .
2023-04-09 09:36:32 +00:00
// active
(new Para())->items([
(new Checkbox('epc_active', $active))->value(1),
(new Label(__('Enable plugin'), Label::OUTSIDE_LABEL_AFTER))->for('epc_active')->class('classic'),
])->render() .
2023-04-09 08:17:36 +00:00
'<p class="form-note">' .
__('This enable public widgets and contents filter.') .
'</p>' .
'<p><a href="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '">' .
__('Set content filters') . '</a></p>' .
'</div>' .
'<div class="col">' .
'<h5>' . __('Extra') . '</h5>' .
'<p>' . __('This is a special feature to edit list of allowed template values and public pages where this plugin works.') . '</p>' .
2023-04-09 09:36:32 +00:00
// allowedtplvalues
(new Para())->items([
(new Label(__('Allowed DC template values:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedtplvalues'),
(new Input('epc_allowedtplvalues'))->size(100)->maxlenght(0)->value(Epc::implode($allowedtplvalues)),
])->render() .
2023-04-09 08:17:36 +00:00
'<p class="form-note">' . __('Use "readable_name1:template_value1;readable_name2:template_value2;" like "entry content:EntryContent;entry excerpt:EntryExcerpt;".') . '</p>' .
2023-04-09 09:36:32 +00:00
// allowedpubpages
(new Para())->items([
(new Label(__('Allowed public pages:'), Label::OUTSIDE_LABEL_BEFORE))->for('epc_allowedpubpages'),
(new Input('epc_allowedpubpages'))->size(100)->maxlenght(0)->value(Epc::implode($allowedpubpages)),
])->render() .
2023-04-09 08:17:36 +00:00
'<p class="form-note">' . __('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".') . '</p>' .
'</div>' .
'</div>' .
'<br class="clear" />' .
'</div>';
},
# Save preference
'adminBeforeBlogSettingsUpdate' => function (dcSettings $blog_settings): void {
$active = !empty($_POST['epc_active']);
$allowedtplvalues = Epc::explode($_POST['epc_allowedtplvalues']);
$allowedpubpages = Epc::explode($_POST['epc_allowedpubpages']);
2023-04-09 08:17:36 +00:00
$blog_settings->get(My::id())->put('active', $active);
$blog_settings->get(My::id())->put('allowedtplvalues', json_encode($allowedtplvalues));
$blog_settings->get(My::id())->put('allowedpubpages', json_encode($allowedpubpages));
},
# List filter
'adminFiltersListsV2' => function (ArrayObject $sorts): void {
$sorts['epc'] = [
My::name(),
[
__('Date') => 'epc_upddt',
__('Key') => 'epc_key',
__('Value') => 'epc_value',
__('ID') => 'epc_id',
],
'epc_upddt',
'desc',
[__('records per page'), 20],
];
},
# Widgets
'initWidgets' => [Widgets::class, 'initWidgets'],
]);
return true;
}
}