]>
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 == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
181 include "rssfuncs.php";
182 update_rss_feed($this->link
, $feed, true);
185 if ($method_split[0] == "MarkAllReadGR") {
186 catchup_feed($this->link
, $method_split[1], false);
189 // FIXME: might break tag display?
191 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
192 $result = db_query($this->link
,
193 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
195 if (db_num_rows($result) == 0) {
196 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
200 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
202 $result = db_query($this->link
, "SELECT rtl_content FROM ttrss_feeds
203 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
205 if (db_num_rows($result) == 1) {
206 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
208 $rtl_content = false;
212 $rtl_tag = "dir=\"RTL\"";
218 $rtl_content = false;
221 @$search = db_escape_string($_REQUEST["query"]);
224 $disable_cache = true;
227 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
228 @$match_on = db_escape_string($_REQUEST["match_on"]);
234 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
236 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
237 if( $search_mode == '' && $method != '' ){
238 $search_mode = $method;
240 // error_log("search_mode: " . $search_mode);
241 $qfh_ret = queryFeedHeadlines($this->link
, $feed, $limit, $view_mode, $cat_view,
242 $search, $search_mode, $match_on, $override_order, $offset);
244 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
246 $result = $qfh_ret[0];
247 $feed_title = $qfh_ret[1];
248 $feed_site_url = $qfh_ret[2];
249 $last_error = $qfh_ret[3];
251 $vgroup_last_feed = $vgr_last_feed;
255 if (db_num_rows($result) > 0) {
256 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
258 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
263 $headlines_count = db_num_rows($result);
265 if (get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
266 $button_plugins = array();
267 foreach (explode(",", ARTICLE_BUTTON_PLUGINS
) as $p) {
268 $pclass = trim("${p}_button");
270 if (class_exists($pclass)) {
271 $plugin = new $pclass($link);
272 array_push($button_plugins, $plugin);
277 if (db_num_rows($result) > 0) {
282 $cur_feed_title = '';
284 $fresh_intl = get_pref($this->link
, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
286 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
288 while ($line = db_fetch_assoc($result)) {
290 $class = ($lnum %
2) ?
"even" : "odd";
293 $feed_id = $line["feed_id"];
294 $label_cache = $line["label_cache"];
298 $label_cache = json_decode($label_cache, true);
301 if ($label_cache["no-labels"] == 1)
304 $labels = $label_cache;
308 if (!is_array($labels)) $labels = get_article_labels($this->link
, $id);
310 $labels_str = "<span id=\"HLLCTR-$id\">";
311 $labels_str .= format_article_labels($labels, $id);
312 $labels_str .= "</span>";
314 if (count($topmost_article_ids) < 3) {
315 array_push($topmost_article_ids, $id);
318 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
320 $update_pic = "<img id='FUPDPIC-$id' src=\"".
321 theme_image($this->link
, 'images/updated.png')."\"
324 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
328 if (sql_bool_to_bool($line["unread"]) &&
329 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
331 $update_pic = "<img id='FUPDPIC-$id' src=\"".
332 theme_image($this->link
, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
335 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
343 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
344 $marked_pic = "<img id=\"FMPIC-$id\"
345 src=\"".theme_image($this->link
, 'images/mark_set.png')."\"
346 class=\"markedPic\" alt=\"Unstar article\"
347 onclick='javascript:toggleMark($id)'>";
349 $marked_pic = "<img id=\"FMPIC-$id\"
350 src=\"".theme_image($this->link
, 'images/mark_unset.png')."\"
351 class=\"markedPic\" alt=\"Star article\"
352 onclick='javascript:toggleMark($id)'>";
355 if ($line["published"] == "t" ||
$line["published"] == "1") {
356 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
357 'images/pub_set.png')."\"
359 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
361 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
362 'images/pub_unset.png')."\"
364 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
367 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
368 # $line["title"] . "</a>";
370 # $content_link = "<a
371 # href=\"" . htmlspecialchars($line["link"]) . "\"
372 # onclick=\"view($id,$feed_id);\">" .
373 # $line["title"] . "</a>";
375 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
376 # $line["title"] . "</a>";
378 $updated_fmt = make_local_datetime($this->link
, $line["updated_noms"], false);
380 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
381 $content_preview = truncate_string(strip_tags($line["content_preview"]),
385 $score = $line["score"];
387 $score_pic = theme_image($this->link
,
388 "images/" . get_score_pic($score));
390 /* $score_title = __("(Click to change)");
391 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
392 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
394 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
399 } else if ($score < -100) {
405 $entry_author = $line["author"];
408 $entry_author = " - $entry_author";
411 $has_feed_icon = feed_has_icon($feed_id);
413 if ($has_feed_icon) {
414 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
416 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
419 if (!get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
421 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
422 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
424 $cur_feed_title = $line["feed_title"];
425 $vgroup_last_feed = $feed_id;
427 $cur_feed_title = htmlspecialchars($cur_feed_title);
429 $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
431 $reply['content'] .= "<div class='cdmFeedTitle'>".
432 "<div style=\"float : right\">$feed_icon_img</div>".
433 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
434 $line["feed_title"]."</a> $vf_catchup_link</div>";
439 $mouseover_attrs = "onmouseover='postMouseIn($id)'
440 onmouseout='postMouseOut($id)'";
442 $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
444 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
446 $reply['content'] .= "<div class='hlLeft'>";
448 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
451 $reply['content'] .= "$marked_pic";
452 $reply['content'] .= "$published_pic";
454 $reply['content'] .= "</div>";
456 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
457 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
458 $reply['content'] .= "<a id=\"RTITLE-$id\"
459 href=\"" . htmlspecialchars($line["link"]) . "\"
461 truncate_string($line["title"], 200);
463 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
464 if ($content_preview) {
465 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
469 $reply['content'] .= "</a></span>";
471 $reply['content'] .= $labels_str;
473 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
474 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
475 if (@$line["feed_title"]) {
476 $reply['content'] .= "<span class=\"hlFeed\">
477 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
478 $line["feed_title"]."</a>)
483 $reply['content'] .= "</div>";
485 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
486 $reply['content'] .= "<div class=\"hlRight\">";
488 $reply['content'] .= $score_pic;
490 if ($line["feed_title"] && !get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
492 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
493 style=\"cursor : pointer\"
494 title=\"".htmlspecialchars($line['feed_title'])."\">
495 $feed_icon_img<span>";
498 $reply['content'] .= "</div>";
499 $reply['content'] .= "</div>";
503 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
504 if ($feed_id != $vgroup_last_feed) {
506 $cur_feed_title = $line["feed_title"];
507 $vgroup_last_feed = $feed_id;
509 $cur_feed_title = htmlspecialchars($cur_feed_title);
511 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
513 $has_feed_icon = feed_has_icon($feed_id);
515 if ($has_feed_icon) {
516 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
518 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
521 $reply['content'] .= "<div class='cdmFeedTitle'>".
522 "<div style=\"float : right\">$feed_icon_img</div>".
523 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
524 $line["feed_title"]."</a> $vf_catchup_link</div>";
528 $expand_cdm = get_pref($this->link
, 'CDM_EXPANDED');
530 $mouseover_attrs = "onmouseover='postMouseIn($id)'
531 onmouseout='postMouseOut($id)'";
533 $reply['content'] .= "<div class=\"$class\"
534 id=\"RROW-$id\" $mouseover_attrs'>";
536 $reply['content'] .= "<div class=\"cdmHeader\">";
538 $reply['content'] .= "<div>";
540 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
541 'RROW-$id')\" id=\"RCHK-$id\"/>";
543 $reply['content'] .= "$marked_pic";
544 $reply['content'] .= "$published_pic";
546 $reply['content'] .= "</div>";
548 $reply['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .
549 strip_tags($line['title']) . "</div>";
551 $reply['content'] .= "<span id=\"RTITLE-$id\"
552 onclick=\"return cdmClicked(event, $id);\"
553 class=\"titleWrap$hlc_suffix\">
555 title=\"".htmlspecialchars($line['title'])."\"
556 target=\"_blank\" href=\"".
557 htmlspecialchars($line["link"])."\">".
558 truncate_string($line["title"], 100) .
559 " $entry_author</a>";
561 $reply['content'] .= $labels_str;
563 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
564 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
565 if (@$line["feed_title"]) {
566 $reply['content'] .= "<span class=\"hlFeed\">
567 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
568 $line["feed_title"]."</a>)
574 $content_hidden = "style=\"display : none\"";
576 $excerpt_hidden = "style=\"display : none\"";
578 $reply['content'] .= "<span $excerpt_hidden
579 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
581 $reply['content'] .= "</span>";
583 $reply['content'] .= "<div>";
584 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
585 $reply['content'] .= "$score_pic";
587 if (!get_pref($this->link
, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
588 $reply['content'] .= "<span style=\"cursor : pointer\"
589 title=\"".htmlspecialchars($line["feed_title"])."\"
590 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
592 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
593 $reply['content'] .= "</div>";
595 $reply['content'] .= "</div>";
597 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
598 onclick=\"return cdmClicked(event, $id);\"
601 $reply['content'] .= "<div class=\"cdmContentInner\">";
603 if ($line["orig_feed_id"]) {
605 $tmp_result = db_query($this->link
, "SELECT * FROM ttrss_archived_feeds
606 WHERE id = ".$line["orig_feed_id"]);
608 if (db_num_rows($tmp_result) != 0) {
610 $reply['content'] .= "<div clear='both'>";
611 $reply['content'] .= __("Originally from:");
613 $reply['content'] .= " ";
615 $tmp_line = db_fetch_assoc($tmp_result);
617 $reply['content'] .= "<a target='_blank'
618 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
619 $tmp_line['title'] . "</a>";
621 $reply['content'] .= " ";
623 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
624 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";
626 $reply['content'] .= "</div>";
630 $feed_site_url = $line["site_url"];
632 $article_content = sanitize($this->link
, $line["content_preview"],
633 false, false, $feed_site_url);
635 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
637 $reply['content'] .= format_article_note($id, $line['note']);
639 $reply['content'] .= "</div>";
641 $reply['content'] .= "<span id=\"CWRAP-$id\">";
642 $reply['content'] .= $expand_cdm ?
$article_content : '';
643 $reply['content'] .= "</span>";
645 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
646 ttrss_feeds WHERE id = ".
647 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
648 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
650 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
651 0, "always_display_enclosures")); */
653 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
655 $reply['content'] .= format_article_enclosures($this->link
, $id, $always_display_enclosures,
658 $reply['content'] .= "</div>";
660 $reply['content'] .= "<div class=\"cdmFooter\">";
662 $tag_cache = $line["tag_cache"];
664 $tags_str = format_tags_string(
665 get_article_tags($this->link
, $id, $_SESSION["uid"], $tag_cache),
668 $reply['content'] .= "<img src='".theme_image($this->link
,
669 'images/tag.png')."' alt='Tags' title='Tags'>
670 <span id=\"ATSTR-$id\">$tags_str</span>
671 <a title=\"".__('Edit tags for this article')."\"
672 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
674 $num_comments = $line["num_comments"];
675 $entry_comments = "";
677 if ($num_comments > 0) {
678 if ($line["comments"]) {
679 $comments_url = $line["comments"];
681 $comments_url = $line["link"];
683 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
685 if ($line["comments"] && $line["link"] != $line["comments"]) {
686 $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";
690 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
692 $reply['content'] .= "<div style=\"float : right\">";
694 $reply['content'] .= "<img src=\"images/art-zoom.png\"
695 onclick=\"zoomToArticle(event, $id)\"
696 style=\"cursor : pointer\"
698 title='".__('Open article in new tab')."'>";
700 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
702 foreach ($button_plugins as $p) {
703 $reply['content'] .= $p->render($id, $line);
706 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
707 style=\"cursor : pointer\" style=\"cursor : pointer\"
708 onclick=\"dismissArticle($id)\"
709 title='".__('Close article')."'>";
711 $reply['content'] .= "</div>";
712 $reply['content'] .= "</div>";
714 $reply['content'] .= "</div>";
716 $reply['content'] .= "</div>";
723 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
728 switch ($view_mode) {
730 $message = __("No unread articles found to display.");
733 $message = __("No updated articles found to display.");
736 $message = __("No starred articles found to display.");
740 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
742 $message = __("No articles found to display.");
746 if (!$offset && $message) {
747 $reply['content'] .= "<div class='whiteBox'>$message";
749 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
751 $result = db_query($this->link
, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
752 WHERE owner_uid = " . $_SESSION['uid']);
754 $last_updated = db_fetch_result($result, 0, "last_updated");
755 $last_updated = make_local_datetime($this->link
, $last_updated, false);
757 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
759 $result = db_query($this->link
, "SELECT COUNT(id) AS num_errors
760 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
762 $num_errors = db_fetch_result($result, 0, "num_errors");
764 if ($num_errors > 0) {
765 $reply['content'] .= "<br/>";
766 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
767 __('Some feeds have update errors (click for details)')."</a>";
769 $reply['content'] .= "</span></p></div>";
773 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
775 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
776 $vgroup_last_feed, $reply);
779 private function outputFeedList($special = true) {
783 $enable_cats = get_pref($this->link
, 'ENABLE_FEED_CATS');
785 $feedlist['identifier'] = 'id';
786 $feedlist['label'] = 'name';
787 $feedlist['items'] = array();
789 $owner_uid = $_SESSION["uid"];
796 $cat_hidden = get_pref($this->link
, "_COLLAPSED_SPECIAL");
797 $cat = $this->feedlist_init_cat(-1, $cat_hidden);
799 $cat['items'] = array();
802 foreach (array(-4, -3, -1, -2, 0) as $i) {
803 array_push($cat['items'], $this->feedlist_init_feed($i));
807 array_push($feedlist['items'], $cat);
809 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
812 $result = db_query($this->link
, "SELECT * FROM
813 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
815 if (db_num_rows($result) > 0) {
817 if (get_pref($this->link
, 'ENABLE_FEED_CATS')) {
818 $cat_hidden = get_pref($this->link
, "_COLLAPSED_LABELS");
819 $cat = $this->feedlist_init_cat(-2, $cat_hidden);
821 $cat['items'] = array();
824 while ($line = db_fetch_assoc($result)) {
826 $label_id = -$line['id'] - 11;
827 $count = getFeedUnread($this->link
, $label_id);
829 $feed = $this->feedlist_init_feed($label_id, false, $count);
831 $feed['fg_color'] = $line['fg_color'];
832 $feed['bg_color'] = $line['bg_color'];
834 array_push($cat['items'], $feed);
838 array_push($feedlist['items'], $cat);
840 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
845 /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
846 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
847 $order_by_qpart = "order_id,category,unread DESC,title";
849 $order_by_qpart = "order_id,category,title";
852 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
853 $order_by_qpart = "unread DESC,title";
855 $order_by_qpart = "title";
862 $order_by_qpart = "ttrss_feed_categories.order_id,category,
863 ttrss_feeds.order_id,title";
865 $order_by_qpart = "title";
867 $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
868 ".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated_noms,
870 COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS category,
871 ttrss_feed_categories.collapsed,
873 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
874 ON (ttrss_feed_categories.id = cat_id)
875 LEFT JOIN ttrss_counters_cache
877 (ttrss_feeds.id = feed_id)
879 ttrss_feeds.owner_uid = '$owner_uid'
880 ORDER BY $order_by_qpart";
882 $result = db_query($this->link
, $query);
884 $actid = $_REQUEST["actid"];
886 if (db_num_rows($result) > 0) {
891 $cat['items'] = array();
895 while ($line = db_fetch_assoc($result)) {
897 $feed = htmlspecialchars(trim($line["title"]));
899 if (!$feed) $feed = "[Untitled]";
901 $feed_id = $line["id"];
902 $unread = $line["unread"];
904 $cat_id = $line["cat_id"];
905 $tmp_category = $line["category"];
907 if ($category != $tmp_category && $enable_cats) {
909 $category = $tmp_category;
911 $collapsed = sql_bool_to_bool($line["collapsed"]);
913 // workaround for NULL category
914 if ($category == __("Uncategorized")) {
915 $collapsed = get_pref($this->link
, "_COLLAPSED_UNCAT");
918 if ($cat) array_push($feedlist['items'], $cat);
920 $cat = $this->feedlist_init_cat($cat_id, $collapsed);
923 $updated = make_local_datetime($this->link
, $line["updated_noms"], false);
925 array_push($cat['items'], $this->feedlist_init_feed($feed_id,
926 $feed, $unread, $line['last_error'], $updated));
930 array_push($feedlist['items'], $cat);
932 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
941 function catchupAll() {
942 db_query($this->link
, "UPDATE ttrss_user_entries SET
943 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
944 ccache_zero_all($this->link
, $_SESSION["uid"]);
947 function collapse() {
948 $cat_id = db_escape_string($_REQUEST["cid"]);
949 $mode = (int) db_escape_string($_REQUEST['mode']);
950 toggle_collapse_cat($this->link
, $cat_id, $mode);
954 $root = (bool)$_REQUEST["root"];
957 print json_encode($this->outputFeedList($this->link
));
960 $feeds = $this->outputFeedList($this->link
, false);
963 $root['id'] = 'root';
964 $root['name'] = __('Feeds');
965 $root['items'] = $feeds['items'];
968 $fl['identifier'] = 'id';
969 $fl['label'] = 'name';
970 $fl['items'] = array($root);
972 print json_encode($fl);
977 $timing_info = getmicrotime();
981 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
983 $omode = db_escape_string($_REQUEST["omode"]);
985 $feed = db_escape_string($_REQUEST["feed"]);
986 $method = db_escape_string($_REQUEST["m"]);
987 $view_mode = db_escape_string($_REQUEST["view_mode"]);
988 $limit = (int) get_pref($this->link
, "DEFAULT_ARTICLE_LIMIT");
989 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
990 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
991 @$offset = db_escape_string($_REQUEST["skip"]);
992 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
993 $order_by = db_escape_string($_REQUEST["order_by"]);
995 if (is_numeric($feed)) $feed = (int) $feed;
997 /* Feed -5 is a special case: it is used to display auxiliary information
998 * when there's nothing to load - e.g. no stuff in fresh feed */
1001 print json_encode(generate_dashboard_feed($this->link
));
1008 $label_feed = -11-$feed;
1009 $result = db_query($this->link
, "SELECT id FROM ttrss_labels2 WHERE
1010 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
1011 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
1012 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
1013 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1014 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
1015 $result = db_query($this->link
, "SELECT id FROM ttrss_feed_categories WHERE
1016 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1019 if ($result && db_num_rows($result) == 0) {
1020 print json_encode(generate_error_feed($this->link
, __("Feed not found.")));
1024 /* Updating a label ccache means recalculating all of the caches
1025 * so for performance reasons we don't do that here */
1028 ccache_update($this->link
, $feed, $_SESSION["uid"], $cat_view);
1031 set_pref($this->link
, "_DEFAULT_VIEW_MODE", $view_mode);
1032 set_pref($this->link
, "_DEFAULT_VIEW_LIMIT", $limit);
1033 set_pref($this->link
, "_DEFAULT_VIEW_ORDER_BY", $order_by);
1035 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
1036 db_query($this->link
, "UPDATE ttrss_feeds SET last_viewed = NOW()
1037 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
1040 $reply['headlines'] = array();
1042 if (!$next_unread_feed)
1043 $reply['headlines']['id'] = $feed;
1045 $reply['headlines']['id'] = $next_unread_feed;
1047 $reply['headlines']['is_cat'] = (bool) $cat_view;
1049 $override_order = false;
1051 if (get_pref($this->link
, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
1052 $date_sort_field = "updated";
1054 $date_sort_field = "date_entered";
1057 switch ($order_by) {
1059 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1060 $override_order = "$date_sort_field";
1062 $override_order = "$date_sort_field DESC";
1067 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1068 $override_order = "title DESC, $date_sort_field";
1070 $override_order = "title, $date_sort_field DESC";
1075 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1076 $override_order = "score, $date_sort_field";
1078 $override_order = "score DESC, $date_sort_field DESC";
1083 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
1085 $ret = $this->format_headlines_list($feed, $method,
1086 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
1087 $vgroup_last_feed, $override_order);
1089 $topmost_article_ids = $ret[0];
1090 $headlines_count = $ret[1];
1091 $returned_feed = $ret[2];
1092 $disable_cache = $ret[3];
1093 $vgroup_last_feed = $ret[4];
1095 $reply['headlines']['content'] =& $ret[5]['content'];
1096 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
1098 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
1100 $reply['headlines-info'] = array("count" => (int) $headlines_count,
1101 "vgroup_last_feed" => $vgroup_last_feed,
1102 "disable_cache" => (bool) $disable_cache);
1104 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
1106 if (is_array($topmost_article_ids) && !get_pref($this->link
, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
1107 $articles = array();
1109 foreach ($topmost_article_ids as $id) {
1110 array_push($articles, format_article($this->link
, $id, false));
1113 $reply['articles'] = $articles;
1116 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
1118 $reply['runtime-info'] = make_runtime_info($this->link
);
1120 print json_encode($reply);