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 $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";
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>";
89 $reply .= "<span class=\"sel_links\">
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, $check_first_id = false,
152 $skip_first_id_check = false) {
154 $disable_cache = false;
158 $rgba_cache = array();
160 $timing_info = microtime(true);
162 $topmost_article_ids = array();
164 if (!$offset) $offset = 0;
165 if ($method == "undefined") $method = "";
167 $method_split = explode(":", $method);
169 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
170 // Update the feed if required with some basic flood control
172 $any_needs_curl = false;
174 if (ini_get("open_basedir")) {
175 $pluginhost = PluginHost
::getInstance();
176 foreach ($pluginhost->get_plugins() as $plugin) {
177 $flags = $plugin->flags();
179 if (isset($flags["needs_curl"]) && $flags["needs_curl"]) {
180 $any_needs_curl = true;
186 //if ($_REQUEST["debug"]) print "<!-- any_needs_curl: $any_needs_curl -->";
188 if (!$any_needs_curl) {
190 $result = $this->dbh
->query(
191 "SELECT cache_images," . SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated
192 FROM ttrss_feeds WHERE id = '$feed'");
194 if ($this->dbh
->num_rows($result) != 0) {
195 $last_updated = strtotime($this->dbh
->fetch_result($result, 0, "last_updated"));
196 $cache_images = sql_bool_to_bool($this->dbh
->fetch_result($result, 0, "cache_images"));
198 if (!$cache_images && time() - $last_updated > 120) {
199 include "rssfuncs.php";
200 update_rss_feed($feed, true, true);
202 $this->dbh
->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
203 WHERE id = '$feed'");
207 $this->dbh
->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
208 WHERE id = '$feed'");
212 if ($method_split[0] == "MarkAllReadGR") {
213 catchup_feed($method_split[1], false);
216 // FIXME: might break tag display?
218 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
219 $result = $this->dbh
->query(
220 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
222 if ($this->dbh
->num_rows($result) == 0) {
223 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
227 @$search = $this->dbh
->escape_string($_REQUEST["query"]);
228 @$search_language = $this->dbh
->escape_string($_REQUEST["search_language"]); // PGSQL only
231 $disable_cache = true;
234 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
237 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX
&& $feed > LABEL_BASE_INDEX
) {
238 $handler = PluginHost
::getInstance()->get_feed_handler(
239 PluginHost
::feed_to_pfeed_id($feed));
244 "view_mode" => $view_mode,
245 "cat_view" => $cat_view,
247 "override_order" => $override_order,
249 "owner_uid" => $_SESSION["uid"],
252 "include_children" => $include_children);
254 $qfh_ret = $handler->get_headlines(PluginHost
::feed_to_pfeed_id($feed),
259 /*$qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $cat_view,
260 $search, false, $override_order, $offset, 0,
261 false, 0, $include_children, $topid);*/
263 //function queryFeedHeadlines($feed, $limit,
264 // $view_mode, $cat_view, $search, $search_mode,
265 // $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false,
266 // $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) {
271 "view_mode" => $view_mode,
272 "cat_view" => $cat_view,
274 "search_language" => $search_language,
275 "override_order" => $override_order,
277 "include_children" => $include_children,
278 "check_first_id" => $check_first_id,
279 "skip_first_id_check" => $skip_first_id_check
282 $qfh_ret = queryFeedHeadlines($params);
285 $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && $feed != -6;
287 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
289 $result = $qfh_ret[0];
290 $feed_title = $qfh_ret[1];
291 $feed_site_url = $qfh_ret[2];
292 $last_error = $qfh_ret[3];
293 $last_updated = strpos($qfh_ret[4], '1970-') === FALSE ?
294 make_local_datetime($qfh_ret[4], false) : __("Never");
295 $highlight_words = $qfh_ret[5];
296 $reply['first_id'] = $qfh_ret[6];
298 $vgroup_last_feed = $vgr_last_feed;
300 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
302 $feed, $cat_view, $search, $view_mode,
303 $last_error, $last_updated);
305 $headlines_count = is_numeric($result) ?
0 : $this->dbh
->num_rows($result);
308 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_HEADLINES_BEFORE
) as $p) {
309 $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret);
313 $reply['content'] = '';
315 if ($headlines_count > 0) {
320 $cur_feed_title = '';
322 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
324 $expand_cdm = get_pref('CDM_EXPANDED');
326 while ($line = $this->dbh
->fetch_assoc($result)) {
328 $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250);
330 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
331 $line = $p->hook_query_headlines($line, 250, false);
334 if (get_pref('SHOW_CONTENT_PREVIEW')) {
335 $content_preview = $line["content_preview"];
339 $feed_id = $line["feed_id"];
340 $label_cache = $line["label_cache"];
344 $label_cache = json_decode($label_cache, true);
347 if ($label_cache["no-labels"] == 1)
350 $labels = $label_cache;
354 if (!is_array($labels)) $labels = get_article_labels($id);
356 $labels_str = "<span class=\"HLLCTR-$id\">";
357 $labels_str .= format_article_labels($labels, $id);
358 $labels_str .= "</span>";
360 if (count($topmost_article_ids) < 3) {
361 array_push($topmost_article_ids, $id);
366 if (sql_bool_to_bool($line["unread"])) {
371 if (sql_bool_to_bool($line["marked"])) {
373 src=\"images/mark_set.png\"
374 class=\"markedPic\" alt=\"Unstar article\"
375 onclick='toggleMark($id)'>";
379 src=\"images/mark_unset.png\"
380 class=\"markedPic\" alt=\"Star article\"
381 onclick='toggleMark($id)'>";
384 if (sql_bool_to_bool($line["published"])) {
385 $published_pic = "<img src=\"images/pub_set.png\"
387 alt=\"Unpublish article\" onclick='togglePub($id)'>";
388 $class .= " published";
390 $published_pic = "<img src=\"images/pub_unset.png\"
392 alt=\"Publish article\" onclick='togglePub($id)'>";
395 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
396 # $line["title"] . "</a>";
398 # $content_link = "<a
399 # href=\"" . htmlspecialchars($line["link"]) . "\"
400 # onclick=\"view($id,$feed_id);\">" .
401 # $line["title"] . "</a>";
403 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
404 # $line["title"] . "</a>";
406 $updated_fmt = make_local_datetime($line["updated"], false, false, false, true);
407 $date_entered_fmt = T_sprintf("Imported at %s",
408 make_local_datetime($line["date_entered"], false));
410 $score = $line["score"];
412 $score_pic = "images/" . get_score_pic($score);
414 /* $score_title = __("(Click to change)");
415 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
416 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
418 $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
422 $hlc_suffix = "high";
423 } else if ($score < -100) {
429 $entry_author = $line["author"];
432 $entry_author = " — $entry_author";
435 $has_feed_icon = feed_has_icon($feed_id);
437 if ($has_feed_icon) {
438 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
440 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.png\" alt=\"\">";
443 $entry_site_url = $line["site_url"];
445 //setting feed headline background color, needs to change text color based on dark/light
446 $fav_color = $line['favicon_avg_color'];
448 require_once "colors.php";
450 if ($fav_color && $fav_color != 'fail') {
451 if (!isset($rgba_cache[$feed_id])) {
452 $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color));
456 if (!get_pref('COMBINED_DISPLAY_MODE')) {
458 if ($vfeed_group_enabled) {
459 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
461 $cur_feed_title = $line["feed_title"];
462 $vgroup_last_feed = $feed_id;
464 $cur_feed_title = htmlspecialchars($cur_feed_title);
466 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
468 $reply['content'] .= "<div data-feed-id='$feed_id' id='FTITLE-$feed_id' class='cdmFeedTitle'>".
469 "<div style='float : right'>$feed_icon_img</div>".
470 "<a class='title' href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
471 $line["feed_title"]."</a>
472 $vf_catchup_link</div>";
478 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
479 onmouseout='postMouseOut($id)'";
481 $reply['content'] .= "<div class='hl $class' data-orig-feed-id='$feed_id' data-article-id='$id' id='RROW-$id' $mouseover_attrs>";
483 $reply['content'] .= "<div class='hlLeft'>";
485 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
486 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
489 $reply['content'] .= "$marked_pic";
490 $reply['content'] .= "$published_pic";
492 $reply['content'] .= "</div>";
494 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
495 class=\"hlTitle\"><span class='hlContent $hlc_suffix'>";
496 $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title $hlc_suffix\"
497 href=\"" . htmlspecialchars($line["link"]) . "\"
499 truncate_string($line["title"], 200);
501 if (get_pref('SHOW_CONTENT_PREVIEW')) {
502 $reply['content'] .= "<span class=\"contentPreview\">" . $line["content_preview"] . "</span>";
505 $reply['content'] .= "</a></span>";
507 $reply['content'] .= $labels_str;
509 $reply['content'] .= "</div>";
511 if (!$vfeed_group_enabled) {
512 if (@$line["feed_title"]) {
513 $rgba = @$rgba_cache[$feed_id];
515 $reply['content'] .= "<span class=\"hlFeed\"><a style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
516 truncate_string($line["feed_title"],30)."</a></span>";
521 $reply['content'] .= "<span class=\"hlUpdated\">";
523 $reply['content'] .= "<div title='$date_entered_fmt'>$updated_fmt</div>
526 $reply['content'] .= "<div class=\"hlRight\">";
528 $reply['content'] .= $score_pic;
530 if ($line["feed_title"] && !$vfeed_group_enabled) {
532 $reply['content'] .= "<span onclick=\"viewfeed({feed:$feed_id})\"
533 style=\"cursor : pointer\"
534 title=\"".htmlspecialchars($line['feed_title'])."\">
535 $feed_icon_img</span>";
538 $reply['content'] .= "</div>";
539 $reply['content'] .= "</div>";
543 if ($line["tag_cache"])
544 $tags = explode(",", $line["tag_cache"]);
548 $line["content"] = sanitize($line["content"],
549 sql_bool_to_bool($line['hide_images']), false, $entry_site_url, $highlight_words, $line["id"]);
551 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_CDM
) as $p) {
552 $line = $p->hook_render_article_cdm($line);
555 if ($vfeed_group_enabled && $line["feed_title"]) {
556 if ($feed_id != $vgroup_last_feed) {
558 $cur_feed_title = $line["feed_title"];
559 $vgroup_last_feed = $feed_id;
561 $cur_feed_title = htmlspecialchars($cur_feed_title);
563 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
565 $has_feed_icon = feed_has_icon($feed_id);
567 if ($has_feed_icon) {
568 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
570 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
573 $reply['content'] .= "<div data-feed-id='$feed_id' id='FTITLE-$feed_id' class='cdmFeedTitle'>".
574 "<div style=\"float : right\">$feed_icon_img</div>".
575 "<a href=\"#\" class='title' onclick=\"viewfeed({feed:$feed_id})\">".
576 $line["feed_title"]."</a> $vf_catchup_link</div>";
581 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
582 onmouseout='postMouseOut($id)'";
584 $expanded_class = $expand_cdm ?
"expanded" : "expandable";
586 $reply['content'] .= "<div class=\"cdm $hlc_suffix $expanded_class $class\"
587 id=\"RROW-$id\" data-article-id='$id' data-orig-feed-id='$feed_id' $mouseover_attrs>";
589 $reply['content'] .= "<div class=\"cdmHeader\">";
590 $reply['content'] .= "<div style=\"vertical-align : middle\">";
592 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
593 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
596 $reply['content'] .= "$marked_pic";
597 $reply['content'] .= "$published_pic";
599 $reply['content'] .= "</div>";
601 if ($highlight_words && count($highlight_words > 0)) {
602 foreach ($highlight_words as $word) {
603 $line["title"] = preg_replace("/(\Q$word\E)/i",
604 "<span class=\"highlight\">$1</span>", $line["title"]);
608 $reply['content'] .= "<span id=\"RTITLE-$id\"
609 onclick=\"return cdmClicked(event, $id);\"
610 class=\"titleWrap $hlc_suffix\">
611 <a class=\"title $hlc_suffix\"
612 title=\"".htmlspecialchars($line["title"])."\"
613 target=\"_blank\" href=\"".
614 htmlspecialchars($line["link"])."\">".
616 "</a> <span class=\"author\">$entry_author</span>";
618 $reply['content'] .= $labels_str;
620 $reply['content'] .= "<span class='collapseBtn' style='display : none'>
621 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
622 title=\"".__("Collapse article")."\"/></span>";
625 $content_hidden = "style=\"display : none\"";
627 $excerpt_hidden = "style=\"display : none\"";
629 $reply['content'] .= "<span $excerpt_hidden id=\"CEXC-$id\" class=\"cdmExcerpt\">" . $content_preview . "</span>";
631 $reply['content'] .= "</span>";
633 if (!$vfeed_group_enabled) {
634 if (@$line["feed_title"]) {
635 $rgba = @$rgba_cache[$feed_id];
637 $reply['content'] .= "<div class=\"hlFeed\">
638 <a href=\"#\" style=\"background-color: rgba($rgba,0.3)\"
639 onclick=\"viewfeed({feed:$feed_id})\">".
640 truncate_string($line["feed_title"],30)."</a>
645 $reply['content'] .= "<span class='updated' title='$date_entered_fmt'>
646 $updated_fmt</span>";
648 $reply['content'] .= "<div class='scoreWrap' style=\"vertical-align : middle\">";
649 $reply['content'] .= "$score_pic";
651 if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
652 $reply['content'] .= "<span style=\"cursor : pointer\"
653 title=\"".htmlspecialchars($line["feed_title"])."\"
654 onclick=\"viewfeed({feed:$feed_id})\">$feed_icon_img</span>";
656 $reply['content'] .= "</div>";
658 $reply['content'] .= "</div>";
660 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
661 onclick=\"return cdmClicked(event, $id);\"
664 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
666 $reply['content'] .= format_article_note($id, $line['note']);
668 $reply['content'] .= "</div>";
670 if (!$line['lang']) $line['lang'] = 'en';
672 $reply['content'] .= "<div class=\"cdmContentInner\" lang=\"".$line['lang']."\">";
674 if ($line["orig_feed_id"]) {
676 $tmp_result = $this->dbh
->query("SELECT * FROM ttrss_archived_feeds
677 WHERE id = ".$line["orig_feed_id"] . " AND owner_uid = " . $_SESSION["uid"]);
679 if ($this->dbh
->num_rows($tmp_result) != 0) {
681 $reply['content'] .= "<div clear='both'>";
682 $reply['content'] .= __("Originally from:");
684 $reply['content'] .= " ";
686 $tmp_line = $this->dbh
->fetch_assoc($tmp_result);
688 $reply['content'] .= "<a target='_blank'
689 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
690 $tmp_line['title'] . "</a>";
692 $reply['content'] .= " ";
694 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
695 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.png'></a>";
697 $reply['content'] .= "</div>";
701 $reply['content'] .= "<span id=\"CWRAP-$id\">";
703 // if (!$expand_cdm) {
704 $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">";
705 $reply['content'] .= htmlspecialchars($line["content"]);
706 $reply['content'] .= "</span.";
709 // $reply['content'] .= $line["content"];
712 $reply['content'] .= "</span>";
714 $reply['content'] .= "</div>";
716 $reply['content'] .= "<div class=\"cdmIntermediate\">";
718 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
719 $reply['content'] .= format_article_enclosures($id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"]));
721 $reply['content'] .= "</div>";
723 $reply['content'] .= "<div class=\"cdmFooter\" onclick=\"cdmFooterClick(event)\">";
725 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_LEFT_BUTTON
) as $p) {
726 $reply['content'] .= $p->hook_article_left_button($line);
729 $tags_str = format_tags_string($tags, $id);
731 $reply['content'] .= "<span class='left'>";
733 $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>
734 <span id=\"ATSTR-$id\">$tags_str</span>
735 <a title=\"".__('Edit tags for this article')."\"
736 href=\"#\" onclick=\"editArticleTags($id)\">(+)</a>";
738 $num_comments = $line["num_comments"];
739 $entry_comments = "";
741 if ($num_comments > 0) {
742 if ($line["comments"]) {
743 $comments_url = htmlspecialchars($line["comments"]);
745 $comments_url = htmlspecialchars($line["link"]);
747 $entry_comments = "<a class=\"postComments\"
748 target='_blank' href=\"$comments_url\">$num_comments ".
749 _ngettext("comment", "comments", $num_comments)."</a>";
752 if ($line["comments"] && $line["link"] != $line["comments"]) {
753 $entry_comments = "<a class=\"postComments\" target='_blank' href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
757 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
759 $reply['content'] .= "</span>";
760 $reply['content'] .= "<div>";
762 // $reply['content'] .= "$marked_pic";
763 // $reply['content'] .= "$published_pic";
765 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_BUTTON
) as $p) {
766 $reply['content'] .= $p->hook_article_button($line);
769 $reply['content'] .= "</div>";
770 $reply['content'] .= "</div>";
772 $reply['content'] .= "</div>";
774 $reply['content'] .= "</div>";
781 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
783 } else if (!is_numeric($result)) {
786 switch ($view_mode) {
788 $message = __("No unread articles found to display.");
791 $message = __("No updated articles found to display.");
794 $message = __("No starred articles found to display.");
797 if ($feed < LABEL_BASE_INDEX
) {
798 $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.");
800 $message = __("No articles found to display.");
804 if (!$offset && $message) {
805 $reply['content'] = "<div class='whiteBox'>$message";
807 $reply['content'] .= "<p><span class=\"insensitive\">";
809 $result = $this->dbh
->query("SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
810 WHERE owner_uid = " . $_SESSION['uid']);
812 $last_updated = $this->dbh
->fetch_result($result, 0, "last_updated");
813 $last_updated = make_local_datetime($last_updated, false);
815 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
817 $result = $this->dbh
->query("SELECT COUNT(id) AS num_errors
818 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
820 $num_errors = $this->dbh
->fetch_result($result, 0, "num_errors");
822 if ($num_errors > 0) {
823 $reply['content'] .= "<br/>";
824 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
825 __('Some feeds have update errors (click for details)')."</a>";
827 $reply['content'] .= "</span></p></div>";
830 } else if (is_numeric($result) && $result == -1) {
831 $reply['first_id_changed'] = true;
834 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
836 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
837 $vgroup_last_feed, $reply);
840 function catchupAll() {
841 $this->dbh
->query("UPDATE ttrss_user_entries SET
842 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
843 ccache_zero_all($_SESSION["uid"]);
847 $timing_info = microtime(true);
851 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
853 $feed = $this->dbh
->escape_string($_REQUEST["feed"]);
854 $method = $this->dbh
->escape_string($_REQUEST["m"]);
855 $view_mode = $this->dbh
->escape_string($_REQUEST["view_mode"]);
857 @$cat_view = $_REQUEST["cat"] == "true";
858 @$next_unread_feed = $this->dbh
->escape_string($_REQUEST["nuf"]);
859 @$offset = $this->dbh
->escape_string($_REQUEST["skip"]);
860 @$vgroup_last_feed = $this->dbh
->escape_string($_REQUEST["vgrlf"]);
861 $order_by = $this->dbh
->escape_string($_REQUEST["order_by"]);
862 $check_first_id = $this->dbh
->escape_string($_REQUEST["fid"]);
864 if (is_numeric($feed)) $feed = (int) $feed;
866 /* Feed -5 is a special case: it is used to display auxiliary information
867 * when there's nothing to load - e.g. no stuff in fresh feed */
870 print json_encode($this->generate_dashboard_feed());
876 if ($feed < LABEL_BASE_INDEX
) {
877 $label_feed = feed_to_label_id($feed);
878 $result = $this->dbh
->query("SELECT id FROM ttrss_labels2 WHERE
879 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
880 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
881 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
882 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
883 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
884 $result = $this->dbh
->query("SELECT id FROM ttrss_feed_categories WHERE
885 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
888 if ($result && $this->dbh
->num_rows($result) == 0) {
889 print json_encode($this->generate_error_feed(__("Feed not found.")));
893 /* Updating a label ccache means recalculating all of the caches
894 * so for performance reasons we don't do that here */
897 ccache_update($feed, $_SESSION["uid"], $cat_view);
900 set_pref("_DEFAULT_VIEW_MODE", $view_mode);
901 set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by);
903 /* bump login timestamp if needed */
904 if (time() - $_SESSION["last_login_update"] > 3600) {
905 $this->dbh
->query("UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
907 $_SESSION["last_login_update"] = time();
910 if (!$cat_view && is_numeric($feed) && $feed > 0) {
911 $this->dbh
->query("UPDATE ttrss_feeds SET last_viewed = NOW()
912 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
915 $reply['headlines'] = array();
917 $override_order = false;
918 $skip_first_id_check = false;
922 $override_order = "ttrss_entries.title";
925 $override_order = "score DESC, date_entered, updated";
926 $skip_first_id_check = true;
929 $override_order = "updated DESC";
933 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
935 $ret = $this->format_headlines_list($feed, $method,
936 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
937 $vgroup_last_feed, $override_order, true, $check_first_id, $skip_first_id_check);
939 //$topmost_article_ids = $ret[0];
940 $headlines_count = $ret[1];
941 /* $returned_feed = $ret[2]; */
942 $disable_cache = $ret[3];
943 $vgroup_last_feed = $ret[4];
945 //$reply['headlines']['content'] =& $ret[5]['content'];
946 //$reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
948 $reply['headlines'] = $ret[5];
950 if (!$next_unread_feed)
951 $reply['headlines']['id'] = $feed;
953 $reply['headlines']['id'] = $next_unread_feed;
955 $reply['headlines']['is_cat'] = (bool) $cat_view;
957 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
959 $reply['headlines-info'] = array("count" => (int) $headlines_count,
960 "vgroup_last_feed" => $vgroup_last_feed,
961 "disable_cache" => (bool) $disable_cache);
963 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
965 $reply['runtime-info'] = make_runtime_info();
967 print json_encode($reply);
971 private function generate_dashboard_feed() {
974 $reply['headlines']['id'] = -5;
975 $reply['headlines']['is_cat'] = false;
977 $reply['headlines']['toolbar'] = '';
979 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
981 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
983 $result = $this->dbh
->query("SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
984 WHERE owner_uid = " . $_SESSION['uid']);
986 $last_updated = $this->dbh
->fetch_result($result, 0, "last_updated");
987 $last_updated = make_local_datetime($last_updated, false);
989 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
991 $result = $this->dbh
->query("SELECT COUNT(id) AS num_errors
992 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
994 $num_errors = $this->dbh
->fetch_result($result, 0, "num_errors");
996 if ($num_errors > 0) {
997 $reply['headlines']['content'] .= "<br/>";
998 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
999 __('Some feeds have update errors (click for details)')."</a>";
1001 $reply['headlines']['content'] .= "</span></p>";
1003 $reply['headlines-info'] = array("count" => 0,
1004 "vgroup_last_feed" => '',
1006 "disable_cache" => true);
1011 private function generate_error_feed($error) {
1014 $reply['headlines']['id'] = -7;
1015 $reply['headlines']['is_cat'] = false;
1017 $reply['headlines']['toolbar'] = '';
1018 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
1020 $reply['headlines-info'] = array("count" => 0,
1021 "vgroup_last_feed" => '',
1023 "disable_cache" => true);
1028 function quickAddFeed() {
1029 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
1030 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">";
1032 print "<div id='fadd_multiple_notify' style='display : none'>";
1033 print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below.");
1036 print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
1037 print "<div class=\"dlgSecCont\">";
1039 print "<div style='float : right'>
1040 <img style='display : none'
1041 id='feed_add_spinner' src='images/indicator_white.gif'></div>";
1043 print "<input style=\"font-size : 16px; width : 20em;\"
1044 placeHolder=\"".__("Feed or site URL")."\"
1045 dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
1049 if (get_pref('ENABLE_FEED_CATS')) {
1050 print __('Place in category:') . " ";
1051 print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
1056 print '<div id="feedDlg_feedsContainer" style="display : none">
1058 <div class="dlgSec">' . __('Available feeds') . '</div>
1059 <div class="dlgSecCont">'.
1060 '<select id="feedDlg_feedContainerSelect"
1061 dojoType="dijit.form.Select" size="3">
1062 <script type="dojo/method" event="onChange" args="value">
1063 dijit.byId("feedDlg_feedUrl").attr("value", value);
1068 print "<div id='feedDlg_loginContainer' style='display : none'>
1070 <div class=\"dlgSec\">".__("Authentication")."</div>
1071 <div class=\"dlgSecCont\">".
1073 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
1074 placeHolder=\"".__("Login")."\"
1075 style=\"width : 10em;\"> ".
1077 placeHolder=\"".__("Password")."\"
1078 dojoType=\"dijit.form.TextBox\" type='password'
1079 style=\"width : 10em;\" name='pass'\">
1083 print "<div style=\"clear : both\">
1084 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
1085 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
1086 <label for=\"feedDlg_loginCheck\">".
1087 __('This feed requires authentication.')."</div>";
1091 print "<div class=\"dlgButtons\">
1092 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
1094 if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
)) {
1095 print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
1098 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
1104 function feedBrowser() {
1105 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
) return;
1107 $browser_search = $this->dbh
->escape_string($_REQUEST["search"]);
1109 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
1110 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">";
1112 print "<div dojoType=\"dijit.Toolbar\">
1113 <div style='float : right'>
1114 <img style='display : none'
1115 id='feed_browser_spinner' src='images/indicator_white.gif'>
1116 <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
1117 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
1118 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
1121 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
1122 <option value='1'>" . __('Popular feeds') . "</option>
1123 <option value='2'>" . __('Feed archive') . "</option>
1128 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
1130 foreach (array(25, 50, 100, 200) as $l) {
1131 //$issel = ($l == $limit) ? "selected=\"1\"" : "";
1132 print "<option value=\"$l\">$l</option>";
1139 require_once "feedbrowser.php";
1141 print "<ul class='browseFeedList' id='browseFeedList'>";
1142 print make_feed_browser("", 25);
1145 print "<div align='center'>
1146 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
1147 <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
1148 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
1153 $this->params
= explode(":", $this->dbh
->escape_string($_REQUEST["param"]), 2);
1155 $active_feed_id = sprintf("%d", $this->params
[0]);
1156 $is_cat = $this->params
[1] != "false";
1158 print "<div class=\"dlgSec\">".__('Look for')."</div>";
1160 print "<div class=\"dlgSecCont\">";
1162 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1163 style=\"font-size : 16px; width : 20em;\"
1164 required=\"1\" name=\"query\" type=\"search\" value=''>";
1166 print "<hr/><span style='float : right'>".T_sprintf('in %s', getFeedTitle($active_feed_id, $is_cat))."</span>";
1168 if (DB_TYPE
== "pgsql") {
1170 print_select("search_language", "", Pref_Feeds
::$feed_languages,
1171 "dojoType='dijit.form.Select' title=\"".__('Used for word stemming')."\"");
1176 print "<div class=\"dlgButtons\">";
1178 if (count(PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SEARCH
)) == 0) {
1179 print "<div style=\"float : left\">
1180 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">".__("Search syntax")."</a>
1184 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
1185 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>
1189 function update_debugger() {
1190 header("Content-type: text/html");
1192 $feed_id = (int)$_REQUEST["feed_id"];
1193 @$do_update = $_REQUEST["action"] == "do_update";
1194 $csrf_token = $_REQUEST["csrf_token"];
1196 $refetch_checked = isset($_REQUEST["force_refetch"]) ?
"checked" : "";
1197 $rehash_checked = isset($_REQUEST["force_rehash"]) ?
"checked" : "";
1202 <link rel
="stylesheet" type
="text/css" href
="css/utility.css">
1203 <title
>Feed Debugger
</title
>
1205 <body
class="small_margins">
1206 <h1
>Feed Debugger
: <?php
echo "$feed_id: " . getFeedTitle($feed_id) ?
></h1
>
1207 <form method
="GET" action
="">
1208 <input type
="hidden" name
="op" value
="feeds">
1209 <input type
="hidden" name
="method" value
="update_debugger">
1210 <input type
="hidden" name
="xdebug" value
="1">
1211 <input type
="hidden" name
="csrf_token" value
="<?php echo $csrf_token ?>">
1212 <input type
="hidden" name
="action" value
="do_update">
1213 <input type
="hidden" name
="feed_id" value
="<?php echo $feed_id ?>">
1214 <input type
="checkbox" name
="force_refetch" value
="1" <?php
echo $refetch_checked ?
>> Force refetch
<br
/>
1215 <input type
="checkbox" name
="force_rehash" value
="1" <?php
echo $rehash_checked ?
>> Force rehash
<br
/>
1217 <p
/><button type
="submit">Continue</button
>
1225 include "rssfuncs.php";
1226 update_rss_feed($feed_id, true, true);