]> git.wh0rd.org - tt-rss.git/blame - classes/feeds.php
rework class system to use subdirectories
[tt-rss.git] / classes / feeds.php
CommitLineData
3f363052 1<?php\r
369dbc19 2class Feeds extends Handler_Protected {\r
46da73c2 3\r
8484ce22
AD
4 function csrf_ignore($method) {\r
5 $csrf_ignored = array("index");\r
6\r
7 return array_search($method, $csrf_ignored) !== false;\r
8 }\r
9\r
79178062
AD
10 private function format_headline_subtoolbar($feed_site_url, $feed_title,\r
11 $feed_id, $is_cat, $search, $match_on,\r
12 $search_mode, $view_mode, $error) {\r
13\r
14 $page_prev_link = "viewFeedGoPage(-1)";\r
15 $page_next_link = "viewFeedGoPage(1)";\r
16 $page_first_link = "viewFeedGoPage(0)";\r
17\r
18 $catchup_page_link = "catchupPage()";\r
19 $catchup_feed_link = "catchupCurrentFeed()";\r
20 $catchup_sel_link = "catchupSelection()";\r
21\r
22 $archive_sel_link = "archiveSelection()";\r
23 $delete_sel_link = "deleteSelection()";\r
24\r
25 $sel_all_link = "selectArticles('all')";\r
26 $sel_unread_link = "selectArticles('unread')";\r
27 $sel_none_link = "selectArticles('none')";\r
28 $sel_inv_link = "selectArticles('invert')";\r
29\r
30 $tog_unread_link = "selectionToggleUnread()";\r
31 $tog_marked_link = "selectionToggleMarked()";\r
32 $tog_published_link = "selectionTogglePublished()";\r
33\r
f1080825
AD
34 if ($is_cat) $cat_q = "&is_cat=$is_cat";\r
35\r
36 if ($search) {\r
37 $search_q = "&q=$search&m=$match_on&smode=$search_mode";\r
38 } else {\r
39 $search_q = "";\r
40 }\r
41\r
42 $rss_link = htmlspecialchars(get_self_url_prefix() .\r
43 "/public.php?op=rss&id=$feed_id$cat_q$search_q");\r
44\r
45 // right part\r
46\r
47 $reply .= "<span class='r'>";\r
48\r
49 if ($feed_site_url) {\r
50 $target = "target=\"_blank\"";\r
51 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".\r
52 truncate_string($feed_title,30)."</a>";\r
53\r
54 if ($error) {\r
55 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";\r
56 }\r
57\r
58 } else {\r
59 $reply .= $feed_title;\r
60 }\r
61\r
62 $reply .= "\r
63 <a href=\"#\"\r
64 title=\"".__("View as RSS feed")."\"\r
65 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">\r
66 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";\r
67\r
68 $reply .= "</span>";\r
69\r
70 // left part\r
79178062
AD
71\r
72 $reply .= __('Select:')."\r
73 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,\r
74 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,\r
75 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,\r
76 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";\r
77\r
78 $reply .= " ";\r
79\r
80 $reply .= "<select dojoType=\"dijit.form.Select\"\r
81 onchange=\"headlineActionsChange(this)\">";\r
82 $reply .= "<option value=\"false\">".__('Actions...')."</option>";\r
83\r
84 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";\r
85\r
86 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>\r
87 <option value=\"$tog_marked_link\">".__('Starred')."</option>\r
88 <option value=\"$tog_published_link\">".__('Published')."</option>";\r
89\r
90 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";\r
91\r
92 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";\r
93\r
94 if ($feed_id != "0") {\r
95 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";\r
96 } else {\r
97 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";\r
98 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";\r
99\r
100 }\r
101\r
102 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').\r
103 "</option>";\r
104\r
79178062
AD
105 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";\r
106\r
107 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";\r
108\r
109 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";\r
110\r
111 $reply .= "</select>";\r
112\r
f1080825 113 //$reply .= "</div>";\r
79178062 114\r
f1080825 115 //$reply .= "</h2";\r
79178062
AD
116\r
117 return $reply;\r
118 }\r
119\r
120 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,\r
121 $next_unread_feed, $offset, $vgr_last_feed = false,\r
09101297 122 $override_order = false, $include_children = false) {\r
79178062 123\r
369dbc19
AD
124 global $plugins;\r
125\r
79178062
AD
126 $disable_cache = false;\r
127\r
128 $reply = array();\r
129\r
130 $timing_info = getmicrotime();\r
131\r
132 $topmost_article_ids = array();\r
133\r
134 if (!$offset) $offset = 0;\r
135 if ($method == "undefined") $method = "";\r
136\r
137 $method_split = explode(":", $method);\r
138\r
3c696512
AD
139 if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {\r
140 include "rssfuncs.php";\r
141 update_rss_feed($this->link, $feed, true);\r
142 }\r
79178062 143\r
79178062
AD
144 if ($method_split[0] == "MarkAllReadGR") {\r
145 catchup_feed($this->link, $method_split[1], false);\r
146 }\r
147\r
148 // FIXME: might break tag display?\r
149\r
150 if (is_numeric($feed) && $feed > 0 && !$cat_view) {\r
151 $result = db_query($this->link,\r
152 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");\r
153\r
154 if (db_num_rows($result) == 0) {\r
155 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";\r
156 }\r
157 }\r
158\r
159 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {\r
160\r
161 $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds\r
162 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);\r
163\r
164 if (db_num_rows($result) == 1) {\r
165 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));\r
166 } else {\r
167 $rtl_content = false;\r
168 }\r
169\r
170 if ($rtl_content) {\r
171 $rtl_tag = "dir=\"RTL\"";\r
172 } else {\r
173 $rtl_tag = "";\r
174 }\r
175 } else {\r
176 $rtl_tag = "";\r
177 $rtl_content = false;\r
178 }\r
179\r
180 @$search = db_escape_string($_REQUEST["query"]);\r
181\r
182 if ($search) {\r
183 $disable_cache = true;\r
184 }\r
185\r
186 @$search_mode = db_escape_string($_REQUEST["search_mode"]);\r
187 @$match_on = db_escape_string($_REQUEST["match_on"]);\r
188\r
189 if (!$match_on) {\r
190 $match_on = "both";\r
191 }\r
192\r
193 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);\r
194\r
195// error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");\r
196 if( $search_mode == '' && $method != '' ){\r
197 $search_mode = $method;\r
198 }\r
199// error_log("search_mode: " . $search_mode);\r
200 $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,\r
09101297
AD
201 $search, $search_mode, $match_on, $override_order, $offset, 0,\r
202 false, 0, $include_children);\r
79178062
AD
203\r
204 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);\r
205\r
206 $result = $qfh_ret[0];\r
207 $feed_title = $qfh_ret[1];\r
208 $feed_site_url = $qfh_ret[2];\r
209 $last_error = $qfh_ret[3];\r
210\r
211 $vgroup_last_feed = $vgr_last_feed;\r
212\r
213// if (!$offset) {\r
214\r
215 if (db_num_rows($result) > 0) {\r
216 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,\r
217 $feed_title,\r
218 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,\r
219 $last_error);\r
220 }\r
221// }\r
222\r
223 $headlines_count = db_num_rows($result);\r
224\r
369dbc19
AD
225 $plugins->hook('headlines_before', $reply);\r
226\r
1baac280
AD
227 if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {\r
228 $button_plugins = array();\r
229 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {\r
369dbc19 230 $pclass = trim("button_${p}");\r
1baac280
AD
231\r
232 if (class_exists($pclass)) {\r
233 $plugin = new $pclass($link);\r
234 array_push($button_plugins, $plugin);\r
235 }\r
236 }\r
237 }\r
238\r
79178062
AD
239 if (db_num_rows($result) > 0) {\r
240\r
241 $lnum = $offset;\r
242\r
243 $num_unread = 0;\r
244 $cur_feed_title = '';\r
245\r
246 $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;\r
247\r
248 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);\r
249\r
250 while ($line = db_fetch_assoc($result)) {\r
251\r
369dbc19
AD
252 if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {\r
253 $plugins->hook('cdm_article_before', $line);\r
254 } else {\r
255 $plugins->hook('headlines_row', $line);\r
256 }\r
257\r
79178062
AD
258 $class = ($lnum % 2) ? "even" : "odd";\r
259\r
260 $id = $line["id"];\r
261 $feed_id = $line["feed_id"];\r
262 $label_cache = $line["label_cache"];\r
263 $labels = false;\r
264\r
265 if ($label_cache) {\r
266 $label_cache = json_decode($label_cache, true);\r
267\r
268 if ($label_cache) {\r
269 if ($label_cache["no-labels"] == 1)\r
270 $labels = array();\r
271 else\r
272 $labels = $label_cache;\r
273 }\r
274 }\r
275\r
276 if (!is_array($labels)) $labels = get_article_labels($this->link, $id);\r
277\r
278 $labels_str = "<span id=\"HLLCTR-$id\">";\r
279 $labels_str .= format_article_labels($labels, $id);\r
280 $labels_str .= "</span>";\r
281\r
282 if (count($topmost_article_ids) < 3) {\r
283 array_push($topmost_article_ids, $id);\r
284 }\r
285\r
286 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {\r
287\r
288 $update_pic = "<img id='FUPDPIC-$id' src=\"".\r
289 theme_image($this->link, 'images/updated.png')."\"\r
290 alt=\"Updated\">";\r
291 } else {\r
292 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"\r
293 alt=\"Updated\">";\r
294 }\r
295\r
296 if (sql_bool_to_bool($line["unread"]) &&\r
297 time() - strtotime($line["updated_noms"]) < $fresh_intl) {\r
298\r
299 $update_pic = "<img id='FUPDPIC-$id' src=\"".\r
300 theme_image($this->link, 'images/fresh_sign.png')."\" alt=\"Fresh\">";\r
301 }\r
302\r
303 if ($line["unread"] == "t" || $line["unread"] == "1") {\r
304 $class .= " Unread";\r
305 ++$num_unread;\r
306 $is_unread = true;\r
307 } else {\r
308 $is_unread = false;\r
309 }\r
310\r
311 if ($line["marked"] == "t" || $line["marked"] == "1") {\r
312 $marked_pic = "<img id=\"FMPIC-$id\"\r
313 src=\"".theme_image($this->link, 'images/mark_set.png')."\"\r
314 class=\"markedPic\" alt=\"Unstar article\"\r
315 onclick='javascript:toggleMark($id)'>";\r
316 } else {\r
317 $marked_pic = "<img id=\"FMPIC-$id\"\r
318 src=\"".theme_image($this->link, 'images/mark_unset.png')."\"\r
319 class=\"markedPic\" alt=\"Star article\"\r
320 onclick='javascript:toggleMark($id)'>";\r
321 }\r
322\r
323 if ($line["published"] == "t" || $line["published"] == "1") {\r
324 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,\r
325 'images/pub_set.png')."\"\r
326 class=\"markedPic\"\r
327 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";\r
328 } else {\r
329 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,\r
330 'images/pub_unset.png')."\"\r
331 class=\"markedPic\"\r
332 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";\r
333 }\r
334\r
335# $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .\r
336# $line["title"] . "</a>";\r
337\r
338# $content_link = "<a\r
339# href=\"" . htmlspecialchars($line["link"]) . "\"\r
340# onclick=\"view($id,$feed_id);\">" .\r
341# $line["title"] . "</a>";\r
342\r
343# $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .\r
344# $line["title"] . "</a>";\r
345\r
346 $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);\r
347\r
348 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {\r
d3253f49
AD
349 $content_preview = truncate_string(strip_tags($line["content_preview"]),\r
350 100);\r
79178062
AD
351 }\r
352\r
353 $score = $line["score"];\r
354\r
355 $score_pic = theme_image($this->link,\r
356 "images/" . get_score_pic($score));\r
357\r
358/* $score_title = __("(Click to change)");\r
359 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"\r
360 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */\r
361\r
362 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"\r
363 title=\"$score\">";\r
364\r
365 if ($score > 500) {\r
366 $hlc_suffix = "H";\r
367 } else if ($score < -100) {\r
368 $hlc_suffix = "L";\r
369 } else {\r
370 $hlc_suffix = "";\r
371 }\r
372\r
373 $entry_author = $line["author"];\r
374\r
375 if ($entry_author) {\r
376 $entry_author = " - $entry_author";\r
377 }\r
378\r
379 $has_feed_icon = feed_has_icon($feed_id);\r
380\r
381 if ($has_feed_icon) {\r
382 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";\r
383 } else {\r
384 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";\r
385 }\r
386\r
387 if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {\r
388\r
389 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {\r
390 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {\r
391\r
392 $cur_feed_title = $line["feed_title"];\r
393 $vgroup_last_feed = $feed_id;\r
394\r
395 $cur_feed_title = htmlspecialchars($cur_feed_title);\r
396\r
44245618 397 $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";\r
79178062
AD
398\r
399 $reply['content'] .= "<div class='cdmFeedTitle'>".\r
400 "<div style=\"float : right\">$feed_icon_img</div>".\r
401 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
402 $line["feed_title"]."</a> $vf_catchup_link</div>";\r
403\r
404 }\r
405 }\r
406\r
407 $mouseover_attrs = "onmouseover='postMouseIn($id)'\r
408 onmouseout='postMouseOut($id)'";\r
409\r
410 $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";\r
411\r
412 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";\r
413\r
414 $reply['content'] .= "<div class='hlLeft'>";\r
415\r
416 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"\r
417 id=\"RCHK-$id\">";\r
418\r
419 $reply['content'] .= "$marked_pic";\r
420 $reply['content'] .= "$published_pic";\r
421\r
422 $reply['content'] .= "</div>";\r
423\r
424 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'\r
425 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";\r
426 $reply['content'] .= "<a id=\"RTITLE-$id\"\r
427 href=\"" . htmlspecialchars($line["link"]) . "\"\r
428 onclick=\"\">" .\r
d3253f49 429 truncate_string($line["title"], 200);\r
79178062
AD
430\r
431 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {\r
432 if ($content_preview) {\r
433 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";\r
434 }\r
435 }\r
436\r
437 $reply['content'] .= "</a></span>";\r
438\r
439 $reply['content'] .= $labels_str;\r
440\r
441 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&\r
442 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {\r
443 if (@$line["feed_title"]) {\r
444 $reply['content'] .= "<span class=\"hlFeed\">\r
445 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
446 $line["feed_title"]."</a>)\r
447 </span>";\r
448 }\r
449 }\r
450\r
451 $reply['content'] .= "</div>";\r
452\r
453 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";\r
454 $reply['content'] .= "<div class=\"hlRight\">";\r
455\r
456 $reply['content'] .= $score_pic;\r
457\r
458 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {\r
459\r
460 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"\r
461 style=\"cursor : pointer\"\r
462 title=\"".htmlspecialchars($line['feed_title'])."\">\r
463 $feed_icon_img<span>";\r
464 }\r
465\r
466 $reply['content'] .= "</div>";\r
467 $reply['content'] .= "</div>";\r
468\r
469 } else {\r
470\r
471 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {\r
472 if ($feed_id != $vgroup_last_feed) {\r
473\r
474 $cur_feed_title = $line["feed_title"];\r
475 $vgroup_last_feed = $feed_id;\r
476\r
477 $cur_feed_title = htmlspecialchars($cur_feed_title);\r
478\r
479 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";\r
480\r
481 $has_feed_icon = feed_has_icon($feed_id);\r
482\r
483 if ($has_feed_icon) {\r
484 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";\r
485 } else {\r
486 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";\r
487 }\r
488\r
489 $reply['content'] .= "<div class='cdmFeedTitle'>".\r
490 "<div style=\"float : right\">$feed_icon_img</div>".\r
491 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
492 $line["feed_title"]."</a> $vf_catchup_link</div>";\r
493 }\r
494 }\r
495\r
496 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');\r
497\r
498 $mouseover_attrs = "onmouseover='postMouseIn($id)'\r
499 onmouseout='postMouseOut($id)'";\r
500\r
501 $reply['content'] .= "<div class=\"$class\"\r
502 id=\"RROW-$id\" $mouseover_attrs'>";\r
503\r
504 $reply['content'] .= "<div class=\"cdmHeader\">";\r
505\r
506 $reply['content'] .= "<div>";\r
507\r
508 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,\r
509 'RROW-$id')\" id=\"RCHK-$id\"/>";\r
510\r
511 $reply['content'] .= "$marked_pic";\r
512 $reply['content'] .= "$published_pic";\r
513\r
514 $reply['content'] .= "</div>";\r
515\r
aa8b48a0
AD
516 $reply['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .\r
517 strip_tags($line['title']) . "</div>";\r
518\r
79178062
AD
519 $reply['content'] .= "<span id=\"RTITLE-$id\"\r
520 onclick=\"return cdmClicked(event, $id);\"\r
521 class=\"titleWrap$hlc_suffix\">\r
522 <a class=\"title\"\r
523 title=\"".htmlspecialchars($line['title'])."\"\r
524 target=\"_blank\" href=\"".\r
525 htmlspecialchars($line["link"])."\">".\r
526 truncate_string($line["title"], 100) .\r
527 " $entry_author</a>";\r
528\r
529 $reply['content'] .= $labels_str;\r
530\r
531 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&\r
532 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {\r
533 if (@$line["feed_title"]) {\r
534 $reply['content'] .= "<span class=\"hlFeed\">\r
535 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
536 $line["feed_title"]."</a>)\r
537 </span>";\r
538 }\r
539 }\r
540\r
541 if (!$expand_cdm)\r
542 $content_hidden = "style=\"display : none\"";\r
543 else\r
544 $excerpt_hidden = "style=\"display : none\"";\r
545\r
546 $reply['content'] .= "<span $excerpt_hidden\r
547 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";\r
548\r
549 $reply['content'] .= "</span>";\r
550\r
551 $reply['content'] .= "<div>";\r
552 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";\r
553 $reply['content'] .= "$score_pic";\r
554\r
555 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {\r
556 $reply['content'] .= "<span style=\"cursor : pointer\"\r
557 title=\"".htmlspecialchars($line["feed_title"])."\"\r
558 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";\r
559 }\r
560 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";\r
561 $reply['content'] .= "</div>";\r
562\r
563 $reply['content'] .= "</div>";\r
564\r
565 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden\r
566 onclick=\"return cdmClicked(event, $id);\"\r
567 id=\"CICD-$id\">";\r
568\r
569 $reply['content'] .= "<div class=\"cdmContentInner\">";\r
570\r
571 if ($line["orig_feed_id"]) {\r
572\r
573 $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds\r
574 WHERE id = ".$line["orig_feed_id"]);\r
575\r
576 if (db_num_rows($tmp_result) != 0) {\r
577\r
578 $reply['content'] .= "<div clear='both'>";\r
579 $reply['content'] .= __("Originally from:");\r
580\r
581 $reply['content'] .= "&nbsp;";\r
582\r
583 $tmp_line = db_fetch_assoc($tmp_result);\r
584\r
585 $reply['content'] .= "<a target='_blank'\r
586 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .\r
587 $tmp_line['title'] . "</a>";\r
588\r
589 $reply['content'] .= "&nbsp;";\r
590\r
591 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";\r
11cb9506 592 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";\r
79178062
AD
593\r
594 $reply['content'] .= "</div>";\r
595 }\r
596 }\r
597\r
598 $feed_site_url = $line["site_url"];\r
599\r
600 $article_content = sanitize($this->link, $line["content_preview"],\r
601 false, false, $feed_site_url);\r
602\r
603 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";\r
604 if ($line['note']) {\r
605 $reply['content'] .= format_article_note($id, $line['note']);\r
606 }\r
607 $reply['content'] .= "</div>";\r
608\r
609 $reply['content'] .= "<span id=\"CWRAP-$id\">";\r
610 $reply['content'] .= $expand_cdm ? $article_content : '';\r
611 $reply['content'] .= "</span>";\r
612\r
613/* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM\r
614 ttrss_feeds WHERE id = ".\r
615 (($line['feed_id'] == null) ? $line['orig_feed_id'] :\r
616 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);\r
617\r
618 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,\r
619 0, "always_display_enclosures")); */\r
620\r
621 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);\r
622\r
623 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,\r
624 $article_content);\r
625\r
626 $reply['content'] .= "</div>";\r
627\r
628 $reply['content'] .= "<div class=\"cdmFooter\">";\r
629\r
630 $tag_cache = $line["tag_cache"];\r
631\r
632 $tags_str = format_tags_string(\r
633 get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),\r
634 $id);\r
635\r
636 $reply['content'] .= "<img src='".theme_image($this->link,\r
637 'images/tag.png')."' alt='Tags' title='Tags'>\r
638 <span id=\"ATSTR-$id\">$tags_str</span>\r
639 <a title=\"".__('Edit tags for this article')."\"\r
640 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";\r
641\r
642 $num_comments = $line["num_comments"];\r
643 $entry_comments = "";\r
644\r
645 if ($num_comments > 0) {\r
646 if ($line["comments"]) {\r
647 $comments_url = $line["comments"];\r
648 } else {\r
649 $comments_url = $line["link"];\r
650 }\r
651 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";\r
652 } else {\r
653 if ($line["comments"] && $line["link"] != $line["comments"]) {\r
654 $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";\r
655 }\r
656 }\r
657\r
658 if ($entry_comments) $reply['content'] .= "&nbsp;($entry_comments)";\r
659\r
660 $reply['content'] .= "<div style=\"float : right\">";\r
661\r
662 $reply['content'] .= "<img src=\"images/art-zoom.png\"\r
663 onclick=\"zoomToArticle(event, $id)\"\r
664 style=\"cursor : pointer\"\r
665 alt='Zoom'\r
666 title='".__('Open article in new tab')."'>";\r
667\r
668 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);\r
669\r
f9ac31d6 670 foreach ($button_plugins as $p) {\r
1baac280 671 $reply['content'] .= $p->render($id, $line);\r
79178062
AD
672 }\r
673\r
79178062
AD
674 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"\r
675 style=\"cursor : pointer\" style=\"cursor : pointer\"\r
676 onclick=\"dismissArticle($id)\"\r
638e27c8 677 title='".__('Close article')."'>";\r
79178062
AD
678\r
679 $reply['content'] .= "</div>";\r
680 $reply['content'] .= "</div>";\r
681\r
682 $reply['content'] .= "</div>";\r
683\r
684 $reply['content'] .= "</div>";\r
685\r
369dbc19
AD
686 $plugins->hook('cdm_article_after', $reply['content']);\r
687\r
79178062
AD
688 }\r
689\r
690 ++$lnum;\r
691 }\r
692\r
369dbc19
AD
693 $plugins->hook('headlines_after', $reply);\r
694\r
79178062
AD
695 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);\r
696\r
697 } else {\r
698 $message = "";\r
699\r
700 switch ($view_mode) {\r
701 case "unread":\r
702 $message = __("No unread articles found to display.");\r
703 break;\r
704 case "updated":\r
705 $message = __("No updated articles found to display.");\r
706 break;\r
707 case "marked":\r
708 $message = __("No starred articles found to display.");\r
709 break;\r
710 default:\r
711 if ($feed < -10) {\r
712 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");\r
713 } else {\r
714 $message = __("No articles found to display.");\r
715 }\r
716 }\r
717\r
718 if (!$offset && $message) {\r
719 $reply['content'] .= "<div class='whiteBox'>$message";\r
720\r
721 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";\r
722\r
723 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds\r
724 WHERE owner_uid = " . $_SESSION['uid']);\r
725\r
726 $last_updated = db_fetch_result($result, 0, "last_updated");\r
727 $last_updated = make_local_datetime($this->link, $last_updated, false);\r
728\r
729 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);\r
730\r
731 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors\r
732 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);\r
733\r
734 $num_errors = db_fetch_result($result, 0, "num_errors");\r
735\r
736 if ($num_errors > 0) {\r
737 $reply['content'] .= "<br/>";\r
738 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".\r
739 __('Some feeds have update errors (click for details)')."</a>";\r
740 }\r
741 $reply['content'] .= "</span></p></div>";\r
742 }\r
743 }\r
744\r
745 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);\r
746\r
747 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,\r
748 $vgroup_last_feed, $reply);\r
749 }\r
750\r
3f363052
AD
751 function catchupAll() {\r
752 db_query($this->link, "UPDATE ttrss_user_entries SET\r
753 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);\r
754 ccache_zero_all($this->link, $_SESSION["uid"]);\r
46da73c2 755 }\r
3f363052
AD
756\r
757 function collapse() {\r
758 $cat_id = db_escape_string($_REQUEST["cid"]);\r
759 $mode = (int) db_escape_string($_REQUEST['mode']);\r
760 toggle_collapse_cat($this->link, $cat_id, $mode);\r
761 }\r
762\r
3f363052
AD
763 function view() {\r
764 $timing_info = getmicrotime();\r
46da73c2 765\r
3f363052 766 $reply = array();\r
46da73c2 767\r
3f363052 768 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);\r
46da73c2 769\r
3f363052 770 $omode = db_escape_string($_REQUEST["omode"]);\r
46da73c2 771\r
3f363052
AD
772 $feed = db_escape_string($_REQUEST["feed"]);\r
773 $method = db_escape_string($_REQUEST["m"]);\r
774 $view_mode = db_escape_string($_REQUEST["view_mode"]);\r
775 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");\r
09101297 776 @$cat_view = $_REQUEST["cat"] == "true";\r
3f363052
AD
777 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);\r
778 @$offset = db_escape_string($_REQUEST["skip"]);\r
779 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);\r
780 $order_by = db_escape_string($_REQUEST["order_by"]);\r
854a2ace 781 $include_children = $_REQUEST["include_children"] == "true";\r
46da73c2 782\r
3f363052 783 if (is_numeric($feed)) $feed = (int) $feed;\r
46da73c2 784\r
3f363052
AD
785 /* Feed -5 is a special case: it is used to display auxiliary information\r
786 * when there's nothing to load - e.g. no stuff in fresh feed */\r
46da73c2 787\r
3f363052
AD
788 if ($feed == -5) {\r
789 print json_encode(generate_dashboard_feed($this->link));\r
790 return;\r
791 }\r
46da73c2 792\r
3f363052 793 $result = false;\r
46da73c2 794\r
3f363052
AD
795 if ($feed < -10) {\r
796 $label_feed = -11-$feed;\r
797 $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE\r
798 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);\r
799 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {\r
800 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE\r
801 id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r
802 } else if ($cat_view && is_numeric($feed) && $feed > 0) {\r
803 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE\r
804 id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r
805 }\r
46da73c2 806\r
3f363052
AD
807 if ($result && db_num_rows($result) == 0) {\r
808 print json_encode(generate_error_feed($this->link, __("Feed not found.")));\r
809 return;\r
810 }\r
46da73c2 811\r
3f363052
AD
812 /* Updating a label ccache means recalculating all of the caches\r
813 * so for performance reasons we don't do that here */\r
46da73c2 814\r
3f363052
AD
815 if ($feed >= 0) {\r
816 ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);\r
817 }\r
46da73c2 818\r
3f363052
AD
819 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);\r
820 set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);\r
821 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);\r
e07f8981 822 set_pref($this->link, "_DEFAULT_INCLUDE_CHILDREN", $include_children);\r
854a2ace 823\r
3f363052
AD
824 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {\r
825 db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()\r
826 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);\r
827 }\r
46da73c2 828\r
3f363052 829 $reply['headlines'] = array();\r
46da73c2 830\r
3f363052
AD
831 if (!$next_unread_feed)\r
832 $reply['headlines']['id'] = $feed;\r
833 else\r
834 $reply['headlines']['id'] = $next_unread_feed;\r
46da73c2 835\r
3f363052 836 $reply['headlines']['is_cat'] = (bool) $cat_view;\r
46da73c2 837\r
3f363052 838 $override_order = false;\r
46da73c2 839\r
3f363052
AD
840 if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {\r
841 $date_sort_field = "updated";\r
842 } else {\r
843 $date_sort_field = "date_entered";\r
844 }\r
46da73c2 845\r
3f363052
AD
846 switch ($order_by) {\r
847 case "date":\r
848 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
849 $override_order = "$date_sort_field";\r
850 } else {\r
851 $override_order = "$date_sort_field DESC";\r
852 }\r
853 break;\r
46da73c2 854\r
3f363052
AD
855 case "title":\r
856 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
857 $override_order = "title DESC, $date_sort_field";\r
858 } else {\r
859 $override_order = "title, $date_sort_field DESC";\r
860 }\r
861 break;\r
46da73c2 862\r
3f363052
AD
863 case "score":\r
864 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
865 $override_order = "score, $date_sort_field";\r
866 } else {\r
867 $override_order = "score DESC, $date_sort_field DESC";\r
868 }\r
869 break;\r
870 }\r
46da73c2 871\r
3f363052 872 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);\r
46da73c2 873\r
79178062 874 $ret = $this->format_headlines_list($feed, $method,\r
3f363052 875 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,\r
09101297 876 $vgroup_last_feed, $override_order, $include_children);\r
46da73c2 877\r
3f363052
AD
878 $topmost_article_ids = $ret[0];\r
879 $headlines_count = $ret[1];\r
880 $returned_feed = $ret[2];\r
881 $disable_cache = $ret[3];\r
882 $vgroup_last_feed = $ret[4];\r
46da73c2 883\r
3f363052
AD
884 $reply['headlines']['content'] =& $ret[5]['content'];\r
885 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];\r
46da73c2 886\r
3f363052 887 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);\r
46da73c2 888\r
3f363052
AD
889 $reply['headlines-info'] = array("count" => (int) $headlines_count,\r
890 "vgroup_last_feed" => $vgroup_last_feed,\r
891 "disable_cache" => (bool) $disable_cache);\r
46da73c2 892\r
3f363052 893 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);\r
46da73c2 894\r
3f363052
AD
895 if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {\r
896 $articles = array();\r
46da73c2 897\r
3f363052
AD
898 foreach ($topmost_article_ids as $id) {\r
899 array_push($articles, format_article($this->link, $id, false));\r
900 }\r
46da73c2 901\r
3f363052
AD
902 $reply['articles'] = $articles;\r
903 }\r
46da73c2 904\r
3f363052 905 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);\r
46da73c2 906\r
3f363052 907 $reply['runtime-info'] = make_runtime_info($this->link);\r
46da73c2 908\r
3f363052 909 print json_encode($reply);\r
46da73c2 910\r
3f363052
AD
911 }\r
912}\r
46da73c2 913?>\r