fix PSR coding style

This commit is contained in:
Jean-Christian Denis 2021-11-01 10:33:43 +01:00
parent d416fc3c33
commit a10ab12580
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
16 changed files with 283 additions and 268 deletions

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -53,13 +52,13 @@ class epcAdminBehaviors
public static function adminDashboardFavorites($core, $favs) public static function adminDashboardFavorites($core, $favs)
{ {
$favs->register('enhancePostContent', [ $favs->register('enhancePostContent', [
'title' => __('Enhance post content'), 'title' => __('Enhance post content'),
'url' => 'plugin.php?p=enhancePostContent', 'url' => 'plugin.php?p=enhancePostContent',
'small-icon' => 'index.php?pf=enhancePostContent/icon.png', 'small-icon' => 'index.php?pf=enhancePostContent/icon.png',
'large-icon' => 'index.php?pf=enhancePostContent/icon-big.png', 'large-icon' => 'index.php?pf=enhancePostContent/icon-big.png',
'permissions' => $core->auth->check('contentadmin', $core->blog->id), 'permissions' => $core->auth->check('contentadmin', $core->blog->id),
'active_cb' => [ 'active_cb' => [
'epcAdminBehaviors', 'epcAdminBehaviors',
'adminDashboardFavoritesActive' 'adminDashboardFavoritesActive'
] ]
]); ]);
@ -67,38 +66,38 @@ class epcAdminBehaviors
public static function adminDashboardFavoritesActive($request, $params) public static function adminDashboardFavoritesActive($request, $params)
{ {
return $request == 'plugin.php' return $request == 'plugin.php'
&& isset($params['p']) && isset($params['p'])
&& $params['p'] == 'enhancePostContent'; && $params['p'] == 'enhancePostContent';
} }
public static function sortbyCombo() public static function sortbyCombo()
{ {
return [ return [
__('Date') => 'epc_upddt', __('Date') => 'epc_upddt',
__('Key') => 'epc_key', __('Key') => 'epc_key',
__('Value') => 'epc_value', __('Value') => 'epc_value',
__('ID') => 'epc_id' __('ID') => 'epc_id'
]; ];
} }
public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings) public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings)
{ {
$active = (boolean) $blog_settings->enhancePostContent->enhancePostContent_active; $active = (boolean) $blog_settings->enhancePostContent->enhancePostContent_active;
$allowedtplvalues = libEPC::blogAllowedTplValues(); $allowedtplvalues = libEPC::blogAllowedTplValues();
$allowedpubpages = libEPC::blogAllowedPubPages(); $allowedpubpages = libEPC::blogAllowedPubPages();
echo echo
'<div class="fieldset"><h4 id="epc_params">' . __('Enhance post content') .'</h4>' . '<div class="fieldset"><h4 id="epc_params">' . __('Enhance post content') . '</h4>' .
'<div class="two-cols">' . '<div class="two-cols">' .
'<div class="col">' . '<div class="col">' .
'<p><label class="classic">' . '<p><label class="classic">' .
form::checkbox('epc_active', '1', $active) . form::checkbox('epc_active', '1', $active) .
__('Enable plugin') . '</label></p>' . __('Enable plugin') . '</label></p>' .
'<p class="form-note">' . '<p class="form-note">' .
__('This enable public widgets and contents filter.') . __('This enable public widgets and contents filter.') .
'</p>' . '</p>' .
'<p><a href="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '">' . '<p><a href="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '">' .
__('Set content filters') . '</a></p>' . __('Set content filters') . '</a></p>' .
'</div>' . '</div>' .
'<div class="col">' . '<div class="col">' .
@ -112,15 +111,15 @@ class epcAdminBehaviors
'<p class="form-note">' . __('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".') . '</p>' . '<p class="form-note">' . __('Use "readable_name1:template_page1;readable_name2:template_page2;" like "post page:post.html;home page:home.html;".') . '</p>' .
'</div>' . '</div>' .
'</div>' . '</div>' .
'<br class="clear" />' . '<br class="clear" />' .
'</div>'; '</div>';
} }
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings) public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
{ {
$active = !empty($_POST['epc_active']); $active = !empty($_POST['epc_active']);
$allowedtplvalues = libEPC::explode($_POST['epc_allowedtplvalues']); $allowedtplvalues = libEPC::explode($_POST['epc_allowedtplvalues']);
$allowedpubpages = libEPC::explode($_POST['epc_allowedpubpages']); $allowedpubpages = libEPC::explode($_POST['epc_allowedpubpages']);
$blog_settings->enhancePostContent->put('enhancePostContent_active', $active); $blog_settings->enhancePostContent->put('enhancePostContent_active', $active);
$blog_settings->enhancePostContent->put('enhancePostContent_allowedtplvalues', serialize($allowedtplvalues)); $blog_settings->enhancePostContent->put('enhancePostContent_allowedtplvalues', serialize($allowedtplvalues));
@ -137,4 +136,4 @@ class epcAdminBehaviors
[__('records per page'), 20] [__('records per page'), 20]
]; ];
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -21,14 +20,14 @@ $this->registerModule(
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'2021.09.05.1', '2021.09.05.1',
[ [
'requires' => [['core', '2.19']], 'requires' => [['core', '2.19']],
'permissions' => 'contentadmin', 'permissions' => 'contentadmin',
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/enhancePostContent', 'support' => 'https://github.com/JcDenis/enhancePostContent',
'details' => 'https://plugins.dotaddict.org/dc2/details/enhancePostContent', 'details' => 'https://plugins.dotaddict.org/dc2/details/enhancePostContent',
'repository' => 'https://raw.githubusercontent.com/JcDenis/enhancePostContent/master/dcstore.xml', 'repository' => 'https://raw.githubusercontent.com/JcDenis/enhancePostContent/master/dcstore.xml',
'settings' => [ 'settings' => [
'blog' => '#params.epc_params' 'blog' => '#params.epc_params'
] ]
] ]
); );

View file

@ -1,22 +1,21 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$dc_min = '2.18'; $dc_min = '2.18';
$mod_id = 'enhancePostContent'; $mod_id = 'enhancePostContent';
$new_version = $core->plugins->moduleInfo($mod_id, 'version'); $new_version = $core->plugins->moduleInfo($mod_id, 'version');
$old_version = $core->getVersion($mod_id); $old_version = $core->getVersion($mod_id);
@ -26,18 +25,20 @@ if (version_compare($old_version, $new_version, '>=')) {
try { try {
# Check Dotclear version # Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare') if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) {
throw new Exception(sprintf( throw new Exception(sprintf(
'%s requires Dotclear %s', $mod_id, $dc_min '%s requires Dotclear %s',
$mod_id,
$dc_min
)); ));
} }
# Database # Database
$s = new dbStruct($core->con, $core->prefix); $s = new dbStruct($core->con, $core->prefix);
$s->epc $s->epc
->epc_id ('bigint', 0, false) ->epc_id('bigint', 0, false)
->blog_id ('varchar', 32, false) ->blog_id('varchar', 32, false)
->epc_type('varchar', 32, false, "'epc'") ->epc_type('varchar', 32, false, "'epc'")
->epc_filter('varchar', 64, false) ->epc_filter('varchar', 64, false)
->epc_key('varchar', 255, false) ->epc_key('varchar', 255, false)
@ -50,15 +51,15 @@ try {
->index('idx_epc_filter', 'btree', 'epc_filter') ->index('idx_epc_filter', 'btree', 'epc_filter')
->index('idx_epc_key', 'btree', 'epc_key'); ->index('idx_epc_key', 'btree', 'epc_key');
$si = new dbStruct($core->con, $core->prefix); $si = new dbStruct($core->con, $core->prefix);
$changes = $si->synchronize($s); $changes = $si->synchronize($s);
$s = null; $s = null;
# Settings # Settings
$core->blog->settings->addNamespace($mod_id); $core->blog->settings->addNamespace($mod_id);
$s = $core->blog->settings->enhancePostContent; $s = $core->blog->settings->enhancePostContent;
$s->put('enhancePostContent_active', false,'boolean', 'Enable enhancePostContent', false, true); $s->put('enhancePostContent_active', false, 'boolean', 'Enable enhancePostContent', false, true);
$s->put('enhancePostContent_list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true); $s->put('enhancePostContent_list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true);
$s->put('enhancePostContent_list_order', 'desc', 'string', 'Admin records list order', false, true); $s->put('enhancePostContent_list_order', 'desc', 'string', 'Admin records list order', false, true);
$s->put('enhancePostContent_list_nb', 20, 'integer', 'Admin records list nb per page', false, true); $s->put('enhancePostContent_list_nb', 20, 'integer', 'Admin records list nb per page', false, true);
@ -67,7 +68,7 @@ try {
# Filters settings # Filters settings
$filters = libEPC::getFilters(); $filters = libEPC::getFilters();
foreach($filters as $id => $filter) { foreach ($filters as $id => $filter) {
# Only editable options # Only editable options
$opt = [ $opt = [
'nocase' => $filter->nocase, 'nocase' => $filter->nocase,
@ -78,11 +79,12 @@ try {
'pubPages' => $filter->pubPages 'pubPages' => $filter->pubPages
]; ];
$s->put('enhancePostContent_' . $id, serialize($opt), 'string', 'Settings for ' . $id, false, true); $s->put('enhancePostContent_' . $id, serialize($opt), 'string', 'Settings for ' . $id, false, true);
/* # only tables /* # only tables
if (isset($filter['list'])) { if (isset($filter['list'])) {
$s->put('enhancePostContent_' . $id . 'List', serialize($filter['list']), 'string', 'List for ' . $id, false, true); $s->put('enhancePostContent_' . $id . 'List', serialize($filter['list']), 'string', 'List for ' . $id, false, true);
} }
*/ } */
}
# Update old versions # Update old versions
if ($old_version && version_compare('2021.10.05', $old_version, '>=')) { if ($old_version && version_compare('2021.10.05', $old_version, '>=')) {
@ -97,4 +99,4 @@ try {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
return false; return false;

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -35,7 +34,7 @@ $__autoload['epcFilter'] = $d . 'lib.epc.filter.php';
$__autoload['epcRecords'] = $d . 'lib.epc.records.php'; $__autoload['epcRecords'] = $d . 'lib.epc.records.php';
$__autoload['adminEpcList'] = $d . 'lib.epc.pager.php'; $__autoload['adminEpcList'] = $d . 'lib.epc.pager.php';
foreach($filters as $f) { foreach ($filters as $f) {
$__autoload['epcFilter' . $f] = $d . 'lib.epc.filters.php'; $__autoload['epcFilter' . $f] = $d . 'lib.epc.filters.php';
$core->addBehavior('enhancePostContentFilters', ['epcFilter' . $f, 'create']); $core->addBehavior('enhancePostContentFilters', ['epcFilter' . $f, 'create']);
} }
@ -45,4 +44,4 @@ $core->url->register(
'epc.css', 'epc.css',
'^epc\.css', '^epc\.css',
['publicEnhancePostContent', 'css'] ['publicEnhancePostContent', 'css']
); );

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -20,7 +19,6 @@ require dirname(__FILE__) . '/_widgets.php';
$core->blog->settings->addNamespace('enhancePostContent'); $core->blog->settings->addNamespace('enhancePostContent');
if ($core->blog->settings->enhancePostContent->enhancePostContent_active) { if ($core->blog->settings->enhancePostContent->enhancePostContent_active) {
$core->addBehavior( $core->addBehavior(
'publicHeadContent', 'publicHeadContent',
['publicEnhancePostContent', 'publicHeadContent'] ['publicEnhancePostContent', 'publicHeadContent']
@ -40,7 +38,7 @@ class publicEnhancePostContent
{ {
/** /**
* Add filters CSS to page header * Add filters CSS to page header
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
*/ */
public static function publicHeadContent(dcCore $core) public static function publicHeadContent(dcCore $core)
@ -50,26 +48,25 @@ class publicEnhancePostContent
public static function css($args) public static function css($args)
{ {
$css = []; $css = [];
$filters = libEPC::getFilters(); $filters = libEPC::getFilters();
foreach($filters as $id => $filter) { foreach ($filters as $id => $filter) {
if ('' != $filter->class || '' != $filter->style) { if ('' != $filter->class || '' != $filter->style) {
continue; continue;
} }
$res = ''; $res = '';
foreach($filter->class as $k => $class) { foreach ($filter->class as $k => $class) {
$styles = $filter->style; $styles = $filter->style;
$style = html::escapeHTML(trim($styles[$k])); $style = html::escapeHTML(trim($styles[$k]));
if ('' != $style) { if ('' != $style) {
$res .= $class . " {" . $style . "} "; $res .= $class . ' {' . $style . '} ';
} }
} }
if (!empty($res)) { if (!empty($res)) {
$css[] = $css[] = '/* CSS for enhancePostContent ' . $id . " */ \n" . $res . "\n";
"/* CSS for enhancePostContent " . $id . " */ \n" . $res . "\n";
} }
} }
@ -82,7 +79,7 @@ class publicEnhancePostContent
/** /**
* Filter template blocks content * Filter template blocks content
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @param string $tag Tempalte block name * @param string $tag Tempalte block name
* @param array $args Tempalte Block arguments * @param array $args Tempalte Block arguments
@ -91,11 +88,11 @@ class publicEnhancePostContent
{ {
$filters = libEPC::getFilters(); $filters = libEPC::getFilters();
foreach($filters as $id => $filter) { foreach ($filters as $id => $filter) {
if (!libEPC::testContext($tag, $args, $filter)) { if (!libEPC::testContext($tag, $args, $filter)) {
continue; continue;
} }
$filter->publicContent($tag, $args); $filter->publicContent($tag, $args);
} }
} }
} }

View file

@ -1,58 +1,81 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) {
if (!defined('DC_CONTEXT_ADMIN')){
return; return;
} }
$this->addUserAction( $this->addUserAction(
/* type */ 'settings', /* type */
/* action */ 'delete_all', 'settings',
/* ns */ 'enhancePostContent', /* action */
/* description */ __('delete all settings') 'delete_all',
/* ns */
'enhancePostContent',
/* description */
__('delete all settings')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ 'enhancePostContent', /* action */
/* description */ __('delete plugin files') 'delete',
/* ns */
'enhancePostContent',
/* description */
__('delete plugin files')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'versions', /* type */
/* action */ 'delete', 'versions',
/* ns */ 'enhancePostContent', /* action */
/* description */ __('delete the version number') 'delete',
/* ns */
'enhancePostContent',
/* description */
__('delete the version number')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'settings', /* type */
/* action */ 'delete_all', 'settings',
/* ns */ 'enhancePostContent', /* action */
/* description */ sprintf(__('delete all %s settings'), 'enhancePostContent') 'delete_all',
/* ns */
'enhancePostContent',
/* description */
sprintf(__('delete all %s settings'), 'enhancePostContent')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ 'enhancePostContent', /* action */
/* description */ sprintf(__('delete %s plugin files'), 'enhancePostContent') 'delete',
/* ns */
'enhancePostContent',
/* description */
sprintf(__('delete %s plugin files'), 'enhancePostContent')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'versions', /* type */
/* action */ 'delete', 'versions',
/* ns */ 'enhancePostContent', /* action */
/* description */ sprintf(__('delete %s version number'), 'enhancePostContent') 'delete',
); /* ns */
'enhancePostContent',
/* description */
sprintf(__('delete %s version number'), 'enhancePostContent')
);

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -29,7 +28,7 @@ class enhancePostContentWidget
{ {
/** /**
* Admin part for widget that show extracted content * Admin part for widget that show extracted content
* *
* @param dcWidgets $w dcWidgets instance * @param dcWidgets $w dcWidgets instance
*/ */
public static function adminContentList($w) public static function adminContentList($w)
@ -54,8 +53,8 @@ class enhancePostContentWidget
); );
# Type # Type
$filters = libEPC::getFilters(); $filters = libEPC::getFilters();
$types = []; $types = [];
foreach($filters as $id => $filter) { foreach ($filters as $id => $filter) {
$types[$filter->name] = $id; $types[$filter->name] = $id;
} }
$w->epclist->setting( $w->epclist->setting(
@ -67,7 +66,7 @@ class enhancePostContentWidget
); );
# Content # Content
$contents = libEPC::defaultAllowedWidgetValues(); $contents = libEPC::defaultAllowedWidgetValues();
foreach($contents as $k => $v) { foreach ($contents as $k => $v) {
$w->epclist->setting( $w->epclist->setting(
'content' . $v['id'], 'content' . $v['id'],
sprintf(__('Enable filter on %s'), __($k)), sprintf(__('Enable filter on %s'), __($k)),
@ -105,7 +104,7 @@ class enhancePostContentWidget
/** /**
* Public part for widget that show extracted content * Public part for widget that show extracted content
* *
* @param dcWidget $w dcWidget instance * @param dcWidget $w dcWidget instance
*/ */
public static function publicContentList($w) public static function publicContentList($w)
@ -127,7 +126,7 @@ class enhancePostContentWidget
# Content # Content
$content = ''; $content = '';
foreach(libEPC::defaultAllowedWidgetValues() as $k => $v) { foreach (libEPC::defaultAllowedWidgetValues() as $k => $v) {
$ns = 'content' . $v['id']; $ns = 'content' . $v['id'];
if ($w->$ns && is_callable($v['cb'])) { if ($w->$ns && is_callable($v['cb'])) {
$content .= call_user_func_array( $content .= call_user_func_array(
@ -142,7 +141,7 @@ class enhancePostContentWidget
} }
# Filter # Filter
$list = []; $list = [];
$filters = libEPC::getFilters(); $filters = libEPC::getFilters();
if (isset($filters[$w->type])) { if (isset($filters[$w->type])) {
@ -157,14 +156,13 @@ class enhancePostContentWidget
# Parse result # Parse result
$res = ''; $res = '';
foreach($list as $line) { foreach ($list as $line) {
if (empty($line['matches'][0]['match'])) { if (empty($line['matches'][0]['match'])) {
continue; continue;
} }
$res .= $res .= '<li>' . $line['matches'][0]['match'] .
'<li>' . $line['matches'][0]['match'] . ($w->show_total ? ' (' . $line['total'] . ')' : '') .
($w->show_total ? ' (' . $line['total'] .')' : '') .
'</li>'; '</li>';
} }
@ -173,12 +171,12 @@ class enhancePostContentWidget
} }
return $w->renderDiv( return $w->renderDiv(
$w->content_only, $w->content_only,
$w->class, $w->class,
'id="epc_' . $w->type .'"', 'id="epc_' . $w->type . '"',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
($w->text ? '<p>' . html::escapeHTML($w->text) . '</p>' : '') . ($w->text ? '<p>' . html::escapeHTML($w->text) . '</p>' : '') .
'<ul>' . $res . '</ul>' '<ul>' . $res . '</ul>'
); );
} }
} }

View file

@ -1,21 +1,20 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
abstract class epcFilter abstract class epcFilter
{ {
public $core; public $core;
private $id = 'undefined'; private $id = 'undefined';
private $records = null; private $records = null;
private $properties = [ private $properties = [
@ -41,7 +40,7 @@ abstract class epcFilter
final public function __construct(dcCore $core) final public function __construct(dcCore $core)
{ {
$this->core = $core; $this->core = $core;
$this->id = $this->init(); $this->id = $this->init();
$this->blogSettings(); $this->blogSettings();
} }
@ -84,11 +83,12 @@ abstract class epcFilter
final protected function setProperties($property, $value = null): bool final protected function setProperties($property, $value = null): bool
{ {
$properties = is_array($property) ? $property : [$property => $value]; $properties = is_array($property) ? $property : [$property => $value];
foreach($properties as $k => $v) { foreach ($properties as $k => $v) {
if (isset($this->properties[$k])) { if (isset($this->properties[$k])) {
$this->properties[$k] = $v; $this->properties[$k] = $v;
} }
} }
return true; return true;
} }
@ -100,17 +100,18 @@ abstract class epcFilter
final protected function setSettings($setting, $value = null): bool final protected function setSettings($setting, $value = null): bool
{ {
$settings = is_array($setting) ? $setting : [$setting => $value]; $settings = is_array($setting) ? $setting : [$setting => $value];
foreach($settings as $k => $v) { foreach ($settings as $k => $v) {
if (isset($this->settings[$k])) { if (isset($this->settings[$k])) {
$this->settings[$k] = $v; $this->settings[$k] = $v;
} }
} }
return true; return true;
} }
private function blogSettings() private function blogSettings()
{ {
$ns = 'enhancePostContent_' . $this->id; $ns = 'enhancePostContent_' . $this->id;
$opt = @unserialize($this->core->blog->settings->enhancePostContent->$ns); $opt = @unserialize($this->core->blog->settings->enhancePostContent->$ns);
if (!is_array($opt)) { if (!is_array($opt)) {
@ -142,7 +143,7 @@ abstract class epcFilter
final public function records() final public function records()
{ {
if ($this->records === null && $this->has_list) { if ($this->records === null && $this->has_list) {
$records = new epcRecords($this->core); $records = new epcRecords($this->core);
$this->records = $records->getRecords(['epc_filter' => $this->id()]); $this->records = $records->getRecords(['epc_filter' => $this->id()]);
} }
@ -160,4 +161,4 @@ abstract class epcFilter
{ {
return null; return null;
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class epcFilterTag extends epcFilter class epcFilterTag extends epcFilter
{ {
protected function init(): string protected function init(): string
@ -43,7 +42,7 @@ class epcFilterTag extends epcFilter
$metas = $this->core->meta->getMetadata(['meta_type' => 'tag']); $metas = $this->core->meta->getMetadata(['meta_type' => 'tag']);
while($metas->fetch()) { while ($metas->fetch()) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$metas->meta_id, $metas->meta_id,
sprintf($this->replace, $this->core->blog->url . $this->core->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), sprintf($this->replace, $this->core->blog->url . $this->core->url->getBase('tag') . '/' . $metas->meta_id, '\\1'),
@ -63,7 +62,7 @@ class epcFilterTag extends epcFilter
$metas = $this->core->meta->getMetadata(['meta_type' => 'tag']); $metas = $this->core->meta->getMetadata(['meta_type' => 'tag']);
while($metas->fetch()) { while ($metas->fetch()) {
$list[] = libEPC::matchString( $list[] = libEPC::matchString(
$metas->meta_id, $metas->meta_id,
sprintf($this->widget, $this->core->blog->url . $this->core->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), sprintf($this->widget, $this->core->blog->url . $this->core->url->getBase('tag') . '/' . $metas->meta_id, '\\1'),
@ -109,7 +108,7 @@ class epcFilterSearch extends epcFilter
$searchs = explode(' ', $GLOBALS['_search']); $searchs = explode(' ', $GLOBALS['_search']);
foreach($searchs as $k => $v) { foreach ($searchs as $k => $v) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$v, $v,
sprintf($this->replace, '\\1'), sprintf($this->replace, '\\1'),
@ -149,7 +148,7 @@ class epcFilterAcronym extends epcFilter
public function publicContent($tag, $args) public function publicContent($tag, $args)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->replace, __($this->records()->epc_value), '\\1'), sprintf($this->replace, __($this->records()->epc_value), '\\1'),
@ -163,8 +162,8 @@ class epcFilterAcronym extends epcFilter
public function widgetList($content, $w, &$list) public function widgetList($content, $w, &$list)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = libEPC::matchString( $list[] = libEPC::matchString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->widget, __($this->records()->epc_value), '\\1'), sprintf($this->widget, __($this->records()->epc_value), '\\1'),
$content, $content,
@ -188,7 +187,7 @@ class epcFilterAbbreviation extends epcFilter
'htmltag' => 'a', 'htmltag' => 'a',
'class' => ['abbr.epc-abbr'], 'class' => ['abbr.epc-abbr'],
'replace' => '<abbr class="epc-abbr" title="%s">%s</abbr>', 'replace' => '<abbr class="epc-abbr" title="%s">%s</abbr>',
'widget' => '<abbr title="%s">%s</abbr>' 'widget' => '<abbr title="%s">%s</abbr>'
]); ]);
$this->setSettings([ $this->setSettings([
@ -203,7 +202,7 @@ class epcFilterAbbreviation extends epcFilter
public function publicContent($tag, $args) public function publicContent($tag, $args)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->replace, __($this->records()->epc_value), '\\1'), sprintf($this->replace, __($this->records()->epc_value), '\\1'),
@ -217,7 +216,7 @@ class epcFilterAbbreviation extends epcFilter
public function widgetList($content, $w, &$list) public function widgetList($content, $w, &$list)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = libEPC::matchString( $list[] = libEPC::matchString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->widget, __($this->records()->epc_value), '\\1'), sprintf($this->widget, __($this->records()->epc_value), '\\1'),
@ -242,7 +241,7 @@ class epcFilterDefinition extends epcFilter
'htmltag' => 'dfn', 'htmltag' => 'dfn',
'class' => ['dfn.epc-dfn'], 'class' => ['dfn.epc-dfn'],
'replace' => '<dfn class="epc-dfn" title="%s">%s</dfn>', 'replace' => '<dfn class="epc-dfn" title="%s">%s</dfn>',
'widget' => '<dfn class="epc-dfn" title="%s">%s</dfn>' 'widget' => '<dfn class="epc-dfn" title="%s">%s</dfn>'
]); ]);
$this->setSettings([ $this->setSettings([
@ -257,7 +256,7 @@ class epcFilterDefinition extends epcFilter
public function publicContent($tag, $args) public function publicContent($tag, $args)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->replace, __($this->records()->epc_value), '\\1'), sprintf($this->replace, __($this->records()->epc_value), '\\1'),
@ -271,7 +270,7 @@ class epcFilterDefinition extends epcFilter
public function widgetList($content, $w, &$list) public function widgetList($content, $w, &$list)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = libEPC::matchString( $list[] = libEPC::matchString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->widget, __($this->records()->epc_value), '\\1'), sprintf($this->widget, __($this->records()->epc_value), '\\1'),
@ -312,7 +311,7 @@ class epcFilterCitation extends epcFilter
public function publicContent($tag, $args) public function publicContent($tag, $args)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->replace, __($this->records()->epc_value), '\\1'), sprintf($this->replace, __($this->records()->epc_value), '\\1'),
@ -326,7 +325,7 @@ class epcFilterCitation extends epcFilter
public function widgetList($content, $w, &$list) public function widgetList($content, $w, &$list)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = libEPC::matchString( $list[] = libEPC::matchString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->widget, __($this->records()->epc_value), '\\1'), sprintf($this->widget, __($this->records()->epc_value), '\\1'),
@ -366,7 +365,7 @@ class epcFilterLink extends epcFilter
public function publicContent($tag, $args) public function publicContent($tag, $args)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->replace, '\\1', $this->records()->epc_value, '\\1'), sprintf($this->replace, '\\1', $this->records()->epc_value, '\\1'),
@ -380,7 +379,7 @@ class epcFilterLink extends epcFilter
public function widgetList($content, $w, &$list) public function widgetList($content, $w, &$list)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$list[] = libEPC::matchString( $list[] = libEPC::matchString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->widget, $this->records()->epc_value, $this->records()->epc_value, '\\1'), sprintf($this->widget, $this->records()->epc_value, $this->records()->epc_value, '\\1'),
@ -421,7 +420,7 @@ class epcFilterReplace extends epcFilter
public function publicContent($tag, $args) public function publicContent($tag, $args)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->replace, $this->records()->epc_value, '\\2'), sprintf($this->replace, $this->records()->epc_value, '\\2'),
@ -462,7 +461,7 @@ class epcFilterUpdate extends epcFilter
public function publicContent($tag, $args) public function publicContent($tag, $args)
{ {
while($this->records()->fetch()) { while ($this->records()->fetch()) {
$args[0] = libEPC::replaceString( $args[0] = libEPC::replaceString(
$this->records()->epc_key, $this->records()->epc_key,
sprintf($this->replace, '\\1', $this->records()->epc_value), sprintf($this->replace, '\\1', $this->records()->epc_value),
@ -511,4 +510,4 @@ class epcFilterTwitter extends epcFilter
return null; return null;
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -22,7 +21,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class adminEpcList extends adminGenericList 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()) { if ($filter->show()) {
@ -31,7 +30,7 @@ class adminEpcList extends adminGenericList
echo '<p><strong>' . __('No record') . '</strong></p>'; 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;
$epc_id = []; $epc_id = [];
@ -47,12 +46,12 @@ class adminEpcList extends adminGenericList
'date' => '<th scope="col">' . __('Date') . '</th>' 'date' => '<th scope="col">' . __('Date') . '</th>'
]; ];
$html_block = $html_block = '<div class="table-outer"><table><caption>' .
'<div class="table-outer"><table><caption>' . (
($filter->show() ? $filter->show() ?
sprintf(__('List of %s records matching the filter.'), $this->rs_count) : sprintf(__('List of %s records matching the filter.'), $this->rs_count) :
sprintf(__('List of %s records.'), $this->rs_count) sprintf(__('List of %s records.'), $this->rs_count)
). '</caption>' . ) . '</caption>' .
'<tr>' . implode($cols) . '</tr>%s</table>%s</div>'; '<tr>' . implode($cols) . '</tr>%s</table>%s</div>';
if ($enclose_block) { if ($enclose_block) {
@ -73,15 +72,15 @@ class adminEpcList extends adminGenericList
private function line($checked) private function line($checked)
{ {
$cols = [ $cols = [
'check' => '<td class="nowrap">' . form::checkbox(['epc_id[]'], $this->rs->epc_id, ['checked' => $checked]) . '</td>', 'check' => '<td class="nowrap">' . form::checkbox(['epc_id[]'], $this->rs->epc_id, ['checked' => $checked]) . '</td>',
'key' => '<td class="nowrap">' . html::escapeHTML($this->rs->epc_key) . '</td>', 'key' => '<td class="nowrap">' . html::escapeHTML($this->rs->epc_key) . '</td>',
'value' => '<td class="maximal">' . html::escapeHTML($this->rs->epc_value) . '</td>', 'value' => '<td class="maximal">' . html::escapeHTML($this->rs->epc_value) . '</td>',
'date' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . '</td>' 'date' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . '</td>'
]; ];
return return
'<tr class="line" id="p' . $this->rs->epc_id . '">' . '<tr class="line" id="p' . $this->rs->epc_id . '">' .
implode($cols) . implode($cols) .
'</tr>'; '</tr>';
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
# l10n # l10n
__('entry excerpt');__('entry content');__('comment content'); __('entry excerpt');__('entry content');__('comment content');
__('home page');__('post page');__('category page');__('search results page'); __('home page');__('post page');__('category page');__('search results page');
@ -19,7 +18,7 @@ __('atom feeds');__('RSS feeds');
class libEPC class libEPC
{ {
protected static $default_filters = null; protected static $default_filters = null;
public static $epcFilterLimit = []; public static $epcFilterLimit = [];
# #
# Default definition # Default definition
@ -103,15 +102,15 @@ class libEPC
global $core; global $core;
if (self::$default_filters === null) { if (self::$default_filters === null) {
$final = $sort = []; $final = $sort = [];
$filters = new arrayObject(); $filters = new arrayObject();
try { try {
$core->callBehavior('enhancePostContentFilters', $filters, $core); $core->callBehavior('enhancePostContentFilters', $filters, $core);
foreach($filters as $filter) { foreach ($filters as $filter) {
if ($filter instanceOf epcFilter && !isset($final[$filter->id()])) { if ($filter instanceof epcFilter && !isset($final[$filter->id()])) {
$sort[$filter->id()] = $filter->priority; $sort[$filter->id()] = $filter->priority;
$final[$filter->id()] = $filter; $final[$filter->id()] = $filter;
} }
} }
@ -127,10 +126,10 @@ class libEPC
public static function testContext($tag, $args, $filter) public static function testContext($tag, $args, $filter)
{ {
return is_array($filter->pubPages) return is_array($filter->pubPages)
&& in_array($GLOBALS['_ctx']->current_tpl,$filter->pubPages) && in_array($GLOBALS['_ctx']->current_tpl, $filter->pubPages)
&& is_array($filter->tplValues) && is_array($filter->tplValues)
&& in_array($tag, $filter->tplValues) && in_array($tag, $filter->tplValues)
&& $args[0] != '' //content && $args[0] != '' //content
&& empty($args[2]) // remove html && empty($args[2]) // remove html
; ;
@ -158,7 +157,7 @@ class libEPC
return $s; return $s;
} }
# Remove words that are into unwanted html tags # Remove words that are into unwanted html tags
$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)) { if (is_array($ignore_tags) && !empty($ignore_tags)) {
$tags = implode('|', $ignore_tags); $tags = implode('|', $ignore_tags);
@ -190,14 +189,15 @@ class libEPC
} }
# Build array # Build array
$m = []; $m = [];
$loop = 0; $loop = 0;
foreach($matches[1] as $match) { foreach ($matches[1] as $match) {
$m[$loop]['key'] = $match; $m[$loop]['key'] = $match;
$m[$loop]['match'] = preg_replace('#(' . $p . '(s|))#s' . $i, $r, $match, -1, $count); $m[$loop]['match'] = preg_replace('#(' . $p . '(s|))#s' . $i, $r, $match, -1, $count);
$m[$loop]['num'] = $count; $m[$loop]['num'] = $count;
$loop++; $loop++;
} }
return ['total' => $t, 'matches' => $m]; return ['total' => $t, 'matches' => $m];
} }
@ -226,9 +226,10 @@ class libEPC
} }
$r = ''; $r = '';
foreach($a as $k => $v) { foreach ($a as $k => $v) {
$r .= $k . ':' . $v . ';'; $r .= $k . ':' . $v . ';';
} }
return $r; return $r;
} }
@ -247,7 +248,7 @@ class libEPC
return []; return [];
} }
foreach($s as $cpl) { foreach ($s as $cpl) {
$cur = explode(':', $cpl); $cur = explode(':', $cpl);
if (!is_array($cur) || !isset($cur[1])) { if (!is_array($cur) || !isset($cur[1])) {
@ -263,6 +264,7 @@ class libEPC
$r[$key] = $val; $r[$key] = $val;
} }
return $r; return $r;
} }
@ -310,7 +312,7 @@ class libEPC
return null; return null;
} }
$res = ''; $res = '';
$post_ids = []; $post_ids = [];
while ($_ctx->posts->fetch()) { while ($_ctx->posts->fetch()) {
$comments = $core->blog->getComments(['post_id' => $_ctx->posts->post_id]); $comments = $core->blog->getComments(['post_id' => $_ctx->posts->post_id]);
@ -321,4 +323,4 @@ class libEPC
return $res; return $res;
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class epcRecords class epcRecords
{ {
public $core; public $core;
@ -20,10 +19,10 @@ class epcRecords
public function __construct($core) public function __construct($core)
{ {
$this->core = $core; $this->core = $core;
$this->con = $core->con; $this->con = $core->con;
$this->table = $core->prefix . 'epc'; $this->table = $core->prefix . 'epc';
$this->blog = $core->con->escape($core->blog->id); $this->blog = $core->con->escape($core->blog->id);
} }
public function getRecords($params, $count_only = false) public function getRecords($params, $count_only = false)
@ -35,14 +34,12 @@ class epcRecords
if (!empty($params['columns']) && is_array($params['columns'])) { if (!empty($params['columns']) && is_array($params['columns'])) {
$content_req .= implode(', ', $params['columns']) . ', '; $content_req .= implode(', ', $params['columns']) . ', ';
} }
$strReq = $strReq = 'SELECT E.epc_id, E.blog_id, E.epc_type, E.epc_upddt, ' .
'SELECT E.epc_id, E.blog_id, E.epc_type, E.epc_upddt, ' .
$content_req . $content_req .
'E.epc_filter, E.epc_key, E.epc_value '; 'E.epc_filter, E.epc_key, E.epc_value ';
} }
$strReq .= $strReq .= 'FROM ' . $this->table . ' E ';
'FROM ' . $this->table . ' E ';
if (!empty($params['from'])) { if (!empty($params['from'])) {
$strReq .= $params['from'] . ' '; $strReq .= $params['from'] . ' ';
@ -70,7 +67,7 @@ class epcRecords
if (!empty($params['epc_id'])) { if (!empty($params['epc_id'])) {
if (is_array($params['epc_id'])) { if (is_array($params['epc_id'])) {
array_walk($params['epc_id'], function(&$v, $k) { if ($v !==null) { $v = (integer) $v; }}); array_walk($params['epc_id'], function (&$v, $k) { if ($v !== null) { $v = (integer) $v; }});
} else { } else {
$params['epc_id'] = [(integer) $params['epc_id']]; $params['epc_id'] = [(integer) $params['epc_id']];
} }
@ -111,8 +108,8 @@ class epcRecords
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
try { try {
$cur->epc_id = $this->getNextId(); $cur->epc_id = $this->getNextId();
$cur->blog_id = $this->blog; $cur->blog_id = $this->blog;
$cur->epc_upddt = date('Y-m-d H:i:s'); $cur->epc_upddt = date('Y-m-d H:i:s');
$this->getCursor($cur); $this->getCursor($cur);
@ -121,6 +118,7 @@ class epcRecords
$this->con->unlock(); $this->con->unlock();
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
$this->trigger(); $this->trigger();
@ -141,7 +139,7 @@ class epcRecords
$cur->epc_upddt = date('Y-m-d H:i:s'); $cur->epc_upddt = date('Y-m-d H:i:s');
$cur->update("WHERE epc_id = " . $id . " AND blog_id = '" . $this->blog . "' "); $cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . $this->blog . "' ");
$this->trigger(); $this->trigger();
# --BEHAVIOR-- enhancePostContentAfterUpdRecord # --BEHAVIOR-- enhancePostContentAfterUpdRecord
@ -151,10 +149,10 @@ class epcRecords
public function isRecord($filter, $key, $not_id = null) public function isRecord($filter, $key, $not_id = null)
{ {
return 0 < $this->getRecords([ return 0 < $this->getRecords([
'epc_filter' => $filter, 'epc_filter' => $filter,
'epc_key' => $key, 'epc_key' => $key,
'not_id' => $not_id 'not_id' => $not_id
], true)->f(0); ], true)->f(0);
} }
public function delRecord($id) public function delRecord($id)
@ -170,7 +168,7 @@ class epcRecords
$this->con->execute( $this->con->execute(
'DELETE FROM ' . $this->table . ' ' . 'DELETE FROM ' . $this->table . ' ' .
'WHERE epc_id = ' . $id .' ' . 'WHERE epc_id = ' . $id . ' ' .
"AND blog_id = '" . $this->blog . "' " "AND blog_id = '" . $this->blog . "' "
); );
@ -207,4 +205,4 @@ class epcRecords
{ {
$this->core->blog->triggerBlog(); $this->core->blog->triggerBlog();
} }
} }

View file

@ -1,51 +1,50 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
# Move 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, '>=')) { 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()) { while ($f->fetch()) {
if (preg_match('#enhancePostContent_(.*?)List#', $f->setting_id, $m)) { if (preg_match('#enhancePostContent_(.*?)List#', $f->setting_id, $m)) {
$curlist = @unserialize($f->setting_value); $curlist = @unserialize($f->setting_value);
if (is_array($curlist)) { if (is_array($curlist)) {
foreach($curlist as $k => $v) { foreach ($curlist as $k => $v) {
$cur = $core->con->openCursor($core->prefix . 'epc'); $cur = $core->con->openCursor($core->prefix . 'epc');
$core->con->writeLock($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->epc_id = $core->con->select('SELECT MAX(epc_id) FROM ' . $core->prefix . 'epc' . ' ')->f(0) + 1;
$cur->blog_id = $f->blog_id; $cur->blog_id = $f->blog_id;
$cur->epc_filter = strtolower($m[1]); $cur->epc_filter = strtolower($m[1]);
$cur->epc_key = $k; $cur->epc_key = $k;
$cur->epc_value = $v; $cur->epc_value = $v;
$cur->insert(); $cur->insert();
$core->con->unlock(); $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 # Move old filter name to filter id
} elseif ($old_version && version_compare('2021.10.05', $old_version, '>=')) { } elseif ($old_version && version_compare('2021.10.05', $old_version, '>=')) {
$rs = $core->con->select('SELECT epc_id, epc_filter FROM ' . $core->prefix . 'epc'); $rs = $core->con->select('SELECT epc_id, epc_filter FROM ' . $core->prefix . 'epc');
while($rs->fetch()) { while ($rs->fetch()) {
$cur = $core->con->openCursor($core->prefix . 'epc'); $cur = $core->con->openCursor($core->prefix . 'epc');
$cur->epc_filter = strtolower($rs->epc_filter); $cur->epc_filter = strtolower($rs->epc_filter);
$cur->update("WHERE epc_id = " . $rs->epc_id . " "); $cur->update('WHERE epc_id = ' . $rs->epc_id . ' ');
$core->blog->triggerBlog(); $core->blog->triggerBlog();
} }
} }

View file

@ -1,16 +1,15 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @brief enhancePostContent, a plugin for Dotclear 2
* *
* @package Dotclear * @package Dotclear
* @subpackage Plugin * @subpackage Plugin
* *
* @author Jean-Christian Denis and Contributors * @author Jean-Christian Denis and Contributors
* *
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -22,12 +21,12 @@ dcPage::check('contentadmin');
$_filters = libEPC::getFilters(); $_filters = libEPC::getFilters();
$filters_id = $filters_combo = []; $filters_id = $filters_combo = [];
foreach($_filters as $id => $filter) { foreach ($_filters as $id => $filter) {
$filters_id[$id] = $filter->name; $filters_id[$id] = $filter->name;
$filters_combo[$filter->name] = $id; $filters_combo[$filter->name] = $id;
} }
$action = $_POST['action'] ?? ''; $action = $_POST['action'] ?? '';
$part = $_REQUEST['part'] ?? key($filters_id); $part = $_REQUEST['part'] ?? key($filters_id);
if (!isset($filters_id[$part])) { if (!isset($filters_id[$part])) {
@ -69,7 +68,7 @@ try {
); );
$core->adminurl->redirect( $core->adminurl->redirect(
'admin.plugin.enhancePostContent', 'admin.plugin.enhancePostContent',
['part' => $part], ['part' => $part],
'#settings' '#settings'
); );
@ -80,7 +79,7 @@ try {
&& !empty($_POST['new_key']) && !empty($_POST['new_key'])
&& !empty($_POST['new_value']) && !empty($_POST['new_value'])
) { ) {
$cur = $records->openCursor(); $cur = $records->openCursor();
$cur->epc_filter = $filter->id(); $cur->epc_filter = $filter->id();
$cur->epc_key = html::escapeHTML($_POST['new_key']); $cur->epc_key = html::escapeHTML($_POST['new_key']);
$cur->epc_value = html::escapeHTML($_POST['new_value']); $cur->epc_value = html::escapeHTML($_POST['new_value']);
@ -97,17 +96,17 @@ try {
); );
} }
$core->adminurl->redirect( $core->adminurl->redirect(
'admin.plugin.enhancePostContent', 'admin.plugin.enhancePostContent',
['part' => $part], ['part' => $part],
'#record' '#record'
); );
} }
# Update filter records # Update filter records
if ($action == 'deleterecords' && $filter->has_list if ($action == 'deleterecords' && $filter->has_list
&& !empty($_POST['epc_id']) && is_array($_POST['epc_id']) && !empty($_POST['epc_id']) && is_array($_POST['epc_id'])
) { ) {
foreach($_POST['epc_id'] as $id) { foreach ($_POST['epc_id'] as $id) {
$records->delRecord($id); $records->delRecord($id);
} }
@ -121,13 +120,13 @@ try {
http::redirect($_REQUEST['redir']); http::redirect($_REQUEST['redir']);
} else { } else {
$core->adminurl->redirect( $core->adminurl->redirect(
'admin.plugin.enhancePostContent', 'admin.plugin.enhancePostContent',
['part' => $part], ['part' => $part],
'#record' '#record'
); );
} }
} }
} catch(Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
@ -138,19 +137,18 @@ if ($filter->has_list) {
$sorts->add(dcAdminFilters::getPageFilter()); $sorts->add(dcAdminFilters::getPageFilter());
$sorts->add('part', $part); $sorts->add('part', $part);
$params = $sorts->params(); $params = $sorts->params();
$params['epc_filter'] = $filter->id(); $params['epc_filter'] = $filter->id();
try { try {
$list = $records->getRecords($params); $list = $records->getRecords($params);
$counter = $records->getRecords($params, true); $counter = $records->getRecords($params, true);
$pager = new adminEpcList($core, $list, $counter->f(0)); $pager = new adminEpcList($core, $list, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
$header = $sorts->js($core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $part], '&').'#record'); $header = $sorts->js($core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $part], '&') . '#record');
} }
# -- Display page -- # -- Display page --
@ -196,7 +194,7 @@ echo '
<div class="two-boxes odd"> <div class="two-boxes odd">
<h4>' . __('Pages to be filtered') . '</h4>'; <h4>' . __('Pages to be filtered') . '</h4>';
foreach(libEPC::blogAllowedPubPages() as $k => $v) { foreach (libEPC::blogAllowedPubPages() as $k => $v) {
echo ' echo '
<p><label for="filter_pubPages' . $v . '">' . <p><label for="filter_pubPages' . $v . '">' .
form::checkbox( form::checkbox(
@ -228,7 +226,7 @@ form::number('filter_limit', ['min' => 0, 'max' => 99, 'default' => (integer) $f
</div><div class="two-boxes odd"> </div><div class="two-boxes odd">
<h4>' . __('Contents to be filtered') . '</h4>'; <h4>' . __('Contents to be filtered') . '</h4>';
foreach(libEPC::blogAllowedTplValues() as $k => $v) { foreach (libEPC::blogAllowedTplValues() as $k => $v) {
echo ' echo '
<p><label for="filter_tplValues' . $v . '">' . <p><label for="filter_tplValues' . $v . '">' .
form::checkbox( form::checkbox(
@ -243,12 +241,12 @@ echo '
</div><div class="two-boxes even"> </div><div class="two-boxes even">
<h4>' . __('Style') . '</h4>'; <h4>' . __('Style') . '</h4>';
foreach($filter->class as $k => $v) { foreach ($filter->class as $k => $v) {
echo ' echo '
<p><label for="filter_style' . $k . '">' . <p><label for="filter_style' . $k . '">' .
sprintf(__('Class "%s":'), $v) . '</label>' . sprintf(__('Class "%s":'), $v) . '</label>' .
form::field( form::field(
['filter_style[]', 'filter_style'.$k], ['filter_style[]', 'filter_style' . $k],
60, 60,
255, 255,
html::escapeHTML($filter->style[$k]) html::escapeHTML($filter->style[$k])
@ -279,24 +277,26 @@ form::hidden(['part'], $part) . '
# Filter records list # Filter records list
if ($filter->has_list) { if ($filter->has_list) {
$pager_url = $core->adminurl->get('admin.plugin.enhancePostContent', array_diff_key($sorts->values(true), ['page' => ''])).'&page=%s#record'; $pager_url = $core->adminurl->get('admin.plugin.enhancePostContent', array_diff_key($sorts->values(true), ['page' => ''])) . '&page=%s#record';
echo ' echo '
<div class="multi-part" id="record" title="' . __('Records') . '">'; <div class="multi-part" id="record" title="' . __('Records') . '">';
$sorts->display(['admin.plugin.enhancePostContent', '#record'], form::hidden('p', 'enhancePostContent') . form::hidden('part', $part)); $sorts->display(['admin.plugin.enhancePostContent', '#record'], form::hidden('p', 'enhancePostContent') . form::hidden('part', $part));
$pager->display($sorts, $pager_url, $pager->display(
$sorts,
$pager_url,
'<form action="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '#record" method="post" id="form-records">' . '<form action="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '#record" method="post" id="form-records">' .
'%s' . '%s' .
'<div class="two-cols">' . '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' . '<p class="col right">' .
form::hidden('action', 'deleterecords') . form::hidden('action', 'deleterecords') .
'<input id="del-action" type="submit" name="save" value="' . __('Delete selected records') . '" /></p>' . '<input id="del-action" type="submit" name="save" value="' . __('Delete selected records') . '" /></p>' .
$core->adminurl->getHiddenFormFields('admin.plugin.enhancePostContent', array_merge(['p' => 'enhancePostContent'], $sorts->values(true))) . $core->adminurl->getHiddenFormFields('admin.plugin.enhancePostContent', array_merge(['p' => 'enhancePostContent'], $sorts->values(true))) .
form::hidden('redir', $core->adminurl->get('admin.plugin.enhancePostContent', $sorts->values(true))) . form::hidden('redir', $core->adminurl->get('admin.plugin.enhancePostContent', $sorts->values(true))) .
$core->formNonce() . $core->formNonce() .
'</div>' . '</div>' .
@ -311,11 +311,11 @@ if ($filter->has_list) {
<form action="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '#record" method="post" id="form-create">' . <form action="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '#record" method="post" id="form-create">' .
'<p><label for="new_key">' . __('Key:') . '</label>' . '<p><label for="new_key">' . __('Key:') . '</label>' .
form::field('new_key', 60, 255, ['extra_html' => 'required']) . form::field('new_key', 60, 255, ['extra_html' => 'required']) .
'</p>' . '</p>' .
'<p><label for="new_value">' . __('Value:') . '</label>' . '<p><label for="new_value">' . __('Value:') . '</label>' .
form::field('new_value', 60, 255, ['extra_html' => 'required']) . form::field('new_value', 60, 255, ['extra_html' => 'required']) .
'</p> '</p>
<p class="clear">' . <p class="clear">' .
@ -333,4 +333,4 @@ $core->callBehavior('enhancePostContentAdminPage', $core);
dcPage::helpBlock('enhancePostContent'); dcPage::helpBlock('enhancePostContent');
echo '</body></html>'; echo '</body></html>';

View file

@ -2,9 +2,9 @@
# -- BEGIN LICENSE BLOCK ---------------------------------- # -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of enhancePostContent, a plugin for Dotclear 2. # This file is part of enhancePostContent, a plugin for Dotclear 2.
# #
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors # Copyright (c) 2009-2021 Jean-Christian Denis and contributors
# #
# Licensed under the GPL version 2.0 license. # Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at # A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@ -15,4 +15,4 @@ if (!defined('DC_RC_PATH')) {
return; return;
} }
$__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html'; $__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html';

View file

@ -2,9 +2,9 @@
# -- BEGIN LICENSE BLOCK ---------------------------------- # -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of enhancePostContent, a plugin for Dotclear 2. # This file is part of enhancePostContent, a plugin for Dotclear 2.
# #
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors # Copyright (c) 2009-2021 Jean-Christian Denis and contributors
# #
# Licensed under the GPL version 2.0 license. # Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at # A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@ -15,4 +15,4 @@ if (!defined('DC_RC_PATH')) {
return; return;
} }
$__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html'; $__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html';