diff --git a/_admin.php b/_admin.php index 9c6e23a..dd66729 100644 --- a/_admin.php +++ b/_admin.php @@ -14,12 +14,12 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -$core->blog->settings->addNamespace('enhancePostContent'); +dcCore::app()->blog->settings->addNamespace('enhancePostContent'); -require dirname(__FILE__) . '/_widgets.php'; +require __DIR__ . '/_widgets.php'; # Admin menu -$_menu['Plugins']->addItem( +dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Enhance post content'), 'plugin.php?p=enhancePostContent', 'index.php?pf=enhancePostContent/icon.png', @@ -27,40 +27,40 @@ $_menu['Plugins']->addItem( '/plugin.php\?p=enhancePostContent(&.*)?$/', $_SERVER['REQUEST_URI'] ), - $core->auth->check('contentadmin', $core->blog->id) + dcCore::app()->auth->check('contentadmin', dcCore::app()->blog->id) ); -$core->addBehavior( - 'adminDashboardFavorites', +dcCore::app()->addBehavior( + 'adminDashboardFavoritesV2', ['epcAdminBehaviors', 'adminDashboardFavorites'] ); -$core->addBehavior( - 'adminBlogPreferencesForm', +dcCore::app()->addBehavior( + 'adminBlogPreferencesFormV2', ['epcAdminBehaviors', 'adminBlogPreferencesForm'] ); -$core->addBehavior( +dcCore::app()->addBehavior( 'adminBeforeBlogSettingsUpdate', ['epcAdminBehaviors', 'adminBeforeBlogSettingsUpdate'] ); -$core->addBehavior( - 'adminFiltersLists', +dcCore::app()->addBehavior( + 'adminFiltersListsV2', ['epcAdminBehaviors', 'adminFiltersLists'] ); class epcAdminBehaviors { - public static function adminDashboardFavorites($core, $favs) + public static function adminDashboardFavorites(dcFavorites $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), + 'permissions' => dcCore::app()->auth->check('contentadmin', dcCore::app()->blog->id), 'active_cb' => [ 'epcAdminBehaviors', - 'adminDashboardFavoritesActive' - ] + 'adminDashboardFavoritesActive', + ], ]); } @@ -77,11 +77,11 @@ class epcAdminBehaviors __('Date') => 'epc_upddt', __('Key') => 'epc_key', __('Value') => 'epc_value', - __('ID') => 'epc_id' + __('ID') => 'epc_id', ]; } - public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings) + public static function adminBlogPreferencesForm(dcSettings $blog_settings) { $active = (bool) $blog_settings->enhancePostContent->enhancePostContent_active; $allowedtplvalues = libEPC::blogAllowedTplValues(); @@ -97,7 +97,7 @@ class epcAdminBehaviors '

' . __('This enable public widgets and contents filter.') . '

' . - '

' . + '

' . __('Set content filters') . '

