level up phpstan (use php 8.1 readonly properties)

This commit is contained in:
Jean-Christian Denis 2023-04-09 23:52:07 +02:00
parent ffe9e86eae
commit 1f35a43a8c
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
22 changed files with 283 additions and 301 deletions

View file

@ -14,8 +14,8 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use adminGenericFilterV2;
use adminGenericListV2; use adminGenericListV2;
use dcCore;
use dcPager; use dcPager;
use Dotclear\Helper\Html\Form\Checkbox; use Dotclear\Helper\Html\Form\Checkbox;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
@ -29,12 +29,12 @@ use dt;
*/ */
class BackendList extends adminGenericListV2 class BackendList extends adminGenericListV2
{ {
public function display($filter, $pager_url, $enclose_block = '') public function display(adminGenericFilterV2 $filter, string $pager_url, string $enclose_block): void
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
echo '<p><strong>' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '</strong></p>'; echo '<p><strong>' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '</strong></p>';
} else { } else {
$pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10); $pager = new dcPager($filter->value('page'), $this->rs_count, $filter->value('nb'), 10);
$pager->base_url = $pager_url; $pager->base_url = $pager_url;
$epc_id = []; $epc_id = [];

View file

@ -33,8 +33,8 @@ __('RSS feeds');
class Epc class Epc
{ {
protected static $default_filters = null; protected static array $default_filters = [];
public static $epcFilterLimit = []; public static array $epcFilterLimit = [];
# #
# Default definition # Default definition
@ -48,6 +48,7 @@ class Epc
'comment content' => 'CommentContent', 'comment content' => 'CommentContent',
]); ]);
# --BEHAVIOR-- enhancePostContentAllowedTplValues : ArrayObject
dcCore::app()->callBehavior('enhancePostContentAllowedTplValues', $rs); dcCore::app()->callBehavior('enhancePostContentAllowedTplValues', $rs);
return iterator_to_array($rs, true); return iterator_to_array($rs, true);
@ -55,7 +56,7 @@ class Epc
public static function blogAllowedTplValues(): array public static function blogAllowedTplValues(): array
{ {
$rs = json_decode(dcCore::app()->blog->settings->get(basename(dirname('../' . __DIR__)))->get('allowedtplvalues')); $rs = json_decode(dcCore::app()->blog->settings->get(My::id())->get('allowedtplvalues'));
return is_array($rs) ? $rs : self::defaultAllowedTplValues(); return is_array($rs) ? $rs : self::defaultAllowedTplValues();
} }
@ -77,6 +78,7 @@ class Epc
], ],
]); ]);
# --BEHAVIOR-- enhancePostContentAllowedWidgetValues : ArrayObject
dcCore::app()->callBehavior('enhancePostContentAllowedWidgetValues', $rs); dcCore::app()->callBehavior('enhancePostContentAllowedWidgetValues', $rs);
return iterator_to_array($rs, true); return iterator_to_array($rs, true);
@ -93,6 +95,7 @@ class Epc
'RSS feeds' => 'rss2.xml', 'RSS feeds' => 'rss2.xml',
]); ]);
# --BEHAVIOR-- enhancePostContentAllowedPubPages : ArrayObject
dcCore::app()->callBehavior('enhancePostContentAllowedPubPages', $rs); dcCore::app()->callBehavior('enhancePostContentAllowedPubPages', $rs);
return iterator_to_array($rs, true); return iterator_to_array($rs, true);
@ -107,15 +110,17 @@ class Epc
public static function getFilters(): ?array public static function getFilters(): ?array
{ {
if (self::$default_filters === null) { if (empty(self::$default_filters)) {
$final = $sort = []; $final = $sort = [];
/** @var ArrayObject<string,EpcFilter> $filters The filters stack */
$filters = new ArrayObject(); $filters = new ArrayObject();
try { try {
# --BEHAVIOR-- enhancePostContentFilters : ArrayObject
dcCore::app()->callBehavior('enhancePostContentFilters', $filters); dcCore::app()->callBehavior('enhancePostContentFilters', $filters);
foreach ($filters as $filter) { foreach ($filters as $filter) {
if ($filter instanceof epcFilter && !isset($final[$filter->id()])) { if (!isset($final[$filter->id()]) && ($filter instanceof EpcFilter)) {
$sort[$filter->id()] = $filter->priority; $sort[$filter->id()] = $filter->priority;
$final[$filter->id()] = $filter; $final[$filter->id()] = $filter;
} }
@ -132,9 +137,7 @@ class Epc
public static function testContext(string $tag, array $args, EpcFilter $filter): bool public static function testContext(string $tag, array $args, EpcFilter $filter): bool
{ {
return is_array($filter->pubPages) return in_array(dcCore::app()->ctx->current_tpl, $filter->pubPages)
&& in_array(dcCore::app()->ctx->current_tpl, $filter->pubPages)
&& is_array($filter->tplValues)
&& in_array($tag, $filter->tplValues) && in_array($tag, $filter->tplValues)
&& $args[0] != '' //content && $args[0] != '' //content
&& empty($args['encode_xml']) && empty($args['encode_xml'])
@ -184,7 +187,7 @@ class Epc
return $s = preg_replace('#ççççç(.*?)ççççç#s', '$1', $s); return $s = preg_replace('#ççççç(.*?)ççççç#s', '$1', $s);
} }
public static function matchString(string $p, string $r, string $s, EcpFilter $filter, string $before = '\b', string $after = '\b'): array public static function matchString(string $p, string $r, string $s, EpcFilter $filter, string $before = '\b', string $after = '\b'): array
{ {
# Case sensitive # Case sensitive
$i = $filter->nocase ? 'i' : ''; $i = $filter->nocase ? 'i' : '';
@ -231,7 +234,7 @@ class Epc
return $a; return $a;
} }
if (!is_array($a)) { if (!is_array($a)) {
return []; return '';
} }
$r = ''; $r = '';
@ -248,7 +251,7 @@ class Epc
return $s; return $s;
} }
if (!is_string($s)) { if (!is_string($s)) {
return ''; return [];
} }
$r = []; $r = [];
@ -284,7 +287,7 @@ class Epc
public static function widgetContentEntryExcerpt(?WidgetsElement $w = null): string public static function widgetContentEntryExcerpt(?WidgetsElement $w = null): string
{ {
if (!dcCore::app()->ctx->exists('posts')) { if (!dcCore::app()->ctx->exists('posts')) {
return null; return '';
} }
$res = ''; $res = '';
@ -298,7 +301,7 @@ class Epc
public static function widgetContentEntryContent(): string public static function widgetContentEntryContent(): string
{ {
if (!dcCore::app()->ctx->exists('posts')) { if (!dcCore::app()->ctx->exists('posts')) {
return null; return '';
} }
$res = ''; $res = '';
@ -312,7 +315,7 @@ class Epc
public static function widgetContentCommentContent(): string public static function widgetContentCommentContent(): string
{ {
if (!dcCore::app()->ctx->exists('posts')) { if (!dcCore::app()->ctx->exists('posts')) {
return null; return '';
} }
$res = ''; $res = '';

View file

@ -18,133 +18,98 @@ use ArrayObject;
use dcCore; use dcCore;
use dcRecord; use dcRecord;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
use Exception;
abstract class EpcFilter abstract class EpcFilter
{ {
private $id = 'undefined'; protected string $id = 'undefined';
private $records = null;
private $properties = [ private ?dcRecord $records = null;
'priority' => 500,
'name' => 'undefined', // properties
'help' => 'undefined', public readonly int $priority;
'has_list' => false, public readonly string $name;
'htmltag' => '', public readonly string $help;
'class' => [], public readonly bool $has_list;
'replace' => '', public readonly string $htmltag;
'widget' => '', public readonly array $class;
]; public readonly string $replace;
private $settings = [ public readonly string $widget;
'nocase' => false,
'plural' => false, // settings
'limit' => 0, public readonly bool $nocase;
'style' => [], public readonly bool $plural;
'notag' => '', public readonly int $limit;
'tplValues' => [], public readonly array $style;
'pubPages' => [], public readonly string $notag;
]; public readonly array $tplValues;
public readonly array $pubPages;
final public function __construct() final public function __construct()
{ {
$this->id = $this->init(); if ($this->id == 'undefined') {
throw new Exception('Undefined Filter id');
}
$this->blogSettings(); // get blog settings
$s = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get($this->id), true);
if (empty($s)) {
$s = [];
}
$properties = $this->initProperties();
$settings = $this->initSettings();
// from filter defautl properties
$this->priority = isset($properties['priority']) ? abs((int) $properties['priority']) : 500;
$this->name = isset($properties['name']) ? (string) $properties['name'] : 'undefined';
$this->help = isset($properties['help']) ? (string) $properties['help'] : 'undefined';
$this->has_list = isset($properties['has_list']) ? (bool) $properties['has_list'] : false;
$this->htmltag = isset($properties['htmltag']) ? (string) $properties['htmltag'] : '';
$this->class = isset($properties['class']) && is_array($properties['class']) ? $properties['class'] : [];
$this->replace = isset($properties['replace']) ? (string) $properties['replace'] : '';
$this->widget = isset($properties['widget']) ? (string) $properties['widget'] : '';
// from filter defautl settings
$nocase = isset($settings['nocase']) ? (bool) $settings['nocase'] : false;
$plural = isset($settings['plural']) ? (bool) $settings['plural'] : false;
$limit = isset($settings['limit']) ? abs((int) $settings['limit']) : 0;
$style = isset($settings['style']) && is_array($settings['style']) ? $settings['style'] : [];
$notag = isset($settings['notag']) ? (string) $settings['notag'] : '';
$tplValues = isset($settings['tplValues']) && is_array($settings['tplValues']) ? $settings['tplValues'] : [];
$pubPages = isset($settings['pubPages']) && is_array($settings['pubPages']) ? $settings['pubPages'] : [];
// from blog settings
$this->nocase = isset($s['nocase']) ? (bool) $s['nocase'] : $nocase;
$this->plural = isset($s['plural']) ? (bool) $s['plural'] : $plural;
$this->limit = isset($s['limit']) ? abs((int) $s['limit']) : $limit;
$this->style = isset($s['style']) && is_array($s['style']) ? $s['style'] : $style;
$this->notag = isset($s['notag']) ? (string) $s['notag'] : $notag;
$this->tplValues = isset($s['tplValues']) && is_array($s['tplValues']) ? $s['tplValues'] : $tplValues;
$this->pubPages = isset($s['pubPages']) && is_array($s['pubPages']) ? $s['pubPages'] : $pubPages;
}
protected function initProperties(): array
{
return [];
}
protected function initSettings(): array
{
return [];
} }
public static function create(ArrayObject $o): void public static function create(ArrayObject $o): void
{ {
$c = get_called_class(); $c = static::class;
$o->append(new $c()); $o->append(new $c());
} }
final public function id() final public function id(): string
{ {
return $this->id; return $this->id;
} }
final public function __get(string $k): mixed
{
if (isset($this->properties[$k])) {
return $this->properties[$k];
}
if (isset($this->settings[$k])) {
return $this->settings[$k];
}
return null;
}
final public function __set(string $k, mixed $v): void
{
if (isset($this->settings[$k])) {
$this->settings[$k] = $v;
}
}
final public function property(string $k): mixed
{
return $this->properties[$k] ?? null;
}
final protected function setProperties(array|string $property, mixed $value = null): bool
{
$properties = is_array($property) ? $property : [$property => $value];
foreach ($properties as $k => $v) {
if (isset($this->properties[$k])) {
$this->properties[$k] = $v;
}
}
return true;
}
final public function setting(string $k): mixed
{
return $this->settings[$k] ?? null;
}
final protected function setSettings(array|string $setting, mixed $value = null): bool
{
$settings = is_array($setting) ? $setting : [$setting => $value];
foreach ($settings as $k => $v) {
if (isset($this->settings[$k])) {
$this->settings[$k] = $v;
}
}
return true;
}
private function blogSettings(): void
{
$opt = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get($this->id));
if (empty($opt)) {
$opt = [];
}
if (isset($opt->nocase)) {
$this->settings['nocase'] = (bool) $opt->nocase;
}
if (isset($opt->plural)) {
$this->settings['plural'] = (bool) $opt->plural;
}
if (isset($opt->limit)) {
$this->settings['limit'] = abs((int) $opt->limit);
}
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(): ?dcRecord final public function records(): ?dcRecord
{ {
if ($this->records === null && $this->has_list) { if ($this->records === null && $this->has_list) {
@ -154,15 +119,11 @@ abstract class EpcFilter
return $this->records; return $this->records;
} }
abstract protected function init(): string;
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
{ {
return;
} }
public function widgetList(string $content, WidgetsElement $w, array &$list): void public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
{ {
return;
} }
} }

View file

@ -17,6 +17,7 @@ namespace Dotclear\Plugin\enhancePostContent;
use cursor; use cursor;
use dcCore; use dcCore;
use dcRecord; use dcRecord;
use Exception;
class EpcRecord class EpcRecord
{ {
@ -118,7 +119,7 @@ class EpcRecord
} }
self::trigger(); self::trigger();
# --BEHAVIOR-- enhancePostContentAfterAddRecord # --BEHAVIOR-- enhancePostContentAfterAddRecord : cursor
dcCore::app()->callBehavior('enhancePostContentAfterAddRecord', $cur); dcCore::app()->callBehavior('enhancePostContentAfterAddRecord', $cur);
return (int) $cur->getField('epc_id'); return (int) $cur->getField('epc_id');
@ -135,11 +136,11 @@ class EpcRecord
$cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog->id) . "' "); $cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog->id) . "' ");
self::trigger(); self::trigger();
# --BEHAVIOR-- enhancePostContentAfterUpdRecord # --BEHAVIOR-- enhancePostContentAfterUpdRecord : cursor, int
dcCore::app()->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id); dcCore::app()->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id);
} }
public static function isRecord(string $filter, string $key, int $not_id = null): bool public static function isRecord(?string $filter, ?string $key, ?int $not_id = null): bool
{ {
return 0 < self::getRecords([ return 0 < self::getRecords([
'epc_filter' => $filter, 'epc_filter' => $filter,
@ -154,7 +155,7 @@ class EpcRecord
throw new Exception(__('No such record ID')); throw new Exception(__('No such record ID'));
} }
# --BEHAVIOR-- enhancePostContentBeforeDelRecord # --BEHAVIOR-- enhancePostContentBeforeDelRecord, int
dcCore::app()->callBehavior('enhancePostContentbeforeDelRecord', $id); dcCore::app()->callBehavior('enhancePostContentbeforeDelRecord', $id);
dcCore::app()->con->execute( dcCore::app()->con->execute(

View file

@ -14,15 +14,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter; namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterAbbreviation extends EpcFilter class EpcFilterAbbreviation extends EpcFilter
{ {
protected function init(): string protected string $id = 'abbreviation';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 400, 'priority' => 400,
'name' => __('Abbreviation'), 'name' => __('Abbreviation'),
'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'), 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'),
@ -31,36 +34,37 @@ class EpcFilterAbbreviation extends EpcFilter
'class' => ['abbr.epc-abbr'], 'class' => ['abbr.epc-abbr'],
'replace' => '<abbr class="epc-abbr" title="%s">%s</abbr>', 'replace' => '<abbr class="epc-abbr" title="%s">%s</abbr>',
'widget' => '<abbr title="%s">%s</abbr>', 'widget' => '<abbr title="%s">%s</abbr>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'style' => ['font-weight: bold;'], 'style' => ['font-weight: bold;'],
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'abbreviation';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = Epc::replaceString( $args[0] = Epc::replaceString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->replace, __($this->records()->epc_value), '\\1'), sprintf($this->replace, __($this->records()->f('epc_value')), '\\1'),
$args[0], $args[0],
$this $this
); );
} }
} }
public function widgetList(string $content, WidgetsElement $w, array &$list): void public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = Epc::matchString( $list[] = Epc::matchString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->widget, __($this->records()->epc_value), '\\1'), sprintf($this->widget, __($this->records()->f('epc_value')), '\\1'),
$content, $content,
$this $this
); );

View file

@ -14,15 +14,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter; namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterAcronym extends EpcFilter class EpcFilterAcronym extends EpcFilter
{ {
protected function init(): string protected string $id = 'acronym';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 700, 'priority' => 700,
'name' => __('Acronym'), 'name' => __('Acronym'),
'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'), 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'),
@ -31,36 +34,37 @@ class EpcFilterAcronym extends EpcFilter
'class' => ['acronym.epc-acronym'], 'class' => ['acronym.epc-acronym'],
'replace' => '<acronym class="epc-acronym" title="%s">%s</acronym>', 'replace' => '<acronym class="epc-acronym" title="%s">%s</acronym>',
'widget' => '<acronym title="%s">%s</acronym>', 'widget' => '<acronym title="%s">%s</acronym>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'style' => ['font-weight: bold;'], 'style' => ['font-weight: bold;'],
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'acronym';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = Epc::replaceString( $args[0] = Epc::replaceString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->replace, __($this->records()->epc_value), '\\1'), sprintf($this->replace, __($this->records()->f('epc_value')), '\\1'),
$args[0], $args[0],
$this $this
); );
} }
} }
public function widgetList(string $content, WidgetsElement $w, array &$list): void public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = Epc::matchString( $list[] = Epc::matchString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->widget, __($this->records()->epc_value), '\\1'), sprintf($this->widget, __($this->records()->f('epc_value')), '\\1'),
$content, $content,
$this $this
); );

