From 5e9afe15e551276a6c2c7f7df69d5c6ec1a2a02b Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 15 Nov 2022 11:08:10 +0100 Subject: [PATCH] prepare DC 2.24 --- _admin.php | 76 ++++++++++++++++++++--------------------- _define.php | 8 ++--- _prepend.php | 2 +- _public.php | 2 +- _widgets.php | 22 +++++------- inc/class.topwriter.php | 54 ++++++++++++++--------------- 6 files changed, 78 insertions(+), 86 deletions(-) diff --git a/_admin.php b/_admin.php index 5a9ccda..4ecb208 100644 --- a/_admin.php +++ b/_admin.php @@ -14,18 +14,18 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -require dirname(__FILE__) . '/_widgets.php'; +require __DIR__ . '/_widgets.php'; # Dashboard item and user preference -$core->addBehavior( - 'adminDashboardItems', +dcCore::app()->addBehavior( + 'adminDashboardItemsV2', ['topWriterAdmin', 'adminDashboardItems'] ); -$core->addBehavior( - 'adminDashboardOptionsForm', +dcCore::app()->addBehavior( + 'adminDashboardOptionsFormV2', ['topWriterAdmin', 'adminDashboardOptionsForm'] ); -$core->addBehavior( +dcCore::app()->addBehavior( 'adminAfterDashboardOptionsUpdate', ['topWriterAdmin', 'adminAfterDashboardOptionsUpdate'] ); @@ -37,13 +37,13 @@ $core->addBehavior( */ class topWriterAdmin { - public static function adminDashboardItems(dcCore $core, $__dashboard_items) + public static function adminDashboardItems($__dashboard_items) { - $pref = self::setDefaultPref($core); + $pref = self::setDefaultPref(); # top posts if ($pref['topWriterPostsItems']) { - $lines = topWriter::posts($core, $pref['topWriterPostsPeriod'], $pref['topWriterPostsLimit']); + $lines = topWriter::posts($pref['topWriterPostsPeriod'], $pref['topWriterPostsLimit']); if (empty($lines)) { return null; } @@ -62,7 +62,7 @@ class topWriterAdmin # top comments if ($pref['topWriterCommentsItems']) { - $lines = topWriter::comments($core, $pref['topWriterCommentsPeriod'], $pref['topWriterCommentsLimit']); + $lines = topWriter::comments($pref['topWriterCommentsPeriod'], $pref['topWriterCommentsLimit']); if (empty($lines)) { return null; } @@ -80,9 +80,9 @@ class topWriterAdmin } } - public static function adminDashboardOptionsForm(dcCore $core) + public static function adminDashboardOptionsForm() { - $pref = self::setDefaultPref($core); + $pref = self::setDefaultPref(); echo '
' . @@ -110,80 +110,78 @@ class topWriterAdmin public static function adminAfterDashboardOptionsUpdate($user_id) { - global $core; - - $core->auth->user_prefs->dashboard->put( + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsItems', !empty($_POST['topWriterPostsItems']), 'boolean' ); - $core->auth->user_prefs->dashboard->put( + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsPeriod', (string) $_POST['topWriterPostsPeriod'], 'string' ); - $core->auth->user_prefs->dashboard->put( + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsLimit', (int) $_POST['topWriterPostsLimit'], 'integer' ); - $core->auth->user_prefs->dashboard->put( + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsItems', !empty($_POST['topWriterCommentsItems']), 'boolean' ); - $core->auth->user_prefs->dashboard->put( + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsPeriod', (string) $_POST['topWriterCommentsPeriod'], 'string' ); - $core->auth->user_prefs->dashboard->put( + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsLimit', (int) $_POST['topWriterCommentsLimit'], 'integer' ); } - private static function setDefaultPref($core) + private static function setDefaultPref() { - if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsItems')) { - $core->auth->user_prefs->dashboard->put( + if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsItems')) { + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsItems', false, 'boolean' ); } - if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsPeriod')) { - $core->auth->user_prefs->dashboard->put( + if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsPeriod')) { + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsPeriod', 'month', 'string' ); } - if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsLimit')) { - $core->auth->user_prefs->dashboard->put( + if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsLimit')) { + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterPostsLimit', 10, 'integer' ); } - if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsItems')) { - $core->auth->user_prefs->dashboard->put( + if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsItems')) { + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsItems', false, 'boolean' ); } - if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsPeriod')) { - $core->auth->user_prefs->dashboard->put( + if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsPeriod')) { + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsPeriod', 'month', 'string' ); } - if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsLimit')) { - $core->auth->user_prefs->dashboard->put( + if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsLimit')) { + dcCore::app()->auth->user_prefs->dashboard->put( 'topWriterCommentsLimit', 10, 'integer' @@ -191,12 +189,12 @@ class topWriterAdmin } return [ - 'topWriterPostsItems' => $core->auth->user_prefs->dashboard->get('topWriterPostsItems'), - 'topWriterPostsPeriod' => $core->auth->user_prefs->dashboard->get('topWriterPostsPeriod'), - 'topWriterPostsLimit' => $core->auth->user_prefs->dashboard->get('topWriterPostsLimit') ?? 10, - 'topWriterCommentsItems' => $core->auth->user_prefs->dashboard->get('topWriterCommentsItems'), - 'topWriterCommentsPeriod' => $core->auth->user_prefs->dashboard->get('topWriterCommentsPeriod'), - 'topWriterCommentsLimit' => $core->auth->user_prefs->dashboard->get('topWriterCommentsLimit') ?? 10 + 'topWriterPostsItems' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsItems'), + 'topWriterPostsPeriod' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsPeriod'), + 'topWriterPostsLimit' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsLimit') ?? 10, + 'topWriterCommentsItems' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsItems'), + 'topWriterCommentsPeriod' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsPeriod'), + 'topWriterCommentsLimit' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsLimit') ?? 10, ]; } } diff --git a/_define.php b/_define.php index 1d09873..bcd8e2c 100644 --- a/_define.php +++ b/_define.php @@ -18,13 +18,13 @@ $this->registerModule( 'Top writer', 'Ranking of the most prolific writers and/or commentators', 'Jean-Christian Denis, Pierre Van Glabeke', - '0.9', + '0.10', [ - 'requires' => [['core', '2.19']], - 'permissions' => 'admin', + 'requires' => [['core', '2.24']], + 'permissions' => dcAuth::PERMISSION_CONTENT_ADMIN, 'type' => 'plugin', 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=333002#p333002', 'details' => 'http://plugins.dotaddict.org/dc2/details/topWriter', - 'repository' => 'https://raw.githubusercontent.com/JcDenis/topWriter/master/dcstore.xml' + 'repository' => 'https://raw.githubusercontent.com/JcDenis/topWriter/master/dcstore.xml', ] ); diff --git a/_prepend.php b/_prepend.php index 384aa68..920c4e2 100644 --- a/_prepend.php +++ b/_prepend.php @@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) { return; } -$__autoload['topWriter'] = dirname(__FILE__) . '/inc/class.topwriter.php'; +Clearbricks::lib()->autoload(['topWriter' => __DIR__ . '/inc/class.topwriter.php']); diff --git a/_public.php b/_public.php index 63fa027..8ff9c3d 100644 --- a/_public.php +++ b/_public.php @@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) { return null; } -require dirname(__FILE__) . '/_widgets.php'; +require __DIR__ . '/_widgets.php'; diff --git a/_widgets.php b/_widgets.php index e00554e..2378d60 100644 --- a/_widgets.php +++ b/_widgets.php @@ -14,7 +14,7 @@ if (!defined('DC_RC_PATH')) { return null; } -$core->addBehavior('initWidgets', ['topWriterWidget', 'init']); +dcCore::app()->addBehavior('initWidgets', ['topWriterWidget', 'init']); class topWriterWidget { @@ -50,7 +50,7 @@ class topWriterWidget 'combo', [ __('Ascending') => 'asc', - __('Descending') => 'desc' + __('Descending') => 'desc', ] ) ->setting( @@ -100,7 +100,7 @@ class topWriterWidget 'combo', [ __('Ascending') => 'asc', - __('Descending') => 'desc' + __('Descending') => 'desc', ] ) ->setting( @@ -117,16 +117,14 @@ class topWriterWidget public static function topCom($w) { - global $core; - if ($w->offline - || ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) - || ($w->homeonly == 2 && $core->url->isHome($core->url->type)) + || ($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type)) + || ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type)) ) { return null; } - $lines = topWriter::comments($core, $w->period, $w->limit, $w->sort == 'desc', $w->exclude); + $lines = topWriter::comments($w->period, $w->limit, $w->sort == 'desc', $w->exclude); if (empty($lines)) { return null; } @@ -142,16 +140,14 @@ class topWriterWidget public static function topPost($w) { - global $core; - if ($w->offline - || ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) - || ($w->homeonly == 2 && $core->url->isHome($core->url->type)) + || ($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type)) + || ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type)) ) { return null; } - $lines = topWriter::posts($core, $w->period, $w->limit, $w->sort == 'desc'); + $lines = topWriter::posts($w->period, $w->limit, $w->sort == 'desc'); if (empty($lines)) { return null; } diff --git a/inc/class.topwriter.php b/inc/class.topwriter.php index 1e8d676..f21e80b 100644 --- a/inc/class.topwriter.php +++ b/inc/class.topwriter.php @@ -16,30 +16,30 @@ if (!defined('DC_RC_PATH')) { class topWriter { - public static function posts(dcCore $core, string $period, int $limit, bool $sort_desc = true) + public static function posts(string $period, int $limit, bool $sort_desc = true) { $req = 'SELECT COUNT(*) AS count, U.user_id ' . - 'FROM ' . $core->prefix . 'post P ' . - 'INNER JOIN ' . $core->prefix . 'user U ON U.user_id = P.user_id ' . - "WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " . + 'FROM ' . dcCore::app()->prefix . 'post P ' . + 'INNER JOIN ' . dcCore::app()->prefix . 'user U ON U.user_id = P.user_id ' . + "WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " . 'AND post_status=1 AND user_status=1 ' . self::period('post_dt', $period) . 'GROUP BY U.user_id ' . 'ORDER BY count ' . ($sort_desc ? 'DESC' : 'ASC') . ' , U.user_id ASC ' . - $core->con->limit(abs((int) $limit)); + dcCore::app()->con->limit(abs((int) $limit)); - $rs = $core->con->select($req); + $rs = dcCore::app()->con->select($req); if ($rs->isEmpty()) { return null; } - $core->blog->settings->addNamespace('authormode'); + dcCore::app()->blog->settings->addNamespace('authormode'); $res = []; $i = 0; while ($rs->fetch()) { - $user = $core->con->select( - 'SELECT * FROM ' . $core->prefix . "user WHERE user_id='" . $rs->user_id . "' " + $user = dcCore::app()->con->select( + 'SELECT * FROM ' . dcCore::app()->prefix . "user WHERE user_id='" . $rs->user_id . "' " ); if ($user->isEmpty()) { continue; @@ -56,9 +56,9 @@ class topWriter } $i++; - if ($core->blog->settings->authormode->authormode_active) { + if (dcCore::app()->blog->settings->authormode->authormode_active) { $res[$i]['author_link'] = 'blog->url . dcCore::app()->url->getBase('author') . '/' . $user->user_id . '" ' . 'title="' . __('Author posts') . '">' . $author . ''; } elseif ($user->user_url) { $res[$i]['author_link'] = 'prefix . 'user U' . - ' INNER JOIN ' . $core->prefix . 'post P ON P.user_id = U.user_id ' . - " WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " . + ' FROM ' . dcCore::app()->prefix . 'user U' . + ' INNER JOIN ' . dcCore::app()->prefix . 'post P ON P.user_id = U.user_id ' . + " WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " . ' GROUP BY U.user_email) '; } $req .= 'GROUP BY comment_email ' . 'ORDER BY count ' . ($sort_desc ? 'DESC' : 'ASC') . ' ' . - $core->con->limit(abs((int) $limit)); + dcCore::app()->con->limit(abs((int) $limit)); - $rs = $core->con->select($req); + $rs = dcCore::app()->con->select($req); if ($rs->isEmpty()) { return null; } @@ -110,8 +110,8 @@ class topWriter $res = []; $i = 0; while ($rs->fetch()) { - $user = $core->con->select( - 'SELECT * FROM ' . $core->prefix . 'comment ' . + $user = dcCore::app()->con->select( + 'SELECT * FROM ' . dcCore::app()->prefix . 'comment ' . "WHERE comment_email='" . $rs->comment_email . "' " . 'ORDER BY comment_dt DESC' ); @@ -150,27 +150,25 @@ class topWriter case 'day': $time = 3600 * 24; - break; + break; case 'week': $time = 3600 * 24 * 7; - break; + break; case 'month': $time = 3600 * 24 * 30; - break; + break; case 'year': $time = 3600 * 24 * 30 * 12; - break; + break; default: return ''; - - break; } return "AND $field > TIMESTAMP '" . dt::str($pattern, time() - $time) . "' "; @@ -183,7 +181,7 @@ class topWriter __('last week') => 'week', __('last month') => 'month', __('last year') => 'year', - __('from begining') => '' + __('from begining') => '', ]; } }