]>
git.wh0rd.org - tt-rss.git/blob - classes/feeds.php
2 require_once "colors.php";
4 class Feeds
extends Handler_Protected
{
6 function csrf_ignore($method) {
7 $csrf_ignored = array("index");
9 return array_search($method, $csrf_ignored) !== false;
12 private function make_gradient($end, $class) {
13 $start = $class == "even" ?
"#f0f0f0" : "#ffffff";
15 return "style='background: linear-gradient(left , $start 6%, $end 100%);
16 background: -o-linear-gradient(left , $start 6%, $end 100%);
17 background: -moz-linear-gradient(left , $start 6%, $end 100%);
18 background: -webkit-linear-gradient(left , $start 6%, $end 100%);
19 background: -ms-linear-gradient(left , $start 6%, $end 100%);
20 background: -webkit-gradient(linear, left top, right top,
21 color-stop(0.06, $start), color-stop(1, $end));'";
24 private function format_headline_subtoolbar($feed_site_url, $feed_title,
25 $feed_id, $is_cat, $search, $match_on,
26 $search_mode, $view_mode, $error) {
28 $page_prev_link = "viewFeedGoPage(-1)";
29 $page_next_link = "viewFeedGoPage(1)";
30 $page_first_link = "viewFeedGoPage(0)";
32 $catchup_page_link = "catchupPage()";
33 $catchup_feed_link = "catchupCurrentFeed()";
34 $catchup_sel_link = "catchupSelection()";
36 $archive_sel_link = "archiveSelection()";
37 $delete_sel_link = "deleteSelection()";
39 $sel_all_link = "selectArticles('all')";
40 $sel_unread_link = "selectArticles('unread')";
41 $sel_none_link = "selectArticles('none')";
42 $sel_inv_link = "selectArticles('invert')";
44 $tog_unread_link = "selectionToggleUnread()";
45 $tog_marked_link = "selectionToggleMarked()";
46 $tog_published_link = "selectionTogglePublished()";
48 if ($is_cat) $cat_q = "&is_cat=$is_cat";
51 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
56 $rss_link = htmlspecialchars(get_self_url_prefix() .
57 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
61 $reply .= "<span class='r'>";
64 $target = "target=\"_blank\"";
65 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
66 truncate_string($feed_title,30)."</a>";
69 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
73 $reply .= $feed_title;
78 title=\"".__("View as RSS feed")."\"
79 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
80 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
86 $reply .= __('Select:')."
87 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
88 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
89 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
90 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
94 $reply .= "<select dojoType=\"dijit.form.Select\"
95 onchange=\"headlineActionsChange(this)\">";
96 $reply .= "<option value=\"false\">".__('Actions...')."</option>";
98 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
100 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
101 <option value=\"$tog_marked_link\">".__('Starred')."</option>
102 <option value=\"$tog_published_link\">".__('Published')."</option>";
104 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
106 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
108 if ($feed_id != "0") {
109 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
111 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
112 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
116 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
119 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
121 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
123 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
125 $reply .= "</select>";
127 //$reply .= "</div>";
134 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
135 $next_unread_feed, $offset, $vgr_last_feed = false,
136 $override_order = false, $include_children = false) {
138 $disable_cache = false;
142 $timing_info = getmicrotime();
144 $topmost_article_ids = array();
146 if (!$offset) $offset = 0;
147 if ($method == "undefined") $method = "";
149 $method_split = explode(":", $method);
151 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
152 // Update the feed if required with some basic flood control
154 $result = db_query($this->link
,
155 "SELECT ".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
156 FROM ttrss_feeds WHERE id = '$feed'");
158 if (db_num_rows($result) != 0) {
159 $last_updated = strtotime(db_fetch_result($result, 0, "last_updated"));
160 if (time() - $last_updated > 120) {
161 include "rssfuncs.php";
162 update_rss_feed($this->link
, $feed, true, true);
167 if ($method_split[0] == "MarkAllReadGR") {
168 catchup_feed($this->link
, $method_split[1], false);
171 // FIXME: might break tag display?
173 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
174 $result = db_query($this->link
,
175 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
177 if (db_num_rows($result) == 0) {
178 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
182 if (is_numeric($feed) && $feed > 0) {
184 $result = db_query($this->link
, "SELECT rtl_content FROM ttrss_feeds
185 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
187 if (db_num_rows($result) == 1) {
188 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
190 $rtl_content = false;
194 $rtl_tag = "dir=\"RTL\"";
200 $rtl_content = false;
203 @$search = db_escape_string($_REQUEST["query"]);
206 $disable_cache = true;
209 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
210 @$match_on = db_escape_string($_REQUEST["match_on"]);
216 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
218 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
219 if( $search_mode == '' && $method != '' ){
220 $search_mode = $method;
222 // error_log("search_mode: " . $search_mode);
223 $qfh_ret = queryFeedHeadlines($this->link
, $feed, $limit, $view_mode, $cat_view,
224 $search, $search_mode, $match_on, $override_order, $offset, 0,
225 false, 0, $include_children);
227 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
229 $result = $qfh_ret[0];
230 $feed_title = $qfh_ret[1];
231 $feed_site_url = $qfh_ret[2];
232 $last_error = $qfh_ret[3];
234 $vgroup_last_feed = $vgr_last_feed;
238 if (db_num_rows($result) > 0) {
239 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
241 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
246 $headlines_count = db_num_rows($result);
248 if (get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
249 $button_plugins = array();
250 foreach (explode(",", ARTICLE_BUTTON_PLUGINS
) as $p) {
251 $pclass = "button_" . trim($p);
253 if (class_exists($pclass)) {
254 $plugin = new $pclass($link);
255 array_push($button_plugins, $plugin);
260 if (db_num_rows($result) > 0) {
265 $cur_feed_title = '';
267 $fresh_intl = get_pref($this->link
, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
269 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
271 while ($line = db_fetch_assoc($result)) {
272 $class = ($lnum %
2) ?
"even" : "odd";
275 $feed_id = $line["feed_id"];
276 $label_cache = $line["label_cache"];
278 $label_row_style = "";
281 $label_cache = json_decode($label_cache, true);
284 if ($label_cache["no-labels"] == 1)
287 $labels = $label_cache;
291 if (!is_array($labels)) $labels = get_article_labels($this->link
, $id);
293 if (count($labels) > 0) {
294 for ($i = 0; $i < min(4, count($labels)); $i++
) {
295 $bg = rgb2hsl(_color_unpack($labels[$i][3]));
297 if ($bg && $bg[1] > 0) {
301 $bg = _color_pack(hsl2rgb($bg));
302 $label_row_style = $this->make_gradient($bg, $class);;
309 $labels_str = "<span id=\"HLLCTR-$id\">";
310 $labels_str .= format_article_labels($labels, $id);
311 $labels_str .= "</span>";
313 if (count($topmost_article_ids) < 3) {
314 array_push($topmost_article_ids, $id);
317 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
319 $update_pic = "<img id='FUPDPIC-$id' src=\"".
320 theme_image($this->link
, 'images/updated.png')."\"
323 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
327 if (sql_bool_to_bool($line["unread"]) &&
328 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
330 $update_pic = "<img id='FUPDPIC-$id' src=\"".
331 theme_image($this->link
, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
334 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
342 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
343 $marked_pic = "<img id=\"FMPIC-$id\"
344 src=\"".theme_image($this->link
, 'images/mark_set.png')."\"
345 class=\"markedPic\" alt=\"Unstar article\"
346 onclick='javascript:toggleMark($id)'>";
348 $marked_pic = "<img id=\"FMPIC-$id\"
349 src=\"".theme_image($this->link
, 'images/mark_unset.png')."\"
350 class=\"markedPic\" alt=\"Star article\"
351 onclick='javascript:toggleMark($id)'>";
354 if ($line["published"] == "t" ||
$line["published"] == "1") {
355 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
356 'images/pub_set.png')."\"
358 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
360 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
361 'images/pub_unset.png')."\"
363 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
366 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
367 # $line["title"] . "</a>";
369 # $content_link = "<a
370 # href=\"" . htmlspecialchars($line["link"]) . "\"
371 # onclick=\"view($id,$feed_id);\">" .
372 # $line["title"] . "</a>";
374 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
375 # $line["title"] . "</a>";
377 $updated_fmt = make_local_datetime($this->link
, $line["updated_noms"], false);
379 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
380 $content_preview = truncate_string(strip_tags($line["content_preview"]),
384 $score = $line["score"];
386 $score_pic = theme_image($this->link
,
387 "images/" . get_score_pic($score));
389 /* $score_title = __("(Click to change)");
390 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
391 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
393 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
398 } else if ($score < -100) {
404 $entry_author = $line["author"];
407 $entry_author = " - $entry_author";
410 $has_feed_icon = feed_has_icon($feed_id);
412 if ($has_feed_icon) {
413 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
415 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
418 if (!get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
420 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
421 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
423 $cur_feed_title = $line["feed_title"];
424 $vgroup_last_feed = $feed_id;
426 $cur_feed_title = htmlspecialchars($cur_feed_title);
428 $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
430 $reply['content'] .= "<div class='cdmFeedTitle'>".
431 "<div style=\"float : right\">$feed_icon_img</div>".
432 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
433 $line["feed_title"]."</a> $vf_catchup_link</div>";
438 $mouseover_attrs = "onmouseover='postMouseIn($id)'
439 onmouseout='postMouseOut($id)'";
441 $reply['content'] .= "<div class='$class' id='RROW-$id' $label_row_style $mouseover_attrs>";
443 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
445 $reply['content'] .= "<div class='hlLeft'>";
447 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
450 $reply['content'] .= "$marked_pic";
451 $reply['content'] .= "$published_pic";
453 $reply['content'] .= "</div>";
455 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
456 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
457 $reply['content'] .= "<a id=\"RTITLE-$id\"
458 href=\"" . htmlspecialchars($line["link"]) . "\"
460 truncate_string($line["title"], 200);
462 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
463 if ($content_preview) {
464 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
468 $reply['content'] .= "</a></span>";
470 $reply['content'] .= $labels_str;
472 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
473 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
474 if (@$line["feed_title"]) {
475 $reply['content'] .= "<span class=\"hlFeed\">
476 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
477 $line["feed_title"]."</a>)
482 $reply['content'] .= "</div>";
484 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
485 $reply['content'] .= "<div class=\"hlRight\">";
487 $reply['content'] .= $score_pic;
489 if ($line["feed_title"] && !get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
491 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
492 style=\"cursor : pointer\"
493 title=\"".htmlspecialchars($line['feed_title'])."\">
494 $feed_icon_img<span>";
497 $reply['content'] .= "</div>";
498 $reply['content'] .= "</div>";
502 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
503 if ($feed_id != $vgroup_last_feed) {
505 $cur_feed_title = $line["feed_title"];
506 $vgroup_last_feed = $feed_id;
508 $cur_feed_title = htmlspecialchars($cur_feed_title);
510 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
512 $has_feed_icon = feed_has_icon($feed_id);
514 if ($has_feed_icon) {
515 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
517 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
520 $reply['content'] .= "<div class='cdmFeedTitle'>".
521 "<div style=\"float : right\">$feed_icon_img</div>".
522 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
523 $line["feed_title"]."</a> $vf_catchup_link</div>";
527 $expand_cdm = get_pref($this->link
, 'CDM_EXPANDED');
529 $mouseover_attrs = "onmouseover='postMouseIn($id)'
530 onmouseout='postMouseOut($id)'";
532 $reply['content'] .= "<div class=\"$class\" $label_row_style
533 id=\"RROW-$id\" $mouseover_attrs'>";
535 $reply['content'] .= "<div class=\"cdmHeader\">";
537 $reply['content'] .= "<div>";
539 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
540 'RROW-$id')\" id=\"RCHK-$id\"/>";
542 $reply['content'] .= "$marked_pic";
543 $reply['content'] .= "$published_pic";
545 $reply['content'] .= "</div>";
547 $reply['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .
548 htmlspecialchars(strip_tags($line['title'])) . "</div>";
550 $reply['content'] .= "<span id=\"RTITLE-$id\"
551 onclick=\"return cdmClicked(event, $id);\"
552 class=\"titleWrap$hlc_suffix\">
554 title=\"".htmlspecialchars($line['title'])."\"
555 target=\"_blank\" href=\"".
556 htmlspecialchars($line["link"])."\">".
558 " $entry_author</a>";
560 $reply['content'] .= $labels_str;
562 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
563 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
564 if (@$line["feed_title"]) {
565 $reply['content'] .= "<span class=\"hlFeed\">
566 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
567 $line["feed_title"]."</a>)
573 $content_hidden = "style=\"display : none\"";
575 $excerpt_hidden = "style=\"display : none\"";
577 $reply['content'] .= "<span $excerpt_hidden
578 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
580 $reply['content'] .= "</span>";
582 $reply['content'] .= "<div>";
583 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
584 $reply['content'] .= "$score_pic";
586 if (!get_pref($this->link
, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
587 $reply['content'] .= "<span style=\"cursor : pointer\"
588 title=\"".htmlspecialchars($line["feed_title"])."\"
589 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
591 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
592 $reply['content'] .= "</div>";
594 $reply['content'] .= "</div>";
596 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
597 onclick=\"return cdmClicked(event, $id);\"
600 $reply['content'] .= "<div class=\"cdmContentInner\">";
602 if ($line["orig_feed_id"]) {
604 $tmp_result = db_query($this->link
, "SELECT * FROM ttrss_archived_feeds
605 WHERE id = ".$line["orig_feed_id"]);
607 if (db_num_rows($tmp_result) != 0) {
609 $reply['content'] .= "<div clear='both'>";
610 $reply['content'] .= __("Originally from:");
612 $reply['content'] .= " ";
614 $tmp_line = db_fetch_assoc($tmp_result);
616 $reply['content'] .= "<a target='_blank'
617 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
618 $tmp_line['title'] . "</a>";
620 $reply['content'] .= " ";
622 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
623 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";
625 $reply['content'] .= "</div>";
629 # $feed_site_url = $line["site_url"];
630 $article_content = $line["content_preview"];
632 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
634 $reply['content'] .= format_article_note($id, $line['note']);
636 $reply['content'] .= "</div>";
638 $reply['content'] .= "<span id=\"CWRAP-$id\">";
639 $reply['content'] .= $article_content;
640 $reply['content'] .= "</span>";
642 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
643 ttrss_feeds WHERE id = ".
644 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
645 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
647 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
648 0, "always_display_enclosures")); */
650 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
652 $reply['content'] .= format_article_enclosures($this->link
, $id, $always_display_enclosures,
655 $reply['content'] .= "</div>";
657 $reply['content'] .= "<div class=\"cdmFooter\">";
659 $tag_cache = $line["tag_cache"];
661 $tags_str = format_tags_string(
662 get_article_tags($this->link
, $id, $_SESSION["uid"], $tag_cache),
665 $reply['content'] .= "<img src='".theme_image($this->link
,
666 'images/tag.png')."' alt='Tags' title='Tags'>
667 <span id=\"ATSTR-$id\">$tags_str</span>
668 <a title=\"".__('Edit tags for this article')."\"
669 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
671 $num_comments = $line["num_comments"];
672 $entry_comments = "";
674 if ($num_comments > 0) {
675 if ($line["comments"]) {
676 $comments_url = htmlspecialchars($line["comments"]);
678 $comments_url = htmlspecialchars($line["link"]);
680 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
682 if ($line["comments"] && $line["link"] != $line["comments"]) {
683 $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";
687 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
689 $reply['content'] .= "<div style=\"float : right\">";
691 $reply['content'] .= "<img src=\"images/art-zoom.png\"
692 onclick=\"zoomToArticle(event, $id)\"
693 style=\"cursor : pointer\"
695 title='".__('Open article in new tab')."'>";
697 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
699 foreach ($button_plugins as $p) {
700 $reply['content'] .= $p->render($id, $line);
703 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
704 style=\"cursor : pointer\" style=\"cursor : pointer\"
705 onclick=\"dismissArticle($id)\"
706 title='".__('Close article')."'>";
708 $reply['content'] .= "</div>";
709 $reply['content'] .= "</div>";
711 $reply['content'] .= "</div>";
713 $reply['content'] .= "</div>";
720 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
725 switch ($view_mode) {
727 $message = __("No unread articles found to display.");
730 $message = __("No updated articles found to display.");
733 $message = __("No starred articles found to display.");
737 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
739 $message = __("No articles found to display.");
743 if (!$offset && $message) {
744 $reply['content'] .= "<div class='whiteBox'>$message";
746 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
748 $result = db_query($this->link
, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
749 WHERE owner_uid = " . $_SESSION['uid']);
751 $last_updated = db_fetch_result($result, 0, "last_updated");
752 $last_updated = make_local_datetime($this->link
, $last_updated, false);
754 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
756 $result = db_query($this->link
, "SELECT COUNT(id) AS num_errors
757 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
759 $num_errors = db_fetch_result($result, 0, "num_errors");
761 if ($num_errors > 0) {
762 $reply['content'] .= "<br/>";
763 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
764 __('Some feeds have update errors (click for details)')."</a>";
766 $reply['content'] .= "</span></p></div>";
770 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
772 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
773 $vgroup_last_feed, $reply);
776 function catchupAll() {
777 db_query($this->link
, "UPDATE ttrss_user_entries SET
778 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
779 ccache_zero_all($this->link
, $_SESSION["uid"]);
782 function collapse() {
783 $cat_id = db_escape_string($_REQUEST["cid"]);
784 $mode = (int) db_escape_string($_REQUEST['mode']);
785 toggle_collapse_cat($this->link
, $cat_id, $mode);
789 $timing_info = getmicrotime();
793 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
795 $omode = db_escape_string($_REQUEST["omode"]);
797 $feed = db_escape_string($_REQUEST["feed"]);
798 $method = db_escape_string($_REQUEST["m"]);
799 $view_mode = db_escape_string($_REQUEST["view_mode"]);
800 $limit = (int) get_pref($this->link
, "DEFAULT_ARTICLE_LIMIT");
801 @$cat_view = $_REQUEST["cat"] == "true";
802 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
803 @$offset = db_escape_string($_REQUEST["skip"]);
804 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
805 $order_by = db_escape_string($_REQUEST["order_by"]);
807 if (is_numeric($feed)) $feed = (int) $feed;
809 /* Feed -5 is a special case: it is used to display auxiliary information
810 * when there's nothing to load - e.g. no stuff in fresh feed */
813 print json_encode(generate_dashboard_feed($this->link
));
820 $label_feed = -11-$feed;
821 $result = db_query($this->link
, "SELECT id FROM ttrss_labels2 WHERE
822 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
823 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
824 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
825 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
826 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
827 $result = db_query($this->link
, "SELECT id FROM ttrss_feed_categories WHERE
828 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
831 if ($result && db_num_rows($result) == 0) {
832 print json_encode(generate_error_feed($this->link
, __("Feed not found.")));
836 /* Updating a label ccache means recalculating all of the caches
837 * so for performance reasons we don't do that here */
840 ccache_update($this->link
, $feed, $_SESSION["uid"], $cat_view);
843 set_pref($this->link
, "_DEFAULT_VIEW_MODE", $view_mode);
844 set_pref($this->link
, "_DEFAULT_VIEW_LIMIT", $limit);
845 set_pref($this->link
, "_DEFAULT_VIEW_ORDER_BY", $order_by);
847 if (!$cat_view && is_numeric($feed) && $feed > 0) {
848 db_query($this->link
, "UPDATE ttrss_feeds SET last_viewed = NOW()
849 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
852 $reply['headlines'] = array();
854 if (!$next_unread_feed)
855 $reply['headlines']['id'] = $feed;
857 $reply['headlines']['id'] = $next_unread_feed;
859 $reply['headlines']['is_cat'] = (bool) $cat_view;
861 $override_order = false;
863 if (get_pref($this->link
, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
864 $date_sort_field = "updated";
866 $date_sort_field = "date_entered";
871 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
872 $override_order = "$date_sort_field";
874 $override_order = "$date_sort_field DESC";
879 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
880 $override_order = "title DESC, $date_sort_field";
882 $override_order = "title, $date_sort_field DESC";
887 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
888 $override_order = "score, $date_sort_field";
890 $override_order = "score DESC, $date_sort_field DESC";
895 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
897 $ret = $this->format_headlines_list($feed, $method,
898 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
899 $vgroup_last_feed, $override_order, true);
901 $topmost_article_ids = $ret[0];
902 $headlines_count = $ret[1];
903 $returned_feed = $ret[2];
904 $disable_cache = $ret[3];
905 $vgroup_last_feed = $ret[4];
907 $reply['headlines']['content'] =& $ret[5]['content'];
908 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
910 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
912 $reply['headlines-info'] = array("count" => (int) $headlines_count,
913 "vgroup_last_feed" => $vgroup_last_feed,
914 "disable_cache" => (bool) $disable_cache);
916 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
918 if (is_array($topmost_article_ids) && !get_pref($this->link
, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
921 foreach ($topmost_article_ids as $id) {
922 array_push($articles, format_article($this->link
, $id, false));
925 $reply['articles'] = $articles;
928 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
930 $reply['runtime-info'] = make_runtime_info($this->link
);
932 print json_encode($reply);