code review

master
Jean-Christian Paul Denis 2022-12-21 22:27:20 +01:00
parent 8b112f8fec
commit 1b1d6fb40f
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
20 changed files with 684 additions and 579 deletions

View File

@ -40,7 +40,7 @@ dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $f
# Preference form # Preference form
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings) { 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(); $allowedtplvalues = enhancePostContent::blogAllowedTplValues();
$allowedpubpages = enhancePostContent::blogAllowedPubPages(); $allowedpubpages = enhancePostContent::blogAllowedPubPages();
@ -78,9 +78,9 @@ dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings
$allowedtplvalues = enhancePostContent::explode($_POST['epc_allowedtplvalues']); $allowedtplvalues = enhancePostContent::explode($_POST['epc_allowedtplvalues']);
$allowedpubpages = enhancePostContent::explode($_POST['epc_allowedpubpages']); $allowedpubpages = enhancePostContent::explode($_POST['epc_allowedpubpages']);
$blog_settings->__get(basename(__DIR__))->put('active', $active); $blog_settings->get(basename(__DIR__))->put('active', $active);
$blog_settings->__get(basename(__DIR__))->put('allowedtplvalues', json_encode($allowedtplvalues)); $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('allowedpubpages', json_encode($allowedpubpages));
}); });
# List filter # List filter

View File

