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_CONTEXT_ADMIN')){return;} |
---|
14 | |
---|
15 | class zoneclearFeedServerFeedsList extends adminGenericList |
---|
16 | { |
---|
17 | public function feedsDisplay($page,$nb_per_page,$url) |
---|
18 | { |
---|
19 | if ($this->rs->isEmpty()) |
---|
20 | { |
---|
21 | echo '<p><strong>'.__('There is no feed').'</strong></p>'; |
---|
22 | } |
---|
23 | else |
---|
24 | { |
---|
25 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
---|
26 | |
---|
27 | $pager->base_url = $url; |
---|
28 | |
---|
29 | $html_block = |
---|
30 | '<table class="clear">'. |
---|
31 | '<thead>'. |
---|
32 | '<tr>'. |
---|
33 | '<th class="nowrap" colspan="2">'.__('Name').'</th>'. |
---|
34 | '<th>'.__('Feed').'</th>'. |
---|
35 | '<th>'.__('Lang').'</th>'. |
---|
36 | '<th>'.__('Tags').'</th>'. |
---|
37 | '<th>'.__('Frequency').'</th>'. |
---|
38 | '<th class="nowrap">'.__('Last update').'</th>'. |
---|
39 | '<th>'.__('Category').'</th>'. |
---|
40 | '<th>'.__('Owner').'</th>'. |
---|
41 | '<th>'.__('Entries').'</th>'. |
---|
42 | '<th>'.__('Status').'</th>'. |
---|
43 | '</tr>'. |
---|
44 | '</thead>'. |
---|
45 | '<tbody>%s</tbody>'. |
---|
46 | '</table>'; |
---|
47 | |
---|
48 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
49 | $blocks = explode('%s',$html_block); |
---|
50 | echo $blocks[0]; |
---|
51 | |
---|
52 | $this->rs->index(((integer)$page - 1) * $nb_per_page); |
---|
53 | $iter = 0; |
---|
54 | while ($iter < $nb_per_page) |
---|
55 | { |
---|
56 | echo $this->feedsLine($url,$iter); |
---|
57 | |
---|
58 | if ($this->rs->isEnd()) |
---|
59 | { |
---|
60 | break; |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | $this->rs->moveNext(); |
---|
65 | } |
---|
66 | $iter++; |
---|
67 | } |
---|
68 | echo $blocks[1]; |
---|
69 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | private function feedsLine($url,$loop) |
---|
74 | { |
---|
75 | $combo_status = zoneclearFeedServer::getAllStatus(); |
---|
76 | $combo_upd_int = zoneclearFeedServer::getAllUpdateInterval(); |
---|
77 | $status = $this->rs->feed_status ? |
---|
78 | '<img src="images/check-on.png" alt="enable" />' : |
---|
79 | '<img src="images/check-off.png" alt="disable" />'; |
---|
80 | $category = $this->rs->cat_id ? $this->rs->cat_title : __('none'); |
---|
81 | |
---|
82 | $entries_count = $this->rs->zc->getPostsByFeed(array('feed_id'=>$this->rs->feed_id),true)->f(0); |
---|
83 | |
---|
84 | return |
---|
85 | '<tr class="line">'."\n". |
---|
86 | '<td class="nowrap">'. |
---|
87 | form::checkbox(array('feeds[]'),$this->rs->feed_id,0). |
---|
88 | '</td>'. |
---|
89 | '<td class="nowrap">'. |
---|
90 | '<a href="plugin.php?p=zoneclearFeedServer&part=feed&feed_id='.$this->rs->feed_id.'" title="'.__('Edit').'">'. |
---|
91 | html::escapeHTML($this->rs->feed_name).'</a>'. |
---|
92 | "</td>\n". |
---|
93 | '<td class="maximal nowrap">'. |
---|
94 | '<a href="'.$this->rs->feed_feed.'" title="'.html::escapeHTML($this->rs->feed_desc).'">'.$this->rs->feed_feed.'</a>'. |
---|
95 | "</td>\n". |
---|
96 | '<td class="nowrap">'. |
---|
97 | html::escapeHTML($this->rs->feed_lang). |
---|
98 | "</td>\n". |
---|
99 | '<td class="nowrap">'. |
---|
100 | html::escapeHTML($this->rs->feed_tags). |
---|
101 | "</td>\n". |
---|
102 | '<td class="nowrap">'. |
---|
103 | array_search($this->rs->feed_upd_int,$combo_upd_int). |
---|
104 | "</td>\n". |
---|
105 | '<td class="nowrap">'. |
---|
106 | ($this->rs->feed_upd_last < 1 ? |
---|
107 | __('never') : |
---|
108 | dt::str(__('%Y-%m-%d %H:%M'),$this->rs->feed_upd_last,$this->rs->zc->core->auth->getInfo('user_tz')) |
---|
109 | ). |
---|
110 | "</td>\n". |
---|
111 | '<td>'. |
---|
112 | html::escapeHTML($category). |
---|
113 | "</td>\n". |
---|
114 | '<td class="nowrap">'. |
---|
115 | html::escapeHTML($this->rs->feed_owner). |
---|
116 | "</td>\n". |
---|
117 | '<td class="nowrap">'. |
---|
118 | ($entries_count ? |
---|
119 | '<a href="plugin.php?p=zoneclearFeedServer&part=feed&tab=entries&feed_id='.$this->rs->feed_id.'" title="'.__('View entries').'">'.$entries_count.'</a>' : |
---|
120 | $entries_count |
---|
121 | ). |
---|
122 | "</td>\n". |
---|
123 | '<td>'. |
---|
124 | $status. |
---|
125 | "</td>\n". |
---|
126 | '</tr>'."\n"; |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | # Actions |
---|
131 | $feeds_action = ''; |
---|
132 | |
---|
133 | # Delete posts |
---|
134 | if ($action == 'deletepost' && !empty($_POST['feeds'])) |
---|
135 | { |
---|
136 | try |
---|
137 | { |
---|
138 | $types = array( |
---|
139 | 'zoneclearfeed_url', |
---|
140 | 'zoneclearfeed_author', |
---|
141 | 'zoneclearfeed_site', |
---|
142 | 'zoneclearfeed_sitename', |
---|
143 | 'zoneclearfeed_id' |
---|
144 | ); |
---|
145 | foreach($_POST['feeds'] as $feed_id) |
---|
146 | { |
---|
147 | $posts = $zc->getPostsByFeed(array('feed_id'=>$feed_id)); |
---|
148 | while($posts->fetch()) |
---|
149 | { |
---|
150 | $core->blog->delPost($posts->post_id); |
---|
151 | $core->con->execute( |
---|
152 | 'DELETE FROM '.$core->prefix.'meta '. |
---|
153 | 'WHERE post_id = '.$posts->post_id.' '. |
---|
154 | 'AND meta_type '.$core->con->in($types).' ' |
---|
155 | ); |
---|
156 | } |
---|
157 | } |
---|
158 | http::redirect($p_url.'&part=feeds&msg='.$action); |
---|
159 | } |
---|
160 | catch (Exception $e) { |
---|
161 | $core->error->add($e->getMessage()); |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | # Delete feeds |
---|
166 | if ($action == 'deletefeed' && !empty($_POST['feeds'])) |
---|
167 | { |
---|
168 | try { |
---|
169 | foreach($_POST['feeds'] as $feed_id) |
---|
170 | { |
---|
171 | $zc->delFeed($feed_id); |
---|
172 | } |
---|
173 | http::redirect($p_url.'&part=feeds&msg='.$action); |
---|
174 | } |
---|
175 | catch (Exception $e) { |
---|
176 | $core->error->add($e->getMessage()); |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | # Enable feeds |
---|
181 | if ($action == 'enablefeed' && !empty($_POST['feeds'])) |
---|
182 | { |
---|
183 | try { |
---|
184 | foreach($_POST['feeds'] as $feed_id) |
---|
185 | { |
---|
186 | $zc->enableFeed($feed_id,true); |
---|
187 | } |
---|
188 | http::redirect($p_url.'&part=feeds&msg='.$action); |
---|
189 | } |
---|
190 | catch (Exception $e) { |
---|
191 | $core->error->add($e->getMessage()); |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | # Disable feeds |
---|
196 | if ($action == 'disablefeed' && !empty($_POST['feeds'])) |
---|
197 | { |
---|
198 | try { |
---|
199 | foreach($_POST['feeds'] as $feed_id) |
---|
200 | { |
---|
201 | $zc->enableFeed($feed_id,false); |
---|
202 | } |
---|
203 | http::redirect($p_url.'&part=feeds&msg='.$action); |
---|
204 | } |
---|
205 | catch (Exception $e) { |
---|
206 | $core->error->add($e->getMessage()); |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | # Update (check) feeds |
---|
211 | if ($action == 'updatefeed' && !empty($_POST['feeds'])) |
---|
212 | { |
---|
213 | try { |
---|
214 | foreach($_POST['feeds'] as $feed_id) |
---|
215 | { |
---|
216 | $zc->checkFeedsUpdate($feed_id,true); |
---|
217 | } |
---|
218 | http::redirect($p_url.'&part=feeds&msg='.$action); |
---|
219 | } |
---|
220 | catch (Exception $e) { |
---|
221 | $core->error->add($e->getMessage()); |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | # Move to right part |
---|
226 | if ($action == 'changecat' && !empty($_POST['feeds'])) |
---|
227 | { |
---|
228 | $feeds_action = 'changecat'; |
---|
229 | } |
---|
230 | |
---|
231 | # Update category for a group of feeds |
---|
232 | if ($action == 'updfeedcat' && !empty($_POST['feeds'])) |
---|
233 | { |
---|
234 | try { |
---|
235 | foreach($_POST['feeds'] as $feed_id) |
---|
236 | { |
---|
237 | $cur = $zc->openCursor(); |
---|
238 | $cur->cat_id = abs((integer) $_POST['upd_cat_id']); |
---|
239 | $zc->updFeed($feed_id,$cur); |
---|
240 | } |
---|
241 | http::redirect($p_url.'&part=feeds&msg=changecat'); |
---|
242 | } |
---|
243 | catch (Exception $e) { |
---|
244 | $core->error->add($e->getMessage()); |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | # Move to right part |
---|
249 | if ( $action == 'changeint' && !empty($_POST['feeds'])) |
---|
250 | { |
---|
251 | $feeds_action = 'changeint'; |
---|
252 | } |
---|
253 | |
---|
254 | # Update interval for a group of feeds |
---|
255 | if ($action == 'updfeedint' && !empty($_POST['feeds'])) |
---|
256 | { |
---|
257 | try { |
---|
258 | foreach($_POST['feeds'] as $feed_id) |
---|
259 | { |
---|
260 | $cur = $zc->openCursor(); |
---|
261 | $cur->feed_upd_int = abs((integer) $_POST['upd_upd_int']); |
---|
262 | $zc->updFeed($feed_id,$cur); |
---|
263 | } |
---|
264 | http::redirect($p_url.'&part=feeds&msg='.$action); |
---|
265 | } |
---|
266 | catch (Exception $e) { |
---|
267 | $core->error->add($e->getMessage()); |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | # Set 0 last update for a group of feeds |
---|
272 | if ($action == 'resetupdlast' && !empty($_POST['feeds'])) |
---|
273 | { |
---|
274 | try { |
---|
275 | foreach($_POST['feeds'] as $feed_id) |
---|
276 | { |
---|
277 | $cur = $zc->openCursor(); |
---|
278 | $cur->feed_upd_last = 0; |
---|
279 | $zc->updFeed($feed_id,$cur); |
---|
280 | } |
---|
281 | http::redirect($p_url.'&part=feeds&msg='.$action); |
---|
282 | } |
---|
283 | catch (Exception $e) { |
---|
284 | $core->error->add($e->getMessage()); |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | # Combos |
---|
289 | $combo_langs = l10n::getISOcodes(true); |
---|
290 | $combo_status = $zc->getAllStatus(); |
---|
291 | $combo_upd_int = $zc->getAllUpdateInterval(); |
---|
292 | $combo_sortby = array( |
---|
293 | __('Date') => 'feed_upddt', |
---|
294 | __('Name') => 'lowername', |
---|
295 | __('frequency') => 'feed_upd_int', |
---|
296 | __('Date of update') => 'feed_upd_last', |
---|
297 | __('Status') => 'feed_status' |
---|
298 | ); |
---|
299 | $combo_order = array( |
---|
300 | __('Descending') => 'desc', |
---|
301 | __('Ascending') => 'asc' |
---|
302 | ); |
---|
303 | |
---|
304 | $combo_feeds_action = array( |
---|
305 | __('change category') => 'changecat', |
---|
306 | __('change update interval') => 'changeint', |
---|
307 | __('disable feed update') => 'disablefeed', |
---|
308 | __('enable feed update') => 'enablefeed', |
---|
309 | __('Reset last update') => 'resetupdlast', |
---|
310 | __('Update (check) feed') => 'updatefeed', |
---|
311 | __('delete related posts') => 'deletepost', |
---|
312 | __('delete feed (without related posts)') => 'deletefeed' |
---|
313 | ); |
---|
314 | $combo_categories = array('-'=>''); |
---|
315 | try |
---|
316 | { |
---|
317 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
318 | } |
---|
319 | catch (Exception $e) |
---|
320 | { |
---|
321 | $core->error->add($e->getMessage()); |
---|
322 | } |
---|
323 | while ($categories->fetch()) |
---|
324 | { |
---|
325 | $combo_categories[str_repeat(' ',$categories->level-1).'• '. |
---|
326 | html::escapeHTML($categories->cat_title)] = $categories->cat_id; |
---|
327 | } |
---|
328 | |
---|
329 | # Prepared lists |
---|
330 | $show_filters = false; |
---|
331 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'feed_upddt'; |
---|
332 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
333 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; |
---|
334 | $nb_per_page = 30; |
---|
335 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) |
---|
336 | { |
---|
337 | if ($nb_per_page != $_GET['nb']) $show_filters = true; |
---|
338 | $nb_per_page = (integer) $_GET['nb']; |
---|
339 | } |
---|
340 | |
---|
341 | $params = array(); |
---|
342 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
343 | |
---|
344 | if ($sortby != '' && in_array($sortby,$combo_sortby)) |
---|
345 | { |
---|
346 | if ($order != '' && in_array($order,$combo_order)) |
---|
347 | { |
---|
348 | $params['order'] = $sortby.' '.$order; |
---|
349 | } |
---|
350 | if ($sortby != 'feed_upddt' || $order != 'desc') |
---|
351 | { |
---|
352 | $show_filters = true; |
---|
353 | } |
---|
354 | } |
---|
355 | |
---|
356 | $pager_base_url = $p_url. |
---|
357 | '&part=feeds'. |
---|
358 | '&sortby='.$sortby. |
---|
359 | '&order='.$order. |
---|
360 | '&nb='.$nb_per_page. |
---|
361 | '&page=%s'; |
---|
362 | |
---|
363 | try |
---|
364 | { |
---|
365 | $feeds = $zc->getFeeds($params); |
---|
366 | $feeds_counter = $zc->getFeeds($params,true)->f(0); |
---|
367 | $feeds_list = new zoneclearFeedServerFeedsList($core,$feeds,$feeds_counter,$pager_base_url); |
---|
368 | } |
---|
369 | catch (Exception $e) |
---|
370 | { |
---|
371 | $core->error->add($e->getMessage()); |
---|
372 | } |
---|
373 | |
---|
374 | if (!$show_filters) |
---|
375 | { |
---|
376 | $header .= dcPage::jsLoad('js/filter-controls.js'); |
---|
377 | } |
---|
378 | |
---|
379 | echo ' |
---|
380 | <html> |
---|
381 | <head><title>'.__('Feeds server').'</title>'.$header. |
---|
382 | dcPage::jsLoad('index.php?pf=zoneclearFeedServer/js/feeds.js'). |
---|
383 | '</head> |
---|
384 | <body> |
---|
385 | <h2>'.html::escapeHTML($core->blog->name). |
---|
386 | ' › '.__('Feeds'). |
---|
387 | ' - <a class="button" href="'.$p_url.'&part=feed">'.__('New feed').'</a>'. |
---|
388 | '</h2>'.$msg; |
---|
389 | |
---|
390 | # Category form |
---|
391 | if ($feeds_action == 'changecat') |
---|
392 | { |
---|
393 | echo ' |
---|
394 | <form method="post" action="'.$p_url.'"> |
---|
395 | <p>'.__('This changes category for all selected feeds.').'</p>'; |
---|
396 | |
---|
397 | foreach($_POST['feeds'] as $feed_id) |
---|
398 | { |
---|
399 | echo |
---|
400 | '<p><label class="classic">'. |
---|
401 | form::checkbox(array('feeds[]'),$feed_id,1).' '. |
---|
402 | $zc->getFeeds(array('feed_id'=>$feed_id))->f('feed_name'). |
---|
403 | '</label></p>'; |
---|
404 | } |
---|
405 | |
---|
406 | echo ' |
---|
407 | <p>'.__('Select a category:').' '. |
---|
408 | form::combo(array('upd_cat_id'),$combo_categories,'').' |
---|
409 | <input type="submit" name="updfeedcat" value="ok" />'. |
---|
410 | form::hidden(array('p'),'zoneclearFeedServer'). |
---|
411 | form::hidden(array('action'),'updfeedcat'). |
---|
412 | form::hidden(array('part'),'feeds'). |
---|
413 | $core->formNonce().' |
---|
414 | </p> |
---|
415 | </form> |
---|
416 | <p><a href="'.$p_url.'&part=feeds">'.__('back').'</a></p>'; |
---|
417 | } |
---|
418 | # Interval form |
---|
419 | elseif ($feeds_action == 'changeint') |
---|
420 | { |
---|
421 | echo ' |
---|
422 | <form method="post" action="'.$p_url.'"> |
---|
423 | <p>'.__('This changes interval of updates for all selected feeds.').'</p>'; |
---|
424 | |
---|
425 | foreach($_POST['feeds'] as $feed_id) |
---|
426 | { |
---|
427 | echo |
---|
428 | '<p><label class="classic">'. |
---|
429 | form::checkbox(array('feeds[]'),$feed_id,1).' '. |
---|
430 | $zc->getFeeds(array('feed_id'=>$feed_id))->f('feed_name'). |
---|
431 | '</label></p>'; |
---|
432 | } |
---|
433 | |
---|
434 | echo ' |
---|
435 | <p>'.__('Select a frequency:').' '. |
---|
436 | form::combo(array('upd_upd_int'),$combo_upd_int,'').' |
---|
437 | <input type="submit" name="updfeedint" value="ok" />'. |
---|
438 | form::hidden(array('p'),'zoneclearFeedServer'). |
---|
439 | form::hidden(array('action'),'updfeedint'). |
---|
440 | form::hidden(array('part'),'feeds'). |
---|
441 | $core->formNonce().' |
---|
442 | </p> |
---|
443 | </form> |
---|
444 | <p><a href="'.$p_url.'&part=feeds">'.__('back').'</a></p>'; |
---|
445 | } |
---|
446 | # Feed list |
---|
447 | else |
---|
448 | { |
---|
449 | if ($core->error->flag()) |
---|
450 | { |
---|
451 | echo '<p>'.__('An error occured when try to get list of feeds').'</p>'; |
---|
452 | } |
---|
453 | else |
---|
454 | { |
---|
455 | if (!$show_filters) |
---|
456 | { |
---|
457 | echo '<p><a id="filter-control" class="form-control" href="#">'. |
---|
458 | __('Filters').'</a></p>'; |
---|
459 | } |
---|
460 | |
---|
461 | echo |
---|
462 | '<form action="'.$p_url.'&part=feeds" method="get" id="filters-form"> |
---|
463 | <fieldset><legend>'.__('Filters').'</legend> |
---|
464 | <div class="three-cols"> |
---|
465 | <div class="col"> |
---|
466 | <label>'.__('Order by:').form::combo('sortby',$combo_sortby,$sortby).'</label> |
---|
467 | </div> |
---|
468 | <div class="col"> |
---|
469 | <label>'.__('Sort:').form::combo('order',$combo_order,$order).'</label> |
---|
470 | </div> |
---|
471 | <div class="col"> |
---|
472 | <p> |
---|
473 | <label class="classic">'. |
---|
474 | form::field('nb',3,3,$nb_per_page).' '.__('Entries per page').' |
---|
475 | </label> |
---|
476 | <input type="submit" value="'.__('filter').'" />'. |
---|
477 | form::hidden(array('p'),'zoneclearFeedServer'). |
---|
478 | form::hidden(array('part'),'feeds').' |
---|
479 | </p> |
---|
480 | </div> |
---|
481 | </div> |
---|
482 | <br class="clear" /> |
---|
483 | </fieldset> |
---|
484 | </form> |
---|
485 | <form action="'.$p_url.'&part=feeds" method="post" id="form-actions">'; |
---|
486 | |
---|
487 | $feeds_list->feedsDisplay($page,$nb_per_page,$pager_base_url); |
---|
488 | |
---|
489 | echo ' |
---|
490 | <div class="two-cols"> |
---|
491 | <p class="col checkboxes-helpers"></p> |
---|
492 | <p class="col right">'.__('Selected feeds action:').' '. |
---|
493 | form::combo(array('action'),$combo_feeds_action).' |
---|
494 | <input type="submit" value="'.__('ok').'" />'. |
---|
495 | form::hidden(array('sortby'),$sortby). |
---|
496 | form::hidden(array('order'),$order). |
---|
497 | form::hidden(array('page'),$page). |
---|
498 | form::hidden(array('nb'),$nb_per_page). |
---|
499 | form::hidden(array('p'),'zoneclearFeedServer'). |
---|
500 | form::hidden(array('part'),'feeds'). |
---|
501 | $core->formNonce().' |
---|
502 | </p> |
---|
503 | </div> |
---|
504 | </form>'; |
---|
505 | } |
---|
506 | } |
---|
507 | |
---|
508 | dcPage::helpBlock('zoneclearFeedServer'); |
---|
509 | echo $footer.'</body></html>'; |
---|
510 | ?> |
---|