prepare DC 2.24

This commit is contained in:
Jean-Christian Paul Denis 2022-11-15 11:08:10 +01:00
parent 2a3980165a
commit 5e9afe15e5
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
6 changed files with 78 additions and 86 deletions

View File

@ -14,18 +14,18 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
require dirname(__FILE__) . '/_widgets.php'; require __DIR__ . '/_widgets.php';
# Dashboard item and user preference # Dashboard item and user preference
$core->addBehavior( dcCore::app()->addBehavior(
'adminDashboardItems', 'adminDashboardItemsV2',
['topWriterAdmin', 'adminDashboardItems'] ['topWriterAdmin', 'adminDashboardItems']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminDashboardOptionsForm', 'adminDashboardOptionsFormV2',
['topWriterAdmin', 'adminDashboardOptionsForm'] ['topWriterAdmin', 'adminDashboardOptionsForm']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminAfterDashboardOptionsUpdate', 'adminAfterDashboardOptionsUpdate',
['topWriterAdmin', 'adminAfterDashboardOptionsUpdate'] ['topWriterAdmin', 'adminAfterDashboardOptionsUpdate']
); );
@ -37,13 +37,13 @@ $core->addBehavior(
*/ */
class topWriterAdmin 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 # top posts
if ($pref['topWriterPostsItems']) { if ($pref['topWriterPostsItems']) {
$lines = topWriter::posts($core, $pref['topWriterPostsPeriod'], $pref['topWriterPostsLimit']); $lines = topWriter::posts($pref['topWriterPostsPeriod'], $pref['topWriterPostsLimit']);
if (empty($lines)) { if (empty($lines)) {
return null; return null;
} }
@ -62,7 +62,7 @@ class topWriterAdmin
# top comments # top comments
if ($pref['topWriterCommentsItems']) { if ($pref['topWriterCommentsItems']) {
$lines = topWriter::comments($core, $pref['topWriterCommentsPeriod'], $pref['topWriterCommentsLimit']); $lines = topWriter::comments($pref['topWriterCommentsPeriod'], $pref['topWriterCommentsLimit']);
if (empty($lines)) { if (empty($lines)) {
return null; 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 echo
'<div class="fieldset">' . '<div class="fieldset">' .
@ -110,80 +110,78 @@ class topWriterAdmin
public static function adminAfterDashboardOptionsUpdate($user_id) public static function adminAfterDashboardOptionsUpdate($user_id)
{ {
global $core; dcCore::app()->auth->user_prefs->dashboard->put(
$core->auth->user_prefs->dashboard->put(
'topWriterPostsItems', 'topWriterPostsItems',
!empty($_POST['topWriterPostsItems']), !empty($_POST['topWriterPostsItems']),
'boolean' 'boolean'
); );
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterPostsPeriod', 'topWriterPostsPeriod',
(string) $_POST['topWriterPostsPeriod'], (string) $_POST['topWriterPostsPeriod'],
'string' 'string'
); );
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterPostsLimit', 'topWriterPostsLimit',
(int) $_POST['topWriterPostsLimit'], (int) $_POST['topWriterPostsLimit'],
'integer' 'integer'
); );
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterCommentsItems', 'topWriterCommentsItems',
!empty($_POST['topWriterCommentsItems']), !empty($_POST['topWriterCommentsItems']),
'boolean' 'boolean'
); );
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterCommentsPeriod', 'topWriterCommentsPeriod',
(string) $_POST['topWriterCommentsPeriod'], (string) $_POST['topWriterCommentsPeriod'],
'string' 'string'
); );
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterCommentsLimit', 'topWriterCommentsLimit',
(int) $_POST['topWriterCommentsLimit'], (int) $_POST['topWriterCommentsLimit'],
'integer' 'integer'
); );
} }
private static function setDefaultPref($core) private static function setDefaultPref()
{ {
if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsItems')) { if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsItems')) {
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterPostsItems', 'topWriterPostsItems',
false, false,
'boolean' 'boolean'
); );
} }
if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsPeriod')) { if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsPeriod')) {
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterPostsPeriod', 'topWriterPostsPeriod',
'month', 'month',
'string' 'string'
); );
} }
if (!$core->auth->user_prefs->dashboard->prefExists('topWriterPostsLimit')) { if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsLimit')) {
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterPostsLimit', 'topWriterPostsLimit',
10, 10,
'integer' 'integer'
); );
} }
if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsItems')) { if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsItems')) {
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterCommentsItems', 'topWriterCommentsItems',
false, false,
'boolean' 'boolean'
); );
} }
if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsPeriod')) { if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsPeriod')) {
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterCommentsPeriod', 'topWriterCommentsPeriod',
'month', 'month',
'string' 'string'
); );
} }
if (!$core->auth->user_prefs->dashboard->prefExists('topWriterCommentsLimit')) { if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsLimit')) {
$core->auth->user_prefs->dashboard->put( dcCore::app()->auth->user_prefs->dashboard->put(
'topWriterCommentsLimit', 'topWriterCommentsLimit',
10, 10,
'integer' 'integer'
@ -191,12 +189,12 @@ class topWriterAdmin
} }
return [ return [
'topWriterPostsItems' => $core->auth->user_prefs->dashboard->get('topWriterPostsItems'), 'topWriterPostsItems' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsItems'),
'topWriterPostsPeriod' => $core->auth->user_prefs->dashboard->get('topWriterPostsPeriod'), 'topWriterPostsPeriod' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsPeriod'),
'topWriterPostsLimit' => $core->auth->user_prefs->dashboard->get('topWriterPostsLimit') ?? 10, 'topWriterPostsLimit' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsLimit') ?? 10,
'topWriterCommentsItems' => $core->auth->user_prefs->dashboard->get('topWriterCommentsItems'), 'topWriterCommentsItems' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsItems'),
'topWriterCommentsPeriod' => $core->auth->user_prefs->dashboard->get('topWriterCommentsPeriod'), 'topWriterCommentsPeriod' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsPeriod'),
'topWriterCommentsLimit' => $core->auth->user_prefs->dashboard->get('topWriterCommentsLimit') ?? 10 'topWriterCommentsLimit' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsLimit') ?? 10,
]; ];
} }
} }

