2021-10-31 22:22:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief enhancePostContent, a plugin for Dotclear 2
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-10-31 22:22:34 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-10-31 22:22:34 +00:00
|
|
|
* @author Jean-Christian Denis and Contributors
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-10-31 22:22:34 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
|
|
|
abstract class epcFilter
|
|
|
|
{
|
2021-11-01 09:33:43 +00:00
|
|
|
private $id = 'undefined';
|
2021-10-31 22:22:34 +00:00
|
|
|
private $records = null;
|
|
|
|
|
|
|
|
private $properties = [
|
2021-10-31 22:50:38 +00:00
|
|
|
'priority' => 500,
|
2021-10-31 22:22:34 +00:00
|
|
|
'name' => 'undefined',
|
|
|
|
'help' => 'undefined',
|
|
|
|
'has_list' => false,
|
|
|
|
'htmltag' => '',
|
|
|
|
'class' => [],
|
|
|
|
'replace' => '',
|
2022-11-13 20:30:48 +00:00
|
|
|
'widget' => '',
|
2021-10-31 22:22:34 +00:00
|
|
|
];
|
|
|
|
private $settings = [
|
|
|
|
'nocase' => false,
|
|
|
|
'plural' => false,
|
|
|
|
'limit' => 0,
|
|
|
|
'style' => [],
|
|
|
|
'notag' => '',
|
|
|
|
'tplValues' => [],
|
2022-11-13 20:30:48 +00:00
|
|
|
'pubPages' => [],
|
2021-10-31 22:22:34 +00:00
|
|
|
];
|
|
|
|
|
2022-11-13 20:30:48 +00:00
|
|
|
final public function __construct()
|
2021-10-31 22:22:34 +00:00
|
|
|
{
|
2022-11-13 20:30:48 +00:00
|
|
|
$this->id = $this->init();
|
2021-10-31 22:22:34 +00:00
|
|
|
|
|
|
|
$this->blogSettings();
|
|
|
|
}
|
|
|
|
|
2022-11-13 20:30:48 +00:00
|
|
|
public static function create(arrayObject $o)
|
2021-10-31 22:22:34 +00:00
|
|
|
{
|
|
|
|
$c = get_called_class();
|
2022-11-13 20:30:48 +00:00
|
|
|
$o->append(new $c());
|
2021-10-31 22:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final public function id()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function __get($k)
|
|
|
|
{
|
|
|
|
if (isset($this->properties[$k])) {
|
|
|
|
return $this->properties[$k];
|
|
|
|
}
|
|
|
|
if (isset($this->settings[$k])) {
|
|
|
|
return $this->settings[$k];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function __set($k, $v)
|
|
|
|
{
|
|
|
|
if (isset($this->settings[$k])) {
|
|
|
|
$this->settings[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function property($k)
|
|
|
|
{
|
|
|
|
return $this->properties[$k] ?? null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function setProperties($property, $value = null): bool
|
|
|
|
{
|
|
|
|
$properties = is_array($property) ? $property : [$property => $value];
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($properties as $k => $v) {
|
2021-10-31 22:22:34 +00:00
|
|
|
if (isset($this->properties[$k])) {
|
|
|
|
$this->properties[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
2021-11-01 09:33:43 +00:00
|
|
|
|
2021-10-31 22:22:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function setting($k)
|
|
|
|
{
|
|
|
|
return $this->settings[$k] ?? null;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected function setSettings($setting, $value = null): bool
|
|
|
|
{
|
|
|
|
$settings = is_array($setting) ? $setting : [$setting => $value];
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($settings as $k => $v) {
|
2021-10-31 22:22:34 +00:00
|
|
|
if (isset($this->settings[$k])) {
|
|
|
|
$this->settings[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
2021-11-01 09:33:43 +00:00
|
|
|
|
2021-10-31 22:22:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function blogSettings()
|
|
|
|
{
|
2022-12-13 20:39:18 +00:00
|
|
|
$opt = json_decode((string) dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->__get($this->id));
|
2021-10-31 22:22:34 +00:00
|
|
|
|
|
|
|
if (!is_array($opt)) {
|
|
|
|
$opt = [];
|
|
|
|
}
|
|
|
|
if (isset($opt['nocase'])) {
|
2021-11-06 13:46:37 +00:00
|
|
|
$this->settings['nocase'] = (bool) $opt['nocase'];
|
2021-10-31 22:22:34 +00:00
|
|
|
}
|
|
|
|
if (isset($opt['plural'])) {
|
2021-11-06 13:46:37 +00:00
|
|
|
$this->settings['plural'] = (bool) $opt['plural'];
|
2021-10-31 22:22:34 +00:00
|
|
|
}
|
|
|
|
if (isset($opt['limit'])) {
|
2021-11-06 13:46:37 +00:00
|
|
|
$this->settings['limit'] = abs((int) $opt['limit']);
|
2021-10-31 22:22:34 +00:00
|
|
|
}
|
|
|
|
if (isset($opt['style']) && is_array($opt['style'])) {
|
|
|
|
$this->settings['style'] = (array) $opt['style'];
|
|
|
|
}
|
|
|
|
if (isset($opt['notag'])) {
|
|
|
|
$this->settings['notag'] = (string) $opt['notag'];
|
|
|
|
}
|
|
|
|
if (isset($opt['tplValues'])) {
|
|
|
|
$this->settings['tplValues'] = (array) $opt['tplValues'];
|
|
|
|
}
|
|
|
|
if (isset($opt['pubPages'])) {
|
|
|
|
$this->settings['pubPages'] = (array) $opt['pubPages'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function records()
|
|
|
|
{
|
|
|
|
if ($this->records === null && $this->has_list) {
|
2022-11-13 20:30:48 +00:00
|
|
|
$records = new epcRecords();
|
2021-10-31 22:22:34 +00:00
|
|
|
$this->records = $records->getRecords(['epc_filter' => $this->id()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->records;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected function init(): string;
|
|
|
|
|
|
|
|
public function publicContent($tag, $args)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function widgetList($content, $w, &$list)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-01 09:33:43 +00:00
|
|
|
}
|