From 64e42494ca5c4fbbd6f0291369418fd632db4659 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 24 Aug 2021 22:05:23 +0200 Subject: [PATCH] update php code to PSR-2 and short array --- CHANGELOG.md | 2 + _admin.php | 67 +- _define.php | 33 +- _install.php | 148 ++-- _prepend.php | 9 +- _public.php | 147 ++-- _uninstall.php | 60 +- _widgets.php | 344 +++++---- inc/lib.epc.php | 1548 +++++++++++++++++++------------------- inc/lib.epc.records.php | 377 +++++----- inc/lib.epc.update.php | 45 +- index.php | 614 ++++++++------- locales/en/resources.php | 7 +- locales/fr/resources.php | 7 +- 14 files changed, 1668 insertions(+), 1740 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30cf412..e897ccc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,14 @@ enhancePostContent xxxx.xx.xx * Not added priority on filters for replacement order * Not added priority on lists of filters for replacement order * Not added auto-find post title in content + * move settings from plugin to blog enhancePostContent 2021.08.xx * switch to Dotclear 2.19 * switch to php 7.3+ and php 8.0.x * switch to Github * update license + * update php code to PSR-2 and short array enhancePostContent 2013.11.08 * Switch to Dotclear 2.6 (admin styles and settings) diff --git a/_admin.php b/_admin.php index ed05492..a6b1a91 100644 --- a/_admin.php +++ b/_admin.php @@ -12,50 +12,49 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + return null; } -require dirname(__FILE__).'/_widgets.php'; +require dirname(__FILE__) . '/_widgets.php'; # Admin menu $_menu['Blog']->addItem( - __('Enhance post content'), - 'plugin.php?p=enhancePostContent', - 'index.php?pf=enhancePostContent/icon.png', - preg_match( - '/plugin.php\?p=enhancePostContent(&.*)?$/', - $_SERVER['REQUEST_URI'] - ), - $core->auth->check('contentadmin', $core->blog->id) + __('Enhance post content'), + 'plugin.php?p=enhancePostContent', + 'index.php?pf=enhancePostContent/icon.png', + preg_match( + '/plugin.php\?p=enhancePostContent(&.*)?$/', + $_SERVER['REQUEST_URI'] + ), + $core->auth->check('contentadmin', $core->blog->id) ); $core->addBehavior( - 'adminDashboardFavorites', - array('epcAdminBehaviors', 'adminDashboardFavorites') + 'adminDashboardFavorites', + ['epcAdminBehaviors', 'adminDashboardFavorites'] ); class epcAdminBehaviors { - public static function adminDashboardFavorites($core, $favs) - { - $favs->register('enhancePostContent', array( - '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' => array( - 'epcAdminBehaviors', - 'adminDashboardFavoritesActive' - ) - )); - } + 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', + 'permissions' => $core->auth->check('contentadmin', $core->blog->id), + 'active_cb' => [ + 'epcAdminBehaviors', + 'adminDashboardFavoritesActive' + ] + ]); + } - public static function adminDashboardFavoritesActive($request, $params) - { - return $request == 'plugin.php' - && isset($params['p']) - && $params['p'] == 'enhancePostContent'; - } -} + public static function adminDashboardFavoritesActive($request, $params) + { + return $request == 'plugin.php' + && isset($params['p']) + && $params['p'] == 'enhancePostContent'; + } +} \ No newline at end of file diff --git a/_define.php b/_define.php index 8baaaaa..c167698 100644 --- a/_define.php +++ b/_define.php @@ -12,24 +12,19 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } - + $this->registerModule( - /* Name */ - "Enhance post content", - /* Description*/ - "Add features to words in post content", - /* Author */ - "Jean-Christian Denis", - /* Version */ - '2013.11.08', - array( - 'permissions' => 'contentadmin', - 'type' => 'plugin', - 'dc_min' => '2.6', - 'support' => 'http://jcd.lv/q=enhancePostContent', - 'details' => 'http://plugins.dotaddict.org/dc2/details/enhancePostContent' - ) -); + 'Enhance post content', + 'Add features to words in post content', + 'Jean-Christian Denis and Contributors', + '2021.08.0', + [ + 'permissions' => 'contentadmin', + 'type' => 'plugin', + 'dc_min' => '2.18', + 'support' => 'https://github.com/JcDenis/enhancePostContent', + 'details' => 'https://plugins.dotaddict.org/dc2/details/enhancePostContent' + ] +); \ No newline at end of file diff --git a/_install.php b/_install.php index f540dfd..9abee83 100644 --- a/_install.php +++ b/_install.php @@ -12,93 +12,89 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + return null; } -$dc_min = '2.6'; +$dc_min = '2.18'; $mod_id = 'enhancePostContent'; $new_version = $core->plugins->moduleInfo($mod_id, 'version'); $old_version = $core->getVersion($mod_id); if (version_compare($old_version, $new_version, '>=')) { - - return null; + return null; } -try -{ - # Check Dotclear version - if (!method_exists('dcUtils', 'versionsCompare') - || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { - throw new Exception(sprintf( - '%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_type('varchar', 32, false, "'epc'") - ->epc_filter('varchar', 64, false) - ->epc_key('varchar', 255, false) - ->epc_value('text', 0, false) - ->epc_upddt('timestamp', 0, false, 'now()') - - ->primary('pk_epc', 'epc_id') - ->index('idx_epc_blog_id', 'btree', 'blog_id') - ->index('idx_epc_type', 'btree', 'epc_type') - ->index('idx_epc_filter', 'btree', 'epc_filter') - ->index('idx_epc_key', 'btree', 'epc_key'); - - $si = new dbStruct($core->con, $core->prefix); - $changes = $si->synchronize($s); - $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_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); - $s->put('enhancePostContent_allowedtplvalues', serialize(libEPC::defaultAllowedTplValues()), 'string', 'List of allowed template values', false, true); - $s->put('enhancePostContent_allowedpubpages', serialize(libEPC::defaultAllowedPubPages()), 'string', 'List of allowed template pages', false, true); - - # Filters settings - $filters = libEPC::defaultFilters(); - foreach($filters as $name => $filter) { - # Only editable options - $opt = array( - 'nocase' => $filter['nocase'], - 'plural' => $filter['plural'], - 'style' => $filter['style'], - 'notag' => $filter['notag'], - 'tplValues' => $filter['tplValues'], - 'pubPages' => $filter['pubPages'] - ); - $s->put('enhancePostContent_'.$name, serialize($opt), 'string', 'Settings for '.$name, false, true); - # only tables - if (isset($filter['list'])) { - $s->put('enhancePostContent_'.$name.'List', serialize($filter['list']), 'string', 'List for '.$name, false, true); - } - } +try { + # Check Dotclear version + if (!method_exists('dcUtils', 'versionsCompare') + || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { + throw new Exception(sprintf( + '%s requires Dotclear %s', $mod_id, $dc_min + )); + } - # Move old filters lists from settings to database - if ($old_version && version_compare('0.6.6', $old_version, '>=')) { - include_once dirname(__FILE__).'/inc/lib.epc.update.php'; - } + # Database + $s = new dbStruct($core->con, $core->prefix); + $s->epc + ->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) + ->epc_value('text', 0, false) + ->epc_upddt('timestamp', 0, false, 'now()') - # Version - $core->setVersion($mod_id, $new_version); + ->primary('pk_epc', 'epc_id') + ->index('idx_epc_blog_id', 'btree', 'blog_id') + ->index('idx_epc_type', 'btree', 'epc_type') + ->index('idx_epc_filter', 'btree', 'epc_filter') + ->index('idx_epc_key', 'btree', 'epc_key'); - return true; -} -catch (Exception $e) { - $core->error->add($e->getMessage()); + $si = new dbStruct($core->con, $core->prefix); + $changes = $si->synchronize($s); + $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_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); + $s->put('enhancePostContent_allowedtplvalues', serialize(libEPC::defaultAllowedTplValues()), 'string', 'List of allowed template values', false, true); + $s->put('enhancePostContent_allowedpubpages', serialize(libEPC::defaultAllowedPubPages()), 'string', 'List of allowed template pages', false, true); + + # Filters settings + $filters = libEPC::defaultFilters(); + foreach($filters as $name => $filter) { + # Only editable options + $opt = [ + 'nocase' => $filter['nocase'], + 'plural' => $filter['plural'], + 'style' => $filter['style'], + 'notag' => $filter['notag'], + 'tplValues' => $filter['tplValues'], + 'pubPages' => $filter['pubPages'] + ]; + $s->put('enhancePostContent_' . $name, serialize($opt), 'string', 'Settings for ' . $name, false, true); + # only tables + if (isset($filter['list'])) { + $s->put('enhancePostContent_' . $name . 'List', serialize($filter['list']), 'string', 'List for ' . $name, false, true); + } + } + + # Move old filters lists from settings to database + if ($old_version && version_compare('0.6.6', $old_version, '>=')) { + include_once dirname(__FILE__) . '/inc/lib.epc.update.php'; + } + + # Version + $core->setVersion($mod_id, $new_version); + + return true; +} catch (Exception $e) { + $core->error->add($e->getMessage()); } -return false; +return false; \ No newline at end of file diff --git a/_prepend.php b/_prepend.php index 0ee787e..41f9b66 100644 --- a/_prepend.php +++ b/_prepend.php @@ -12,11 +12,10 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } -$d = dirname(__FILE__).'/inc/'; +$d = dirname(__FILE__) . '/inc/'; -$__autoload['libEPC'] = $d.'lib.epc.php'; -$__autoload['epcRecords'] = $d.'lib.epc.records.php'; +$__autoload['libEPC'] = $d . 'lib.epc.php'; +$__autoload['epcRecords'] = $d . 'lib.epc.records.php'; \ No newline at end of file diff --git a/_public.php b/_public.php index d7d697d..2c5dbbe 100644 --- a/_public.php +++ b/_public.php @@ -12,24 +12,23 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } -require dirname(__FILE__).'/_widgets.php'; +require dirname(__FILE__) . '/_widgets.php'; $core->blog->settings->addNamespace('enhancePostContent'); if ($core->blog->settings->enhancePostContent->enhancePostContent_active) { - $core->addBehavior( - 'publicHeadContent', - array('publicEnhancePostContent', 'publicHeadContent') - ); - $core->addBehavior( - 'publicBeforeContentFilter', - array('publicEnhancePostContent', 'publicContentFilter') - ); + $core->addBehavior( + 'publicHeadContent', + ['publicEnhancePostContent', 'publicHeadContent'] + ); + $core->addBehavior( + 'publicBeforeContentFilter', + ['publicEnhancePostContent', 'publicContentFilter'] + ); } /** @@ -39,73 +38,71 @@ if ($core->blog->settings->enhancePostContent->enhancePostContent_active) { */ class publicEnhancePostContent { - /** - * Add filters CSS to page header - * - * @param dcCore $core dcCore instance - */ - public static function publicHeadContent(dcCore $core) - { - $filters = libEPC::blogFilters(); - - foreach($filters as $name => $filter) { + /** + * Add filters CSS to page header + * + * @param dcCore $core dcCore instance + */ + public static function publicHeadContent(dcCore $core) + { + $filters = libEPC::blogFilters(); - if (empty($filter['class']) - || empty($filter['style']) - ) { - continue; - } + foreach($filters as $name => $filter) { - $res = ''; - foreach($filter['class'] as $k => $class) { - $style = html::escapeHTML(trim($filter['style'][$k])); - if ('' != $style) { - $res .= $class." {".$style."} "; - } - } + if (empty($filter['class']) + || empty($filter['style'])) { + continue; + } - if (!empty($res)) { - echo - "\n \n". - " \n"; - } - } - } + $res = ''; + foreach($filter['class'] as $k => $class) { + $style = html::escapeHTML(trim($filter['style'][$k])); + if ('' != $style) { + $res .= $class . " {" . $style . "} "; + } + } - /** - * Filter template blocks content - * - * @param dcCore $core dcCore instance - * @param string $tag Tempalte block name - * @param array $args Tempalte Block arguments - */ - public static function publicContentFilter(dcCore $core, $tag, $args) - { - $filters = libEPC::blogFilters(); - $records = new epcRecords($core); - - foreach($filters as $name => $filter) { + if (!empty($res)) { + echo + "\n \n" . + " \n"; + } + } + } - if (!isset($filter['publicContentFilter']) - || !is_callable($filter['publicContentFilter']) - || !libEPC::testContext($tag,$args,$filter) - ) { - continue; - } - - if ($filter['has_list']) { - $filter['list'] = $records->getRecords(array( - 'epc_filter' => $name) - ); - if ($filter['list']->isEmpty()) { - continue; - } - } + /** + * Filter template blocks content + * + * @param dcCore $core dcCore instance + * @param string $tag Tempalte block name + * @param array $args Tempalte Block arguments + */ + public static function publicContentFilter(dcCore $core, $tag, $args) + { + $filters = libEPC::blogFilters(); + $records = new epcRecords($core); - call_user_func_array( - $filter['publicContentFilter'], - array($core, $filter, $tag, $args) - ); - } - } -} + foreach($filters as $name => $filter) { + + if (!isset($filter['publicContentFilter']) + || !is_callable($filter['publicContentFilter']) + || !libEPC::testContext($tag,$args,$filter)) { + continue; + } + + if ($filter['has_list']) { + $filter['list'] = $records->getRecords(array( + 'epc_filter' => $name) + ); + if ($filter['list']->isEmpty()) { + continue; + } + } + + call_user_func_array( + $filter['publicContentFilter'], + [$core, $filter, $tag, $args] + ); + } + } +} \ No newline at end of file diff --git a/_uninstall.php b/_uninstall.php index 6c12d08..da39ac6 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -11,48 +11,48 @@ # # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_CONTEXT_ADMIN')){return;} +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') -); - - -$this->addDirectAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ 'enhancePostContent', - /* description */ sprintf(__('delete all %s settings'),'enhancePostContent') + /* type */ 'versions', + /* action */ 'delete', + /* ns */ 'enhancePostContent', + /* description */ __('delete the version number') ); $this->addDirectAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ 'enhancePostContent', - /* description */ sprintf(__('delete %s plugin files'),'enhancePostContent') + /* type */ 'settings', + /* action */ 'delete_all', + /* ns */ 'enhancePostContent', + /* description */ sprintf(__('delete all %s settings'), 'enhancePostContent') ); $this->addDirectAction( - /* type */ 'versions', - /* action */ 'delete', - /* ns */ 'enhancePostContent', - /* description */ sprintf(__('delete %s version number'),'enhancePostContent') + /* type */ 'plugins', + /* action */ 'delete', + /* ns */ 'enhancePostContent', + /* description */ sprintf(__('delete %s plugin files'), 'enhancePostContent') ); -?> \ No newline at end of file + +$this->addDirectAction( + /* type */ 'versions', + /* action */ 'delete', + /* ns */ 'enhancePostContent', + /* description */ sprintf(__('delete %s version number'), 'enhancePostContent') +); \ No newline at end of file diff --git a/_widgets.php b/_widgets.php index e2f2641..ca7c1c4 100644 --- a/_widgets.php +++ b/_widgets.php @@ -12,13 +12,12 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } $core->addBehavior( - 'initWidgets', - array('enhancePostContentWidget', 'adminContentList') + 'initWidgets', + ['enhancePostContentWidget', 'adminContentList'] ); /** @@ -28,193 +27,186 @@ $core->addBehavior( */ class enhancePostContentWidget { - /** - * Admin part for widget that show extracted content - * - * @param dcWidgets $w dcWidgets instance - */ - public static function adminContentList($w) - { - global $core; - - $w->create( - 'epclist', - __('Enhance post content'), - array('enhancePostContentWidget', 'publicContentList'), - null, - __('List filtered contents.') - ); - # Title - $w->epclist->setting( - 'title', - __('Title:'), - __('In this article'), - 'text' - ); - # Text - $w->epclist->setting( - 'text', - __('Description:'), - '', - 'text' - ); - # Type - $filters = libEPC::blogFilters(); - $types = array(); - foreach($filters as $name => $filter) - { - if (!isset($filter['widgetListFilter']) - || !is_callable($filter['widgetListFilter']) - ) { - continue; - } + /** + * Admin part for widget that show extracted content + * + * @param dcWidgets $w dcWidgets instance + */ + public static function adminContentList($w) + { + global $core; - $types[__($name)] = $name; - } - $w->epclist->setting( - 'type', - __('Type:'), - 'Definition', - 'combo', - $types - ); - # Content - $contents = libEPC::defaultAllowedWidgetValues(); - foreach($contents as $k => $v) { - $w->epclist->setting( - 'content'.$v['id'], - sprintf(__('Enable filter on %s'), __($k)), - 1, - 'check' - ); - } - # Case sensitive - $w->epclist->setting( - 'nocase', - __('Search case insensitive'), - 0, - 'check' - ); - # Plural - $w->epclist->setting( - 'plural', - __('Search also plural'), - 0, - 'check' - ); - # Show count - $w->epclist->setting( - 'show_total', - __('Show the number of appearance'), - 1, - 'check' - ); - # widget option - content only - $w->epclist->setting( - 'content_only', - __('Content only'), - 0, - 'check' - ); - # widget option - additionnal CSS - $w->epclist->setting( - 'class', - __('CSS class:'), - '' - ); - } + $w->create( + 'epclist', + __('Enhance post content'), + ['enhancePostContentWidget', 'publicContentList'], + null, + __('List filtered contents.') + ); + # Title + $w->epclist->setting( + 'title', + __('Title:'), + __('In this article'), + 'text' + ); + # Text + $w->epclist->setting( + 'text', + __('Description:'), + '', + 'text' + ); + # Type + $filters = libEPC::blogFilters(); + $types = []; + foreach($filters as $name => $filter) { + if (!isset($filter['widgetListFilter']) + || !is_callable($filter['widgetListFilter'])) { + continue; + } - /** - * Public part for widget that show extracted content - * - * @param dcWidget $w dcWidget instance - */ - public static function publicContentList($w) - { - global $core, $_ctx; + $types[__($name)] = $name; + } + $w->epclist->setting( + 'type', + __('Type:'), + 'Definition', + 'combo', + $types + ); + # Content + $contents = libEPC::defaultAllowedWidgetValues(); + foreach($contents as $k => $v) { + $w->epclist->setting( + 'content' . $v['id'], + sprintf(__('Enable filter on %s'), __($k)), + 1, + 'check' + ); + } + # Case sensitive + $w->epclist->setting( + 'nocase', + __('Search case insensitive'), + 0, + 'check' + ); + # Plural + $w->epclist->setting( + 'plural', + __('Search also plural'), + 0, + 'check' + ); + # Show count + $w->epclist->setting( + 'show_total', + __('Show the number of appearance'), + 1, + 'check' + ); + # widget option - content only + $w->epclist->setting( + 'content_only', + __('Content only'), + 0, + 'check' + ); + # widget option - additionnal CSS + $w->epclist->setting( + 'class', + __('CSS class:'), + '' + ); + } - $core->blog->settings->addNamespace('enhancePostContent'); + /** + * Public part for widget that show extracted content + * + * @param dcWidget $w dcWidget instance + */ + public static function publicContentList($w) + { + global $core, $_ctx; - # Page - if (!$core->blog->settings->enhancePostContent->enhancePostContent_active - || !in_array($_ctx->current_tpl,array('post.html','page.html')) - ) { - return null; - } + $core->blog->settings->addNamespace('enhancePostContent'); - # Content - $content = ''; - $allowedwidgetvalues = libEPC::defaultAllowedWidgetValues(); - foreach($allowedwidgetvalues as $k => $v) { + # Page + if (!$core->blog->settings->enhancePostContent->enhancePostContent_active + || !in_array($_ctx->current_tpl, ['post.html', 'page.html'])) { + return null; + } - $ns = 'content'.$v['id']; - if ($w->$ns && is_callable($v['callback'])) { + # Content + $content = ''; + $allowedwidgetvalues = libEPC::defaultAllowedWidgetValues(); + foreach($allowedwidgetvalues as $k => $v) { - $content .= call_user_func_array( - $v['callback'], - array($core,$w) - ); - } - } + $ns = 'content' . $v['id']; + if ($w->$ns && is_callable($v['callback'])) { - if (empty($content)) { + $content .= call_user_func_array( + $v['callback'], + [$core, $w] + ); + } + } - return null; - } + if (empty($content)) { + return null; + } - # Filter - $list = array(); - $filters = libEPC::blogFilters(); + # Filter + $list = []; + $filters = libEPC::blogFilters(); - if (isset($filters[$w->type]) - && isset($filters[$w->type]['widgetListFilter']) - && is_callable($filters[$w->type]['widgetListFilter']) - ) { - $filters[$w->type]['nocase'] = $w->nocase; - $filters[$w->type]['plural'] = $w->plural; + if (isset($filters[$w->type]) + && isset($filters[$w->type]['widgetListFilter']) + && is_callable($filters[$w->type]['widgetListFilter'])) { + $filters[$w->type]['nocase'] = $w->nocase; + $filters[$w->type]['plural'] = $w->plural; - if ($filters[$w->type]['has_list']) { - $records = new epcRecords($core); - $filters[$w->type]['list'] = $records->getRecords( - array('epc_filter' => $w->type) - ); - } + if ($filters[$w->type]['has_list']) { + $records = new epcRecords($core); + $filters[$w->type]['list'] = $records->getRecords( + ['epc_filter' => $w->type] + ); + } - call_user_func_array( - $filters[$w->type]['widgetListFilter'], - array($core, $filters[$w->type], $content, $w, &$list) - ); - } + call_user_func_array( + $filters[$w->type]['widgetListFilter'], + [$core, $filters[$w->type], $content, $w, &$list] + ); + } - if (empty($list)) { + if (empty($list)) { + return null; + } - return null; - } + # Parse result + $res = ''; + foreach($list as $line) { + if (empty($line['matches'][0]['match'])) { + continue; + } - # Parse result - $res = ''; - foreach($list as $line) { - if (empty($line['matches'][0]['match'])) { - continue; - } + $res .= + '
  • ' . $line['matches'][0]['match'] . + ($w->show_total ? ' (' . $line['total'] .')' : '') . + '
  • '; + } - $res .= - '
  • '.$line['matches'][0]['match']. - ($w->show_total ? ' ('.$line['total'].')' : ''). - '
  • '; - } + if (empty($res)) { + return null; + } - if (empty($res)) { - - return null; - } - - return - ($w->content_only ? '' : '
    '). - ($w->title ? '

    '.html::escapeHTML($w->title).'

    ' : ''). - ($w->text ? '

    '.html::escapeHTML($w->text).'

    ' : ''). - ''. - ($w->content_only ? '' : '
    '); - } -} + return + ($w->content_only ? '' : '
    ') . + ($w->title ? '

    ' . html::escapeHTML($w->title) . '

    ' : '') . + ($w->text ? '

    ' . html::escapeHTML($w->text) . '

    ' : '') . + '' . + ($w->content_only ? '' : '
    '); + } +} \ No newline at end of file diff --git a/inc/lib.epc.php b/inc/lib.epc.php index 3709406..081d863 100644 --- a/inc/lib.epc.php +++ b/inc/lib.epc.php @@ -20,780 +20,778 @@ __('atom feeds');__('RSS feeds'); class libEPC { - # - # Default definition - # - - public static function defaultAllowedTplValues() - { - return array( - 'entry excerpt' => 'EntryExcerpt', - 'entry content' => 'EntryContent', - 'comment content' => 'CommentContent', - ); - } - - public static function blogAllowedTplValues() - { - global $core; - $core->blog->settings->addNamespace('enhancePostContent'); - $allowedtplvalues = self::defaultAllowedTplValues(); - $rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedtplvalues); - return is_array($rs) ? $rs : $allowedtplvalues; - } - - public static function defaultAllowedWidgetValues() - { - global $core; - - $rs = array( - 'entry excerpt' => array( - 'id' => 'entryexcerpt', - 'callback' => array('libEPC','widgetContentEntryExcerpt') - ), - 'entry content' => array( - 'id' => 'entrycontent', - 'callback' => array('libEPC','widgetContentEntryContent') - ), - 'comment content' => array( - 'id' => 'commentcontent', - 'callback' => array('libEPC','widgetContentCommentContent') - ) - ); - - $core->callBehavior('enhancePostContentAllowedWidgetValues',$rs); - - return $rs; - } - - public static function defaultAllowedPubPages() - { - return array( - 'home page' => 'home.html', - 'post page' => 'post.html', - 'category page' => 'category.html', - 'search results page' => 'search.html', - 'atom feeds' => 'atom.xml', - 'RSS feeds' => 'rss2.xml' - ); - } - - public static function blogAllowedPubPages() - { - global $core; - $core->blog->settings->addNamespace('enhancePostContent'); - $allowedpubpages = self::defaultAllowedPubPages(); - $rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedpubpages); - return is_array($rs) ? $rs : $allowedpubpages; - } - - public static function defaultFilters() - { - global $core; - - $filters = array( - 'Tag' => array( - 'id' => 'tag', - 'publicContentFilter' => array('libEPC','publicContentFilterTag'), - 'widgetListFilter' => array('libEPC','widgetListTag'), - - 'help' => __('Highlight tags of your blog.'), - 'has_list' => false, - 'htmltag' => 'a', - 'class' => array('a.epc-tag'), - 'replace' => '%s', - 'widget' => '%s', - - 'nocase' => false, - 'plural' => false, - 'limit' => 0, - 'style' => array('text-decoration: none; border-bottom: 3px double #CCCCCC;'), - 'notag' => 'a,h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html') - ), - 'Search' => array( - 'id' => 'search', - 'publicContentFilter' => array('libEPC','publicContentFilterSearch'), - - 'help' => __('Highlight searched words.'), - 'has_list' => false, - 'htmltag' => '', - 'class' => array('span.epc-search'), - 'replace' => '%s', - - 'nocase' => true, - 'plural' => true, - 'limit' => 0, - 'style' => array('color: #FFCC66;'), - 'notag' => 'h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('search.html') - ), - 'Acronym' => array( - 'id' => 'acronym', - 'publicContentFilter' => array('libEPC','publicContentFilterAcronym'), - 'widgetListFilter' => array('libEPC','widgetListAcronym'), - - 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'), - 'has_list' => true, - 'htmltag' => 'acronym', - 'class' => array('acronym.epc-acronym'), - 'replace' => '%s', - 'widget' => '%s', - - 'nocase' => false, - 'plural' => false, - 'limit' => 0, - 'style' => array('font-weight: bold;'), - 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html'), - ), - 'Abbreviation' => array( - 'id' => 'abbreviation', - 'publicContentFilter' => array('libEPC','publicContentFilterAbbreviation'), - 'widgetListFilter' => array('libEPC','widgetListAbbreviation'), - - 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'), - 'has_list' => true, - 'htmltag' => 'a', - 'class' => array('abbr.epc-abbr'), - 'replace' => '%s', - 'widget' => '%s', - - 'nocase' => false, - 'plural' => false, - 'limit' => 0, - 'style' => array('font-weight: bold;'), - 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html'), - ), - 'Definition' => array( - 'id' => 'definition', - 'publicContentFilter' => array('libEPC','publicContentFilterDefinition'), - 'widgetListFilter' => array('libEPC','widgetListDefinition'), - - 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'), - 'has_list' => true, - 'htmltag' => 'dfn', - 'class' => array('dfn.epc-dfn'), - 'replace' => '%s', - 'widget' => '%s', - - 'nocase' => false, - 'plural' => false, - 'limit' => 0, - 'style' => array('font-weight: bold;'), - 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html'), - ), - 'Citation' => array( - 'id' => 'citation', - 'publicContentFilter' => array('libEPC','publicContentFilterCitation'), - 'widgetListFilter' => array('libEPC','widgetListCitation'), - - 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'), - 'has_list' => true, - 'htmltag' => 'cite', - 'class' => array('cite.epc-cite'), - 'replace' => '%s', - 'widget' => '%s', - - 'nocase' => true, - 'plural' => false, - 'limit' => 0, - 'style' => array('font-style: italic;'), - 'notag' => 'a,h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html'), - ), - 'Link' => array( - 'id' => 'link', - 'publicContentFilter' => array('libEPC','publicContentFilterLink'), - 'widgetListFilter' => array('libEPC','widgetListLink'), - - 'help' => __('Link some words. First term of the list is the term to link and second term the link.'), - 'has_list' => true, - 'htmltag' => 'a', - 'class' => array('a.epc-link'), - 'replace' => '%s', - 'widget' => '%s', - - 'nocase' => false, - 'plural' => false, - 'limit' => 0, - 'style' => array('text-decoration: none; font-style: italic; color: #0000FF;'), - 'notag' => 'a,h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html'), - ), - 'Replace' => array( - 'id' => 'replace', - 'publicContentFilter' => array('libEPC','publicContentFilterReplace'), - - 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'), - 'has_list' => true, - 'htmltag' => '', - 'class' => array('span.epc-replace'), - 'replace' => '%s', - - 'nocase' => true, - 'plural' => true, - 'limit' => 0, - 'style' => array('font-style: italic;'), - 'notag' => 'h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html'), - ), - 'Update' => array( - 'id' => 'update', - 'publicContentFilter' => array('libEPC','publicContentFilterUpdate'), - - 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'), - 'has_list' => true, - 'htmltag' => 'del,ins', - 'class' => array('del.epc-update','ins.epc-update'), - 'replace' => '%s %s', - - 'nocase' => true, - 'plural' => true, - 'limit' => 0, - 'style' => array('text-decoration: line-through;','font-style: italic;'), - 'notag' => 'h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html'), - ), - 'Twitter' => array( - 'id' => 'twitter', - 'publicContentFilter' => array('libEPC','publicContentFilterTwitter'), - - 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'), - 'has_list' => false, - 'htmltag' => 'a', - 'class' => array('a.epc-twitter'), - 'replace' => '%s', - - 'nocase' => false, - 'plural' => false, - 'limit' => 0, - 'style' => array('text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'), - 'notag' => 'a,h1,h2,h3', - 'tplValues' => array('EntryContent'), - 'pubPages' => array('post.html') - ) - ); - - $core->callBehavior('enhancePostContentDefaultFilters',$filters); - - return $filters; - } - - public static function blogFilters($one=null) - { - global $core; - $core->blog->settings->addNamespace('enhancePostContent'); - $filters = self::defaultFilters(); - - foreach($filters as $name => $filter) - { - # Parse filters options - $ns = 'enhancePostContent_'.$name; - $opt[$name] = @unserialize($core->blog->settings->enhancePostContent->$ns); - - if (!is_array($opt[$name])) - { - $opt[$name] = array(); - } - if (isset($opt[$name]['nocase'])) - { - $filters[$name]['nocase'] = (boolean) $opt[$name]['nocase']; - } - if (isset($opt[$name]['plural'])) - { - $filters[$name]['plural'] = (boolean) $opt[$name]['plural']; - } - if (isset($opt[$name]['limit'])) - { - $filters[$name]['limit'] = abs((integer) $opt[$name]['limit']); - } - if (isset($opt[$name]['style']) && is_array($opt[$name]['style'])) - { - $filters[$name]['style'] = (array) $opt[$name]['style']; - } - if (isset($opt[$name]['notag'])) - { - $filters[$name]['notag'] = (string) $opt[$name]['notag']; - } - if (isset($opt[$name]['tplValues'])) - { - $filters[$name]['tplValues'] = (array) $opt[$name]['tplValues']; - } - if (isset($opt[$name]['pubPages'])) - { - $filters[$name]['pubPages'] = (array) $opt[$name]['pubPages']; - } - } - - $core->callBehavior('enhancePostContentBlogFilters',$filters); - - return $filters; - } + # + # Default definition + # + + public static function defaultAllowedTplValues() + { + return [ + 'entry excerpt' => 'EntryExcerpt', + 'entry content' => 'EntryContent', + 'comment content' => 'CommentContent', + ]; + } + + public static function blogAllowedTplValues() + { + global $core; + $core->blog->settings->addNamespace('enhancePostContent'); + $allowedtplvalues = self::defaultAllowedTplValues(); + $rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedtplvalues); + return is_array($rs) ? $rs : $allowedtplvalues; + } + + public static function defaultAllowedWidgetValues() + { + global $core; + + $rs = [ + 'entry excerpt' => [ + 'id' => 'entryexcerpt', + 'callback' => ['libEPC','widgetContentEntryExcerpt'] + ], + 'entry content' => [ + 'id' => 'entrycontent', + 'callback' => ['libEPC','widgetContentEntryContent'] + ], + 'comment content' => [ + 'id' => 'commentcontent', + 'callback' => ['libEPC','widgetContentCommentContent'] + ] + ]; + + $core->callBehavior('enhancePostContentAllowedWidgetValues', $rs); + + return $rs; + } + + public static function defaultAllowedPubPages() + { + return [ + 'home page' => 'home.html', + 'post page' => 'post.html', + 'category page' => 'category.html', + 'search results page' => 'search.html', + 'atom feeds' => 'atom.xml', + 'RSS feeds' => 'rss2.xml' + ]; + } + + public static function blogAllowedPubPages() + { + global $core; + $core->blog->settings->addNamespace('enhancePostContent'); + $allowedpubpages = self::defaultAllowedPubPages(); + $rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedpubpages); + return is_array($rs) ? $rs : $allowedpubpages; + } + + public static function defaultFilters() + { + global $core; + + $filters = [ + 'Tag' => [ + 'id' => 'tag', + 'publicContentFilter' => ['libEPC', 'publicContentFilterTag'], + 'widgetListFilter' => ['libEPC', 'widgetListTag'], + + 'help' => __('Highlight tags of your blog.'), + 'has_list' => false, + 'htmltag' => 'a', + 'class' => ['a.epc-tag'], + 'replace' => '%s', + 'widget' => '%s', + + 'nocase' => false, + 'plural' => false, + 'limit' => 0, + 'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'], + 'notag' => 'a,h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'] + ], + 'Search' => [ + 'id' => 'search', + 'publicContentFilter' => ['libEPC', 'publicContentFilterSearch'], + + 'help' => __('Highlight searched words.'), + 'has_list' => false, + 'htmltag' => '', + 'class' => ['span.epc-search'], + 'replace' => '%s', + + 'nocase' => true, + 'plural' => true, + 'limit' => 0, + 'style' => ['color: #FFCC66;'], + 'notag' => 'h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['search.html'] + ], + 'Acronym' => [ + 'id' => 'acronym', + 'publicContentFilter' => ['libEPC', 'publicContentFilterAcronym'], + 'widgetListFilter' => ['libEPC', 'widgetListAcronym'], + + 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'), + 'has_list' => true, + 'htmltag' => 'acronym', + 'class' => ['acronym.epc-acronym'], + 'replace' => '%s', + 'widget' => '%s', + + 'nocase' => false, + 'plural' => false, + 'limit' => 0, + 'style' => ['font-weight: bold;'], + 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'], + ], + 'Abbreviation' => [ + 'id' => 'abbreviation', + 'publicContentFilter' => ['libEPC', 'publicContentFilterAbbreviation'], + 'widgetListFilter' => ['libEPC', 'widgetListAbbreviation'], + + 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'), + 'has_list' => true, + 'htmltag' => 'a', + 'class' => ['abbr.epc-abbr'], + 'replace' => '%s', + 'widget' => '%s', + + 'nocase' => false, + 'plural' => false, + 'limit' => 0, + 'style' => ['font-weight: bold;'], + 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'], + ], + 'Definition' => [ + 'id' => 'definition', + 'publicContentFilter' => ['libEPC', 'publicContentFilterDefinition'], + 'widgetListFilter' => ['libEPC', 'widgetListDefinition'], + + 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'), + 'has_list' => true, + 'htmltag' => 'dfn', + 'class' => ['dfn.epc-dfn'], + 'replace' => '%s', + 'widget' => '%s', + + 'nocase' => false, + 'plural' => false, + 'limit' => 0, + 'style' => ['font-weight: bold;'], + 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'], + ], + 'Citation' => [ + 'id' => 'citation', + 'publicContentFilter' => ['libEPC', 'publicContentFilterCitation'], + 'widgetListFilter' => ['libEPC', 'widgetListCitation'], + + 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'), + 'has_list' => true, + 'htmltag' => 'cite', + 'class' => ['cite.epc-cite'], + 'replace' => '%s', + 'widget' => '%s', + + 'nocase' => true, + 'plural' => false, + 'limit' => 0, + 'style' => ['font-style: italic;'], + 'notag' => 'a,h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'], + ], + 'Link' => [ + 'id' => 'link', + 'publicContentFilter' => ['libEPC', 'publicContentFilterLink'], + 'widgetListFilter' => ['libEPC', 'widgetListLink'], + + 'help' => __('Link some words. First term of the list is the term to link and second term the link.'), + 'has_list' => true, + 'htmltag' => 'a', + 'class' => ['a.epc-link'], + 'replace' => '%s', + 'widget' => '%s', + + 'nocase' => false, + 'plural' => false, + 'limit' => 0, + 'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'], + 'notag' => 'a,h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'], + ], + 'Replace' => [ + 'id' => 'replace', + 'publicContentFilter' => ['libEPC', 'publicContentFilterReplace'], + + 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'), + 'has_list' => true, + 'htmltag' => '', + 'class' => ['span.epc-replace'], + 'replace' => '%s', + + 'nocase' => true, + 'plural' => true, + 'limit' => 0, + 'style' => ['font-style: italic;'], + 'notag' => 'h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'], + ], + 'Update' => [ + 'id' => 'update', + 'publicContentFilter' => ['libEPC', 'publicContentFilterUpdate'], + + 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'), + 'has_list' => true, + 'htmltag' => 'del,ins', + 'class' => ['del.epc-update', 'ins.epc-update'], + 'replace' => '%s %s', + + 'nocase' => true, + 'plural' => true, + 'limit' => 0, + 'style' => ['text-decoration: line-through;', 'font-style: italic;'], + 'notag' => 'h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'], + ], + 'Twitter' => [ + 'id' => 'twitter', + 'publicContentFilter' => ['libEPC', 'publicContentFilterTwitter'], + + 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'), + 'has_list' => false, + 'htmltag' => 'a', + 'class' => ['a.epc-twitter'], + 'replace' => '%s', + + 'nocase' => false, + 'plural' => false, + 'limit' => 0, + 'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'], + 'notag' => 'a,h1,h2,h3', + 'tplValues' => ['EntryContent'], + 'pubPages' => ['post.html'] + ] + ]; + + $core->callBehavior('enhancePostContentDefaultFilters', $filters); + + return $filters; + } + + public static function blogFilters($one = null) + { + global $core; + $core->blog->settings->addNamespace('enhancePostContent'); + $filters = self::defaultFilters(); + + foreach($filters as $name => $filter) { + # Parse filters options + $ns = 'enhancePostContent_' . $name; + $opt[$name] = @unserialize($core->blog->settings->enhancePostContent->$ns); + + if (!is_array($opt[$name])) { + $opt[$name] = []; + } + if (isset($opt[$name]['nocase'])) { + $filters[$name]['nocase'] = (boolean) $opt[$name]['nocase']; + } + if (isset($opt[$name]['plural'])) { + $filters[$name]['plural'] = (boolean) $opt[$name]['plural']; + } + if (isset($opt[$name]['limit'])) { + $filters[$name]['limit'] = abs((integer) $opt[$name]['limit']); + } + if (isset($opt[$name]['style']) && is_array($opt[$name]['style'])) { + $filters[$name]['style'] = (array) $opt[$name]['style']; + } + if (isset($opt[$name]['notag'])) { + $filters[$name]['notag'] = (string) $opt[$name]['notag']; + } + if (isset($opt[$name]['tplValues'])) { + $filters[$name]['tplValues'] = (array) $opt[$name]['tplValues']; + } + if (isset($opt[$name]['pubPages'])) { + $filters[$name]['pubPages'] = (array) $opt[$name]['pubPages']; + } + } + + $core->callBehavior('enhancePostContentBlogFilters', $filters); + + return $filters; + } - public static function testContext($tag,$args,$opt) - { - return - isset($opt['pubPages']) - && is_array($opt['pubPages']) - && in_array($GLOBALS['_ctx']->current_tpl,$opt['pubPages']) - && isset($opt['tplValues']) - && is_array($opt['tplValues']) - && in_array($tag,$opt['tplValues']) - && $args[0] != '' //content - && !$args[2] // remove html - ; - } - - public static function replaceString($p,$r,$s,$filter,$before='\b',$after='\b') - { - # Limit - if ($filter['limit'] > 0) - { - $l = isset($GLOBALS['epcFilterLimit'][$filter['id']][$p]) ? $GLOBALS['epcFilterLimit'][$filter['id']][$p] : $filter['limit']; - if ($l < 1) return $s; - } else { - $l = -1; - } - # Case sensitive - $i = $filter['nocase'] ? 'i' : ''; - # Plural - $x = $filter['plural'] ? $p.'s|'.$p : $p; - # Mark words - $s = preg_replace('#('.$before.')('.$x.')('.$after.')#s'.$i,'$1ççççç$2ççççç$3',$s,-1,$count); - # Nothing to parse - if (!$count) return $s; - # Remove words that are into unwanted html 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); - } - if (!empty($tags)) - { - $s = preg_replace_callback('#(<('.$tags.')[^>]*?>)(.*?)()#s',array('libEPC','removeTags'),$s); - } - # Remove words inside html tag (class, title, alt, href, ...) - $s = preg_replace('#(ççççç('.$p.'(s|))ççççç)(?=[^<]+>)#s'.$i,'$2$4',$s); - # Replace words by what you want (with limit) - $s = preg_replace('#ççççç('.$p.'(s|))ççççç#s'.$i,$r,$s,$l,$count); - # update limit - $GLOBALS['epcFilterLimit'][$filter['id']][$p] = $l - $count; - # Clean rest - return $s = preg_replace('#ççççç(.*?)ççççç#s','$1',$s); - } - - public static function matchString($p,$r,$s,$filter,$before='\b',$after='\b') - { - # Case sensitive - $i = $filter['nocase'] ? 'i' : ''; - # Plural - $x = $filter['plural'] ? $p.'s|'.$p : $p; - # Mark words - $t = preg_match_all('#'.$before.'('.$x.')'.$after.'#s'.$i,$s,$matches); - # Nothing to parse - if (!$t) return array('total'=>0,'matches'=>array()); - - # Build array - $m = array(); - $loop=0; - 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; - $loop++; - } - return array('total'=>$t,'matches'=>$m); - } - - public static function quote($s) - { - return preg_quote($s,'#'); - } - - public static function removeTags($m) - { - return $m[1].preg_replace('#ççççç(?!ççççç)#s','$1',$m[3]).$m[4]; - } - - public static function decodeTags($t) - { - return preg_match_all('#([A-Za-z0-9]+)#',(string) $t, $m) ? $m[1] : array(); - } - - public static function implode($a) - { - if (is_string($a)) return $a; - if (!is_array($a)) return array(); - - $r = ''; - foreach($a as $k => $v) - { - $r .= $k.':'.$v.';'; - } - return $r; - } - - public static function explode($s) - { - if (is_array($s)) return $s; - if (!is_string($s)) return ''; - - $r = array(); - $s = explode(';',(string) $s); - if (!is_array($s)) return array(); - - foreach($s as $cpl) - { - $cur = explode(':',$cpl); - - if (!is_array($cur) || !isset($cur[1])) continue; - - $key = html::escapeHTML(trim($cur[0])); - $val = html::escapeHTML(trim($cur[1])); - - if (empty($key) || empty($val)) continue; - - $r[$key] = $val; - } - return $r; - } - - # - # Widgets - # - - public static function widgetContentEntryExcerpt($core,$w) - { - global $_ctx; - if (!$_ctx->exists('posts')) return; - - $res = ''; - while ($_ctx->posts->fetch()) - { - $res .= $_ctx->posts->post_excerpt; - } - return $res; - } - - public static function widgetContentEntryContent() - { - global $_ctx; - if (!$_ctx->exists('posts')) return; - - $res = ''; - while ($_ctx->posts->fetch()) - { - $res .= $_ctx->posts->post_content; - } - return $res; - } - - public static function widgetContentCommentContent() - { - global $core, $_ctx; - if (!$_ctx->exists('posts')) return; - - $res = ''; - $post_ids = array(); - while ($_ctx->posts->fetch()) - { - $comments = $core->blog->getComments(array('post_id'=>$_ctx->posts->post_id)); - while ($comments->fetch()) - { - $res .= $comments->getContent(); - } - } - return $res; - } - - # - # Filters - # - - public static function publicContentFilterTag($core,$filter,$tag,$args) - { - if (!$core->plugins->moduleExists('tags')) return; - - $metas = $core->meta->getMetadata(array('meta_type'=>'tag')); - - while($metas->fetch()) - { - $k = $metas->meta_id; - $args[0] = self::replaceString( - $k, - sprintf($filter['replace'],$core->blog->url.$core->url->getBase('tag').'/'.$k,'\\1'), - $args[0], - $filter - ); - } - return; - } - - public static function widgetListTag($core,$filter,$content,$w,&$list) - { - if (!$core->plugins->moduleExists('tags')) return; + public static function testContext($tag, $args, $opt) + { + return + isset($opt['pubPages']) + && is_array($opt['pubPages']) + && in_array($GLOBALS['_ctx']->current_tpl,$opt['pubPages']) + && isset($opt['tplValues']) + && is_array($opt['tplValues']) + && in_array($tag, $opt['tplValues']) + && $args[0] != '' //content + && !$args[2] // remove html + ; + } + + public static function replaceString($p, $r, $s, $filter, $before = '\b', $after = '\b') + { + # Limit + if ($filter['limit'] > 0) { + $l = isset($GLOBALS['epcFilterLimit'][$filter['id']][$p]) ? $GLOBALS['epcFilterLimit'][$filter['id']][$p] : $filter['limit']; + if ($l < 1) { + return $s; + } + } else { + $l = -1; + } + # Case sensitive + $i = $filter['nocase'] ? 'i' : ''; + # Plural + $x = $filter['plural'] ? $p . 's|' . $p : $p; + # Mark words + $s = preg_replace('#(' . $before . ')(' . $x . ')(' . $after . ')#s' . $i, '$1ççççç$2ççççç$3', $s, -1, $count); + # Nothing to parse + if (!$count) { + return $s; + } + # Remove words that are into unwanted html 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); + } + if (!empty($tags)) { + $s = preg_replace_callback('#(<(' . $tags . ')[^>]*?>)(.*?)()#s', ['libEPC', 'removeTags'], $s); + } + # Remove words inside html tag (class, title, alt, href, ...) + $s = preg_replace('#(ççççç(' . $p . '(s|))ççççç)(?=[^<]+>)#s' . $i, '$2$4', $s); + # Replace words by what you want (with limit) + $s = preg_replace('#ççççç(' . $p . '(s|))ççççç#s' . $i, $r, $s, $l, $count); + # update limit + $GLOBALS['epcFilterLimit'][$filter['id']][$p] = $l - $count; + # Clean rest + return $s = preg_replace('#ççççç(.*?)ççççç#s', '$1', $s); + } + + public static function matchString($p, $r, $s, $filter, $before = '\b', $after = '\b') + { + # Case sensitive + $i = $filter['nocase'] ? 'i' : ''; + # Plural + $x = $filter['plural'] ? $p . 's|' . $p : $p; + # Mark words + $t = preg_match_all('#' . $before . '(' . $x . ')' . $after . '#s' . $i, $s, $matches); + # Nothing to parse + if (!$t) { + return ['total' => 0, 'matches' => []]; + } + + # Build array + $m = []; + $loop = 0; + 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; + $loop++; + } + return ['total' => $t, 'matches' => $m]; + } + + public static function quote($s) + { + return preg_quote($s, '#'); + } + + public static function removeTags($m) + { + return $m[1] . preg_replace('#ççççç(?!ççççç)#s', '$1', $m[3]) . $m[4]; + } + + public static function decodeTags($t) + { + return preg_match_all('#([A-Za-z0-9]+)#', (string) $t, $m) ? $m[1] : []; + } + + public static function implode($a) + { + if (is_string($a)) { + return $a; + } + if (!is_array($a)) { + return []; + } + + $r = ''; + foreach($a as $k => $v) { + $r .= $k . ':' . $v . ';'; + } + return $r; + } + + public static function explode($s) + { + if (is_array($s)) { + return $s; + } + if (!is_string($s)) { + return ''; + } + + $r = []; + $s = explode(';', (string) $s); + if (!is_array($s)) { + return []; + } + + foreach($s as $cpl) { + $cur = explode(':', $cpl); + + if (!is_array($cur) || !isset($cur[1])) { + continue; + } + + $key = html::escapeHTML(trim($cur[0])); + $val = html::escapeHTML(trim($cur[1])); + + if (empty($key) || empty($val)) { + continue; + } + + $r[$key] = $val; + } + return $r; + } + + # + # Widgets + # + + public static function widgetContentEntryExcerpt($core, $w) + { + global $_ctx; + if (!$_ctx->exists('posts')) { + return; + } + + $res = ''; + while ($_ctx->posts->fetch()) { + $res .= $_ctx->posts->post_excerpt; + } + return $res; + } + + public static function widgetContentEntryContent() + { + global $_ctx; + if (!$_ctx->exists('posts')) { + return; + } + + $res = ''; + while ($_ctx->posts->fetch()) { + $res .= $_ctx->posts->post_content; + } + return $res; + } + + public static function widgetContentCommentContent() + { + global $core, $_ctx; + if (!$_ctx->exists('posts')) { + return; + } + + $res = ''; + $post_ids = []; + while ($_ctx->posts->fetch()) { + $comments = $core->blog->getComments(['post_id' => $_ctx->posts->post_id]); + while ($comments->fetch()) { + $res .= $comments->getContent(); + } + } + return $res; + } + + # + # Filters + # + + public static function publicContentFilterTag($core, $filter, $tag, $args) + { + if (!$core->plugins->moduleExists('tags')) { + return; + } + + $metas = $core->meta->getMetadata(['meta_type' => 'tag']); + + while($metas->fetch()) { + $k = $metas->meta_id; + $args[0] = self::replaceString( + $k, + sprintf($filter['replace'], $core->blog->url . $core->url->getBase('tag') . '/' . $k, '\\1'), + $args[0], + $filter + ); + } + return; + } + + public static function widgetListTag($core, $filter, $content, $w, &$list) + { + if (!$core->plugins->moduleExists('tags')) { + return; + } - $metas = $core->meta->getMetadata(array('meta_type'=>'tag')); - - while($metas->fetch()) - { - $k = $metas->meta_id; - $list[] = self::matchString( - $k, - sprintf($filter['widget'],$core->blog->url.$core->url->getBase('tag').'/'.$k,'\\1'), - $content, - $filter - ); - } - return; - } - - public static function publicContentFilterSearch($core,$filter,$tag,$args) - { - if (!isset($GLOBALS['_search'])) return; - - $searchs = explode(' ',$GLOBALS['_search']); - - foreach($searchs as $k => $v) - { - $args[0] = self::replaceString( - $v, - sprintf($filter['replace'],'\\1'), - $args[0], - $filter - ); - } - return; - } - - public static function publicContentFilterAcronym($core,$filter,$tag,$args) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $args[0] = self::replaceString( - $k, - sprintf($filter['replace'],__($v),'\\1'), - $args[0], - $filter - ); - } - return; - } - - public static function widgetListAcronym($core,$filter,$content,$w,&$list) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $list[] = self::matchString( - $k, - sprintf($filter['widget'],__($v),'\\1'), - $content, - $filter - ); - } - return; - } - - public static function publicContentFilterAbbreviation($core,$filter,$tag,$args) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $args[0] = self::replaceString( - $k, - sprintf($filter['replace'],__($v),'\\1'), - $args[0], - $filter - ); - } - return; - } - - public static function widgetListAbbreviation($core,$filter,$content,$w,&$list) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $list[] = self::matchString( - $k, - sprintf($filter['widget'],__($v),'\\1'), - $content, - $filter - ); - } - return; - } - - public static function publicContentFilterDefinition($core,$filter,$tag,$args) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $args[0] = self::replaceString( - $k, - sprintf($filter['replace'],__($v),'\\1'), - $args[0], - $filter - ); - } - return; - } - - public static function widgetListDefinition($core,$filter,$content,$w,&$list) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $list[] = self::matchString( - $k, - sprintf($filter['widget'],__($v),'\\1'), - $content, - $filter - ); - } - return; - } - - public static function publicContentFilterCitation($core,$filter,$tag,$args) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $args[0] = self::replaceString( - $k, - sprintf($filter['replace'],__($v),'\\1'), - $args[0], - $filter - ); - } - return; - } - - public static function widgetListCitation($core,$filter,$content,$w,&$list) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $list[] = self::matchString( - $k, - sprintf($filter['widget'],__($v),'\\1'), - $content, - $filter - ); - } - return; - } - - public static function publicContentFilterLink($core,$filter,$tag,$args) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $args[0] = self::replaceString( - $k, - sprintf($filter['replace'],'\\1',$v,'\\1'), - $args[0], - $filter - ); - } - return; - } - - public static function widgetListLink($core,$filter,$content,$w,&$list) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $list[] = self::matchString( - $k, - sprintf($filter['widget'],$v,$v,'\\1'), - $content, - $filter - ); - } - return; - } - - public static function publicContentFilterReplace($core,$filter,$tag,$args) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $args[0] = self::replaceString( - $k, - sprintf($filter['replace'],$v,'\\2'), - $args[0], - $filter - ); - } - return; - } - - public static function publicContentFilterUpdate($core,$filter,$tag,$args) - { - while($filter['list']->fetch()) - { - $k = $filter['list']->epc_key; - $v = $filter['list']->epc_value; - - $args[0] = self::replaceString( - $k, - sprintf($filter['replace'],'\\1',$v), - $args[0], - $filter - ); - } - return; - } - - public static function publicContentFilterTwitter($core,$filter,$tag,$args) - { - $args[0] = self::replaceString( - '[A-Za-z0-9_]{2,}', - sprintf($filter['replace'],'http://twitter.com/\\1','\\1'), - $args[0], - $filter, - '[^@]@','\b' - ); - return; - } -} -?> \ No newline at end of file + $metas = $core->meta->getMetadata(['meta_type' => 'tag']); + + while($metas->fetch()) { + $k = $metas->meta_id; + $list[] = self::matchString( + $k, + sprintf($filter['widget'], $core->blog->url . $core->url->getBase('tag') . '/' . $k, '\\1'), + $content, + $filter + ); + } + return; + } + + public static function publicContentFilterSearch($core, $filter, $tag, $args) + { + if (!isset($GLOBALS['_search'])) { + return; + } + + $searchs = explode(' ', $GLOBALS['_search']); + + foreach($searchs as $k => $v) { + $args[0] = self::replaceString( + $v, + sprintf($filter['replace'], '\\1'), + $args[0], + $filter + ); + } + return; + } + + public static function publicContentFilterAcronym($core, $filter, $tag, $args) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $args[0] = self::replaceString( + $k, + sprintf($filter['replace'], __($v), '\\1'), + $args[0], + $filter + ); + } + return; + } + + public static function widgetListAcronym($core, $filter, $content, $w, &$list) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $list[] = self::matchString( + $k, + sprintf($filter['widget'], __($v), '\\1'), + $content, + $filter + ); + } + return; + } + + public static function publicContentFilterAbbreviation($core, $filter, $tag, $args) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $args[0] = self::replaceString( + $k, + sprintf($filter['replace'], __($v), '\\1'), + $args[0], + $filter + ); + } + return; + } + + public static function widgetListAbbreviation($core, $filter, $content, $w, &$list) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $list[] = self::matchString( + $k, + sprintf($filter['widget'], __($v), '\\1'), + $content, + $filter + ); + } + return; + } + + public static function publicContentFilterDefinition($core, $filter, $tag, $args) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $args[0] = self::replaceString( + $k, + sprintf($filter['replace'], __($v), '\\1'), + $args[0], + $filter + ); + } + return; + } + + public static function widgetListDefinition($core, $filter, $content, $w, &$list) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $list[] = self::matchString( + $k, + sprintf($filter['widget'], __($v), '\\1'), + $content, + $filter + ); + } + return; + } + + public static function publicContentFilterCitation($core, $filter, $tag, $args) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $args[0] = self::replaceString( + $k, + sprintf($filter['replace'], __($v), '\\1'), + $args[0], + $filter + ); + } + return; + } + + public static function widgetListCitation($core, $filter, $content, $w, &$list) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $list[] = self::matchString( + $k, + sprintf($filter['widget'], __($v), '\\1'), + $content, + $filter + ); + } + return; + } + + public static function publicContentFilterLink($core, $filter, $tag, $args) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $args[0] = self::replaceString( + $k, + sprintf($filter['replace'], '\\1', $v, '\\1'), + $args[0], + $filter + ); + } + return; + } + + public static function widgetListLink($core, $filter, $content, $w, &$list) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $list[] = self::matchString( + $k, + sprintf($filter['widget'], $v, $v, '\\1'), + $content, + $filter + ); + } + return; + } + + public static function publicContentFilterReplace($core, $filter, $tag, $args) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $args[0] = self::replaceString( + $k, + sprintf($filter['replace'], $v, '\\2'), + $args[0], + $filter + ); + } + return; + } + + public static function publicContentFilterUpdate($core, $filter, $tag, $args) + { + while($filter['list']->fetch()) { + $k = $filter['list']->epc_key; + $v = $filter['list']->epc_value; + + $args[0] = self::replaceString( + $k, + sprintf($filter['replace'], '\\1', $v), + $args[0], + $filter + ); + } + return; + } + + public static function publicContentFilterTwitter($core, $filter, $tag, $args) + { + $args[0] = self::replaceString( + '[A-Za-z0-9_]{2,}', + sprintf($filter['replace'], 'http://twitter.com/\\1', '\\1'), + $args[0], + $filter, + '[^@]@', + '\b' + ); + return; + } +} \ No newline at end of file diff --git a/inc/lib.epc.records.php b/inc/lib.epc.records.php index 59c3f55..2574e45 100644 --- a/inc/lib.epc.records.php +++ b/inc/lib.epc.records.php @@ -13,212 +13,179 @@ class epcRecords { - public $core; - public $con; - public $table; - public $blog; - - public function __construct($core) - { - $this->core = $core; - $this->con = $core->con; - $this->table = $core->prefix.'epc'; - $this->blog = $core->con->escape($core->blog->id); - } - - public function getRecords($params,$count_only=false) - { - if ($count_only) - { - $strReq = 'SELECT count(E.epc_id) '; - } - else - { - $content_req = ''; - 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, '. - $content_req. - 'E.epc_filter, E.epc_key, E.epc_value '; - } - - $strReq .= - 'FROM '.$this->table.' E '; - - if (!empty($params['from'])) - { - $strReq .= $params['from'].' '; - } - - $strReq .= "WHERE E.blog_id = '".$this->blog."' "; - - if (isset($params['epc_type'])) - { - if (is_array($params['epc_type']) && !empty($params['epc_type'])) - { - $strReq .= 'AND E.epc_type '.$this->con->in($params['epc_type']); - } - elseif ($params['epc_type'] != '') - { - $strReq .= "AND E.epc_type = '".$this->con->escape($params['epc_type'])."' "; - } - } - else - { - $strReq .= "AND E.epc_type = 'epc' "; - } - - if (isset($params['epc_filter'])) - { - if (is_array($params['epc_filter']) && !empty($params['epc_filter'])) - { - $strReq .= 'AND E.epc_filter '.$this->con->in($params['epc_filter']); - } - elseif ($params['epc_filter'] != '') - { - $strReq .= "AND E.epc_filter = '".$this->con->escape($params['epc_filter'])."' "; - } - } - - if (!empty($params['epc_id'])) - { - if (is_array($params['epc_id'])) - { - array_walk($params['epc_id'],create_function('&$v,$k','if($v!==null){$v=(integer)$v;}')); - } - else - { - $params['epc_id'] = array((integer) $params['epc_id']); - } - $strReq .= 'AND E.epc_id '.$this->con->in($params['epc_id']); - } - - if (!empty($params['sql'])) - { - $strReq .= $params['sql'].' '; - } - - if (!$count_only) - { - if (!empty($params['order'])) - { - $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; - } - else - { - $strReq .= 'ORDER BY E.epc_key ASC '; - } - } - - if (!$count_only && !empty($params['limit'])) - { - $strReq .= $this->con->limit($params['limit']); - } - - return $this->con->select($strReq); - } - - public function addRecord($cur) - { - $this->con->writeLock($this->table); - - try - { - $cur->epc_id = $this->getNextId(); - $cur->blog_id = $this->blog; - $cur->epc_upddt = date('Y-m-d H:i:s'); - - $this->getCursor($cur); - - $cur->insert(); - $this->con->unlock(); - } - catch (Exception $e) - { - $this->con->unlock(); - throw $e; - } - $this->trigger(); - - # --BEHAVIOR-- enhancePostContentAfterAddRecord - $this->core->callBehavior('enhancePostContentAfterAddRecord',$cur); - - return $cur->epc_id; - } - - public function updRecord($id,$cur) - { - $id = (integer) $id; - - if (empty($id)) - { - throw new Exception(__('No such record ID')); - } - - $cur->epc_upddt = date('Y-m-d H:i:s'); - - $cur->update("WHERE epc_id = ".$id." AND blog_id = '".$this->blog."' "); - $this->trigger(); - - # --BEHAVIOR-- enhancePostContentAfterUpdRecord - $this->core->callBehavior('enhancePostContentAfterUpdRecord',$cur,$id); - } + public $core; + public $con; + public $table; + public $blog; - public function delRecord($id) - { - $id = (integer) $id; - - if (empty($id)) { - throw new Exception(__('No such record ID')); - } + public function __construct($core) + { + $this->core = $core; + $this->con = $core->con; + $this->table = $core->prefix . 'epc'; + $this->blog = $core->con->escape($core->blog->id); + } - # --BEHAVIOR-- enhancePostContentBeforeDelRecord - $this->core->callBehavior('enhancePostContentbeforeDelRecord',$id); + public function getRecords($params, $count_only = false) + { + if ($count_only) { + $strReq = 'SELECT count(E.epc_id) '; + } else { + $content_req = ''; + 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, ' . + $content_req . + 'E.epc_filter, E.epc_key, E.epc_value '; + } - $this->con->execute( - 'DELETE FROM '.$this->table.' '. - 'WHERE epc_id = '.$id.' '. - "AND blog_id = '".$this->blog."' " - ); + $strReq .= + 'FROM ' . $this->table . ' E '; - $this->trigger(); - } - - private function getNextId() - { - return $this->con->select( - 'SELECT MAX(epc_id) FROM '.$this->table.' ' - )->f(0) + 1; - } - - public function openCursor() - { - return $this->con->openCursor($this->table); - } - - private function getCursor($cur,$epc_id=null) - { - if ($cur->epc_key == '') - { - throw new Exception(__('No record key')); - } - if ($cur->epc_value == '') - { - throw new Exception(__('No record value')); - } - if ($cur->epc_filter == '') - { - throw new Exception(__('No record filter')); - } - $epc_id = is_int($epc_id) ? $epc_id : $cur->epc_id; - } - - private function trigger() - { - $this->core->blog->triggerBlog(); - } -} -?> \ No newline at end of file + if (!empty($params['from'])) { + $strReq .= $params['from'] . ' '; + } + + $strReq .= "WHERE E.blog_id = '" . $this->blog . "' "; + + if (isset($params['epc_type'])) { + if (is_array($params['epc_type']) && !empty($params['epc_type'])) { + $strReq .= 'AND E.epc_type ' . $this->con->in($params['epc_type']); + } elseif ($params['epc_type'] != '') { + $strReq .= "AND E.epc_type = '" . $this->con->escape($params['epc_type']) . "' "; + } + } else { + $strReq .= "AND E.epc_type = 'epc' "; + } + + if (isset($params['epc_filter'])) { + if (is_array($params['epc_filter']) && !empty($params['epc_filter'])) { + $strReq .= 'AND E.epc_filter ' . $this->con->in($params['epc_filter']); + } elseif ($params['epc_filter'] != '') { + $strReq .= "AND E.epc_filter = '" . $this->con->escape($params['epc_filter']) . "' "; + } + } + + if (!empty($params['epc_id'])) { + if (is_array($params['epc_id'])) { + array_walk($params['epc_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}')); + } else { + $params['epc_id'] = [(integer) $params['epc_id']]; + } + $strReq .= 'AND E.epc_id ' . $this->con->in($params['epc_id']); + } + + if (!empty($params['sql'])) { + $strReq .= $params['sql'] . ' '; + } + + if (!$count_only) { + if (!empty($params['order'])) { + $strReq .= 'ORDER BY ' . $this->con->escape($params['order']) . ' '; + } else { + $strReq .= 'ORDER BY E.epc_key ASC '; + } + } + + if (!$count_only && !empty($params['limit'])) { + $strReq .= $this->con->limit($params['limit']); + } + + return $this->con->select($strReq); + } + + public function addRecord($cur) + { + $this->con->writeLock($this->table); + + try { + $cur->epc_id = $this->getNextId(); + $cur->blog_id = $this->blog; + $cur->epc_upddt = date('Y-m-d H:i:s'); + + $this->getCursor($cur); + + $cur->insert(); + $this->con->unlock(); + } catch (Exception $e) { + $this->con->unlock(); + throw $e; + } + $this->trigger(); + + # --BEHAVIOR-- enhancePostContentAfterAddRecord + $this->core->callBehavior('enhancePostContentAfterAddRecord', $cur); + + return $cur->epc_id; + } + + public function updRecord($id, $cur) + { + $id = (integer) $id; + + if (empty($id)) { + throw new Exception(__('No such record ID')); + } + + $cur->epc_upddt = date('Y-m-d H:i:s'); + + $cur->update("WHERE epc_id = " . $id . " AND blog_id = '" . $this->blog . "' "); + $this->trigger(); + + # --BEHAVIOR-- enhancePostContentAfterUpdRecord + $this->core->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id); + } + + public function delRecord($id) + { + $id = (integer) $id; + + if (empty($id)) { + throw new Exception(__('No such record ID')); + } + + # --BEHAVIOR-- enhancePostContentBeforeDelRecord + $this->core->callBehavior('enhancePostContentbeforeDelRecord', $id); + + $this->con->execute( + 'DELETE FROM ' . $this->table . ' ' . + 'WHERE epc_id = ' . $id .' ' . + "AND blog_id = '" . $this->blog . "' " + ); + + $this->trigger(); + } + + private function getNextId() + { + return $this->con->select( + 'SELECT MAX(epc_id) FROM ' . $this->table . ' ' + )->f(0) + 1; + } + + public function openCursor() + { + return $this->con->openCursor($this->table); + } + + private function getCursor($cur, $epc_id = null) + { + if ($cur->epc_key == '') { + throw new Exception(__('No record key')); + } + if ($cur->epc_value == '') { + throw new Exception(__('No record value')); + } + if ($cur->epc_filter == '') { + throw new Exception(__('No record filter')); + } + $epc_id = is_int($epc_id) ? $epc_id : $cur->epc_id; + } + + private function trigger() + { + $this->core->blog->triggerBlog(); + } +} \ No newline at end of file diff --git a/inc/lib.epc.update.php b/inc/lib.epc.update.php index 68aff59..45b6741 100644 --- a/inc/lib.epc.update.php +++ b/inc/lib.epc.update.php @@ -13,31 +13,26 @@ # This file only update old filters lists from settings to database -$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)) - { - $curlist = @unserialize($f->setting_value); - if (is_array($curlist)) - { - foreach($curlist as $k => $v) - { - $cur = $core->con->openCursor($core->prefix.'epc'); - $core->con->writeLock($core->prefix.'epc'); +while ($f->fetch()) { + if (preg_match('#enhancePostContent_(.*?)List#', $f->setting_id, $m)) { + $curlist = @unserialize($f->setting_value); + if (is_array($curlist)) { + 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_filter = $m[1]; - $cur->epc_key = $k; - $cur->epc_value = $v; + $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 = $m[1]; + $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."' "); - } -} -?> \ No newline at end of file + $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 . "' "); + } +} \ No newline at end of file diff --git a/index.php b/index.php index fe1dd37..dd39484 100644 --- a/index.php +++ b/index.php @@ -12,8 +12,7 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + return null; } dcPage::check('contentadmin'); @@ -26,7 +25,7 @@ $s = $core->blog->settings->enhancePostContent; $_filters = libEPC::blogFilters(); $filters_id = array(); foreach($_filters as $name => $filter) { - $filters_id[$filter['id']] = $name; + $filters_id[$filter['id']] = $name; } $action = isset($_POST['action']) ? $_POST['action'] : ''; @@ -37,404 +36,391 @@ $records = new epcRecords($core); # -- Action -- if (!empty($action)) { - # --BEHAVIOR-- enhancePostContentAdminSave - $core->callBehavior('enhancePostContentAdminSave',$core); + # --BEHAVIOR-- enhancePostContentAdminSave + $core->callBehavior('enhancePostContentAdminSave', $core); } -try -{ - # Update filter settings - if ($action == 'savefiltersetting' - && isset($filters_id[$default_part]) - ) { - # Parse filters options - $name = $filters_id[$default_part]; - $f = array( - 'nocase' => !empty($_POST['filter_nocase']), - 'plural' => !empty($_POST['filter_plural']), - 'limit' => abs((integer) $_POST['filter_limit']), - 'style' => (array) $_POST['filter_style'], - 'notag' => (string) $_POST['filter_notag'], - 'tplValues' => (array) $_POST['filter_tplValues'], - 'pubPages' => (array) $_POST['filter_pubPages'] - ); +try { + # Update filter settings + if ($action == 'savefiltersetting' + && isset($filters_id[$default_part])) { + # Parse filters options + $name = $filters_id[$default_part]; + $f = [ + 'nocase' => !empty($_POST['filter_nocase']), + 'plural' => !empty($_POST['filter_plural']), + 'limit' => abs((integer) $_POST['filter_limit']), + 'style' => (array) $_POST['filter_style'], + 'notag' => (string) $_POST['filter_notag'], + 'tplValues' => (array) $_POST['filter_tplValues'], + 'pubPages' => (array) $_POST['filter_pubPages'] + ]; - $s->put('enhancePostContent_'.$name, serialize($f)); + $s->put('enhancePostContent_' . $name, serialize($f)); - $core->blog->triggerBlog(); + $core->blog->triggerBlog(); - dcPage::addSuccessNotice( - __('Filter successfully updated.') - ); - http::redirect( - $p_url.'part='.$default_part.'#setting' - ); - } + dcPage::addSuccessNotice( + __('Filter successfully updated.') + ); + http::redirect( + $p_url . 'part=' . $default_part . '#setting' + ); + } - # Add new filter record - if ($action == 'savenewrecord' - && isset($filters_id[$default_part]) - && !empty($_POST['new_key']) - && !empty($_POST['new_value']) - ) { - $cur = $records->openCursor(); - $cur->epc_filter = $filters_id[$default_part]; - $cur->epc_key = html::escapeHTML($_POST['new_key']); - $cur->epc_value = html::escapeHTML($_POST['new_value']); - $records->addRecord($cur); + # Add new filter record + if ($action == 'savenewrecord' + && isset($filters_id[$default_part]) + && !empty($_POST['new_key']) + && !empty($_POST['new_value'])) { + $cur = $records->openCursor(); + $cur->epc_filter = $filters_id[$default_part]; + $cur->epc_key = html::escapeHTML($_POST['new_key']); + $cur->epc_value = html::escapeHTML($_POST['new_value']); + $records->addRecord($cur); - $core->blog->triggerBlog(); + $core->blog->triggerBlog(); - dcPage::addSuccessNotice( - __('Filter successfully updated.') - ); - http::redirect( - $p_url.'&part='.$default_part.'#record' - ); - } + dcPage::addSuccessNotice( + __('Filter successfully updated.') + ); + http::redirect( + $p_url . '&part=' . $default_part . '#record' + ); + } - # Update filter records - if ($action == 'saveupdaterecords' - && isset($filters_id[$default_part]) - && $_filters[$filters_id[$default_part]]['has_list'] - ) { - foreach($_POST['epc_id'] as $k => $id) { + # Update filter records + if ($action == 'saveupdaterecords' + && isset($filters_id[$default_part]) + && $_filters[$filters_id[$default_part]]['has_list']) { + foreach($_POST['epc_id'] as $k => $id) { - $k = abs((integer) $k); - $id = abs((integer) $id); + $k = abs((integer) $k); + $id = abs((integer) $id); - if (empty($_POST['epc_key'][$k]) - || empty($_POST['epc_value'][$k]) - ) { - $records->delRecord($id); - } - elseif ($_POST['epc_key'][$k] != $_POST['epc_old_key'][$k] - || $_POST['epc_value'][$k] != $_POST['epc_old_value'][$k] - ) { - $cur = $records->openCursor(); - $cur->epc_filter = $filters_id[$default_part]; - $cur->epc_key = html::escapeHTML($_POST['epc_key'][$k]); - $cur->epc_value = html::escapeHTML($_POST['epc_value'][$k]); - $records->updRecord($id,$cur); - } - } + if (empty($_POST['epc_key'][$k]) + || empty($_POST['epc_value'][$k])) { + $records->delRecord($id); + } elseif ($_POST['epc_key'][$k] != $_POST['epc_old_key'][$k] + || $_POST['epc_value'][$k] != $_POST['epc_old_value'][$k]) { + $cur = $records->openCursor(); + $cur->epc_filter = $filters_id[$default_part]; + $cur->epc_key = html::escapeHTML($_POST['epc_key'][$k]); + $cur->epc_value = html::escapeHTML($_POST['epc_value'][$k]); + $records->updRecord($id, $cur); + } + } - $core->blog->triggerBlog(); + $core->blog->triggerBlog(); - $redir = !empty($_REQUEST['redir']) ? - $_REQUEST['redir'] : - $p_url.'&part='.$default_part.'#record'; + $redir = !empty($_REQUEST['redir']) ? + $_REQUEST['redir'] : + $p_url . '&part=' . $default_part . '#record'; - dcPage::addSuccessNotice( - __('Filter successfully updated.') - ); - http::redirect( - $redir - ); - } -} -catch(Exception $e) { - $core->error->add($e->getMessage()); + dcPage::addSuccessNotice( + __('Filter successfully updated.') + ); + http::redirect( + $redir + ); + } +} catch(Exception $e) { + $core->error->add($e->getMessage()); } # -- Prepare page -- -$breadcrumb = array( - html::escapeHTML($core->blog->name) => '', - __('Enhance post content') => $p_url -); -$top_menu = array(); +$breadcrumb = [ + html::escapeHTML($core->blog->name) => '', + __('Enhance post content') => $p_url +]; +$top_menu = []; foreach($filters_id as $id => $name) { - $active = ''; - if ($default_part == $id) { - $breadcrumb[__($filters_id[$default_part])] = ''; - $active = ' class="active"'; - } + $active = ''; + if ($default_part == $id) { + $breadcrumb[__($filters_id[$default_part])] = ''; + $active = ' class="active"'; + } - $top_menu[] = - ''.__($name).''; + $top_menu[] = + '' . __($name) . ''; } # -- Display page -- # Headers echo ' -'.__('Enhance post content').''. -dcPage::jsLoad('js/_posts_list.js'). -dcPage::jsToolbar(). -dcPage::jsPageTabs(). +' . __('Enhance post content') . '' . +dcPage::jsLoad('js/_posts_list.js') . +dcPage::jsToolbar() . +dcPage::jsPageTabs() . # --BEHAVIOR-- enhancePostContentAdminHeader -$core->callBehavior('enhancePostContentAdminHeader',$core).' +$core->callBehavior('enhancePostContentAdminHeader', $core) . ' -'. +' . # Title -dcPage::breadcrumb($breadcrumb). -dcPage::notices(). +dcPage::breadcrumb($breadcrumb) . +dcPage::notices() . # Filters list -'
      '. -'
    • '.implode('
    • ', $top_menu).'
    • '. +'
        ' . +'
      • ' . implode('
      • ', $top_menu) . '
      • ' . '
      '; # Filter content if (isset($filters_id[$default_part])) { - $name = $filters_id[$default_part]; - $filter = $_filters[$name]; + $name = $filters_id[$default_part]; + $filter = $_filters[$name]; - # Filter title and description - echo ' -

      '.__($filters_id[$default_part]).'

      -

      '.$filter['help'].'

      '; + # Filter title and description + echo ' +

      ' . __($filters_id[$default_part]) . '

      +

      ' . $filter['help'] . '

      '; - # Filter settings - echo ' -
      -
      '; + # Filter settings + echo ' +
      +
      '; - echo - '
      -

      '.__('Pages to be filtered').'

      '; + echo + '
      +

      ' . __('Pages to be filtered') . '

      '; - foreach(libEPC::blogAllowedPubPages() as $k => $v) { - echo ' -

      '; - } + foreach(libEPC::blogAllowedPubPages() as $k => $v) { + echo ' +

      '; + } - echo - '
      '; + echo + '
      '; - echo - '
      -

      '.__('Filtering').'

      + echo + '
      +

      ' . __('Filtering') . '

      -

      +

      -

      +

      -

      '. - form::field('filter_limit', 4, 10, html::escapeHTML($filter['limit'])).' -

      -

      '.__('Leave it blank or set it to 0 for no limit').'

      +

      ' . + form::field('filter_limit', 4, 10, html::escapeHTML($filter['limit'])) . ' +

      +

      ' . __('Leave it blank or set it to 0 for no limit') . '

      -
      '; +
      '; - echo - '
      -

      '.__('Contents to be filtered').'

      '; + echo + '
      +

      ' . __('Contents to be filtered') . '

      '; - foreach(libEPC::blogAllowedTplValues() as $k => $v) { - echo ' -

      '; - } + foreach(libEPC::blogAllowedTplValues() as $k => $v) { + echo ' +

      '; + } - echo - '
      '; + echo + '
      '; - echo - '
      -

      '.__('Style').'

      '; + echo + '
      +

      ' . __('Style') . '

      '; - foreach($filter['class'] as $k => $v) { - echo ' -

      '. - form::field( - array('filter_style[]', 'filter_style'.$k), - 60, - 255, - html::escapeHTML($filter['style'][$k]) - ). - '

      '; - } + foreach($filter['class'] as $k => $v) { + echo ' +

      ' . + form::field( + ['filter_style[]', 'filter_style'.$k], + 60, + 255, + html::escapeHTML($filter['style'][$k]) + ) . + '

      '; + } - echo ' -

      '.sprintf(__('The inserted HTML tag looks like: %s'), html::escapeHTML(str_replace('%s', '...', $filter['replace']))).'

      + echo ' +

      ' . sprintf(__('The inserted HTML tag looks like: %s'), html::escapeHTML(str_replace('%s', '...', $filter['replace']))) . '

      -

      '. - form::field('filter_notag', 60, 255, html::escapeHTML($filter['notag'])).' -

      -

      '.__('This is the list of HTML tags where content will be ignored.').' '. - (empty($filter['htmltag']) ? '' : sprintf(__('Tag "%s" always be ignored.'), $filter['htmltag'])).'

      +

      ' . + form::field('filter_notag', 60, 255, html::escapeHTML($filter['notag'])) . ' +

      +

      ' . __('This is the list of HTML tags where content will be ignored.') . ' ' . + (empty($filter['htmltag']) ? '' : sprintf(__('Tag "%s" always be ignored.'), $filter['htmltag'])) . '

      -
      '; +
      '; - echo '
      -
      -

      '. - $core->formNonce(). - form::hidden(array('action'), 'savefiltersetting').' - -

      -
      + echo '
      +
      +

      ' . + $core->formNonce() . + form::hidden(['action'], 'savefiltersetting') . ' + +

      +
      - -
      '; + +
      '; - # Filter records list - if ($filter['has_list']) { + # Filter records list + if ($filter['has_list']) { - $sortby_combo = array( - 'epc_upddt', - 'epc_key', - 'epc_value', - 'epc_id' - ); + $sortby_combo = [ + 'epc_upddt', + 'epc_key', + 'epc_value', + 'epc_id' + ]; - $order_combo = array( - 'asc', - 'desc' - ); - - $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : (string) $s->enhancePostContent_list_sortby; - $order = !empty($_GET['order']) ? $_GET['order'] : (string) $s->enhancePostContent_list_order; - $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; - $nb = !empty($_GET['nb']) && (integer) $_GET['nb'] > 0 ? (integer) $_GET['nb'] : (integer) $s->enhancePostContent_list_nb; + $order_combo = [ + 'asc', + 'desc' + ]; + + $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : (string) $s->enhancePostContent_list_sortby; + $order = !empty($_GET['order']) ? $_GET['order'] : (string) $s->enhancePostContent_list_order; + $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; + $nb = !empty($_GET['nb']) && (integer) $_GET['nb'] > 0 ? (integer) $_GET['nb'] : (integer) $s->enhancePostContent_list_nb; - $params = array(); - $params['epc_filter'] = $name; - $params['limit'] = array((($page-1)*$nb), $nb); + $params = []; + $params['epc_filter'] = $name; + $params['limit'] = [(($page - 1) * $nb), $nb]; - if ($sortby !== '' && in_array($sortby, $sortby_combo)) { - if ($order !== '' && in_array($order, $order_combo)) { - $params['order'] = $sortby.' '.$order; - } - } + if ($sortby !== '' && in_array($sortby, $sortby_combo)) { + if ($order !== '' && in_array($order, $order_combo)) { + $params['order'] = $sortby . ' ' . $order; + } + } - try { - $list = $records->getRecords($params); - $counter = $records->getRecords($params, true); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } + try { + $list = $records->getRecords($params); + $counter = $records->getRecords($params, true); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } - $pager_url = $p_url. - '&nb='.$nb. - '&sortby=%s'. - '&order='.($order == 'desc' ? 'desc' : 'asc'). - '&page=%s'. - '&part='.$default_part. - '#record'; + $pager_url = $p_url . + '&nb=' . $nb . + '&sortby=%s' . + '&order=' . ($order == 'desc' ? 'desc' : 'asc') . + '&page=%s' . + '&part=' . $default_part . + '#record'; - $pager = new pager($page, $counter->f(0), $nb, 10); - $pager->html_prev = __('«prev.'); - $pager->html_next = __('next»'); - $pager->base_url = sprintf($pager_url, $sortby,'%s'); - $pager->var_page = 'page'; + $pager = new pager($page, $counter->f(0), $nb, 10); + $pager->html_prev = __('«prev.'); + $pager->html_next = __('next»'); + $pager->base_url = sprintf($pager_url, $sortby, '%s'); + $pager->var_page = 'page'; - echo ' -
      '; + echo ' +
      '; - if ($core->error->flag() || $list->isEmpty()) { - echo '

      '.__('No record').'

      '; - } - else { - echo ' -
      -

      '.__('Page(s)').' : '.$pager->getLinks().'

      - - - - - - - '; + if ($core->error->flag() || $list->isEmpty()) { + echo '

      ' . __('No record') . '

      '; + } else { + echo ' + +

      ' . __('Page(s)') . ' : ' . $pager->getLinks() . '

      +
      ' - .__('Key').''. - __('Value').''. - __('Date').'
      + + + + + + '; - while($list->fetch()) { - echo ' - - - - - '; - } + while($list->fetch()) { + echo ' + + + + + '; + } - echo ' - -
      ' . + __('Key') . '' . + __('Value') . '' . + __('Date') . '
      '. - form::hidden(array('epc_id[]'), $list->epc_id). - form::hidden(array('epc_old_key[]'), html::escapeHTML($list->epc_key)). - form::hidden(array('epc_old_value[]'), html::escapeHTML($list->epc_value)). - form::field(array('epc_key[]'), 30, 225, html::escapeHTML($list->epc_key), '').''. - form::field(array('epc_value[]'), 90, 225, html::escapeHTML($list->epc_value), 'maximal').''. - dt::dt2str(__('%Y-%m-%d %H:%M'), $list->epc_upddt,$core->auth->getInfo('user_tz')).'
      ' . + form::hidden(['epc_id[]'], $list->epc_id) . + form::hidden(['epc_old_key[]'], html::escapeHTML($list->epc_key)) . + form::hidden(['epc_old_value[]'], html::escapeHTML($list->epc_value)) . + form::field(['epc_key[]'], 30, 225, html::escapeHTML($list->epc_key), '') . '' . + form::field(['epc_value[]'], 90, 225, html::escapeHTML($list->epc_value), 'maximal') . '' . + dt::dt2str(__('%Y-%m-%d %H:%M'), $list->epc_upddt,$core->auth->getInfo('user_tz')) . '
      -

      '.__('In order to remove a record, leave empty its key or value.').'

      -

      '.__('Page(s)').' : '.$pager->getLinks().'

      + echo ' + + +

      ' . __('In order to remove a record, leave empty its key or value.') . '

      +

      ' . __('Page(s)') . ' : ' . $pager->getLinks() . '

      -
      -

      '. - $core->formNonce(). - form::hidden(array('redir'), sprintf($pager_url, $sortby, $page)). - form::hidden(array('action'), 'saveupdaterecords').' - -

      -
      +
      +

      ' . + $core->formNonce() . + form::hidden(['redir'], sprintf($pager_url, $sortby, $page)) . + form::hidden(['action'], 'saveupdaterecords') . ' + +

      +
      -
      '; - } + '; + } - echo '
      '; + echo '
      '; - # New record - echo ' -
      -
      '. + # New record + echo ' +
      + ' . - '

      '. - form::field('new_key', 60, 255). - '

      '. + '

      ' . + form::field('new_key', 60, 255) . + '

      ' . - '

      '. - form::field('new_value', 60, 255). - '

      + '

      ' . + form::field('new_value', 60, 255) . + '

      -

      '. - form::hidden(array('action'), 'savenewrecord'). - $core->formNonce().' - -

      - -
      '; - } +

      ' . + form::hidden(['action'], 'savenewrecord') . + $core->formNonce() . ' + +

      + +
      '; + } } # --BEHAVIOR-- enhancePostContentAdminPage -$core->callBehavior('enhancePostContentAdminPage',$core); +$core->callBehavior('enhancePostContentAdminPage', $core); dcPage::helpBlock('enhancePostContent'); # Footers echo '

      -'.__('Configuration').' - -enhancePostContent - '.$core->plugins->moduleInfo('enhancePostContent', 'version').'  -'.__('enhancePostContent').' +enhancePostContent - ' . $core->plugins->moduleInfo('enhancePostContent', 'version') . '  +' . __('enhancePostContent') . '

      '; \ No newline at end of file diff --git a/locales/en/resources.php b/locales/en/resources.php index 29676b8..19066b3 100644 --- a/locales/en/resources.php +++ b/locales/en/resources.php @@ -11,7 +11,8 @@ # # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')) { return; } +if (!defined('DC_RC_PATH')) { + return; +} -$__resources['help']['enhancePostContent'] = dirname(__FILE__).'/help/help.html'; -?> \ No newline at end of file +$__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html'; \ No newline at end of file diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 29676b8..19066b3 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -11,7 +11,8 @@ # # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')) { return; } +if (!defined('DC_RC_PATH')) { + return; +} -$__resources['help']['enhancePostContent'] = dirname(__FILE__).'/help/help.html'; -?> \ No newline at end of file +$__resources['help']['enhancePostContent'] = dirname(__FILE__) . '/help/help.html'; \ No newline at end of file