' . '' . '
' . @@ -126,14 +126,14 @@ class epcAdminBehaviors $blog_settings->enhancePostContent->put('enhancePostContent_allowedpubpages', serialize($allowedpubpages)); } - public static function adminFiltersLists(dcCore $core, $sorts) + public static function adminFiltersLists($sorts) { $sorts['epc'] = [ __('Enhance post content'), self::sortbyCombo(), 'epc_upddt', 'desc', - [__('records per page'), 20] + [__('records per page'), 20], ]; } } diff --git a/_define.php b/_define.php index bd35a90..3675b75 100644 --- a/_define.php +++ b/_define.php @@ -18,16 +18,16 @@ $this->registerModule( 'Enhance post content', 'Add features to words in post content', 'Jean-Christian Denis and Contributors', - '2021.11.13', + '2021.12.11', [ - 'requires' => [['core', '2.20']], - 'permissions' => 'contentadmin', + 'requires' => [['core', '2.24']], + 'permissions' => dcAuth::PERMISSION_CONTENT_ADMIN, 'type' => 'plugin', 'support' => 'https://github.com/JcDenis/enhancePostContent', 'details' => 'https://plugins.dotaddict.org/dc2/details/enhancePostContent', 'repository' => 'https://raw.githubusercontent.com/JcDenis/enhancePostContent/master/dcstore.xml', 'settings' => [ - 'blog' => '#params.epc_params' - ] + 'blog' => '#params.epc_params', + ], ] ); diff --git a/_install.php b/_install.php index 07530b8..3445af3 100644 --- a/_install.php +++ b/_install.php @@ -14,10 +14,10 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -$dc_min = '2.18'; +$dc_min = '2.24'; $mod_id = 'enhancePostContent'; -$new_version = $core->plugins->moduleInfo($mod_id, 'version'); -$old_version = $core->getVersion($mod_id); +$new_version = dcCore::app()->plugins->moduleInfo($mod_id, 'version'); +$old_version = dcCore::app()->getVersion($mod_id); if (version_compare($old_version, $new_version, '>=')) { return null; @@ -35,7 +35,7 @@ try { } # Database - $s = new dbStruct($core->con, $core->prefix); + $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $s->epc ->epc_id('bigint', 0, false) ->blog_id('varchar', 32, false) @@ -51,13 +51,13 @@ try { ->index('idx_epc_filter', 'btree', 'epc_filter') ->index('idx_epc_key', 'btree', 'epc_key'); - $si = new dbStruct($core->con, $core->prefix); + $si = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $changes = $si->synchronize($s); $s = null; # Settings - $core->blog->settings->addNamespace($mod_id); - $s = $core->blog->settings->enhancePostContent; + dcCore::app()->blog->settings->addNamespace($mod_id); + $s = dcCore::app()->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); @@ -76,7 +76,7 @@ try { 'style' => $filter->style, 'notag' => $filter->notag, 'tplValues' => $filter->tplValues, - 'pubPages' => $filter->pubPages + 'pubPages' => $filter->pubPages, ]; $s->put('enhancePostContent_' . $id, serialize($opt), 'string', 'Settings for ' . $id, false, true); /* # only tables @@ -92,11 +92,11 @@ try { } # Version - $core->setVersion($mod_id, $new_version); + dcCore::app()->setVersion($mod_id, $new_version); return true; } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } return false; diff --git a/_prepend.php b/_prepend.php index 7d12179..8c233eb 100644 --- a/_prepend.php +++ b/_prepend.php @@ -24,22 +24,22 @@ $filters = [ 'Link', 'Replace', 'Update', - 'Twitter' + 'Twitter', ]; -$d = dirname(__FILE__) . '/inc/'; +$d = __DIR__ . '/inc/'; -$__autoload['libEPC'] = $d . 'lib.epc.php'; -$__autoload['epcFilter'] = $d . 'lib.epc.filter.php'; -$__autoload['epcRecords'] = $d . 'lib.epc.records.php'; -$__autoload['adminEpcList'] = $d . 'lib.epc.pager.php'; +Clearbricks::lib()->autoload(['libEPC' => $d . 'lib.epc.php']); +Clearbricks::lib()->autoload(['epcFilter' => $d . 'lib.epc.filter.php']); +Clearbricks::lib()->autoload(['epcRecords' => $d . 'lib.epc.records.php']); +Clearbricks::lib()->autoload(['adminEpcList' => $d . 'lib.epc.pager.php']); foreach ($filters as $f) { - $__autoload['epcFilter' . $f] = $d . 'lib.epc.filters.php'; - $core->addBehavior('enhancePostContentFilters', ['epcFilter' . $f, 'create']); + Clearbricks::lib()->autoload(['epcFilter' . $f => $d . 'lib.epc.filters.php']); + dcCore::app()->addBehavior('enhancePostContentFilters', ['epcFilter' . $f, 'create']); } -$core->url->register( +dcCore::app()->url->register( 'epccss', 'epc.css', '^epc\.css', diff --git a/_public.php b/_public.php index 60a8304..839055c 100644 --- a/_public.php +++ b/_public.php @@ -14,17 +14,17 @@ if (!defined('DC_RC_PATH')) { return null; } -require dirname(__FILE__) . '/_widgets.php'; +require __DIR__ . '/_widgets.php'; -$core->blog->settings->addNamespace('enhancePostContent'); +dcCore::app()->blog->settings->addNamespace('enhancePostContent'); -if ($core->blog->settings->enhancePostContent->enhancePostContent_active) { - $core->addBehavior( - 'publicHeadContent', +if (dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_active) { + dcCore::app()->addBehavior( + 'publicHeadContentV2', ['publicEnhancePostContent', 'publicHeadContent'] ); - $core->addBehavior( - 'publicBeforeContentFilter', + dcCore::app()->addBehavior( + 'publicBeforeContentFilterV2', ['publicEnhancePostContent', 'publicContentFilter'] ); } @@ -38,12 +38,10 @@ class publicEnhancePostContent { /** * Add filters CSS to page header - * - * @param dcCore $core dcCore instance */ - public static function publicHeadContent(dcCore $core) + public static function publicHeadContent() { - echo dcUtils::cssLoad($core->blog->url . $core->url->getURLFor('epccss')); + echo dcUtils::cssLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('epccss')); } public static function css($args) @@ -80,11 +78,10 @@ class publicEnhancePostContent /** * 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) + public static function publicContentFilter($tag, $args) { $filters = libEPC::getFilters(); diff --git a/_widgets.php b/_widgets.php index d2327b7..d531921 100644 --- a/_widgets.php +++ b/_widgets.php @@ -14,7 +14,7 @@ if (!defined('DC_RC_PATH')) { return null; } -$core->addBehavior( +dcCore::app()->addBehavior( 'initWidgets', ['enhancePostContentWidget', 'adminContentList'] ); @@ -33,8 +33,6 @@ class enhancePostContentWidget */ public static function adminContentList($w) { - global $core; - $w->create( 'epclist', __('Enhance post content'), @@ -109,17 +107,15 @@ class enhancePostContentWidget */ public static function publicContentList($w) { - global $core, $_ctx; - if ($w->offline) { return null; } - $core->blog->settings->addNamespace('enhancePostContent'); + dcCore::app()->blog->settings->addNamespace('enhancePostContent'); # Page - if (!$core->blog->settings->enhancePostContent->enhancePostContent_active - || !in_array($_ctx->current_tpl, ['post.html', 'page.html']) + if (!dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_active + || !in_array(dcCore::app()->ctx->current_tpl, ['post.html', 'page.html']) ) { return null; } @@ -131,7 +127,7 @@ class enhancePostContentWidget if ($w->$ns && is_callable($v['cb'])) { $content .= call_user_func_array( $v['cb'], - [$core, $w] + [dcCore::app(), $w] ); } } diff --git a/inc/lib.epc.filter.php b/inc/lib.epc.filter.php index 0ee19b7..1ae60d1 100644 --- a/inc/lib.epc.filter.php +++ b/inc/lib.epc.filter.php @@ -12,8 +12,6 @@ */ abstract class epcFilter { - public $core; - private $id = 'undefined'; private $records = null; @@ -25,7 +23,7 @@ abstract class epcFilter 'htmltag' => '', 'class' => [], 'replace' => '', - 'widget' => '' + 'widget' => '', ]; private $settings = [ 'nocase' => false, @@ -34,21 +32,20 @@ abstract class epcFilter 'style' => [], 'notag' => '', 'tplValues' => [], - 'pubPages' => [] + 'pubPages' => [], ]; - final public function __construct(dcCore $core) + final public function __construct() { - $this->core = $core; - $this->id = $this->init(); + $this->id = $this->init(); $this->blogSettings(); } - public static function create(arrayObject $o, dcCore $core) + public static function create(arrayObject $o) { $c = get_called_class(); - $o->append(new $c($core)); + $o->append(new $c()); } final public function id() @@ -112,7 +109,7 @@ abstract class epcFilter private function blogSettings() { $ns = 'enhancePostContent_' . $this->id; - $opt = @unserialize($this->core->blog->settings->enhancePostContent->$ns); + $opt = @unserialize(dcCore::app()->blog->settings->enhancePostContent->$ns); if (!is_array($opt)) { $opt = []; @@ -143,7 +140,7 @@ abstract class epcFilter final public function records() { if ($this->records === null && $this->has_list) { - $records = new epcRecords($this->core); + $records = new epcRecords(); $this->records = $records->getRecords(['epc_filter' => $this->id()]); } diff --git a/inc/lib.epc.filters.php b/inc/lib.epc.filters.php index 2c52786..bd93132 100644 --- a/inc/lib.epc.filters.php +++ b/inc/lib.epc.filters.php @@ -21,14 +21,14 @@ class epcFilterTag extends epcFilter 'htmltag' => 'a', 'class' => ['a.epc-tag'], 'replace' => '%s', - 'widget' => '%s' + 'widget' => '%s', ]); $this->setSettings([ 'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'], 'notag' => 'a,h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'tag'; @@ -36,16 +36,16 @@ class epcFilterTag extends epcFilter public function publicContent($tag, $args) { - if (!$this->core->plugins->moduleExists('tags')) { + if (!dcCore::app()->plugins->moduleExists('tags')) { return null; } - $metas = $this->core->meta->getMetadata(['meta_type' => 'tag']); + $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); while ($metas->fetch()) { $args[0] = libEPC::replaceString( $metas->meta_id, - sprintf($this->replace, $this->core->blog->url . $this->core->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), + sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), $args[0], $this ); @@ -56,16 +56,16 @@ class epcFilterTag extends epcFilter public function widgetList($content, $w, &$list) { - if (!$this->core->plugins->moduleExists('tags')) { + if (!dcCore::app()->plugins->moduleExists('tags')) { return null; } - $metas = $this->core->meta->getMetadata(['meta_type' => 'tag']); + $metas = dcCore::app()->meta->getMetadata(['meta_type' => 'tag']); while ($metas->fetch()) { $list[] = libEPC::matchString( $metas->meta_id, - sprintf($this->widget, $this->core->blog->url . $this->core->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), + sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->meta_id, '\\1'), $content, $this ); @@ -85,7 +85,7 @@ class epcFilterSearch extends epcFilter 'help' => __('Highlight searched words.'), 'htmltag' => '', 'class' => ['span.epc-search'], - 'replace' => '%s' + 'replace' => '%s', ]); $this->setSettings([ @@ -94,7 +94,7 @@ class epcFilterSearch extends epcFilter 'style' => ['color: #FFCC66;'], 'notag' => 'h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['search.html'] + 'pubPages' => ['search.html'], ]); return 'search'; @@ -102,11 +102,11 @@ class epcFilterSearch extends epcFilter public function publicContent($tag, $args) { - if (!isset($GLOBALS['_search'])) { + if (empty(dcCore::app()->public->search)) { return null; } - $searchs = explode(' ', $GLOBALS['_search']); + $searchs = explode(' ', dcCore::app()->public->search); foreach ($searchs as $k => $v) { $args[0] = libEPC::replaceString( @@ -133,14 +133,14 @@ class epcFilterAcronym extends epcFilter 'htmltag' => 'acronym', 'class' => ['acronym.epc-acronym'], 'replace' => '%s', - 'widget' => '%s' + 'widget' => '%s', ]); $this->setSettings([ 'style' => ['font-weight: bold;'], 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'acronym'; @@ -187,14 +187,14 @@ class epcFilterAbbreviation extends epcFilter 'htmltag' => 'a', 'class' => ['abbr.epc-abbr'], 'replace' => '%s', - 'widget' => '%s' + 'widget' => '%s', ]); $this->setSettings([ 'style' => ['font-weight: bold;'], 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'abbreviation'; @@ -241,14 +241,14 @@ class epcFilterDefinition extends epcFilter 'htmltag' => 'dfn', 'class' => ['dfn.epc-dfn'], 'replace' => '%s', - 'widget' => '%s' + 'widget' => '%s', ]); $this->setSettings([ 'style' => ['font-weight: bold;'], 'notag' => 'a,acronym,abbr,dfn,h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'definition'; @@ -295,7 +295,7 @@ class epcFilterCitation extends epcFilter 'htmltag' => 'cite', 'class' => ['cite.epc-cite'], 'replace' => '%s', - 'widget' => '%s' + 'widget' => '%s', ]); $this->setSettings([ @@ -303,7 +303,7 @@ class epcFilterCitation extends epcFilter 'style' => ['font-style: italic;'], 'notag' => 'a,h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'citation'; @@ -350,14 +350,14 @@ class epcFilterLink extends epcFilter 'htmltag' => 'a', 'class' => ['a.epc-link'], 'replace' => '%s', - 'widget' => '%s' + 'widget' => '%s', ]); $this->setSettings([ 'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'], 'notag' => 'a,h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'link'; @@ -403,7 +403,7 @@ class epcFilterReplace extends epcFilter 'has_list' => true, 'htmltag' => '', 'class' => ['span.epc-replace'], - 'replace' => '%s' + 'replace' => '%s', ]); $this->setSettings([ @@ -412,7 +412,7 @@ class epcFilterReplace extends epcFilter 'style' => ['font-style: italic;'], 'notag' => 'h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'replace'; @@ -444,7 +444,7 @@ class epcFilterUpdate extends epcFilter 'has_list' => true, 'htmltag' => 'del,ins', 'class' => ['del.epc-update', 'ins.epc-update'], - 'replace' => '%s %s' + 'replace' => '%s %s', ]); $this->setSettings([ @@ -453,7 +453,7 @@ class epcFilterUpdate extends epcFilter 'style' => ['text-decoration: line-through;', 'font-style: italic;'], 'notag' => 'h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'update'; @@ -484,14 +484,14 @@ class epcFilterTwitter extends epcFilter 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'), 'htmltag' => 'a', 'class' => ['a.epc-twitter'], - 'replace' => '%s' + 'replace' => '%s', ]); $this->setSettings([ 'style' => ['text-decoration: none; font-weight: bold; font-style: italic; color: #0000FF;'], 'notag' => 'a,h1,h2,h3', 'tplValues' => ['EntryContent'], - 'pubPages' => ['post.html'] + 'pubPages' => ['post.html'], ]); return 'twitter'; diff --git a/inc/lib.epc.pager.php b/inc/lib.epc.pager.php index 707fd33..1abb2db 100644 --- a/inc/lib.epc.pager.php +++ b/inc/lib.epc.pager.php @@ -43,7 +43,7 @@ class adminEpcList extends adminGenericList $cols = [ 'key' => '' . __('Key') . '', 'value' => '' . __('Value') . '', - 'date' => '' . __('Date') . '' + 'date' => '' . __('Date') . '', ]; $html_block = '
', 'key' => '', 'value' => '', - 'date' => '' + 'date' => '', ]; return diff --git a/inc/lib.epc.php b/inc/lib.epc.php index 4782b17..b5ca1ba 100644 --- a/inc/lib.epc.php +++ b/inc/lib.epc.php @@ -11,9 +11,15 @@ * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ # l10n -__('entry excerpt');__('entry content');__('comment content'); -__('home page');__('post page');__('category page');__('search results page'); -__('atom feeds');__('RSS feeds'); +__('entry excerpt'); +__('entry content'); +__('comment content'); +__('home page'); +__('post page'); +__('category page'); +__('search results page'); +__('atom feeds'); +__('RSS feeds'); class libEPC { @@ -26,91 +32,79 @@ class libEPC public static function defaultAllowedTplValues() { - global $core; - $rs = new arrayObject([ 'entry excerpt' => 'EntryExcerpt', 'entry content' => 'EntryContent', 'comment content' => 'CommentContent', ]); - $core->callBehavior('enhancePostContentAllowedTplValues', $rs); + dcCore::app()->callBehavior('enhancePostContentAllowedTplValues', $rs); return iterator_to_array($rs, true); } public static function blogAllowedTplValues() { - global $core; - - $core->blog->settings->addNamespace('enhancePostContent'); - $rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedtplvalues); + dcCore::app()->blog->settings->addNamespace('enhancePostContent'); + $rs = @unserialize(dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_allowedtplvalues); return is_array($rs) ? $rs : self::defaultAllowedTplValues(); } public static function defaultAllowedWidgetValues() { - global $core; - $rs = new arrayObject([ 'entry excerpt' => [ 'id' => 'entryexcerpt', - 'cb' => ['libEPC','widgetContentEntryExcerpt'] + 'cb' => ['libEPC','widgetContentEntryExcerpt'], ], 'entry content' => [ 'id' => 'entrycontent', - 'cb' => ['libEPC','widgetContentEntryContent'] + 'cb' => ['libEPC','widgetContentEntryContent'], ], 'comment content' => [ 'id' => 'commentcontent', - 'cb' => ['libEPC','widgetContentCommentContent'] - ] + 'cb' => ['libEPC','widgetContentCommentContent'], + ], ]); - $core->callBehavior('enhancePostContentAllowedWidgetValues', $rs); + dcCore::app()->callBehavior('enhancePostContentAllowedWidgetValues', $rs); return iterator_to_array($rs, true); } public static function defaultAllowedPubPages() { - global $core; - $rs = new arrayObject([ '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' + 'RSS feeds' => 'rss2.xml', ]); - $core->callBehavior('enhancePostContentAllowedPubPages', $rs); + dcCore::app()->callBehavior('enhancePostContentAllowedPubPages', $rs); return iterator_to_array($rs, true); } public static function blogAllowedPubPages() { - global $core; - - $core->blog->settings->addNamespace('enhancePostContent'); - $rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedpubpages); + dcCore::app()->blog->settings->addNamespace('enhancePostContent'); + $rs = @unserialize(dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_allowedpubpages); return is_array($rs) ? $rs : self::defaultAllowedPubPages(); } public static function getFilters() { - global $core; - if (self::$default_filters === null) { - $final = $sort = []; + $final = $sort = []; $filters = new arrayObject(); try { - $core->callBehavior('enhancePostContentFilters', $filters, $core); + dcCore::app()->callBehavior('enhancePostContentFilters', $filters); foreach ($filters as $filter) { if ($filter instanceof epcFilter && !isset($final[$filter->id()])) { @@ -119,7 +113,7 @@ class libEPC } } } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } array_multisort($sort, $final); self::$default_filters = $final; @@ -131,7 +125,7 @@ class libEPC public static function testContext($tag, $args, $filter) { return is_array($filter->pubPages) - && in_array($GLOBALS['_ctx']->current_tpl, $filter->pubPages) + && in_array(dcCore::app()->ctx->current_tpl, $filter->pubPages) && is_array($filter->tplValues) && in_array($tag, $filter->tplValues) && $args[0] != '' //content @@ -279,17 +273,15 @@ class libEPC # Widgets # - public static function widgetContentEntryExcerpt($core, $w) + public static function widgetContentEntryExcerpt($w) { - global $_ctx; - - if (!$_ctx->exists('posts')) { + if (!dcCore::app()->ctx->exists('posts')) { return null; } $res = ''; - while ($_ctx->posts->fetch()) { - $res .= $_ctx->posts->post_excerpt; + while (dcCore::app()->ctx->posts->fetch()) { + $res .= dcCore::app()->ctx->posts->post_excerpt; } return $res; @@ -297,15 +289,13 @@ class libEPC public static function widgetContentEntryContent() { - global $_ctx; - - if (!$_ctx->exists('posts')) { + if (!dcCore::app()->ctx->exists('posts')) { return null; } $res = ''; - while ($_ctx->posts->fetch()) { - $res .= $_ctx->posts->post_content; + while (dcCore::app()->ctx->posts->fetch()) { + $res .= dcCore::app()->ctx->posts->post_content; } return $res; @@ -313,16 +303,14 @@ class libEPC public static function widgetContentCommentContent() { - global $core, $_ctx; - - if (!$_ctx->exists('posts')) { + if (!dcCore::app()->ctx->exists('posts')) { return null; } $res = ''; $post_ids = []; - while ($_ctx->posts->fetch()) { - $comments = $core->blog->getComments(['post_id' => $_ctx->posts->post_id]); + while (dcCore::app()->ctx->posts->fetch()) { + $comments = dcCore::app()->blog->getComments(['post_id' => dcCore::app()->ctx->posts->post_id]); while ($comments->fetch()) { $res .= $comments->getContent(); } diff --git a/inc/lib.epc.records.php b/inc/lib.epc.records.php index 5c1815f..c69e069 100644 --- a/inc/lib.epc.records.php +++ b/inc/lib.epc.records.php @@ -12,17 +12,15 @@ */ class epcRecords { - public $core; public $con; public $table; public $blog; - public function __construct($core) + public function __construct() { - $this->core = $core; - $this->con = $core->con; - $this->table = $core->prefix . 'epc'; - $this->blog = $core->con->escape($core->blog->id); + $this->con = dcCore::app()->con; + $this->table = dcCore::app()->prefix . 'epc'; + $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); } public function getRecords($params, $count_only = false) @@ -124,7 +122,7 @@ class epcRecords $this->trigger(); # --BEHAVIOR-- enhancePostContentAfterAddRecord - $this->core->callBehavior('enhancePostContentAfterAddRecord', $cur); + dcCore::app()->callBehavior('enhancePostContentAfterAddRecord', $cur); return $cur->epc_id; } @@ -143,7 +141,7 @@ class epcRecords $this->trigger(); # --BEHAVIOR-- enhancePostContentAfterUpdRecord - $this->core->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id); + dcCore::app()->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id); } public function isRecord($filter, $key, $not_id = null) @@ -151,7 +149,7 @@ class epcRecords return 0 < $this->getRecords([ 'epc_filter' => $filter, 'epc_key' => $key, - 'not_id' => $not_id + 'not_id' => $not_id, ], true)->f(0); } @@ -164,7 +162,7 @@ class epcRecords } # --BEHAVIOR-- enhancePostContentBeforeDelRecord - $this->core->callBehavior('enhancePostContentbeforeDelRecord', $id); + dcCore::app()->callBehavior('enhancePostContentbeforeDelRecord', $id); $this->con->execute( 'DELETE FROM ' . $this->table . ' ' . @@ -203,6 +201,6 @@ class epcRecords private function trigger() { - $this->core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); } } diff --git a/inc/lib.epc.update.php b/inc/lib.epc.update.php index 9a2c600..0560071 100644 --- a/inc/lib.epc.update.php +++ b/inc/lib.epc.update.php @@ -10,41 +10,45 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ +if (!isset($old_version)) { + return null; +} + # Move old filters lists from settings to database if ($old_version && version_compare('0.6.6', $old_version, '>=')) { - $f = $core->con->select('SELECT * FROM ' . $core->prefix . "setting WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL "); + $f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->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'); + $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'epc'); + dcCore::app()->con->writeLock(dcCore::app()->prefix . 'epc'); - $cur->epc_id = $core->con->select('SELECT MAX(epc_id) FROM ' . $core->prefix . 'epc' . ' ')->f(0) + 1; + $cur->epc_id = dcCore::app()->con->select('SELECT MAX(epc_id) FROM ' . dcCore::app()->prefix . 'epc' . ' ')->f(0) + 1; $cur->blog_id = $f->blog_id; $cur->epc_filter = strtolower($m[1]); $cur->epc_key = $k; $cur->epc_value = $v; $cur->insert(); - $core->con->unlock(); + dcCore::app()->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 . "' "); + dcCore::app()->con->execute('DELETE FROM ' . dcCore::app()->prefix . "setting WHERE setting_id='" . $f->setting_id . "' AND setting_ns='enhancePostContent' AND blog_id='" . $f->blog_id . "' "); } } - # Move old filter name to filter id +# Move old filter name to filter id } elseif ($old_version && version_compare('2021.10.05', $old_version, '>=')) { - $rs = $core->con->select('SELECT epc_id, epc_filter FROM ' . $core->prefix . 'epc'); + $rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . 'epc'); while ($rs->fetch()) { - $cur = $core->con->openCursor($core->prefix . 'epc'); + $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'epc'); $cur->epc_filter = strtolower($rs->epc_filter); $cur->update('WHERE epc_id = ' . $rs->epc_id . ' '); - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); } } diff --git a/index.php b/index.php index b6d4c43..635c1d4 100644 --- a/index.php +++ b/index.php @@ -35,13 +35,13 @@ if (!isset($filters_id[$part])) { $header = ''; $filter = $_filters[$part]; -$records = new epcRecords($core); +$records = new epcRecords(); # -- Action -- if (!empty($action)) { # --BEHAVIOR-- enhancePostContentAdminSave - $core->callBehavior('enhancePostContentAdminSave', $core); + dcCore::app()->callBehavior('enhancePostContentAdminSave'); } try { @@ -55,19 +55,19 @@ try { 'style' => (array) $_POST['filter_style'], 'notag' => (string) $_POST['filter_notag'], 'tplValues' => (array) $_POST['filter_tplValues'], - 'pubPages' => (array) $_POST['filter_pubPages'] + 'pubPages' => (array) $_POST['filter_pubPages'], ]; - $core->blog->settings->addNamespace('enhancePostContent'); - $core->blog->settings->enhancePostContent->put('enhancePostContent_' . $filter->id(), serialize($f)); + dcCore::app()->blog->settings->addNamespace('enhancePostContent'); + dcCore::app()->blog->settings->enhancePostContent->put('enhancePostContent_' . $filter->id(), serialize($f)); - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); dcPage::addSuccessNotice( __('Filter successfully updated.') ); - $core->adminurl->redirect( + dcCore::app()->adminurl->redirect( 'admin.plugin.enhancePostContent', ['part' => $part], '#settings' @@ -89,13 +89,13 @@ try { } else { $records->addRecord($cur); - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); dcPage::addSuccessNotice( __('Filter successfully updated.') ); } - $core->adminurl->redirect( + dcCore::app()->adminurl->redirect( 'admin.plugin.enhancePostContent', ['part' => $part], '#record' @@ -104,13 +104,13 @@ try { # Update filter records if ($action == 'deleterecords' && $filter->has_list - && !empty($_POST['epc_id']) && is_array($_POST['epc_id']) + && !empty($_POST['epc_id']) && is_array($_POST['epc_id']) ) { foreach ($_POST['epc_id'] as $id) { $records->delRecord($id); } - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); dcPage::addSuccessNotice( __('Filter successfully updated.') @@ -119,7 +119,7 @@ try { if (!empty($_REQUEST['redir'])) { http::redirect($_REQUEST['redir']); } else { - $core->adminurl->redirect( + dcCore::app()->adminurl->redirect( 'admin.plugin.enhancePostContent', ['part' => $part], '#record' @@ -127,13 +127,13 @@ try { } } } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } # -- Prepare page -- if ($filter->has_list) { - $sorts = new adminGenericFilter($core, 'epc'); + $sorts = new adminGenericFilter(dcCore::app(), 'epc'); $sorts->add(dcAdminFilters::getPageFilter()); $sorts->add('part', $part); @@ -143,12 +143,12 @@ if ($filter->has_list) { try { $list = $records->getRecords($params); $counter = $records->getRecords($params, true); - $pager = new adminEpcList($core, $list, $counter->f(0)); + $pager = new adminEpcList(dcCore::app(), $list, $counter->f(0)); } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } - $header = $sorts->js($core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $part], '&') . '#record'); + $header = $sorts->js(dcCore::app()->adminurl->get('admin.plugin.enhancePostContent', ['part' => $part], '&') . '#record'); } # -- Display page -- @@ -161,7 +161,7 @@ dcPage::jsLoad(dcPage::getPF('enhancePostContent/js/index.js')) . $header . # --BEHAVIOR-- enhancePostContentAdminHeader -$core->callBehavior('enhancePostContentAdminHeader', $core) . ' +dcCore::app()->callBehavior('enhancePostContentAdminHeader') . ' ' . @@ -169,12 +169,12 @@ $core->callBehavior('enhancePostContentAdminHeader', $core) . ' dcPage::breadcrumb([ __('Plugins') => '', __('Enhance post content') => '', - $filter->name => '' + $filter->name => '', ]) . dcPage::notices() . # Filters select menu list -'' . +'' . '

