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