addBehavior( 'initWidgets', ['zoneclearFeedServerWidget', 'adminSource'] ); dcCore::app()->addBehavior( 'initWidgets', ['zoneclearFeedServerWidget', 'adminNumber'] ); /** * @ingroup DC_PLUGIN_ZONECLEARFEEDSERVER * @brief Mix your blog with a feeds planet - widgets methods. * @since 2.6 */ class zoneclearFeedServerWidget { /** * Widget configuration for sources list. * * @param dcWidgets $w dcWidgets instance */ public static function adminSource($w) { $w ->create( 'zcfssource', __('Feeds server: sources'), ['zoneclearFeedServerWidget', 'publicSource'], null, __('List sources of feeds') ) ->addTitle( __('Feeds sources'), ) ->setting( 'sortby', __('Order by:'), 'feed_upd_last', 'combo', [ __('Last update') => 'feed_upd_last', __('Name') => 'lowername', __('Create date') => 'feed_creadt', ] ) ->setting( 'sort', __('Sort:'), 'desc', 'combo', [ __('Ascending') => 'asc', __('Descending') => 'desc', ] ) ->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. * * @param dcWidgets $w dcWidgets instance */ public static function adminNumber($w) { $w ->create( 'zcfsnumber', __('Feeds server: numbers'), ['zoneclearFeedServerWidget', 'publicNumber'], null, __('Show some numbers about feeds') ) ->addTitle( __('Feeds numbers'), ) ->setting( 'title', __('Title:'), __('Feeds numbers'), '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. * * @param dcWidget $w dcWidget instance */ public static function publicSource($w) { if ($w->offline) { return null; } 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; } $p = []; $p['order'] = ($w->sortby && in_array($w->sortby, ['feed_upd_last', 'lowername', 'feed_creadt'])) ? $w->sortby . ' ' : 'feed_upd_last '; $p['order'] .= $w->sort == 'desc' ? 'DESC' : 'ASC'; $p['limit'] = abs((int) $w->limit); $p['feed_status'] = 1; $zc = new zoneclearFeedServer(); $rs = $zc->getFeeds($p); if ($rs->isEmpty()) { return null; } $lines = []; $i = 1; while ($rs->fetch()) { $lines[] = sprintf( '
  • %s
  • ', $rs->feed_url, $rs->feed_owner, $rs->feed_name ); $i++; } $pub = ''; if ($w->pagelink && dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) { $pub = sprintf( '

    %s

    ', dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage'), html::escapeHTML($w->pagelink) ); } return $w->renderDiv( $w->content_only, 'zoneclear-sources ' . $w->class, '', ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . sprintf('', implode('', $lines)) . $pub ); } /** * Widget for feeds info. * * @param dcWidget $w dcWidget instance */ public static function publicNumber($w) { if ($w->offline) { return; } 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; } $zc = new zoneclearFeedServer(); $content = ''; # Feed if ($w->feed_show) { $title = ($w->feed_title ? sprintf( '%s ', html::escapeHTML($w->feed_title) ) : ''); $count = $zc->getFeeds([], true)->f(0); $text = $count ? sprintf(__('one source', '%d sources', $count), $count) : __('no sources'); if (dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) { $text = sprintf( '%s', dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage'), $text ); } $content .= sprintf('
  • %s%s
  • ', $title, $text); } # Entry if ($w->entry_show) { $count = 0; $feeds = $zc->getFeeds(); if (!$feeds->isEmpty()) { while ($feeds->fetch()) { $count += (int) $zc->getPostsByFeed(['feed_id' => $feeds->feed_id], true)->f(0); } } $title = ($w->entry_title ? sprintf( '%s ', html::escapeHTML($w->entry_title) ) : ''); $text = $count ? sprintf(__('one entry', '%d entries', $count), $count) : __('no entries'); $content .= sprintf('
  • %s%s
  • ', $title, $text); } if (!$content) { return null; } # Display return $w->renderDiv( $w->content_only, 'zoneclear-number ' . $w->class, '', ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . sprintf('', $content) ); } }