update widgets code
This commit is contained in:
parent
2a8a03621f
commit
8d1c821dd8
329
_widgets.php
329
_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
|
||||||
'zcfssource',
|
->create(
|
||||||
__('Feeds server: sources'),
|
'zcfssource',
|
||||||
array('zoneclearFeedServerWidget', 'publicSource'),
|
__('Feeds server: sources'),
|
||||||
null,
|
['zoneclearFeedServerWidget', 'publicSource'],
|
||||||
__('List sources of feeds')
|
null,
|
||||||
);
|
__('List sources of feeds')
|
||||||
$w->zcfssource->setting(
|
|
||||||
'title',
|
|
||||||
__('Title:'),
|
|
||||||
__('Feeds sources'),
|
|
||||||
'text'
|
|
||||||
);
|
|
||||||
$w->zcfssource->setting(
|
|
||||||
'sortby',
|
|
||||||
__('Order by:'),
|
|
||||||
'feed_upd_last',
|
|
||||||
'combo',
|
|
||||||
array(
|
|
||||||
__('Last update') => 'feed_upd_last',
|
|
||||||
__('Name') => 'lowername',
|
|
||||||
__('Create date') => 'feed_creadt'
|
|
||||||
)
|
)
|
||||||
);
|
->addTitle(
|
||||||
$w->zcfssource->setting(
|
__('Feeds sources'),
|
||||||
'sort',
|
|
||||||
__('Sort:'),
|
|
||||||
'desc',
|
|
||||||
'combo',
|
|
||||||
array(
|
|
||||||
__('Ascending') => 'asc',
|
|
||||||
__('Descending') => 'desc'
|
|
||||||
)
|
)
|
||||||
);
|
->setting(
|
||||||
$w->zcfssource->setting(
|
'sortby',
|
||||||
'limit',
|
__('Order by:'),
|
||||||
__('Limit:'),
|
'feed_upd_last',
|
||||||
10,
|
'combo',
|
||||||
'text'
|
[
|
||||||
);
|
__('Last update') => 'feed_upd_last',
|
||||||
$w->zcfssource->setting('pagelink',__('Link to the list of sources:'),__('All sources'));
|
__('Name') => 'lowername',
|
||||||
$w->zcfssource->setting(
|
__('Create date') => 'feed_creadt'
|
||||||
'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');
|
'sort',
|
||||||
$w->zcfssource->setting('class',__('CSS class:'),'');
|
__('Sort:'),
|
||||||
$w->zcfssource->setting('offline',__('Offline'),0,'check');
|
'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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,71 +95,51 @@ class zoneclearFeedServerWidget
|
|||||||
*/
|
*/
|
||||||
public static function adminNumber($w)
|
public static function adminNumber($w)
|
||||||
{
|
{
|
||||||
$w->create(
|
$w
|
||||||
'zcfsnumber',
|
->create(
|
||||||
__('Feeds server: numbers'),
|
'zcfsnumber',
|
||||||
array('zoneclearFeedServerWidget', 'publicNumber'),
|
__('Feeds server: numbers'),
|
||||||
null,
|
['zoneclearFeedServerWidget', 'publicNumber'],
|
||||||
__('Show some numbers about feeds')
|
null,
|
||||||
);
|
__('Show some numbers about feeds')
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'title',
|
|
||||||
__('Title:')
|
|
||||||
,__('Feeds numbers'),
|
|
||||||
'text'
|
|
||||||
);
|
|
||||||
|
|
||||||
# Feed
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'feed_show',
|
|
||||||
__('Show feeds count'),
|
|
||||||
1,
|
|
||||||
'check'
|
|
||||||
);
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'feed_title',
|
|
||||||
__('Title for feeds count:'),
|
|
||||||
__('Feeds:'),
|
|
||||||
'text'
|
|
||||||
);
|
|
||||||
|
|
||||||
# Entry
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'entry_show',
|
|
||||||
__('Show entries count'),
|
|
||||||
1,
|
|
||||||
'check'
|
|
||||||
);
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'entry_title',
|
|
||||||
__('Title for entries count:'),
|
|
||||||
__('Entries:'),
|
|
||||||
'text'
|
|
||||||
);
|
|
||||||
|
|
||||||
$w->zcfsnumber->setting(
|
|
||||||
'homeonly',
|
|
||||||
__('Display on:'),
|
|
||||||
0,
|
|
||||||
'combo',
|
|
||||||
array(
|
|
||||||
__('All pages') => 0,
|
|
||||||
__('Home page only') => 1,
|
|
||||||
__('Except on home page') => 2
|
|
||||||
)
|
)
|
||||||
);
|
->addTitle(
|
||||||
$w->zcfsnumber->setting(
|
__('Feeds numbers'),
|
||||||
'content_only',
|
)
|
||||||
__('Content only'),
|
->setting(
|
||||||
0,
|
'title',
|
||||||
'check'
|
__('Title:')
|
||||||
);
|
,__('Feeds numbers'),
|
||||||
$w->zcfsnumber->setting(
|
'text'
|
||||||
'class',
|
)
|
||||||
__('CSS class:'),
|
->setting(
|
||||||
''
|
'feed_show',
|
||||||
);
|
__('Show feeds count'),
|
||||||
$w->zcfsnumber->setting('offline',__('Offline'),0,'check');
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,19 +151,20 @@ 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);
|
||||||
$p['feed_status'] = 1;
|
$p['feed_status'] = 1;
|
||||||
@ -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,25 +230,24 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Entry
|
# Entry
|
||||||
@ -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->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
|
$w->content_only,
|
||||||
'<ul>'.$content.'</ul>';
|
'zoneclear-number ' . $w->class,
|
||||||
|
'',
|
||||||
return $w->renderDiv($w->content_only,'zoneclear-number '.$w->class,'',$res);
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
||||||
|
sprintf('<ul>%s</ul>', $content)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user