View file

@ -14,15 +14,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter; namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterCitation extends EpcFilter class EpcFilterCitation extends EpcFilter
{ {
protected function init(): string protected string $id = 'citation';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 600, 'priority' => 600,
'name' => __('Citation'), 'name' => __('Citation'),
'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'), 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'),
@ -31,37 +34,38 @@ class EpcFilterCitation extends EpcFilter
'class' => ['cite.epc-cite'], 'class' => ['cite.epc-cite'],
'replace' => '<cite class="epc-cite" title="%s">%s</cite>', 'replace' => '<cite class="epc-cite" title="%s">%s</cite>',
'widget' => '<cite title="%s">%s</cite>', 'widget' => '<cite title="%s">%s</cite>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'nocase' => true, 'nocase' => true,
'style' => ['font-style: italic;'], 'style' => ['font-style: italic;'],
'notag' => 'a,h1,h2,h3', 'notag' => 'a,h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'citation';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = Epc::replaceString( $args[0] = Epc::replaceString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->replace, __($this->records()->epc_value), '\\1'), sprintf($this->replace, __($this->records()->f('epc_value')), '\\1'),
$args[0], $args[0],
$this $this
); );
} }
} }
public function widgetList(string $content, WidgetsElement $w, array &$list): void public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = Epc::matchString( $list[] = Epc::matchString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->widget, __($this->records()->epc_value), '\\1'), sprintf($this->widget, __($this->records()->f('epc_value')), '\\1'),
$content, $content,
$this $this
); );