@ -17,7 +17,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
try { try {
// Version // Version
if (!dcCore::app()->newVersion( if (!dcCore::app()->newVersion(
basename(__DIR__), basename(__DIR__),
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
)) { )) {
return null; return null;
@ -48,8 +48,7 @@ try {
epcUpgrade::growUp(); epcUpgrade::growUp();
// Settings // Settings
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); $s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
$s = dcCore::app()->blog->settings->__get(basename(__DIR__));
$s->put('active', false, 'boolean', 'Enable enhancePostContent', false, true); $s->put('active', false, 'boolean', 'Enable enhancePostContent', false, true);
$s->put('list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true); $s->put('list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true);

View File

@ -31,10 +31,10 @@ $d = __DIR__ . '/inc/';
Clearbricks::lib()->autoload([ Clearbricks::lib()->autoload([
'enhancePostContent' => $d . 'class.enhancepostcontent.php', 'enhancePostContent' => $d . 'class.enhancepostcontent.php',
'epcFilter' => $d . 'class.epcfilter.php', 'epcFilter' => $d . 'class.epcfilter.php',
'epcRecords' => $d . 'class.epcrecords.php', 'epcRecords' => $d . 'class.epcrecords.php',
'epcUpgrade' => $d . 'class.epcupgrade.php', 'epcUpgrade' => $d . 'class.epcupgrade.php',
'adminEpcList' => $d . 'class.adminepclist.php', 'adminEpcList' => $d . 'class.adminepclist.php',
]); ]);
foreach ($filters as $f) { foreach ($filters as $f) {

View File

@ -18,7 +18,7 @@ require __DIR__ . '/_widgets.php';
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); 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; return null;
} }

View File

@ -114,7 +114,7 @@ class enhancePostContentWidget
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
# Page # 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']) || !in_array(dcCore::app()->ctx->current_tpl, ['post.html', 'page.html'])
) { ) {
return null; return null;

View File

@ -24,11 +24,7 @@ class adminEpcList extends adminGenericList
public function display($filter, $pager_url, $enclose_block = '') public function display($filter, $pager_url, $enclose_block = '')
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
if ($filter->show()) { echo '<p><strong>' . ($filter->show() ? __('No record matches the filter') : __('No record')) . '</strong></p>';
echo '<p><strong>' . __('No record matches the filter') . '</strong></p>';
} else {
echo '<p><strong>' . __('No record') . '</strong></p>';
}
} else { } else {
$pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10); $pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10);
$pager->base_url = $pager_url; $pager->base_url = $pager_url;

View File

@ -46,7 +46,7 @@ class enhancePostContent
public static function blogAllowedTplValues() public static function blogAllowedTplValues()
{ {
dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__))); 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(); return is_array($rs) ? $rs : self::defaultAllowedTplValues();
} }
@ -54,11 +54,11 @@ class enhancePostContent
public static function defaultAllowedWidgetValues() public static function defaultAllowedWidgetValues()
{ {
$rs = new arrayObject([ $rs = new arrayObject([
'entry excerpt' => [ 'entry excerpt' => [
'id' => 'entryexcerpt', 'id' => 'entryexcerpt',
'cb' => ['enhancePostContent','widgetContentEntryExcerpt'], 'cb' => ['enhancePostContent','widgetContentEntryExcerpt'],
], ],
'entry content' => [ 'entry content' => [
'id' => 'entrycontent', 'id' => 'entrycontent',
'cb' => ['enhancePostContent','widgetContentEntryContent'], 'cb' => ['enhancePostContent','widgetContentEntryContent'],
], ],
@ -92,7 +92,7 @@ class enhancePostContent
public static function blogAllowedPubPages() public static function blogAllowedPubPages()
{ {
dcCore::app()->blog->settings->addNamespace(basename(dirname('../' . __DIR__))); 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(); return is_array($rs) ? $rs : self::defaultAllowedPubPages();
} }

View File

@ -108,7 +108,7 @@ abstract class epcFilter
private function blogSettings() 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)) { if (empty($opt)) {
$opt = []; $opt = [];

View File

@ -1,58 +1,69 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterAbbreviation extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 400, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Abbreviation'), */
'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'), if (!defined('DC_RC_PATH')) {
'has_list' => true, return null;
'htmltag' => 'a', }
'class' => ['abbr.epc-abbr'],
'replace' => '<abbr class="epc-abbr" title="%s">%s</abbr>', class epcFilterAbbreviation extends epcFilter
'widget' => '<abbr title="%s">%s</abbr>', {
]); protected function init(): string
{
$this->setSettings([ $this->setProperties([
'style' => ['font-weight: bold;'], 'priority' => 400,
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'name' => __('Abbreviation'),
'tplValues' => ['EntryContent'], 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'),
'pubPages' => ['post.html'], 'has_list' => true,
]); 'htmltag' => 'a',
'class' => ['abbr.epc-abbr'],
return 'abbreviation'; 'replace' => '<abbr class="epc-abbr" title="%s">%s</abbr>',
} 'widget' => '<abbr title="%s">%s</abbr>',
]);
public function publicContent($tag, $args)
{ $this->setSettings([
while ($this->records()->fetch()) { 'style' => ['font-weight: bold;'],
$args[0] = enhancePostContent::replaceString( 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
$this->records()->epc_key, 'tplValues' => ['EntryContent'],
sprintf($this->replace, __($this->records()->epc_value), '\\1'), 'pubPages' => ['post.html'],
$args[0], ]);
$this
); return 'abbreviation';
} }
return null; public function publicContent($tag, $args)
} {
while ($this->records()->fetch()) {
public function widgetList($content, $w, &$list) $args[0] = enhancePostContent::replaceString(
{ $this->records()->epc_key,
while ($this->records()->fetch()) { sprintf($this->replace, __($this->records()->epc_value), '\\1'),
$list[] = enhancePostContent::matchString( $args[0],
$this->records()->epc_key, $this
sprintf($this->widget, __($this->records()->epc_value), '\\1'), );
$content, }
$this
); return null;
} }
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;
}
}

View File

@ -1,58 +1,69 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterAcronym extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 700, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Acronym'), */
'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'), if (!defined('DC_RC_PATH')) {
'has_list' => true, return null;
'htmltag' => 'acronym', }
'class' => ['acronym.epc-acronym'],
'replace' => '<acronym class="epc-acronym" title="%s">%s</acronym>', class epcFilterAcronym extends epcFilter
'widget' => '<acronym title="%s">%s</acronym>', {
]); protected function init(): string
{
$this->setSettings([ $this->setProperties([
'style' => ['font-weight: bold;'], 'priority' => 700,
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'name' => __('Acronym'),
'tplValues' => ['EntryContent'], 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'),
'pubPages' => ['post.html'], 'has_list' => true,
]); 'htmltag' => 'acronym',
'class' => ['acronym.epc-acronym'],
return 'acronym'; 'replace' => '<acronym class="epc-acronym" title="%s">%s</acronym>',
} 'widget' => '<acronym title="%s">%s</acronym>',
]);
public function publicContent($tag, $args)
{ $this->setSettings([
while ($this->records()->fetch()) { 'style' => ['font-weight: bold;'],
$args[0] = enhancePostContent::replaceString( 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
$this->records()->epc_key, 'tplValues' => ['EntryContent'],
sprintf($this->replace, __($this->records()->epc_value), '\\1'), 'pubPages' => ['post.html'],
$args[0], ]);
$this
); return 'acronym';
} }
return null; public function publicContent($tag, $args)
} {
while ($this->records()->fetch()) {
public function widgetList($content, $w, &$list) $args[0] = enhancePostContent::replaceString(
{ $this->records()->epc_key,
while ($this->records()->fetch()) { sprintf($this->replace, __($this->records()->epc_value), '\\1'),
$list[] = enhancePostContent::matchString( $args[0],
$this->records()->epc_key, $this
sprintf($this->widget, __($this->records()->epc_value), '\\1'), );
$content, }
$this
); return null;
} }
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;
}
}

