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