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