postslistOptions/src/Backend.php

73 lines
2.1 KiB
PHP
Raw Normal View History

2023-03-21 21:13:14 +00:00
<?php
/**
* @brief postslistOptions, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\postslistOptions;
use ArrayObject;
use dcCore;
2023-08-13 16:30:22 +00:00
use Dotclear\Core\Backend\Action\ActionsPosts;
use Dotclear\Core\Process;
2023-03-21 21:13:14 +00:00
/**
* Improve admin class
*
* Add menu and dashboard icons, load Improve action modules.
*/
2023-08-13 16:30:22 +00:00
class Backend extends Process
2023-03-21 21:13:14 +00:00
{
public static function init(): bool
{
2023-08-13 16:30:22 +00:00
return self::status(My::checkContext(My::BACKEND));
2023-03-21 21:13:14 +00:00
}
public static function process(): bool
{
2023-08-13 16:30:22 +00:00
if (!self::status()) {
2023-03-21 21:13:14 +00:00
return false;
}
2023-08-13 16:30:22 +00:00
dcCore::app()->addBehavior('adminPostsActions', function (ActionsPosts $pa) {
2023-03-21 21:13:14 +00:00
$pa->addAction(
[
__('Comments') => [
__('Mark as opened') => 'commentsopen',
__('Mark as closed') => 'commentsclose',
__('Delete all comments') => 'commentsdelete',
],
__('Trackbacks') => [
__('Mark as opened') => 'trackbacksopen',
__('Mark as closed') => 'trackbacksclose',
__('Delete all trackbacks') => 'trackbacksdelete',
],
],
2023-08-13 16:30:22 +00:00
function (ActionsPosts $pa, ArrayObject $post) {
2023-03-21 21:13:14 +00:00
$actions = [
'commentsopen',
'commentsclose',
'commentsdelete',
'trackbacksopen',
'trackbacksclose',
'trackbacksdelete',
];
if (in_array($pa->getAction(), $actions)) {
BackendBehaviors::{$pa->getAction()}($pa, $post);
}
}
);
});
return true;
}
}