]>
git.wh0rd.org - tt-rss.git/blob - classes/feeds.php
2 class Feeds
extends Protected_Handler
{
4 function csrf_ignore($method) {
5 $csrf_ignored = array("index");
7 return array_search($method, $csrf_ignored) !== false;
10 private function feedlist_init_cat($cat_id, $hidden = false) {
12 $cat_id = (int) $cat_id;
15 $cat_unread = ccache_find($this->link
, $cat_id, $_SESSION["uid"], true);
16 } else if ($cat_id == 0 ||
$cat_id == -2) {
17 $cat_unread = getCategoryUnread($this->link
, $cat_id);
20 $obj['id'] = 'CAT:' . $cat_id;
21 $obj['items'] = array();
22 $obj['name'] = getCategoryTitle($this->link
, $cat_id);
23 $obj['type'] = 'feed';
24 $obj['unread'] = (int) $cat_unread;
25 $obj['hidden'] = $hidden;
26 $obj['bare_id'] = $cat_id;
31 private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
33 $feed_id = (int) $feed_id;
36 $title = getFeedTitle($this->link
, $feed_id, false);
38 if ($unread === false)
39 $unread = getFeedUnread($this->link
, $feed_id, false);
41 $obj['id'] = 'FEED:' . $feed_id;
42 $obj['name'] = $title;
43 $obj['unread'] = (int) $unread;
44 $obj['type'] = 'feed';
45 $obj['error'] = $error;
46 $obj['updated'] = $updated;
47 $obj['icon'] = getFeedIcon($feed_id);
48 $obj['bare_id'] = $feed_id;
53 private function format_headline_subtoolbar($feed_site_url, $feed_title,
54 $feed_id, $is_cat, $search, $match_on,
55 $search_mode, $view_mode, $error) {
57 $page_prev_link = "viewFeedGoPage(-1)";
58 $page_next_link = "viewFeedGoPage(1)";
59 $page_first_link = "viewFeedGoPage(0)";
61 $catchup_page_link = "catchupPage()";
62 $catchup_feed_link = "catchupCurrentFeed()";
63 $catchup_sel_link = "catchupSelection()";
65 $archive_sel_link = "archiveSelection()";
66 $delete_sel_link = "deleteSelection()";
68 $sel_all_link = "selectArticles('all')";
69 $sel_unread_link = "selectArticles('unread')";
70 $sel_none_link = "selectArticles('none')";
71 $sel_inv_link = "selectArticles('invert')";
73 $tog_unread_link = "selectionToggleUnread()";
74 $tog_marked_link = "selectionToggleMarked()";
75 $tog_published_link = "selectionTogglePublished()";
77 if ($is_cat) $cat_q = "&is_cat=$is_cat";
80 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
85 $rss_link = htmlspecialchars(get_self_url_prefix() .
86 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
90 $reply .= "<span class='r'>";
93 $target = "target=\"_blank\"";
94 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
95 truncate_string($feed_title,30)."</a>";
98 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
102 $reply .= $feed_title;
107 title=\"".__("View as RSS feed")."\"
108 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
109 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
115 $reply .= __('Select:')."
116 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
117 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
118 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
119 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
123 $reply .= "<select dojoType=\"dijit.form.Select\"
124 onchange=\"headlineActionsChange(this)\">";
125 $reply .= "<option value=\"false\">".__('Actions...')."</option>";
127 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
129 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
130 <option value=\"$tog_marked_link\">".__('Starred')."</option>
131 <option value=\"$tog_published_link\">".__('Published')."</option>";
133 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
135 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
137 if ($feed_id != "0") {
138 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
140 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
141 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
145 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
148 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
150 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
152 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
154 $reply .= "</select>";
156 //$reply .= "</div>";
163 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
164 $next_unread_feed, $offset, $vgr_last_feed = false,
165 $override_order = false) {
167 $disable_cache = false;
171 $timing_info = getmicrotime();
173 $topmost_article_ids = array();
175 if (!$offset) $offset = 0;
176 if ($method == "undefined") $method = "";
178 $method_split = explode(":", $method);
180 /* if ($method == "CatchupSelected") {
181 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
182 $cmode = sprintf("%d", $_REQUEST["cmode"]);
184 catchupArticlesById($this->link, $ids, $cmode);
187 if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
188 include "rssfuncs.php";
189 update_rss_feed($this->link
, $feed, true);
192 if ($method == "MarkAllRead") {
193 catchup_feed($this->link
, $feed, $cat_view);
195 if (get_pref($this->link
, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
196 if ($next_unread_feed) {
197 $feed = $next_unread_feed;
202 if ($method_split[0] == "MarkAllReadGR") {
203 catchup_feed($this->link
, $method_split[1], false);
206 // FIXME: might break tag display?
208 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
209 $result = db_query($this->link
,
210 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
212 if (db_num_rows($result) == 0) {
213 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
217 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
219 $result = db_query($this->link
, "SELECT rtl_content FROM ttrss_feeds
220 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
222 if (db_num_rows($result) == 1) {
223 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
225 $rtl_content = false;
229 $rtl_tag = "dir=\"RTL\"";
235 $rtl_content = false;
238 @$search = db_escape_string($_REQUEST["query"]);
241 $disable_cache = true;
244 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
245 @$match_on = db_escape_string($_REQUEST["match_on"]);
251 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
253 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
254 if( $search_mode == '' && $method != '' ){
255 $search_mode = $method;
257 // error_log("search_mode: " . $search_mode);
258 $qfh_ret = queryFeedHeadlines($this->link
, $feed, $limit, $view_mode, $cat_view,
259 $search, $search_mode, $match_on, $override_order, $offset);
261 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
263 $result = $qfh_ret[0];
264 $feed_title = $qfh_ret[1];
265 $feed_site_url = $qfh_ret[2];
266 $last_error = $qfh_ret[3];
268 $vgroup_last_feed = $vgr_last_feed;
272 if (db_num_rows($result) > 0) {
273 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
275 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
280 $headlines_count = db_num_rows($result);
282 if (get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
283 $button_plugins = array();
284 foreach (explode(",", ARTICLE_BUTTON_PLUGINS
) as $p) {
285 $pclass = trim("${p}_button");
287 if (class_exists($pclass)) {
288 $plugin = new $pclass($link);
289 array_push($button_plugins, $plugin);
294 if (db_num_rows($result) > 0) {
299 $cur_feed_title = '';
301 $fresh_intl = get_pref($this->link
, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
303 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
305 while ($line = db_fetch_assoc($result)) {
307 $class = ($lnum %
2) ?
"even" : "odd";
310 $feed_id = $line["feed_id"];
311 $label_cache = $line["label_cache"];
315 $label_cache = json_decode($label_cache, true);
318 if ($label_cache["no-labels"] == 1)
321 $labels = $label_cache;
325 if (!is_array($labels)) $labels = get_article_labels($this->link
, $id);
327 $labels_str = "<span id=\"HLLCTR-$id\">";
328 $labels_str .= format_article_labels($labels, $id);
329 $labels_str .= "</span>";
331 if (count($topmost_article_ids) < 3) {
332 array_push($topmost_article_ids, $id);
335 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
337 $update_pic = "<img id='FUPDPIC-$id' src=\"".
338 theme_image($this->link
, 'images/updated.png')."\"
341 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
345 if (sql_bool_to_bool($line["unread"]) &&
346 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
348 $update_pic = "<img id='FUPDPIC-$id' src=\"".
349 theme_image($this->link
, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
352 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
360 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
361 $marked_pic = "<img id=\"FMPIC-$id\"
362 src=\"".theme_image($this->link
, 'images/mark_set.png')."\"
363 class=\"markedPic\" alt=\"Unstar article\"
364 onclick='javascript:toggleMark($id)'>";
366 $marked_pic = "<img id=\"FMPIC-$id\"
367 src=\"".theme_image($this->link
, 'images/mark_unset.png')."\"
368 class=\"markedPic\" alt=\"Star article\"
369 onclick='javascript:toggleMark($id)'>";
372 if ($line["published"] == "t" ||
$line["published"] == "1") {
373 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
374 'images/pub_set.png')."\"
376 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
378 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
379 'images/pub_unset.png')."\"
381 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
384 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
385 # $line["title"] . "</a>";
387 # $content_link = "<a
388 # href=\"" . htmlspecialchars($line["link"]) . "\"
389 # onclick=\"view($id,$feed_id);\">" .
390 # $line["title"] . "</a>";
392 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
393 # $line["title"] . "</a>";
395 $updated_fmt = make_local_datetime($this->link
, $line["updated_noms"], false);
397 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
398 $content_preview = truncate_string(strip_tags($line["content_preview"]),
402 $score = $line["score"];
404 $score_pic = theme_image($this->link
,
405 "images/" . get_score_pic($score));
407 /* $score_title = __("(Click to change)");
408 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
409 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
411 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
416 } else if ($score < -100) {
422 $entry_author = $line["author"];
425 $entry_author = " - $entry_author";
428 $has_feed_icon = feed_has_icon($feed_id);
430 if ($has_feed_icon) {
431 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
433 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
436 if (!get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
438 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
439 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
441 $cur_feed_title = $line["feed_title"];
442 $vgroup_last_feed = $feed_id;
444 $cur_feed_title = htmlspecialchars($cur_feed_title);
446 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
448 $reply['content'] .= "<div class='cdmFeedTitle'>".
449 "<div style=\"float : right\">$feed_icon_img</div>".
450 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
451 $line["feed_title"]."</a> $vf_catchup_link</div>";
456 $mouseover_attrs = "onmouseover='postMouseIn($id)'
457 onmouseout='postMouseOut($id)'";
459 $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
461 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
463 $reply['content'] .= "<div class='hlLeft'>";
465 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
468 $reply['content'] .= "$marked_pic";
469 $reply['content'] .= "$published_pic";
471 $reply['content'] .= "</div>";
473 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
474 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
475 $reply['content'] .= "<a id=\"RTITLE-$id\"
476 href=\"" . htmlspecialchars($line["link"]) . "\"
478 truncate_string($line["title"], 200);
480 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
481 if ($content_preview) {
482 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
486 $reply['content'] .= "</a></span>";
488 $reply['content'] .= $labels_str;
490 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
491 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
492 if (@$line["feed_title"]) {
493 $reply['content'] .= "<span class=\"hlFeed\">
494 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
495 $line["feed_title"]."</a>)
500 $reply['content'] .= "</div>";
502 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
503 $reply['content'] .= "<div class=\"hlRight\">";
505 $reply['content'] .= $score_pic;
507 if ($line["feed_title"] && !get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
509 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
510 style=\"cursor : pointer\"
511 title=\"".htmlspecialchars($line['feed_title'])."\">
512 $feed_icon_img<span>";
515 $reply['content'] .= "</div>";
516 $reply['content'] .= "</div>";
520 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
521 if ($feed_id != $vgroup_last_feed) {
523 $cur_feed_title = $line["feed_title"];
524 $vgroup_last_feed = $feed_id;
526 $cur_feed_title = htmlspecialchars($cur_feed_title);
528 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
530 $has_feed_icon = feed_has_icon($feed_id);
532 if ($has_feed_icon) {
533 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
535 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
538 $reply['content'] .= "<div class='cdmFeedTitle'>".
539 "<div style=\"float : right\">$feed_icon_img</div>".
540 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
541 $line["feed_title"]."</a> $vf_catchup_link</div>";
545 $expand_cdm = get_pref($this->link
, 'CDM_EXPANDED');
547 $mouseover_attrs = "onmouseover='postMouseIn($id)'
548 onmouseout='postMouseOut($id)'";
550 $reply['content'] .= "<div class=\"$class\"
551 id=\"RROW-$id\" $mouseover_attrs'>";
553 $reply['content'] .= "<div class=\"cdmHeader\">";
555 $reply['content'] .= "<div>";
557 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
558 'RROW-$id')\" id=\"RCHK-$id\"/>";
560 $reply['content'] .= "$marked_pic";
561 $reply['content'] .= "$published_pic";
563 $reply['content'] .= "</div>";
565 $reply['content'] .= "<span id=\"RTITLE-$id\"
566 onclick=\"return cdmClicked(event, $id);\"
567 class=\"titleWrap$hlc_suffix\">
569 title=\"".htmlspecialchars($line['title'])."\"
570 target=\"_blank\" href=\"".
571 htmlspecialchars($line["link"])."\">".
572 truncate_string($line["title"], 100) .
573 " $entry_author</a>";
575 $reply['content'] .= $labels_str;
577 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
578 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
579 if (@$line["feed_title"]) {
580 $reply['content'] .= "<span class=\"hlFeed\">
581 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
582 $line["feed_title"]."</a>)
588 $content_hidden = "style=\"display : none\"";
590 $excerpt_hidden = "style=\"display : none\"";
592 $reply['content'] .= "<span $excerpt_hidden
593 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
595 $reply['content'] .= "</span>";
597 $reply['content'] .= "<div>";
598 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
599 $reply['content'] .= "$score_pic";
601 if (!get_pref($this->link
, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
602 $reply['content'] .= "<span style=\"cursor : pointer\"
603 title=\"".htmlspecialchars($line["feed_title"])."\"
604 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
606 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
607 $reply['content'] .= "</div>";
609 $reply['content'] .= "</div>";
611 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
612 onclick=\"return cdmClicked(event, $id);\"
615 $reply['content'] .= "<div class=\"cdmContentInner\">";
617 if ($line["orig_feed_id"]) {
619 $tmp_result = db_query($this->link
, "SELECT * FROM ttrss_archived_feeds
620 WHERE id = ".$line["orig_feed_id"]);
622 if (db_num_rows($tmp_result) != 0) {
624 $reply['content'] .= "<div clear='both'>";
625 $reply['content'] .= __("Originally from:");
627 $reply['content'] .= " ";
629 $tmp_line = db_fetch_assoc($tmp_result);
631 $reply['content'] .= "<a target='_blank'
632 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
633 $tmp_line['title'] . "</a>";
635 $reply['content'] .= " ";
637 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
638 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";
640 $reply['content'] .= "</div>";
644 $feed_site_url = $line["site_url"];
646 $article_content = sanitize($this->link
, $line["content_preview"],
647 false, false, $feed_site_url);
649 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
651 $reply['content'] .= format_article_note($id, $line['note']);
653 $reply['content'] .= "</div>";
655 $reply['content'] .= "<span id=\"CWRAP-$id\">";
656 $reply['content'] .= $expand_cdm ?
$article_content : '';
657 $reply['content'] .= "</span>";
659 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
660 ttrss_feeds WHERE id = ".
661 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
662 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
664 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
665 0, "always_display_enclosures")); */
667 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
669 $reply['content'] .= format_article_enclosures($this->link
, $id, $always_display_enclosures,
672 $reply['content'] .= "</div>";
674 $reply['content'] .= "<div class=\"cdmFooter\">";
676 $tag_cache = $line["tag_cache"];
678 $tags_str = format_tags_string(
679 get_article_tags($this->link
, $id, $_SESSION["uid"], $tag_cache),
682 $reply['content'] .= "<img src='".theme_image($this->link
,
683 'images/tag.png')."' alt='Tags' title='Tags'>
684 <span id=\"ATSTR-$id\">$tags_str</span>
685 <a title=\"".__('Edit tags for this article')."\"
686 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
688 $num_comments = $line["num_comments"];
689 $entry_comments = "";
691 if ($num_comments > 0) {
692 if ($line["comments"]) {
693 $comments_url = $line["comments"];
695 $comments_url = $line["link"];
697 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
699 if ($line["comments"] && $line["link"] != $line["comments"]) {
700 $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";
704 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
706 $reply['content'] .= "<div style=\"float : right\">";
708 $reply['content'] .= "<img src=\"images/art-zoom.png\"
709 onclick=\"zoomToArticle(event, $id)\"
710 style=\"cursor : pointer\"
712 title='".__('Open article in new tab')."'>";
714 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
716 foreach ($button_plugins as $p) {
717 $reply['content'] .= $p->render($id, $line);
720 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
721 style=\"cursor : pointer\" style=\"cursor : pointer\"
722 onclick=\"dismissArticle($id)\"
723 title='".__('Close article')."'>";
725 $reply['content'] .= "</div>";
726 $reply['content'] .= "</div>";
728 $reply['content'] .= "</div>";
730 $reply['content'] .= "</div>";
737 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
742 switch ($view_mode) {
744 $message = __("No unread articles found to display.");
747 $message = __("No updated articles found to display.");
750 $message = __("No starred articles found to display.");
754 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
756 $message = __("No articles found to display.");
760 if (!$offset && $message) {
761 $reply['content'] .= "<div class='whiteBox'>$message";
763 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
765 $result = db_query($this->link
, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
766 WHERE owner_uid = " . $_SESSION['uid']);
768 $last_updated = db_fetch_result($result, 0, "last_updated");
769 $last_updated = make_local_datetime($this->link
, $last_updated, false);
771 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
773 $result = db_query($this->link
, "SELECT COUNT(id) AS num_errors
774 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
776 $num_errors = db_fetch_result($result, 0, "num_errors");
778 if ($num_errors > 0) {
779 $reply['content'] .= "<br/>";
780 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
781 __('Some feeds have update errors (click for details)')."</a>";
783 $reply['content'] .= "</span></p></div>";
787 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
789 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
790 $vgroup_last_feed, $reply);
793 private function outputFeedList($special = true) {
797 $enable_cats = get_pref($this->link
, 'ENABLE_FEED_CATS');
799 $feedlist['identifier'] = 'id';
800 $feedlist['label'] = 'name';
801 $feedlist['items'] = array();
803 $owner_uid = $_SESSION["uid"];
810 $cat_hidden = get_pref($this->link
, "_COLLAPSED_SPECIAL");
811 $cat = $this->feedlist_init_cat(-1, $cat_hidden);
813 $cat['items'] = array();
816 foreach (array(-4, -3, -1, -2, 0) as $i) {
817 array_push($cat['items'], $this->feedlist_init_feed($i));
821 array_push($feedlist['items'], $cat);
823 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
826 $result = db_query($this->link
, "SELECT * FROM
827 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
829 if (db_num_rows($result) > 0) {
831 if (get_pref($this->link
, 'ENABLE_FEED_CATS')) {
832 $cat_hidden = get_pref($this->link
, "_COLLAPSED_LABELS");
833 $cat = $this->feedlist_init_cat(-2, $cat_hidden);
835 $cat['items'] = array();
838 while ($line = db_fetch_assoc($result)) {
840 $label_id = -$line['id'] - 11;
841 $count = getFeedUnread($this->link
, $label_id);
843 $feed = $this->feedlist_init_feed($label_id, false, $count);
845 $feed['fg_color'] = $line['fg_color'];
846 $feed['bg_color'] = $line['bg_color'];
848 array_push($cat['items'], $feed);
852 array_push($feedlist['items'], $cat);
854 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
859 /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
860 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
861 $order_by_qpart = "order_id,category,unread DESC,title";
863 $order_by_qpart = "order_id,category,title";
866 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
867 $order_by_qpart = "unread DESC,title";
869 $order_by_qpart = "title";
876 $order_by_qpart = "ttrss_feed_categories.order_id,category,
877 ttrss_feeds.order_id,title";
879 $order_by_qpart = "title";
881 $age_qpart = getMaxAgeSubquery();
883 $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
884 ".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated_noms,
886 ttrss_feed_categories.title AS category,
887 ttrss_feed_categories.collapsed,
889 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
890 ON (ttrss_feed_categories.id = cat_id)
891 LEFT JOIN ttrss_counters_cache
893 (ttrss_feeds.id = feed_id)
895 ttrss_feeds.owner_uid = '$owner_uid'
896 ORDER BY $order_by_qpart";
898 $result = db_query($this->link
, $query);
900 $actid = $_REQUEST["actid"];
902 if (db_num_rows($result) > 0) {
907 $cat['items'] = array();
911 while ($line = db_fetch_assoc($result)) {
913 $feed = htmlspecialchars(trim($line["title"]));
915 if (!$feed) $feed = "[Untitled]";
917 $feed_id = $line["id"];
918 $unread = $line["unread"];
920 $cat_id = $line["cat_id"];
921 $tmp_category = $line["category"];
922 if (!$tmp_category) $tmp_category = __("Uncategorized");
924 if ($category != $tmp_category && $enable_cats) {
926 $category = $tmp_category;
928 $collapsed = sql_bool_to_bool($line["collapsed"]);
930 // workaround for NULL category
931 if ($category == __("Uncategorized")) {
932 $collapsed = get_pref($this->link
, "_COLLAPSED_UNCAT");
935 if ($cat) array_push($feedlist['items'], $cat);
937 $cat = $this->feedlist_init_cat($cat_id, $collapsed);
940 $updated = make_local_datetime($this->link
, $line["updated_noms"], false);
942 array_push($cat['items'], $this->feedlist_init_feed($feed_id,
943 $feed, $unread, $line['last_error'], $updated));
947 array_push($feedlist['items'], $cat);
949 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
958 function catchupAll() {
959 db_query($this->link
, "UPDATE ttrss_user_entries SET
960 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
961 ccache_zero_all($this->link
, $_SESSION["uid"]);
964 function collapse() {
965 $cat_id = db_escape_string($_REQUEST["cid"]);
966 $mode = (int) db_escape_string($_REQUEST['mode']);
967 toggle_collapse_cat($this->link
, $cat_id, $mode);
971 $root = (bool)$_REQUEST["root"];
974 print json_encode($this->outputFeedList($this->link
));
977 $feeds = $this->outputFeedList($this->link
, false);
980 $root['id'] = 'root';
981 $root['name'] = __('Feeds');
982 $root['items'] = $feeds['items'];
985 $fl['identifier'] = 'id';
986 $fl['label'] = 'name';
987 $fl['items'] = array($root);
989 print json_encode($fl);
994 $timing_info = getmicrotime();
998 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
1000 $omode = db_escape_string($_REQUEST["omode"]);
1002 $feed = db_escape_string($_REQUEST["feed"]);
1003 $method = db_escape_string($_REQUEST["m"]);
1004 $view_mode = db_escape_string($_REQUEST["view_mode"]);
1005 $limit = (int) get_pref($this->link
, "DEFAULT_ARTICLE_LIMIT");
1006 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
1007 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
1008 @$offset = db_escape_string($_REQUEST["skip"]);
1009 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
1010 $order_by = db_escape_string($_REQUEST["order_by"]);
1012 if (is_numeric($feed)) $feed = (int) $feed;
1014 /* Feed -5 is a special case: it is used to display auxiliary information
1015 * when there's nothing to load - e.g. no stuff in fresh feed */
1018 print json_encode(generate_dashboard_feed($this->link
));
1025 $label_feed = -11-$feed;
1026 $result = db_query($this->link
, "SELECT id FROM ttrss_labels2 WHERE
1027 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
1028 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
1029 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
1030 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1031 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
1032 $result = db_query($this->link
, "SELECT id FROM ttrss_feed_categories WHERE
1033 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1036 if ($result && db_num_rows($result) == 0) {
1037 print json_encode(generate_error_feed($this->link
, __("Feed not found.")));
1041 /* Updating a label ccache means recalculating all of the caches
1042 * so for performance reasons we don't do that here */
1045 ccache_update($this->link
, $feed, $_SESSION["uid"], $cat_view);
1048 set_pref($this->link
, "_DEFAULT_VIEW_MODE", $view_mode);
1049 set_pref($this->link
, "_DEFAULT_VIEW_LIMIT", $limit);
1050 set_pref($this->link
, "_DEFAULT_VIEW_ORDER_BY", $order_by);
1052 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
1053 db_query($this->link
, "UPDATE ttrss_feeds SET last_viewed = NOW()
1054 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
1057 $reply['headlines'] = array();
1059 if (!$next_unread_feed)
1060 $reply['headlines']['id'] = $feed;
1062 $reply['headlines']['id'] = $next_unread_feed;
1064 $reply['headlines']['is_cat'] = (bool) $cat_view;
1066 $override_order = false;
1068 if (get_pref($this->link
, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
1069 $date_sort_field = "updated";
1071 $date_sort_field = "date_entered";
1074 switch ($order_by) {
1076 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1077 $override_order = "$date_sort_field";
1079 $override_order = "$date_sort_field DESC";
1084 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1085 $override_order = "title DESC, $date_sort_field";
1087 $override_order = "title, $date_sort_field DESC";
1092 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1093 $override_order = "score, $date_sort_field";
1095 $override_order = "score DESC, $date_sort_field DESC";
1100 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
1102 $ret = $this->format_headlines_list($feed, $method,
1103 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
1104 $vgroup_last_feed, $override_order);
1106 $topmost_article_ids = $ret[0];
1107 $headlines_count = $ret[1];
1108 $returned_feed = $ret[2];
1109 $disable_cache = $ret[3];
1110 $vgroup_last_feed = $ret[4];
1112 $reply['headlines']['content'] =& $ret[5]['content'];
1113 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
1115 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
1117 $reply['headlines-info'] = array("count" => (int) $headlines_count,
1118 "vgroup_last_feed" => $vgroup_last_feed,
1119 "disable_cache" => (bool) $disable_cache);
1121 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
1123 if (is_array($topmost_article_ids) && !get_pref($this->link
, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
1124 $articles = array();
1126 foreach ($topmost_article_ids as $id) {
1127 array_push($articles, format_article($this->link
, $id, false));
1130 $reply['articles'] = $articles;
1133 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
1135 $reply['runtime-info'] = make_runtime_info($this->link
);
1137 print json_encode($reply);