2 require_once "colors.php";
4 class Feeds
extends Handler_Protected
{
8 function csrf_ignore($method) {
9 $csrf_ignored = array("index", "feedbrowser", "quickaddfeed", "search");
11 return array_search($method, $csrf_ignored) !== false;
14 private function format_headline_subtoolbar($feed_site_url, $feed_title,
15 $feed_id, $is_cat, $search,
16 $search_mode, $view_mode, $error, $feed_last_updated) {
18 $catchup_sel_link = "catchupSelection()";
20 $archive_sel_link = "archiveSelection()";
21 $delete_sel_link = "deleteSelection()";
23 $sel_all_link = "selectArticles('all')";
24 $sel_unread_link = "selectArticles('unread')";
25 $sel_none_link = "selectArticles('none')";
26 $sel_inv_link = "selectArticles('invert')";
28 $tog_unread_link = "selectionToggleUnread()";
29 $tog_marked_link = "selectionToggleMarked()";
30 $tog_published_link = "selectionTogglePublished()";
32 $set_score_link = "setSelectionScore()";
34 if ($is_cat) $cat_q = "&is_cat=$is_cat";
37 $search_q = "&q=$search&smode=$search_mode";
42 $reply .= "<span class=\"holder\">";
44 $rss_link = htmlspecialchars(get_self_url_prefix() .
45 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
49 $error_class = $error ?
"error" : "";
51 $reply .= "<span class='r'>
53 title=\"".__("View as RSS feed")."\"
54 onclick=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">
55 <img class=\"noborder\" src=\"images/pub_set.png\"></a>";
59 $reply .= "<span id='feed_title' class='$error_class'>";
62 $last_updated = T_sprintf("Last updated: %s",
65 $target = "target=\"_blank\"";
66 $reply .= "<a title=\"$last_updated\" $target href=\"$feed_site_url\">".
67 truncate_string($feed_title, 30)."</a>";
70 $error = htmlspecialchars($error);
71 $reply .= " <img title=\"$error\" src='images/error.png' alt='error' class=\"noborder\">";
75 $reply .= $feed_title;
82 # $reply .= "</span>";
86 $reply .= "<span class=\"main\">";
87 $reply .= "<span id='selected_prompt'></span>";
90 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
91 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
92 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
93 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
97 $reply .= "<select dojoType=\"dijit.form.Select\"
98 onchange=\"headlineActionsChange(this)\">";
99 $reply .= "<option value=\"false\">".__('More...')."</option>";
101 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
103 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
104 <option value=\"$tog_marked_link\">".__('Starred')."</option>
105 <option value=\"$tog_published_link\">".__('Published')."</option>";
107 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
109 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
110 $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>";
112 if ($feed_id != "0") {
113 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
115 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
116 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
120 if (PluginHost
::getInstance()->get_plugin("mail")) {
121 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
125 if (PluginHost
::getInstance()->get_plugin("mailto")) {
126 $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
130 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
132 //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
134 $reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
136 $reply .= "</select>";
140 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_HEADLINE_TOOLBAR_BUTTON
) as $p) {
141 $reply .= $p->hook_headline_toolbar_button($feed_id, $is_cat);
144 $reply .= "</span></span>";
149 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
150 $next_unread_feed, $offset, $vgr_last_feed = false,
151 $override_order = false, $include_children = false) {
153 if (isset($_REQUEST["DevForceUpdate"]))
154 header("Content-Type: text/plain; charset=utf-8");
156 $disable_cache = false;
160 $rgba_cache = array();
162 $timing_info = microtime(true);
164 $topmost_article_ids = array();
166 if (!$offset) $offset = 0;
167 if ($method == "undefined") $method = "";
169 $method_split = explode(":", $method);
171 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
172 // Update the feed if required with some basic flood control
174 $result = $this->dbh
->query(
175 "SELECT cache_images,".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
176 FROM ttrss_feeds WHERE id = '$feed'");
178 if ($this->dbh
->num_rows($result) != 0) {
179 $last_updated = strtotime($this->dbh
->fetch_result($result, 0, "last_updated"));
180 $cache_images = sql_bool_to_bool($this->dbh
->fetch_result($result, 0, "cache_images"));
182 if (!$cache_images && time() - $last_updated > 120 ||
isset($_REQUEST['DevForceUpdate'])) {
183 include "rssfuncs.php";
184 update_rss_feed($feed, true, true);
186 $this->dbh
->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
187 WHERE id = '$feed'");
192 if ($method_split[0] == "MarkAllReadGR") {
193 catchup_feed($method_split[1], false);
196 // FIXME: might break tag display?
198 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
199 $result = $this->dbh
->query(
200 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
202 if ($this->dbh
->num_rows($result) == 0) {
203 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
207 @$search = $this->dbh
->escape_string($_REQUEST["query"]);
210 $disable_cache = true;
213 @$search_mode = $this->dbh
->escape_string($_REQUEST["search_mode"]);
215 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
217 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
218 if($search_mode == '' && $method != '' ){
219 $search_mode = $method;
221 // error_log("search_mode: " . $search_mode);
223 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX
&& $feed > LABEL_BASE_INDEX
) {
224 $handler = PluginHost
::getInstance()->get_feed_handler(
225 PluginHost
::feed_to_pfeed_id($feed));
227 // function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false) {
232 "view_mode" => $view_mode,
233 "cat_view" => $cat_view,
235 "search_mode" => $search_mode,
236 "override_order" => $override_order,
238 "owner_uid" => $_SESSION["uid"],
241 "include_children" => $include_children);
243 $qfh_ret = $handler->get_headlines(PluginHost
::feed_to_pfeed_id($feed),
248 $qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $cat_view,
249 $search, $search_mode, $override_order, $offset, 0,
250 false, 0, $include_children);
253 $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && $feed != -6;
255 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
257 $result = $qfh_ret[0];
258 $feed_title = $qfh_ret[1];
259 $feed_site_url = $qfh_ret[2];
260 $last_error = $qfh_ret[3];
261 $last_updated = strpos($qfh_ret[4], '1970-') === FALSE ?
262 make_local_datetime($qfh_ret[4], false) : __("Never");
263 $highlight_words = $qfh_ret[5];
265 $vgroup_last_feed = $vgr_last_feed;
267 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
269 $feed, $cat_view, $search, $search_mode, $view_mode,
270 $last_error, $last_updated);
272 $headlines_count = $this->dbh
->num_rows($result);
274 /* if (get_pref('COMBINED_DISPLAY_MODE')) {
275 $button_plugins = array();
276 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
277 $pclass = "button_" . trim($p);
279 if (class_exists($pclass)) {
280 $plugin = new $pclass();
281 array_push($button_plugins, $plugin);
287 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_HEADLINES_BEFORE
) as $p) {
288 $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret);
292 if ($this->dbh
->num_rows($result) > 0) {
297 $cur_feed_title = '';
299 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
301 $expand_cdm = get_pref('CDM_EXPANDED');
303 while ($line = $this->dbh
->fetch_assoc($result)) {
304 $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250);
306 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
307 $line = $p->hook_query_headlines($line, 250, false);
310 if (get_pref('SHOW_CONTENT_PREVIEW')) {
311 $content_preview = $line["content_preview"];
315 $feed_id = $line["feed_id"];
316 $label_cache = $line["label_cache"];
320 $label_cache = json_decode($label_cache, true);
323 if ($label_cache["no-labels"] == 1)
326 $labels = $label_cache;
330 if (!is_array($labels)) $labels = get_article_labels($id);
332 $labels_str = "<span class=\"HLLCTR-$id\">";
333 $labels_str .= format_article_labels($labels, $id);
334 $labels_str .= "</span>";
336 if (count($topmost_article_ids) < 3) {
337 array_push($topmost_article_ids, $id);
342 if (sql_bool_to_bool($line["unread"])) {
347 if (sql_bool_to_bool($line["marked"])) {
349 src=\"images/mark_set.png\"
350 class=\"markedPic\" alt=\"Unstar article\"
351 onclick='toggleMark($id)'>";
355 src=\"images/mark_unset.png\"
356 class=\"markedPic\" alt=\"Star article\"
357 onclick='toggleMark($id)'>";
360 if (sql_bool_to_bool($line["published"])) {
361 $published_pic = "<img src=\"images/pub_set.png\"
363 alt=\"Unpublish article\" onclick='togglePub($id)'>";
364 $class .= " published";
366 $published_pic = "<img src=\"images/pub_unset.png\"
368 alt=\"Publish article\" onclick='togglePub($id)'>";
371 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
372 # $line["title"] . "</a>";
374 # $content_link = "<a
375 # href=\"" . htmlspecialchars($line["link"]) . "\"
376 # onclick=\"view($id,$feed_id);\">" .
377 # $line["title"] . "</a>";
379 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
380 # $line["title"] . "</a>";
382 $updated_fmt = make_local_datetime($line["updated"], false);
383 $date_entered_fmt = T_sprintf("Imported at %s",
384 make_local_datetime($line["date_entered"], false));
386 $score = $line["score"];
388 $score_pic = "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' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
398 $hlc_suffix = "high";
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/pub_set.png\" alt=\"\">";
419 $entry_site_url = $line["site_url"];
421 //setting feed headline background color, needs to change text color based on dark/light
422 $fav_color = $line['favicon_avg_color'];
424 require_once "colors.php";
426 if ($fav_color && $fav_color != 'fail') {
427 if (!isset($rgba_cache[$feed_id])) {
428 $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color));
432 if (!get_pref('COMBINED_DISPLAY_MODE')) {
434 if ($vfeed_group_enabled) {
435 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
437 $cur_feed_title = $line["feed_title"];
438 $vgroup_last_feed = $feed_id;
440 $cur_feed_title = htmlspecialchars($cur_feed_title);
442 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
444 $reply['content'] .= "<div id='FTITLE-$feed_id' class='cdmFeedTitle'>".
445 "<div style='float : right'>$feed_icon_img</div>".
446 "<a class='title' href=\"#\" onclick=\"viewfeed($feed_id)\">". $line["feed_title"]."</a>
447 $vf_catchup_link</div>";
452 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
453 onmouseout='postMouseOut($id)'";
455 $reply['content'] .= "<div class='hl $class' orig-feed-id='$feed_id' id='RROW-$id' $mouseover_attrs>";
457 $reply['content'] .= "<div class='hlLeft'>";
459 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
460 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
463 $reply['content'] .= "$marked_pic";
464 $reply['content'] .= "$published_pic";
466 $reply['content'] .= "</div>";
468 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
469 class=\"hlTitle\"><span class='hlContent $hlc_suffix'>";
470 $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title $hlc_suffix\"
471 href=\"" . htmlspecialchars($line["link"]) . "\"
473 truncate_string($line["title"], 200);
475 if (get_pref('SHOW_CONTENT_PREVIEW')) {
476 $reply['content'] .= "<span class=\"contentPreview\">" . $line["content_preview"] . "</span>";
479 $reply['content'] .= "</a></span>";
481 $reply['content'] .= $labels_str;
483 $reply['content'] .= "</div>";
485 if (!$vfeed_group_enabled) {
486 if (@$line["feed_title"]) {
487 $rgba = @$rgba_cache[$feed_id];
489 $reply['content'] .= "<span class=\"hlFeed\"><a style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed($feed_id)\">".
490 truncate_string($line["feed_title"],30)."</a></span>";
495 $reply['content'] .= "<span class=\"hlUpdated\">";
497 $reply['content'] .= "<div title='$date_entered_fmt'>$updated_fmt</div>
500 $reply['content'] .= "<div class=\"hlRight\">";
502 $reply['content'] .= $score_pic;
504 if ($line["feed_title"] && !$vfeed_group_enabled) {
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 ($line["tag_cache"])
518 $tags = explode(",", $line["tag_cache"]);
522 $line["content"] = sanitize($line["content"],
523 sql_bool_to_bool($line['hide_images']), false, $entry_site_url, $highlight_words, $line["id"]);
525 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_CDM
) as $p) {
526 $line = $p->hook_render_article_cdm($line);
529 if ($vfeed_group_enabled && $line["feed_title"]) {
530 if ($feed_id != $vgroup_last_feed) {
532 $cur_feed_title = $line["feed_title"];
533 $vgroup_last_feed = $feed_id;
535 $cur_feed_title = htmlspecialchars($cur_feed_title);
537 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
539 $has_feed_icon = feed_has_icon($feed_id);
541 if ($has_feed_icon) {
542 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
544 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
547 $reply['content'] .= "<div id='FTITLE-$feed_id' class='cdmFeedTitle'>".
548 "<div style=\"float : right\">$feed_icon_img</div>".
549 "<a href=\"#\" class='title' onclick=\"viewfeed($feed_id)\">".
550 $line["feed_title"]."</a> $vf_catchup_link</div>";
554 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
555 onmouseout='postMouseOut($id)'";
557 $expanded_class = $expand_cdm ?
"expanded" : "expandable";
559 $reply['content'] .= "<div class=\"cdm $hlc_suffix $expanded_class $class\"
560 id=\"RROW-$id\" orig-feed-id='$feed_id' $mouseover_attrs>";
562 $reply['content'] .= "<div class=\"cdmHeader\">";
563 $reply['content'] .= "<div style=\"vertical-align : middle\">";
565 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
566 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
569 $reply['content'] .= "$marked_pic";
570 $reply['content'] .= "$published_pic";
572 $reply['content'] .= "</div>";
574 if ($highlight_words && count($highlight_words > 0)) {
575 foreach ($highlight_words as $word) {
576 $line["title"] = preg_replace("/(\Q$word\E)/i",
577 "<span class=\"highlight\">$1</span>", $line["title"]);
581 $reply['content'] .= "<span id=\"RTITLE-$id\"
582 onclick=\"return cdmClicked(event, $id);\"
583 class=\"titleWrap $hlc_suffix\">
584 <a class=\"title $hlc_suffix\"
585 title=\"".htmlspecialchars($line["title"])."\"
586 target=\"_blank\" href=\"".
587 htmlspecialchars($line["link"])."\">".
589 "</a> <span class=\"author\">$entry_author</span>";
591 $reply['content'] .= $labels_str;
593 $reply['content'] .= "<span class='collapseBtn' style='display : none'>
594 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
595 title=\"".__("Collapse article")."\"/></span>";
598 $content_hidden = "style=\"display : none\"";
600 $excerpt_hidden = "style=\"display : none\"";
602 $reply['content'] .= "<span $excerpt_hidden id=\"CEXC-$id\" class=\"cdmExcerpt\">" . $content_preview . "</span>";
604 $reply['content'] .= "</span>";
606 if (!$vfeed_group_enabled) {
607 if (@$line["feed_title"]) {
608 $rgba = @$rgba_cache[$feed_id];
610 $reply['content'] .= "<div class=\"hlFeed\">
611 <a href=\"#\" style=\"background-color: rgba($rgba,0.3)\"
612 onclick=\"viewfeed($feed_id)\">".
613 truncate_string($line["feed_title"],30)."</a>
618 $reply['content'] .= "<span class='updated' title='$date_entered_fmt'>
619 $updated_fmt</span>";
621 $reply['content'] .= "<div class='scoreWrap' style=\"vertical-align : middle\">";
622 $reply['content'] .= "$score_pic";
624 if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
625 $reply['content'] .= "<span style=\"cursor : pointer\"
626 title=\"".htmlspecialchars($line["feed_title"])."\"
627 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
629 $reply['content'] .= "</div>";
631 $reply['content'] .= "</div>";
633 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
634 onclick=\"return cdmClicked(event, $id);\"
637 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
639 $reply['content'] .= format_article_note($id, $line['note']);
641 $reply['content'] .= "</div>";
643 if (!$line['lang']) $line['lang'] = 'en';
645 $reply['content'] .= "<div class=\"cdmContentInner\" lang=\"".$line['lang']."\">";
647 if ($line["orig_feed_id"]) {
649 $tmp_result = $this->dbh
->query("SELECT * FROM ttrss_archived_feeds
650 WHERE id = ".$line["orig_feed_id"]);
652 if ($this->dbh
->num_rows($tmp_result) != 0) {
654 $reply['content'] .= "<div clear='both'>";
655 $reply['content'] .= __("Originally from:");
657 $reply['content'] .= " ";
659 $tmp_line = $this->dbh
->fetch_assoc($tmp_result);
661 $reply['content'] .= "<a target='_blank'
662 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
663 $tmp_line['title'] . "</a>";
665 $reply['content'] .= " ";
667 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
668 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.png'></a>";
670 $reply['content'] .= "</div>";
674 $reply['content'] .= "<span id=\"CWRAP-$id\">";
676 // if (!$expand_cdm) {
677 $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">";
678 $reply['content'] .= htmlspecialchars($line["content"]);
679 $reply['content'] .= "</span.";
682 // $reply['content'] .= $line["content"];
685 $reply['content'] .= "</span>";
687 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
689 $reply['content'] .= format_article_enclosures($id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"]));
691 $reply['content'] .= "</div>";
693 $reply['content'] .= "<div class=\"cdmFooter\">";
695 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_LEFT_BUTTON
) as $p) {
696 $reply['content'] .= $p->hook_article_left_button($line);
699 $tags_str = format_tags_string($tags, $id);
701 $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>
702 <span id=\"ATSTR-$id\">$tags_str</span>
703 <a title=\"".__('Edit tags for this article')."\"
704 href=\"#\" onclick=\"editArticleTags($id)\">(+)</a>";
706 $num_comments = $line["num_comments"];
707 $entry_comments = "";
709 if ($num_comments > 0) {
710 if ($line["comments"]) {
711 $comments_url = htmlspecialchars($line["comments"]);
713 $comments_url = htmlspecialchars($line["link"]);
715 $entry_comments = "<a class=\"postComments\"
716 target='_blank' href=\"$comments_url\">$num_comments ".
717 _ngettext("comment", "comments", $num_comments)."</a>";
720 if ($line["comments"] && $line["link"] != $line["comments"]) {
721 $entry_comments = "<a class=\"postComments\" target='_blank' href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
725 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
727 $reply['content'] .= "<div style=\"float : right\">";
729 // $reply['content'] .= "$marked_pic";
730 // $reply['content'] .= "$published_pic";
732 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_BUTTON
) as $p) {
733 $reply['content'] .= $p->hook_article_button($line);
736 $reply['content'] .= "</div>";
737 $reply['content'] .= "</div>";
739 $reply['content'] .= "</div>";
741 $reply['content'] .= "</div>";
748 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
753 switch ($view_mode) {
755 $message = __("No unread articles found to display.");
758 $message = __("No updated articles found to display.");
761 $message = __("No starred articles found to display.");
764 if ($feed < LABEL_BASE_INDEX
) {
765 $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter.");
767 $message = __("No articles found to display.");
771 if (!$offset && $message) {
772 $reply['content'] .= "<div class='whiteBox'>$message";
774 $reply['content'] .= "<p><span class=\"insensitive\">";
776 $result = $this->dbh
->query("SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
777 WHERE owner_uid = " . $_SESSION['uid']);
779 $last_updated = $this->dbh
->fetch_result($result, 0, "last_updated");
780 $last_updated = make_local_datetime($last_updated, false);
782 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
784 $result = $this->dbh
->query("SELECT COUNT(id) AS num_errors
785 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
787 $num_errors = $this->dbh
->fetch_result($result, 0, "num_errors");
789 if ($num_errors > 0) {
790 $reply['content'] .= "<br/>";
791 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
792 __('Some feeds have update errors (click for details)')."</a>";
794 $reply['content'] .= "</span></p></div>";
798 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
800 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
801 $vgroup_last_feed, $reply);
804 function catchupAll() {
805 $this->dbh
->query("UPDATE ttrss_user_entries SET
806 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
807 ccache_zero_all($_SESSION["uid"]);
811 $timing_info = microtime(true);
815 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
817 $feed = $this->dbh
->escape_string($_REQUEST["feed"]);
818 $method = $this->dbh
->escape_string($_REQUEST["m"]);
819 $view_mode = $this->dbh
->escape_string($_REQUEST["view_mode"]);
821 @$cat_view = $_REQUEST["cat"] == "true";
822 @$next_unread_feed = $this->dbh
->escape_string($_REQUEST["nuf"]);
823 @$offset = $this->dbh
->escape_string($_REQUEST["skip"]);
824 @$vgroup_last_feed = $this->dbh
->escape_string($_REQUEST["vgrlf"]);
825 $order_by = $this->dbh
->escape_string($_REQUEST["order_by"]);
827 if (is_numeric($feed)) $feed = (int) $feed;
829 /* Feed -5 is a special case: it is used to display auxiliary information
830 * when there's nothing to load - e.g. no stuff in fresh feed */
833 print json_encode($this->generate_dashboard_feed());
839 if ($feed < LABEL_BASE_INDEX
) {
840 $label_feed = feed_to_label_id($feed);
841 $result = $this->dbh
->query("SELECT id FROM ttrss_labels2 WHERE
842 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
843 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
844 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
845 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
846 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
847 $result = $this->dbh
->query("SELECT id FROM ttrss_feed_categories WHERE
848 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
851 if ($result && $this->dbh
->num_rows($result) == 0) {
852 print json_encode($this->generate_error_feed(__("Feed not found.")));
856 /* Updating a label ccache means recalculating all of the caches
857 * so for performance reasons we don't do that here */
860 ccache_update($feed, $_SESSION["uid"], $cat_view);
863 set_pref("_DEFAULT_VIEW_MODE", $view_mode);
864 set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by);
866 /* bump login timestamp if needed */
867 if (time() - $_SESSION["last_login_update"] > 3600) {
868 $this->dbh
->query("UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
870 $_SESSION["last_login_update"] = time();
873 if (!$cat_view && is_numeric($feed) && $feed > 0) {
874 $this->dbh
->query("UPDATE ttrss_feeds SET last_viewed = NOW()
875 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
878 $reply['headlines'] = array();
880 if (!$next_unread_feed)
881 $reply['headlines']['id'] = $feed;
883 $reply['headlines']['id'] = $next_unread_feed;
885 $reply['headlines']['is_cat'] = (bool) $cat_view;
887 $override_order = false;
891 $override_order = "ttrss_entries.title";
894 $override_order = "score DESC, date_entered, updated";
897 $override_order = "updated DESC";
901 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
903 $ret = $this->format_headlines_list($feed, $method,
904 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
905 $vgroup_last_feed, $override_order, true);
907 //$topmost_article_ids = $ret[0];
908 $headlines_count = $ret[1];
909 /* $returned_feed = $ret[2]; */
910 $disable_cache = $ret[3];
911 $vgroup_last_feed = $ret[4];
913 $reply['headlines']['content'] =& $ret[5]['content'];
914 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
916 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
918 $reply['headlines-info'] = array("count" => (int) $headlines_count,
919 "vgroup_last_feed" => $vgroup_last_feed,
920 "disable_cache" => (bool) $disable_cache);
922 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
924 $reply['runtime-info'] = make_runtime_info();
926 print json_encode($reply);
930 private function generate_dashboard_feed() {
933 $reply['headlines']['id'] = -5;
934 $reply['headlines']['is_cat'] = false;
936 $reply['headlines']['toolbar'] = '';
937 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
939 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
941 $result = $this->dbh
->query("SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
942 WHERE owner_uid = " . $_SESSION['uid']);
944 $last_updated = $this->dbh
->fetch_result($result, 0, "last_updated");
945 $last_updated = make_local_datetime($last_updated, false);
947 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
949 $result = $this->dbh
->query("SELECT COUNT(id) AS num_errors
950 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
952 $num_errors = $this->dbh
->fetch_result($result, 0, "num_errors");
954 if ($num_errors > 0) {
955 $reply['headlines']['content'] .= "<br/>";
956 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
957 __('Some feeds have update errors (click for details)')."</a>";
959 $reply['headlines']['content'] .= "</span></p>";
961 $reply['headlines-info'] = array("count" => 0,
962 "vgroup_last_feed" => '',
964 "disable_cache" => true);
969 private function generate_error_feed($error) {
972 $reply['headlines']['id'] = -6;
973 $reply['headlines']['is_cat'] = false;
975 $reply['headlines']['toolbar'] = '';
976 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
978 $reply['headlines-info'] = array("count" => 0,
979 "vgroup_last_feed" => '',
981 "disable_cache" => true);
986 function quickAddFeed() {
987 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
988 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">";
990 print "<div id='fadd_multiple_notify' style='display : none'>";
991 print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below.");
994 print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
995 print "<div class=\"dlgSecCont\">";
997 print "<div style='float : right'>
998 <img style='display : none'
999 id='feed_add_spinner' src='images/indicator_white.gif'></div>";
1001 print "<input style=\"font-size : 16px; width : 20em;\"
1002 placeHolder=\"".__("Feed or site URL")."\"
1003 dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
1007 if (get_pref('ENABLE_FEED_CATS')) {
1008 print __('Place in category:') . " ";
1009 print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
1014 print '<div id="feedDlg_feedsContainer" style="display : none">
1016 <div class="dlgSec">' . __('Available feeds') . '</div>
1017 <div class="dlgSecCont">'.
1018 '<select id="feedDlg_feedContainerSelect"
1019 dojoType="dijit.form.Select" size="3">
1020 <script type="dojo/method" event="onChange" args="value">
1021 dijit.byId("feedDlg_feedUrl").attr("value", value);
1026 print "<div id='feedDlg_loginContainer' style='display : none'>
1028 <div class=\"dlgSec\">".__("Authentication")."</div>
1029 <div class=\"dlgSecCont\">".
1031 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
1032 placeHolder=\"".__("Login")."\"
1033 style=\"width : 10em;\"> ".
1035 placeHolder=\"".__("Password")."\"
1036 dojoType=\"dijit.form.TextBox\" type='password'
1037 style=\"width : 10em;\" name='pass'\">
1041 print "<div style=\"clear : both\">
1042 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
1043 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
1044 <label for=\"feedDlg_loginCheck\">".
1045 __('This feed requires authentication.')."</div>";
1049 print "<div class=\"dlgButtons\">
1050 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
1052 if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
)) {
1053 print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
1056 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
1062 function feedBrowser() {
1063 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
) return;
1065 $browser_search = $this->dbh
->escape_string($_REQUEST["search"]);
1067 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
1068 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">";
1070 print "<div dojoType=\"dijit.Toolbar\">
1071 <div style='float : right'>
1072 <img style='display : none'
1073 id='feed_browser_spinner' src='images/indicator_white.gif'>
1074 <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
1075 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
1076 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
1079 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
1080 <option value='1'>" . __('Popular feeds') . "</option>
1081 <option value='2'>" . __('Feed archive') . "</option>
1086 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
1088 foreach (array(25, 50, 100, 200) as $l) {
1089 //$issel = ($l == $limit) ? "selected=\"1\"" : "";
1090 print "<option value=\"$l\">$l</option>";
1097 require_once "feedbrowser.php";
1099 print "<ul class='browseFeedList' id='browseFeedList'>";
1100 print make_feed_browser("", 25);
1103 print "<div align='center'>
1104 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
1105 <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
1106 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
1111 $this->params
= explode(":", $this->dbh
->escape_string($_REQUEST["param"]), 2);
1113 $active_feed_id = sprintf("%d", $this->params
[0]);
1114 $is_cat = $this->params
[1] != "false";
1116 print "<div class=\"dlgSec\">".__('Look for')."</div>";
1118 print "<div class=\"dlgSecCont\">";
1120 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1121 style=\"font-size : 16px; width : 20em;\"
1122 required=\"1\" name=\"query\" type=\"search\" value=''>";
1124 print "<hr/>".__('Limit search to:')." ";
1126 print "<select name=\"search_mode\" dojoType=\"dijit.form.Select\">
1127 <option value=\"all_feeds\">".__('All feeds')."</option>";
1129 $feed_title = getFeedTitle($active_feed_id);
1132 $feed_cat_title = getFeedCatTitle($active_feed_id);
1134 $feed_cat_title = getCategoryTitle($active_feed_id);
1137 if ($active_feed_id && !$is_cat) {
1138 print "<option selected=\"1\" value=\"this_feed\">$feed_title</option>";
1140 print "<option disabled=\"1\" value=\"false\">".__('This feed')."</option>";
1144 $cat_preselected = "selected=\"1\"";
1147 if (get_pref('ENABLE_FEED_CATS') && ($active_feed_id > 0 ||
$is_cat)) {
1148 print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
1150 //print "<option disabled>".__('This category')."</option>";
1157 print "<div class=\"dlgButtons\">";
1159 if (count(PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SEARCH
)) == 0) {
1160 print "<div style=\"float : left\">
1161 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">".__("Search syntax")."</a>
1165 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
1166 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>