View File

@ -18,13 +18,13 @@ $this->registerModule(
'Top writer', 'Top writer',
'Ranking of the most prolific writers and/or commentators', 'Ranking of the most prolific writers and/or commentators',
'Jean-Christian Denis, Pierre Van Glabeke', 'Jean-Christian Denis, Pierre Van Glabeke',
'0.9', '0.10',
[ [
'requires' => [['core', '2.19']], 'requires' => [['core', '2.24']],
'permissions' => 'admin', 'permissions' => dcAuth::PERMISSION_CONTENT_ADMIN,
'type' => 'plugin', 'type' => 'plugin',
'support' => 'http://forum.dotclear.org/viewtopic.php?pid=333002#p333002', 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=333002#p333002',
'details' => 'http://plugins.dotaddict.org/dc2/details/topWriter', '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',
] ]
); );

View File

@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) {
return; return;
} }
$__autoload['topWriter'] = dirname(__FILE__) . '/inc/class.topwriter.php'; Clearbricks::lib()->autoload(['topWriter' => __DIR__ . '/inc/class.topwriter.php']);

View File

@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
require dirname(__FILE__) . '/_widgets.php'; require __DIR__ . '/_widgets.php';

View File

@ -14,7 +14,7 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$core->addBehavior('initWidgets', ['topWriterWidget', 'init']); dcCore::app()->addBehavior('initWidgets', ['topWriterWidget', 'init']);
class topWriterWidget class topWriterWidget
{ {
@ -50,7 +50,7 @@ class topWriterWidget
'combo', 'combo',
[ [
__('Ascending') => 'asc', __('Ascending') => 'asc',
__('Descending') => 'desc' __('Descending') => 'desc',
] ]
) )
->setting( ->setting(
@ -100,7 +100,7 @@ class topWriterWidget
'combo', 'combo',
[ [
__('Ascending') => 'asc', __('Ascending') => 'asc',
__('Descending') => 'desc' __('Descending') => 'desc',
] ]
) )
->setting( ->setting(
@ -117,16 +117,14 @@ class topWriterWidget
public static function topCom($w) public static function topCom($w)
{ {
global $core;
if ($w->offline if ($w->offline
|| ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) || ($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type))
|| ($w->homeonly == 2 && $core->url->isHome($core->url->type)) || ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))
) { ) {
return null; 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)) { if (empty($lines)) {
return null; return null;
} }
@ -142,16 +140,14 @@ class topWriterWidget
public static function topPost($w) public static function topPost($w)
{ {
global $core;
if ($w->offline if ($w->offline
|| ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) || ($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type))
|| ($w->homeonly == 2 && $core->url->isHome($core->url->type)) || ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))
) { ) {
return null; 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)) { if (empty($lines)) {
return null; return null;
} }

View File