View File

@ -1,59 +1,70 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterCitation extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 600, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Citation'), */
'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'), if (!defined('DC_RC_PATH')) {
'has_list' => true, return null;
'htmltag' => 'cite', }
'class' => ['cite.epc-cite'],
'replace' => '<cite class="epc-cite" title="%s">%s</cite>', class epcFilterCitation extends epcFilter
'widget' => '<cite title="%s">%s</cite>', {
]); protected function init(): string
{
$this->setSettings([ $this->setProperties([
'nocase' => true, 'priority' => 600,
'style' => ['font-style: italic;'], 'name' => __('Citation'),
'notag' => 'a,h1,h2,h3', 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'),
'tplValues' => ['EntryContent'], 'has_list' => true,
'pubPages' => ['post.html'], 'htmltag' => 'cite',
]); 'class' => ['cite.epc-cite'],
'replace' => '<cite class="epc-cite" title="%s">%s</cite>',
return 'citation'; 'widget' => '<cite title="%s">%s</cite>',
} ]);
public function publicContent($tag, $args) $this->setSettings([
{ 'nocase' => true,
while ($this->records()->fetch()) { 'style' => ['font-style: italic;'],
$args[0] = enhancePostContent::replaceString( 'notag' => 'a,h1,h2,h3',
$this->records()->epc_key, 'tplValues' => ['EntryContent'],
sprintf($this->replace, __($this->records()->epc_value), '\\1'), 'pubPages' => ['post.html'],
$args[0], ]);
$this
); return 'citation';
} }
return null; public function publicContent($tag, $args)
} {
while ($this->records()->fetch()) {
public function widgetList($content, $w, &$list) $args[0] = enhancePostContent::replaceString(
{ $this->records()->epc_key,
while ($this->records()->fetch()) { sprintf($this->replace, __($this->records()->epc_value), '\\1'),
$list[] = enhancePostContent::matchString( $args[0],
$this->records()->epc_key, $this
sprintf($this->widget, __($this->records()->epc_value), '\\1'), );
$content, }
$this
); return null;
} }
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;
}
}

View File

@ -1,58 +1,69 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterDefinition extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 800, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Definition'), */
'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'), if (!defined('DC_RC_PATH')) {
'has_list' => true, return null;
'htmltag' => 'dfn', }
'class' => ['dfn.epc-dfn'],
'replace' => '<dfn class="epc-dfn" title="%s">%s</dfn>', class epcFilterDefinition extends epcFilter
'widget' => '<dfn class="epc-dfn" title="%s">%s</dfn>', {
]); protected function init(): string
{
$this->setSettings([ $this->setProperties([
'style' => ['font-weight: bold;'], 'priority' => 800,
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'name' => __('Definition'),
'tplValues' => ['EntryContent'], 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'),
'pubPages' => ['post.html'], 'has_list' => true,
]); 'htmltag' => 'dfn',
'class' => ['dfn.epc-dfn'],
return 'definition'; 'replace' => '<dfn class="epc-dfn" title="%s">%s</dfn>',
} 'widget' => '<dfn class="epc-dfn" title="%s">%s</dfn>',
]);
public function publicContent($tag, $args)
{ $this->setSettings([
while ($this->records()->fetch()) { 'style' => ['font-weight: bold;'],
$args[0] = enhancePostContent::replaceString( 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
$this->records()->epc_key, 'tplValues' => ['EntryContent'],
sprintf($this->replace, __($this->records()->epc_value), '\\1'), 'pubPages' => ['post.html'],
$args[0], ]);
$this
); return 'definition';
} }
return null; public function publicContent($tag, $args)
} {
while ($this->records()->fetch()) {
public function widgetList($content, $w, &$list) $args[0] = enhancePostContent::replaceString(
{ $this->records()->epc_key,
while ($this->records()->fetch()) { sprintf($this->replace, __($this->records()->epc_value), '\\1'),
$list[] = enhancePostContent::matchString( $args[0],
$this->records()->epc_key, $this
sprintf($this->widget, __($this->records()->epc_value), '\\1'), );
$content, }
$this
); return null;
} }
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;
}
}

View File

@ -1,58 +1,69 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterLink extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 500, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Link'), */
'help' => __('Link some words. First term of the list is the term to link and second term the link.'), if (!defined('DC_RC_PATH')) {
'has_list' => true, return null;
'htmltag' => 'a', }
'class' => ['a.epc-link'],
'replace' => '<a class="epc-link" title="%s" href="%s">%s</a>', class epcFilterLink extends epcFilter
'widget' => '<a title="%s" href="%s">%s</a>', {
]); protected function init(): string
{
$this->setSettings([ $this->setProperties([
'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'], 'priority' => 500,
'notag' => 'a,h1,h2,h3', 'name' => __('Link'),
'tplValues' => ['EntryContent'], 'help' => __('Link some words. First term of the list is the term to link and second term the link.'),
'pubPages' => ['post.html'], 'has_list' => true,
]); 'htmltag' => 'a',
'class' => ['a.epc-link'],
return 'link'; 'replace' => '<a class="epc-link" title="%s" href="%s">%s</a>',
} 'widget' => '<a title="%s" href="%s">%s</a>',
]);
public function publicContent($tag, $args)
{ $this->setSettings([
while ($this->records()->fetch()) { 'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'],
$args[0] = enhancePostContent::replaceString( 'notag' => 'a,h1,h2,h3',
$this->records()->epc_key, 'tplValues' => ['EntryContent'],
sprintf($this->replace, '\\1', $this->records()->epc_value, '\\1'), 'pubPages' => ['post.html'],
$args[0], ]);
$this
); return 'link';
} }
return null; public function publicContent($tag, $args)
} {
while ($this->records()->fetch()) {
public function widgetList($content, $w, &$list) $args[0] = enhancePostContent::replaceString(
{ $this->records()->epc_key,
while ($this->records()->fetch()) { sprintf($this->replace, '\\1', $this->records()->epc_value, '\\1'),
$list[] = enhancePostContent::matchString( $args[0],
$this->records()->epc_key, $this
sprintf($this->widget, $this->records()->epc_value, $this->records()->epc_value, '\\1'), );
$content, }
$this
); return null;
} }
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;
}
}

View File

@ -1,45 +1,56 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterReplace extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 200, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Replace'), */
'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'), if (!defined('DC_RC_PATH')) {
'has_list' => true, return null;
'htmltag' => '', }
'class' => ['span.epc-replace'],
'replace' => '<span class="epc-replace">%s</span>', class epcFilterReplace extends epcFilter
]); {
protected function init(): string
$this->setSettings([ {
'nocase' => true, $this->setProperties([
'plural' => true, 'priority' => 200,
'style' => ['font-style: italic;'], 'name' => __('Replace'),
'notag' => 'h1,h2,h3', 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'),
'tplValues' => ['EntryContent'], 'has_list' => true,
'pubPages' => ['post.html'], 'htmltag' => '',
]); 'class' => ['span.epc-replace'],
'replace' => '<span class="epc-replace">%s</span>',
return 'replace'; ]);
}
$this->setSettings([
public function publicContent($tag, $args) 'nocase' => true,
{ 'plural' => true,
while ($this->records()->fetch()) { 'style' => ['font-style: italic;'],
$args[0] = enhancePostContent::replaceString( 'notag' => 'h1,h2,h3',
$this->records()->epc_key, 'tplValues' => ['EntryContent'],
sprintf($this->replace, $this->records()->epc_value, '\\2'), 'pubPages' => ['post.html'],
$args[0], ]);
$this
); return 'replace';
} }
return null; 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;
}
}

View File

