diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0687d1c..6ed140c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@ dev
- [ ] add priority on filters for replacement order
- [ ] add priority on lists of filters for replacement order
- [ ] add auto-find post title in content
-- [ ] split filters into modules
+- split filters into modules
- add autosubmit onadmin menu
- move sort options from blog pref to user pref
- add pager for records list
diff --git a/_install.php b/_install.php
index 7294ec2..95fa63d 100644
--- a/_install.php
+++ b/_install.php
@@ -66,26 +66,26 @@ try {
$s->put('enhancePostContent_allowedpubpages', serialize(libEPC::defaultAllowedPubPages()), 'string', 'List of allowed template pages', false, true);
# Filters settings
- $filters = libEPC::defaultFilters();
- foreach($filters as $name => $filter) {
+ $filters = libEPC::getFilters();
+ foreach($filters as $id => $filter) {
# Only editable options
$opt = [
- 'nocase' => $filter['nocase'],
- 'plural' => $filter['plural'],
- 'style' => $filter['style'],
- 'notag' => $filter['notag'],
- 'tplValues' => $filter['tplValues'],
- 'pubPages' => $filter['pubPages']
+ 'nocase' => $filter->nocase,
+ 'plural' => $filter->plural,
+ 'style' => $filter->style,
+ 'notag' => $filter->notag,
+ 'tplValues' => $filter->tplValues,
+ 'pubPages' => $filter->pubPages
];
- $s->put('enhancePostContent_' . $name, serialize($opt), 'string', 'Settings for ' . $name, false, true);
- # only tables
+ $s->put('enhancePostContent_' . $id, serialize($opt), 'string', 'Settings for ' . $id, false, true);
+/* # only tables
if (isset($filter['list'])) {
- $s->put('enhancePostContent_' . $name . 'List', serialize($filter['list']), 'string', 'List for ' . $name, false, true);
+ $s->put('enhancePostContent_' . $id . 'List', serialize($filter['list']), 'string', 'List for ' . $id, false, true);
}
- }
+*/ }
- # Move old filters lists from settings to database
- if ($old_version && version_compare('0.6.6', $old_version, '>=')) {
+ # Update old versions
+ if ($old_version && version_compare('2021.10.05', $old_version, '>=')) {
include_once dirname(__FILE__) . '/inc/lib.epc.update.php';
}
diff --git a/_prepend.php b/_prepend.php
index 9389dae..4dcebbf 100644
--- a/_prepend.php
+++ b/_prepend.php
@@ -15,12 +15,31 @@ if (!defined('DC_RC_PATH')) {
return null;
}
+$filters = [
+ 'Tag',
+ 'Search',
+ 'Acronym',
+ 'Abbreviation',
+ 'Definition',
+ 'Citation',
+ 'Link',
+ 'Replace',
+ 'Update',
+ 'Twitter'
+];
+
$d = dirname(__FILE__) . '/inc/';
$__autoload['libEPC'] = $d . 'lib.epc.php';
+$__autoload['epcFilter'] = $d . 'lib.epc.filter.php';
$__autoload['epcRecords'] = $d . 'lib.epc.records.php';
$__autoload['adminEpcList'] = $d . 'lib.epc.pager.php';
+foreach($filters as $f) {
+ $__autoload['epcFilter' . $f] = $d . 'lib.epc.filters.php';
+ $core->addBehavior('enhancePostContentFilters', ['epcFilter' . $f, 'create']);
+}
+
$core->url->register(
'epccss',
'epc.css',
diff --git a/_public.php b/_public.php
index 3a1c841..d919705 100644
--- a/_public.php
+++ b/_public.php
@@ -51,16 +51,17 @@ class publicEnhancePostContent
public static function css($args)
{
$css = [];
- $filters = libEPC::blogFilters();
+ $filters = libEPC::getFilters();
- foreach($filters as $name => $filter) {
- if (empty($filter['class']) || empty($filter['style'])) {
+ foreach($filters as $id => $filter) {
+ if ('' != $filter->class || '' != $filter->style) {
continue;
}
$res = '';
- foreach($filter['class'] as $k => $class) {
- $style = html::escapeHTML(trim($filter['style'][$k]));
+ foreach($filter->class as $k => $class) {
+ $styles = $filter->style;
+ $style = html::escapeHTML(trim($styles[$k]));
if ('' != $style) {
$res .= $class . " {" . $style . "} ";
}
@@ -68,7 +69,7 @@ class publicEnhancePostContent
if (!empty($res)) {
$css[] =
- "/* CSS for enhancePostContent " . $name . " */ \n" . $res . "\n";
+ "/* CSS for enhancePostContent " . $id . " */ \n" . $res . "\n";
}
}
@@ -88,30 +89,13 @@ class publicEnhancePostContent
*/
public static function publicContentFilter(dcCore $core, $tag, $args)
{
- $filters = libEPC::blogFilters();
- $records = new epcRecords($core);
+ $filters = libEPC::getFilters();
- foreach($filters as $name => $filter) {
-
- if (!isset($filter['publicContentFilter'])
- || !is_callable($filter['publicContentFilter'])
- || !libEPC::testContext($tag,$args,$filter)) {
+ foreach($filters as $id => $filter) {
+ if (!libEPC::testContext($tag, $args, $filter)) {
continue;
}
-
- if ($filter['has_list']) {
- $filter['list'] = $records->getRecords(array(
- 'epc_filter' => $name)
- );
- if ($filter['list']->isEmpty()) {
- continue;
- }
- }
-
- call_user_func_array(
- $filter['publicContentFilter'],
- [$core, $filter, $tag, $args]
- );
+ $filter->publicContent($tag, $args);
}
}
}
\ No newline at end of file
diff --git a/_widgets.php b/_widgets.php
index 4d0778e..371d11c 100644
--- a/_widgets.php
+++ b/_widgets.php
@@ -44,12 +44,7 @@ class enhancePostContentWidget
__('List filtered contents.')
);
# Title
- $w->epclist->setting(
- 'title',
- __('Title:'),
- __('In this article'),
- 'text'
- );
+ $w->epclist->addTitle(__('In this article'));
# Text
$w->epclist->setting(
'text',
@@ -58,15 +53,10 @@ class enhancePostContentWidget
'text'
);
# Type
- $filters = libEPC::blogFilters();
+ $filters = libEPC::getFilters();
$types = [];
- foreach($filters as $name => $filter) {
- if (!isset($filter['widgetListFilter'])
- || !is_callable($filter['widgetListFilter'])) {
- continue;
- }
-
- $types[__($name)] = $name;
+ foreach($filters as $id => $filter) {
+ $types[$filter->name] = $id;
}
$w->epclist->setting(
'type',
@@ -106,19 +96,11 @@ class enhancePostContentWidget
1,
'check'
);
- # widget option - content only
- $w->epclist->setting(
- 'content_only',
- __('Content only'),
- 0,
- 'check'
- );
- # widget option - additionnal CSS
- $w->epclist->setting(
- 'class',
- __('CSS class:'),
- ''
- );
+ # widget options
+ $w->epclist
+ ->addContentOnly()
+ ->addClass()
+ ->addOffline();
}
/**
@@ -130,24 +112,26 @@ class enhancePostContentWidget
{
global $core, $_ctx;
+ if ($w->offline) {
+ return null;
+ }
+
$core->blog->settings->addNamespace('enhancePostContent');
# Page
if (!$core->blog->settings->enhancePostContent->enhancePostContent_active
- || !in_array($_ctx->current_tpl, ['post.html', 'page.html'])) {
+ || !in_array($_ctx->current_tpl, ['post.html', 'page.html'])
+ ) {
return null;
}
# Content
$content = '';
- $allowedwidgetvalues = libEPC::defaultAllowedWidgetValues();
- foreach($allowedwidgetvalues as $k => $v) {
-
+ foreach(libEPC::defaultAllowedWidgetValues() as $k => $v) {
$ns = 'content' . $v['id'];
- if ($w->$ns && is_callable($v['callback'])) {
-
+ if ($w->$ns && is_callable($v['cb'])) {
$content .= call_user_func_array(
- $v['callback'],
+ $v['cb'],
[$core, $w]
);
}
@@ -159,25 +143,12 @@ class enhancePostContentWidget
# Filter
$list = [];
- $filters = libEPC::blogFilters();
+ $filters = libEPC::getFilters();
- if (isset($filters[$w->type])
- && isset($filters[$w->type]['widgetListFilter'])
- && is_callable($filters[$w->type]['widgetListFilter'])) {
- $filters[$w->type]['nocase'] = $w->nocase;
- $filters[$w->type]['plural'] = $w->plural;
-
- if ($filters[$w->type]['has_list']) {
- $records = new epcRecords($core);
- $filters[$w->type]['list'] = $records->getRecords(
- ['epc_filter' => $w->type]
- );
- }
-
- call_user_func_array(
- $filters[$w->type]['widgetListFilter'],
- [$core, $filters[$w->type], $content, $w, &$list]
- );
+ 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)) {
diff --git a/inc/lib.epc.filter.php b/inc/lib.epc.filter.php
new file mode 100644
index 0000000..87d19cb
--- /dev/null
+++ b/inc/lib.epc.filter.php
@@ -0,0 +1,162 @@
+ 'undefined',
+ 'help' => 'undefined',
+ 'has_list' => false,
+ 'htmltag' => '',
+ 'class' => [],
+ 'replace' => '',
+ 'widget' => ''
+ ];
+ private $settings = [
+ 'nocase' => false,
+ 'plural' => false,
+ 'limit' => 0,
+ 'style' => [],
+ 'notag' => '',
+ 'tplValues' => [],
+ 'pubPages' => []
+ ];
+
+ final public function __construct(dcCore $core)
+ {
+ $this->core = $core;
+ $this->id = $this->init();
+
+ $this->blogSettings();
+ }
+
+ public static function create(arrayObject $o, dcCore $core)
+ {
+ $c = get_called_class();
+ $o->append(new $c($core));
+ }
+
+ 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];
+ foreach($properties as $k => $v) {
+ if (isset($this->properties[$k])) {
+ $this->properties[$k] = $v;
+ }
+ }
+ 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];
+ foreach($settings as $k => $v) {
+ if (isset($this->settings[$k])) {
+ $this->settings[$k] = $v;
+ }
+ }
+ return true;
+ }
+
+ private function blogSettings()
+ {
+ $ns = 'enhancePostContent_' . $this->id;
+ $opt = @unserialize($this->core->blog->settings->enhancePostContent->$ns);
+
+ if (!is_array($opt)) {
+ $opt = [];
+ }
+ if (isset($opt['nocase'])) {
+ $this->settings['nocase'] = (boolean) $opt['nocase'];
+ }
+ if (isset($opt['plural'])) {
+ $this->settings['plural'] = (boolean) $opt['plural'];
+ }
+ if (isset($opt['limit'])) {
+ $this->settings['limit'] = abs((integer) $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()
+ {
+ if ($this->records === null && $this->has_list) {
+ $records = new epcRecords($this->core);
+ $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;
+ }
+}
\ No newline at end of file
diff --git a/inc/lib.epc.filters.php b/inc/lib.epc.filters.php
new file mode 100644
index 0000000..09253bf
--- /dev/null
+++ b/inc/lib.epc.filters.php
@@ -0,0 +1,504 @@
+setProperties([
+ 'name' => __('Tag'),
+ 'help' => __('Highlight tags of your blog.'),
+ 'htmltag' => 'a',
+ 'class' => ['a.epc-tag'],
+ 'replace' => '%s',
+ 'widget' => '%s'
+ ]);
+
+ $this->setSettings([
+ 'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'],
+ 'notag' => 'a,h1,h2,h3',
+ 'tplValues' => ['EntryContent'],
+ 'pubPages' => ['post.html']
+ ]);
+
+ return 'tag';
+ }
+
+ public function publicContent($tag, $args)
+ {
+ if (!$this->core->plugins->moduleExists('tags')) {
+ return null;
+ }
+
+ $metas = $this->core->meta->getMetadata(['meta_type' => 'tag']);
+
+ while($metas->fetch()) {
+ $args[0] = libEPC::replaceString(
+ $metas->meta_id,
+ sprintf($this->replace, $this->core->blog->url . $this->core->url->getBase('tag') . '/' . $metas->meta_id, '\\1'),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+
+ public function widgetList($content, $w, &$list)
+ {
+ if (!$this->core->plugins->moduleExists('tags')) {
+ return null;
+ }
+
+ $metas = $this->core->meta->getMetadata(['meta_type' => 'tag']);
+
+ while($metas->fetch()) {
+ $list[] = libEPC::matchString(
+ $metas->meta_id,
+ sprintf($this->widget, $this->core->blog->url . $this->core->url->getBase('tag') . '/' . $metas->meta_id, '\\1'),
+ $content,
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterSearch extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ 'name' => __('Search'),
+ 'help' => __('Highlight searched words.'),
+ 'htmltag' => '',
+ 'class' => ['span.epc-search'],
+ 'replace' => '%s'
+ ]);
+
+ $this->setSettings([
+ 'nocase' => true,
+ 'plural' => true,
+ 'style' => ['color: #FFCC66;'],
+ 'notag' => 'h1,h2,h3',
+ 'tplValues' => ['EntryContent'],
+ 'pubPages' => ['search.html']
+ ]);
+
+ return 'search';
+ }
+
+ public function publicContent($tag, $args)
+ {
+ if (!isset($GLOBALS['_search'])) {
+ return null;
+ }
+
+ $searchs = explode(' ', $GLOBALS['_search']);
+
+ foreach($searchs as $k => $v) {
+ $args[0] = libEPC::replaceString(
+ $v,
+ sprintf($this->replace, '\\1'),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterAcronym extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ 'name' => __('Acronym'),
+ 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'),
+ 'has_list' => true,
+ 'htmltag' => 'acronym',
+ 'class' => ['acronym.epc-acronym'],
+ 'replace' => '%s',
+ 'widget' => '%s'
+ ]);
+
+ $this->setSettings([
+ 'style' => ['font-weight: bold;'],
+ 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
+ 'tplValues' => ['EntryContent'],
+ 'pubPages' => ['post.html']
+ ]);
+
+ return 'acronym';
+ }
+
+ public function publicContent($tag, $args)
+ {
+ while($this->records()->fetch()) {
+ $args[0] = libEPC::replaceString(
+ $this->records()->epc_key,
+ sprintf($this->replace, __($this->records()->epc_value), '\\1'),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+
+ public function widgetList($content, $w, &$list)
+ {
+ while($this->records()->fetch()) {
+ $list[] = libEPC::matchString(
+ $this->records()->epc_key,
+ sprintf($this->widget, __($this->records()->epc_value), '\\1'),
+ $content,
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterAbbreviation extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ 'name' => __('Abbreviation'),
+ 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'),
+ 'has_list' => true,
+ 'htmltag' => 'a',
+ 'class' => ['abbr.epc-abbr'],
+ 'replace' => '%s',
+ 'widget' => '%s'
+ ]);
+
+ $this->setSettings([
+ 'style' => ['font-weight: bold;'],
+ 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
+ 'tplValues' => ['EntryContent'],
+ 'pubPages' => ['post.html']
+ ]);
+
+ return 'abbreviation';
+ }
+
+ public function publicContent($tag, $args)
+ {
+ while($this->records()->fetch()) {
+ $args[0] = libEPC::replaceString(
+ $this->records()->epc_key,
+ sprintf($this->replace, __($this->records()->epc_value), '\\1'),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+
+ public function widgetList($content, $w, &$list)
+ {
+ while($this->records()->fetch()) {
+ $list[] = libEPC::matchString(
+ $this->records()->epc_key,
+ sprintf($this->widget, __($this->records()->epc_value), '\\1'),
+ $content,
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterDefinition extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ 'name' => __('Definition'),
+ 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'),
+ 'has_list' => true,
+ 'htmltag' => 'dfn',
+ 'class' => ['dfn.epc-dfn'],
+ 'replace' => '%s',
+ 'widget' => '%s'
+ ]);
+
+ $this->setSettings([
+ 'style' => ['font-weight: bold;'],
+ 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
+ 'tplValues' => ['EntryContent'],
+ 'pubPages' => ['post.html']
+ ]);
+
+ return 'definition';
+ }
+
+ public function publicContent($tag, $args)
+ {
+ while($this->records()->fetch()) {
+ $args[0] = libEPC::replaceString(
+ $this->records()->epc_key,
+ sprintf($this->replace, __($this->records()->epc_value), '\\1'),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+
+ public function widgetList($content, $w, &$list)
+ {
+ while($this->records()->fetch()) {
+ $list[] = libEPC::matchString(
+ $this->records()->epc_key,
+ sprintf($this->widget, __($this->records()->epc_value), '\\1'),
+ $content,
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterCitation extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ 'name' => __('Citation'),
+ 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'),
+ 'has_list' => true,
+ 'htmltag' => 'cite',
+ 'class' => ['cite.epc-cite'],
+ 'replace' => '%s',
+ 'widget' => '%s'
+ ]);
+
+ $this->setSettings([
+ 'nocase' => true,
+ 'style' => ['font-style: italic;'],
+ 'notag' => 'a,h1,h2,h3',
+ 'tplValues' => ['EntryContent'],
+ 'pubPages' => ['post.html']
+ ]);
+
+ return 'citation';
+ }
+
+ public function publicContent($tag, $args)
+ {
+ while($this->records()->fetch()) {
+ $args[0] = libEPC::replaceString(
+ $this->records()->epc_key,
+ sprintf($this->replace, __($this->records()->epc_value), '\\1'),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+
+ public function widgetList($content, $w, &$list)
+ {
+ while($this->records()->fetch()) {
+ $list[] = libEPC::matchString(
+ $this->records()->epc_key,
+ sprintf($this->widget, __($this->records()->epc_value), '\\1'),
+ $content,
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterLink extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ 'name' => __('Link'),
+ 'help' => __('Link some words. First term of the list is the term to link and second term the link.'),
+ 'has_list' => true,
+ 'htmltag' => 'a',
+ 'class' => ['a.epc-link'],
+ 'replace' => '%s',
+ 'widget' => '%s'
+ ]);
+
+ $this->setSettings([
+ 'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'],
+ 'notag' => 'a,h1,h2,h3',
+ 'tplValues' => ['EntryContent'],
+ 'pubPages' => ['post.html']
+ ]);
+
+ return 'link';
+ }
+
+ public function publicContent($tag, $args)
+ {
+ while($this->records()->fetch()) {
+ $args[0] = libEPC::replaceString(
+ $this->records()->epc_key,
+ sprintf($this->replace, '\\1', $this->records()->epc_value, '\\1'),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+
+ public function widgetList($content, $w, &$list)
+ {
+ while($this->records()->fetch()) {
+ $list[] = libEPC::matchString(
+ $this->records()->epc_key,
+ sprintf($this->widget, $this->records()->epc_value, $this->records()->epc_value, '\\1'),
+ $content,
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterReplace extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ 'name' => __('Replace'),
+ 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'),
+ 'has_list' => true,
+ 'htmltag' => '',
+ 'class' => ['span.epc-replace'],
+ 'replace' => '%s'
+ ]);
+
+ $this->setSettings([
+ 'nocase' => true,
+ 'plural' => true,
+ 'style' => ['font-style: italic;'],
+ 'notag' => 'h1,h2,h3',
+ 'tplValues' => ['EntryContent'],
+ 'pubPages' => ['post.html']
+ ]);
+
+ return 'replace';
+ }
+
+ public function publicContent($tag, $args)
+ {
+ while($this->records()->fetch()) {
+ $args[0] = libEPC::replaceString(
+ $this->records()->epc_key,
+ sprintf($this->replace, $this->records()->epc_value, '\\2'),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterUpdate extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ 'name' => __('Update'),
+ 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'),
+ 'has_list' => true,
+ 'htmltag' => 'del,ins',
+ 'class' => ['del.epc-update', 'ins.epc-update'],
+ 'replace' => '%s %s'
+ ]);
+
+ $this->setSettings([
+ '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($tag, $args)
+ {
+ while($this->records()->fetch()) {
+ $args[0] = libEPC::replaceString(
+ $this->records()->epc_key,
+ sprintf($this->replace, '\\1', $this->records()->epc_value),
+ $args[0],
+ $this
+ );
+ }
+
+ return null;
+ }
+}
+
+class epcFilterTwitter extends epcFilter
+{
+ protected function init(): string
+ {
+ $this->setProperties([
+ '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' => '%s'
+ ]);
+
+ $this->setSettings([
+ '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($tag, $args)
+ {
+ $args[0] = libEPC::replaceString(
+ '[A-Za-z0-9_]{2,}',
+ sprintf($this->replace, 'http://twitter.com/\\1', '\\1'),
+ $args[0],
+ $this,
+ '[^@]@',
+ '\b'
+ );
+
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/inc/lib.epc.pager.php b/inc/lib.epc.pager.php
index aa06d6f..d15eb3e 100644
--- a/inc/lib.epc.pager.php
+++ b/inc/lib.epc.pager.php
@@ -1,4 +1,15 @@
'EntryExcerpt',
- 'entry content' => 'EntryContent',
+ $rs = new arrayObject([
+ 'entry excerpt' => 'EntryExcerpt',
+ 'entry content' => 'EntryContent',
'comment content' => 'CommentContent',
- ];
+ ]);
+
+ $core->callBehavior('enhancePostContentAllowedTplValues', $rs);
+
+ return iterator_to_array($rs, true);
}
public static function blogAllowedTplValues()
{
global $core;
+
$core->blog->settings->addNamespace('enhancePostContent');
- $allowedtplvalues = self::defaultAllowedTplValues();
$rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedtplvalues);
- return is_array($rs) ? $rs : $allowedtplvalues;
+
+ return is_array($rs) ? $rs : self::defaultAllowedTplValues();
}
public static function defaultAllowedWidgetValues()
{
global $core;
- $rs = [
+ $rs = new arrayObject([
'entry excerpt' => [
'id' => 'entryexcerpt',
- 'callback' => ['libEPC','widgetContentEntryExcerpt']
+ 'cb' => ['libEPC','widgetContentEntryExcerpt']
],
'entry content' => [
'id' => 'entrycontent',
- 'callback' => ['libEPC','widgetContentEntryContent']
+ 'cb' => ['libEPC','widgetContentEntryContent']
],
'comment content' => [
'id' => 'commentcontent',
- 'callback' => ['libEPC','widgetContentCommentContent']
+ 'cb' => ['libEPC','widgetContentCommentContent']
]
- ];
+ ]);
$core->callBehavior('enhancePostContentAllowedWidgetValues', $rs);
- return $rs;
+ return iterator_to_array($rs, true);
}
public static function defaultAllowedPubPages()
{
- return [
- 'home page' => 'home.html',
- 'post page' => 'post.html',
- 'category page' => 'category.html',
+ $rs = new arrayObject([
+ 'home page' => 'home.html',
+ 'post page' => 'post.html',
+ 'category page' => 'category.html',
'search results page' => 'search.html',
- 'atom feeds' => 'atom.xml',
- 'RSS feeds' => 'rss2.xml'
- ];
+ 'atom feeds' => 'atom.xml',
+ 'RSS feeds' => 'rss2.xml'
+ ]);
+
+ $core->callBehavior('enhancePostContentAllowedPubPages', $rs);
+
+ return iterator_to_array($rs, true);
}
public static function blogAllowedPubPages()
{
global $core;
+
$core->blog->settings->addNamespace('enhancePostContent');
- $allowedpubpages = self::defaultAllowedPubPages();
$rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedpubpages);
- return is_array($rs) ? $rs : $allowedpubpages;
+
+ return is_array($rs) ? $rs : self::defaultAllowedPubPages();
}
- public static function defaultFilters()
+ public static function getFilters()
{
global $core;
- $filters = [
- 'Tag' => [
- 'id' => 'tag',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterTag'],
- 'widgetListFilter' => ['libEPC', 'widgetListTag'],
+ if (self::$default_filters === null) {
+ $final = [];
+ $filters = new arrayObject();
- 'help' => __('Highlight tags of your blog.'),
- 'has_list' => false,
- 'htmltag' => 'a',
- 'class' => ['a.epc-tag'],
- 'replace' => '%s',
- 'widget' => '%s',
+ try {
+ $core->callBehavior('enhancePostContentFilters', $filters, $core);
- 'nocase' => false,
- 'plural' => false,
- 'limit' => 0,
- 'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'],
- 'notag' => 'a,h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html']
- ],
- 'Search' => [
- 'id' => 'search',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterSearch'],
-
- 'help' => __('Highlight searched words.'),
- 'has_list' => false,
- 'htmltag' => '',
- 'class' => ['span.epc-search'],
- 'replace' => '%s',
-
- 'nocase' => true,
- 'plural' => true,
- 'limit' => 0,
- 'style' => ['color: #FFCC66;'],
- 'notag' => 'h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['search.html']
- ],
- 'Acronym' => [
- 'id' => 'acronym',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterAcronym'],
- 'widgetListFilter' => ['libEPC', 'widgetListAcronym'],
-
- 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'),
- 'has_list' => true,
- 'htmltag' => 'acronym',
- 'class' => ['acronym.epc-acronym'],
- 'replace' => '%s',
- 'widget' => '%s',
-
- 'nocase' => false,
- 'plural' => false,
- 'limit' => 0,
- 'style' => ['font-weight: bold;'],
- 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html'],
- ],
- 'Abbreviation' => [
- 'id' => 'abbreviation',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterAbbreviation'],
- 'widgetListFilter' => ['libEPC', 'widgetListAbbreviation'],
-
- 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'),
- 'has_list' => true,
- 'htmltag' => 'a',
- 'class' => ['abbr.epc-abbr'],
- 'replace' => '%s',
- 'widget' => '%s',
-
- 'nocase' => false,
- 'plural' => false,
- 'limit' => 0,
- 'style' => ['font-weight: bold;'],
- 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html'],
- ],
- 'Definition' => [
- 'id' => 'definition',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterDefinition'],
- 'widgetListFilter' => ['libEPC', 'widgetListDefinition'],
-
- 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'),
- 'has_list' => true,
- 'htmltag' => 'dfn',
- 'class' => ['dfn.epc-dfn'],
- 'replace' => '%s',
- 'widget' => '%s',
-
- 'nocase' => false,
- 'plural' => false,
- 'limit' => 0,
- 'style' => ['font-weight: bold;'],
- 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html'],
- ],
- 'Citation' => [
- 'id' => 'citation',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterCitation'],
- 'widgetListFilter' => ['libEPC', 'widgetListCitation'],
-
- 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'),
- 'has_list' => true,
- 'htmltag' => 'cite',
- 'class' => ['cite.epc-cite'],
- 'replace' => '%s',
- 'widget' => '%s',
-
- 'nocase' => true,
- 'plural' => false,
- 'limit' => 0,
- 'style' => ['font-style: italic;'],
- 'notag' => 'a,h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html'],
- ],
- 'Link' => [
- 'id' => 'link',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterLink'],
- 'widgetListFilter' => ['libEPC', 'widgetListLink'],
-
- 'help' => __('Link some words. First term of the list is the term to link and second term the link.'),
- 'has_list' => true,
- 'htmltag' => 'a',
- 'class' => ['a.epc-link'],
- 'replace' => '%s',
- 'widget' => '%s',
-
- 'nocase' => false,
- 'plural' => false,
- 'limit' => 0,
- 'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'],
- 'notag' => 'a,h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html'],
- ],
- 'Replace' => [
- 'id' => 'replace',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterReplace'],
-
- 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'),
- 'has_list' => true,
- 'htmltag' => '',
- 'class' => ['span.epc-replace'],
- 'replace' => '%s',
-
- 'nocase' => true,
- 'plural' => true,
- 'limit' => 0,
- 'style' => ['font-style: italic;'],
- 'notag' => 'h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html'],
- ],
- 'Update' => [
- 'id' => 'update',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterUpdate'],
-
- 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'),
- 'has_list' => true,
- 'htmltag' => 'del,ins',
- 'class' => ['del.epc-update', 'ins.epc-update'],
- 'replace' => '%s %s',
-
- 'nocase' => true,
- 'plural' => true,
- 'limit' => 0,
- 'style' => ['text-decoration: line-through;', 'font-style: italic;'],
- 'notag' => 'h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html'],
- ],
- 'Twitter' => [
- 'id' => 'twitter',
- 'publicContentFilter' => ['libEPC', 'publicContentFilterTwitter'],
-
- 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'),
- 'has_list' => false,
- 'htmltag' => 'a',
- 'class' => ['a.epc-twitter'],
- 'replace' => '%s',
-
- 'nocase' => false,
- 'plural' => false,
- 'limit' => 0,
- 'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'],
- 'notag' => 'a,h1,h2,h3',
- 'tplValues' => ['EntryContent'],
- 'pubPages' => ['post.html']
- ]
- ];
-
- $core->callBehavior('enhancePostContentDefaultFilters', $filters);
-
- return $filters;
- }
-
- public static function blogFilters($one = null)
- {
- global $core;
- $core->blog->settings->addNamespace('enhancePostContent');
- $filters = self::defaultFilters();
-
- foreach($filters as $name => $filter) {
- # Parse filters options
- $ns = 'enhancePostContent_' . $name;
- $opt[$name] = @unserialize($core->blog->settings->enhancePostContent->$ns);
-
- if (!is_array($opt[$name])) {
- $opt[$name] = [];
+ foreach($filters as $filter) {
+ if ($filter instanceOf epcFilter && !isset($final[$filter->id()])) {
+ $final[$filter->id()] = $filter;
+ }
+ }
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
}
- if (isset($opt[$name]['nocase'])) {
- $filters[$name]['nocase'] = (boolean) $opt[$name]['nocase'];
- }
- if (isset($opt[$name]['plural'])) {
- $filters[$name]['plural'] = (boolean) $opt[$name]['plural'];
- }
- if (isset($opt[$name]['limit'])) {
- $filters[$name]['limit'] = abs((integer) $opt[$name]['limit']);
- }
- if (isset($opt[$name]['style']) && is_array($opt[$name]['style'])) {
- $filters[$name]['style'] = (array) $opt[$name]['style'];
- }
- if (isset($opt[$name]['notag'])) {
- $filters[$name]['notag'] = (string) $opt[$name]['notag'];
- }
- if (isset($opt[$name]['tplValues'])) {
- $filters[$name]['tplValues'] = (array) $opt[$name]['tplValues'];
- }
- if (isset($opt[$name]['pubPages'])) {
- $filters[$name]['pubPages'] = (array) $opt[$name]['pubPages'];
- }
- $filters[$name]['name'] = $name;
+ self::$default_filters = $final;
}
- $core->callBehavior('enhancePostContentBlogFilters', $filters);
-
- return $filters;
+ return self::$default_filters;
}
- public static function testContext($tag, $args, $opt)
+ public static function testContext($tag, $args, $filter)
{
- return
- isset($opt['pubPages'])
- && is_array($opt['pubPages'])
- && in_array($GLOBALS['_ctx']->current_tpl,$opt['pubPages'])
- && isset($opt['tplValues'])
- && is_array($opt['tplValues'])
- && in_array($tag, $opt['tplValues'])
- && $args[0] != '' //content
- && empty($args[2]) // remove html
+ return is_array($filter->pubPages)
+ && in_array($GLOBALS['_ctx']->current_tpl,$filter->pubPages)
+ && is_array($filter->tplValues)
+ && in_array($tag, $filter->tplValues)
+ && $args[0] != '' //content
+ && empty($args[2]) // remove html
;
}
public static function replaceString($p, $r, $s, $filter, $before = '\b', $after = '\b')
{
# Limit
- if ($filter['limit'] > 0) {
- $limit = in_array($filter['id'] . '_' . $p, self::$epcFilterLimit) ? self::$epcFilterLimit[$filter['id'] . '_' . $p] : $filter['limit'];
+ if ($filter->limit > 0) {
+ $limit = in_array($filter->id() . '_' . $p, self::$epcFilterLimit) ? self::$epcFilterLimit[$filter->id() . '_' . $p] : $filter->limit;
if ($limit < 1) {
return $s;
}
@@ -362,9 +146,9 @@ class libEPC
$limit = -1;
}
# Case sensitive
- $i = $filter['nocase'] ? 'i' : '';
+ $i = $filter->nocase ? 'i' : '';
# Plural
- $x = $filter['plural'] ? $p . 's|' . $p : $p;
+ $x = $filter->plural ? $p . 's|' . $p : $p;
# Mark words
$s = preg_replace('#(' . $before . ')(' . $x . ')(' . $after . ')#su' . $i, '$1ççççç$2ççççç$3', $s, -1, $count);
# Nothing to parse
@@ -373,7 +157,7 @@ class libEPC
}
# Remove words that are into unwanted html tags
$tags = '';
- $ignore_tags = array_merge(self::decodeTags($filter['htmltag']), self::decodeTags($filter['notag']));
+ $ignore_tags = array_merge(self::decodeTags($filter->htmltag), self::decodeTags($filter->notag));
if (is_array($ignore_tags) && !empty($ignore_tags)) {
$tags = implode('|', $ignore_tags);
}
@@ -385,7 +169,7 @@ class libEPC
# Replace words by what you want (with limit)
$s = preg_replace('#ççççç(' . $p . '(s|))ççççç#s' . $i, $r, $s, $limit, $count);
# update limit
- self::$epcFilterLimit[$filter['id'] . '_' . $p] = $limit - $count;
+ self::$epcFilterLimit[$filter->id() . '_' . $p] = $limit - $count;
# Clean rest
return $s = preg_replace('#ççççç(.*?)ççççç#s', '$1', $s);
}
@@ -393,11 +177,11 @@ class libEPC
public static function matchString($p, $r, $s, $filter, $before = '\b', $after = '\b')
{
# Case sensitive
- $i = $filter['nocase'] ? 'i' : '';
+ $i = $filter->nocase ? 'i' : '';
# Plural
- $x = $filter['plural'] ? $p . 's|' . $p : $p;
+ $x = $filter->plural ? $p . 's|' . $p : $p;
# Mark words
- $t = preg_match_all('#' . $before . '(' . $x . ')' . $after . '#s' . $i, $s, $matches);
+ $t = preg_match_all('#' . $before . '(' . $x . ')' . $after . '#su' . $i, $s, $matches);
# Nothing to parse
if (!$t) {
return ['total' => 0, 'matches' => []];
@@ -487,36 +271,41 @@ class libEPC
public static function widgetContentEntryExcerpt($core, $w)
{
global $_ctx;
+
if (!$_ctx->exists('posts')) {
- return;
+ return null;
}
$res = '';
while ($_ctx->posts->fetch()) {
$res .= $_ctx->posts->post_excerpt;
}
+
return $res;
}
public static function widgetContentEntryContent()
{
global $_ctx;
+
if (!$_ctx->exists('posts')) {
- return;
+ return null;
}
$res = '';
while ($_ctx->posts->fetch()) {
$res .= $_ctx->posts->post_content;
}
+
return $res;
}
public static function widgetContentCommentContent()
{
global $core, $_ctx;
+
if (!$_ctx->exists('posts')) {
- return;
+ return null;
}
$res = '';
@@ -527,274 +316,7 @@ class libEPC
$res .= $comments->getContent();
}
}
+
return $res;
}
-
- #
- # Filters
- #
-
- public static function publicContentFilterTag($core, $filter, $tag, $args)
- {
- if (!$core->plugins->moduleExists('tags')) {
- return;
- }
-
- $metas = $core->meta->getMetadata(['meta_type' => 'tag']);
-
- while($metas->fetch()) {
- $k = $metas->meta_id;
- $args[0] = self::replaceString(
- $k,
- sprintf($filter['replace'], $core->blog->url . $core->url->getBase('tag') . '/' . $k, '\\1'),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function widgetListTag($core, $filter, $content, $w, &$list)
- {
- if (!$core->plugins->moduleExists('tags')) {
- return;
- }
-
- $metas = $core->meta->getMetadata(['meta_type' => 'tag']);
-
- while($metas->fetch()) {
- $k = $metas->meta_id;
- $list[] = self::matchString(
- $k,
- sprintf($filter['widget'], $core->blog->url . $core->url->getBase('tag') . '/' . $k, '\\1'),
- $content,
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterSearch($core, $filter, $tag, $args)
- {
- if (!isset($GLOBALS['_search'])) {
- return;
- }
-
- $searchs = explode(' ', $GLOBALS['_search']);
-
- foreach($searchs as $k => $v) {
- $args[0] = self::replaceString(
- $v,
- sprintf($filter['replace'], '\\1'),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterAcronym($core, $filter, $tag, $args)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $args[0] = self::replaceString(
- $k,
- sprintf($filter['replace'], __($v), '\\1'),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function widgetListAcronym($core, $filter, $content, $w, &$list)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $list[] = self::matchString(
- $k,
- sprintf($filter['widget'], __($v), '\\1'),
- $content,
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterAbbreviation($core, $filter, $tag, $args)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $args[0] = self::replaceString(
- $k,
- sprintf($filter['replace'], __($v), '\\1'),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function widgetListAbbreviation($core, $filter, $content, $w, &$list)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $list[] = self::matchString(
- $k,
- sprintf($filter['widget'], __($v), '\\1'),
- $content,
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterDefinition($core, $filter, $tag, $args)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $args[0] = self::replaceString(
- $k,
- sprintf($filter['replace'], __($v), '\\1'),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function widgetListDefinition($core, $filter, $content, $w, &$list)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $list[] = self::matchString(
- $k,
- sprintf($filter['widget'], __($v), '\\1'),
- $content,
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterCitation($core, $filter, $tag, $args)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $args[0] = self::replaceString(
- $k,
- sprintf($filter['replace'], __($v), '\\1'),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function widgetListCitation($core, $filter, $content, $w, &$list)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $list[] = self::matchString(
- $k,
- sprintf($filter['widget'], __($v), '\\1'),
- $content,
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterLink($core, $filter, $tag, $args)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $args[0] = self::replaceString(
- $k,
- sprintf($filter['replace'], '\\1', $v, '\\1'),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function widgetListLink($core, $filter, $content, $w, &$list)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $list[] = self::matchString(
- $k,
- sprintf($filter['widget'], $v, $v, '\\1'),
- $content,
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterReplace($core, $filter, $tag, $args)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $args[0] = self::replaceString(
- $k,
- sprintf($filter['replace'], $v, '\\2'),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterUpdate($core, $filter, $tag, $args)
- {
- while($filter['list']->fetch()) {
- $k = $filter['list']->epc_key;
- $v = $filter['list']->epc_value;
-
- $args[0] = self::replaceString(
- $k,
- sprintf($filter['replace'], '\\1', $v),
- $args[0],
- $filter
- );
- }
- return;
- }
-
- public static function publicContentFilterTwitter($core, $filter, $tag, $args)
- {
- $args[0] = self::replaceString(
- '[A-Za-z0-9_]{2,}',
- sprintf($filter['replace'], 'http://twitter.com/\\1', '\\1'),
- $args[0],
- $filter,
- '[^@]@',
- '\b'
- );
- return;
- }
}
\ No newline at end of file
diff --git a/inc/lib.epc.update.php b/inc/lib.epc.update.php
index 5188973..6c69439 100644
--- a/inc/lib.epc.update.php
+++ b/inc/lib.epc.update.php
@@ -11,28 +11,41 @@
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
-# This file only update old filters lists from settings to database
+# Move old filters lists from settings to database
+if ($old_version && version_compare('0.6.6', $old_version, '>=')) {
+ $f = $core->con->select("SELECT * FROM " . $core->prefix . "setting WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL ");
-$f = $core->con->select("SELECT * FROM " . $core->prefix . "setting WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL ");
+ while ($f->fetch()) {
+ if (preg_match('#enhancePostContent_(.*?)List#', $f->setting_id, $m)) {
+ $curlist = @unserialize($f->setting_value);
+ if (is_array($curlist)) {
+ foreach($curlist as $k => $v) {
+ $cur = $core->con->openCursor($core->prefix . 'epc');
+ $core->con->writeLock($core->prefix . 'epc');
-while ($f->fetch()) {
- if (preg_match('#enhancePostContent_(.*?)List#', $f->setting_id, $m)) {
- $curlist = @unserialize($f->setting_value);
- if (is_array($curlist)) {
- foreach($curlist as $k => $v) {
- $cur = $core->con->openCursor($core->prefix . 'epc');
- $core->con->writeLock($core->prefix . 'epc');
+ $cur->epc_id = $core->con->select('SELECT MAX(epc_id) FROM ' . $core->prefix . 'epc' . ' ')->f(0) + 1;
+ $cur->blog_id = $f->blog_id;
+ $cur->epc_filter = strtolower($m[1]);
+ $cur->epc_key = $k;
+ $cur->epc_value = $v;
- $cur->epc_id = $core->con->select('SELECT MAX(epc_id) FROM ' . $core->prefix . 'epc' . ' ')->f(0) + 1;
- $cur->blog_id = $f->blog_id;
- $cur->epc_filter = $m[1];
- $cur->epc_key = $k;
- $cur->epc_value = $v;
-
- $cur->insert();
- $core->con->unlock();
+ $cur->insert();
+ $core->con->unlock();
+ }
}
+ $core->con->execute("DELETE FROM " . $core->prefix . "setting WHERE setting_id='" . $f->setting_id . "' AND setting_ns='enhancePostContent' AND blog_id='" . $f->blog_id . "' ");
}
- $core->con->execute("DELETE FROM " . $core->prefix . "setting WHERE setting_id='" . $f->setting_id . "' AND setting_ns='enhancePostContent' AND blog_id='" . $f->blog_id . "' ");
+ }
+
+# Move old filter name to filter id
+} elseif ($old_version && version_compare('2021.10.05', $old_version, '>=')) {
+ $rs = $core->con->select('SELECT epc_id, epc_filter FROM ' . $core->prefix . 'epc');
+ while($rs->fetch()) {
+ $cur = $core->con->openCursor($core->prefix . 'epc');
+
+ $cur->epc_filter = strtolower($rs->epc_filter);
+
+ $cur->update("WHERE epc_id = " . $rs->epc_id . " ");
+ $core->blog->triggerBlog();
}
}
\ No newline at end of file
diff --git a/index.php b/index.php
index d734a16..c604f0a 100644
--- a/index.php
+++ b/index.php
@@ -17,15 +17,14 @@ if (!defined('DC_CONTEXT_ADMIN')) {
dcPage::check('contentadmin');
-
# -- Prepare queries and object --
-$_filters = libEPC::blogFilters();
+$_filters = libEPC::getFilters();
$filters_id = $filters_combo = [];
-foreach($_filters as $name => $filter) {
- $filters_id[$filter['id']] = $name;
- $filters_combo[__($name)] = $filter['id'];
+foreach($_filters as $id => $filter) {
+ $filters_id[$id] = $filter->name;
+ $filters_combo[$filter->name] = $id;
}
$action = $_POST['action'] ?? '';
@@ -36,7 +35,7 @@ if (!isset($filters_id[$part])) {
}
$header = '';
-$filter = $_filters[$filters_id[$part]];
+$filter = $_filters[$part];
$records = new epcRecords($core);
# -- Action --
@@ -61,7 +60,7 @@ try {
];
$core->blog->settings->addNamespace('enhancePostContent');
- $core->blog->settings->enhancePostContent->put('enhancePostContent_' . $filter['name'], serialize($f));
+ $core->blog->settings->enhancePostContent->put('enhancePostContent_' . $filter->id(), serialize($f));
$core->blog->triggerBlog();
@@ -82,7 +81,7 @@ try {
&& !empty($_POST['new_value'])
) {
$cur = $records->openCursor();
- $cur->epc_filter = $filter['name'];
+ $cur->epc_filter = $filter->id();
$cur->epc_key = html::escapeHTML($_POST['new_key']);
$cur->epc_value = html::escapeHTML($_POST['new_value']);
@@ -105,7 +104,7 @@ try {
}
# Update filter records
- if ($action == 'deleterecords' && $filter['has_list']
+ if ($action == 'deleterecords' && $filter->has_list
&& !empty($_POST['epc_id']) && is_array($_POST['epc_id'])
) {
foreach($_POST['epc_id'] as $id) {
@@ -134,13 +133,13 @@ try {
# -- Prepare page --
-if ($filter['has_list']) {
+if ($filter->has_list) {
$sorts = new adminGenericFilter($core, 'epc');
$sorts->add(dcAdminFilters::getPageFilter());
$sorts->add('part', $part);
$params = $sorts->params();
- $params['epc_filter'] = $filter['name'];
+ $params['epc_filter'] = $filter->id();
try {
$list = $records->getRecords($params);
@@ -159,8 +158,6 @@ if ($filter['has_list']) {
# Page headers
echo '
' . $filter['help'] . '
'; +' . $filter->help . '
'; # Filter settings echo ' @@ -205,7 +202,7 @@ foreach(libEPC::blogAllowedPubPages() as $k => $v) { form::checkbox( ['filter_pubPages[]', 'filter_pubPages' . $v], $v, - in_array($v, $filter['pubPages']) + in_array($v, $filter->pubPages) ) . __($k) . ''; } @@ -215,16 +212,16 @@ echo '' . -form::number('filter_limit', ['min' => 0, 'max' => 99, 'default' => (integer) $filter['limit']]) . ' +form::number('filter_limit', ['min' => 0, 'max' => 99, 'default' => (integer) $filter->limit]) . '
' . __('Leave it blank or set it to 0 for no limit') . '
@@ -237,7 +234,7 @@ foreach(libEPC::blogAllowedTplValues() as $k => $v) { form::checkbox( ['filter_tplValues[]', 'filter_tplValues' . $v], $v, - in_array($v, $filter['tplValues']) + in_array($v, $filter->tplValues) ) . __($k) . ''; } @@ -246,7 +243,7 @@ echo '' . @@ -254,19 +251,19 @@ foreach($filter['class'] as $k => $v) { ['filter_style[]', 'filter_style'.$k], 60, 255, - html::escapeHTML($filter['style'][$k]) + html::escapeHTML($filter->style[$k]) ) . '
'; } echo ' -' . sprintf(__('The inserted HTML tag looks like: %s'), html::escapeHTML(str_replace('%s', '...', $filter['replace']))) . '
+' . sprintf(__('The inserted HTML tag looks like: %s'), html::escapeHTML(str_replace('%s', '...', $filter->replace))) . '
' . -form::field('filter_notag', 60, 255, html::escapeHTML($filter['notag'])) . ' +form::field('filter_notag', 60, 255, html::escapeHTML($filter->notag)) . '
' . __('This is the list of HTML tags where content will be ignored.') . ' ' . -(empty($filter['htmltag']) ? '' : sprintf(__('Tag "%s" always be ignored.'), $filter['htmltag'])) . '
+('' != $filter->htmltag ? '' : sprintf(__('Tag "%s" always be ignored.'), $filter->htmltag)) . '' . @@ -281,7 +278,7 @@ form::hidden(['part'], $part) . '