use namespace
This commit is contained in:
parent
bad619c16f
commit
4df184ca2f
17
_prepend.php
17
_prepend.php
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief topWriter, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis, Pierre Van Glabeke
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Clearbricks::lib()->autoload(['topWriter' => __DIR__ . '/inc/class.topwriter.php']);
|
|
17
_public.php
17
_public.php
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @brief topWriter, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis, Pierre Van Glabeke
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
require __DIR__ . '/_widgets.php';
|
|
44
src/Backend.php
Normal file
44
src/Backend.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief topWriter, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis, Pierre Van Glabeke
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Dotclear\Plugin\topWriter;
|
||||||
|
|
||||||
|
use dcCore;
|
||||||
|
use dcNsProcess;
|
||||||
|
|
||||||
|
class Backend extends dcNsProcess
|
||||||
|
{
|
||||||
|
public static function init(): bool
|
||||||
|
{
|
||||||
|
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||||
|
|
||||||
|
return static::$init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function process(): bool
|
||||||
|
{
|
||||||
|
if (!static::$init) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcCore::app()->addBehaviors([
|
||||||
|
'adminDashboardItemsV2' => [BackendBehaviors::class, 'adminDashboardItemsV2'],
|
||||||
|
'adminDashboardOptionsFormV2' => [BackendBehaviors::class, 'adminDashboardOptionsFormV2'],
|
||||||
|
'adminAfterDashboardOptionsUpdate' => [BackendBehaviors::class, 'adminAfterDashboardOptionsUpdate'],
|
||||||
|
'initWidgets' => [Widgets::class, 'initWidgets'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -10,77 +10,62 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
require __DIR__ . '/_widgets.php';
|
namespace Dotclear\Plugin\topWriter;
|
||||||
|
|
||||||
# Dashboard item and user preference
|
use ArrayObject;
|
||||||
dcCore::app()->addBehavior(
|
use dcCore;
|
||||||
'adminDashboardItemsV2',
|
use form;
|
||||||
['topWriterAdmin', 'adminDashboardItemsV2']
|
use html;
|
||||||
);
|
|
||||||
dcCore::app()->addBehavior(
|
|
||||||
'adminDashboardOptionsFormV2',
|
|
||||||
['topWriterAdmin', 'adminDashboardOptionsFormV2']
|
|
||||||
);
|
|
||||||
dcCore::app()->addBehavior(
|
|
||||||
'adminAfterDashboardOptionsUpdate',
|
|
||||||
['topWriterAdmin', 'adminAfterDashboardOptionsUpdate']
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_TOPWRITER
|
* @ingroup DC_PLUGIN_TOPWRITER
|
||||||
* @brief Display most active users - admin methods.
|
* @brief Display most active users - admin methods.
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
class topWriterAdmin
|
class BackendBehaviors
|
||||||
{
|
{
|
||||||
public static function adminDashboardItemsV2($__dashboard_items)
|
public static function adminDashboardItemsV2(ArrayObject $__dashboard_items): void
|
||||||
{
|
{
|
||||||
$pref = self::setDefaultPref();
|
$pref = self::setDefaultPref();
|
||||||
|
|
||||||
# top posts
|
# top posts
|
||||||
if ($pref['topWriterPostsItems']) {
|
if ($pref['topWriterPostsItems']) {
|
||||||
$lines = topWriter::posts($pref['topWriterPostsPeriod'], $pref['topWriterPostsLimit']);
|
$lines = Utils::posts($pref['topWriterPostsPeriod'], $pref['topWriterPostsLimit']);
|
||||||
if (empty($lines)) {
|
if (!empty($lines)) {
|
||||||
return null;
|
$li = [];
|
||||||
}
|
foreach ($lines as $k => $line) {
|
||||||
|
$li[] = sprintf('<li><strong>%s</strong> %s (%s)</li>', $k, $line['author'], $line['count']);
|
||||||
|
}
|
||||||
|
|
||||||
$li = [];
|
# Display
|
||||||
foreach ($lines as $k => $line) {
|
$__dashboard_items[0][] = '<div class="box small" id="topWriterPostsItems">' .
|
||||||
$li[] = sprintf('<li><strong>%s</strong> %s (%s)</li>', $k, $line['author'], $line['count']);
|
'<h3>' . html::escapeHTML(__('Top writer: entries')) . '</h3>' .
|
||||||
|
'<ul>' . implode('', $li) . '</ul>' .
|
||||||
|
'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
# Display
|
|
||||||
$__dashboard_items[0][] = '<div class="box small" id="topWriterPostsItems">' .
|
|
||||||
'<h3>' . html::escapeHTML(__('Top writer: entries')) . '</h3>' .
|
|
||||||
'<ul>' . implode('', $li) . '</ul>' .
|
|
||||||
'</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# top comments
|
# top comments
|
||||||
if ($pref['topWriterCommentsItems']) {
|
if ($pref['topWriterCommentsItems']) {
|
||||||
$lines = topWriter::comments($pref['topWriterCommentsPeriod'], $pref['topWriterCommentsLimit']);
|
$lines = Utils::comments($pref['topWriterCommentsPeriod'], $pref['topWriterCommentsLimit']);
|
||||||
if (empty($lines)) {
|
if (!empty($lines)) {
|
||||||
return null;
|
$li = [];
|
||||||
}
|
foreach ($lines as $k => $line) {
|
||||||
|
$li[] = sprintf('<li><strong>%s</strong> %s (%s)</li>', $k, $line['author'], $line['count']);
|
||||||
|
}
|
||||||
|
|
||||||
$li = [];
|
# Display
|
||||||
foreach ($lines as $k => $line) {
|
$__dashboard_items[0][] = '<div class="box small" id="topWriterCommentsItems">' .
|
||||||
$li[] = sprintf('<li><strong>%s</strong> %s (%s)</li>', $k, $line['author'], $line['count']);
|
'<h3>' . html::escapeHTML(__('Top writer: comments')) . '</h3>' .
|
||||||
|
'<ul>' . implode('', $li) . '</ul>' .
|
||||||
|
'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
# Display
|
|
||||||
$__dashboard_items[0][] = '<div class="box small" id="topWriterCommentsItems">' .
|
|
||||||
'<h3>' . html::escapeHTML(__('Top writer: comments')) . '</h3>' .
|
|
||||||
'<ul>' . implode('', $li) . '</ul>' .
|
|
||||||
'</div>';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function adminDashboardOptionsFormV2()
|
public static function adminDashboardOptionsFormV2(): void
|
||||||
{
|
{
|
||||||
$pref = self::setDefaultPref();
|
$pref = self::setDefaultPref();
|
||||||
|
|
||||||
@ -91,7 +76,7 @@ class topWriterAdmin
|
|||||||
form::checkbox('topWriterPostsItems', 1, $pref['topWriterPostsItems']) . ' ' .
|
form::checkbox('topWriterPostsItems', 1, $pref['topWriterPostsItems']) . ' ' .
|
||||||
__('Show') . '</label></p>' .
|
__('Show') . '</label></p>' .
|
||||||
'<p><label class="classic" for="topWriterPostsPeriod">' . __('Period:') . ' </label>' .
|
'<p><label class="classic" for="topWriterPostsPeriod">' . __('Period:') . ' </label>' .
|
||||||
form::combo('topWriterPostsPeriod', topWriter::periods(), $pref['topWriterPostsPeriod']) . '</p>' .
|
form::combo('topWriterPostsPeriod', Utils::periods(), $pref['topWriterPostsPeriod']) . '</p>' .
|
||||||
'<p><label class="classic" for="topWriterPostsLimit">' . __('Limit:') . ' </label>' .
|
'<p><label class="classic" for="topWriterPostsLimit">' . __('Limit:') . ' </label>' .
|
||||||
form::number('topWriterPostsLimit', ['min' => 1, 'max' => 20, 'default' => $pref['topWriterPostsLimit']]) . '</p>' .
|
form::number('topWriterPostsLimit', ['min' => 1, 'max' => 20, 'default' => $pref['topWriterPostsLimit']]) . '</p>' .
|
||||||
'</div>' .
|
'</div>' .
|
||||||
@ -102,86 +87,86 @@ class topWriterAdmin
|
|||||||
form::checkbox('topWriterCommentsItems', 1, $pref['topWriterCommentsItems']) . ' ' .
|
form::checkbox('topWriterCommentsItems', 1, $pref['topWriterCommentsItems']) . ' ' .
|
||||||
__('Show') . '</label></p>' .
|
__('Show') . '</label></p>' .
|
||||||
'<p><label class="classic" for="topWriterCommentsPeriod">' . __('Period:') . ' </label>' .
|
'<p><label class="classic" for="topWriterCommentsPeriod">' . __('Period:') . ' </label>' .
|
||||||
form::combo('topWriterCommentsPeriod', topWriter::periods(), $pref['topWriterCommentsPeriod']) . '</p>' .
|
form::combo('topWriterCommentsPeriod', Utils::periods(), $pref['topWriterCommentsPeriod']) . '</p>' .
|
||||||
'<p><label class="classic" for="topWriterCommentsLimit">' . __('Limit:') . ' </label>' .
|
'<p><label class="classic" for="topWriterCommentsLimit">' . __('Limit:') . ' </label>' .
|
||||||
form::number('topWriterCommentsLimit', ['min' => 1, 'max' => 20, 'default' => $pref['topWriterCommentsLimit']]) . '</p>' .
|
form::number('topWriterCommentsLimit', ['min' => 1, 'max' => 20, 'default' => $pref['topWriterCommentsLimit']]) . '</p>' .
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function adminAfterDashboardOptionsUpdate($user_id)
|
public static function adminAfterDashboardOptionsUpdate(?string $user_id): void
|
||||||
{
|
{
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterPostsItems',
|
'topWriterPostsItems',
|
||||||
!empty($_POST['topWriterPostsItems']),
|
!empty($_POST['topWriterPostsItems']),
|
||||||
'boolean'
|
'boolean'
|
||||||
);
|
);
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterPostsPeriod',
|
'topWriterPostsPeriod',
|
||||||
(string) $_POST['topWriterPostsPeriod'],
|
(string) $_POST['topWriterPostsPeriod'],
|
||||||
'string'
|
'string'
|
||||||
);
|
);
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterPostsLimit',
|
'topWriterPostsLimit',
|
||||||
(int) $_POST['topWriterPostsLimit'],
|
(int) $_POST['topWriterPostsLimit'],
|
||||||
'integer'
|
'integer'
|
||||||
);
|
);
|
||||||
|
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterCommentsItems',
|
'topWriterCommentsItems',
|
||||||
!empty($_POST['topWriterCommentsItems']),
|
!empty($_POST['topWriterCommentsItems']),
|
||||||
'boolean'
|
'boolean'
|
||||||
);
|
);
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterCommentsPeriod',
|
'topWriterCommentsPeriod',
|
||||||
(string) $_POST['topWriterCommentsPeriod'],
|
(string) $_POST['topWriterCommentsPeriod'],
|
||||||
'string'
|
'string'
|
||||||
);
|
);
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterCommentsLimit',
|
'topWriterCommentsLimit',
|
||||||
(int) $_POST['topWriterCommentsLimit'],
|
(int) $_POST['topWriterCommentsLimit'],
|
||||||
'integer'
|
'integer'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function setDefaultPref()
|
private static function setDefaultPref(): array
|
||||||
{
|
{
|
||||||
if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsItems')) {
|
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterPostsItems')) {
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterPostsItems',
|
'topWriterPostsItems',
|
||||||
false,
|
false,
|
||||||
'boolean'
|
'boolean'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsPeriod')) {
|
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterPostsPeriod')) {
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterPostsPeriod',
|
'topWriterPostsPeriod',
|
||||||
'month',
|
'month',
|
||||||
'string'
|
'string'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterPostsLimit')) {
|
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterPostsLimit')) {
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterPostsLimit',
|
'topWriterPostsLimit',
|
||||||
10,
|
10,
|
||||||
'integer'
|
'integer'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsItems')) {
|
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterCommentsItems')) {
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterCommentsItems',
|
'topWriterCommentsItems',
|
||||||
false,
|
false,
|
||||||
'boolean'
|
'boolean'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsPeriod')) {
|
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterCommentsPeriod')) {
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterCommentsPeriod',
|
'topWriterCommentsPeriod',
|
||||||
'month',
|
'month',
|
||||||
'string'
|
'string'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!dcCore::app()->auth->user_prefs->dashboard->prefExists('topWriterCommentsLimit')) {
|
if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterCommentsLimit')) {
|
||||||
dcCore::app()->auth->user_prefs->dashboard->put(
|
dcCore::app()->auth->user_prefs->get('dashboard')->put(
|
||||||
'topWriterCommentsLimit',
|
'topWriterCommentsLimit',
|
||||||
10,
|
10,
|
||||||
'integer'
|
'integer'
|
||||||
@ -189,12 +174,12 @@ class topWriterAdmin
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'topWriterPostsItems' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsItems'),
|
'topWriterPostsItems' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterPostsItems'),
|
||||||
'topWriterPostsPeriod' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsPeriod'),
|
'topWriterPostsPeriod' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterPostsPeriod'),
|
||||||
'topWriterPostsLimit' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterPostsLimit') ?? 10,
|
'topWriterPostsLimit' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterPostsLimit') ?? 10,
|
||||||
'topWriterCommentsItems' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsItems'),
|
'topWriterCommentsItems' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterCommentsItems'),
|
||||||
'topWriterCommentsPeriod' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsPeriod'),
|
'topWriterCommentsPeriod' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterCommentsPeriod'),
|
||||||
'topWriterCommentsLimit' => dcCore::app()->auth->user_prefs->dashboard->get('topWriterCommentsLimit') ?? 10,
|
'topWriterCommentsLimit' => dcCore::app()->auth->user_prefs->get('dashboard')->get('topWriterCommentsLimit') ?? 10,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
src/Frontend.php
Normal file
41
src/Frontend.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief topWriter, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis, Pierre Van Glabeke
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Dotclear\Plugin\topWriter;
|
||||||
|
|
||||||
|
use dcCore;
|
||||||
|
use dcNsProcess;
|
||||||
|
|
||||||
|
class Frontend extends dcNsProcess
|
||||||
|
{
|
||||||
|
public static function init(): bool
|
||||||
|
{
|
||||||
|
static::$init = true;
|
||||||
|
|
||||||
|
return static::$init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function process(): bool
|
||||||
|
{
|
||||||
|
if (!static::$init) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcCore::app()->addBehaviors([
|
||||||
|
'initWidgets' => [Widgets::class, 'initWidgets'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -10,17 +10,23 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
class topWriter
|
namespace Dotclear\Plugin\topWriter;
|
||||||
|
|
||||||
|
use dcAuth;
|
||||||
|
use dcBlog;
|
||||||
|
use dcCore;
|
||||||
|
use dcUtils;
|
||||||
|
use dt;
|
||||||
|
|
||||||
|
class Utils
|
||||||
{
|
{
|
||||||
public static function posts(string $period, int $limit, bool $sort_desc = true)
|
public static function posts(string $period, int $limit, bool $sort_desc = true): array
|
||||||
{
|
{
|
||||||
$req = 'SELECT COUNT(*) AS count, U.user_id ' .
|
$req = 'SELECT COUNT(*) AS count, U.user_id ' .
|
||||||
'FROM ' . dcCore::app()->prefix . 'post P ' .
|
'FROM ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ' .
|
||||||
'INNER JOIN ' . dcCore::app()->prefix . 'user U ON U.user_id = P.user_id ' .
|
'INNER JOIN ' . dcCore::app()->prefix . dcAuth::USER_TABLE_NAME . ' U ON U.user_id = P.user_id ' .
|
||||||
"WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->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) .
|
||||||
@ -30,16 +36,14 @@ class topWriter
|
|||||||
|
|
||||||
$rs = dcCore::app()->con->select($req);
|
$rs = dcCore::app()->con->select($req);
|
||||||
if ($rs->isEmpty()) {
|
if ($rs->isEmpty()) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->blog->settings->addNamespace('authormode');
|
|
||||||
|
|
||||||
$res = [];
|
$res = [];
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($rs->fetch()) {
|
while ($rs->fetch()) {
|
||||||
$user = dcCore::app()->con->select(
|
$user = dcCore::app()->con->select(
|
||||||
'SELECT * FROM ' . dcCore::app()->prefix . "user WHERE user_id='" . $rs->user_id . "' "
|
'SELECT * FROM ' . dcCore::app()->prefix . dcAuth::USER_TABLE_NAME . " WHERE user_id='" . $rs->user_id . "' "
|
||||||
);
|
);
|
||||||
if ($user->isEmpty()) {
|
if ($user->isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
@ -56,7 +60,7 @@ class topWriter
|
|||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
if (dcCore::app()->blog->settings->authormode->authormode_active) {
|
if (dcCore::app()->blog->settings->get('authormode')->get('authormode_active')) {
|
||||||
$res[$i]['author_link'] = '<a href="' .
|
$res[$i]['author_link'] = '<a href="' .
|
||||||
dcCore::app()->blog->url . dcCore::app()->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>';
|
||||||
@ -69,21 +73,17 @@ class topWriter
|
|||||||
if ($rs->count == 0) {
|
if ($rs->count == 0) {
|
||||||
$res[$i]['count'] = __('no entries');
|
$res[$i]['count'] = __('no entries');
|
||||||
} else {
|
} else {
|
||||||
$res[$i]['count'] = sprintf(__('one entry', '%s entries', $rs->count), $rs->count);
|
$res[$i]['count'] = sprintf(__('one entry', '%s entries', (int) $rs->count), $rs->count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$i) {
|
return $i ? $res : [];
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function comments(string $period, int $limit, bool $sort_desc = true, $exclude = false)
|
public static function comments(string $period, int $limit, bool $sort_desc = true, bool $exclude = false): array
|
||||||
{
|
{
|
||||||
$req = 'SELECT COUNT(*) AS count, comment_email ' .
|
$req = 'SELECT COUNT(*) AS count, comment_email ' .
|
||||||
'FROM ' . dcCore::app()->prefix . 'post P, ' . dcCore::app()->prefix . 'comment C ' .
|
'FROM ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P, ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' .
|
||||||
'WHERE P.post_id=C.post_id ' .
|
'WHERE P.post_id=C.post_id ' .
|
||||||
"AND blog_id='" . dcCore::app()->con->escape(dcCore::app()->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 ' .
|
||||||
@ -92,8 +92,8 @@ class topWriter
|
|||||||
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 ' . dcCore::app()->prefix . 'user U' .
|
' FROM ' . dcCore::app()->prefix . dcAuth::USER_TABLE_NAME . ' U' .
|
||||||
' INNER JOIN ' . dcCore::app()->prefix . 'post P ON P.user_id = U.user_id ' .
|
' INNER JOIN ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ON P.user_id = U.user_id ' .
|
||||||
" WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " .
|
" WHERE blog_id='" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " .
|
||||||
' GROUP BY U.user_email) ';
|
' GROUP BY U.user_email) ';
|
||||||
}
|
}
|
||||||
@ -104,14 +104,14 @@ class topWriter
|
|||||||
|
|
||||||
$rs = dcCore::app()->con->select($req);
|
$rs = dcCore::app()->con->select($req);
|
||||||
if ($rs->isEmpty()) {
|
if ($rs->isEmpty()) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = [];
|
$res = [];
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($rs->fetch()) {
|
while ($rs->fetch()) {
|
||||||
$user = dcCore::app()->con->select(
|
$user = dcCore::app()->con->select(
|
||||||
'SELECT * FROM ' . dcCore::app()->prefix . 'comment ' .
|
'SELECT * FROM ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' ' .
|
||||||
"WHERE comment_email='" . $rs->comment_email . "' " .
|
"WHERE comment_email='" . $rs->comment_email . "' " .
|
||||||
'ORDER BY comment_dt DESC'
|
'ORDER BY comment_dt DESC'
|
||||||
);
|
);
|
||||||
@ -131,15 +131,11 @@ class topWriter
|
|||||||
if ($rs->count == 0) {
|
if ($rs->count == 0) {
|
||||||
$res[$i]['count'] = __('no comments');
|
$res[$i]['count'] = __('no comments');
|
||||||
} else {
|
} else {
|
||||||
$res[$i]['count'] = sprintf(__('one comment', '%s comments', $rs->count), $rs->count);
|
$res[$i]['count'] = sprintf(__('one comment', '%s comments', (int) $rs->count), $rs->count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$i) {
|
return $i ? $res : [];
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function period(string $field, string $period): string
|
private static function period(string $field, string $period): string
|
||||||
@ -174,7 +170,7 @@ class topWriter
|
|||||||
return "AND $field > TIMESTAMP '" . dt::str($pattern, time() - $time) . "' ";
|
return "AND $field > TIMESTAMP '" . dt::str($pattern, time() - $time) . "' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function periods()
|
public static function periods(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
__('last day') => 'day',
|
__('last day') => 'day',
|
||||||
|
@ -10,22 +10,25 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcCore::app()->addBehavior('initWidgets', ['topWriterWidget', 'init']);
|
namespace Dotclear\Plugin\topWriter;
|
||||||
|
|
||||||
class topWriterWidget
|
use dcCore;
|
||||||
|
use Dotclear\Plugin\widgets\WidgetsStack;
|
||||||
|
use Dotclear\Plugin\widgets\WidgetsElement;
|
||||||
|
use html;
|
||||||
|
|
||||||
|
class Widgets
|
||||||
{
|
{
|
||||||
public static function init($w)
|
public static function initWidgets(WidgetsStack $w): void
|
||||||
{
|
{
|
||||||
#Top comments widget
|
#Top comments widget
|
||||||
$w
|
$w
|
||||||
->create(
|
->create(
|
||||||
'topcom',
|
'topcom',
|
||||||
__('Top writer: comments'),
|
__('Top writer: comments'),
|
||||||
['topWriterWidget', 'topCom'],
|
[self::class, 'topComWidget'],
|
||||||
null,
|
null,
|
||||||
__('List users who write more comments')
|
__('List users who write more comments')
|
||||||
)
|
)
|
||||||
@ -41,7 +44,7 @@ class topWriterWidget
|
|||||||
__('Period:'),
|
__('Period:'),
|
||||||
'year',
|
'year',
|
||||||
'combo',
|
'combo',
|
||||||
topWriter::periods()
|
Utils::periods()
|
||||||
)
|
)
|
||||||
->setting(
|
->setting(
|
||||||
'sort',
|
'sort',
|
||||||
@ -75,7 +78,7 @@ class topWriterWidget
|
|||||||
->create(
|
->create(
|
||||||
'toppost',
|
'toppost',
|
||||||
__('Top writer: entries'),
|
__('Top writer: entries'),
|
||||||
['topWriterWidget', 'topPost'],
|
[self::class, 'topPostWidget'],
|
||||||
null,
|
null,
|
||||||
__('List users who write more posts')
|
__('List users who write more posts')
|
||||||
)
|
)
|
||||||
@ -91,7 +94,7 @@ class topWriterWidget
|
|||||||
__('Period:'),
|
__('Period:'),
|
||||||
'year',
|
'year',
|
||||||
'combo',
|
'combo',
|
||||||
topWriter::periods()
|
Utils::periods()
|
||||||
)
|
)
|
||||||
->setting(
|
->setting(
|
||||||
'sort',
|
'sort',
|
||||||
@ -115,19 +118,19 @@ class topWriterWidget
|
|||||||
->addOffline();
|
->addOffline();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function topCom($w)
|
public static function topComWidget(WidgetsElement $w): string
|
||||||
{
|
{
|
||||||
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
||||||
return null;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines = topWriter::comments($w->period, $w->limit, $w->sort == 'desc', $w->exclude);
|
$lines = Utils::comments($w->period, (int) $w->limit, $w->sort == 'desc', (bool) $w->exclude);
|
||||||
if (empty($lines)) {
|
if (empty($lines)) {
|
||||||
return null;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $w->renderDiv(
|
return $w->renderDiv(
|
||||||
$w->content_only,
|
(bool) $w->content_only,
|
||||||
'topcomments ' . $w->class,
|
'topcomments ' . $w->class,
|
||||||
'',
|
'',
|
||||||
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
||||||
@ -135,19 +138,19 @@ class topWriterWidget
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function topPost($w)
|
public static function topPostWidget(WidgetsElement $w): string
|
||||||
{
|
{
|
||||||
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
||||||
return null;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines = topWriter::posts($w->period, $w->limit, $w->sort == 'desc');
|
$lines = Utils::posts($w->period, (int) $w->limit, $w->sort == 'desc');
|
||||||
if (empty($lines)) {
|
if (empty($lines)) {
|
||||||
return null;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $w->renderDiv(
|
return $w->renderDiv(
|
||||||
$w->content_only,
|
(bool) $w->content_only,
|
||||||
'topentries ' . $w->class,
|
'topentries ' . $w->class,
|
||||||
'',
|
'',
|
||||||
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
||||||
@ -155,7 +158,7 @@ class topWriterWidget
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function lines($lines, $id, $text)
|
private static function lines(array $lines, string $id, string $text): array
|
||||||
{
|
{
|
||||||
$li = [];
|
$li = [];
|
||||||
foreach ($lines as $k => $line) {
|
foreach ($lines as $k => $line) {
|
||||||
|
Loading…
Reference in New Issue
Block a user