prepare DC 2.24
parent
2a3980165a
commit
5e9afe15e5
76
_admin.php
76
_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
|
||||
'<div class="fieldset">' .
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
]
|
||||
);
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -14,4 +14,4 @@ if (!defined('DC_RC_PATH')) {
|
|||
return null;
|
||||
}
|
||||
|
||||
require dirname(__FILE__) . '/_widgets.php';
|
||||
require __DIR__ . '/_widgets.php';
|
||||
|
|
22
_widgets.php
22
_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;
|
||||
}
|
||||
|
|
|
@ -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'] = '<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>';
|
||||
} elseif ($user->user_url) {
|
||||
$res[$i]['author_link'] = '<a href="' . $user->user_url . '" title="' .
|
||||
|
@ -80,29 +80,29 @@ class topWriter
|
|||
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 ' .
|
||||
'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 ' .
|
||||
"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 ' .
|
||||
self::period('comment_dt', $period);
|
||||
|
||||
if ($exclude) {
|
||||
$req .= 'AND comment_email NOT IN (' .
|
||||
' SELECT U.user_email ' .
|
||||
' FROM ' . $core->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'
|
||||
);
|
||||
|
@ -169,8 +169,6 @@ class topWriter
|
|||
|
||||
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') => '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue