level up phpstan (use php 8.1 readonly properties)

master
Jean-Christian Paul 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

@ -58,7 +58,7 @@ class Backend extends dcNsProcess
dcCore::app()->addBehaviors([
# Dashboard favorites
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
$favs->register(My::id(), [
'title' => My::name(),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
@ -68,7 +68,7 @@ class Backend extends dcNsProcess
]);
},
# Preference form
'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings):void {
'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings): void {
$active = (bool) $blog_settings->get(My::id())->get('active');
$allowedtplvalues = Epc::blogAllowedTplValues();
$allowedpubpages = Epc::blogAllowedPubPages();
@ -119,7 +119,7 @@ class Backend extends dcNsProcess
$blog_settings->get(My::id())->put('allowedpubpages', json_encode($allowedpubpages));
},
# List filter
'adminFiltersListsV2' => function (ArrayObject $sorts): void {
'adminFiltersListsV2' => function (ArrayObject $sorts): void {
$sorts['epc'] = [
My::name(),
[
@ -134,7 +134,7 @@ class Backend extends dcNsProcess
];
},
# Widgets
'initWidgets' => [Widgets::class, 'initWidgets'],
'initWidgets' => [Widgets::class, 'initWidgets'],
]);
return true;

View File

@ -14,8 +14,8 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent;
use adminGenericFilterV2;
use adminGenericListV2;
use dcCore;
use dcPager;
use Dotclear\Helper\Html\Form\Checkbox;
use Dotclear\Helper\Html\Html;
@ -29,12 +29,12 @@ use dt;
*/
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()) {
echo '<p><strong>' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '</strong></p>';
} 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;
$epc_id = [];

View File

