]>
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,
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 $set_score_link = "setSelectionScore()";
50 if ($is_cat) $cat_q = "&is_cat=$is_cat";
53 $search_q = "&q=$search&smode=$search_mode";
58 $rss_link = htmlspecialchars(get_self_url_prefix() .
59 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
63 $reply .= "<span class='r'>";
64 $reply .= "<span id='feed_title'>";
67 $target = "target=\"_blank\"";
68 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
69 truncate_string($feed_title,30)."</a>";
72 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
76 $reply .= $feed_title;
83 title=\"".__("View as RSS feed")."\"
84 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
85 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/pub_set.svg\"></a>";
91 $reply .= __('Select:')."
92 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
93 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
94 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
95 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
99 $reply .= "<select dojoType=\"dijit.form.Select\"
100 onchange=\"headlineActionsChange(this)\">";
101 $reply .= "<option value=\"false\">".__('More...')."</option>";
103 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
105 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
106 <option value=\"$tog_marked_link\">".__('Starred')."</option>
107 <option value=\"$tog_published_link\">".__('Published')."</option>";
109 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
111 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
112 $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>";
114 if ($feed_id != "0") {
115 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
117 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
118 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
124 if ($pluginhost->get_plugin("mail")) {
125 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
129 if ($pluginhost->get_plugin("mailto")) {
130 $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
134 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
136 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
138 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
140 $reply .= "</select>";
142 //$reply .= "</div>";
149 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
150 $next_unread_feed, $offset, $vgr_last_feed = false,
151 $override_order = false, $include_children = false) {
153 if (isset($_REQUEST["DevForceUpdate"]))
154 header("Content-Type: text/plain");
156 $disable_cache = false;
160 $timing_info = microtime(true);
162 $topmost_article_ids = array();
164 if (!$offset) $offset = 0;
165 if ($method == "undefined") $method = "";
167 $method_split = explode(":", $method);
169 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
170 // Update the feed if required with some basic flood control
172 $result = db_query($this->link
,
173 "SELECT cache_images,".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
174 FROM ttrss_feeds WHERE id = '$feed'");
176 if (db_num_rows($result) != 0) {
177 $last_updated = strtotime(db_fetch_result($result, 0, "last_updated"));
178 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
180 if (!$cache_images && time() - $last_updated > 120 ||
isset($_REQUEST['DevForceUpdate'])) {
181 include "rssfuncs.php";
182 update_rss_feed($this->link
, $feed, true, true);
184 db_query($this->link
, "UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
185 WHERE id = '$feed'");
190 if ($method_split[0] == "MarkAllReadGR") {
191 catchup_feed($this->link
, $method_split[1], false);
194 // FIXME: might break tag display?
196 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
197 $result = db_query($this->link
,
198 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
200 if (db_num_rows($result) == 0) {
201 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
205 @$search = db_escape_string($this->link
, $_REQUEST["query"]);
208 $disable_cache = true;
211 @$search_mode = db_escape_string($this->link
, $_REQUEST["search_mode"]);
213 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
215 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
216 if( $search_mode == '' && $method != '' ){
217 $search_mode = $method;
219 // error_log("search_mode: " . $search_mode);
220 $qfh_ret = queryFeedHeadlines($this->link
, $feed, $limit, $view_mode, $cat_view,
221 $search, $search_mode, $override_order, $offset, 0,
222 false, 0, $include_children);
224 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
226 $result = $qfh_ret[0];
227 $feed_title = $qfh_ret[1];
228 $feed_site_url = $qfh_ret[2];
229 $last_error = $qfh_ret[3];
231 $vgroup_last_feed = $vgr_last_feed;
233 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
235 $feed, $cat_view, $search, $search_mode, $view_mode,
238 $headlines_count = db_num_rows($result);
240 /* if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
241 $button_plugins = array();
242 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
243 $pclass = "button_" . trim($p);
245 if (class_exists($pclass)) {
246 $plugin = new $pclass($link);
247 array_push($button_plugins, $plugin);
254 if (db_num_rows($result) > 0) {
259 $cur_feed_title = '';
261 $fresh_intl = get_pref($this->link
, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
263 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
265 $expand_cdm = get_pref($this->link
, 'CDM_EXPANDED');
267 while ($line = db_fetch_assoc($result)) {
268 $class = ($lnum %
2) ?
"even" : "odd";
271 $feed_id = $line["feed_id"];
272 $label_cache = $line["label_cache"];
274 $label_row_style = "";
277 $label_cache = json_decode($label_cache, true);
280 if ($label_cache["no-labels"] == 1)
283 $labels = $label_cache;
287 if (!is_array($labels)) $labels = get_article_labels($this->link
, $id);
289 if (count($labels) > 0) {
290 for ($i = 0; $i < min(4, count($labels)); $i++
) {
291 $bg = rgb2hsl(_color_unpack($labels[$i][3]));
293 if ($bg && $bg[1] > 0) {
297 $bg = _color_pack(hsl2rgb($bg));
298 $label_row_style = $this->make_gradient($bg, $class);;
305 $labels_str = "<span id=\"HLLCTR-$id\">";
306 $labels_str .= format_article_labels($labels, $id);
307 $labels_str .= "</span>";
309 if (count($topmost_article_ids) < 3) {
310 array_push($topmost_article_ids, $id);
313 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
321 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
322 $marked_pic = "<img id=\"FMPIC-$id\"
323 src=\"images/mark_set.svg\"
324 class=\"markedPic\" alt=\"Unstar article\"
325 onclick='javascript:toggleMark($id)'>";
327 $marked_pic = "<img id=\"FMPIC-$id\"
328 src=\"images/mark_unset.svg\"
329 class=\"markedPic\" alt=\"Star article\"
330 onclick='javascript:toggleMark($id)'>";
333 if ($line["published"] == "t" ||
$line["published"] == "1") {
334 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.svg\"
336 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
338 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.svg\"
340 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
343 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
344 # $line["title"] . "</a>";
346 # $content_link = "<a
347 # href=\"" . htmlspecialchars($line["link"]) . "\"
348 # onclick=\"view($id,$feed_id);\">" .
349 # $line["title"] . "</a>";
351 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
352 # $line["title"] . "</a>";
354 $updated_fmt = make_local_datetime($this->link
, $line["updated_noms"], false);
356 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
357 $content_preview = truncate_string(strip_tags($line["content_preview"]),
361 $score = $line["score"];
363 $score_pic = "images/" . get_score_pic($score);
365 /* $score_title = __("(Click to change)");
366 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
367 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
369 $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
374 } else if ($score < -100) {
380 $entry_author = $line["author"];
383 $entry_author = " - $entry_author";
386 $has_feed_icon = feed_has_icon($feed_id);
388 if ($has_feed_icon) {
389 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
391 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.svg\" alt=\"\">";
394 $entry_site_url = $line["site_url"];
396 if (!get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
398 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
399 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
401 $cur_feed_title = $line["feed_title"];
402 $vgroup_last_feed = $feed_id;
404 $cur_feed_title = htmlspecialchars($cur_feed_title);
406 $vf_catchup_link = "(<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('Mark as read')."</a>)";
408 $reply['content'] .= "<div class='cdmFeedTitle'>".
409 "<div style=\"float : right\">$feed_icon_img</div>".
410 "<a class='title' href=\"#\" onclick=\"viewfeed($feed_id)\">".
411 $line["feed_title"]."</a> $vf_catchup_link</div>";
416 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
417 onmouseout='postMouseOut($id)'";
419 $reply['content'] .= "<div class='$class' id='RROW-$id' $label_row_style $mouseover_attrs>";
421 $reply['content'] .= "<div class='hlLeft'>";
423 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
424 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
427 $reply['content'] .= "$marked_pic";
428 $reply['content'] .= "$published_pic";
430 $reply['content'] .= "</div>";
432 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
433 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
434 $reply['content'] .= "<a id=\"RTITLE-$id\"
435 href=\"" . htmlspecialchars($line["link"]) . "\"
437 truncate_string($line["title"], 200);
439 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
440 if ($content_preview) {
441 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
445 $reply['content'] .= "</a></span>";
447 $reply['content'] .= $labels_str;
449 $reply['content'] .= "</div>";
451 $reply['content'] .= "<span class=\"hlUpdated\">";
453 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
454 if (@$line["feed_title"]) {
455 $reply['content'] .= "<div class=\"hlFeed\">
456 <a href=\"#\" onclick=\"viewfeed($feed_id)\">".
457 $line["feed_title"]."</a>
462 $reply['content'] .= "$updated_fmt</span>";
463 $reply['content'] .= "<div class=\"hlRight\">";
465 $reply['content'] .= $score_pic;
467 if ($line["feed_title"] && !get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
469 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
470 style=\"cursor : pointer\"
471 title=\"".htmlspecialchars($line['feed_title'])."\">
472 $feed_icon_img<span>";
475 $reply['content'] .= "</div>";
476 $reply['content'] .= "</div>";
480 $line["tags"] = get_article_tags($this->link
, $id, $_SESSION["uid"], $line["tag_cache"]);
481 unset($line["tag_cache"]);
483 $line["content"] = sanitize($this->link
, $line["content_preview"],
484 sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
486 foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_CDM
) as $p) {
487 $line = $p->hook_render_article_cdm($line);
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 class='catchup' 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=\"#\" class='title' onclick=\"viewfeed($feed_id)\">".
511 $line["feed_title"]."</a> $vf_catchup_link</div>";
515 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
516 onmouseout='postMouseOut($id)'";
518 $expanded_class = $expand_cdm ?
"expanded" : "";
520 $reply['content'] .= "<div class=\"cdm $expanded_class $class\"
521 id=\"RROW-$id\" $mouseover_attrs'>";
523 $reply['content'] .= "<div class=\"cdmHeader\">";
525 $reply['content'] .= "<div style=\"vertical-align : middle\">";
527 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
528 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
531 $reply['content'] .= "$marked_pic";
532 $reply['content'] .= "$published_pic";
534 $reply['content'] .= "</div>";
536 $reply['content'] .= "<span id=\"RTITLE-$id\"
537 onclick=\"return cdmClicked(event, $id);\"
538 class=\"titleWrap$hlc_suffix\">
540 target=\"_blank\" href=\"".
541 htmlspecialchars($line["link"])."\">".
543 " <span class=\"author\">$entry_author</span></a>";
545 $reply['content'] .= $labels_str;
547 $reply['content'] .= "<span class='collapseBtn' style='display : none'>
548 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
549 title=\"".__("Collapse article")."\"/></span>";
552 $content_hidden = "style=\"display : none\"";
554 $excerpt_hidden = "style=\"display : none\"";
556 $reply['content'] .= "<span $excerpt_hidden
557 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
558 $reply['content'] .= "</span>";
560 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
561 if (@$line["feed_title"]) {
562 $reply['content'] .= "<div class=\"hlFeed\">
563 <a href=\"#\" onclick=\"viewfeed($feed_id)\">".
564 $line["feed_title"]."</a>
569 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
571 $reply['content'] .= "<div style=\"vertical-align : middle\">";
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>";
581 $reply['content'] .= "</div>";
583 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
584 onclick=\"return cdmClicked(event, $id);\"
587 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
589 $reply['content'] .= format_article_note($id, $line['note']);
591 $reply['content'] .= "</div>";
594 $reply['content'] .= "<div class=\"cdmContentInner\">";
596 if ($line["orig_feed_id"]) {
598 $tmp_result = db_query($this->link
, "SELECT * FROM ttrss_archived_feeds
599 WHERE id = ".$line["orig_feed_id"]);
601 if (db_num_rows($tmp_result) != 0) {
603 $reply['content'] .= "<div clear='both'>";
604 $reply['content'] .= __("Originally from:");
606 $reply['content'] .= " ";
608 $tmp_line = db_fetch_assoc($tmp_result);
610 $reply['content'] .= "<a target='_blank'
611 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
612 $tmp_line['title'] . "</a>";
614 $reply['content'] .= " ";
616 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
617 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.svg'></a>";
619 $reply['content'] .= "</div>";
623 $reply['content'] .= "<span id=\"CWRAP-$id\">";
625 // if (!$expand_cdm) {
626 $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">";
627 $reply['content'] .= htmlspecialchars($line["content"]);
628 $reply['content'] .= "</span.";
631 // $reply['content'] .= $line["content"];
634 $reply['content'] .= "</span>";
636 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
638 $reply['content'] .= format_article_enclosures($this->link
, $id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"]));
640 $reply['content'] .= "</div>";
642 $reply['content'] .= "<div class=\"cdmFooter\">";
644 $tags_str = format_tags_string($line["tags"], $id);
646 $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>
647 <span id=\"ATSTR-$id\">$tags_str</span>
648 <a title=\"".__('Edit tags for this article')."\"
649 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
651 $num_comments = $line["num_comments"];
652 $entry_comments = "";
654 if ($num_comments > 0) {
655 if ($line["comments"]) {
656 $comments_url = htmlspecialchars($line["comments"]);
658 $comments_url = htmlspecialchars($line["link"]);
660 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
662 if ($line["comments"] && $line["link"] != $line["comments"]) {
663 $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";
667 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
669 $reply['content'] .= "<div style=\"float : right\">";
671 foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON
) as $p) {
672 $reply['content'] .= $p->hook_article_button($line);
675 $reply['content'] .= "</div>";
676 $reply['content'] .= "</div>";
678 $reply['content'] .= "</div>";
680 $reply['content'] .= "</div>";
687 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
692 switch ($view_mode) {
694 $message = __("No unread articles found to display.");
697 $message = __("No updated articles found to display.");
700 $message = __("No starred articles found to display.");
704 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
706 $message = __("No articles found to display.");
710 if (!$offset && $message) {
711 $reply['content'] .= "<div class='whiteBox'>$message";
713 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
715 $result = db_query($this->link
, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
716 WHERE owner_uid = " . $_SESSION['uid']);
718 $last_updated = db_fetch_result($result, 0, "last_updated");
719 $last_updated = make_local_datetime($this->link
, $last_updated, false);
721 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
723 $result = db_query($this->link
, "SELECT COUNT(id) AS num_errors
724 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
726 $num_errors = db_fetch_result($result, 0, "num_errors");
728 if ($num_errors > 0) {
729 $reply['content'] .= "<br/>";
730 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
731 __('Some feeds have update errors (click for details)')."</a>";
733 $reply['content'] .= "</span></p></div>";
737 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
739 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
740 $vgroup_last_feed, $reply);
743 function catchupAll() {
744 db_query($this->link
, "UPDATE ttrss_user_entries SET
745 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
746 ccache_zero_all($this->link
, $_SESSION["uid"]);
750 $timing_info = microtime(true);
754 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
756 $omode = db_escape_string($this->link
, $_REQUEST["omode"]);
758 $feed = db_escape_string($this->link
, $_REQUEST["feed"]);
759 $method = db_escape_string($this->link
, $_REQUEST["m"]);
760 $view_mode = db_escape_string($this->link
, $_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($this->link
, $_REQUEST["nuf"]);
764 @$offset = db_escape_string($this->link
, $_REQUEST["skip"]);
765 @$vgroup_last_feed = db_escape_string($this->link
, $_REQUEST["vgrlf"]);
766 $order_by = db_escape_string($this->link
, $_REQUEST["order_by"]);
768 if (is_numeric($feed)) $feed = (int) $feed;
770 /* Feed -5 is a special case: it is used to display auxiliary information
771 * when there's nothing to load - e.g. no stuff in fresh feed */
774 print json_encode($this->generate_dashboard_feed($this->link
));
781 $label_feed = -11-$feed;
782 $result = db_query($this->link
, "SELECT id FROM ttrss_labels2 WHERE
783 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
784 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
785 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
786 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
787 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
788 $result = db_query($this->link
, "SELECT id FROM ttrss_feed_categories WHERE
789 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
792 if ($result && db_num_rows($result) == 0) {
793 print json_encode($this->generate_error_feed($this->link
, __("Feed not found.")));
797 /* Updating a label ccache means recalculating all of the caches
798 * so for performance reasons we don't do that here */
801 ccache_update($this->link
, $feed, $_SESSION["uid"], $cat_view);
804 set_pref($this->link
, "_DEFAULT_VIEW_MODE", $view_mode);
805 set_pref($this->link
, "_DEFAULT_VIEW_LIMIT", $limit);
806 set_pref($this->link
, "_DEFAULT_VIEW_ORDER_BY", $order_by);
808 /* bump login timestamp if needed */
809 if (time() - $_SESSION["last_login_update"] > 3600) {
810 db_query($this->link
, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
812 $_SESSION["last_login_update"] = time();
815 if (!$cat_view && is_numeric($feed) && $feed > 0) {
816 db_query($this->link
, "UPDATE ttrss_feeds SET last_viewed = NOW()
817 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
820 $reply['headlines'] = array();
822 if (!$next_unread_feed)
823 $reply['headlines']['id'] = $feed;
825 $reply['headlines']['id'] = $next_unread_feed;
827 $reply['headlines']['is_cat'] = (bool) $cat_view;
829 $override_order = false;
831 if (get_pref($this->link
, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
832 $date_sort_field = "updated";
834 $date_sort_field = "date_entered";
839 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
840 $override_order = "$date_sort_field";
842 $override_order = "$date_sort_field DESC";
847 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
848 $override_order = "title DESC, $date_sort_field";
850 $override_order = "title, $date_sort_field DESC";
855 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
856 $override_order = "score, $date_sort_field";
858 $override_order = "score DESC, $date_sort_field DESC";
863 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
865 $ret = $this->format_headlines_list($feed, $method,
866 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
867 $vgroup_last_feed, $override_order, true);
869 //$topmost_article_ids = $ret[0];
870 $headlines_count = $ret[1];
871 $returned_feed = $ret[2];
872 $disable_cache = $ret[3];
873 $vgroup_last_feed = $ret[4];
875 $reply['headlines']['content'] =& $ret[5]['content'];
876 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
878 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
880 $reply['headlines-info'] = array("count" => (int) $headlines_count,
881 "vgroup_last_feed" => $vgroup_last_feed,
882 "disable_cache" => (bool) $disable_cache);
884 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
886 $reply['runtime-info'] = make_runtime_info($this->link
);
888 print json_encode($reply);
892 private function generate_dashboard_feed($link) {
895 $reply['headlines']['id'] = -5;
896 $reply['headlines']['is_cat'] = false;
898 $reply['headlines']['toolbar'] = '';
899 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
901 $reply['headlines']['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
903 $result = db_query($link, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
904 WHERE owner_uid = " . $_SESSION['uid']);
906 $last_updated = db_fetch_result($result, 0, "last_updated");
907 $last_updated = make_local_datetime($link, $last_updated, false);
909 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
911 $result = db_query($link, "SELECT COUNT(id) AS num_errors
912 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
914 $num_errors = db_fetch_result($result, 0, "num_errors");
916 if ($num_errors > 0) {
917 $reply['headlines']['content'] .= "<br/>";
918 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
919 __('Some feeds have update errors (click for details)')."</a>";
921 $reply['headlines']['content'] .= "</span></p>";
923 $reply['headlines-info'] = array("count" => 0,
924 "vgroup_last_feed" => '',
926 "disable_cache" => true);
931 private function generate_error_feed($link, $error) {
934 $reply['headlines']['id'] = -6;
935 $reply['headlines']['is_cat'] = false;
937 $reply['headlines']['toolbar'] = '';
938 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
940 $reply['headlines-info'] = array("count" => 0,
941 "vgroup_last_feed" => '',
943 "disable_cache" => true);