' . form::combo('part', $filters_combo, $part) . ' ' . '' . @@ -189,7 +189,7 @@ echo ' # Filter settings echo '

- +

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

'; @@ -265,7 +265,7 @@ form::field('filter_notag', 60, 255, html::escapeHTML($filter->notag)) . '

' . -$core->formNonce() . +dcCore::app()->formNonce() . form::hidden(['action'], 'savefiltersetting') . form::hidden(['part'], $part) . ' @@ -276,8 +276,8 @@ form::hidden(['part'], $part) . '

'; # Filter records list -if ($filter->has_list) { - $pager_url = $core->adminurl->get('admin.plugin.enhancePostContent', array_diff_key($sorts->values(true), ['page' => ''])) . '&page=%s#record'; +if ($filter->has_list && isset($sorts) && isset($pager)) { + $pager_url = dcCore::app()->adminurl->get('admin.plugin.enhancePostContent', array_diff_key($sorts->values(true), ['page' => ''])) . '&page=%s#record'; echo '
'; @@ -287,7 +287,7 @@ if ($filter->has_list) { $pager->display( $sorts, $pager_url, - '' . + '' . '%s' . '
' . @@ -296,9 +296,9 @@ if ($filter->has_list) { '

' . form::hidden('action', 'deleterecords') . '