View file

@ -14,15 +14,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter; namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterDefinition extends EpcFilter class EpcFilterDefinition extends EpcFilter
{ {
protected function init(): string protected string $id = 'definition';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 800, 'priority' => 800,
'name' => __('Definition'), 'name' => __('Definition'),
'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'), 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'),
@ -31,36 +34,37 @@ class EpcFilterDefinition extends EpcFilter
'class' => ['dfn.epc-dfn'], 'class' => ['dfn.epc-dfn'],
'replace' => '<dfn class="epc-dfn" title="%s">%s</dfn>', 'replace' => '<dfn class="epc-dfn" title="%s">%s</dfn>',
'widget' => '<dfn class="epc-dfn" title="%s">%s</dfn>', 'widget' => '<dfn class="epc-dfn" title="%s">%s</dfn>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'style' => ['font-weight: bold;'], 'style' => ['font-weight: bold;'],
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'definition';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = Epc::replaceString( $args[0] = Epc::replaceString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->replace, __($this->records()->epc_value), '\\1'), sprintf($this->replace, __($this->records()->f('epc_value')), '\\1'),
$args[0], $args[0],
$this $this
); );
} }
} }
public function widgetList(string $content, WidgetsElement $w, array &$list): void public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = Epc::matchString( $list[] = Epc::matchString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->widget, __($this->records()->epc_value), '\\1'), sprintf($this->widget, __($this->records()->f('epc_value')), '\\1'),
$content, $content,
$this $this
); );

