2015-04-25 18:37:25 +00:00
|
|
|
<?php
|
2021-09-02 21:22:11 +00:00
|
|
|
/**
|
|
|
|
* @brief topWriter, a plugin for Dotclear 2
|
2021-11-06 20:15:51 +00:00
|
|
|
*
|
2021-09-02 21:22:11 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-06 20:15:51 +00:00
|
|
|
*
|
2021-09-02 21:22:11 +00:00
|
|
|
* @author Jean-Christian Denis, Pierre Van Glabeke
|
2021-11-06 20:15:51 +00:00
|
|
|
*
|
2021-09-02 21:22:11 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2015-04-25 18:37:25 +00:00
|
|
|
if (!defined('DC_RC_PATH')) {
|
2021-08-27 20:09:31 +00:00
|
|
|
return null;
|
2015-04-25 18:37:25 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 10:08:10 +00:00
|
|
|
dcCore::app()->addBehavior('initWidgets', ['topWriterWidget', 'init']);
|
2015-04-25 18:37:25 +00:00
|
|
|
|
|
|
|
class topWriterWidget
|
|
|
|
{
|
2021-08-27 20:09:31 +00:00
|
|
|
public static function init($w)
|
|
|
|
{
|
2021-11-06 20:15:51 +00:00
|
|
|
#Top comments widget
|
2021-08-27 20:09:31 +00:00
|
|
|
$w
|
|
|
|
->create(
|
|
|
|
'topcom',
|
2021-09-17 21:11:07 +00:00
|
|
|
__('Top writer: comments'),
|
2021-08-27 20:09:31 +00:00
|
|
|
['topWriterWidget', 'topCom'],
|
|
|
|
null,
|
|
|
|
__('List users who write more comments')
|
|
|
|
)
|
|
|
|
->addTitle(__('Top comments'))
|
|
|
|
->setting(
|
|
|
|
'text',
|
2021-11-06 20:15:51 +00:00
|
|
|
__('Text:') . ' (%rank%, %author%, %count%)',
|
2021-08-27 20:09:31 +00:00
|
|
|
'%author% (%count%)',
|
|
|
|
'text'
|
|
|
|
)
|
|
|
|
->setting(
|
|
|
|
'period',
|
|
|
|
__('Period:'),
|
|
|
|
'year',
|
|
|
|
'combo',
|
2021-11-06 20:15:51 +00:00
|
|
|
topWriter::periods()
|
2021-08-27 20:09:31 +00:00
|
|
|
)
|
|
|
|
->setting(
|
|
|
|
'sort',
|
|
|
|
__('Sort:'),
|
|
|
|
'desc',
|
|
|
|
'combo',
|
|
|
|
[
|
2021-11-06 20:15:51 +00:00
|
|
|
__('Ascending') => 'asc',
|
2022-11-15 10:08:10 +00:00
|
|
|
__('Descending') => 'desc',
|
2021-08-27 20:09:31 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
->setting(
|
|
|
|
'limit',
|
|
|
|
__('Limit:'),
|
|
|
|
'10',
|
|
|
|
'text'
|
|
|
|
)
|
|
|
|
->setting(
|
|
|
|
'exclude',
|
|
|
|
__('Exclude post writer from list'),
|
|
|
|
0,
|
|
|
|
'check'
|
|
|
|
)
|
|
|
|
->addHomeOnly()
|
|
|
|
->addContentOnly()
|
|
|
|
->addClass()
|
|
|
|
->addOffline();
|
|
|
|
|
|
|
|
#Top entries widget
|
|
|
|
$w
|
|
|
|
->create(
|
|
|
|
'toppost',
|
2021-09-17 21:11:07 +00:00
|
|
|
__('Top writer: entries'),
|
2021-08-27 20:09:31 +00:00
|
|
|
['topWriterWidget', 'topPost'],
|
|
|
|
null,
|
|
|
|
__('List users who write more posts')
|
|
|
|
)
|
|
|
|
->addTitle(__('Top entries'))
|
|
|
|
->setting(
|
|
|
|
'text',
|
2021-11-06 20:15:51 +00:00
|
|
|
__('Text:') . ' (%rank%, %author%, %count%)',
|
2021-08-27 20:09:31 +00:00
|
|
|
'%author% (%count%)',
|
|
|
|
'text'
|
|
|
|
)
|
|
|
|
->setting(
|
|
|
|
'period',
|
|
|
|
__('Period:'),
|
|
|
|
'year',
|
|
|
|
'combo',
|
2021-11-06 20:15:51 +00:00
|
|
|
topWriter::periods()
|
2021-08-27 20:09:31 +00:00
|
|
|
)
|
|
|
|
->setting(
|
|
|
|
'sort',
|
2021-11-06 20:15:51 +00:00
|
|
|
__('Sort:'),
|
|
|
|
'desc',
|
2021-08-27 20:09:31 +00:00
|
|
|
'combo',
|
|
|
|
[
|
2021-11-06 20:15:51 +00:00
|
|
|
__('Ascending') => 'asc',
|
2022-11-15 10:08:10 +00:00
|
|
|
__('Descending') => 'desc',
|
2021-08-27 20:09:31 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
->setting(
|
|
|
|
'limit',
|
|
|
|
__('Limit:'),
|
|
|
|
'10',
|
|
|
|
'text'
|
|
|
|
)
|
|
|
|
->addHomeOnly()
|
|
|
|
->addContentOnly()
|
|
|
|
->addClass()
|
|
|
|
->addOffline();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function topCom($w)
|
|
|
|
{
|
2022-12-23 09:32:20 +00:00
|
|
|
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
2021-08-27 20:09:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-15 10:08:10 +00:00
|
|
|
$lines = topWriter::comments($w->period, $w->limit, $w->sort == 'desc', $w->exclude);
|
2021-11-06 20:15:51 +00:00
|
|
|
if (empty($lines)) {
|
2021-08-27 20:09:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $w->renderDiv(
|
|
|
|
$w->content_only,
|
|
|
|
'topcomments ' . $w->class,
|
|
|
|
'',
|
|
|
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
2021-11-06 20:15:51 +00:00
|
|
|
sprintf('<ul>%s</ul>', implode('', self::lines($lines, 'comments', $w->text)))
|
2021-08-27 20:09:31 +00:00
|
|
|
);
|
|
|
|
}
|
2021-09-02 21:22:11 +00:00
|
|
|
|
2021-08-27 20:09:31 +00:00
|
|
|
public static function topPost($w)
|
|
|
|
{
|
2022-12-23 09:32:20 +00:00
|
|
|
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
2021-08-27 20:09:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-15 10:08:10 +00:00
|
|
|
$lines = topWriter::posts($w->period, $w->limit, $w->sort == 'desc');
|
2021-11-06 20:15:51 +00:00
|
|
|
if (empty($lines)) {
|
2021-08-27 20:09:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $w->renderDiv(
|
|
|
|
$w->content_only,
|
|
|
|
'topentries ' . $w->class,
|
|
|
|
'',
|
|
|
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
2021-11-06 20:15:51 +00:00
|
|
|
sprintf('<ul>%s</ul>', implode('', self::lines($lines, 'posts', $w->text)))
|
2021-08-27 20:09:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-06 20:15:51 +00:00
|
|
|
private static function lines($lines, $id, $text)
|
2021-08-27 20:09:31 +00:00
|
|
|
{
|
2021-11-06 20:15:51 +00:00
|
|
|
$li = [];
|
|
|
|
foreach ($lines as $k => $line) {
|
|
|
|
$rank = '<span class="top' . $id . '-rank">' . $k . '</span>';
|
|
|
|
$author = '<span class="top' . $id . '-author">' . (empty($line['author_link']) ? $line['author'] : $line['author_link']) . '</span>';
|
|
|
|
$li[] = sprintf(
|
|
|
|
'<li>%s</li>',
|
|
|
|
str_replace(
|
|
|
|
['%rank%', '%author%', '%count%'],
|
|
|
|
[$rank, $author, $line['count']],
|
|
|
|
$text
|
|
|
|
)
|
|
|
|
);
|
2021-08-27 20:09:31 +00:00
|
|
|
}
|
|
|
|
|
2021-11-06 20:15:51 +00:00
|
|
|
return $li;
|
2021-08-27 20:09:31 +00:00
|
|
|
}
|
2021-11-06 20:15:51 +00:00
|
|
|
}
|