]>
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);
221 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX
) {
224 $handler = $pluginhost->get_feed_handler(
225 PluginHost
::feed_to_pfeed_id($feed));
227 // function queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false) {
232 "view_mode" => $view_mode,
233 "cat_view" => $cat_view,
235 "search_mode" => $search_mode,
236 "override_order" => $override_order,
238 "owner_uid" => $_SESSION["uid"],
241 "include_children" => $include_children);
243 $qfh_ret = $handler->get_headlines(PluginHost
::feed_to_pfeed_id($feed),
248 $qfh_ret = queryFeedHeadlines($this->link
, $feed, $limit, $view_mode, $cat_view,
249 $search, $search_mode, $override_order, $offset, 0,
250 false, 0, $include_children);
253 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
255 $result = $qfh_ret[0];
256 $feed_title = $qfh_ret[1];
257 $feed_site_url = $qfh_ret[2];
258 $last_error = $qfh_ret[3];
260 $vgroup_last_feed = $vgr_last_feed;
262 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
264 $feed, $cat_view, $search, $search_mode, $view_mode,
267 $headlines_count = db_num_rows($result);
269 /* if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
270 $button_plugins = array();
271 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
272 $pclass = "button_" . trim($p);
274 if (class_exists($pclass)) {
275 $plugin = new $pclass($link);
276 array_push($button_plugins, $plugin);
283 if (db_num_rows($result) > 0) {
288 $cur_feed_title = '';
290 $fresh_intl = get_pref($this->link
, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
292 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
294 $expand_cdm = get_pref($this->link
, 'CDM_EXPANDED');
296 while ($line = db_fetch_assoc($result)) {
297 $class = ($lnum %
2) ?
"even" : "odd";
300 $feed_id = $line["feed_id"];
301 $label_cache = $line["label_cache"];
303 $label_row_style = "";
306 $label_cache = json_decode($label_cache, true);
309 if ($label_cache["no-labels"] == 1)
312 $labels = $label_cache;
316 if (!is_array($labels)) $labels = get_article_labels($this->link
, $id);
318 if (count($labels) > 0) {
319 for ($i = 0; $i < min(4, count($labels)); $i++
) {
320 $bg = rgb2hsl(_color_unpack($labels[$i][3]));
322 if ($bg && $bg[1] > 0) {
326 $bg = _color_pack(hsl2rgb($bg));
327 $label_row_style = $this->make_gradient($bg, $class);;
334 $labels_str = "<span id=\"HLLCTR-$id\">";
335 $labels_str .= format_article_labels($labels, $id);
336 $labels_str .= "</span>";
338 if (count($topmost_article_ids) < 3) {
339 array_push($topmost_article_ids, $id);
342 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
350 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
351 $marked_pic = "<img id=\"FMPIC-$id\"
352 src=\"images/mark_set.svg\"
353 class=\"markedPic\" alt=\"Unstar article\"
354 onclick='javascript:toggleMark($id)'>";
356 $marked_pic = "<img id=\"FMPIC-$id\"
357 src=\"images/mark_unset.svg\"
358 class=\"markedPic\" alt=\"Star article\"
359 onclick='javascript:toggleMark($id)'>";
362 if ($line["published"] == "t" ||
$line["published"] == "1") {
363 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.svg\"
365 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
367 $published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.svg\"
369 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
372 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
373 # $line["title"] . "</a>";
375 # $content_link = "<a
376 # href=\"" . htmlspecialchars($line["link"]) . "\"
377 # onclick=\"view($id,$feed_id);\">" .
378 # $line["title"] . "</a>";
380 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
381 # $line["title"] . "</a>";
383 $updated_fmt = make_local_datetime($this->link
, $line["updated"], false);
384 $date_entered_fmt = T_sprintf("Imported at %s",
385 make_local_datetime($this->link
, $line["date_entered"], false));
387 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
388 $content_preview = truncate_string(strip_tags($line["content_preview"]),
392 $score = $line["score"];
394 $score_pic = "images/" . get_score_pic($score);
396 /* $score_title = __("(Click to change)");
397 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
398 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
400 $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
405 } else if ($score < -100) {
411 $entry_author = $line["author"];
414 $entry_author = " - $entry_author";
417 $has_feed_icon = feed_has_icon($feed_id);
419 if ($has_feed_icon) {
420 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
422 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.svg\" alt=\"\">";
425 $entry_site_url = $line["site_url"];
427 if (!get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
429 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
430 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
432 $cur_feed_title = $line["feed_title"];
433 $vgroup_last_feed = $feed_id;
435 $cur_feed_title = htmlspecialchars($cur_feed_title);
437 $vf_catchup_link = "(<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('Mark as read')."</a>)";
439 $reply['content'] .= "<div class='cdmFeedTitle'>".
440 "<div style=\"float : right\">$feed_icon_img</div>".
441 "<a class='title' href=\"#\" onclick=\"viewfeed($feed_id)\">".
442 $line["feed_title"]."</a> $vf_catchup_link</div>";
447 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
448 onmouseout='postMouseOut($id)'";
450 $reply['content'] .= "<div class='$class' id='RROW-$id' $label_row_style $mouseover_attrs>";
452 $reply['content'] .= "<div class='hlLeft'>";
454 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
455 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
458 $reply['content'] .= "$marked_pic";
459 $reply['content'] .= "$published_pic";
461 $reply['content'] .= "</div>";
463 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
464 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
465 $reply['content'] .= "<a id=\"RTITLE-$id\"
466 href=\"" . htmlspecialchars($line["link"]) . "\"
468 truncate_string($line["title"], 200);
470 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
471 if ($content_preview) {
472 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
476 $reply['content'] .= "</a></span>";
478 $reply['content'] .= $labels_str;
480 $reply['content'] .= "</div>";
482 $reply['content'] .= "<span class=\"hlUpdated\">";
484 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
485 if (@$line["feed_title"]) {
486 $reply['content'] .= "<div class=\"hlFeed\">
487 <a href=\"#\" onclick=\"viewfeed($feed_id)\">".
488 truncate_string($line["feed_title"],30)."</a>
493 $reply['content'] .= "<span title='$date_entered_fmt'>$updated_fmt</span>
496 $reply['content'] .= "<div class=\"hlRight\">";
498 $reply['content'] .= $score_pic;
500 if ($line["feed_title"] && !get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
502 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
503 style=\"cursor : pointer\"
504 title=\"".htmlspecialchars($line['feed_title'])."\">
505 $feed_icon_img<span>";
508 $reply['content'] .= "</div>";
509 $reply['content'] .= "</div>";
513 $line["tags"] = get_article_tags($this->link
, $id, $_SESSION["uid"], $line["tag_cache"]);
514 unset($line["tag_cache"]);
516 $line["content"] = sanitize($this->link
, $line["content_preview"],
517 sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
519 foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_CDM
) as $p) {
520 $line = $p->hook_render_article_cdm($line);
523 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
524 if ($feed_id != $vgroup_last_feed) {
526 $cur_feed_title = $line["feed_title"];
527 $vgroup_last_feed = $feed_id;
529 $cur_feed_title = htmlspecialchars($cur_feed_title);
531 $vf_catchup_link = "(<a class='catchup' onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
533 $has_feed_icon = feed_has_icon($feed_id);
535 if ($has_feed_icon) {
536 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
538 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
541 $reply['content'] .= "<div class='cdmFeedTitle'>".
542 "<div style=\"float : right\">$feed_icon_img</div>".
543 "<a href=\"#\" class='title' onclick=\"viewfeed($feed_id)\">".
544 $line["feed_title"]."</a> $vf_catchup_link</div>";
548 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
549 onmouseout='postMouseOut($id)'";
551 $expanded_class = $expand_cdm ?
"expanded" : "";
553 $reply['content'] .= "<div class=\"cdm $expanded_class $class\"
554 id=\"RROW-$id\" $mouseover_attrs'>";
556 $reply['content'] .= "<div class=\"cdmHeader\">";
558 $reply['content'] .= "<div style=\"vertical-align : middle\">";
560 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
561 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
564 $reply['content'] .= "$marked_pic";
565 $reply['content'] .= "$published_pic";
567 $reply['content'] .= "</div>";
569 $reply['content'] .= "<span id=\"RTITLE-$id\"
570 onclick=\"return cdmClicked(event, $id);\"
571 class=\"titleWrap$hlc_suffix\">
573 target=\"_blank\" href=\"".
574 htmlspecialchars($line["link"])."\">".
576 " <span class=\"author\">$entry_author</span></a>";
578 $reply['content'] .= $labels_str;
580 $reply['content'] .= "<span class='collapseBtn' style='display : none'>
581 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
582 title=\"".__("Collapse article")."\"/></span>";
585 $content_hidden = "style=\"display : none\"";
587 $excerpt_hidden = "style=\"display : none\"";
589 $reply['content'] .= "<span $excerpt_hidden
590 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
591 $reply['content'] .= "</span>";
593 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
594 if (@$line["feed_title"]) {
595 $reply['content'] .= "<div class=\"hlFeed\">
596 <a href=\"#\" onclick=\"viewfeed($feed_id)\">".
597 truncate_string($line["feed_title"],30)."</a>
602 $reply['content'] .= "<span class='updated' title='$date_entered_fmt'>
603 $updated_fmt</span>";
605 $reply['content'] .= "<div style=\"vertical-align : middle\">";
606 $reply['content'] .= "$score_pic";
608 if (!get_pref($this->link
, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
609 $reply['content'] .= "<span style=\"cursor : pointer\"
610 title=\"".htmlspecialchars($line["feed_title"])."\"
611 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
613 $reply['content'] .= "</div>";
615 $reply['content'] .= "</div>";
617 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
618 onclick=\"return cdmClicked(event, $id);\"
621 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
623 $reply['content'] .= format_article_note($id, $line['note']);
625 $reply['content'] .= "</div>";
628 $reply['content'] .= "<div class=\"cdmContentInner\">";
630 if ($line["orig_feed_id"]) {
632 $tmp_result = db_query($this->link
, "SELECT * FROM ttrss_archived_feeds
633 WHERE id = ".$line["orig_feed_id"]);
635 if (db_num_rows($tmp_result) != 0) {
637 $reply['content'] .= "<div clear='both'>";
638 $reply['content'] .= __("Originally from:");
640 $reply['content'] .= " ";
642 $tmp_line = db_fetch_assoc($tmp_result);
644 $reply['content'] .= "<a target='_blank'
645 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
646 $tmp_line['title'] . "</a>";
648 $reply['content'] .= " ";
650 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
651 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.svg'></a>";
653 $reply['content'] .= "</div>";
657 $reply['content'] .= "<span id=\"CWRAP-$id\">";
659 // if (!$expand_cdm) {
660 $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">";
661 $reply['content'] .= htmlspecialchars($line["content"]);
662 $reply['content'] .= "</span.";
665 // $reply['content'] .= $line["content"];
668 $reply['content'] .= "</span>";
670 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
672 $reply['content'] .= format_article_enclosures($this->link
, $id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"]));
674 $reply['content'] .= "</div>";
676 $reply['content'] .= "<div class=\"cdmFooter\">";
678 $tags_str = format_tags_string($line["tags"], $id);
680 $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>
681 <span id=\"ATSTR-$id\">$tags_str</span>
682 <a title=\"".__('Edit tags for this article')."\"
683 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
685 $num_comments = $line["num_comments"];
686 $entry_comments = "";
688 if ($num_comments > 0) {
689 if ($line["comments"]) {
690 $comments_url = htmlspecialchars($line["comments"]);
692 $comments_url = htmlspecialchars($line["link"]);
694 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
696 if ($line["comments"] && $line["link"] != $line["comments"]) {
697 $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";
701 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
703 $reply['content'] .= "<div style=\"float : right\">";
705 foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON
) as $p) {
706 $reply['content'] .= $p->hook_article_button($line);
709 $reply['content'] .= "</div>";
710 $reply['content'] .= "</div>";
712 $reply['content'] .= "</div>";
714 $reply['content'] .= "</div>";
721 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
726 switch ($view_mode) {
728 $message = __("No unread articles found to display.");
731 $message = __("No updated articles found to display.");
734 $message = __("No starred articles found to display.");
737 if ($feed < LABEL_BASE_INDEX
) {
738 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
740 $message = __("No articles found to display.");
744 if (!$offset && $message) {
745 $reply['content'] .= "<div class='whiteBox'>$message";
747 $reply['content'] .= "<p><span class=\"insensitive\">";
749 $result = db_query($this->link
, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
750 WHERE owner_uid = " . $_SESSION['uid']);
752 $last_updated = db_fetch_result($result, 0, "last_updated");
753 $last_updated = make_local_datetime($this->link
, $last_updated, false);
755 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
757 $result = db_query($this->link
, "SELECT COUNT(id) AS num_errors
758 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
760 $num_errors = db_fetch_result($result, 0, "num_errors");
762 if ($num_errors > 0) {
763 $reply['content'] .= "<br/>";
764 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
765 __('Some feeds have update errors (click for details)')."</a>";
767 $reply['content'] .= "</span></p></div>";
771 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
773 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
774 $vgroup_last_feed, $reply);
777 function catchupAll() {
778 db_query($this->link
, "UPDATE ttrss_user_entries SET
779 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
780 ccache_zero_all($this->link
, $_SESSION["uid"]);
784 $timing_info = microtime(true);
788 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
790 $omode = db_escape_string($this->link
, $_REQUEST["omode"]);
792 $feed = db_escape_string($this->link
, $_REQUEST["feed"]);
793 $method = db_escape_string($this->link
, $_REQUEST["m"]);
794 $view_mode = db_escape_string($this->link
, $_REQUEST["view_mode"]);
795 $limit = (int) get_pref($this->link
, "DEFAULT_ARTICLE_LIMIT");
796 @$cat_view = $_REQUEST["cat"] == "true";
797 @$next_unread_feed = db_escape_string($this->link
, $_REQUEST["nuf"]);
798 @$offset = db_escape_string($this->link
, $_REQUEST["skip"]);
799 @$vgroup_last_feed = db_escape_string($this->link
, $_REQUEST["vgrlf"]);
800 $order_by = db_escape_string($this->link
, $_REQUEST["order_by"]);
802 if (is_numeric($feed)) $feed = (int) $feed;
804 /* Feed -5 is a special case: it is used to display auxiliary information
805 * when there's nothing to load - e.g. no stuff in fresh feed */
808 print json_encode($this->generate_dashboard_feed($this->link
));
814 if ($feed < LABEL_BASE_INDEX
) {
815 $label_feed = feed_to_label_id($feed);
816 $result = db_query($this->link
, "SELECT id FROM ttrss_labels2 WHERE
817 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
818 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
819 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
820 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
821 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
822 $result = db_query($this->link
, "SELECT id FROM ttrss_feed_categories WHERE
823 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
826 if ($result && db_num_rows($result) == 0) {
827 print json_encode($this->generate_error_feed($this->link
, __("Feed not found.")));
831 /* Updating a label ccache means recalculating all of the caches
832 * so for performance reasons we don't do that here */
835 ccache_update($this->link
, $feed, $_SESSION["uid"], $cat_view);
838 set_pref($this->link
, "_DEFAULT_VIEW_MODE", $view_mode);
839 set_pref($this->link
, "_DEFAULT_VIEW_LIMIT", $limit);
840 set_pref($this->link
, "_DEFAULT_VIEW_ORDER_BY", $order_by);
842 /* bump login timestamp if needed */
843 if (time() - $_SESSION["last_login_update"] > 3600) {
844 db_query($this->link
, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
846 $_SESSION["last_login_update"] = time();
849 if (!$cat_view && is_numeric($feed) && $feed > 0) {
850 db_query($this->link
, "UPDATE ttrss_feeds SET last_viewed = NOW()
851 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
854 $reply['headlines'] = array();
856 if (!$next_unread_feed)
857 $reply['headlines']['id'] = $feed;
859 $reply['headlines']['id'] = $next_unread_feed;
861 $reply['headlines']['is_cat'] = (bool) $cat_view;
863 $override_order = false;
867 $override_order = "date_entered DESC, updated";
870 $override_order = "updated DESC";
874 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
876 $ret = $this->format_headlines_list($feed, $method,
877 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
878 $vgroup_last_feed, $override_order, true);
880 //$topmost_article_ids = $ret[0];
881 $headlines_count = $ret[1];
882 $returned_feed = $ret[2];
883 $disable_cache = $ret[3];
884 $vgroup_last_feed = $ret[4];
886 $reply['headlines']['content'] =& $ret[5]['content'];
887 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
889 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
891 $reply['headlines-info'] = array("count" => (int) $headlines_count,
892 "vgroup_last_feed" => $vgroup_last_feed,
893 "disable_cache" => (bool) $disable_cache);
895 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
897 $reply['runtime-info'] = make_runtime_info($this->link
);
899 print json_encode($reply);
903 private function generate_dashboard_feed($link) {
906 $reply['headlines']['id'] = -5;
907 $reply['headlines']['is_cat'] = false;
909 $reply['headlines']['toolbar'] = '';
910 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
912 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
914 $result = db_query($link, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
915 WHERE owner_uid = " . $_SESSION['uid']);
917 $last_updated = db_fetch_result($result, 0, "last_updated");
918 $last_updated = make_local_datetime($link, $last_updated, false);
920 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
922 $result = db_query($link, "SELECT COUNT(id) AS num_errors
923 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
925 $num_errors = db_fetch_result($result, 0, "num_errors");
927 if ($num_errors > 0) {
928 $reply['headlines']['content'] .= "<br/>";
929 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
930 __('Some feeds have update errors (click for details)')."</a>";
932 $reply['headlines']['content'] .= "</span></p>";
934 $reply['headlines-info'] = array("count" => 0,
935 "vgroup_last_feed" => '',
937 "disable_cache" => true);
942 private function generate_error_feed($link, $error) {
945 $reply['headlines']['id'] = -6;
946 $reply['headlines']['is_cat'] = false;
948 $reply['headlines']['toolbar'] = '';
949 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
951 $reply['headlines-info'] = array("count" => 0,
952 "vgroup_last_feed" => '',
954 "disable_cache" => true);