]>
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 format_headline_subtoolbar($feed_site_url, $feed_title,
13 $feed_id, $is_cat, $search, $match_on,
14 $search_mode, $view_mode, $error) {
16 $page_prev_link = "viewFeedGoPage(-1)";
17 $page_next_link = "viewFeedGoPage(1)";
18 $page_first_link = "viewFeedGoPage(0)";
20 $catchup_page_link = "catchupPage()";
21 $catchup_feed_link = "catchupCurrentFeed()";
22 $catchup_sel_link = "catchupSelection()";
24 $archive_sel_link = "archiveSelection()";
25 $delete_sel_link = "deleteSelection()";
27 $sel_all_link = "selectArticles('all')";
28 $sel_unread_link = "selectArticles('unread')";
29 $sel_none_link = "selectArticles('none')";
30 $sel_inv_link = "selectArticles('invert')";
32 $tog_unread_link = "selectionToggleUnread()";
33 $tog_marked_link = "selectionToggleMarked()";
34 $tog_published_link = "selectionTogglePublished()";
36 if ($is_cat) $cat_q = "&is_cat=$is_cat";
39 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
44 $rss_link = htmlspecialchars(get_self_url_prefix() .
45 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
49 $reply .= "<span class='r'>";
52 $target = "target=\"_blank\"";
53 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
54 truncate_string($feed_title,30)."</a>";
57 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
61 $reply .= $feed_title;
66 title=\"".__("View as RSS feed")."\"
67 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
68 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
74 $reply .= __('Select:')."
75 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
76 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
77 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
78 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
82 $reply .= "<select dojoType=\"dijit.form.Select\"
83 onchange=\"headlineActionsChange(this)\">";
84 $reply .= "<option value=\"false\">".__('Actions...')."</option>";
86 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
88 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
89 <option value=\"$tog_marked_link\">".__('Starred')."</option>
90 <option value=\"$tog_published_link\">".__('Published')."</option>";
92 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
94 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
96 if ($feed_id != "0") {
97 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
99 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
100 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
104 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
107 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
109 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
111 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
113 $reply .= "</select>";
115 //$reply .= "</div>";
122 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
123 $next_unread_feed, $offset, $vgr_last_feed = false,
124 $override_order = false, $include_children = false) {
126 $disable_cache = false;
130 $timing_info = getmicrotime();
132 $topmost_article_ids = array();
134 if (!$offset) $offset = 0;
135 if ($method == "undefined") $method = "";
137 $method_split = explode(":", $method);
139 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
140 // Update the feed if required with some basic flood control
142 $result = db_query($this->link
,
143 "SELECT ".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
144 FROM ttrss_feeds WHERE id = '$feed'");
146 if (db_num_rows($result) != 0) {
147 $last_updated = strtotime(db_fetch_result($result, 0, "last_updated"));
148 if (time() - $last_updated > 120) {
149 include "rssfuncs.php";
150 update_rss_feed($this->link
, $feed, true, true);
155 if ($method_split[0] == "MarkAllReadGR") {
156 catchup_feed($this->link
, $method_split[1], false);
159 // FIXME: might break tag display?
161 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
162 $result = db_query($this->link
,
163 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
165 if (db_num_rows($result) == 0) {
166 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
170 if (is_numeric($feed) && $feed > 0) {
172 $result = db_query($this->link
, "SELECT rtl_content FROM ttrss_feeds
173 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
175 if (db_num_rows($result) == 1) {
176 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
178 $rtl_content = false;
182 $rtl_tag = "dir=\"RTL\"";
188 $rtl_content = false;
191 @$search = db_escape_string($_REQUEST["query"]);
194 $disable_cache = true;
197 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
198 @$match_on = db_escape_string($_REQUEST["match_on"]);
204 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
206 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
207 if( $search_mode == '' && $method != '' ){
208 $search_mode = $method;
210 // error_log("search_mode: " . $search_mode);
211 $qfh_ret = queryFeedHeadlines($this->link
, $feed, $limit, $view_mode, $cat_view,
212 $search, $search_mode, $match_on, $override_order, $offset, 0,
213 false, 0, $include_children);
215 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
217 $result = $qfh_ret[0];
218 $feed_title = $qfh_ret[1];
219 $feed_site_url = $qfh_ret[2];
220 $last_error = $qfh_ret[3];
222 $vgroup_last_feed = $vgr_last_feed;
226 if (db_num_rows($result) > 0) {
227 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
229 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
234 $headlines_count = db_num_rows($result);
236 if (get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
237 $button_plugins = array();
238 foreach (explode(",", ARTICLE_BUTTON_PLUGINS
) as $p) {
239 $pclass = trim("button_${p}");
241 if (class_exists($pclass)) {
242 $plugin = new $pclass($link);
243 array_push($button_plugins, $plugin);
248 if (db_num_rows($result) > 0) {
253 $cur_feed_title = '';
255 $fresh_intl = get_pref($this->link
, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
257 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
259 while ($line = db_fetch_assoc($result)) {
260 $class = ($lnum %
2) ?
"even" : "odd";
263 $feed_id = $line["feed_id"];
264 $label_cache = $line["label_cache"];
266 $label_row_style = "";
269 $label_cache = json_decode($label_cache, true);
272 if ($label_cache["no-labels"] == 1)
275 $labels = $label_cache;
276 if (count($labels) > 0) {
277 $bg = rgb2hsl(_color_unpack($labels[0][3]));
278 if ($bg && $bg[1] > 0) {
282 if ($class == "even")
287 $bg = _color_pack(hsl2rgb($bg));
288 $label_row_style = "style='background-color : $bg;'";
295 if (!is_array($labels)) $labels = get_article_labels($this->link
, $id);
297 $labels_str = "<span id=\"HLLCTR-$id\">";
298 $labels_str .= format_article_labels($labels, $id);
299 $labels_str .= "</span>";
301 if (count($topmost_article_ids) < 3) {
302 array_push($topmost_article_ids, $id);
305 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
307 $update_pic = "<img id='FUPDPIC-$id' src=\"".
308 theme_image($this->link
, 'images/updated.png')."\"
311 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
315 if (sql_bool_to_bool($line["unread"]) &&
316 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
318 $update_pic = "<img id='FUPDPIC-$id' src=\"".
319 theme_image($this->link
, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
322 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
330 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
331 $marked_pic = "<img id=\"FMPIC-$id\"
332 src=\"".theme_image($this->link
, 'images/mark_set.png')."\"
333 class=\"markedPic\" alt=\"Unstar article\"
334 onclick='javascript:toggleMark($id)'>";
336 $marked_pic = "<img id=\"FMPIC-$id\"
337 src=\"".theme_image($this->link
, 'images/mark_unset.png')."\"
338 class=\"markedPic\" alt=\"Star article\"
339 onclick='javascript:toggleMark($id)'>";
342 if ($line["published"] == "t" ||
$line["published"] == "1") {
343 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
344 'images/pub_set.png')."\"
346 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
348 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
349 'images/pub_unset.png')."\"
351 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
354 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
355 # $line["title"] . "</a>";
357 # $content_link = "<a
358 # href=\"" . htmlspecialchars($line["link"]) . "\"
359 # onclick=\"view($id,$feed_id);\">" .
360 # $line["title"] . "</a>";
362 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
363 # $line["title"] . "</a>";
365 $updated_fmt = make_local_datetime($this->link
, $line["updated_noms"], false);
367 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
368 $content_preview = truncate_string(strip_tags($line["content_preview"]),
372 $score = $line["score"];
374 $score_pic = theme_image($this->link
,
375 "images/" . get_score_pic($score));
377 /* $score_title = __("(Click to change)");
378 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
379 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
381 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
386 } else if ($score < -100) {
392 $entry_author = $line["author"];
395 $entry_author = " - $entry_author";
398 $has_feed_icon = feed_has_icon($feed_id);
400 if ($has_feed_icon) {
401 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
403 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
406 if (!get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
408 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
409 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
411 $cur_feed_title = $line["feed_title"];
412 $vgroup_last_feed = $feed_id;
414 $cur_feed_title = htmlspecialchars($cur_feed_title);
416 $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
418 $reply['content'] .= "<div class='cdmFeedTitle'>".
419 "<div style=\"float : right\">$feed_icon_img</div>".
420 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
421 $line["feed_title"]."</a> $vf_catchup_link</div>";
426 $mouseover_attrs = "onmouseover='postMouseIn($id)'
427 onmouseout='postMouseOut($id)'";
429 $reply['content'] .= "<div class='$class' id='RROW-$id' $label_row_style $mouseover_attrs>";
431 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
433 $reply['content'] .= "<div class='hlLeft'>";
435 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
438 $reply['content'] .= "$marked_pic";
439 $reply['content'] .= "$published_pic";
441 $reply['content'] .= "</div>";
443 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
444 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
445 $reply['content'] .= "<a id=\"RTITLE-$id\"
446 href=\"" . htmlspecialchars($line["link"]) . "\"
448 truncate_string($line["title"], 200);
450 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
451 if ($content_preview) {
452 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
456 $reply['content'] .= "</a></span>";
458 $reply['content'] .= $labels_str;
460 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
461 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
462 if (@$line["feed_title"]) {
463 $reply['content'] .= "<span class=\"hlFeed\">
464 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
465 $line["feed_title"]."</a>)
470 $reply['content'] .= "</div>";
472 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
473 $reply['content'] .= "<div class=\"hlRight\">";
475 $reply['content'] .= $score_pic;
477 if ($line["feed_title"] && !get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
479 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
480 style=\"cursor : pointer\"
481 title=\"".htmlspecialchars($line['feed_title'])."\">
482 $feed_icon_img<span>";
485 $reply['content'] .= "</div>";
486 $reply['content'] .= "</div>";
490 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
491 if ($feed_id != $vgroup_last_feed) {
493 $cur_feed_title = $line["feed_title"];
494 $vgroup_last_feed = $feed_id;
496 $cur_feed_title = htmlspecialchars($cur_feed_title);
498 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
500 $has_feed_icon = feed_has_icon($feed_id);
502 if ($has_feed_icon) {
503 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
505 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
508 $reply['content'] .= "<div class='cdmFeedTitle'>".
509 "<div style=\"float : right\">$feed_icon_img</div>".
510 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
511 $line["feed_title"]."</a> $vf_catchup_link</div>";
515 $expand_cdm = get_pref($this->link
, 'CDM_EXPANDED');
517 $mouseover_attrs = "onmouseover='postMouseIn($id)'
518 onmouseout='postMouseOut($id)'";
520 $reply['content'] .= "<div class=\"$class\" $label_row_style
521 id=\"RROW-$id\" $mouseover_attrs'>";
523 $reply['content'] .= "<div class=\"cdmHeader\">";
525 $reply['content'] .= "<div>";
527 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
528 'RROW-$id')\" id=\"RCHK-$id\"/>";
530 $reply['content'] .= "$marked_pic";
531 $reply['content'] .= "$published_pic";
533 $reply['content'] .= "</div>";
535 $reply['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .
536 htmlspecialchars(strip_tags($line['title'])) . "</div>";
538 $reply['content'] .= "<span id=\"RTITLE-$id\"
539 onclick=\"return cdmClicked(event, $id);\"
540 class=\"titleWrap$hlc_suffix\">
542 title=\"".htmlspecialchars($line['title'])."\"
543 target=\"_blank\" href=\"".
544 htmlspecialchars($line["link"])."\">".
546 " $entry_author</a>";
548 $reply['content'] .= $labels_str;
550 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
551 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
552 if (@$line["feed_title"]) {
553 $reply['content'] .= "<span class=\"hlFeed\">
554 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
555 $line["feed_title"]."</a>)
561 $content_hidden = "style=\"display : none\"";
563 $excerpt_hidden = "style=\"display : none\"";
565 $reply['content'] .= "<span $excerpt_hidden
566 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
568 $reply['content'] .= "</span>";
570 $reply['content'] .= "<div>";
571 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
572 $reply['content'] .= "$score_pic";
574 if (!get_pref($this->link
, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
575 $reply['content'] .= "<span style=\"cursor : pointer\"
576 title=\"".htmlspecialchars($line["feed_title"])."\"
577 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
579 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
580 $reply['content'] .= "</div>";
582 $reply['content'] .= "</div>";
584 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
585 onclick=\"return cdmClicked(event, $id);\"
588 $reply['content'] .= "<div class=\"cdmContentInner\">";
590 if ($line["orig_feed_id"]) {
592 $tmp_result = db_query($this->link
, "SELECT * FROM ttrss_archived_feeds
593 WHERE id = ".$line["orig_feed_id"]);
595 if (db_num_rows($tmp_result) != 0) {
597 $reply['content'] .= "<div clear='both'>";
598 $reply['content'] .= __("Originally from:");
600 $reply['content'] .= " ";
602 $tmp_line = db_fetch_assoc($tmp_result);
604 $reply['content'] .= "<a target='_blank'
605 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
606 $tmp_line['title'] . "</a>";
608 $reply['content'] .= " ";
610 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
611 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";
613 $reply['content'] .= "</div>";
617 $feed_site_url = $line["site_url"];
619 $article_content = sanitize($this->link
, $line["content_preview"],
620 false, false, $feed_site_url);
622 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
624 $reply['content'] .= format_article_note($id, $line['note']);
626 $reply['content'] .= "</div>";
628 $reply['content'] .= "<span id=\"CWRAP-$id\">";
629 $reply['content'] .= $expand_cdm ?
$article_content : '';
630 $reply['content'] .= "</span>";
632 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
633 ttrss_feeds WHERE id = ".
634 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
635 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
637 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
638 0, "always_display_enclosures")); */
640 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
642 $reply['content'] .= format_article_enclosures($this->link
, $id, $always_display_enclosures,
645 $reply['content'] .= "</div>";
647 $reply['content'] .= "<div class=\"cdmFooter\">";
649 $tag_cache = $line["tag_cache"];
651 $tags_str = format_tags_string(
652 get_article_tags($this->link
, $id, $_SESSION["uid"], $tag_cache),
655 $reply['content'] .= "<img src='".theme_image($this->link
,
656 'images/tag.png')."' alt='Tags' title='Tags'>
657 <span id=\"ATSTR-$id\">$tags_str</span>
658 <a title=\"".__('Edit tags for this article')."\"
659 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
661 $num_comments = $line["num_comments"];
662 $entry_comments = "";
664 if ($num_comments > 0) {
665 if ($line["comments"]) {
666 $comments_url = htmlspecialchars($line["comments"]);
668 $comments_url = htmlspecialchars($line["link"]);
670 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
672 if ($line["comments"] && $line["link"] != $line["comments"]) {
673 $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";
677 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
679 $reply['content'] .= "<div style=\"float : right\">";
681 $reply['content'] .= "<img src=\"images/art-zoom.png\"
682 onclick=\"zoomToArticle(event, $id)\"
683 style=\"cursor : pointer\"
685 title='".__('Open article in new tab')."'>";
687 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
689 foreach ($button_plugins as $p) {
690 $reply['content'] .= $p->render($id, $line);
693 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
694 style=\"cursor : pointer\" style=\"cursor : pointer\"
695 onclick=\"dismissArticle($id)\"
696 title='".__('Close article')."'>";
698 $reply['content'] .= "</div>";
699 $reply['content'] .= "</div>";
701 $reply['content'] .= "</div>";
703 $reply['content'] .= "</div>";
710 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
715 switch ($view_mode) {
717 $message = __("No unread articles found to display.");
720 $message = __("No updated articles found to display.");
723 $message = __("No starred articles found to display.");
727 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
729 $message = __("No articles found to display.");
733 if (!$offset && $message) {
734 $reply['content'] .= "<div class='whiteBox'>$message";
736 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
738 $result = db_query($this->link
, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
739 WHERE owner_uid = " . $_SESSION['uid']);
741 $last_updated = db_fetch_result($result, 0, "last_updated");
742 $last_updated = make_local_datetime($this->link
, $last_updated, false);
744 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
746 $result = db_query($this->link
, "SELECT COUNT(id) AS num_errors
747 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
749 $num_errors = db_fetch_result($result, 0, "num_errors");
751 if ($num_errors > 0) {
752 $reply['content'] .= "<br/>";
753 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
754 __('Some feeds have update errors (click for details)')."</a>";
756 $reply['content'] .= "</span></p></div>";
760 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
762 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
763 $vgroup_last_feed, $reply);
766 function catchupAll() {
767 db_query($this->link
, "UPDATE ttrss_user_entries SET
768 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
769 ccache_zero_all($this->link
, $_SESSION["uid"]);
772 function collapse() {
773 $cat_id = db_escape_string($_REQUEST["cid"]);
774 $mode = (int) db_escape_string($_REQUEST['mode']);
775 toggle_collapse_cat($this->link
, $cat_id, $mode);
779 $timing_info = getmicrotime();
783 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
785 $omode = db_escape_string($_REQUEST["omode"]);
787 $feed = db_escape_string($_REQUEST["feed"]);
788 $method = db_escape_string($_REQUEST["m"]);
789 $view_mode = db_escape_string($_REQUEST["view_mode"]);
790 $limit = (int) get_pref($this->link
, "DEFAULT_ARTICLE_LIMIT");
791 @$cat_view = $_REQUEST["cat"] == "true";
792 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
793 @$offset = db_escape_string($_REQUEST["skip"]);
794 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
795 $order_by = db_escape_string($_REQUEST["order_by"]);
797 if (is_numeric($feed)) $feed = (int) $feed;
799 /* Feed -5 is a special case: it is used to display auxiliary information
800 * when there's nothing to load - e.g. no stuff in fresh feed */
803 print json_encode(generate_dashboard_feed($this->link
));
810 $label_feed = -11-$feed;
811 $result = db_query($this->link
, "SELECT id FROM ttrss_labels2 WHERE
812 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
813 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
814 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
815 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
816 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
817 $result = db_query($this->link
, "SELECT id FROM ttrss_feed_categories WHERE
818 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
821 if ($result && db_num_rows($result) == 0) {
822 print json_encode(generate_error_feed($this->link
, __("Feed not found.")));
826 /* Updating a label ccache means recalculating all of the caches
827 * so for performance reasons we don't do that here */
830 ccache_update($this->link
, $feed, $_SESSION["uid"], $cat_view);
833 set_pref($this->link
, "_DEFAULT_VIEW_MODE", $view_mode);
834 set_pref($this->link
, "_DEFAULT_VIEW_LIMIT", $limit);
835 set_pref($this->link
, "_DEFAULT_VIEW_ORDER_BY", $order_by);
837 if (!$cat_view && is_numeric($feed) && $feed > 0) {
838 db_query($this->link
, "UPDATE ttrss_feeds SET last_viewed = NOW()
839 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
842 $reply['headlines'] = array();
844 if (!$next_unread_feed)
845 $reply['headlines']['id'] = $feed;
847 $reply['headlines']['id'] = $next_unread_feed;
849 $reply['headlines']['is_cat'] = (bool) $cat_view;
851 $override_order = false;
853 if (get_pref($this->link
, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
854 $date_sort_field = "updated";
856 $date_sort_field = "date_entered";
861 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
862 $override_order = "$date_sort_field";
864 $override_order = "$date_sort_field DESC";
869 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
870 $override_order = "title DESC, $date_sort_field";
872 $override_order = "title, $date_sort_field DESC";
877 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
878 $override_order = "score, $date_sort_field";
880 $override_order = "score DESC, $date_sort_field DESC";
885 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
887 $ret = $this->format_headlines_list($feed, $method,
888 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
889 $vgroup_last_feed, $override_order, true);
891 $topmost_article_ids = $ret[0];
892 $headlines_count = $ret[1];
893 $returned_feed = $ret[2];
894 $disable_cache = $ret[3];
895 $vgroup_last_feed = $ret[4];
897 $reply['headlines']['content'] =& $ret[5]['content'];
898 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
900 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
902 $reply['headlines-info'] = array("count" => (int) $headlines_count,
903 "vgroup_last_feed" => $vgroup_last_feed,
904 "disable_cache" => (bool) $disable_cache);
906 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
908 if (is_array($topmost_article_ids) && !get_pref($this->link
, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
911 foreach ($topmost_article_ids as $id) {
912 array_push($articles, format_article($this->link
, $id, false));
915 $reply['articles'] = $articles;
918 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
920 $reply['runtime-info'] = make_runtime_info($this->link
);
922 print json_encode($reply);