2023-03-19 20:17:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief tweakStores, 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\tweakStores;
|
|
|
|
|
|
|
|
use dcCore;
|
2023-04-24 13:34:16 +00:00
|
|
|
use Exception;
|
2023-03-19 20:17:24 +00:00
|
|
|
|
|
|
|
class Settings
|
|
|
|
{
|
|
|
|
// Enable this plugin
|
|
|
|
public readonly bool $active;
|
|
|
|
|
|
|
|
// Enable plugin pacKman behavior
|
|
|
|
public readonly bool $packman;
|
|
|
|
|
|
|
|
// Predictable dcstore url
|
|
|
|
public readonly string $file_pattern;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor set up plugin settings
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2023-04-24 13:34:16 +00:00
|
|
|
if (is_null(dcCore::app()->blog)) {
|
|
|
|
throw new Exception('blog is not set');
|
|
|
|
}
|
|
|
|
|
2023-03-19 20:17:24 +00:00
|
|
|
$s = dcCore::app()->blog->settings->get(My::id());
|
|
|
|
|
|
|
|
$this->active = (bool) ($s->get('active') ?? false);
|
|
|
|
$this->packman = (bool) ($s->get('packman') ?? false);
|
|
|
|
$this->file_pattern = (string) ($s->get('file_pattern') ?? '');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSetting(string $key): mixed
|
|
|
|
{
|
|
|
|
return $this->{$key} ?? null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overwrite a plugin settings (in db)
|
|
|
|
*
|
|
|
|
* @param string $key The setting ID
|
|
|
|
* @param mixed $value The setting value
|
|
|
|
*
|
|
|
|
* @return bool True on success
|
|
|
|
*/
|
|
|
|
public function writeSetting(string $key, mixed $value): bool
|
|
|
|
{
|
2023-04-24 13:34:16 +00:00
|
|
|
if (is_null(dcCore::app()->blog)) {
|
|
|
|
throw new Exception('blog is not set');
|
|
|
|
}
|
|
|
|
|
2023-03-19 20:17:24 +00:00
|
|
|
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
|
|
|
|
dcCore::app()->blog->settings->get(My::id())->drop($key);
|
|
|
|
dcCore::app()->blog->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List defined settings keys
|
|
|
|
*
|
|
|
|
* @return array The settings keys
|
|
|
|
*/
|
|
|
|
public function listSettings(): array
|
|
|
|
{
|
2023-04-29 08:51:35 +00:00
|
|
|
return get_object_vars($this);
|
2023-03-19 20:17:24 +00:00
|
|
|
}
|
|
|
|
}
|