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