View file

@ -14,15 +14,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter; namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterLink extends EpcFilter class EpcFilterLink extends EpcFilter
{ {
protected function init(): string protected string $id = 'link';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 500, 'priority' => 500,
'name' => __('Link'), 'name' => __('Link'),
'help' => __('Link some words. First term of the list is the term to link and second term the link.'), 'help' => __('Link some words. First term of the list is the term to link and second term the link.'),
@ -31,36 +34,37 @@ class EpcFilterLink extends EpcFilter
'class' => ['a.epc-link'], 'class' => ['a.epc-link'],
'replace' => '<a class="epc-link" title="%s" href="%s">%s</a>', 'replace' => '<a class="epc-link" title="%s" href="%s">%s</a>',
'widget' => '<a title="%s" href="%s">%s</a>', 'widget' => '<a title="%s" href="%s">%s</a>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'], 'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'],
'notag' => 'a,h1,h2,h3', 'notag' => 'a,h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'link';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = Epc::replaceString( $args[0] = Epc::replaceString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->replace, '\\1', $this->records()->epc_value, '\\1'), sprintf($this->replace, '\\1', $this->records()->f('epc_value'), '\\1'),
$args[0], $args[0],
$this $this
); );
} }
} }
public function widgetList(string $content, WidgetsElement $w, array &$list): void public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = Epc::matchString( $list[] = Epc::matchString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->widget, $this->records()->epc_value, $this->records()->epc_value, '\\1'), sprintf($this->widget, $this->records()->f('epc_value'), $this->records()->f('epc_value'), '\\1'),
$content, $content,
$this $this
); );

