2 require_once "colors.php";
4 class Feeds
extends Handler_Protected
{
6 function csrf_ignore($method) {
7 $csrf_ignored = array("index", "feedbrowser", "quickaddfeed", "search");
9 return array_search($method, $csrf_ignored) !== false;
12 private function format_headline_subtoolbar($feed_site_url, $feed_title,
13 $feed_id, $is_cat, $search,
14 $search_mode, $view_mode, $error, $feed_last_updated) {
16 $page_prev_link = "viewFeedGoPage(-1)";
17 $page_next_link = "viewFeedGoPage(1)";
18 $page_first_link = "viewFeedGoPage(0)";
20 $catchup_page_link = "catchupPage()";
21 $catchup_feed_link = "catchupCurrentFeed()";
22 $catchup_sel_link = "catchupSelection()";
24 $archive_sel_link = "archiveSelection()";
25 $delete_sel_link = "deleteSelection()";
27 $sel_all_link = "selectArticles('all')";
28 $sel_unread_link = "selectArticles('unread')";
29 $sel_none_link = "selectArticles('none')";
30 $sel_inv_link = "selectArticles('invert')";
32 $tog_unread_link = "selectionToggleUnread()";
33 $tog_marked_link = "selectionToggleMarked()";
34 $tog_published_link = "selectionTogglePublished()";
36 $set_score_link = "setSelectionScore()";
38 if ($is_cat) $cat_q = "&is_cat=$is_cat";
41 $search_q = "&q=$search&smode=$search_mode";
46 $rss_link = htmlspecialchars(get_self_url_prefix() .
47 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
51 $error_class = $error ?
"error" : "";
53 $reply .= "<span class='r'>";
54 $reply .= "<span id='selected_prompt'></span>";
55 $reply .= "<span id='feed_title' class='$error_class'>";
58 $last_updated = T_sprintf("Last updated: %s",
61 $target = "target=\"_blank\"";
62 $reply .= "<a title=\"$last_updated\" $target href=\"$feed_site_url\">".
63 truncate_string($feed_title,30)."</a>";
66 $reply .= " <img title='$error' src='images/error.png' alt='error' class=\"noborder\" style=\"vertical-align : middle\">";
70 $reply .= $feed_title;
77 title=\"".__("View as RSS feed")."\"
78 onclick=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">
79 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/pub_set.png\"></a>";
85 $reply .= __('Select:')."
86 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
87 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
88 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
89 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
93 $reply .= "<select dojoType=\"dijit.form.Select\"
94 onchange=\"headlineActionsChange(this)\">";
95 $reply .= "<option value=\"false\">".__('More...')."</option>";
97 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
99 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
100 <option value=\"$tog_marked_link\">".__('Starred')."</option>
101 <option value=\"$tog_published_link\">".__('Published')."</option>";
103 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
105 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
106 $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>";
108 if ($feed_id != "0") {
109 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
111 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
112 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
116 if (PluginHost
::getInstance()->get_plugin("mail")) {
117 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
121 if (PluginHost
::getInstance()->get_plugin("mailto")) {
122 $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
126 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
128 //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
130 $reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
132 $reply .= "</select>";
134 //$reply .= "</div>";
138 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_HEADLINE_TOOLBAR_BUTTON
) as $p) {
139 echo $p->hook_headline_toolbar_button($feed_id, $is_cat);
145 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
146 $next_unread_feed, $offset, $vgr_last_feed = false,
147 $override_order = false, $include_children = false) {
149 if (isset($_REQUEST["DevForceUpdate"]))
150 header("Content-Type: text/plain");
152 $disable_cache = false;
156 $rgba_cache = array();
158 $timing_info = microtime(true);
160 $topmost_article_ids = array();
162 if (!$offset) $offset = 0;
163 if ($method == "undefined") $method = "";
165 $method_split = explode(":", $method);
167 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
168 // Update the feed if required with some basic flood control
170 $result = $this->dbh
->query(
171 "SELECT cache_images,".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
172 FROM ttrss_feeds WHERE id = '$feed'");
174 if ($this->dbh
->num_rows($result) != 0) {
175 $last_updated = strtotime($this->dbh
->fetch_result($result, 0, "last_updated"));
176 $cache_images = sql_bool_to_bool($this->dbh
->fetch_result($result, 0, "cache_images"));
178 if (!$cache_images && time() - $last_updated > 120 ||
isset($_REQUEST['DevForceUpdate'])) {
179 include "rssfuncs.php";
180 update_rss_feed($feed, true, true);
182 $this->dbh
->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
183 WHERE id = '$feed'");
188 if ($method_split[0] == "MarkAllReadGR") {
189 catchup_feed($method_split[1], false);
192 // FIXME: might break tag display?
194 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
195 $result = $this->dbh
->query(
196 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
198 if ($this->dbh
->num_rows($result) == 0) {
199 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
203 @$search = $this->dbh
->escape_string($_REQUEST["query"]);
206 $disable_cache = true;
209 @$search_mode = $this->dbh
->escape_string($_REQUEST["search_mode"]);
211 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
213 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
214 if($search_mode == '' && $method != '' ){
215 $search_mode = $method;
217 // error_log("search_mode: " . $search_mode);
219 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX
&& $feed > LABEL_BASE_INDEX
) {
220 $handler = PluginHost
::getInstance()->get_feed_handler(
221 PluginHost
::feed_to_pfeed_id($feed));
223 // 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) {
228 "view_mode" => $view_mode,
229 "cat_view" => $cat_view,
231 "search_mode" => $search_mode,
232 "override_order" => $override_order,
234 "owner_uid" => $_SESSION["uid"],
237 "include_children" => $include_children);
239 $qfh_ret = $handler->get_headlines(PluginHost
::feed_to_pfeed_id($feed),
244 $qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $cat_view,
245 $search, $search_mode, $override_order, $offset, 0,
246 false, 0, $include_children);
249 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
251 $result = $qfh_ret[0];
252 $feed_title = $qfh_ret[1];
253 $feed_site_url = $qfh_ret[2];
254 $last_error = $qfh_ret[3];
255 $last_updated = strpos($qfh_ret[4], '1970-') === FALSE ?
256 make_local_datetime($qfh_ret[4], false) : __("Never");
258 $vgroup_last_feed = $vgr_last_feed;
260 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
262 $feed, $cat_view, $search, $search_mode, $view_mode,
263 $last_error, $last_updated);
265 $headlines_count = $this->dbh
->num_rows($result);
267 /* if (get_pref('COMBINED_DISPLAY_MODE')) {
268 $button_plugins = array();
269 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
270 $pclass = "button_" . trim($p);
272 if (class_exists($pclass)) {
273 $plugin = new $pclass();
274 array_push($button_plugins, $plugin);
279 if ($this->dbh
->num_rows($result) > 0) {
284 $cur_feed_title = '';
286 $fresh_intl = get_pref("FRESH_ARTICLE_MAX_AGE") * 60 * 60;
288 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
290 $expand_cdm = get_pref('CDM_EXPANDED');
292 while ($line = $this->dbh
->fetch_assoc($result)) {
293 $line["content_preview"] = "— " . truncate_string(strip_tags($line["content_preview"]), 250);
295 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
296 $line = $p->hook_query_headlines($line, 250, false);
299 if (get_pref('SHOW_CONTENT_PREVIEW')) {
300 $content_preview = $line["content_preview"];
304 $feed_id = $line["feed_id"];
305 $label_cache = $line["label_cache"];
309 $label_cache = json_decode($label_cache, true);
312 if ($label_cache["no-labels"] == 1)
315 $labels = $label_cache;
319 if (!is_array($labels)) $labels = get_article_labels($id);
321 $labels_str = "<span class=\"HLLCTR-$id\">";
322 $labels_str .= format_article_labels($labels, $id);
323 $labels_str .= "</span>";
325 if (count($topmost_article_ids) < 3) {
326 array_push($topmost_article_ids, $id);
331 if (sql_bool_to_bool($line["unread"])) {
336 if (sql_bool_to_bool($line["marked"])) {
338 src=\"images/mark_set.png\"
339 class=\"markedPic\" alt=\"Unstar article\"
340 onclick='toggleMark($id)'>";
344 src=\"images/mark_unset.png\"
345 class=\"markedPic\" alt=\"Star article\"
346 onclick='toggleMark($id)'>";
349 if (sql_bool_to_bool($line["published"])) {
350 $published_pic = "<img src=\"images/pub_set.png\"
352 alt=\"Unpublish article\" onclick='togglePub($id)'>";
353 $class .= " published";
355 $published_pic = "<img src=\"images/pub_unset.png\"
357 alt=\"Publish article\" onclick='togglePub($id)'>";
360 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
361 # $line["title"] . "</a>";
363 # $content_link = "<a
364 # href=\"" . htmlspecialchars($line["link"]) . "\"
365 # onclick=\"view($id,$feed_id);\">" .
366 # $line["title"] . "</a>";
368 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
369 # $line["title"] . "</a>";
371 $updated_fmt = make_local_datetime($line["updated"], false);
372 $date_entered_fmt = T_sprintf("Imported at %s",
373 make_local_datetime($line["date_entered"], false));
375 $score = $line["score"];
377 $score_pic = "images/" . get_score_pic($score);
379 /* $score_title = __("(Click to change)");
380 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
381 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
383 $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
387 $hlc_suffix = "high";
388 } else if ($score < -100) {
394 $entry_author = $line["author"];
397 $entry_author = " — $entry_author";
400 $has_feed_icon = feed_has_icon($feed_id);
402 if ($has_feed_icon) {
403 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
405 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.png\" alt=\"\">";
408 $entry_site_url = $line["site_url"];
410 //setting feed headline background color, needs to change text color based on dark/light
411 $fav_color = $line['favicon_avg_color'];
413 require_once "colors.php";
415 if ($fav_color && $fav_color != 'fail') {
416 if (!isset($rgba_cache[$feed_id])) {
417 $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color));
421 if (!get_pref('COMBINED_DISPLAY_MODE')) {
423 if (get_pref('VFEED_GROUP_BY_FEED')) {
424 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
426 $cur_feed_title = $line["feed_title"];
427 $vgroup_last_feed = $feed_id;
429 $cur_feed_title = htmlspecialchars($cur_feed_title);
431 $vf_catchup_link = "(<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('Mark as read')."</a>)";
433 $reply['content'] .= "<div class='cdmFeedTitle'>".
434 "<div style=\"float : right\">$feed_icon_img</div>".
435 "<a class='title' href=\"#\" onclick=\"viewfeed($feed_id)\">".
436 $line["feed_title"]."</a> $vf_catchup_link</div>";
441 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
442 onmouseout='postMouseOut($id)'";
444 $reply['content'] .= "<div class='hl $class' id='RROW-$id' $mouseover_attrs>";
446 $reply['content'] .= "<div class='hlLeft'>";
448 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
449 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
452 $reply['content'] .= "$marked_pic";
453 $reply['content'] .= "$published_pic";
455 $reply['content'] .= "</div>";
457 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
458 class=\"hlTitle\"><span class='hlContent $hlc_suffix'>";
459 $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title $hlc_suffix\"
460 href=\"" . htmlspecialchars($line["link"]) . "\"
462 truncate_string($line["title"], 200);
464 if (get_pref('SHOW_CONTENT_PREVIEW')) {
465 $reply['content'] .= "<span class=\"contentPreview\">" . $line["content_preview"] . "</span>";
468 $reply['content'] .= "</a></span>";
470 $reply['content'] .= $labels_str;
472 $reply['content'] .= "</div>";
474 $reply['content'] .= "<span class=\"hlUpdated\">";
476 if (!get_pref('VFEED_GROUP_BY_FEED')) {
477 if (@$line["feed_title"]) {
478 $rgba = @$rgba_cache[$feed_id];
480 $reply['content'] .= "<a class=\"hlFeed\" style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed($feed_id)\">".
481 truncate_string($line["feed_title"],30)."</a>";
485 $reply['content'] .= "<div title='$date_entered_fmt'>$updated_fmt</div>
488 $reply['content'] .= "<div class=\"hlRight\">";
490 $reply['content'] .= $score_pic;
492 if ($line["feed_title"] && !get_pref('VFEED_GROUP_BY_FEED')) {
494 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
495 style=\"cursor : pointer\"
496 title=\"".htmlspecialchars($line['feed_title'])."\">
497 $feed_icon_img<span>";
500 $reply['content'] .= "</div>";
501 $reply['content'] .= "</div>";
505 if ($line["tag_cache"])
506 $tags = explode(",", $line["tag_cache"]);
510 $line["content"] = sanitize($line["content"],
511 sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
513 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_CDM
) as $p) {
514 $line = $p->hook_render_article_cdm($line);
517 if (get_pref('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 class='catchup' 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=\"#\" class='title' onclick=\"viewfeed($feed_id)\">".
538 $line["feed_title"]."</a> $vf_catchup_link</div>";
542 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
543 onmouseout='postMouseOut($id)'";
545 $expanded_class = $expand_cdm ?
"expanded" : "expandable";
547 $reply['content'] .= "<div class=\"cdm $hlc_suffix $expanded_class $class\"
548 id=\"RROW-$id\" $mouseover_attrs>";
550 $reply['content'] .= "<div class=\"cdmHeader\" style=\"$row_background\">";
551 $reply['content'] .= "<div style=\"vertical-align : middle\">";
553 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
554 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
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\">
565 <a class=\"title $hlc_suffix\"
566 target=\"_blank\" href=\"".
567 htmlspecialchars($line["link"])."\">".
569 "</a> <span class=\"author\">$entry_author</span>";
571 $reply['content'] .= $labels_str;
573 $reply['content'] .= "<span class='collapseBtn' style='display : none'>
574 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
575 title=\"".__("Collapse article")."\"/></span>";
578 $content_hidden = "style=\"display : none\"";
580 $excerpt_hidden = "style=\"display : none\"";
582 $reply['content'] .= "<span $excerpt_hidden id=\"CEXC-$id\" class=\"cdmExcerpt\">" . $line["content_preview"] . "</span>";
584 $reply['content'] .= "</span>";
586 if (!get_pref('VFEED_GROUP_BY_FEED')) {
587 if (@$line["feed_title"]) {
588 $rgba = @$rgba_cache[$feed_id];
590 $reply['content'] .= "<div class=\"hlFeed\">
591 <a href=\"#\" style=\"background-color: rgba($rgba,0.3)\"
592 onclick=\"viewfeed($feed_id)\">".
593 truncate_string($line["feed_title"],30)."</a>
598 $reply['content'] .= "<span class='updated' title='$date_entered_fmt'>
599 $updated_fmt</span>";
601 $reply['content'] .= "<div class='scoreWrap' style=\"vertical-align : middle\">";
602 $reply['content'] .= "$score_pic";
604 if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
605 $reply['content'] .= "<span style=\"cursor : pointer\"
606 title=\"".htmlspecialchars($line["feed_title"])."\"
607 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
609 $reply['content'] .= "</div>";
611 $reply['content'] .= "</div>";
613 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
614 onclick=\"return cdmClicked(event, $id);\"
617 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
619 $reply['content'] .= format_article_note($id, $line['note']);
621 $reply['content'] .= "</div>";
623 $reply['content'] .= "<div class=\"cdmContentInner\">";
625 if ($line["orig_feed_id"]) {
627 $tmp_result = $this->dbh
->query("SELECT * FROM ttrss_archived_feeds
628 WHERE id = ".$line["orig_feed_id"]);
630 if ($this->dbh
->num_rows($tmp_result) != 0) {
632 $reply['content'] .= "<div clear='both'>";
633 $reply['content'] .= __("Originally from:");
635 $reply['content'] .= " ";
637 $tmp_line = $this->dbh
->fetch_assoc($tmp_result);
639 $reply['content'] .= "<a target='_blank'
640 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
641 $tmp_line['title'] . "</a>";
643 $reply['content'] .= " ";
645 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
646 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.png'></a>";
648 $reply['content'] .= "</div>";
652 $reply['content'] .= "<span id=\"CWRAP-$id\">";
654 // if (!$expand_cdm) {
655 $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">";
656 $reply['content'] .= htmlspecialchars($line["content"]);
657 $reply['content'] .= "</span.";
660 // $reply['content'] .= $line["content"];
663 $reply['content'] .= "</span>";
665 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
667 $reply['content'] .= format_article_enclosures($id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"]));
669 $reply['content'] .= "</div>";
671 $reply['content'] .= "<div class=\"cdmFooter\">";
673 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_LEFT_BUTTON
) as $p) {
674 $reply['content'] .= $p->hook_article_left_button($line);
677 $tags_str = format_tags_string($tags, $id);
679 $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>
680 <span id=\"ATSTR-$id\">$tags_str</span>
681 <a title=\"".__('Edit tags for this article')."\"
682 href=\"#\" onclick=\"editArticleTags($id)\">(+)</a>";
684 $num_comments = $line["num_comments"];
685 $entry_comments = "";
687 if ($num_comments > 0) {
688 if ($line["comments"]) {
689 $comments_url = htmlspecialchars($line["comments"]);
691 $comments_url = htmlspecialchars($line["link"]);
693 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
695 if ($line["comments"] && $line["link"] != $line["comments"]) {
696 $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";
700 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
702 $reply['content'] .= "<div style=\"float : right\">";
704 // $reply['content'] .= "$marked_pic";
705 // $reply['content'] .= "$published_pic";
707 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_BUTTON
) as $p) {
708 $reply['content'] .= $p->hook_article_button($line);
711 $reply['content'] .= "</div>";
712 $reply['content'] .= "</div>";
714 $reply['content'] .= "</div><hr/>";
716 $reply['content'] .= "</div>";
723 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
728 switch ($view_mode) {
730 $message = __("No unread articles found to display.");
733 $message = __("No updated articles found to display.");
736 $message = __("No starred articles found to display.");
739 if ($feed < LABEL_BASE_INDEX
) {
740 $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.");
742 $message = __("No articles found to display.");
746 if (!$offset && $message) {
747 $reply['content'] .= "<div class='whiteBox'>$message";
749 $reply['content'] .= "<p><span class=\"insensitive\">";
751 $result = $this->dbh
->query("SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
752 WHERE owner_uid = " . $_SESSION['uid']);
754 $last_updated = $this->dbh
->fetch_result($result, 0, "last_updated");
755 $last_updated = make_local_datetime($last_updated, false);
757 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
759 $result = $this->dbh
->query("SELECT COUNT(id) AS num_errors
760 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
762 $num_errors = $this->dbh
->fetch_result($result, 0, "num_errors");
764 if ($num_errors > 0) {
765 $reply['content'] .= "<br/>";
766 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
767 __('Some feeds have update errors (click for details)')."</a>";
769 $reply['content'] .= "</span></p></div>";
773 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
775 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
776 $vgroup_last_feed, $reply);
779 function catchupAll() {
780 $this->dbh
->query("UPDATE ttrss_user_entries SET
781 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
782 ccache_zero_all($_SESSION["uid"]);
786 $timing_info = microtime(true);
790 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
792 $omode = $this->dbh
->escape_string($_REQUEST["omode"]);
794 $feed = $this->dbh
->escape_string($_REQUEST["feed"]);
795 $method = $this->dbh
->escape_string($_REQUEST["m"]);
796 $view_mode = $this->dbh
->escape_string($_REQUEST["view_mode"]);
798 @$cat_view = $_REQUEST["cat"] == "true";
799 @$next_unread_feed = $this->dbh
->escape_string($_REQUEST["nuf"]);
800 @$offset = $this->dbh
->escape_string($_REQUEST["skip"]);
801 @$vgroup_last_feed = $this->dbh
->escape_string($_REQUEST["vgrlf"]);
802 $order_by = $this->dbh
->escape_string($_REQUEST["order_by"]);
804 if (is_numeric($feed)) $feed = (int) $feed;
806 /* Feed -5 is a special case: it is used to display auxiliary information
807 * when there's nothing to load - e.g. no stuff in fresh feed */
810 print json_encode($this->generate_dashboard_feed());
816 if ($feed < LABEL_BASE_INDEX
) {
817 $label_feed = feed_to_label_id($feed);
818 $result = $this->dbh
->query("SELECT id FROM ttrss_labels2 WHERE
819 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
820 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
821 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
822 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
823 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
824 $result = $this->dbh
->query("SELECT id FROM ttrss_feed_categories WHERE
825 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
828 if ($result && $this->dbh
->num_rows($result) == 0) {
829 print json_encode($this->generate_error_feed(__("Feed not found.")));
833 /* Updating a label ccache means recalculating all of the caches
834 * so for performance reasons we don't do that here */
837 ccache_update($feed, $_SESSION["uid"], $cat_view);
840 set_pref("_DEFAULT_VIEW_MODE", $view_mode);
841 set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by);
843 /* bump login timestamp if needed */
844 if (time() - $_SESSION["last_login_update"] > 3600) {
845 $this->dbh
->query("UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
847 $_SESSION["last_login_update"] = time();
850 if (!$cat_view && is_numeric($feed) && $feed > 0) {
851 $this->dbh
->query("UPDATE ttrss_feeds SET last_viewed = NOW()
852 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
855 $reply['headlines'] = array();
857 if (!$next_unread_feed)
858 $reply['headlines']['id'] = $feed;
860 $reply['headlines']['id'] = $next_unread_feed;
862 $reply['headlines']['is_cat'] = (bool) $cat_view;
864 $override_order = false;
868 $override_order = "ttrss_entries.title";
871 $override_order = "score DESC, date_entered, updated";
874 $override_order = "updated DESC";
878 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
880 $ret = $this->format_headlines_list($feed, $method,
881 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
882 $vgroup_last_feed, $override_order, true);
884 //$topmost_article_ids = $ret[0];
885 $headlines_count = $ret[1];
886 $returned_feed = $ret[2];
887 $disable_cache = $ret[3];
888 $vgroup_last_feed = $ret[4];
890 $reply['headlines']['content'] =& $ret[5]['content'];
891 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
893 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
895 $reply['headlines-info'] = array("count" => (int) $headlines_count,
896 "vgroup_last_feed" => $vgroup_last_feed,
897 "disable_cache" => (bool) $disable_cache);
899 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
901 $reply['runtime-info'] = make_runtime_info();
903 print json_encode($reply);
907 private function generate_dashboard_feed() {
910 $reply['headlines']['id'] = -5;
911 $reply['headlines']['is_cat'] = false;
913 $reply['headlines']['toolbar'] = '';
914 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
916 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
918 $result = $this->dbh
->query("SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
919 WHERE owner_uid = " . $_SESSION['uid']);
921 $last_updated = $this->dbh
->fetch_result($result, 0, "last_updated");
922 $last_updated = make_local_datetime($last_updated, false);
924 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
926 $result = $this->dbh
->query("SELECT COUNT(id) AS num_errors
927 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
929 $num_errors = $this->dbh
->fetch_result($result, 0, "num_errors");
931 if ($num_errors > 0) {
932 $reply['headlines']['content'] .= "<br/>";
933 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
934 __('Some feeds have update errors (click for details)')."</a>";
936 $reply['headlines']['content'] .= "</span></p>";
938 $reply['headlines-info'] = array("count" => 0,
939 "vgroup_last_feed" => '',
941 "disable_cache" => true);
946 private function generate_error_feed($error) {
949 $reply['headlines']['id'] = -6;
950 $reply['headlines']['is_cat'] = false;
952 $reply['headlines']['toolbar'] = '';
953 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
955 $reply['headlines-info'] = array("count" => 0,
956 "vgroup_last_feed" => '',
958 "disable_cache" => true);
963 function quickAddFeed() {
964 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
965 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">";
967 print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
968 print "<div class=\"dlgSecCont\">";
970 print "<div style='float : right'>
971 <img style='display : none'
972 id='feed_add_spinner' src='images/indicator_white.gif'></div>";
974 print "<input style=\"font-size : 16px; width : 20em;\"
975 placeHolder=\"".__("Feed or site URL")."\"
976 dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
980 if (get_pref('ENABLE_FEED_CATS')) {
981 print __('Place in category:') . " ";
982 print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
987 print '<div id="feedDlg_feedsContainer" style="display : none">
989 <div class="dlgSec">' . __('Available feeds') . '</div>
990 <div class="dlgSecCont">'.
991 '<select id="feedDlg_feedContainerSelect"
992 dojoType="dijit.form.Select" size="3">
993 <script type="dojo/method" event="onChange" args="value">
994 dijit.byId("feedDlg_feedUrl").attr("value", value);
999 print "<div id='feedDlg_loginContainer' style='display : none'>
1001 <div class=\"dlgSec\">".__("Authentication")."</div>
1002 <div class=\"dlgSecCont\">".
1004 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
1005 placeHolder=\"".__("Login")."\"
1006 style=\"width : 10em;\"> ".
1008 placeHolder=\"".__("Password")."\"
1009 dojoType=\"dijit.form.TextBox\" type='password'
1010 style=\"width : 10em;\" name='pass'\">
1014 print "<div style=\"clear : both\">
1015 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
1016 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
1017 <label for=\"feedDlg_loginCheck\">".
1018 __('This feed requires authentication.')."</div>";
1022 print "<div class=\"dlgButtons\">
1023 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
1025 if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
)) {
1026 print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
1029 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
1035 function feedBrowser() {
1036 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
) return;
1038 $browser_search = $this->dbh
->escape_string($_REQUEST["search"]);
1040 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
1041 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">";
1043 print "<div dojoType=\"dijit.Toolbar\">
1044 <div style='float : right'>
1045 <img style='display : none'
1046 id='feed_browser_spinner' src='images/indicator_white.gif'>
1047 <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
1048 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
1049 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
1052 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
1053 <option value='1'>" . __('Popular feeds') . "</option>
1054 <option value='2'>" . __('Feed archive') . "</option>
1059 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
1061 foreach (array(25, 50, 100, 200) as $l) {
1062 $issel = ($l == $limit) ?
"selected=\"1\"" : "";
1063 print "<option $issel value=\"$l\">$l</option>";
1070 $owner_uid = $_SESSION["uid"];
1072 require_once "feedbrowser.php";
1074 print "<ul class='browseFeedList' id='browseFeedList'>";
1075 print make_feed_browser($search, 25);
1078 print "<div align='center'>
1079 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
1080 <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
1081 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
1086 $this->params
= explode(":", $this->dbh
->escape_string($_REQUEST["param"]), 2);
1088 $active_feed_id = sprintf("%d", $this->params
[0]);
1089 $is_cat = $this->params
[1] != "false";
1091 print "<div class=\"dlgSec\">".__('Look for')."</div>";
1093 print "<div class=\"dlgSecCont\">";
1095 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1096 style=\"font-size : 16px; width : 20em;\"
1097 required=\"1\" name=\"query\" type=\"search\" value=''>";
1099 print "<hr/>".__('Limit search to:')." ";
1101 print "<select name=\"search_mode\" dojoType=\"dijit.form.Select\">
1102 <option value=\"all_feeds\">".__('All feeds')."</option>";
1104 $feed_title = getFeedTitle($active_feed_id);
1107 $feed_cat_title = getFeedCatTitle($active_feed_id);
1109 $feed_cat_title = getCategoryTitle($active_feed_id);
1112 if ($active_feed_id && !$is_cat) {
1113 print "<option selected=\"1\" value=\"this_feed\">$feed_title</option>";
1115 print "<option disabled=\"1\" value=\"false\">".__('This feed')."</option>";
1119 $cat_preselected = "selected=\"1\"";
1122 if (get_pref('ENABLE_FEED_CATS') && ($active_feed_id > 0 ||
$is_cat)) {
1123 print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
1125 //print "<option disabled>".__('This category')."</option>";
1132 print "<div class=\"dlgButtons\">";
1134 if (!SPHINX_ENABLED
) {
1135 print "<div style=\"float : left\">
1136 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">Search syntax</a>
1140 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
1141 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>