@ -16,30 +16,30 @@ if (!defined('DC_RC_PATH')) {
class topWriter 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 ' . $req = 'SELECT COUNT(*) AS count, U.user_id ' .
'FROM ' . $core->prefix . 'post P ' . 'FROM ' . dcCore::app()->prefix . 'post P ' .
'INNER JOIN ' . $core->prefix . 'user U ON U.user_id = P.user_id ' . 'INNER JOIN ' . dcCore::app()->prefix . 'user U ON U.user_id = P.user_id ' .
"WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " . "WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " .
'AND post_status=1 AND user_status=1 ' . 'AND post_status=1 AND user_status=1 ' .
self::period('post_dt', $period) . self::period('post_dt', $period) .
'GROUP BY U.user_id ' . 'GROUP BY U.user_id ' .
'ORDER BY count ' . ($sort_desc ? 'DESC' : 'ASC') . ' , U.user_id ASC ' . '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()) { if ($rs->isEmpty()) {
return null; return null;
} }
$core->blog->settings->addNamespace('authormode'); dcCore::app()->blog->settings->addNamespace('authormode');
$res = []; $res = [];
$i = 0; $i = 0;
while ($rs->fetch()) { while ($rs->fetch()) {
$user = $core->con->select( $user = dcCore::app()->con->select(
'SELECT * FROM ' . $core->prefix . "user WHERE user_id='" . $rs->user_id . "' " 'SELECT * FROM ' . dcCore::app()->prefix . "user WHERE user_id='" . $rs->user_id . "' "
); );
if ($user->isEmpty()) { if ($user->isEmpty()) {
continue; continue;
@ -56,9 +56,9 @@ class topWriter
} }
$i++; $i++;
if ($core->blog->settings->authormode->authormode_active) { if (dcCore::app()->blog->settings->authormode->authormode_active) {
$res[$i]['author_link'] = '<a href="' . $res[$i]['author_link'] = '<a href="' .
$core->blog->url . $core->url->getBase('author') . '/' . $user->user_id . '" ' . dcCore::app()->blog->url . dcCore::app()->url->getBase('author') . '/' . $user->user_id . '" ' .
'title="' . __('Author posts') . '">' . $author . '</a>'; 'title="' . __('Author posts') . '">' . $author . '</a>';
} elseif ($user->user_url) { } elseif ($user->user_url) {
$res[$i]['author_link'] = '<a href="' . $user->user_url . '" title="' . $res[$i]['author_link'] = '<a href="' . $user->user_url . '" title="' .
@ -80,29 +80,29 @@ class topWriter
return $res; return $res;
} }
public static function comments(dcCore $core, string $period, int $limit, bool $sort_desc = true, $exclude = false) public static function comments(string $period, int $limit, bool $sort_desc = true, $exclude = false)
{ {
$req = 'SELECT COUNT(*) AS count, comment_email ' . $req = 'SELECT COUNT(*) AS count, comment_email ' .
'FROM ' . $core->prefix . 'post P, ' . $core->prefix . 'comment C ' . 'FROM ' . dcCore::app()->prefix . 'post P, ' . dcCore::app()->prefix . 'comment C ' .
'WHERE P.post_id=C.post_id ' . 'WHERE P.post_id=C.post_id ' .
"AND blog_id='" . $core->con->escape($core->blog->id) . "' " . "AND blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " .
'AND post_status=1 AND comment_status=1 ' . 'AND post_status=1 AND comment_status=1 ' .
self::period('comment_dt', $period); self::period('comment_dt', $period);
if ($exclude) { if ($exclude) {
$req .= 'AND comment_email NOT IN (' . $req .= 'AND comment_email NOT IN (' .
' SELECT U.user_email ' . ' SELECT U.user_email ' .
' FROM ' . $core->prefix . 'user U' . ' FROM ' . dcCore::app()->prefix . 'user U' .
' INNER JOIN ' . $core->prefix . 'post P ON P.user_id = U.user_id ' . ' INNER JOIN ' . dcCore::app()->prefix . 'post P ON P.user_id = U.user_id ' .
" WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " . " WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " .
' GROUP BY U.user_email) '; ' GROUP BY U.user_email) ';
} }
$req .= 'GROUP BY comment_email ' . $req .= 'GROUP BY comment_email ' .
'ORDER BY count ' . ($sort_desc ? 'DESC' : 'ASC') . ' ' . '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()) { if ($rs->isEmpty()) {
return null; return null;
} }
@ -110,8 +110,8 @@ class topWriter
$res = []; $res = [];
$i = 0; $i = 0;
while ($rs->fetch()) { while ($rs->fetch()) {
$user = $core->con->select( $user = dcCore::app()->con->select(
'SELECT * FROM ' . $core->prefix . 'comment ' . 'SELECT * FROM ' . dcCore::app()->prefix . 'comment ' .
"WHERE comment_email='" . $rs->comment_email . "' " . "WHERE comment_email='" . $rs->comment_email . "' " .
'ORDER BY comment_dt DESC' 'ORDER BY comment_dt DESC'
); );
@ -150,27 +150,25 @@ class topWriter
case 'day': case 'day':
$time = 3600 * 24; $time = 3600 * 24;
break; break;
case 'week': case 'week':
$time = 3600 * 24 * 7; $time = 3600 * 24 * 7;
break; break;
case 'month': case 'month':
$time = 3600 * 24 * 30; $time = 3600 * 24 * 30;
break; break;
case 'year': case 'year':
$time = 3600 * 24 * 30 * 12; $time = 3600 * 24 * 30 * 12;
break; break;
default: default:
return ''; return '';
break;
} }
return "AND $field > TIMESTAMP '" . dt::str($pattern, time() - $time) . "' "; return "AND $field > TIMESTAMP '" . dt::str($pattern, time() - $time) . "' ";
@ -183,7 +181,7 @@ class topWriter
__('last week') => 'week', __('last week') => 'week',
__('last month') => 'month', __('last month') => 'month',
__('last year') => 'year', __('last year') => 'year',
__('from begining') => '' __('from begining') => '',
]; ];
} }
} }