View file

@ -16,13 +16,14 @@ namespace Dotclear\Plugin\enhancePostContent\Filter;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterReplace extends EpcFilter class EpcFilterReplace extends EpcFilter
{ {
protected function init(): string protected string $id = 'replace';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 200, 'priority' => 200,
'name' => __('Replace'), 'name' => __('Replace'),
'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'), 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'),
@ -30,26 +31,27 @@ class EpcFilterReplace extends EpcFilter
'htmltag' => '', 'htmltag' => '',
'class' => ['span.epc-replace'], 'class' => ['span.epc-replace'],
'replace' => '<span class="epc-replace">%s</span>', 'replace' => '<span class="epc-replace">%s</span>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'nocase' => true, 'nocase' => true,
'plural' => true, 'plural' => true,
'style' => ['font-style: italic;'], 'style' => ['font-style: italic;'],
'notag' => 'h1,h2,h3', 'notag' => 'h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'replace';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = Epc::replaceString( $args[0] = Epc::replaceString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->replace, $this->records()->epc_value, '\\2'), sprintf($this->replace, $this->records()->f('epc_value'), '\\2'),
$args[0], $args[0],
$this $this
); );

View file

@ -17,31 +17,33 @@ namespace Dotclear\Plugin\enhancePostContent\Filter;
use dcCore; use dcCore;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterSearch extends EpcFilter class EpcFilterSearch extends EpcFilter
{ {
protected function init(): string protected string $id = 'search';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 100, 'priority' => 100,
'name' => __('Search'), 'name' => __('Search'),
'help' => __('Highlight searched words.'), 'help' => __('Highlight searched words.'),
'htmltag' => '', 'htmltag' => '',
'class' => ['span.epc-search'], 'class' => ['span.epc-search'],
'replace' => '<span class="epc-search" title="' . __('Search') . '">%s</span>', 'replace' => '<span class="epc-search" title="' . __('Search') . '">%s</span>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'nocase' => true, 'nocase' => true,
'plural' => true, 'plural' => true,
'style' => ['color: #FFCC66;'], 'style' => ['color: #FFCC66;'],
'notag' => 'h1,h2,h3', 'notag' => 'h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['search.html'], 'pubPages' => ['search.html'],
]); ];
return 'search';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter; namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use dcCore; use dcCore;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
@ -21,9 +22,11 @@ use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterTag extends EpcFilter class EpcFilterTag extends EpcFilter
{ {
protected function init(): string protected string $id = 'tag';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 900, 'priority' => 900,
'name' => __('Tag'), 'name' => __('Tag'),
'help' => __('Highlight tags of your blog.'), 'help' => __('Highlight tags of your blog.'),
@ -31,16 +34,17 @@ class EpcFilterTag extends EpcFilter
'class' => ['a.epc-tag'], 'class' => ['a.epc-tag'],
'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>', 'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>',
'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>', 'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'], 'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'],
'notag' => 'a,h1,h2,h3', 'notag' => 'a,h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'tag';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
@ -53,15 +57,15 @@ class EpcFilterTag extends EpcFilter
while ($metas->fetch()) { while ($metas->fetch()) {
$args[0] = Epc::replaceString( $args[0] = Epc::replaceString(
$metas->meta_id, $metas->f('meta_id'),
sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
$args[0], $args[0],
$this $this
); );
} }
} }
public function widgetList(string $content, WidgetsElement $w, array &$list): void public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
{ {
if (!dcCore::app()->plugins->moduleExists('tags')) { if (!dcCore::app()->plugins->moduleExists('tags')) {
return; return;
@ -71,8 +75,8 @@ class EpcFilterTag extends EpcFilter
while ($metas->fetch()) { while ($metas->fetch()) {
$list[] = Epc::matchString( $list[] = Epc::matchString(
$metas->meta_id, $metas->f('meta_id'),
sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
$content, $content,
$this $this
); );

View file

@ -16,29 +16,31 @@ namespace Dotclear\Plugin\enhancePostContent\Filter;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterTwitter extends EpcFilter class EpcFilterTwitter extends EpcFilter
{ {
protected function init(): string protected string $id = 'twitter';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 1000, 'priority' => 1000,
'name' => __('Twitter'), 'name' => __('Twitter'),
'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'), 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'),
'htmltag' => 'a', 'htmltag' => 'a',
'class' => ['a.epc-twitter'], 'class' => ['a.epc-twitter'],
'replace' => '<a class="epc-twitter" title="' . __("View this user's twitter page") . '" href="%s">%s</a>', 'replace' => '<a class="epc-twitter" title="' . __("View this user's twitter page") . '" href="%s">%s</a>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'], 'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'],
'notag' => 'a,h1,h2,h3', 'notag' => 'a,h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'twitter';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void

View file

@ -16,13 +16,14 @@ namespace Dotclear\Plugin\enhancePostContent\Filter;
use Dotclear\Plugin\enhancePostContent\Epc; use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter; use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterUpdate extends EpcFilter class EpcFilterUpdate extends EpcFilter
{ {
protected function init(): string protected string $id = 'update';
protected function initProperties(): array
{ {
$this->setProperties([ return [
'priority' => 300, 'priority' => 300,
'name' => __('Update'), 'name' => __('Update'),
'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'), 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'),
@ -30,26 +31,27 @@ class EpcFilterUpdate extends EpcFilter
'htmltag' => 'del,ins', 'htmltag' => 'del,ins',
'class' => ['del.epc-update', 'ins.epc-update'], 'class' => ['del.epc-update', 'ins.epc-update'],
'replace' => '<del class="epc-update">%s</del> <ins class="epc-update">%s</ins>', 'replace' => '<del class="epc-update">%s</del> <ins class="epc-update">%s</ins>',
]); ];
}
$this->setSettings([ protected function initSettings(): array
{
return [
'nocase' => true, 'nocase' => true,
'plural' => true, 'plural' => true,
'style' => ['text-decoration: line-through;', 'font-style: italic;'], 'style' => ['text-decoration: line-through;', 'font-style: italic;'],
'notag' => 'h1,h2,h3', 'notag' => 'h1,h2,h3',
'tplValues' => ['EntryContent'], 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'], 'pubPages' => ['post.html'],
]); ];
return 'update';
} }
public function publicContent(string $tag, array $args): void public function publicContent(string $tag, array $args): void
{ {
while ($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = Epc::replaceString( $args[0] = Epc::replaceString(
$this->records()->epc_key, $this->records()->f('epc_key'),
sprintf($this->replace, '\\1', $this->records()->epc_value), sprintf($this->replace, '\\1', $this->records()->f('epc_value')),
$args[0], $args[0],
$this $this
); );

View file

@ -34,7 +34,7 @@ class Frontend extends dcNsProcess
} }
if (!dcCore::app()->blog->settings->get(My::id())->get('active')) { if (!dcCore::app()->blog->settings->get(My::id())->get('active')) {
return null; return false;
} }
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([

View file

@ -38,7 +38,6 @@ class Install extends dcNsProcess
} }
try { try {
// Database // Database
$s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$s->{My::TABLE_NAME} $s->{My::TABLE_NAME}
@ -98,7 +97,7 @@ class Install extends dcNsProcess
/** /**
* Check upgrade to apply * Check upgrade to apply
*/ */
public static function growUp() public static function growUp(): void
{ {
$current = dcCore::app()->getVersion(My::id()); $current = dcCore::app()->getVersion(My::id());
@ -120,7 +119,7 @@ class Install extends dcNsProcess
* *
* - filters move from settings to dedicated table * - filters move from settings to dedicated table
*/ */
private static function upTo00060607() private static function upTo00060607(): void
{ {
# Move old filters lists from settings to database # Move old filters lists from settings to database
$record = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL "); $record = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL ");
@ -153,7 +152,7 @@ class Install extends dcNsProcess
* *
* - filters change name to id * - filters change name to id
*/ */
private static function upTo20211006() private static function upTo20211006(): void
{ {
# Move old filter name to filter id # Move old filter name to filter id
$record = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . My::TABLE_NAME); $record = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . My::TABLE_NAME);
@ -174,7 +173,7 @@ class Install extends dcNsProcess
* - setting ns changes to abstract one (no real changes), * - setting ns changes to abstract one (no real changes),
* - setting value change from serialize to json_encode (if it's array) * - setting value change from serialize to json_encode (if it's array)
*/ */
private static function upTo20221120() private static function upTo20221120(): void
{ {
// list of settings using serialize values to move to json // list of settings using serialize values to move to json
$ids = [ $ids = [
@ -202,7 +201,7 @@ class Install extends dcNsProcess
$cur->setfield('setting_value', json_encode(unserialize($record->f('setting_value')))); $cur->setfield('setting_value', json_encode(unserialize($record->f('setting_value'))));
} }
$cur->update("WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'enhancePostContent' "); $cur->update("WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = 'enhancePostContent' ");
} }
} }
} }

View file

@ -25,7 +25,7 @@ use Dotclear\Helper\Html\Form\{
Form, Form,
Hidden, Hidden,
Input, Input,
label, Label,
Note, Note,
Number, Number,
Para, Para,
@ -225,7 +225,7 @@ class Manage extends dcNsProcess
$form_pages = [(new Text('h4', __('Pages to be filtered')))]; $form_pages = [(new Text('h4', __('Pages to be filtered')))];
foreach (Epc::blogAllowedPubPages() as $k => $v) { foreach (Epc::blogAllowedPubPages() as $k => $v) {
$form_pages[] = (new Para())->items([ $form_pages[] = (new Para())->items([
(new Checkbox(['filter_pubPages[]', 'filter_pubPages' . $v], in_array($v, $current->filter->pubPages)))->value(1), (new Checkbox(['filter_pubPages[]', 'filter_pubPages' . $v], in_array($v, $current->filter->pubPages)))->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_pubPages' . $v)->class('classic'), (new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_pubPages' . $v)->class('classic'),
]); ]);
} }
@ -233,7 +233,7 @@ class Manage extends dcNsProcess
$form_values = [(new Text('h4', __('Contents to be filtered')))]; $form_values = [(new Text('h4', __('Contents to be filtered')))];
foreach (Epc::blogAllowedTplValues() as $k => $v) { foreach (Epc::blogAllowedTplValues() as $k => $v) {
$form_values[] = (new Para())->items([ $form_values[] = (new Para())->items([
(new Checkbox(['filter_tplValues[]', 'filter_tplValues' . $v], in_array($v, $current->filter->tplValues)))->value(1), (new Checkbox(['filter_tplValues[]', 'filter_tplValues' . $v], in_array($v, $current->filter->tplValues)))->value($v),
(new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_tplValues' . $v)->class('classic'), (new Label(__($k), Label::OUTSIDE_LABEL_AFTER))->for('filter_tplValues' . $v)->class('classic'),
]); ]);
} }
@ -286,7 +286,7 @@ class Manage extends dcNsProcess
])->render(); ])->render();
# Filter records list # Filter records list
if ($current->filter->has_list && isset($sorts) && isset($pager)) { if ($current->filter->has_list && isset($pager)) {
$pager_url = dcCore::app()->adminurl->get('admin.plugin.' . My::id(), array_diff_key($sorts->values(true), ['page' => ''])) . '&page=%s#record'; $pager_url = dcCore::app()->adminurl->get('admin.plugin.' . My::id(), array_diff_key($sorts->values(true), ['page' => ''])) . '&page=%s#record';
echo ' echo '

View file

@ -14,7 +14,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use dcCore;
use Exception; use Exception;
class ManageVars class ManageVars

View file

@ -22,7 +22,7 @@ use dcCore;
class My class My
{ {
/** @var string Required php version */ /** @var string Required php version */
public const PHP_MIN = '8.0'; public const PHP_MIN = '8.1';
/** @var string Plugin table name */ /** @var string Plugin table name */
public const TABLE_NAME = 'epc'; public const TABLE_NAME = 'epc';

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
use ArrayObject;
use dcCore; use dcCore;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Plugin\widgets\WidgetsStack; use Dotclear\Plugin\widgets\WidgetsStack;
@ -29,7 +30,7 @@ class Widgets
/** /**
* Admin part for widget that show extracted content * Admin part for widget that show extracted content
* *
* @param dcWidgets $w dcWidgets instance * @param WidgetsStack $w WidgetsStack instance
*/ */
public static function initWidgets(WidgetsStack $w): void public static function initWidgets(WidgetsStack $w): void
{ {
@ -53,8 +54,10 @@ class Widgets
$filters = Epc::getFilters(); $filters = Epc::getFilters();
$types = []; $types = [];
foreach ($filters as $id => $filter) { foreach ($filters as $id => $filter) {
if ($filter->widget != '') {
$types[$filter->name] = $id; $types[$filter->name] = $id;
} }
}
$w->epclist->setting( $w->epclist->setting(
'type', 'type',
__('Type:'), __('Type:'),
@ -72,20 +75,6 @@ class Widgets
'check' 'check'
); );
} }
# Case sensitive
$w->epclist->setting(
'nocase',
__('Search case insensitive'),
0,
'check'
);
# Plural
$w->epclist->setting(
'plural',
__('Search also plural'),
0,
'check'
);
# Show count # Show count
$w->epclist->setting( $w->epclist->setting(
'show_total', 'show_total',
@ -103,7 +92,7 @@ class Widgets
/** /**
* Public part for widget that show extracted content * Public part for widget that show extracted content
* *
* @param dcWidget $w dcWidget instance * @param WidgetsElement $w WidgetsElement instance
*/ */
public static function parseWidget(WidgetsElement $w): string public static function parseWidget(WidgetsElement $w): string
{ {
@ -123,9 +112,9 @@ class Widgets
foreach (Epc::defaultAllowedWidgetValues() as $k => $v) { foreach (Epc::defaultAllowedWidgetValues() as $k => $v) {
$ns = 'content' . $v['id']; $ns = 'content' . $v['id'];
if ($w->$ns && is_callable($v['cb'])) { if ($w->$ns && is_callable($v['cb'])) {
$content .= call_user_func_array( $content .= call_user_func(
$v['cb'], $v['cb'],
[dcCore::app(), $w] $w
); );
} }
} }
@ -135,16 +124,14 @@ class Widgets
} }
# Filter # Filter
$list = []; $list = new ArrayObject();
$filters = Epc::getFilters(); $filters = Epc::getFilters();
if (isset($filters[$w->type])) { if (isset($filters[$w->type])) {
$filters[$w->type]->nocase = $w->nocase;
$filters[$w->type]->plural = $w->plural;
$filters[$w->type]->widgetList($content, $w, $list); $filters[$w->type]->widgetList($content, $w, $list);
} }
if (empty($list)) { if (!count($list)) {
return ''; return '';
} }