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') . '%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 = '' . form::checkbox(['epc_id[]'], $this->rs->epc_id, ['checked' => $checked]) . ' ',
'key' => '' . html::escapeHTML($this->rs->epc_key) . ' ',
'value' => '' . html::escapeHTML($this->rs->epc_value) . ' ',
- 'date' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . ' '
+ 'date' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . ' ',
];
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
-'