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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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