zoneclearFeedServer/_widgets.php

282 lines
7.8 KiB
PHP
Raw Normal View History

2015-04-25 19:25:03 +00:00
<?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
2021-11-06 15:30:19 +00:00
*
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:30:19 +00:00
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
2021-11-06 15:30:19 +00:00
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2015-04-25 19:25:03 +00:00
if (!defined('DC_RC_PATH')) {
return null;
2015-04-25 19:25:03 +00:00
}
2022-11-15 20:05:21 +00:00
dcCore::app()->addBehavior(
'initWidgets',
2021-09-12 00:23:59 +00:00
['zoneclearFeedServerWidget', 'adminSource']
2015-04-25 19:25:03 +00:00
);
2022-11-15 20:05:21 +00:00
dcCore::app()->addBehavior(
'initWidgets',
2021-09-12 00:23:59 +00:00
['zoneclearFeedServerWidget', 'adminNumber']
2015-04-25 19:25:03 +00:00
);
/**
* @ingroup DC_PLUGIN_ZONECLEARFEEDSERVER
* @brief Mix your blog with a feeds planet - widgets methods.
* @since 2.6
*/
class zoneclearFeedServerWidget
{
/**
* Widget configuration for sources list.
2021-11-06 15:30:19 +00:00
*
2022-11-15 20:05:21 +00:00
* @param dcWidgets $w dcWidgets instance
*/
public static function adminSource($w)
{
2021-09-12 00:23:59 +00:00
$w
->create(
'zcfssource',
__('Feeds server: sources'),
['zoneclearFeedServerWidget', 'publicSource'],
null,
__('List sources of feeds')
)
2021-09-12 00:23:59 +00:00
->addTitle(
__('Feeds sources'),
)
2021-09-12 00:23:59 +00:00
->setting(
2021-11-06 15:30:19 +00:00
'sortby',
__('Order by:'),
'feed_upd_last',
'combo',
[
__('Last update') => 'feed_upd_last',
__('Name') => 'lowername',
2022-11-15 20:05:21 +00:00
__('Create date') => 'feed_creadt',
2021-11-06 15:30:19 +00:00
]
)
2021-09-12 00:23:59 +00:00
->setting(
'sort',
__('Sort:'),
'desc',
'combo',
[
2021-11-06 15:30:19 +00:00
__('Ascending') => 'asc',
2022-11-15 20:05:21 +00:00
__('Descending') => 'desc',
2021-09-12 00:23:59 +00:00
]
)
->setting(
'limit',
__('Limit:'),
10,
'text'
)
->setting(
'pagelink',
__('Link to the list of sources:'),
__('All sources'),
'text'
)
->addHomeOnly()
->addContentOnly()
->addClass()
->addOffline();
}
/**
* Widget configuration for feeds info.
2021-11-06 15:30:19 +00:00
*
2022-11-15 20:05:21 +00:00
* @param dcWidgets $w dcWidgets instance
*/
public static function adminNumber($w)
{
2021-09-12 00:23:59 +00:00
$w
->create(
'zcfsnumber',
__('Feeds server: numbers'),
['zoneclearFeedServerWidget', 'publicNumber'],
null,
__('Show some numbers about feeds')
)
2021-09-12 00:23:59 +00:00
->addTitle(
__('Feeds numbers'),
)
->setting(
'title',
2021-11-06 15:30:19 +00:00
__('Title:'),
__('Feeds numbers'),
2021-09-12 00:23:59 +00:00
'text'
)
->setting(
'feed_show',
__('Show feeds count'),
1,
'check'
)
->setting(
'feed_title',
__('Title for feeds count:'),
__('Feeds:'),
'text'
)
->setting(
'entry_show',
__('Show entries count'),
1,
'check'
)
->setting(
'entry_title',
__('Title for entries count:'),
__('Entries:'),
'text'
)
->addHomeOnly()
->addContentOnly()
->addClass()
->addOffline();
}
/**
* Widget for sources list.
2021-11-06 15:30:19 +00:00
*
* @param dcWidget $w dcWidget instance
*/
public static function publicSource($w)
{
2021-09-12 00:23:59 +00:00
if ($w->offline) {
return null;
}
2022-11-15 20:05:21 +00:00
if (!dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active
|| $w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type)
|| $w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type)
) {
return null;
}
2021-11-06 15:30:19 +00:00
$p = [];
$p['order'] = ($w->sortby && in_array($w->sortby, ['feed_upd_last', 'lowername', 'feed_creadt'])) ?
2021-09-12 00:23:59 +00:00
$w->sortby . ' ' : 'feed_upd_last ';
$p['order'] .= $w->sort == 'desc' ? 'DESC' : 'ASC';
2021-11-06 15:30:19 +00:00
$p['limit'] = abs((int) $w->limit);
$p['feed_status'] = 1;
2022-11-15 20:05:21 +00:00
$zc = new zoneclearFeedServer();
$rs = $zc->getFeeds($p);
if ($rs->isEmpty()) {
return null;
}
2021-09-12 00:23:59 +00:00
$lines = [];
2021-11-06 15:30:19 +00:00
$i = 1;
while ($rs->fetch()) {
2021-09-12 00:23:59 +00:00
$lines[] = sprintf(
2021-11-06 15:30:19 +00:00
'<li><a href="%s" title="%s">%s</a></li>',
2021-09-12 00:23:59 +00:00
$rs->feed_url,
$rs->feed_owner,
$rs->feed_name
);
$i++;
}
2021-09-12 00:23:59 +00:00
$pub = '';
2022-11-15 20:05:21 +00:00
if ($w->pagelink && dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) {
2021-09-12 00:23:59 +00:00
$pub = sprintf(
'<p><strong><a href="%s">%s</a></strong></p>',
2022-11-15 20:05:21 +00:00
dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage'),
2021-09-12 00:23:59 +00:00
html::escapeHTML($w->pagelink)
);
}
2021-09-12 00:23:59 +00:00
return $w->renderDiv(
$w->content_only,
'zoneclear-sources ' . $w->class,
'',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
sprintf('<ul>%s</ul>', implode('', $lines)) . $pub
);
}
/**
* Widget for feeds info.
2021-11-06 15:30:19 +00:00
*
* @param dcWidget $w dcWidget instance
*/
public static function publicNumber($w)
{
2021-09-12 00:23:59 +00:00
if ($w->offline) {
return;
2021-09-12 00:23:59 +00:00
}
2022-11-15 20:05:21 +00:00
if (!dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active
|| $w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type)
|| $w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type)
) {
return null;
}
2022-11-15 20:05:21 +00:00
$zc = new zoneclearFeedServer();
$content = '';
# Feed
if ($w->feed_show) {
2021-09-12 00:23:59 +00:00
$title = ($w->feed_title ? sprintf(
2021-11-06 15:30:19 +00:00
'<strong>%s</strong> ',
2021-09-12 00:23:59 +00:00
html::escapeHTML($w->feed_title)
) : '');
2021-09-12 00:23:59 +00:00
$count = $zc->getFeeds([], true)->f(0);
$text = $count ? sprintf(__('one source', '%d sources', $count), $count) : __('no sources');
2022-11-15 20:05:21 +00:00
if (dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) {
2021-09-12 00:23:59 +00:00
$text = sprintf(
'<a href="%s">%s</a>',
2022-11-15 20:05:21 +00:00
dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage'),
2021-09-12 00:23:59 +00:00
$text
);
}
2021-09-12 00:23:59 +00:00
$content .= sprintf('<li>%s%s</li>', $title, $text);
}
# Entry
if ($w->entry_show) {
$count = 0;
$feeds = $zc->getFeeds();
if (!$feeds->isEmpty()) {
while ($feeds->fetch()) {
2021-11-06 15:30:19 +00:00
$count += (int) $zc->getPostsByFeed(['feed_id' => $feeds->feed_id], true)->f(0);
}
}
2021-09-12 00:23:59 +00:00
$title = ($w->entry_title ? sprintf(
'<strong>%s</strong> ',
html::escapeHTML($w->entry_title)
) : '');
2021-09-12 00:23:59 +00:00
$text = $count ? sprintf(__('one entry', '%d entries', $count), $count) : __('no entries');
2021-09-12 00:23:59 +00:00
$content .= sprintf('<li>%s%s</li>', $title, $text);
}
if (!$content) {
return null;
}
# Display
2021-09-12 00:23:59 +00:00
return $w->renderDiv(
$w->content_only,
'zoneclear-number ' . $w->class,
'',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
sprintf('<ul>%s</ul>', $content)
);
}
2021-11-06 15:30:19 +00:00
}