From 1b1d6fb40fc82400774519d2641d9323725566c8 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Wed, 21 Dec 2022 22:27:20 +0100 Subject: [PATCH] code review --- _admin.php | 8 +- _install.php | 5 +- _prepend.php | 8 +- _public.php | 2 +- _widgets.php | 2 +- inc/class.adminepclist.php | 6 +- inc/class.enhancepostcontent.php | 8 +- inc/class.epcfilter.php | 2 +- inc/class.epcfilterabbreviation.php | 127 +++++++++++++----------- inc/class.epcfilteracronym.php | 127 +++++++++++++----------- inc/class.epcfiltercitation.php | 129 +++++++++++++----------- inc/class.epcfilterdefinition.php | 127 +++++++++++++----------- inc/class.epcfilterlink.php | 127 +++++++++++++----------- inc/class.epcfilterreplace.php | 101 ++++++++++--------- inc/class.epcfiltersearch.php | 111 +++++++++++---------- inc/class.epcfiltertag.php | 149 +++++++++++++++------------- inc/class.epcfiltertwitter.php | 95 ++++++++++-------- inc/class.epcfilterupdate.php | 101 ++++++++++--------- inc/class.epcupgrade.php | 24 ++--- index.php | 4 +- 20 files changed, 684 insertions(+), 579 deletions(-) diff --git a/_admin.php b/_admin.php index 5b03eb3..1dadfcb 100644 --- a/_admin.php +++ b/_admin.php @@ -40,7 +40,7 @@ dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $f # Preference form dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings) { - $active = (bool) $blog_settings->__get(basename(__DIR__))->active; + $active = (bool) $blog_settings->get(basename(__DIR__))->get('active'); $allowedtplvalues = enhancePostContent::blogAllowedTplValues(); $allowedpubpages = enhancePostContent::blogAllowedPubPages(); @@ -78,9 +78,9 @@ dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings $allowedtplvalues = enhancePostContent::explode($_POST['epc_allowedtplvalues']); $allowedpubpages = enhancePostContent::explode($_POST['epc_allowedpubpages']); - $blog_settings->__get(basename(__DIR__))->put('active', $active); - $blog_settings->__get(basename(__DIR__))->put('allowedtplvalues', json_encode($allowedtplvalues)); - $blog_settings->__get(basename(__DIR__))->put('allowedpubpages', json_encode($allowedpubpages)); + $blog_settings->get(basename(__DIR__))->put('active', $active); + $blog_settings->get(basename(__DIR__))->put('allowedtplvalues', json_encode($allowedtplvalues)); + $blog_settings->get(basename(__DIR__))->put('allowedpubpages', json_encode($allowedpubpages)); }); # List filter diff --git a/_install.php b/_install.php index b645958..1d2ff1a 100644 --- a/_install.php +++ b/_install.php @@ -17,7 +17,7 @@ if (!defined('DC_CONTEXT_ADMIN')) { try { // Version if (!dcCore::app()->newVersion( - basename(__DIR__), + basename(__DIR__), dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') )) { return null; @@ -48,8 +48,7 @@ try { epcUpgrade::growUp(); // Settings - dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); - $s = dcCore::app()->blog->settings->__get(basename(__DIR__)); + $s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); $s->put('active', false, 'boolean', 'Enable enhancePostContent', false, true); $s->put('list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true); diff --git a/_prepend.php b/_prepend.php index e6cfca4..a558dd6 100644 --- a/_prepend.php +++ b/_prepend.php @@ -31,10 +31,10 @@ $d = __DIR__ . '/inc/'; Clearbricks::lib()->autoload([ 'enhancePostContent' => $d . 'class.enhancepostcontent.php', - 'epcFilter' => $d . 'class.epcfilter.php', - 'epcRecords' => $d . 'class.epcrecords.php', - 'epcUpgrade' => $d . 'class.epcupgrade.php', - 'adminEpcList' => $d . 'class.adminepclist.php', + 'epcFilter' => $d . 'class.epcfilter.php', + 'epcRecords' => $d . 'class.epcrecords.php', + 'epcUpgrade' => $d . 'class.epcupgrade.php', + 'adminEpcList' => $d . 'class.adminepclist.php', ]); foreach ($filters as $f) { diff --git a/_public.php b/_public.php index 4f6f5f0..d9c54cb 100644 --- a/_public.php +++ b/_public.php @@ -18,7 +18,7 @@ require __DIR__ . '/_widgets.php'; dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); -if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active) { +if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { return null; } diff --git a/_widgets.php b/_widgets.php index ef4e5b6..f86617a 100644 --- a/_widgets.php +++ b/_widgets.php @@ -114,7 +114,7 @@ class enhancePostContentWidget dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); # Page - if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active') || !in_array(dcCore::app()->ctx->current_tpl, ['post.html', 'page.html']) ) { return null; diff --git a/inc/class.adminepclist.php b/inc/class.adminepclist.php index 1abb2db..dae547e 100644 --- a/inc/class.adminepclist.php +++ b/inc/class.adminepclist.php @@ -24,11 +24,7 @@ class adminEpcList extends adminGenericList public function display($filter, $pager_url, $enclose_block = '') { if ($this->rs->isEmpty()) { - if ($filter->show()) { - echo '

' . __('No record matches the filter') . '

'; - } else { - echo '

' . __('No record') . '

'; - } + echo '

' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '

'; } else { $pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10); $pager->base_url = $pager_url; diff --git a/inc/class.enhancepostcontent.php b/inc/class.enhancepostcontent.php index 38f1cc5..d915869 100644 --- a/inc/class.enhancepostcontent.php +++ b/inc/class.enhancepostcontent.php @@ -46,7 +46,7 @@ class enhancePostContent public static function blogAllowedTplValues() { dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__))); - $rs = json_decode(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->allowedtplvalues); + $rs = json_decode(dcCore::app()->blog->settings->get(basename(dirname('../' . __DIR__)))->get('allowedtplvalues')); return is_array($rs) ? $rs : self::defaultAllowedTplValues(); } @@ -54,11 +54,11 @@ class enhancePostContent public static function defaultAllowedWidgetValues() { $rs = new arrayObject([ - 'entry excerpt' => [ + 'entry excerpt' => [ 'id' => 'entryexcerpt', 'cb' => ['enhancePostContent','widgetContentEntryExcerpt'], ], - 'entry content' => [ + 'entry content' => [ 'id' => 'entrycontent', 'cb' => ['enhancePostContent','widgetContentEntryContent'], ], @@ -92,7 +92,7 @@ class enhancePostContent public static function blogAllowedPubPages() { dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__))); - $rs = json_decode(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->allowedpubpages); + $rs = json_decode(dcCore::app()->blog->settings->get(basename(dirname('../' . __DIR__)))->get('allowedpubpages')); return is_array($rs) ? $rs : self::defaultAllowedPubPages(); } diff --git a/inc/class.epcfilter.php b/inc/class.epcfilter.php index 086d0a9..805597a 100644 --- a/inc/class.epcfilter.php +++ b/inc/class.epcfilter.php @@ -108,7 +108,7 @@ abstract class epcFilter private function blogSettings() { - $opt = json_decode((string) dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->__get($this->id)); + $opt = json_decode((string) dcCore::app()->blog->settings->get(basename(dirname('../' . __DIR__)))->get($this->id)); if (empty($opt)) { $opt = []; diff --git a/inc/class.epcfilterabbreviation.php b/inc/class.epcfilterabbreviation.php index fb82cf5..2b47df1 100644 --- a/inc/class.epcfilterabbreviation.php +++ b/inc/class.epcfilterabbreviation.php @@ -1,58 +1,69 @@ -setProperties([ - 'priority' => 400, - '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] = enhancePostContent::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[] = enhancePostContent::matchString( - $this->records()->epc_key, - sprintf($this->widget, __($this->records()->epc_value), '\\1'), - $content, - $this - ); - } - - return null; - } -} +setProperties([ + 'priority' => 400, + '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] = enhancePostContent::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[] = enhancePostContent::matchString( + $this->records()->epc_key, + sprintf($this->widget, __($this->records()->epc_value), '\\1'), + $content, + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcfilteracronym.php b/inc/class.epcfilteracronym.php index da0d964..d3cfc53 100644 --- a/inc/class.epcfilteracronym.php +++ b/inc/class.epcfilteracronym.php @@ -1,58 +1,69 @@ -setProperties([ - 'priority' => 700, - '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] = enhancePostContent::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[] = enhancePostContent::matchString( - $this->records()->epc_key, - sprintf($this->widget, __($this->records()->epc_value), '\\1'), - $content, - $this - ); - } - - return null; - } -} +setProperties([ + 'priority' => 700, + '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] = enhancePostContent::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[] = enhancePostContent::matchString( + $this->records()->epc_key, + sprintf($this->widget, __($this->records()->epc_value), '\\1'), + $content, + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcfiltercitation.php b/inc/class.epcfiltercitation.php index 0d66902..7a75bc3 100644 --- a/inc/class.epcfiltercitation.php +++ b/inc/class.epcfiltercitation.php @@ -1,59 +1,70 @@ -setProperties([ - 'priority' => 600, - '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] = enhancePostContent::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[] = enhancePostContent::matchString( - $this->records()->epc_key, - sprintf($this->widget, __($this->records()->epc_value), '\\1'), - $content, - $this - ); - } - - return null; - } -} +setProperties([ + 'priority' => 600, + '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] = enhancePostContent::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[] = enhancePostContent::matchString( + $this->records()->epc_key, + sprintf($this->widget, __($this->records()->epc_value), '\\1'), + $content, + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcfilterdefinition.php b/inc/class.epcfilterdefinition.php index 6aaed71..39684fa 100644 --- a/inc/class.epcfilterdefinition.php +++ b/inc/class.epcfilterdefinition.php @@ -1,58 +1,69 @@ -setProperties([ - 'priority' => 800, - '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] = enhancePostContent::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[] = enhancePostContent::matchString( - $this->records()->epc_key, - sprintf($this->widget, __($this->records()->epc_value), '\\1'), - $content, - $this - ); - } - - return null; - } -} +setProperties([ + 'priority' => 800, + '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] = enhancePostContent::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[] = enhancePostContent::matchString( + $this->records()->epc_key, + sprintf($this->widget, __($this->records()->epc_value), '\\1'), + $content, + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcfilterlink.php b/inc/class.epcfilterlink.php index fc4146a..bc570be 100644 --- a/inc/class.epcfilterlink.php +++ b/inc/class.epcfilterlink.php @@ -1,58 +1,69 @@ -setProperties([ - 'priority' => 500, - '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] = enhancePostContent::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[] = enhancePostContent::matchString( - $this->records()->epc_key, - sprintf($this->widget, $this->records()->epc_value, $this->records()->epc_value, '\\1'), - $content, - $this - ); - } - - return null; - } -} +setProperties([ + 'priority' => 500, + '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] = enhancePostContent::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[] = enhancePostContent::matchString( + $this->records()->epc_key, + sprintf($this->widget, $this->records()->epc_value, $this->records()->epc_value, '\\1'), + $content, + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcfilterreplace.php b/inc/class.epcfilterreplace.php index 527aaea..11e049f 100644 --- a/inc/class.epcfilterreplace.php +++ b/inc/class.epcfilterreplace.php @@ -1,45 +1,56 @@ -setProperties([ - 'priority' => 200, - '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] = enhancePostContent::replaceString( - $this->records()->epc_key, - sprintf($this->replace, $this->records()->epc_value, '\\2'), - $args[0], - $this - ); - } - - return null; - } -} +setProperties([ + 'priority' => 200, + '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] = enhancePostContent::replaceString( + $this->records()->epc_key, + sprintf($this->replace, $this->records()->epc_value, '\\2'), + $args[0], + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcfiltersearch.php b/inc/class.epcfiltersearch.php index 3a9cbee..c5dd2d8 100644 --- a/inc/class.epcfiltersearch.php +++ b/inc/class.epcfiltersearch.php @@ -1,50 +1,61 @@ -setProperties([ - 'priority' => 100, - '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 (empty(dcCore::app()->public->search)) { - return null; - } - - $searchs = explode(' ', dcCore::app()->public->search); - - foreach ($searchs as $k => $v) { - $args[0] = enhancePostContent::replaceString( - $v, - sprintf($this->replace, '\\1'), - $args[0], - $this - ); - } - - return null; - } -} +setProperties([ + 'priority' => 100, + '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 (empty(dcCore::app()->public->search)) { + return null; + } + + $searchs = explode(' ', dcCore::app()->public->search); + + foreach ($searchs as $k => $v) { + $args[0] = enhancePostContent::replaceString( + $v, + sprintf($this->replace, '\\1'), + $args[0], + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcfiltertag.php b/inc/class.epcfiltertag.php index fa1f02d..8b33c3f 100644 --- a/inc/class.epcfiltertag.php +++ b/inc/class.epcfiltertag.php @@ -1,69 +1,80 @@ -setProperties([ - 'priority' => 900, - '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 (!dcCore::app()->plugins->moduleExists('tags')) { - return null; - } - - $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); - - while ($metas->fetch()) { - $args[0] = enhancePostContent::replaceString( - $metas->meta_id, - sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), - $args[0], - $this - ); - } - - return null; - } - - public function widgetList($content, $w, &$list) - { - if (!dcCore::app()->plugins->moduleExists('tags')) { - return null; - } - - $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); - - while ($metas->fetch()) { - $list[] = enhancePostContent::matchString( - $metas->meta_id, - sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), - $content, - $this - ); - } - - return null; - } -} +setProperties([ + 'priority' => 900, + '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 (!dcCore::app()->plugins->moduleExists('tags')) { + return null; + } + + $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); + + while ($metas->fetch()) { + $args[0] = enhancePostContent::replaceString( + $metas->meta_id, + sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), + $args[0], + $this + ); + } + + return null; + } + + public function widgetList($content, $w, &$list) + { + if (!dcCore::app()->plugins->moduleExists('tags')) { + return null; + } + + $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); + + while ($metas->fetch()) { + $list[] = enhancePostContent::matchString( + $metas->meta_id, + sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), + $content, + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcfiltertwitter.php b/inc/class.epcfiltertwitter.php index 9d05fc9..3d79d8a 100644 --- a/inc/class.epcfiltertwitter.php +++ b/inc/class.epcfiltertwitter.php @@ -1,42 +1,53 @@ -setProperties([ - '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' => '%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] = enhancePostContent::replaceString( - '[A-Za-z0-9_]{2,}', - sprintf($this->replace, 'http://twitter.com/\\1', '\\1'), - $args[0], - $this, - '[^@]@', - '\b' - ); - - return null; - } -} +setProperties([ + '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' => '%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] = enhancePostContent::replaceString( + '[A-Za-z0-9_]{2,}', + sprintf($this->replace, 'http://twitter.com/\\1', '\\1'), + $args[0], + $this, + '[^@]@', + '\b' + ); + + return null; + } +} diff --git a/inc/class.epcfilterupdate.php b/inc/class.epcfilterupdate.php index 032bb0a..7f8d1bb 100644 --- a/inc/class.epcfilterupdate.php +++ b/inc/class.epcfilterupdate.php @@ -1,45 +1,56 @@ -setProperties([ - '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.'), - '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] = enhancePostContent::replaceString( - $this->records()->epc_key, - sprintf($this->replace, '\\1', $this->records()->epc_value), - $args[0], - $this - ); - } - - return null; - } -} +setProperties([ + '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.'), + '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] = enhancePostContent::replaceString( + $this->records()->epc_key, + sprintf($this->replace, '\\1', $this->records()->epc_value), + $args[0], + $this + ); + } + + return null; + } +} diff --git a/inc/class.epcupgrade.php b/inc/class.epcupgrade.php index 1e3fd58..90ca979 100644 --- a/inc/class.epcupgrade.php +++ b/inc/class.epcupgrade.php @@ -21,24 +21,24 @@ class epcUpgrade $current = dcCore::app()->getVersion(basename(dirname('../' . __DIR__))); if ($current && version_compare($current, '0.6.6', '<=')) { - self::postUpgrade00060607(); + self::upTo00060607(); } if ($current && version_compare($current, '2021.10.06', '<=')) { - self::postUpgrade20211006(); + self::upTo20211006(); } if ($current && version_compare($current, '2022.11.20', '<=')) { - self::preUpgrade20221120(); + self::upTo20221120(); } } /** * 0.6.6 - * + * * - filters move from settings to dedicated table */ - private static function postUpgrade00060607() + private static function upTo00060607() { # Move old filters lists from settings to database $f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL "); @@ -68,10 +68,10 @@ class epcUpgrade /** * 2021.10.06 - * + * * - filters change name to id */ - private static function postUpgrade20211006() + private static function upTo20211006() { # Move old filter name to filter id $rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . initEnhancePostContent::TABLE_NAME); @@ -88,18 +88,18 @@ class epcUpgrade /** * 2022.11.20 * - * - setting id changes to shorter one, + * - setting id changes to shorter one, * - setting ns changes to abstract one (no real changes), * - setting value change from serialize to json_encode (if it's array) */ - private static function preUpgrade20221120() + private static function upTo20221120() { // list of settings using serialize values to move to json $ids = [ - 'allowedtplvalues', - 'allowedpubpages' + 'allowedtplvalues', + 'allowedpubpages', ]; - foreach(enhancePostContent::getFilters() as $id => $f) { + foreach (enhancePostContent::getFilters() as $id => $f) { $ids[] = $id; } diff --git a/index.php b/index.php index ce5293e..d4a1de9 100644 --- a/index.php +++ b/index.php @@ -61,7 +61,7 @@ try { ]; dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); - dcCore::app()->blog->settings->__get(basename(__DIR__))->put($filter->id(), json_encode($f)); + dcCore::app()->blog->settings->get(basename(__DIR__))->put($filter->id(), json_encode($f)); dcCore::app()->blog->triggerBlog(); @@ -159,7 +159,7 @@ if ($filter->has_list) { echo ' ' . __('Enhance post content') . '' . dcPage::jsPageTabs() . -dcPage::jsLoad(dcPage::getPF(basename(__DIR__) . '/js/index.js')) . +dcPage::jsModuleLoad(basename(__DIR__) . '/js/index.js') . $header . # --BEHAVIOR-- enhancePostContentAdminHeader