update php code to PSR-2 and short array

master
Jean-Christian Paul Denis 2021-08-24 22:05:23 +02:00
parent 450ada59a1
commit 64e42494ca
14 changed files with 1668 additions and 1740 deletions

View File

@ -2,12 +2,14 @@ enhancePostContent xxxx.xx.xx
* Not added priority on filters for replacement order * Not added priority on filters for replacement order
* Not added priority on lists of filters for replacement order * Not added priority on lists of filters for replacement order
* Not added auto-find post title in content * Not added auto-find post title in content
* move settings from plugin to blog
enhancePostContent 2021.08.xx enhancePostContent 2021.08.xx
* switch to Dotclear 2.19 * switch to Dotclear 2.19
* switch to php 7.3+ and php 8.0.x * switch to php 7.3+ and php 8.0.x
* switch to Github * switch to Github
* update license * update license
* update php code to PSR-2 and short array
enhancePostContent 2013.11.08 enhancePostContent 2013.11.08
* Switch to Dotclear 2.6 (admin styles and settings) * Switch to Dotclear 2.6 (admin styles and settings)

View File

@ -12,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -32,24 +31,24 @@ $_menu['Blog']->addItem(
$core->addBehavior( $core->addBehavior(
'adminDashboardFavorites', 'adminDashboardFavorites',
array('epcAdminBehaviors', 'adminDashboardFavorites') ['epcAdminBehaviors', 'adminDashboardFavorites']
); );
class epcAdminBehaviors class epcAdminBehaviors
{ {
public static function adminDashboardFavorites($core, $favs) public static function adminDashboardFavorites($core, $favs)
{ {
$favs->register('enhancePostContent', array( $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' => array( 'active_cb' => [
'epcAdminBehaviors', 'epcAdminBehaviors',
'adminDashboardFavoritesActive' 'adminDashboardFavoritesActive'
) ]
)); ]);
} }
public static function adminDashboardFavoritesActive($request, $params) public static function adminDashboardFavoritesActive($request, $params)

View File

@ -12,24 +12,19 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$this->registerModule( $this->registerModule(
/* Name */ 'Enhance post content',
"Enhance post content", 'Add features to words in post content',
/* Description*/ 'Jean-Christian Denis and Contributors',
"Add features to words in post content", '2021.08.0',
/* Author */ [
"Jean-Christian Denis",
/* Version */
'2013.11.08',
array(
'permissions' => 'contentadmin', 'permissions' => 'contentadmin',
'type' => 'plugin', 'type' => 'plugin',
'dc_min' => '2.6', 'dc_min' => '2.18',
'support' => 'http://jcd.lv/q=enhancePostContent', 'support' => 'https://github.com/JcDenis/enhancePostContent',
'details' => 'http://plugins.dotaddict.org/dc2/details/enhancePostContent' 'details' => 'https://plugins.dotaddict.org/dc2/details/enhancePostContent'
) ]
); );

View File

@ -12,22 +12,19 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$dc_min = '2.6'; $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);
if (version_compare($old_version, $new_version, '>=')) { if (version_compare($old_version, $new_version, '>=')) {
return null; return null;
} }
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)) {
@ -72,14 +69,14 @@ try
$filters = libEPC::defaultFilters(); $filters = libEPC::defaultFilters();
foreach($filters as $name => $filter) { foreach($filters as $name => $filter) {
# Only editable options # Only editable options
$opt = array( $opt = [
'nocase' => $filter['nocase'], 'nocase' => $filter['nocase'],
'plural' => $filter['plural'], 'plural' => $filter['plural'],
'style' => $filter['style'], 'style' => $filter['style'],
'notag' => $filter['notag'], 'notag' => $filter['notag'],
'tplValues' => $filter['tplValues'], 'tplValues' => $filter['tplValues'],
'pubPages' => $filter['pubPages'] 'pubPages' => $filter['pubPages']
); ];
$s->put('enhancePostContent_' . $name, serialize($opt), 'string', 'Settings for ' . $name, false, true); $s->put('enhancePostContent_' . $name, serialize($opt), 'string', 'Settings for ' . $name, false, true);
# only tables # only tables
if (isset($filter['list'])) { if (isset($filter['list'])) {
@ -96,8 +93,7 @@ try
$core->setVersion($mod_id, $new_version); $core->setVersion($mod_id, $new_version);
return true; return true;
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }

View File

@ -12,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }

View File

@ -12,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -24,11 +23,11 @@ if ($core->blog->settings->enhancePostContent->enhancePostContent_active) {
$core->addBehavior( $core->addBehavior(
'publicHeadContent', 'publicHeadContent',
array('publicEnhancePostContent', 'publicHeadContent') ['publicEnhancePostContent', 'publicHeadContent']
); );
$core->addBehavior( $core->addBehavior(
'publicBeforeContentFilter', 'publicBeforeContentFilter',
array('publicEnhancePostContent', 'publicContentFilter') ['publicEnhancePostContent', 'publicContentFilter']
); );
} }
@ -51,8 +50,7 @@ class publicEnhancePostContent
foreach($filters as $name => $filter) { foreach($filters as $name => $filter) {
if (empty($filter['class']) if (empty($filter['class'])
|| empty($filter['style']) || empty($filter['style'])) {
) {
continue; continue;
} }
@ -88,8 +86,7 @@ class publicEnhancePostContent
if (!isset($filter['publicContentFilter']) if (!isset($filter['publicContentFilter'])
|| !is_callable($filter['publicContentFilter']) || !is_callable($filter['publicContentFilter'])
|| !libEPC::testContext($tag,$args,$filter) || !libEPC::testContext($tag,$args,$filter)) {
) {
continue; continue;
} }
@ -104,7 +101,7 @@ class publicEnhancePostContent
call_user_func_array( call_user_func_array(
$filter['publicContentFilter'], $filter['publicContentFilter'],
array($core, $filter, $tag, $args) [$core, $filter, $tag, $args]
); );
} }
} }

View File

