76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* @brief dcAdvancedCleaner, 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
|
|
*/
|
|
|
|
if (!defined('DC_ADMIN_CONTEXT')) {
|
|
return null;
|
|
}
|
|
|
|
class dcAdvancedCleaner
|
|
{
|
|
protected $core;
|
|
protected $cleaners = [];
|
|
|
|
public function __construct($core)
|
|
{
|
|
$this->core = $core;
|
|
$cleaners = new arrayObject();
|
|
|
|
try {
|
|
$this->core->callBehavior('advancedCleanerAdd', $cleaners, $this->core);
|
|
|
|
foreach($cleaners as $cleaner) {
|
|
if ($cleaner instanceOf advancedCleaner && !isset($this->cleaners[$cleaner->id])) {
|
|
$this->cleaners[$cleaner->id] = $cleaner;
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
$core->error->add($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function get($type = null, $silent = false)
|
|
{
|
|
if (null === $type) {
|
|
return $this->cleaners;
|
|
}
|
|
if (isset($this->cleaners[$type])) {
|
|
return $this->cleaners[$type];
|
|
}
|
|
if ($silent) {
|
|
return false;
|
|
}
|
|
throw new exception(sprintf(__('unknow cleaner type %s'), $type));
|
|
}
|
|
|
|
public function set($type, $action, $ns)
|
|
{
|
|
if (!isset($this->cleaners[$type])) {
|
|
throw new exception(sprintf(__('unknow cleaner type %s'), $type));
|
|
}
|
|
if (strtolower($ns) == 'dcadvancedcleaner') {
|
|
throw new exception(__("dcAdvancedCleaner can't remove itself"));
|
|
}
|
|
|
|
# BEHAVIOR dcAdvancedCleanerBeforeAction
|
|
$this->core->callBehavior('dcAdvancedCleanerBeforeAction', $type, $action, $ns);
|
|
|
|
$ret = $this->cleaners[$type]->set($action, $ns);
|
|
|
|
if ($ret === false) {
|
|
$msg = $this->cleaners[$type]->error($action);
|
|
throw new Exception($msg ?? __('Unknow error'));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |