update widgets code
This commit is contained in:
parent
2a8a03621f
commit
8d1c821dd8
229
_widgets.php
229
_widgets.php
@ -12,17 +12,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'initWidgets',
|
'initWidgets',
|
||||||
array('zoneclearFeedServerWidget', 'adminSource')
|
['zoneclearFeedServerWidget', 'adminSource']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'initWidgets',
|
'initWidgets',
|
||||||
array('zoneclearFeedServerWidget', 'adminNumber')
|
['zoneclearFeedServerWidget', 'adminNumber']
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,61 +38,54 @@ class zoneclearFeedServerWidget
|
|||||||
*/
|
*/
|
||||||
public static function adminSource($w)
|
public static function adminSource($w)
|
||||||
{
|
{
|
||||||
$w->create(
|
$w
|
||||||
|
->create(
|
||||||
'zcfssource',
|
'zcfssource',
|
||||||
__('Feeds server: sources'),
|
__('Feeds server: sources'),
|
||||||
array('zoneclearFeedServerWidget', 'publicSource'),
|
['zoneclearFeedServerWidget', 'publicSource'],
|
||||||
null,
|
null,
|
||||||
__('List sources of feeds')
|
__('List sources of feeds')
|
||||||
);
|
)
|
||||||
$w->zcfssource->setting(
|
->addTitle(
|
||||||
'title',
|
|
||||||
__('Title:'),
|
|
||||||
__('Feeds sources'),
|
__('Feeds sources'),
|
||||||
'text'
|
)
|
||||||
);
|
->setting(
|
||||||
$w->zcfssource->setting(
|
|
||||||
'sortby',
|
'sortby',
|
||||||
__('Order by:'),
|
__('Order by:'),
|
||||||
'feed_upd_last',
|
'feed_upd_last',
|
||||||
'combo',
|
'combo',
|
||||||
array(
|
[
|
||||||
__('Last update') => 'feed_upd_last',
|
__('Last update') => 'feed_upd_last',
|
||||||
__('Name') => 'lowername',
|
__('Name') => 'lowername',
|
||||||
__('Create date') => 'feed_creadt'
|
__('Create date') => 'feed_creadt'
|
||||||
|
]
|
||||||
)
|
)
|
||||||
);
|
->setting(
|
||||||
$w->zcfssource->setting(
|
|
||||||
'sort',
|
'sort',
|
||||||
__('Sort:'),
|
__('Sort:'),
|
||||||
'desc',
|
'desc',
|
||||||
'combo',
|
'combo',
|
||||||
array(
|
[
|
||||||
__('Ascending') => 'asc',
|
__('Ascending') => 'asc',
|
||||||
__('Descending') => 'desc'
|
__('Descending') => 'desc'
|
||||||
|
]
|
||||||
)
|
)
|
||||||
);
|
->setting(
|
||||||
$w->zcfssource->setting(
|
|
||||||
'limit',
|
'limit',
|
||||||
__('Limit:'),
|
__('Limit:'),
|
||||||
10,
|
10,
|
||||||
'text'
|
'text'
|
||||||
);
|
|
||||||
$w->zcfssource->setting('pagelink',__('Link to the list of sources:'),__('All sources'));
|
|
||||||
$w->zcfssource->setting(
|
|
||||||
'homeonly',
|
|
||||||
__('Display on:'),
|
|
||||||
0,
|
|
||||||
'combo',
|
|
||||||
array(
|
|
||||||
__('All pages') => 0,
|
|
||||||
__('Home page only') => 1,
|
|
||||||
__('Except on home page') => 2
|
|
||||||
)
|
)
|
||||||
);
|
->setting(
|
||||||
$w->zcfssource->setting('content_only',__('Content only'),0,'check');
|
'pagelink',
|
||||||
$w->zcfssource->setting('class',__('CSS class:'),'');
|
__('Link to the list of sources:'),
|
||||||
$w->zcfssource->setting('offline',__('Offline'),0,'check');
|
__('All sources'),
|
||||||
|
'text'
|
||||||
|
)
|
||||||
|
->addHomeOnly()
|
||||||
|
->addContentOnly()
|
||||||
|
->addClass()
|
||||||
|
->addOffline();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,71 +95,51 @@ class zoneclearFeedServerWidget
|
|||||||
*/
|
*/
|
||||||
public static function adminNumber($w)
|
public static function adminNumber($w)
|
||||||
{
|
{
|
||||||
$w->create(
|
$w
|
||||||
|
->create(
|
||||||
'zcfsnumber',
|
'zcfsnumber',
|
||||||
__('Feeds server: numbers'),
|
__('Feeds server: numbers'),
|
||||||
array('zoneclearFeedServerWidget', 'publicNumber'),
|
['zoneclearFeedServerWidget', 'publicNumber'],
|
||||||
null,
|
null,
|
||||||
__('Show some numbers about feeds')
|
__('Show some numbers about feeds')
|
||||||
);
|
)
|
||||||
$w->zcfsnumber->setting(
|
->addTitle(
|
||||||
|
__('Feeds numbers'),
|
||||||
|
)
|
||||||
|
->setting(
|
||||||
'title',
|
'title',
|
||||||
__('Title:')
|
__('Title:')
|
||||||
,__('Feeds numbers'),
|
,__('Feeds numbers'),
|
||||||
'text'
|
'text'
|
||||||
);
|
)
|
||||||
|
->setting(
|
||||||
# Feed
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'feed_show',
|
'feed_show',
|
||||||
__('Show feeds count'),
|
__('Show feeds count'),
|
||||||
1,
|
1,
|
||||||
'check'
|
'check'
|
||||||
);
|
)
|
||||||
$w->zcfsnumber->setting(
|
->setting(
|
||||||
'feed_title',
|
'feed_title',
|
||||||
__('Title for feeds count:'),
|
__('Title for feeds count:'),
|
||||||
__('Feeds:'),
|
__('Feeds:'),
|
||||||
'text'
|
'text'
|
||||||
);
|
)
|
||||||
|
->setting(
|
||||||
# Entry
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'entry_show',
|
'entry_show',
|
||||||
__('Show entries count'),
|
__('Show entries count'),
|
||||||
1,
|
1,
|
||||||
'check'
|
'check'
|
||||||
);
|
)
|
||||||
$w->zcfsnumber->setting(
|
->setting(
|
||||||
'entry_title',
|
'entry_title',
|
||||||
__('Title for entries count:'),
|
__('Title for entries count:'),
|
||||||
__('Entries:'),
|
__('Entries:'),
|
||||||
'text'
|
'text'
|
||||||
);
|
|
||||||
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'homeonly',
|
|
||||||
__('Display on:'),
|
|
||||||
0,
|
|
||||||
'combo',
|
|
||||||
array(
|
|
||||||
__('All pages') => 0,
|
|
||||||
__('Home page only') => 1,
|
|
||||||
__('Except on home page') => 2
|
|
||||||
)
|
)
|
||||||
);
|
->addHomeOnly()
|
||||||
$w->zcfsnumber->setting(
|
->addContentOnly()
|
||||||
'content_only',
|
->addClass()
|
||||||
__('Content only'),
|
->addOffline();
|
||||||
0,
|
|
||||||
'check'
|
|
||||||
);
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'class',
|
|
||||||
__('CSS class:'),
|
|
||||||
''
|
|
||||||
);
|
|
||||||
$w->zcfsnumber->setting('offline',__('Offline'),0,'check');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,18 +151,19 @@ class zoneclearFeedServerWidget
|
|||||||
{
|
{
|
||||||
global $core;
|
global $core;
|
||||||
|
|
||||||
if ($w->offline)
|
if ($w->offline) {
|
||||||
return;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active
|
if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active
|
||||||
|| $w->homeonly == 1 && $core->url->type != 'default'
|
|| $w->homeonly == 1 && !$core->url->isHome($core->url->type)
|
||||||
|| $w->homeonly == 2 && $core->url->type == 'default'
|
|| $w->homeonly == 2 && $core->url->isHome($core->url->type)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$p = array();
|
$p = [];
|
||||||
$p['order'] = ($w->sortby && in_array($w->sortby, array('feed_upd_last', 'lowername', 'feed_creadt'))) ?
|
$p['order'] = ($w->sortby && in_array($w->sortby, ['feed_upd_last', 'lowername', 'feed_creadt'])) ?
|
||||||
$w->sortby . ' ' : 'feed_upd_last ';
|
$w->sortby . ' ' : 'feed_upd_last ';
|
||||||
$p['order'] .= $w->sort == 'desc' ? 'DESC' : 'ASC';
|
$p['order'] .= $w->sort == 'desc' ? 'DESC' : 'ASC';
|
||||||
$p['limit'] = abs((integer) $w->limit);
|
$p['limit'] = abs((integer) $w->limit);
|
||||||
@ -200,30 +173,36 @@ class zoneclearFeedServerWidget
|
|||||||
$rs = $zc->getFeeds($p);
|
$rs = $zc->getFeeds($p);
|
||||||
|
|
||||||
if ($rs->isEmpty()) {
|
if ($rs->isEmpty()) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = '';
|
$lines = [];
|
||||||
$i = 1;
|
$i = 1;
|
||||||
while($rs->fetch()) {
|
while($rs->fetch()) {
|
||||||
$res .=
|
$lines[] = sprintf(
|
||||||
'<li>'.
|
'<li><a href="%s" title="%s">%s</a></li>',
|
||||||
'<a href="'.$rs->feed_url.'" title="'.$rs->feed_owner.'">'.$rs->feed_name.'</a>'.
|
$rs->feed_url,
|
||||||
'</li>';
|
$rs->feed_owner,
|
||||||
|
$rs->feed_name
|
||||||
|
);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
$pub = '';
|
||||||
$res =
|
if ($w->pagelink && $core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) {
|
||||||
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
|
$pub = sprintf(
|
||||||
'<ul>'.$res.'</ul>';
|
'<p><strong><a href="%s">%s</a></strong></p>',
|
||||||
|
$core->blog->url . $core->url->getBase('zoneclearFeedsPage'),
|
||||||
if ($w->pagelink) {
|
html::escapeHTML($w->pagelink)
|
||||||
$res .= '<p><strong><a href="'.$core->blog->url.$core->url->getBase('zoneclearFeedsPage').'">'.
|
);
|
||||||
html::escapeHTML($w->pagelink).'</a></strong></p>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $w->renderDiv($w->content_only,'zoneclear-sources '.$w->class,'',$res);
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -235,12 +214,13 @@ class zoneclearFeedServerWidget
|
|||||||
{
|
{
|
||||||
global $core;
|
global $core;
|
||||||
|
|
||||||
if ($w->offline)
|
if ($w->offline) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active
|
if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active
|
||||||
|| $w->homeonly == 1 && $core->url->type != 'default'
|
|| $w->homeonly == 1 && !$core->url->isHome($core->url->type)
|
||||||
|| $w->homeonly == 2 && $core->url->type == 'default'
|
|| $w->homeonly == 2 && $core->url->isHome($core->url->type)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -250,22 +230,21 @@ class zoneclearFeedServerWidget
|
|||||||
|
|
||||||
# Feed
|
# Feed
|
||||||
if ($w->feed_show) {
|
if ($w->feed_show) {
|
||||||
$title = ($w->feed_title ?
|
$title = ($w->feed_title ? sprintf(
|
||||||
'<strong>'.html::escapeHTML($w->feed_title).'</strong> ' : '');
|
'<strong>%s</strong> ',
|
||||||
|
html::escapeHTML($w->feed_title)
|
||||||
|
) : '');
|
||||||
|
|
||||||
$count = $zc->getFeeds(array(),true)->f(0);
|
$count = $zc->getFeeds([], true)->f(0);
|
||||||
|
|
||||||
|
$text = $count ? sprintf(__('one source', '%d sources', $count), $count) : __('no sources');
|
||||||
|
|
||||||
if ($count == 0) {
|
|
||||||
$text = sprintf(__('no sources'),$count);
|
|
||||||
}
|
|
||||||
elseif ($count == 1) {
|
|
||||||
$text = sprintf(__('one source'),$count);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$text = sprintf(__('%d sources'),$count);
|
|
||||||
}
|
|
||||||
if ($core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) {
|
if ($core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) {
|
||||||
$text = '<a href="'.$core->blog->url.$core->url->getBase('zoneclearFeedsPage').'">'.$text.'</a>';
|
$text = sprintf(
|
||||||
|
'<a href="%s">%s</a>',
|
||||||
|
$core->blog->url . $core->url->getBase('zoneclearFeedsPage'),
|
||||||
|
$text
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$content .= sprintf('<li>%s%s</li>', $title, $text);
|
$content .= sprintf('<li>%s%s</li>', $title, $text);
|
||||||
@ -278,36 +257,30 @@ class zoneclearFeedServerWidget
|
|||||||
|
|
||||||
if (!$feeds->isEmpty()) {
|
if (!$feeds->isEmpty()) {
|
||||||
while ($feeds->fetch()) {
|
while ($feeds->fetch()) {
|
||||||
$count += (integer) $zc->getPostsByFeed(array('feed_id' => $feeds->feed_id), true)->f(0);
|
$count += (integer) $zc->getPostsByFeed(['feed_id' => $feeds->feed_id], true)->f(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$title = ($w->entry_title ?
|
$title = ($w->entry_title ? sprintf(
|
||||||
'<strong>'.html::escapeHTML($w->entry_title).'</strong> ' : '');
|
'<strong>%s</strong> ',
|
||||||
|
html::escapeHTML($w->entry_title)
|
||||||
|
) : '');
|
||||||
|
|
||||||
if ($count == 0) {
|
$text = $count ? sprintf(__('one entry', '%d entries', $count), $count) : __('no entries');
|
||||||
$text = sprintf(__('no entries'),$count);
|
|
||||||
}
|
|
||||||
elseif ($count == 1) {
|
|
||||||
$text = sprintf(__('one entry'),$count);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$text = sprintf(__('%d entries'),$count);
|
|
||||||
}
|
|
||||||
|
|
||||||
$content .= sprintf('<li>%s%s</li>', $title, $text);
|
$content .= sprintf('<li>%s%s</li>', $title, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Nothing to display
|
|
||||||
if (!$content) {
|
if (!$content) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Display
|
# Display
|
||||||
$res =
|
return $w->renderDiv(
|
||||||
|
$w->content_only,
|
||||||
|
'zoneclear-number ' . $w->class,
|
||||||
|
'',
|
||||||
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
||||||
'<ul>'.$content.'</ul>';
|
sprintf('<ul>%s</ul>', $content)
|
||||||
|
);
|
||||||
return $w->renderDiv($w->content_only,'zoneclear-number '.$w->class,'',$res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user