' . - $core->adminurl->getHiddenFormFields('admin.plugin.enhancePostContent', array_merge(['p' => 'enhancePostContent'], $sorts->values(true))) . - form::hidden('redir', $core->adminurl->get('admin.plugin.enhancePostContent', $sorts->values(true))) . - $core->formNonce() . + dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.enhancePostContent', array_merge(['p' => 'enhancePostContent'], $sorts->values(true))) . + form::hidden('redir', dcCore::app()->adminurl->get('admin.plugin.enhancePostContent', $sorts->values(true))) . + dcCore::app()->formNonce() . '
' . '' ); @@ -308,7 +308,7 @@ if ($filter->has_list) { # New record echo '
-
' . + ' . '

' . form::field('new_key', 60, 255, ['extra_html' => 'required']) . @@ -321,7 +321,7 @@ if ($filter->has_list) {

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

@@ -329,7 +329,7 @@ if ($filter->has_list) { } # --BEHAVIOR-- enhancePostContentAdminPage -$core->callBehavior('enhancePostContentAdminPage', $core); +dcCore::app()->callBehavior('enhancePostContentAdminPage'); dcPage::helpBlock('enhancePostContent');
' . @@ -75,7 +75,7 @@ class adminEpcList extends adminGenericList 'check' => '
' . form::checkbox(['epc_id[]'], $this->rs->epc_id, ['checked' => $checked]) . '' . html::escapeHTML($this->rs->epc_key) . '' . html::escapeHTML($this->rs->epc_value) . '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . '