]>
git.wh0rd.org - tt-rss.git/blob - classes/feeds.php
2 class Feeds
extends Protected_Handler
{
4 private function feedlist_init_cat($cat_id, $hidden = false) {
6 $cat_id = (int) $cat_id;
9 $cat_unread = ccache_find($this->link
, $cat_id, $_SESSION["uid"], true);
10 } else if ($cat_id == 0 ||
$cat_id == -2) {
11 $cat_unread = getCategoryUnread($this->link
, $cat_id);
14 $obj['id'] = 'CAT:' . $cat_id;
15 $obj['items'] = array();
16 $obj['name'] = getCategoryTitle($this->link
, $cat_id);
17 $obj['type'] = 'feed';
18 $obj['unread'] = (int) $cat_unread;
19 $obj['hidden'] = $hidden;
20 $obj['bare_id'] = $cat_id;
25 private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
27 $feed_id = (int) $feed_id;
30 $title = getFeedTitle($this->link
, $feed_id, false);
32 if ($unread === false)
33 $unread = getFeedUnread($this->link
, $feed_id, false);
35 $obj['id'] = 'FEED:' . $feed_id;
36 $obj['name'] = $title;
37 $obj['unread'] = (int) $unread;
38 $obj['type'] = 'feed';
39 $obj['error'] = $error;
40 $obj['updated'] = $updated;
41 $obj['icon'] = getFeedIcon($feed_id);
42 $obj['bare_id'] = $feed_id;
47 private function format_headline_subtoolbar($feed_site_url, $feed_title,
48 $feed_id, $is_cat, $search, $match_on,
49 $search_mode, $view_mode, $error) {
51 $page_prev_link = "viewFeedGoPage(-1)";
52 $page_next_link = "viewFeedGoPage(1)";
53 $page_first_link = "viewFeedGoPage(0)";
55 $catchup_page_link = "catchupPage()";
56 $catchup_feed_link = "catchupCurrentFeed()";
57 $catchup_sel_link = "catchupSelection()";
59 $archive_sel_link = "archiveSelection()";
60 $delete_sel_link = "deleteSelection()";
62 $sel_all_link = "selectArticles('all')";
63 $sel_unread_link = "selectArticles('unread')";
64 $sel_none_link = "selectArticles('none')";
65 $sel_inv_link = "selectArticles('invert')";
67 $tog_unread_link = "selectionToggleUnread()";
68 $tog_marked_link = "selectionToggleMarked()";
69 $tog_published_link = "selectionTogglePublished()";
71 $reply = "<div id=\"subtoolbar_main\">";
73 $reply .= __('Select:')."
74 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
75 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
76 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
77 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
81 $reply .= "<select dojoType=\"dijit.form.Select\"
82 onchange=\"headlineActionsChange(this)\">";
83 $reply .= "<option value=\"false\">".__('Actions...')."</option>";
85 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
87 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
88 <option value=\"$tog_marked_link\">".__('Starred')."</option>
89 <option value=\"$tog_published_link\">".__('Published')."</option>";
91 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
93 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
95 if ($feed_id != "0") {
96 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
98 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
99 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
103 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
106 if ($is_cat) $cat_q = "&is_cat=$is_cat";
109 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
114 $rss_link = htmlspecialchars(get_self_url_prefix() .
115 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
117 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
119 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
121 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
123 $reply .= "</select>";
127 $reply .= "<div id=\"subtoolbar_ftitle\">";
129 if ($feed_site_url) {
130 $target = "target=\"_blank\"";
131 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
132 truncate_string($feed_title,30)."</a>";
135 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
139 if ($feed_id < -10) {
140 $label_id = -11-$feed_id;
142 $result = db_query($this->link
, "SELECT fg_color, bg_color
143 FROM ttrss_labels2 WHERE id = '$label_id' AND owner_uid = " .
146 if (db_num_rows($result) != 0) {
147 $fg_color = db_fetch_result($result, 0, "fg_color");
148 $bg_color = db_fetch_result($result, 0, "bg_color");
150 $reply .= "<span style=\"background : $bg_color; color : $fg_color\" >";
151 $reply .= $feed_title;
154 $reply .= $feed_title;
158 $reply .= $feed_title;
164 title=\"".__("View as RSS feed")."\"
165 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
166 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
173 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
174 $next_unread_feed, $offset, $vgr_last_feed = false,
175 $override_order = false) {
177 $disable_cache = false;
181 $timing_info = getmicrotime();
183 $topmost_article_ids = array();
185 if (!$offset) $offset = 0;
186 if ($method == "undefined") $method = "";
188 $method_split = explode(":", $method);
190 /* if ($method == "CatchupSelected") {
191 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
192 $cmode = sprintf("%d", $_REQUEST["cmode"]);
194 catchupArticlesById($this->link, $ids, $cmode);
197 //if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
198 // update_rss_feed($this->link, $feed, true);
201 if ($method == "MarkAllRead") {
202 catchup_feed($this->link
, $feed, $cat_view);
204 if (get_pref($this->link
, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
205 if ($next_unread_feed) {
206 $feed = $next_unread_feed;
211 if ($method_split[0] == "MarkAllReadGR") {
212 catchup_feed($this->link
, $method_split[1], false);
215 // FIXME: might break tag display?
217 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
218 $result = db_query($this->link
,
219 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
221 if (db_num_rows($result) == 0) {
222 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
226 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
228 $result = db_query($this->link
, "SELECT rtl_content FROM ttrss_feeds
229 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
231 if (db_num_rows($result) == 1) {
232 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
234 $rtl_content = false;
238 $rtl_tag = "dir=\"RTL\"";
244 $rtl_content = false;
247 @$search = db_escape_string($_REQUEST["query"]);
250 $disable_cache = true;
253 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
254 @$match_on = db_escape_string($_REQUEST["match_on"]);
260 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
262 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
263 if( $search_mode == '' && $method != '' ){
264 $search_mode = $method;
266 // error_log("search_mode: " . $search_mode);
267 $qfh_ret = queryFeedHeadlines($this->link
, $feed, $limit, $view_mode, $cat_view,
268 $search, $search_mode, $match_on, $override_order, $offset);
270 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
272 $result = $qfh_ret[0];
273 $feed_title = $qfh_ret[1];
274 $feed_site_url = $qfh_ret[2];
275 $last_error = $qfh_ret[3];
277 $vgroup_last_feed = $vgr_last_feed;
281 if (db_num_rows($result) > 0) {
282 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
284 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
289 $headlines_count = db_num_rows($result);
291 if (db_num_rows($result) > 0) {
296 $cur_feed_title = '';
298 $fresh_intl = get_pref($this->link
, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
300 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
302 while ($line = db_fetch_assoc($result)) {
304 $class = ($lnum %
2) ?
"even" : "odd";
307 $feed_id = $line["feed_id"];
308 $label_cache = $line["label_cache"];
312 $label_cache = json_decode($label_cache, true);
315 if ($label_cache["no-labels"] == 1)
318 $labels = $label_cache;
322 if (!is_array($labels)) $labels = get_article_labels($this->link
, $id);
324 $labels_str = "<span id=\"HLLCTR-$id\">";
325 $labels_str .= format_article_labels($labels, $id);
326 $labels_str .= "</span>";
328 if (count($topmost_article_ids) < 3) {
329 array_push($topmost_article_ids, $id);
332 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
334 $update_pic = "<img id='FUPDPIC-$id' src=\"".
335 theme_image($this->link
, 'images/updated.png')."\"
338 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
342 if (sql_bool_to_bool($line["unread"]) &&
343 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
345 $update_pic = "<img id='FUPDPIC-$id' src=\"".
346 theme_image($this->link
, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
349 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
357 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
358 $marked_pic = "<img id=\"FMPIC-$id\"
359 src=\"".theme_image($this->link
, 'images/mark_set.png')."\"
360 class=\"markedPic\" alt=\"Unstar article\"
361 onclick='javascript:toggleMark($id)'>";
363 $marked_pic = "<img id=\"FMPIC-$id\"
364 src=\"".theme_image($this->link
, 'images/mark_unset.png')."\"
365 class=\"markedPic\" alt=\"Star article\"
366 onclick='javascript:toggleMark($id)'>";
369 if ($line["published"] == "t" ||
$line["published"] == "1") {
370 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
371 'images/pub_set.png')."\"
373 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
375 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link
,
376 'images/pub_unset.png')."\"
378 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
381 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
382 # $line["title"] . "</a>";
384 # $content_link = "<a
385 # href=\"" . htmlspecialchars($line["link"]) . "\"
386 # onclick=\"view($id,$feed_id);\">" .
387 # $line["title"] . "</a>";
389 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
390 # $line["title"] . "</a>";
392 $updated_fmt = make_local_datetime($this->link
, $line["updated_noms"], false);
394 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
395 $content_preview = truncate_string(strip_tags($line["content_preview"]),
399 $score = $line["score"];
401 $score_pic = theme_image($this->link
,
402 "images/" . get_score_pic($score));
404 /* $score_title = __("(Click to change)");
405 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
406 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
408 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
413 } else if ($score < -100) {
419 $entry_author = $line["author"];
422 $entry_author = " - $entry_author";
425 $has_feed_icon = feed_has_icon($feed_id);
427 if ($has_feed_icon) {
428 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
430 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
433 if (!get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
435 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
436 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
438 $cur_feed_title = $line["feed_title"];
439 $vgroup_last_feed = $feed_id;
441 $cur_feed_title = htmlspecialchars($cur_feed_title);
443 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
445 $reply['content'] .= "<div class='cdmFeedTitle'>".
446 "<div style=\"float : right\">$feed_icon_img</div>".
447 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
448 $line["feed_title"]."</a> $vf_catchup_link</div>";
453 $mouseover_attrs = "onmouseover='postMouseIn($id)'
454 onmouseout='postMouseOut($id)'";
456 $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
458 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
460 $reply['content'] .= "<div class='hlLeft'>";
462 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
465 $reply['content'] .= "$marked_pic";
466 $reply['content'] .= "$published_pic";
468 $reply['content'] .= "</div>";
470 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
471 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
472 $reply['content'] .= "<a id=\"RTITLE-$id\"
473 href=\"" . htmlspecialchars($line["link"]) . "\"
475 truncate_string($line["title"], 200);
477 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
478 if ($content_preview) {
479 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
483 $reply['content'] .= "</a></span>";
485 $reply['content'] .= $labels_str;
487 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
488 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
489 if (@$line["feed_title"]) {
490 $reply['content'] .= "<span class=\"hlFeed\">
491 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
492 $line["feed_title"]."</a>)
497 $reply['content'] .= "</div>";
499 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
500 $reply['content'] .= "<div class=\"hlRight\">";
502 $reply['content'] .= $score_pic;
504 if ($line["feed_title"] && !get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
506 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
507 style=\"cursor : pointer\"
508 title=\"".htmlspecialchars($line['feed_title'])."\">
509 $feed_icon_img<span>";
512 $reply['content'] .= "</div>";
513 $reply['content'] .= "</div>";
517 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
518 if ($feed_id != $vgroup_last_feed) {
520 $cur_feed_title = $line["feed_title"];
521 $vgroup_last_feed = $feed_id;
523 $cur_feed_title = htmlspecialchars($cur_feed_title);
525 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
527 $has_feed_icon = feed_has_icon($feed_id);
529 if ($has_feed_icon) {
530 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
532 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
535 $reply['content'] .= "<div class='cdmFeedTitle'>".
536 "<div style=\"float : right\">$feed_icon_img</div>".
537 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
538 $line["feed_title"]."</a> $vf_catchup_link</div>";
542 $expand_cdm = get_pref($this->link
, 'CDM_EXPANDED');
544 $mouseover_attrs = "onmouseover='postMouseIn($id)'
545 onmouseout='postMouseOut($id)'";
547 $reply['content'] .= "<div class=\"$class\"
548 id=\"RROW-$id\" $mouseover_attrs'>";
550 $reply['content'] .= "<div class=\"cdmHeader\">";
552 $reply['content'] .= "<div>";
554 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
555 'RROW-$id')\" id=\"RCHK-$id\"/>";
557 $reply['content'] .= "$marked_pic";
558 $reply['content'] .= "$published_pic";
560 $reply['content'] .= "</div>";
562 $reply['content'] .= "<span id=\"RTITLE-$id\"
563 onclick=\"return cdmClicked(event, $id);\"
564 class=\"titleWrap$hlc_suffix\">
566 title=\"".htmlspecialchars($line['title'])."\"
567 target=\"_blank\" href=\"".
568 htmlspecialchars($line["link"])."\">".
569 truncate_string($line["title"], 100) .
570 " $entry_author</a>";
572 $reply['content'] .= $labels_str;
574 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED') &&
575 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
576 if (@$line["feed_title"]) {
577 $reply['content'] .= "<span class=\"hlFeed\">
578 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
579 $line["feed_title"]."</a>)
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>";
592 $reply['content'] .= "</span>";
594 $reply['content'] .= "<div>";
595 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
596 $reply['content'] .= "$score_pic";
598 if (!get_pref($this->link
, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
599 $reply['content'] .= "<span style=\"cursor : pointer\"
600 title=\"".htmlspecialchars($line["feed_title"])."\"
601 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
603 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
604 $reply['content'] .= "</div>";
606 $reply['content'] .= "</div>";
608 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
609 onclick=\"return cdmClicked(event, $id);\"
612 $reply['content'] .= "<div class=\"cdmContentInner\">";
614 if ($line["orig_feed_id"]) {
616 $tmp_result = db_query($this->link
, "SELECT * FROM ttrss_archived_feeds
617 WHERE id = ".$line["orig_feed_id"]);
619 if (db_num_rows($tmp_result) != 0) {
621 $reply['content'] .= "<div clear='both'>";
622 $reply['content'] .= __("Originally from:");
624 $reply['content'] .= " ";
626 $tmp_line = db_fetch_assoc($tmp_result);
628 $reply['content'] .= "<a target='_blank'
629 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
630 $tmp_line['title'] . "</a>";
632 $reply['content'] .= " ";
634 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
635 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.gif'></a>";
637 $reply['content'] .= "</div>";
641 $feed_site_url = $line["site_url"];
643 $article_content = sanitize($this->link
, $line["content_preview"],
644 false, false, $feed_site_url);
646 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
648 $reply['content'] .= format_article_note($id, $line['note']);
650 $reply['content'] .= "</div>";
652 $reply['content'] .= "<span id=\"CWRAP-$id\">";
653 $reply['content'] .= $expand_cdm ?
$article_content : '';
654 $reply['content'] .= "</span>";
656 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
657 ttrss_feeds WHERE id = ".
658 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
659 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
661 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
662 0, "always_display_enclosures")); */
664 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
666 $reply['content'] .= format_article_enclosures($this->link
, $id, $always_display_enclosures,
669 $reply['content'] .= "</div>";
671 $reply['content'] .= "<div class=\"cdmFooter\">";
673 $tag_cache = $line["tag_cache"];
675 $tags_str = format_tags_string(
676 get_article_tags($this->link
, $id, $_SESSION["uid"], $tag_cache),
679 $reply['content'] .= "<img src='".theme_image($this->link
,
680 '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 = $line["comments"];
692 $comments_url = $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=\"".$line["comments"]."\">comments</a>";
701 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
703 $reply['content'] .= "<div style=\"float : right\">";
705 $reply['content'] .= "<img src=\"images/art-zoom.png\"
706 onclick=\"zoomToArticle(event, $id)\"
707 style=\"cursor : pointer\"
709 title='".__('Open article in new tab')."'>";
711 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
713 $reply['content'] .= "<img src=\"images/art-pub-note.png\"
714 style=\"cursor : pointer\" style=\"cursor : pointer\"
715 onclick=\"editArticleNote($id)\"
716 alt='PubNote' title='".__('Edit article note')."'>";
719 $reply['content'] .= "<img src=\"".theme_image($this->link
, 'images/art-email.png')."\"
720 style=\"cursor : pointer\"
721 onclick=\"emailArticle($id)\"
722 alt='Zoom' title='".__('Forward by email')."'>";
725 if (ENABLE_TWEET_BUTTON
) {
726 $reply['content'] .= "<img src=\"".theme_image($this->link
, 'images/art-tweet.png')."\"
727 class='tagsPic' style=\"cursor : pointer\"
728 onclick=\"tweetArticle($id)\"
729 alt='Zoom' title='".__('Share on Twitter')."'>";
732 $reply['content'] .= "<img src=\"".theme_image($this->link
, 'images/art-share.png')."\"
733 class='tagsPic' style=\"cursor : pointer\"
734 onclick=\"shareArticle(".$line['int_id'].")\"
735 alt='Zoom' title='".__('Share by URL')."'>";
737 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
738 style=\"cursor : pointer\" style=\"cursor : pointer\"
739 onclick=\"dismissArticle($id)\"
740 alt='Dismiss' title='".__('Dismiss article')."'>";
742 $reply['content'] .= "</div>";
743 $reply['content'] .= "</div>";
745 $reply['content'] .= "</div>";
747 $reply['content'] .= "</div>";
754 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
759 switch ($view_mode) {
761 $message = __("No unread articles found to display.");
764 $message = __("No updated articles found to display.");
767 $message = __("No starred articles found to display.");
771 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
773 $message = __("No articles found to display.");
777 if (!$offset && $message) {
778 $reply['content'] .= "<div class='whiteBox'>$message";
780 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
782 $result = db_query($this->link
, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
783 WHERE owner_uid = " . $_SESSION['uid']);
785 $last_updated = db_fetch_result($result, 0, "last_updated");
786 $last_updated = make_local_datetime($this->link
, $last_updated, false);
788 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
790 $result = db_query($this->link
, "SELECT COUNT(id) AS num_errors
791 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
793 $num_errors = db_fetch_result($result, 0, "num_errors");
795 if ($num_errors > 0) {
796 $reply['content'] .= "<br/>";
797 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
798 __('Some feeds have update errors (click for details)')."</a>";
800 $reply['content'] .= "</span></p></div>";
804 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
806 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
807 $vgroup_last_feed, $reply);
810 private function outputFeedList($special = true) {
814 $enable_cats = get_pref($this->link
, 'ENABLE_FEED_CATS');
816 $feedlist['identifier'] = 'id';
817 $feedlist['label'] = 'name';
818 $feedlist['items'] = array();
820 $owner_uid = $_SESSION["uid"];
827 $cat_hidden = get_pref($this->link
, "_COLLAPSED_SPECIAL");
828 $cat = $this->feedlist_init_cat(-1, $cat_hidden);
830 $cat['items'] = array();
833 foreach (array(-4, -3, -1, -2, 0) as $i) {
834 array_push($cat['items'], $this->feedlist_init_feed($i));
838 array_push($feedlist['items'], $cat);
840 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
843 $result = db_query($this->link
, "SELECT * FROM
844 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
846 if (db_num_rows($result) > 0) {
848 if (get_pref($this->link
, 'ENABLE_FEED_CATS')) {
849 $cat_hidden = get_pref($this->link
, "_COLLAPSED_LABELS");
850 $cat = $this->feedlist_init_cat(-2, $cat_hidden);
852 $cat['items'] = array();
855 while ($line = db_fetch_assoc($result)) {
857 $label_id = -$line['id'] - 11;
858 $count = getFeedUnread($this->link
, $label_id);
860 $feed = $this->feedlist_init_feed($label_id, false, $count);
862 $feed['fg_color'] = $line['fg_color'];
863 $feed['bg_color'] = $line['bg_color'];
865 array_push($cat['items'], $feed);
869 array_push($feedlist['items'], $cat);
871 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
876 /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
877 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
878 $order_by_qpart = "order_id,category,unread DESC,title";
880 $order_by_qpart = "order_id,category,title";
883 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
884 $order_by_qpart = "unread DESC,title";
886 $order_by_qpart = "title";
893 $order_by_qpart = "ttrss_feed_categories.order_id,category,
894 ttrss_feeds.order_id,title";
896 $order_by_qpart = "title";
898 $age_qpart = getMaxAgeSubquery();
900 $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
901 ".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated_noms,
903 ttrss_feed_categories.title AS category,
904 ttrss_feed_categories.collapsed,
906 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
907 ON (ttrss_feed_categories.id = cat_id)
908 LEFT JOIN ttrss_counters_cache
910 (ttrss_feeds.id = feed_id)
912 ttrss_feeds.owner_uid = '$owner_uid'
913 ORDER BY $order_by_qpart";
915 $result = db_query($this->link
, $query);
917 $actid = $_REQUEST["actid"];
919 if (db_num_rows($result) > 0) {
924 $cat['items'] = array();
928 while ($line = db_fetch_assoc($result)) {
930 $feed = htmlspecialchars(trim($line["title"]));
932 if (!$feed) $feed = "[Untitled]";
934 $feed_id = $line["id"];
935 $unread = $line["unread"];
937 $cat_id = $line["cat_id"];
938 $tmp_category = $line["category"];
939 if (!$tmp_category) $tmp_category = __("Uncategorized");
941 if ($category != $tmp_category && $enable_cats) {
943 $category = $tmp_category;
945 $collapsed = sql_bool_to_bool($line["collapsed"]);
947 // workaround for NULL category
948 if ($category == __("Uncategorized")) {
949 $collapsed = get_pref($this->link
, "_COLLAPSED_UNCAT");
952 if ($cat) array_push($feedlist['items'], $cat);
954 $cat = $this->feedlist_init_cat($cat_id, $collapsed);
957 $updated = make_local_datetime($this->link
, $line["updated_noms"], false);
959 array_push($cat['items'], $this->feedlist_init_feed($feed_id,
960 $feed, $unread, $line['last_error'], $updated));
964 array_push($feedlist['items'], $cat);
966 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
975 function catchupAll() {
976 db_query($this->link
, "UPDATE ttrss_user_entries SET
977 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
978 ccache_zero_all($this->link
, $_SESSION["uid"]);
981 function collapse() {
982 $cat_id = db_escape_string($_REQUEST["cid"]);
983 $mode = (int) db_escape_string($_REQUEST['mode']);
984 toggle_collapse_cat($this->link
, $cat_id, $mode);
988 $root = (bool)$_REQUEST["root"];
991 print json_encode($this->outputFeedList($this->link
));
994 $feeds = $this->outputFeedList($this->link
, false);
997 $root['id'] = 'root';
998 $root['name'] = __('Feeds');
999 $root['items'] = $feeds['items'];
1002 $fl['identifier'] = 'id';
1003 $fl['label'] = 'name';
1004 $fl['items'] = array($root);
1006 print json_encode($fl);
1011 $timing_info = getmicrotime();
1015 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
1017 $omode = db_escape_string($_REQUEST["omode"]);
1019 $feed = db_escape_string($_REQUEST["feed"]);
1020 $method = db_escape_string($_REQUEST["m"]);
1021 $view_mode = db_escape_string($_REQUEST["view_mode"]);
1022 $limit = (int) get_pref($this->link
, "DEFAULT_ARTICLE_LIMIT");
1023 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
1024 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
1025 @$offset = db_escape_string($_REQUEST["skip"]);
1026 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
1027 $order_by = db_escape_string($_REQUEST["order_by"]);
1029 if (is_numeric($feed)) $feed = (int) $feed;
1031 /* Feed -5 is a special case: it is used to display auxiliary information
1032 * when there's nothing to load - e.g. no stuff in fresh feed */
1035 print json_encode(generate_dashboard_feed($this->link
));
1042 $label_feed = -11-$feed;
1043 $result = db_query($this->link
, "SELECT id FROM ttrss_labels2 WHERE
1044 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
1045 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
1046 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
1047 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1048 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
1049 $result = db_query($this->link
, "SELECT id FROM ttrss_feed_categories WHERE
1050 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1053 if ($result && db_num_rows($result) == 0) {
1054 print json_encode(generate_error_feed($this->link
, __("Feed not found.")));
1058 /* Updating a label ccache means recalculating all of the caches
1059 * so for performance reasons we don't do that here */
1062 ccache_update($this->link
, $feed, $_SESSION["uid"], $cat_view);
1065 set_pref($this->link
, "_DEFAULT_VIEW_MODE", $view_mode);
1066 set_pref($this->link
, "_DEFAULT_VIEW_LIMIT", $limit);
1067 set_pref($this->link
, "_DEFAULT_VIEW_ORDER_BY", $order_by);
1069 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
1070 db_query($this->link
, "UPDATE ttrss_feeds SET last_viewed = NOW()
1071 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
1074 $reply['headlines'] = array();
1076 if (!$next_unread_feed)
1077 $reply['headlines']['id'] = $feed;
1079 $reply['headlines']['id'] = $next_unread_feed;
1081 $reply['headlines']['is_cat'] = (bool) $cat_view;
1083 $override_order = false;
1085 if (get_pref($this->link
, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
1086 $date_sort_field = "updated";
1088 $date_sort_field = "date_entered";
1091 switch ($order_by) {
1093 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1094 $override_order = "$date_sort_field";
1096 $override_order = "$date_sort_field DESC";
1101 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1102 $override_order = "title DESC, $date_sort_field";
1104 $override_order = "title, $date_sort_field DESC";
1109 if (get_pref($this->link
, 'REVERSE_HEADLINES', $owner_uid)) {
1110 $override_order = "score, $date_sort_field";
1112 $override_order = "score DESC, $date_sort_field DESC";
1117 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
1119 $ret = $this->format_headlines_list($feed, $method,
1120 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
1121 $vgroup_last_feed, $override_order);
1123 $topmost_article_ids = $ret[0];
1124 $headlines_count = $ret[1];
1125 $returned_feed = $ret[2];
1126 $disable_cache = $ret[3];
1127 $vgroup_last_feed = $ret[4];
1129 $reply['headlines']['content'] =& $ret[5]['content'];
1130 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
1132 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
1134 $reply['headlines-info'] = array("count" => (int) $headlines_count,
1135 "vgroup_last_feed" => $vgroup_last_feed,
1136 "disable_cache" => (bool) $disable_cache);
1138 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
1140 if (is_array($topmost_article_ids) && !get_pref($this->link
, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
1141 $articles = array();
1143 foreach ($topmost_article_ids as $id) {
1144 array_push($articles, format_article($this->link
, $id, false));
1147 $reply['articles'] = $articles;
1150 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
1152 $reply['runtime-info'] = make_runtime_info($this->link
);
1154 print json_encode($reply);