@ -11,7 +11,9 @@
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')){return;} if (!defined('DC_CONTEXT_ADMIN')){
return;
}
$this->addUserAction( $this->addUserAction(
/* type */ 'settings', /* type */ 'settings',
@ -34,7 +36,6 @@ $this->addUserAction(
/* description */ __('delete the version number') /* description */ __('delete the version number')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'settings', /* type */ 'settings',
/* action */ 'delete_all', /* action */ 'delete_all',
@ -55,4 +56,3 @@ $this->addDirectAction(
/* ns */ 'enhancePostContent', /* ns */ 'enhancePostContent',
/* description */ sprintf(__('delete %s version number'), 'enhancePostContent') /* description */ sprintf(__('delete %s version number'), 'enhancePostContent')
); );
?>

View File

@ -12,13 +12,12 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$core->addBehavior( $core->addBehavior(
'initWidgets', 'initWidgets',
array('enhancePostContentWidget', 'adminContentList') ['enhancePostContentWidget', 'adminContentList']
); );
/** /**
@ -40,7 +39,7 @@ class enhancePostContentWidget
$w->create( $w->create(
'epclist', 'epclist',
__('Enhance post content'), __('Enhance post content'),
array('enhancePostContentWidget', 'publicContentList'), ['enhancePostContentWidget', 'publicContentList'],
null, null,
__('List filtered contents.') __('List filtered contents.')
); );
@ -60,12 +59,10 @@ class enhancePostContentWidget
); );
# Type # Type
$filters = libEPC::blogFilters(); $filters = libEPC::blogFilters();
$types = array(); $types = [];
foreach($filters as $name => $filter) foreach($filters as $name => $filter) {
{
if (!isset($filter['widgetListFilter']) if (!isset($filter['widgetListFilter'])
|| !is_callable($filter['widgetListFilter']) || !is_callable($filter['widgetListFilter'])) {
) {
continue; continue;
} }
@ -137,8 +134,7 @@ class enhancePostContentWidget
# Page # Page
if (!$core->blog->settings->enhancePostContent->enhancePostContent_active if (!$core->blog->settings->enhancePostContent->enhancePostContent_active
|| !in_array($_ctx->current_tpl,array('post.html','page.html')) || !in_array($_ctx->current_tpl, ['post.html', 'page.html'])) {
) {
return null; return null;
} }
@ -152,42 +148,39 @@ class enhancePostContentWidget
$content .= call_user_func_array( $content .= call_user_func_array(
$v['callback'], $v['callback'],
array($core,$w) [$core, $w]
); );
} }
} }
if (empty($content)) { if (empty($content)) {
return null; return null;
} }
# Filter # Filter
$list = array(); $list = [];
$filters = libEPC::blogFilters(); $filters = libEPC::blogFilters();
if (isset($filters[$w->type]) if (isset($filters[$w->type])
&& isset($filters[$w->type]['widgetListFilter']) && isset($filters[$w->type]['widgetListFilter'])
&& is_callable($filters[$w->type]['widgetListFilter']) && is_callable($filters[$w->type]['widgetListFilter'])) {
) {
$filters[$w->type]['nocase'] = $w->nocase; $filters[$w->type]['nocase'] = $w->nocase;
$filters[$w->type]['plural'] = $w->plural; $filters[$w->type]['plural'] = $w->plural;
if ($filters[$w->type]['has_list']) { if ($filters[$w->type]['has_list']) {
$records = new epcRecords($core); $records = new epcRecords($core);
$filters[$w->type]['list'] = $records->getRecords( $filters[$w->type]['list'] = $records->getRecords(
array('epc_filter' => $w->type) ['epc_filter' => $w->type]
); );
} }
call_user_func_array( call_user_func_array(
$filters[$w->type]['widgetListFilter'], $filters[$w->type]['widgetListFilter'],
array($core, $filters[$w->type], $content, $w, &$list) [$core, $filters[$w->type], $content, $w, &$list]
); );
} }
if (empty($list)) { if (empty($list)) {
return null; return null;
} }
@ -205,7 +198,6 @@ class enhancePostContentWidget
} }
if (empty($res)) { if (empty($res)) {
return null; return null;
} }

View File

@ -26,11 +26,11 @@ class libEPC
public static function defaultAllowedTplValues() public static function defaultAllowedTplValues()
{ {
return array( return [
'entry excerpt' => 'EntryExcerpt', 'entry excerpt' => 'EntryExcerpt',
'entry content' => 'EntryContent', 'entry content' => 'EntryContent',
'comment content' => 'CommentContent', 'comment content' => 'CommentContent',
); ];
} }
public static function blogAllowedTplValues() public static function blogAllowedTplValues()
@ -46,20 +46,20 @@ class libEPC
{ {
global $core; global $core;
$rs = array( $rs = [
'entry excerpt' => array( 'entry excerpt' => [
'id' => 'entryexcerpt', 'id' => 'entryexcerpt',
'callback' => array('libEPC','widgetContentEntryExcerpt') 'callback' => ['libEPC','widgetContentEntryExcerpt']
), ],
'entry content' => array( 'entry content' => [
'id' => 'entrycontent', 'id' => 'entrycontent',
'callback' => array('libEPC','widgetContentEntryContent') 'callback' => ['libEPC','widgetContentEntryContent']
), ],
'comment content' => array( 'comment content' => [
'id' => 'commentcontent', 'id' => 'commentcontent',
'callback' => array('libEPC','widgetContentCommentContent') 'callback' => ['libEPC','widgetContentCommentContent']
) ]
); ];
$core->callBehavior('enhancePostContentAllowedWidgetValues', $rs); $core->callBehavior('enhancePostContentAllowedWidgetValues', $rs);
@ -68,14 +68,14 @@ class libEPC
public static function defaultAllowedPubPages() public static function defaultAllowedPubPages()
{ {
return array( return [
'home page' => 'home.html', 'home page' => 'home.html',
'post page' => 'post.html', 'post page' => 'post.html',
'category page' => 'category.html', 'category page' => 'category.html',
'search results page' => 'search.html', 'search results page' => 'search.html',
'atom feeds' => 'atom.xml', 'atom feeds' => 'atom.xml',
'RSS feeds' => 'rss2.xml' 'RSS feeds' => 'rss2.xml'
); ];
} }
public static function blogAllowedPubPages() public static function blogAllowedPubPages()
@ -91,200 +91,200 @@ class libEPC
{ {
global $core; global $core;
$filters = array( $filters = [
'Tag' => array( 'Tag' => [
'id' => 'tag', 'id' => 'tag',
'publicContentFilter' => array('libEPC','publicContentFilterTag'), 'publicContentFilter' => ['libEPC', 'publicContentFilterTag'],
'widgetListFilter' => array('libEPC','widgetListTag'), 'widgetListFilter' => ['libEPC', 'widgetListTag'],
'help' => __('Highlight tags of your blog.'), 'help' => __('Highlight tags of your blog.'),
'has_list' => false, 'has_list' => false,
'htmltag' => 'a', 'htmltag' => 'a',
'class' => array('a.epc-tag'), 'class' => ['a.epc-tag'],
'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>', 'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>',
'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>', 'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>',
'nocase' => false, 'nocase' => false,
'plural' => false, 'plural' => false,
'limit' => 0, 'limit' => 0,
'style' => array('text-decoration: none; border-bottom: 3px double #CCCCCC;'), 'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'],
'notag' => 'a,h1,h2,h3', 'notag' => 'a,h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html') 'pubPages' => ['post.html']
), ],
'Search' => array( 'Search' => [
'id' => 'search', 'id' => 'search',
'publicContentFilter' => array('libEPC','publicContentFilterSearch'), 'publicContentFilter' => ['libEPC', 'publicContentFilterSearch'],
'help' => __('Highlight searched words.'), 'help' => __('Highlight searched words.'),
'has_list' => false, 'has_list' => false,
'htmltag' => '', 'htmltag' => '',
'class' => array('span.epc-search'), 'class' => ['span.epc-search'],
'replace' => '<span class="epc-search" title="' . __('Search') . '">%s</span>', 'replace' => '<span class="epc-search" title="' . __('Search') . '">%s</span>',
'nocase' => true, 'nocase' => true,
'plural' => true, 'plural' => true,
'limit' => 0, 'limit' => 0,
'style' => array('color: #FFCC66;'), 'style' => ['color: #FFCC66;'],
'notag' => 'h1,h2,h3', 'notag' => 'h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('search.html') 'pubPages' => ['search.html']
), ],
'Acronym' => array( 'Acronym' => [
'id' => 'acronym', 'id' => 'acronym',
'publicContentFilter' => array('libEPC','publicContentFilterAcronym'), 'publicContentFilter' => ['libEPC', 'publicContentFilterAcronym'],
'widgetListFilter' => array('libEPC','widgetListAcronym'), 'widgetListFilter' => ['libEPC', 'widgetListAcronym'],
'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'), 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'),
'has_list' => true, 'has_list' => true,
'htmltag' => 'acronym', 'htmltag' => 'acronym',
'class' => array('acronym.epc-acronym'), 'class' => ['acronym.epc-acronym'],
'replace' => '<acronym class="epc-acronym" title="%s">%s</acronym>', 'replace' => '<acronym class="epc-acronym" title="%s">%s</acronym>',
'widget' => '<acronym title="%s">%s</acronym>', 'widget' => '<acronym title="%s">%s</acronym>',
'nocase' => false, 'nocase' => false,
'plural' => false, 'plural' => false,
'limit' => 0, 'limit' => 0,
'style' => array('font-weight: bold;'), 'style' => ['font-weight: bold;'],
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html'), 'pubPages' => ['post.html'],
), ],
'Abbreviation' => array( 'Abbreviation' => [
'id' => 'abbreviation', 'id' => 'abbreviation',
'publicContentFilter' => array('libEPC','publicContentFilterAbbreviation'), 'publicContentFilter' => ['libEPC', 'publicContentFilterAbbreviation'],
'widgetListFilter' => array('libEPC','widgetListAbbreviation'), 'widgetListFilter' => ['libEPC', 'widgetListAbbreviation'],
'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'), 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'),
'has_list' => true, 'has_list' => true,
'htmltag' => 'a', 'htmltag' => 'a',
'class' => array('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>',
'nocase' => false, 'nocase' => false,
'plural' => false, 'plural' => false,
'limit' => 0, 'limit' => 0,
'style' => array('font-weight: bold;'), 'style' => ['font-weight: bold;'],
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html'), 'pubPages' => ['post.html'],
), ],
'Definition' => array( 'Definition' => [
'id' => 'definition', 'id' => 'definition',
'publicContentFilter' => array('libEPC','publicContentFilterDefinition'), 'publicContentFilter' => ['libEPC', 'publicContentFilterDefinition'],
'widgetListFilter' => array('libEPC','widgetListDefinition'), 'widgetListFilter' => ['libEPC', 'widgetListDefinition'],
'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'), 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'),
'has_list' => true, 'has_list' => true,
'htmltag' => 'dfn', 'htmltag' => 'dfn',
'class' => array('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>',
'nocase' => false, 'nocase' => false,
'plural' => false, 'plural' => false,
'limit' => 0, 'limit' => 0,
'style' => array('font-weight: bold;'), 'style' => ['font-weight: bold;'],
'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html'), 'pubPages' => ['post.html'],
), ],
'Citation' => array( 'Citation' => [
'id' => 'citation', 'id' => 'citation',
'publicContentFilter' => array('libEPC','publicContentFilterCitation'), 'publicContentFilter' => ['libEPC', 'publicContentFilterCitation'],
'widgetListFilter' => array('libEPC','widgetListCitation'), 'widgetListFilter' => ['libEPC', 'widgetListCitation'],
'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'), 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'),
'has_list' => true, 'has_list' => true,
'htmltag' => 'cite', 'htmltag' => 'cite',
'class' => array('cite.epc-cite'), 'class' => ['cite.epc-cite'],
'replace' => '<cite class="epc-cite" title="%s">%s</cite>', 'replace' => '<cite class="epc-cite" title="%s">%s</cite>',
'widget' => '<cite title="%s">%s</cite>', 'widget' => '<cite title="%s">%s</cite>',
'nocase' => true, 'nocase' => true,
'plural' => false, 'plural' => false,
'limit' => 0, 'limit' => 0,
'style' => array('font-style: italic;'), 'style' => ['font-style: italic;'],
'notag' => 'a,h1,h2,h3', 'notag' => 'a,h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html'), 'pubPages' => ['post.html'],
), ],
'Link' => array( 'Link' => [
'id' => 'link', 'id' => 'link',
'publicContentFilter' => array('libEPC','publicContentFilterLink'), 'publicContentFilter' => ['libEPC', 'publicContentFilterLink'],
'widgetListFilter' => array('libEPC','widgetListLink'), 'widgetListFilter' => ['libEPC', 'widgetListLink'],
'help' => __('Link some words. First term of the list is the term to link and second term the link.'), 'help' => __('Link some words. First term of the list is the term to link and second term the link.'),
'has_list' => true, 'has_list' => true,
'htmltag' => 'a', 'htmltag' => 'a',
'class' => array('a.epc-link'), 'class' => ['a.epc-link'],
'replace' => '<a class="epc-link" title="%s" href="%s">%s</a>', 'replace' => '<a class="epc-link" title="%s" href="%s">%s</a>',
'widget' => '<a title="%s" href="%s">%s</a>', 'widget' => '<a title="%s" href="%s">%s</a>',
'nocase' => false, 'nocase' => false,
'plural' => false, 'plural' => false,
'limit' => 0, 'limit' => 0,
'style' => array('text-decoration: none; font-style: italic; color: #0000FF;'), 'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'],
'notag' => 'a,h1,h2,h3', 'notag' => 'a,h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html'), 'pubPages' => ['post.html'],
), ],
'Replace' => array( 'Replace' => [
'id' => 'replace', 'id' => 'replace',
'publicContentFilter' => array('libEPC','publicContentFilterReplace'), 'publicContentFilter' => ['libEPC', 'publicContentFilterReplace'],
'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'), 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'),
'has_list' => true, 'has_list' => true,
'htmltag' => '', 'htmltag' => '',
'class' => array('span.epc-replace'), 'class' => ['span.epc-replace'],
'replace' => '<span class="epc-replace">%s</span>', 'replace' => '<span class="epc-replace">%s</span>',
'nocase' => true, 'nocase' => true,
'plural' => true, 'plural' => true,
'limit' => 0, 'limit' => 0,
'style' => array('font-style: italic;'), 'style' => ['font-style: italic;'],
'notag' => 'h1,h2,h3', 'notag' => 'h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html'), 'pubPages' => ['post.html'],
), ],
'Update' => array( 'Update' => [
'id' => 'update', 'id' => 'update',
'publicContentFilter' => array('libEPC','publicContentFilterUpdate'), 'publicContentFilter' => ['libEPC', 'publicContentFilterUpdate'],
'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'), 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'),
'has_list' => true, 'has_list' => true,
'htmltag' => 'del,ins', 'htmltag' => 'del,ins',
'class' => array('del.epc-update','ins.epc-update'), 'class' => ['del.epc-update', 'ins.epc-update'],
'replace' => '<del class="epc-update">%s</del> <ins class="epc-update">%s</ins>', 'replace' => '<del class="epc-update">%s</del> <ins class="epc-update">%s</ins>',
'nocase' => true, 'nocase' => true,
'plural' => true, 'plural' => true,
'limit' => 0, 'limit' => 0,
'style' => array('text-decoration: line-through;','font-style: italic;'), 'style' => ['text-decoration: line-through;', 'font-style: italic;'],
'notag' => 'h1,h2,h3', 'notag' => 'h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html'), 'pubPages' => ['post.html'],
), ],
'Twitter' => array( 'Twitter' => [
'id' => 'twitter', 'id' => 'twitter',
'publicContentFilter' => array('libEPC','publicContentFilterTwitter'), 'publicContentFilter' => ['libEPC', 'publicContentFilterTwitter'],
'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'), 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'),
'has_list' => false, 'has_list' => false,
'htmltag' => 'a', 'htmltag' => 'a',
'class' => array('a.epc-twitter'), 'class' => ['a.epc-twitter'],
'replace' => '<a class="epc-twitter" title="' . __("View this user's twitter page") . '" href="%s">%s</a>', 'replace' => '<a class="epc-twitter" title="' . __("View this user's twitter page") . '" href="%s">%s</a>',
'nocase' => false, 'nocase' => false,
'plural' => false, 'plural' => false,
'limit' => 0, 'limit' => 0,
'style' => array('text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'), 'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'],
'notag' => 'a,h1,h2,h3', 'notag' => 'a,h1,h2,h3',
'tplValues' => array('EntryContent'), 'tplValues' => ['EntryContent'],
'pubPages' => array('post.html') 'pubPages' => ['post.html']
) ]
); ];
$core->callBehavior('enhancePostContentDefaultFilters', $filters); $core->callBehavior('enhancePostContentDefaultFilters', $filters);
@ -297,42 +297,33 @@ class libEPC
$core->blog->settings->addNamespace('enhancePostContent'); $core->blog->settings->addNamespace('enhancePostContent');
$filters = self::defaultFilters(); $filters = self::defaultFilters();
foreach($filters as $name => $filter) foreach($filters as $name => $filter) {
{
# Parse filters options # Parse filters options
$ns = 'enhancePostContent_' . $name; $ns = 'enhancePostContent_' . $name;
$opt[$name] = @unserialize($core->blog->settings->enhancePostContent->$ns); $opt[$name] = @unserialize($core->blog->settings->enhancePostContent->$ns);
if (!is_array($opt[$name])) if (!is_array($opt[$name])) {
{ $opt[$name] = [];
$opt[$name] = array();
} }
if (isset($opt[$name]['nocase'])) if (isset($opt[$name]['nocase'])) {
{
$filters[$name]['nocase'] = (boolean) $opt[$name]['nocase']; $filters[$name]['nocase'] = (boolean) $opt[$name]['nocase'];
} }
if (isset($opt[$name]['plural'])) if (isset($opt[$name]['plural'])) {
{
$filters[$name]['plural'] = (boolean) $opt[$name]['plural']; $filters[$name]['plural'] = (boolean) $opt[$name]['plural'];
} }
if (isset($opt[$name]['limit'])) if (isset($opt[$name]['limit'])) {
{
$filters[$name]['limit'] = abs((integer) $opt[$name]['limit']); $filters[$name]['limit'] = abs((integer) $opt[$name]['limit']);
} }
if (isset($opt[$name]['style']) && is_array($opt[$name]['style'])) if (isset($opt[$name]['style']) && is_array($opt[$name]['style'])) {
{
$filters[$name]['style'] = (array) $opt[$name]['style']; $filters[$name]['style'] = (array) $opt[$name]['style'];
} }
if (isset($opt[$name]['notag'])) if (isset($opt[$name]['notag'])) {
{
$filters[$name]['notag'] = (string) $opt[$name]['notag']; $filters[$name]['notag'] = (string) $opt[$name]['notag'];
} }
if (isset($opt[$name]['tplValues'])) if (isset($opt[$name]['tplValues'])) {
{
$filters[$name]['tplValues'] = (array) $opt[$name]['tplValues']; $filters[$name]['tplValues'] = (array) $opt[$name]['tplValues'];
} }
if (isset($opt[$name]['pubPages'])) if (isset($opt[$name]['pubPages'])) {
{
$filters[$name]['pubPages'] = (array) $opt[$name]['pubPages']; $filters[$name]['pubPages'] = (array) $opt[$name]['pubPages'];
} }
} }
@ -359,10 +350,11 @@ class libEPC
public static function replaceString($p, $r, $s, $filter, $before = '\b', $after = '\b') public static function replaceString($p, $r, $s, $filter, $before = '\b', $after = '\b')
{ {
# Limit # Limit
if ($filter['limit'] > 0) if ($filter['limit'] > 0) {
{
$l = isset($GLOBALS['epcFilterLimit'][$filter['id']][$p]) ? $GLOBALS['epcFilterLimit'][$filter['id']][$p] : $filter['limit']; $l = isset($GLOBALS['epcFilterLimit'][$filter['id']][$p]) ? $GLOBALS['epcFilterLimit'][$filter['id']][$p] : $filter['limit'];
if ($l < 1) return $s; if ($l < 1) {
return $s;
}
} else { } else {
$l = -1; $l = -1;
} }
@ -373,17 +365,17 @@ class libEPC
# Mark words # Mark words
$s = preg_replace('#(' . $before . ')(' . $x . ')(' . $after . ')#s' . $i, '$1ççççç$2ççççç$3', $s, -1, $count); $s = preg_replace('#(' . $before . ')(' . $x . ')(' . $after . ')#s' . $i, '$1ççççç$2ççççç$3', $s, -1, $count);
# Nothing to parse # Nothing to parse
if (!$count) return $s; if (!$count) {
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);
} }
if (!empty($tags)) if (!empty($tags)) {
{ $s = preg_replace_callback('#(<(' . $tags . ')[^>]*?>)(.*?)(</\\2>)#s', ['libEPC', 'removeTags'], $s);
$s = preg_replace_callback('#(<('.$tags.')[^>]*?>)(.*?)(</\\2>)#s',array('libEPC','removeTags'),$s);
} }
# Remove words inside html tag (class, title, alt, href, ...) # Remove words inside html tag (class, title, alt, href, ...)
$s = preg_replace('#(ççççç(' . $p . '(s|))ççççç)(?=[^<]+>)#s' . $i, '$2$4', $s); $s = preg_replace('#(ççççç(' . $p . '(s|))ççççç)(?=[^<]+>)#s' . $i, '$2$4', $s);
@ -404,19 +396,20 @@ class libEPC
# Mark words # Mark words
$t = preg_match_all('#' . $before . '(' . $x . ')' . $after . '#s' . $i, $s, $matches); $t = preg_match_all('#' . $before . '(' . $x . ')' . $after . '#s' . $i, $s, $matches);
# Nothing to parse # Nothing to parse
if (!$t) return array('total'=>0,'matches'=>array()); if (!$t) {
return ['total' => 0, 'matches' => []];
}
# Build array # Build array
$m = array(); $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 array('total'=>$t,'matches'=>$m); return ['total' => $t, 'matches' => $m];
} }
public static function quote($s) public static function quote($s)
@ -431,17 +424,20 @@ class libEPC
public static function decodeTags($t) public static function decodeTags($t)
{ {
return preg_match_all('#([A-Za-z0-9]+)#',(string) $t, $m) ? $m[1] : array(); return preg_match_all('#([A-Za-z0-9]+)#', (string) $t, $m) ? $m[1] : [];
} }
public static function implode($a) public static function implode($a)
{ {
if (is_string($a)) return $a; if (is_string($a)) {
if (!is_array($a)) return array(); return $a;
}
if (!is_array($a)) {
return [];
}
$r = ''; $r = '';
foreach($a as $k => $v) foreach($a as $k => $v) {
{
$r .= $k . ':' . $v . ';'; $r .= $k . ':' . $v . ';';
} }
return $r; return $r;
@ -449,23 +445,32 @@ class libEPC
public static function explode($s) public static function explode($s)
{ {
if (is_array($s)) return $s; if (is_array($s)) {
if (!is_string($s)) return ''; return $s;
}
if (!is_string($s)) {
return '';
}
$r = array(); $r = [];
$s = explode(';', (string) $s); $s = explode(';', (string) $s);
if (!is_array($s)) return array(); if (!is_array($s)) {
return [];
}
foreach($s as $cpl) foreach($s as $cpl) {
{
$cur = explode(':', $cpl); $cur = explode(':', $cpl);
if (!is_array($cur) || !isset($cur[1])) continue; if (!is_array($cur) || !isset($cur[1])) {
continue;
}
$key = html::escapeHTML(trim($cur[0])); $key = html::escapeHTML(trim($cur[0]));
$val = html::escapeHTML(trim($cur[1])); $val = html::escapeHTML(trim($cur[1]));
if (empty($key) || empty($val)) continue; if (empty($key) || empty($val)) {
continue;
}
$r[$key] = $val; $r[$key] = $val;
} }
@ -479,11 +484,12 @@ class libEPC
public static function widgetContentEntryExcerpt($core, $w) public static function widgetContentEntryExcerpt($core, $w)
{ {
global $_ctx; global $_ctx;
if (!$_ctx->exists('posts')) return; if (!$_ctx->exists('posts')) {
return;
}
$res = ''; $res = '';
while ($_ctx->posts->fetch()) while ($_ctx->posts->fetch()) {
{
$res .= $_ctx->posts->post_excerpt; $res .= $_ctx->posts->post_excerpt;
} }
return $res; return $res;
@ -492,11 +498,12 @@ class libEPC
public static function widgetContentEntryContent() public static function widgetContentEntryContent()
{ {
global $_ctx; global $_ctx;
if (!$_ctx->exists('posts')) return; if (!$_ctx->exists('posts')) {
return;
}
$res = ''; $res = '';
while ($_ctx->posts->fetch()) while ($_ctx->posts->fetch()) {
{
$res .= $_ctx->posts->post_content; $res .= $_ctx->posts->post_content;
} }
return $res; return $res;
@ -505,15 +512,15 @@ class libEPC
public static function widgetContentCommentContent() public static function widgetContentCommentContent()
{ {
global $core, $_ctx; global $core, $_ctx;
if (!$_ctx->exists('posts')) return; if (!$_ctx->exists('posts')) {
return;
}
$res = ''; $res = '';
$post_ids = array(); $post_ids = [];
while ($_ctx->posts->fetch()) while ($_ctx->posts->fetch()) {
{ $comments = $core->blog->getComments(['post_id' => $_ctx->posts->post_id]);
$comments = $core->blog->getComments(array('post_id'=>$_ctx->posts->post_id)); while ($comments->fetch()) {
while ($comments->fetch())
{
$res .= $comments->getContent(); $res .= $comments->getContent();
} }
} }
@ -526,12 +533,13 @@ class libEPC
public static function publicContentFilterTag($core, $filter, $tag, $args) public static function publicContentFilterTag($core, $filter, $tag, $args)
{ {
if (!$core->plugins->moduleExists('tags')) return; if (!$core->plugins->moduleExists('tags')) {
return;
}
$metas = $core->meta->getMetadata(array('meta_type'=>'tag')); $metas = $core->meta->getMetadata(['meta_type' => 'tag']);
while($metas->fetch()) while($metas->fetch()) {
{
$k = $metas->meta_id; $k = $metas->meta_id;
$args[0] = self::replaceString( $args[0] = self::replaceString(
$k, $k,
@ -545,12 +553,13 @@ class libEPC
public static function widgetListTag($core, $filter, $content, $w, &$list) public static function widgetListTag($core, $filter, $content, $w, &$list)
{ {
if (!$core->plugins->moduleExists('tags')) return; if (!$core->plugins->moduleExists('tags')) {
return;
}
$metas = $core->meta->getMetadata(array('meta_type'=>'tag')); $metas = $core->meta->getMetadata(['meta_type' => 'tag']);
while($metas->fetch()) while($metas->fetch()) {
{
$k = $metas->meta_id; $k = $metas->meta_id;
$list[] = self::matchString( $list[] = self::matchString(
$k, $k,
@ -564,12 +573,13 @@ class libEPC
public static function publicContentFilterSearch($core, $filter, $tag, $args) public static function publicContentFilterSearch($core, $filter, $tag, $args)
{ {
if (!isset($GLOBALS['_search'])) return; if (!isset($GLOBALS['_search'])) {
return;
}
$searchs = explode(' ', $GLOBALS['_search']); $searchs = explode(' ', $GLOBALS['_search']);
foreach($searchs as $k => $v) foreach($searchs as $k => $v) {
{
$args[0] = self::replaceString( $args[0] = self::replaceString(
$v, $v,
sprintf($filter['replace'], '\\1'), sprintf($filter['replace'], '\\1'),
@ -582,8 +592,7 @@ class libEPC
public static function publicContentFilterAcronym($core, $filter, $tag, $args) public static function publicContentFilterAcronym($core, $filter, $tag, $args)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -599,8 +608,7 @@ class libEPC
public static function widgetListAcronym($core, $filter, $content, $w, &$list) public static function widgetListAcronym($core, $filter, $content, $w, &$list)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -616,8 +624,7 @@ class libEPC
public static function publicContentFilterAbbreviation($core, $filter, $tag, $args) public static function publicContentFilterAbbreviation($core, $filter, $tag, $args)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -633,8 +640,7 @@ class libEPC
public static function widgetListAbbreviation($core, $filter, $content, $w, &$list) public static function widgetListAbbreviation($core, $filter, $content, $w, &$list)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -650,8 +656,7 @@ class libEPC
public static function publicContentFilterDefinition($core, $filter, $tag, $args) public static function publicContentFilterDefinition($core, $filter, $tag, $args)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -667,8 +672,7 @@ class libEPC
public static function widgetListDefinition($core, $filter, $content, $w, &$list) public static function widgetListDefinition($core, $filter, $content, $w, &$list)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -684,8 +688,7 @@ class libEPC
public static function publicContentFilterCitation($core, $filter, $tag, $args) public static function publicContentFilterCitation($core, $filter, $tag, $args)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -701,8 +704,7 @@ class libEPC
public static function widgetListCitation($core, $filter, $content, $w, &$list) public static function widgetListCitation($core, $filter, $content, $w, &$list)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -718,8 +720,7 @@ class libEPC
public static function publicContentFilterLink($core, $filter, $tag, $args) public static function publicContentFilterLink($core, $filter, $tag, $args)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -735,8 +736,7 @@ class libEPC
public static function widgetListLink($core, $filter, $content, $w, &$list) public static function widgetListLink($core, $filter, $content, $w, &$list)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -752,8 +752,7 @@ class libEPC
public static function publicContentFilterReplace($core, $filter, $tag, $args) public static function publicContentFilterReplace($core, $filter, $tag, $args)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -769,8 +768,7 @@ class libEPC
public static function publicContentFilterUpdate($core, $filter, $tag, $args) public static function publicContentFilterUpdate($core, $filter, $tag, $args)
{ {
while($filter['list']->fetch()) while($filter['list']->fetch()) {
{
$k = $filter['list']->epc_key; $k = $filter['list']->epc_key;
$v = $filter['list']->epc_value; $v = $filter['list']->epc_value;
@ -791,9 +789,9 @@ class libEPC
sprintf($filter['replace'], 'http://twitter.com/\\1', '\\1'), sprintf($filter['replace'], 'http://twitter.com/\\1', '\\1'),
$args[0], $args[0],
$filter, $filter,
'[^@]@','\b' '[^@]@',
'\b'
); );
return; return;
} }
} }
?>

View File

@ -28,15 +28,11 @@ class epcRecords
public function getRecords($params, $count_only = false) public function getRecords($params, $count_only = false)
{ {
if ($count_only) if ($count_only) {
{
$strReq = 'SELECT count(E.epc_id) '; $strReq = 'SELECT count(E.epc_id) ';
} } else {
else
{
$content_req = ''; $content_req = '';
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 =
@ -48,73 +44,52 @@ class epcRecords
$strReq .= $strReq .=
'FROM ' . $this->table . ' E '; 'FROM ' . $this->table . ' E ';
if (!empty($params['from'])) if (!empty($params['from'])) {
{
$strReq .= $params['from'] . ' '; $strReq .= $params['from'] . ' ';
} }
$strReq .= "WHERE E.blog_id = '" . $this->blog . "' "; $strReq .= "WHERE E.blog_id = '" . $this->blog . "' ";
if (isset($params['epc_type'])) if (isset($params['epc_type'])) {
{ if (is_array($params['epc_type']) && !empty($params['epc_type'])) {
if (is_array($params['epc_type']) && !empty($params['epc_type']))
{
$strReq .= 'AND E.epc_type ' . $this->con->in($params['epc_type']); $strReq .= 'AND E.epc_type ' . $this->con->in($params['epc_type']);
} } elseif ($params['epc_type'] != '') {
elseif ($params['epc_type'] != '')
{
$strReq .= "AND E.epc_type = '" . $this->con->escape($params['epc_type']) . "' "; $strReq .= "AND E.epc_type = '" . $this->con->escape($params['epc_type']) . "' ";
} }
} } else {
else
{
$strReq .= "AND E.epc_type = 'epc' "; $strReq .= "AND E.epc_type = 'epc' ";
} }
if (isset($params['epc_filter'])) if (isset($params['epc_filter'])) {
{ if (is_array($params['epc_filter']) && !empty($params['epc_filter'])) {
if (is_array($params['epc_filter']) && !empty($params['epc_filter']))
{
$strReq .= 'AND E.epc_filter ' . $this->con->in($params['epc_filter']); $strReq .= 'AND E.epc_filter ' . $this->con->in($params['epc_filter']);
} } elseif ($params['epc_filter'] != '') {
elseif ($params['epc_filter'] != '')
{
$strReq .= "AND E.epc_filter = '" . $this->con->escape($params['epc_filter']) . "' "; $strReq .= "AND E.epc_filter = '" . $this->con->escape($params['epc_filter']) . "' ";
} }
} }
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'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); array_walk($params['epc_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
} } else {
else $params['epc_id'] = [(integer) $params['epc_id']];
{
$params['epc_id'] = array((integer) $params['epc_id']);
} }
$strReq .= 'AND E.epc_id ' . $this->con->in($params['epc_id']); $strReq .= 'AND E.epc_id ' . $this->con->in($params['epc_id']);
} }
if (!empty($params['sql'])) if (!empty($params['sql'])) {
{
$strReq .= $params['sql'] . ' '; $strReq .= $params['sql'] . ' ';
} }
if (!$count_only) if (!$count_only) {
{ if (!empty($params['order'])) {
if (!empty($params['order']))
{
$strReq .= 'ORDER BY ' . $this->con->escape($params['order']) . ' '; $strReq .= 'ORDER BY ' . $this->con->escape($params['order']) . ' ';
} } else {
else
{
$strReq .= 'ORDER BY E.epc_key ASC '; $strReq .= 'ORDER BY E.epc_key ASC ';
} }
} }
if (!$count_only && !empty($params['limit'])) if (!$count_only && !empty($params['limit'])) {
{
$strReq .= $this->con->limit($params['limit']); $strReq .= $this->con->limit($params['limit']);
} }
@ -125,8 +100,7 @@ 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');
@ -135,9 +109,7 @@ class epcRecords
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} } catch (Exception $e) {
catch (Exception $e)
{
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -153,8 +125,7 @@ class epcRecords
{ {
$id = (integer) $id; $id = (integer) $id;
if (empty($id)) if (empty($id)) {
{
throw new Exception(__('No such record ID')); throw new Exception(__('No such record ID'));
} }
@ -201,16 +172,13 @@ class epcRecords
private function getCursor($cur, $epc_id = null) private function getCursor($cur, $epc_id = null)
{ {
if ($cur->epc_key == '') if ($cur->epc_key == '') {
{
throw new Exception(__('No record key')); throw new Exception(__('No record key'));
} }
if ($cur->epc_value == '') if ($cur->epc_value == '') {
{
throw new Exception(__('No record value')); throw new Exception(__('No record value'));
} }
if ($cur->epc_filter == '') if ($cur->epc_filter == '') {
{
throw new Exception(__('No record filter')); throw new Exception(__('No record filter'));
} }
$epc_id = is_int($epc_id) ? $epc_id : $cur->epc_id; $epc_id = is_int($epc_id) ? $epc_id : $cur->epc_id;
@ -221,4 +189,3 @@ class epcRecords
$this->core->blog->triggerBlog(); $this->core->blog->triggerBlog();
} }
} }
?>

View File

@ -15,15 +15,11 @@
$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');
@ -40,4 +36,3 @@ while ($f->fetch())
$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 . "' ");
} }
} }
?>

View File

@ -12,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -41,15 +40,13 @@ if (!empty($action)) {
$core->callBehavior('enhancePostContentAdminSave', $core); $core->callBehavior('enhancePostContentAdminSave', $core);
} }
try try {
{
# Update filter settings # Update filter settings
if ($action == 'savefiltersetting' if ($action == 'savefiltersetting'
&& isset($filters_id[$default_part]) && isset($filters_id[$default_part])) {
) {
# Parse filters options # Parse filters options
$name = $filters_id[$default_part]; $name = $filters_id[$default_part];
$f = array( $f = [
'nocase' => !empty($_POST['filter_nocase']), 'nocase' => !empty($_POST['filter_nocase']),
'plural' => !empty($_POST['filter_plural']), 'plural' => !empty($_POST['filter_plural']),
'limit' => abs((integer) $_POST['filter_limit']), 'limit' => abs((integer) $_POST['filter_limit']),
@ -57,7 +54,7 @@ try
'notag' => (string) $_POST['filter_notag'], 'notag' => (string) $_POST['filter_notag'],
'tplValues' => (array) $_POST['filter_tplValues'], 'tplValues' => (array) $_POST['filter_tplValues'],
'pubPages' => (array) $_POST['filter_pubPages'] 'pubPages' => (array) $_POST['filter_pubPages']
); ];
$s->put('enhancePostContent_' . $name, serialize($f)); $s->put('enhancePostContent_' . $name, serialize($f));
@ -75,8 +72,7 @@ try
if ($action == 'savenewrecord' if ($action == 'savenewrecord'
&& isset($filters_id[$default_part]) && isset($filters_id[$default_part])
&& !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 = $filters_id[$default_part]; $cur->epc_filter = $filters_id[$default_part];
$cur->epc_key = html::escapeHTML($_POST['new_key']); $cur->epc_key = html::escapeHTML($_POST['new_key']);
@ -96,21 +92,17 @@ try
# Update filter records # Update filter records
if ($action == 'saveupdaterecords' if ($action == 'saveupdaterecords'
&& isset($filters_id[$default_part]) && isset($filters_id[$default_part])
&& $_filters[$filters_id[$default_part]]['has_list'] && $_filters[$filters_id[$default_part]]['has_list']) {
) {
foreach($_POST['epc_id'] as $k => $id) { foreach($_POST['epc_id'] as $k => $id) {
$k = abs((integer) $k); $k = abs((integer) $k);
$id = abs((integer) $id); $id = abs((integer) $id);
if (empty($_POST['epc_key'][$k]) if (empty($_POST['epc_key'][$k])
|| empty($_POST['epc_value'][$k]) || empty($_POST['epc_value'][$k])) {
) {
$records->delRecord($id); $records->delRecord($id);
} } elseif ($_POST['epc_key'][$k] != $_POST['epc_old_key'][$k]
elseif ($_POST['epc_key'][$k] != $_POST['epc_old_key'][$k] || $_POST['epc_value'][$k] != $_POST['epc_old_value'][$k]) {
|| $_POST['epc_value'][$k] != $_POST['epc_old_value'][$k]
) {
$cur = $records->openCursor(); $cur = $records->openCursor();
$cur->epc_filter = $filters_id[$default_part]; $cur->epc_filter = $filters_id[$default_part];
$cur->epc_key = html::escapeHTML($_POST['epc_key'][$k]); $cur->epc_key = html::escapeHTML($_POST['epc_key'][$k]);
@ -132,18 +124,17 @@ try
$redir $redir
); );
} }
} } catch(Exception $e) {
catch(Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
# -- Prepare page -- # -- Prepare page --
$breadcrumb = array( $breadcrumb = [
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Enhance post content') => $p_url __('Enhance post content') => $p_url
); ];
$top_menu = array(); $top_menu = [];
foreach($filters_id as $id => $name) { foreach($filters_id as $id => $name) {
@ -204,7 +195,7 @@ if (isset($filters_id[$default_part])) {
echo ' echo '
<p><label for="filter_pubPages' . $v . '">' . <p><label for="filter_pubPages' . $v . '">' .
form::checkbox( form::checkbox(
array('filter_pubPages[]', 'filter_pubPages'.$v), ['filter_pubPages[]', 'filter_pubPages' . $v],
$v, $v,
in_array($v, $filter['pubPages']) in_array($v, $filter['pubPages'])
) . ) .
@ -242,7 +233,7 @@ if (isset($filters_id[$default_part])) {
echo ' echo '
<p><label for="filter_tplValues' . $v . '">' . <p><label for="filter_tplValues' . $v . '">' .
form::checkbox( form::checkbox(
array('filter_tplValues[]', 'filter_tplValues'.$v), ['filter_tplValues[]', 'filter_tplValues' . $v],
$v, $v,
in_array($v, $filter['tplValues']) in_array($v, $filter['tplValues'])
) . ) .
@ -261,7 +252,7 @@ if (isset($filters_id[$default_part])) {
<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(
array('filter_style[]', 'filter_style'.$k), ['filter_style[]', 'filter_style'.$k],
60, 60,
255, 255,
html::escapeHTML($filter['style'][$k]) html::escapeHTML($filter['style'][$k])
@ -284,7 +275,7 @@ if (isset($filters_id[$default_part])) {
<div class="clear"> <div class="clear">
<p>' . <p>' .
$core->formNonce() . $core->formNonce() .
form::hidden(array('action'), 'savefiltersetting').' form::hidden(['action'], 'savefiltersetting') . '
<input type="submit" name="save" value="' . __('Save') . '" /> <input type="submit" name="save" value="' . __('Save') . '" />
</p> </p>
</div> </div>
@ -295,26 +286,26 @@ if (isset($filters_id[$default_part])) {
# Filter records list # Filter records list
if ($filter['has_list']) { if ($filter['has_list']) {
$sortby_combo = array( $sortby_combo = [
'epc_upddt', 'epc_upddt',
'epc_key', 'epc_key',
'epc_value', 'epc_value',
'epc_id' 'epc_id'
); ];
$order_combo = array( $order_combo = [
'asc', 'asc',
'desc' 'desc'
); ];
$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : (string) $s->enhancePostContent_list_sortby; $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : (string) $s->enhancePostContent_list_sortby;
$order = !empty($_GET['order']) ? $_GET['order'] : (string) $s->enhancePostContent_list_order; $order = !empty($_GET['order']) ? $_GET['order'] : (string) $s->enhancePostContent_list_order;
$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
$nb = !empty($_GET['nb']) && (integer) $_GET['nb'] > 0 ? (integer) $_GET['nb'] : (integer) $s->enhancePostContent_list_nb; $nb = !empty($_GET['nb']) && (integer) $_GET['nb'] > 0 ? (integer) $_GET['nb'] : (integer) $s->enhancePostContent_list_nb;
$params = array(); $params = [];
$params['epc_filter'] = $name; $params['epc_filter'] = $name;
$params['limit'] = array((($page-1)*$nb), $nb); $params['limit'] = [(($page - 1) * $nb), $nb];
if ($sortby !== '' && in_array($sortby, $sortby_combo)) { if ($sortby !== '' && in_array($sortby, $sortby_combo)) {
if ($order !== '' && in_array($order, $order_combo)) { if ($order !== '' && in_array($order, $order_combo)) {
@ -325,8 +316,7 @@ if (isset($filters_id[$default_part])) {
try { try {
$list = $records->getRecords($params); $list = $records->getRecords($params);
$counter = $records->getRecords($params, true); $counter = $records->getRecords($params, true);
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
@ -349,15 +339,14 @@ if (isset($filters_id[$default_part])) {
if ($core->error->flag() || $list->isEmpty()) { if ($core->error->flag() || $list->isEmpty()) {
echo '<p>' . __('No record') . '</p>'; echo '<p>' . __('No record') . '</p>';
} } else {
else {
echo ' echo '
<form action="' . $pager_url . '" method="post"> <form action="' . $pager_url . '" method="post">
<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p> <p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>
<table> <table>
<thead><tr> <thead><tr>
<th><a href="'.sprintf($pager_url, 'epc_key', $page).'">' <th><a href="' . sprintf($pager_url, 'epc_key', $page) . '">' .
.__('Key').'</a></th> __('Key') . '</a></th>
<th><a href="' . sprintf($pager_url, 'epc_value', $page) . '">' . <th><a href="' . sprintf($pager_url, 'epc_value', $page) . '">' .
__('Value') . '</a></th> __('Value') . '</a></th>
<th><a href="' . sprintf($pager_url, 'epc_upddt', $page) . '">' . <th><a href="' . sprintf($pager_url, 'epc_upddt', $page) . '">' .
@ -369,12 +358,12 @@ if (isset($filters_id[$default_part])) {
echo ' echo '
<tr class="line"> <tr class="line">
<td class="nowrap">' . <td class="nowrap">' .
form::hidden(array('epc_id[]'), $list->epc_id). form::hidden(['epc_id[]'], $list->epc_id) .
form::hidden(array('epc_old_key[]'), html::escapeHTML($list->epc_key)). form::hidden(['epc_old_key[]'], html::escapeHTML($list->epc_key)) .
form::hidden(array('epc_old_value[]'), html::escapeHTML($list->epc_value)). form::hidden(['epc_old_value[]'], html::escapeHTML($list->epc_value)) .
form::field(array('epc_key[]'), 30, 225, html::escapeHTML($list->epc_key), '').'</td> form::field(['epc_key[]'], 30, 225, html::escapeHTML($list->epc_key), '') . '</td>
<td class="maximal">' . <td class="maximal">' .
form::field(array('epc_value[]'), 90, 225, html::escapeHTML($list->epc_value), 'maximal').'</td> form::field(['epc_value[]'], 90, 225, html::escapeHTML($list->epc_value), 'maximal') . '</td>
<td class="nowrap">' . <td class="nowrap">' .
dt::dt2str(__('%Y-%m-%d %H:%M'), $list->epc_upddt,$core->auth->getInfo('user_tz')) . '</td> dt::dt2str(__('%Y-%m-%d %H:%M'), $list->epc_upddt,$core->auth->getInfo('user_tz')) . '</td>
</tr>'; </tr>';
@ -389,8 +378,8 @@ if (isset($filters_id[$default_part])) {
<div class="clear"> <div class="clear">
<p>' . <p>' .
$core->formNonce() . $core->formNonce() .
form::hidden(array('redir'), sprintf($pager_url, $sortby, $page)). form::hidden(['redir'], sprintf($pager_url, $sortby, $page)) .
form::hidden(array('action'), 'saveupdaterecords').' form::hidden(['action'], 'saveupdaterecords') . '
<input type="submit" name="save" value="' . __('Save') . '" /> <input type="submit" name="save" value="' . __('Save') . '" />
</p> </p>
</div> </div>
@ -414,7 +403,7 @@ if (isset($filters_id[$default_part])) {
'</p> '</p>
<p class="clear">' . <p class="clear">' .
form::hidden(array('action'), 'savenewrecord'). form::hidden(['action'], 'savenewrecord') .
$core->formNonce() . ' $core->formNonce() . '
<input type="submit" name="save" value="' . __('Save') . '" /> <input type="submit" name="save" value="' . __('Save') . '" />
</p> </p>
@ -431,9 +420,6 @@ dcPage::helpBlock('enhancePostContent');
# Footers # Footers
echo echo
'<hr class="clear"/><p class="right modules"> '<hr class="clear"/><p class="right modules">
<a class="module-config" '.
'href="plugins.php?module=enhancePostContent&amp;conf=1&amp;redir='.
urlencode('plugin.php?p=enhancePostContent').'">'.__('Configuration').'</a> -
enhancePostContent - ' . $core->plugins->moduleInfo('enhancePostContent', 'version') . '&nbsp; enhancePostContent - ' . $core->plugins->moduleInfo('enhancePostContent', 'version') . '&nbsp;
<img alt="' . __('enhancePostContent') . '" src="index.php?pf=enhancePostContent/icon.png" /> <img alt="' . __('enhancePostContent') . '" src="index.php?pf=enhancePostContent/icon.png" />
</p> </p>

View File

@ -11,7 +11,8 @@
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; } if (!defined('DC_RC_PATH')) {
return;
}
$__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html'; $__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html';
?>

View File

@ -11,7 +11,8 @@
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; } if (!defined('DC_RC_PATH')) {
return;
}
$__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html'; $__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html';
?>