@ -33,8 +33,8 @@ __('RSS feeds');
class Epc
{
protected static $default_filters = null;
public static $epcFilterLimit = [];
protected static array $default_filters = [];
public static array $epcFilterLimit = [];
#
# Default definition
@ -48,6 +48,7 @@ class Epc
'comment content' => 'CommentContent',
]);
# --BEHAVIOR-- enhancePostContentAllowedTplValues : ArrayObject
dcCore::app()->callBehavior('enhancePostContentAllowedTplValues', $rs);
return iterator_to_array($rs, true);
@ -55,7 +56,7 @@ class Epc
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();
}
@ -63,20 +64,21 @@ class Epc
public static function defaultAllowedWidgetValues(): array
{
$rs = new ArrayObject([
'entry excerpt' => [
'entry excerpt' => [
'id' => 'entryexcerpt',
'cb' => [self::class,'widgetContentEntryExcerpt'],
'cb' => [self::class, 'widgetContentEntryExcerpt'],
],
'entry content' => [
'entry content' => [
'id' => 'entrycontent',
'cb' => [self::class,'widgetContentEntryContent'],
'cb' => [self::class, 'widgetContentEntryContent'],
],
'comment content' => [
'id' => 'commentcontent',
'cb' => [self::class,'widgetContentCommentContent'],
'cb' => [self::class, 'widgetContentCommentContent'],
],
]);
# --BEHAVIOR-- enhancePostContentAllowedWidgetValues : ArrayObject
dcCore::app()->callBehavior('enhancePostContentAllowedWidgetValues', $rs);
return iterator_to_array($rs, true);
@ -93,6 +95,7 @@ class Epc
'RSS feeds' => 'rss2.xml',
]);
# --BEHAVIOR-- enhancePostContentAllowedPubPages : ArrayObject
dcCore::app()->callBehavior('enhancePostContentAllowedPubPages', $rs);
return iterator_to_array($rs, true);
@ -107,15 +110,17 @@ class Epc
public static function getFilters(): ?array
{
if (self::$default_filters === null) {
$final = $sort = [];
if (empty(self::$default_filters)) {
$final = $sort = [];
/** @var ArrayObject<string,EpcFilter> $filters The filters stack */
$filters = new ArrayObject();
try {
# --BEHAVIOR-- enhancePostContentFilters : ArrayObject
dcCore::app()->callBehavior('enhancePostContentFilters', $filters);
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;
$final[$filter->id()] = $filter;
}
@ -132,9 +137,7 @@ class Epc
public static function testContext(string $tag, array $args, EpcFilter $filter): bool
{
return is_array($filter->pubPages)
&& in_array(dcCore::app()->ctx->current_tpl, $filter->pubPages)
&& is_array($filter->tplValues)
return in_array(dcCore::app()->ctx->current_tpl, $filter->pubPages)
&& in_array($tag, $filter->tplValues)
&& $args[0] != '' //content
&& empty($args['encode_xml'])
@ -184,7 +187,7 @@ class Epc
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
$i = $filter->nocase ? 'i' : '';
@ -231,7 +234,7 @@ class Epc
return $a;
}
if (!is_array($a)) {
return [];
return '';
}
$r = '';
@ -248,7 +251,7 @@ class Epc
return $s;
}
if (!is_string($s)) {
return '';
return [];
}
$r = [];
@ -284,7 +287,7 @@ class Epc
public static function widgetContentEntryExcerpt(?WidgetsElement $w = null): string
{
if (!dcCore::app()->ctx->exists('posts')) {
return null;
return '';
}
$res = '';
@ -298,7 +301,7 @@ class Epc
public static function widgetContentEntryContent(): string
{
if (!dcCore::app()->ctx->exists('posts')) {
return null;
return '';
}
$res = '';
@ -312,7 +315,7 @@ class Epc
public static function widgetContentCommentContent(): string
{
if (!dcCore::app()->ctx->exists('posts')) {
return null;
return '';
}
$res = '';

View File

@ -18,133 +18,98 @@ use ArrayObject;
use dcCore;
use dcRecord;
use Dotclear\Plugin\widgets\WidgetsElement;
use Exception;
abstract class EpcFilter
{
private $id = 'undefined';
private $records = null;
protected string $id = 'undefined';
private $properties = [
'priority' => 500,
'name' => 'undefined',
'help' => 'undefined',
'has_list' => false,
'htmltag' => '',
'class' => [],
'replace' => '',
'widget' => '',
];
private $settings = [
'nocase' => false,
'plural' => false,
'limit' => 0,
'style' => [],
'notag' => '',
'tplValues' => [],
'pubPages' => [],
];
private ?dcRecord $records = null;
// properties
public readonly int $priority;
public readonly string $name;
public readonly string $help;
public readonly bool $has_list;
public readonly string $htmltag;
public readonly array $class;
public readonly string $replace;
public readonly string $widget;
// settings
public readonly bool $nocase;
public readonly bool $plural;
public readonly int $limit;
public readonly array $style;
public readonly string $notag;
public readonly array $tplValues;
public readonly array $pubPages;
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
{
$c = get_called_class();
$c = static::class;
$o->append(new $c());
}
final public function id()
final public function id(): string
{
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
{
if ($this->records === null && $this->has_list) {
@ -154,15 +119,11 @@ abstract class EpcFilter
return $this->records;
}
abstract protected function init(): string;
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 dcCore;
use dcRecord;
use Exception;
class EpcRecord
{
@ -118,7 +119,7 @@ class EpcRecord
}
self::trigger();
# --BEHAVIOR-- enhancePostContentAfterAddRecord
# --BEHAVIOR-- enhancePostContentAfterAddRecord : cursor
dcCore::app()->callBehavior('enhancePostContentAfterAddRecord', $cur);
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) . "' ");
self::trigger();
# --BEHAVIOR-- enhancePostContentAfterUpdRecord
# --BEHAVIOR-- enhancePostContentAfterUpdRecord : cursor, int
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([
'epc_filter' => $filter,
@ -154,7 +155,7 @@ class EpcRecord
throw new Exception(__('No such record ID'));
}
# --BEHAVIOR-- enhancePostContentBeforeDelRecord
# --BEHAVIOR-- enhancePostContentBeforeDelRecord, int
dcCore::app()->callBehavior('enhancePostContentbeforeDelRecord', $id);
dcCore::app()->con->execute(

View File

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

View File

@ -14,15 +14,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterAcronym extends EpcFilter
{
protected function init(): string
protected string $id = 'acronym';
protected function initProperties(): array
{
$this->setProperties([
return [
'priority' => 700,
'name' => __('Acronym'),
'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'],
'replace' => '<acronym class="epc-acronym" title="%s">%s</acronym>',
'widget' => '<acronym title="%s">%s</acronym>',
]);
];
}
$this->setSettings([
protected function initSettings(): array
{
return [
'style' => ['font-weight: bold;'],
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
]);
return 'acronym';
];
}
public function publicContent(string $tag, array $args): void
{
while ($this->records()->fetch()) {
$args[0] = Epc::replaceString(
$this->records()->epc_key,
sprintf($this->replace, __($this->records()->epc_value), '\\1'),
$this->records()->f('epc_key'),
sprintf($this->replace, __($this->records()->f('epc_value')), '\\1'),
$args[0],
$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()) {
$list[] = Epc::matchString(
$this->records()->epc_key,
sprintf($this->widget, __($this->records()->epc_value), '\\1'),
$this->records()->f('epc_key'),
sprintf($this->widget, __($this->records()->f('epc_value')), '\\1'),
$content,
$this
);

View File

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

View File

@ -14,15 +14,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterDefinition extends EpcFilter
{
protected function init(): string
protected string $id = 'definition';
protected function initProperties(): array
{
$this->setProperties([
return [
'priority' => 800,
'name' => __('Definition'),
'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'],
'replace' => '<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;'],
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
]);
return 'definition';
];
}
public function publicContent(string $tag, array $args): void
{
while ($this->records()->fetch()) {
$args[0] = Epc::replaceString(
$this->records()->epc_key,
sprintf($this->replace, __($this->records()->epc_value), '\\1'),
$this->records()->f('epc_key'),
sprintf($this->replace, __($this->records()->f('epc_value')), '\\1'),
$args[0],
$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()) {
$list[] = Epc::matchString(
$this->records()->epc_key,
sprintf($this->widget, __($this->records()->epc_value), '\\1'),
$this->records()->f('epc_key'),
sprintf($this->widget, __($this->records()->f('epc_value')), '\\1'),
$content,
$this
);

View File

@ -14,15 +14,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterLink extends EpcFilter
{
protected function init(): string
protected string $id = 'link';
protected function initProperties(): array
{
$this->setProperties([
return [
'priority' => 500,
'name' => __('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'],
'replace' => '<a class="epc-link" 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;'],
'notag' => 'a,h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
]);
return 'link';
];
}
public function publicContent(string $tag, array $args): void
{
while ($this->records()->fetch()) {
$args[0] = Epc::replaceString(
$this->records()->epc_key,
sprintf($this->replace, '\\1', $this->records()->epc_value, '\\1'),
$this->records()->f('epc_key'),
sprintf($this->replace, '\\1', $this->records()->f('epc_value'), '\\1'),
$args[0],
$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()) {
$list[] = Epc::matchString(
$this->records()->epc_key,
sprintf($this->widget, $this->records()->epc_value, $this->records()->epc_value, '\\1'),
$this->records()->f('epc_key'),
sprintf($this->widget, $this->records()->f('epc_value'), $this->records()->f('epc_value'), '\\1'),
$content,
$this
);

View File

@ -16,13 +16,14 @@ namespace Dotclear\Plugin\enhancePostContent\Filter;
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterReplace extends EpcFilter
{
protected function init(): string
protected string $id = 'replace';
protected function initProperties(): array
{
$this->setProperties([
return [
'priority' => 200,
'name' => __('Replace'),
'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' => '',
'class' => ['span.epc-replace'],
'replace' => '<span class="epc-replace">%s</span>',
]);
];
}
$this->setSettings([
protected function initSettings(): array
{
return [
'nocase' => true,
'plural' => true,
'style' => ['font-style: italic;'],
'notag' => 'h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
]);
return 'replace';
];
}
public function publicContent(string $tag, array $args): void
{
while ($this->records()->fetch()) {
$args[0] = Epc::replaceString(
$this->records()->epc_key,
sprintf($this->replace, $this->records()->epc_value, '\\2'),
$this->records()->f('epc_key'),
sprintf($this->replace, $this->records()->f('epc_value'), '\\2'),
$args[0],
$this
);

View File

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

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
use dcCore;
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
@ -21,9 +22,11 @@ use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterTag extends EpcFilter
{
protected function init(): string
protected string $id = 'tag';
protected function initProperties(): array
{
$this->setProperties([
return [
'priority' => 900,
'name' => __('Tag'),
'help' => __('Highlight tags of your blog.'),
@ -31,16 +34,17 @@ class EpcFilterTag extends EpcFilter
'class' => ['a.epc-tag'],
'replace' => '<a class="epc-tag" 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;'],
'notag' => 'a,h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
]);
return 'tag';
];
}
public function publicContent(string $tag, array $args): void
@ -53,15 +57,15 @@ class EpcFilterTag extends EpcFilter
while ($metas->fetch()) {
$args[0] = Epc::replaceString(
$metas->meta_id,
sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'),
$metas->f('meta_id'),
sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
$args[0],
$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')) {
return;
@ -71,8 +75,8 @@ class EpcFilterTag extends EpcFilter
while ($metas->fetch()) {
$list[] = Epc::matchString(
$metas->meta_id,
sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'),
$metas->f('meta_id'),
sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
$content,
$this
);

View File

@ -16,29 +16,31 @@ namespace Dotclear\Plugin\enhancePostContent\Filter;
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterTwitter extends EpcFilter
{
protected function init(): string
protected string $id = 'twitter';
protected function initProperties(): array
{
$this->setProperties([
return [
'priority' => 1000,
'name' => __('Twitter'),
'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'),
'htmltag' => 'a',
'class' => ['a.epc-twitter'],
'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;'],
'notag' => 'a,h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
]);
return 'twitter';
];
}
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\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
class EpcFilterUpdate extends EpcFilter
{
protected function init(): string
protected string $id = 'update';
protected function initProperties(): array
{
$this->setProperties([
return [
'priority' => 300,
'name' => __('Update'),
'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',
'class' => ['del.epc-update', 'ins.epc-update'],
'replace' => '<del class="epc-update">%s</del> <ins class="epc-update">%s</ins>',
]);
];
}
$this->setSettings([
protected function initSettings(): array
{
return [
'nocase' => true,
'plural' => true,
'style' => ['text-decoration: line-through;', 'font-style: italic;'],
'notag' => 'h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
]);
return 'update';
];
}
public function publicContent(string $tag, array $args): void
{
while ($this->records()->fetch()) {
$args[0] = Epc::replaceString(
$this->records()->epc_key,
sprintf($this->replace, '\\1', $this->records()->epc_value),
$this->records()->f('epc_key'),
sprintf($this->replace, '\\1', $this->records()->f('epc_value')),
$args[0],
$this
);

View File

@ -34,12 +34,12 @@ class Frontend extends dcNsProcess
}
if (!dcCore::app()->blog->settings->get(My::id())->get('active')) {
return null;
return false;
}
dcCore::app()->addBehaviors([
// add CSS URL to header
'publicHeadContent' => function (): void {
'publicHeadContent' => function (): void {
echo dcUtils::cssLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('epccss'));
},
// Filter template blocks content
@ -54,7 +54,7 @@ class Frontend extends dcNsProcess
}
},
// Widgets
'initWidgets' => [Widgets::class, 'initWidgets'],
'initWidgets' => [Widgets::class, 'initWidgets'],
]);
return true;

View File

@ -38,7 +38,6 @@ class Install extends dcNsProcess
}
try {
// Database
$s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$s->{My::TABLE_NAME}
@ -98,7 +97,7 @@ class Install extends dcNsProcess
/**
* Check upgrade to apply
*/
public static function growUp()
public static function growUp(): void
{
$current = dcCore::app()->getVersion(My::id());
@ -120,7 +119,7 @@ class Install extends dcNsProcess
*
* - filters move from settings to dedicated table
*/
private static function upTo00060607()
private static function upTo00060607(): void
{
# 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 ");
@ -153,7 +152,7 @@ class Install extends dcNsProcess
*
* - filters change name to id
*/
private static function upTo20211006()
private static function upTo20211006(): void
{
# Move old filter name to filter id
$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 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
$ids = [
@ -202,7 +201,7 @@ class Install extends dcNsProcess
$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,
Hidden,
Input,
label,
Label,
Note,
Number,
Para,
@ -125,9 +125,9 @@ class Manage extends dcNsProcess
}
# Update filter records
if ($current->action == 'deleterecords'
if ($current->action == 'deleterecords'
&& $current->filter->has_list
&& !empty($_POST['epc_id'])
&& !empty($_POST['epc_id'])
&& is_array($_POST['epc_id'])
) {
foreach ($_POST['epc_id'] as $id) {
@ -198,7 +198,7 @@ class Manage extends dcNsProcess
);
# Page title
echo
echo
dcPage::breadcrumb([
__('Plugins') => '',
My::name() => '',
@ -217,7 +217,7 @@ class Manage extends dcNsProcess
])->render();
# Filter title and description
echo
echo
'<h3>' . $current->filter->name . '</h3>' .
'<p>' . $current->filter->help . '</p>';
@ -225,7 +225,7 @@ class Manage extends dcNsProcess
$form_pages = [(new Text('h4', __('Pages to be filtered')))];
foreach (Epc::blogAllowedPubPages() as $k => $v) {
$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'),
]);
}
@ -233,7 +233,7 @@ class Manage extends dcNsProcess
$form_values = [(new Text('h4', __('Contents to be filtered')))];
foreach (Epc::blogAllowedTplValues() as $k => $v) {
$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'),
]);
}
@ -246,7 +246,7 @@ class Manage extends dcNsProcess
]);
}
echo
echo
(new Div('setting'))->class('multi-part')->title(__('Settings'))->items([
(new Form('setting_form'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#setting')->separator('')->fields([
(new Div())->class('two-boxes even')->items($form_pages),
@ -286,7 +286,7 @@ class Manage extends dcNsProcess
])->render();
# 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';
echo '
@ -319,7 +319,7 @@ class Manage extends dcNsProcess
echo '</div>';
# New record
echo
echo
(new Div('newrecord'))->class('multi-part')->title(__('New record'))->items([
(new Form('form-create'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record')->fields([
(new Para())->items([

View File

@ -14,7 +14,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent;
use dcCore;
use Exception;
class ManageVars
@ -45,10 +44,10 @@ class ManageVars
throw new Exception(__('no filters'));
}
$this->action = $_POST['action'] ?? '';
$this->part = $part;
$this->filter = $_filters[$part];
$this->combo = $filters_combo;
$this->action = $_POST['action'] ?? '';
$this->part = $part;
$this->filter = $_filters[$part];
$this->combo = $filters_combo;
}
public static function init(): ManageVars

View File

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

View File

@ -116,7 +116,7 @@ class Uninstall
/* ns */
My::id(),
/* description */
sprintf(__('delete %s version number'),My::id())
sprintf(__('delete %s version number'), My::id())
);
return true;

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent;
use ArrayObject;
use dcCore;
use Dotclear\Helper\Html\Html;
use Dotclear\Plugin\widgets\WidgetsStack;
@ -29,7 +30,7 @@ class Widgets
/**
* 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
{
@ -53,7 +54,9 @@ class Widgets
$filters = Epc::getFilters();
$types = [];
foreach ($filters as $id => $filter) {
$types[$filter->name] = $id;
if ($filter->widget != '') {
$types[$filter->name] = $id;
}
}
$w->epclist->setting(
'type',
@ -72,20 +75,6 @@ class Widgets
'check'
);
}
# Case sensitive
$w->epclist->setting(
'nocase',
__('Search case insensitive'),
0,
'check'
);
# Plural
$w->epclist->setting(
'plural',
__('Search also plural'),
0,
'check'
);
# Show count
$w->epclist->setting(
'show_total',
@ -103,7 +92,7 @@ class Widgets
/**
* 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
{
@ -123,9 +112,9 @@ class Widgets
foreach (Epc::defaultAllowedWidgetValues() as $k => $v) {
$ns = 'content' . $v['id'];
if ($w->$ns && is_callable($v['cb'])) {
$content .= call_user_func_array(
$content .= call_user_func(
$v['cb'],
[dcCore::app(), $w]
$w
);
}
}
@ -135,16 +124,14 @@ class Widgets
}
# Filter
$list = [];
$list = new ArrayObject();
$filters = Epc::getFilters();
if (isset($filters[$w->type])) {
$filters[$w->type]->nocase = $w->nocase;
$filters[$w->type]->plural = $w->plural;
$filters[$w->type]->widgetList($content, $w, $list);
}
if (empty($list)) {
if (!count($list)) {
return '';
}