1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of zoneclearFeedServer, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009-2011 JC Denis, BG and contributors |
---|
6 | # jcdenis@gdwd.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')){return;} |
---|
14 | |
---|
15 | $core->addBehavior('initWidgets',array('zoneclearFeedServerWidget','adminSource')); |
---|
16 | $core->addBehavior('initWidgets',array('zoneclearFeedServerWidget','adminNumber')); |
---|
17 | |
---|
18 | class zoneclearFeedServerWidget |
---|
19 | { |
---|
20 | public static function adminSource($w) |
---|
21 | { |
---|
22 | $w->create('zcfssource', |
---|
23 | __('Feeds server : sources'), |
---|
24 | array('zoneclearFeedServerWidget','publicSource') |
---|
25 | ); |
---|
26 | $w->zcfssource->setting('title', |
---|
27 | __('Title:'),__('Feeds sources'),'text' |
---|
28 | ); |
---|
29 | $w->zcfssource->setting('sortby', |
---|
30 | __('Order by:'),'lowername','combo',array( |
---|
31 | __('name')=> 'lowername', |
---|
32 | __('creation date') => 'feed_creadt' |
---|
33 | ) |
---|
34 | ); |
---|
35 | $w->zcfssource->setting('sort', |
---|
36 | __('Sort:'),'desc','combo',array( |
---|
37 | __('Ascending') => 'asc', |
---|
38 | __('Descending') => 'desc' |
---|
39 | ) |
---|
40 | ); |
---|
41 | $w->zcfssource->setting('limit', |
---|
42 | __('Limit:'),10,'text' |
---|
43 | ); |
---|
44 | $w->zcfssource->setting('pagelink', |
---|
45 | __('Add link to feeds page'),1,'check' |
---|
46 | ); |
---|
47 | $w->zcfssource->setting('homeonly', |
---|
48 | __('Home page only'),1,'check' |
---|
49 | ); |
---|
50 | } |
---|
51 | |
---|
52 | public static function adminNumber($w) |
---|
53 | { |
---|
54 | $w->create('zcfsnumber',__('Feeds server : numbers'),array('zoneclearFeedServerWidget','publicNumber')); |
---|
55 | $w->zcfsnumber->setting('title',__('Title:'),__('Feeds numbers'),'text'); |
---|
56 | |
---|
57 | # Feed |
---|
58 | $w->zcfsnumber->setting('feed_show',__('Show feeds count'),1,'check'); |
---|
59 | $w->zcfsnumber->setting('feed_title',__('Title for feeds count:'),__('Feeds:'),'text'); |
---|
60 | |
---|
61 | # Entry |
---|
62 | $w->zcfsnumber->setting('entry_show',__('Show entries count'),1,'check'); |
---|
63 | $w->zcfsnumber->setting('entry_title',__('Title for entries count:'),__('Entries:'),'text'); |
---|
64 | |
---|
65 | $w->zcfsnumber->setting('homeonly',__('Home page only'),1,'check'); |
---|
66 | } |
---|
67 | |
---|
68 | public static function publicSource($w) |
---|
69 | { |
---|
70 | global $core; |
---|
71 | |
---|
72 | if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active |
---|
73 | || $w->homeonly && $core->url->type != 'default') return; |
---|
74 | |
---|
75 | $p = array(); |
---|
76 | $p['order'] = ($w->sortby && in_array($w->sortby,array('lowername','feed_creadt'))) ? |
---|
77 | $w->sortby.' ' : 'lowername '; |
---|
78 | |
---|
79 | $p['order'] .= $w->sort == 'desc' ? 'DESC' : 'ASC'; |
---|
80 | |
---|
81 | $p['limit'] = abs((integer) $w->limit); |
---|
82 | $p['feed_status'] = 1; |
---|
83 | |
---|
84 | $zc = new zoneclearFeedServer($core); |
---|
85 | $rs = $zc->getFeeds($p); |
---|
86 | |
---|
87 | if ($rs->isEmpty()) return; |
---|
88 | |
---|
89 | $res = ''; |
---|
90 | $i = 1; |
---|
91 | while($rs->fetch()) |
---|
92 | { |
---|
93 | $res .= |
---|
94 | '<li>'. |
---|
95 | '<a href="'.$rs->feed_url.'" title="'.$rs->feed_owner.'">'.$rs->feed_name.'</a>'. |
---|
96 | '</li>'; |
---|
97 | $i++; |
---|
98 | } |
---|
99 | |
---|
100 | if ($w->pagelink) |
---|
101 | { |
---|
102 | $res .= '<li><a href="'.$core->blog->url.$core->url->getBase('zoneclearFeedsPage').'">'.__('All sources').'</a></li>'; |
---|
103 | } |
---|
104 | |
---|
105 | return |
---|
106 | '<div class="zoneclear-sources">'. |
---|
107 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
108 | '<ul>'.$res.'</ul>'. |
---|
109 | '</div>'; |
---|
110 | } |
---|
111 | |
---|
112 | public static function publicNumber($w) |
---|
113 | { |
---|
114 | global $core; |
---|
115 | |
---|
116 | if (!$core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active |
---|
117 | || $w->homeonly && $core->url->type != 'default') return; |
---|
118 | |
---|
119 | $zc = new zoneclearFeedServer($core); |
---|
120 | $content = ''; |
---|
121 | |
---|
122 | # Feed |
---|
123 | if ($w->feed_show) |
---|
124 | { |
---|
125 | $title = ($w->feed_title ? |
---|
126 | '<strong>'.html::escapeHTML($w->feed_title).'</strong> ' : ''); |
---|
127 | |
---|
128 | $count = $zc->getFeeds(array(),true)->f(0); |
---|
129 | |
---|
130 | if ($count == 0) |
---|
131 | { |
---|
132 | $text = sprintf(__('none'),$count); |
---|
133 | } |
---|
134 | elseif ($count == 1) |
---|
135 | { |
---|
136 | $text = sprintf(__('one source'),$count); |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | $text = sprintf(__('%s sources'),$count); |
---|
141 | } |
---|
142 | if ($core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) |
---|
143 | { |
---|
144 | $text = '<a href="'.$core->blog->url.$core->url->getBase('zoneclearFeedsPage').'">'.$text.'</a>'; |
---|
145 | } |
---|
146 | |
---|
147 | $content .= sprintf('<li>%s%s</li>',$title,$text); |
---|
148 | } |
---|
149 | |
---|
150 | # Entry |
---|
151 | if ($w->entry_show) |
---|
152 | { |
---|
153 | $count = 0; |
---|
154 | $feeds = $zc->getFeeds(); |
---|
155 | if (!$feeds->isEmpty()) |
---|
156 | { |
---|
157 | while ($feeds->fetch()) |
---|
158 | { |
---|
159 | $count += (integer) $zc->getPostsByFeed(array('feed_id'=>$feeds->feed_id),true)->f(0); |
---|
160 | } |
---|
161 | } |
---|
162 | $title = ($w->entry_title ? |
---|
163 | '<strong>'.html::escapeHTML($w->entry_title).'</strong> ' : ''); |
---|
164 | |
---|
165 | if ($count == 0) |
---|
166 | { |
---|
167 | $text = sprintf(__('none'),$count); |
---|
168 | } |
---|
169 | elseif ($count == 1) |
---|
170 | { |
---|
171 | $text = sprintf(__('one entry'),$count); |
---|
172 | } |
---|
173 | else |
---|
174 | { |
---|
175 | $text = sprintf(__('%s entries'),$count); |
---|
176 | } |
---|
177 | |
---|
178 | $content .= sprintf('<li>%s%s</li>',$title,$text); |
---|
179 | } |
---|
180 | |
---|
181 | # Nothing to display |
---|
182 | if (!$content) return; |
---|
183 | |
---|
184 | # Display |
---|
185 | return |
---|
186 | '<div class="zoneclear-number">'. |
---|
187 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
188 | '<ul>'.$content.'</ul>'. |
---|
189 | '</div>'; |
---|
190 | } |
---|
191 | } |
---|
192 | ?> |
---|