@ -1,50 +1,61 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterSearch extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 100, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Search'), */
'help' => __('Highlight searched words.'), if (!defined('DC_RC_PATH')) {
'htmltag' => '', return null;
'class' => ['span.epc-search'], }
'replace' => '<span class="epc-search" title="' . __('Search') . '">%s</span>',
]); class epcFilterSearch extends epcFilter
{
$this->setSettings([ protected function init(): string
'nocase' => true, {
'plural' => true, $this->setProperties([
'style' => ['color: #FFCC66;'], 'priority' => 100,
'notag' => 'h1,h2,h3', 'name' => __('Search'),
'tplValues' => ['EntryContent'], 'help' => __('Highlight searched words.'),
'pubPages' => ['search.html'], 'htmltag' => '',
]); 'class' => ['span.epc-search'],
'replace' => '<span class="epc-search" title="' . __('Search') . '">%s</span>',
return 'search'; ]);
}
$this->setSettings([
public function publicContent($tag, $args) 'nocase' => true,
{ 'plural' => true,
if (empty(dcCore::app()->public->search)) { 'style' => ['color: #FFCC66;'],
return null; 'notag' => 'h1,h2,h3',
} 'tplValues' => ['EntryContent'],
'pubPages' => ['search.html'],
$searchs = explode(' ', dcCore::app()->public->search); ]);
foreach ($searchs as $k => $v) { return 'search';
$args[0] = enhancePostContent::replaceString( }
$v,
sprintf($this->replace, '\\1'), public function publicContent($tag, $args)
$args[0], {
$this if (empty(dcCore::app()->public->search)) {
); return null;
} }
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;
}
}

View File

@ -1,69 +1,80 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterTag extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 900, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Tag'), */
'help' => __('Highlight tags of your blog.'), if (!defined('DC_RC_PATH')) {
'htmltag' => 'a', return null;
'class' => ['a.epc-tag'], }
'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>',
'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>', class epcFilterTag extends epcFilter
]); {
protected function init(): string
$this->setSettings([ {
'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'], $this->setProperties([
'notag' => 'a,h1,h2,h3', 'priority' => 900,
'tplValues' => ['EntryContent'], 'name' => __('Tag'),
'pubPages' => ['post.html'], 'help' => __('Highlight tags of your blog.'),
]); 'htmltag' => 'a',
'class' => ['a.epc-tag'],
return 'tag'; 'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>',
} 'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>',
]);
public function publicContent($tag, $args)
{ $this->setSettings([
if (!dcCore::app()->plugins->moduleExists('tags')) { 'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'],
return null; 'notag' => 'a,h1,h2,h3',
} 'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
$metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); ]);
while ($metas->fetch()) { return 'tag';
$args[0] = enhancePostContent::replaceString( }
$metas->meta_id,
sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), public function publicContent($tag, $args)
$args[0], {
$this if (!dcCore::app()->plugins->moduleExists('tags')) {
); return null;
} }
return null; $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']);
}
while ($metas->fetch()) {
public function widgetList($content, $w, &$list) $args[0] = enhancePostContent::replaceString(
{ $metas->meta_id,
if (!dcCore::app()->plugins->moduleExists('tags')) { sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'),
return null; $args[0],
} $this
);
$metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); }
while ($metas->fetch()) { return null;
$list[] = enhancePostContent::matchString( }
$metas->meta_id,
sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), public function widgetList($content, $w, &$list)
$content, {
$this if (!dcCore::app()->plugins->moduleExists('tags')) {
); return null;
} }
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;
}
}

View File

@ -1,42 +1,53 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterTwitter extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 1000, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Twitter'), */
'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'), if (!defined('DC_RC_PATH')) {
'htmltag' => 'a', return null;
'class' => ['a.epc-twitter'], }
'replace' => '<a class="epc-twitter" title="' . __("View this user's twitter page") . '" href="%s">%s</a>',
]); class epcFilterTwitter extends epcFilter
{
$this->setSettings([ protected function init(): string
'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'], {
'notag' => 'a,h1,h2,h3', $this->setProperties([
'tplValues' => ['EntryContent'], 'priority' => 1000,
'pubPages' => ['post.html'], 'name' => __('Twitter'),
]); 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'),
'htmltag' => 'a',
return 'twitter'; 'class' => ['a.epc-twitter'],
} 'replace' => '<a class="epc-twitter" title="' . __("View this user's twitter page") . '" href="%s">%s</a>',
]);
public function publicContent($tag, $args)
{ $this->setSettings([
$args[0] = enhancePostContent::replaceString( 'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'],
'[A-Za-z0-9_]{2,}', 'notag' => 'a,h1,h2,h3',
sprintf($this->replace, 'http://twitter.com/\\1', '\\1'), 'tplValues' => ['EntryContent'],
$args[0], 'pubPages' => ['post.html'],
$this, ]);
'[^@]@',
'\b' return 'twitter';
); }
return null; 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;
}
}

View File

