2023-04-16 00:48:32 +00:00
|
|
|
<?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
|
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\dcAdvancedCleaner;
|
|
|
|
|
|
|
|
use Dotclear\Plugin\Uninstaller\{
|
2023-05-01 13:49:22 +00:00
|
|
|
CleanerParent,
|
|
|
|
CleanersStack,
|
2023-04-16 00:48:32 +00:00
|
|
|
Uninstaller
|
|
|
|
};
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
class ManageVars
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ManageVars self instance
|
|
|
|
*/
|
|
|
|
private static $container;
|
|
|
|
|
2023-05-01 13:49:22 +00:00
|
|
|
public readonly CleanersStack $cleaners;
|
|
|
|
public readonly ?CleanerParent $cleaner;
|
2023-04-24 11:37:49 +00:00
|
|
|
public readonly string $related;
|
2023-04-16 00:48:32 +00:00
|
|
|
public readonly array $entries;
|
|
|
|
public readonly string $action;
|
|
|
|
public readonly array $combo;
|
|
|
|
|
|
|
|
protected function __construct()
|
|
|
|
{
|
|
|
|
$this->cleaners = Uninstaller::instance()->cleaners;
|
|
|
|
|
2023-04-24 11:37:49 +00:00
|
|
|
$related = $_REQUEST['related'] ?? '';
|
2023-04-16 00:48:32 +00:00
|
|
|
$entries = $_REQUEST['entries'] ?? [];
|
|
|
|
$action = $_POST['action'] ?? '';
|
|
|
|
|
|
|
|
$cleaner = null;
|
|
|
|
$combo = [];
|
2023-05-01 13:49:22 +00:00
|
|
|
foreach ($this->cleaners as $k) {
|
2023-04-16 00:48:32 +00:00
|
|
|
$combo[$k->name] = $k->id;
|
2023-04-25 08:17:37 +00:00
|
|
|
if ($k->id == ($_REQUEST['part'] ?? '/')) {
|
2023-04-16 00:48:32 +00:00
|
|
|
$cleaner = $k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($cleaner === null) {
|
2023-04-24 11:37:49 +00:00
|
|
|
$related = '';
|
2023-04-16 00:48:32 +00:00
|
|
|
if (!($cleaner = $this->cleaners->get('caches'))) {
|
|
|
|
throw new Exception(__('Failed to load cleaner'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->cleaner = $cleaner;
|
2023-04-24 11:37:49 +00:00
|
|
|
$this->related = $related;
|
2023-04-16 00:48:32 +00:00
|
|
|
$this->entries = is_array($entries) ? $entries : [];
|
|
|
|
$this->action = is_string($action) ? $action : '';
|
|
|
|
$this->combo = $combo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function init(): ManageVars
|
|
|
|
{
|
|
|
|
if (!(self::$container instanceof self)) {
|
|
|
|
self::$container = new self();
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$container;
|
|
|
|
}
|
|
|
|
}
|