@ -1,45 +1,56 @@
<?php <?php
if (!defined('DC_RC_PATH')) { /**
return null; * @brief enhancePostContent, a plugin for Dotclear 2
} *
* @package Dotclear
class epcFilterUpdate extends epcFilter * @subpackage Plugin
{ *
protected function init(): string * @author Jean-Christian Denis and Contributors
{ *
$this->setProperties([ * @copyright Jean-Christian Denis
'priority' => 300, * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
'name' => __('Update'), */
'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'), if (!defined('DC_RC_PATH')) {
'has_list' => true, return null;
'htmltag' => 'del,ins', }
'class' => ['del.epc-update', 'ins.epc-update'],
'replace' => '<del class="epc-update">%s</del> <ins class="epc-update">%s</ins>', class epcFilterUpdate extends epcFilter
]); {
protected function init(): string
$this->setSettings([ {
'nocase' => true, $this->setProperties([
'plural' => true, 'priority' => 300,
'style' => ['text-decoration: line-through;', 'font-style: italic;'], 'name' => __('Update'),
'notag' => 'h1,h2,h3', 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'),
'tplValues' => ['EntryContent'], 'has_list' => true,
'pubPages' => ['post.html'], 'htmltag' => 'del,ins',
]); 'class' => ['del.epc-update', 'ins.epc-update'],
'replace' => '<del class="epc-update">%s</del> <ins class="epc-update">%s</ins>',
return 'update'; ]);
}
$this->setSettings([
public function publicContent($tag, $args) 'nocase' => true,
{ 'plural' => true,
while ($this->records()->fetch()) { 'style' => ['text-decoration: line-through;', 'font-style: italic;'],
$args[0] = enhancePostContent::replaceString( 'notag' => 'h1,h2,h3',
$this->records()->epc_key, 'tplValues' => ['EntryContent'],
sprintf($this->replace, '\\1', $this->records()->epc_value), 'pubPages' => ['post.html'],
$args[0], ]);
$this
); return 'update';
} }
return null; 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;
}
}

View File

@ -21,24 +21,24 @@ class epcUpgrade
$current = dcCore::app()->getVersion(basename(dirname('../' . __DIR__))); $current = dcCore::app()->getVersion(basename(dirname('../' . __DIR__)));
if ($current && version_compare($current, '0.6.6', '<=')) { if ($current && version_compare($current, '0.6.6', '<=')) {
self::postUpgrade00060607(); self::upTo00060607();
} }
if ($current && version_compare($current, '2021.10.06', '<=')) { if ($current && version_compare($current, '2021.10.06', '<=')) {
self::postUpgrade20211006(); self::upTo20211006();
} }
if ($current && version_compare($current, '2022.11.20', '<=')) { if ($current && version_compare($current, '2022.11.20', '<=')) {
self::preUpgrade20221120(); self::upTo20221120();
} }
} }
/** /**
* 0.6.6 * 0.6.6
* *
* - filters move from settings to dedicated table * - filters move from settings to dedicated table
*/ */
private static function postUpgrade00060607() private static function upTo00060607()
{ {
# Move old filters lists from settings to database # 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 "); $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 * 2021.10.06
* *
* - filters change name to id * - filters change name to id
*/ */
private static function postUpgrade20211006() private static function upTo20211006()
{ {
# Move old filter name to filter id # Move old filter name to filter id
$rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . initEnhancePostContent::TABLE_NAME); $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 * 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 ns changes to abstract one (no real changes),
* - setting value change from serialize to json_encode (if it's array) * - setting value change from serialize to json_encode (if it's array)
*/ */
private static function preUpgrade20221120() private static function upTo20221120()
{ {
// list of settings using serialize values to move to json // list of settings using serialize values to move to json
$ids = [ $ids = [
'allowedtplvalues', 'allowedtplvalues',
'allowedpubpages' 'allowedpubpages',
]; ];
foreach(enhancePostContent::getFilters() as $id => $f) { foreach (enhancePostContent::getFilters() as $id => $f) {
$ids[] = $id; $ids[] = $id;
} }

View File

@ -61,7 +61,7 @@ try {
]; ];
dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); 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(); dcCore::app()->blog->triggerBlog();
@ -159,7 +159,7 @@ if ($filter->has_list) {
echo ' echo '
<html><head><title>' . __('Enhance post content') . '</title>' . <html><head><title>' . __('Enhance post content') . '</title>' .
dcPage::jsPageTabs() . dcPage::jsPageTabs() .
dcPage::jsLoad(dcPage::getPF(basename(__DIR__) . '/js/index.js')) . dcPage::jsModuleLoad(basename(__DIR__) . '/js/index.js') .
$header . $header .
# --BEHAVIOR-- enhancePostContentAdminHeader # --BEHAVIOR-- enhancePostContentAdminHeader