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) {
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 $reply .= "<span class='r'>";
52 $reply .= "<span id='feed_title'>";
55 $target = "target=\"_blank\"";
56 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
57 truncate_string($feed_title,30)."</a>";
60 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
64 $reply .= $feed_title;
71 title=\"".__("View as RSS feed")."\"
72 onclick=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">
73 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/pub_set.svg\"></a>";
79 $reply .= __('Select:')."
80 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
81 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
82 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
83 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
87 $reply .= "<select dojoType=\"dijit.form.Select\"
88 onchange=\"headlineActionsChange(this)\">";
89 $reply .= "<option value=\"false\">".__('More...')."</option>";
91 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
93 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
94 <option value=\"$tog_marked_link\">".__('Starred')."</option>
95 <option value=\"$tog_published_link\">".__('Published')."</option>";
97 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
99 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
100 $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>";
102 if ($feed_id != "0") {
103 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
105 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
106 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
112 if ($pluginhost->get_plugin("mail")) {
113 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
117 if ($pluginhost->get_plugin("mailto")) {
118 $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
122 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
124 //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
126 $reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
128 $reply .= "</select>";
130 //$reply .= "</div>";
134 foreach ($pluginhost->get_hooks($pluginhost::HOOK_HEADLINE_TOOLBAR_BUTTON
) as $p) {
135 echo $p->hook_headline_toolbar_button($feed_id, $is_cat);
141 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
142 $next_unread_feed, $offset, $vgr_last_feed = false,
143 $override_order = false, $include_children = false) {
145 if (isset($_REQUEST["DevForceUpdate"]))
146 header("Content-Type: text/plain");
148 $disable_cache = false;
152 $timing_info = microtime(true);
154 $topmost_article_ids = array();
156 if (!$offset) $offset = 0;
157 if ($method == "undefined") $method = "";
159 $method_split = explode(":", $method);
161 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
162 // Update the feed if required with some basic flood control
164 $result = db_query($this->link
,
165 "SELECT cache_images,".SUBSTRING_FOR_DATE
."(last_updated,1,19) AS last_updated
166 FROM ttrss_feeds WHERE id = '$feed'");
168 if (db_num_rows($result) != 0) {
169 $last_updated = strtotime(db_fetch_result($result, 0, "last_updated"));
170 $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
172 if (!$cache_images && time() - $last_updated > 120 ||
isset($_REQUEST['DevForceUpdate'])) {
173 include "rssfuncs.php";
174 update_rss_feed($this->link
, $feed, true, true);
176 db_query($this->link
, "UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
177 WHERE id = '$feed'");
182 if ($method_split[0] == "MarkAllReadGR") {
183 catchup_feed($this->link
, $method_split[1], false);
186 // FIXME: might break tag display?
188 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
189 $result = db_query($this->link
,
190 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
192 if (db_num_rows($result) == 0) {
193 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
197 @$search = db_escape_string($this->link
, $_REQUEST["query"]);
200 $disable_cache = true;
203 @$search_mode = db_escape_string($this->link
, $_REQUEST["search_mode"]);
205 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
207 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
208 if( $search_mode == '' && $method != '' ){
209 $search_mode = $method;
211 // error_log("search_mode: " . $search_mode);
213 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX
&& $feed > LABEL_BASE_INDEX
) {
216 $handler = $pluginhost->get_feed_handler(
217 PluginHost
::feed_to_pfeed_id($feed));
219 // function queryFeedHeadlines($link, $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) {
224 "view_mode" => $view_mode,
225 "cat_view" => $cat_view,
227 "search_mode" => $search_mode,
228 "override_order" => $override_order,
230 "owner_uid" => $_SESSION["uid"],
233 "include_children" => $include_children);
235 $qfh_ret = $handler->get_headlines(PluginHost
::feed_to_pfeed_id($feed),
240 $qfh_ret = queryFeedHeadlines($this->link
, $feed, $limit, $view_mode, $cat_view,
241 $search, $search_mode, $override_order, $offset, 0,
242 false, 0, $include_children);
245 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
247 $result = $qfh_ret[0];
248 $feed_title = $qfh_ret[1];
249 $feed_site_url = $qfh_ret[2];
250 $last_error = $qfh_ret[3];
252 $vgroup_last_feed = $vgr_last_feed;
254 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
256 $feed, $cat_view, $search, $search_mode, $view_mode,
259 $headlines_count = db_num_rows($result);
261 /* if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
262 $button_plugins = array();
263 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
264 $pclass = "button_" . trim($p);
266 if (class_exists($pclass)) {
267 $plugin = new $pclass($link);
268 array_push($button_plugins, $plugin);
275 if (db_num_rows($result) > 0) {
280 $cur_feed_title = '';
282 $fresh_intl = get_pref($this->link
, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
284 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
286 $expand_cdm = get_pref($this->link
, 'CDM_EXPANDED');
288 while ($line = db_fetch_assoc($result)) {
289 $class = ($lnum %
2) ?
"even" : "odd";
292 $feed_id = $line["feed_id"];
293 $label_cache = $line["label_cache"];
297 $label_cache = json_decode($label_cache, true);
300 if ($label_cache["no-labels"] == 1)
303 $labels = $label_cache;
307 if (!is_array($labels)) $labels = get_article_labels($this->link
, $id);
309 $labels_str = "<span id=\"HLLCTR-$id\">";
310 $labels_str .= format_article_labels($labels, $id);
311 $labels_str .= "</span>";
313 if (count($topmost_article_ids) < 3) {
314 array_push($topmost_article_ids, $id);
317 if (sql_bool_to_bool($line["unread"])) {
322 if (sql_bool_to_bool($line["marked"])) {
324 src=\"images/mark_set.svg\"
325 class=\"markedPic\" alt=\"Unstar article\"
326 onclick='toggleMark($id)'>";
330 src=\"images/mark_unset.svg\"
331 class=\"markedPic\" alt=\"Star article\"
332 onclick='toggleMark($id)'>";
335 if (sql_bool_to_bool($line["published"])) {
336 $published_pic = "<img src=\"images/pub_set.svg\"
338 alt=\"Unpublish article\" onclick='togglePub($id)'>";
339 $class .= " published";
341 $published_pic = "<img src=\"images/pub_unset.svg\"
343 alt=\"Publish article\" onclick='togglePub($id)'>";
346 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
347 # $line["title"] . "</a>";
349 # $content_link = "<a
350 # href=\"" . htmlspecialchars($line["link"]) . "\"
351 # onclick=\"view($id,$feed_id);\">" .
352 # $line["title"] . "</a>";
354 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
355 # $line["title"] . "</a>";
357 $updated_fmt = make_local_datetime($this->link
, $line["updated"], false);
358 $date_entered_fmt = T_sprintf("Imported at %s",
359 make_local_datetime($this->link
, $line["date_entered"], false));
361 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
362 $content_preview = truncate_string(strip_tags($line["content_preview"]),
366 $score = $line["score"];
368 $score_pic = "images/" . get_score_pic($score);
370 /* $score_title = __("(Click to change)");
371 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
372 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
374 $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
379 } else if ($score < -100) {
385 $entry_author = $line["author"];
388 $entry_author = " - $entry_author";
391 $has_feed_icon = feed_has_icon($feed_id);
393 if ($has_feed_icon) {
394 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
396 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.svg\" alt=\"\">";
399 $entry_site_url = $line["site_url"];
401 if (!get_pref($this->link
, 'COMBINED_DISPLAY_MODE')) {
403 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
404 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
406 $cur_feed_title = $line["feed_title"];
407 $vgroup_last_feed = $feed_id;
409 $cur_feed_title = htmlspecialchars($cur_feed_title);
411 $vf_catchup_link = "(<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('Mark as read')."</a>)";
413 $reply['content'] .= "<div class='cdmFeedTitle'>".
414 "<div style=\"float : right\">$feed_icon_img</div>".
415 "<a class='title' href=\"#\" onclick=\"viewfeed($feed_id)\">".
416 $line["feed_title"]."</a> $vf_catchup_link</div>";
421 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
422 onmouseout='postMouseOut($id)'";
424 $reply['content'] .= "<div class='hl $class' id='RROW-$id' $mouseover_attrs>";
426 $reply['content'] .= "<div class='hlLeft'>";
428 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
429 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
432 $reply['content'] .= "$marked_pic";
433 $reply['content'] .= "$published_pic";
435 $reply['content'] .= "</div>";
437 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
438 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
439 $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title\"
440 href=\"" . htmlspecialchars($line["link"]) . "\"
442 truncate_string($line["title"], 200);
444 if (get_pref($this->link
, 'SHOW_CONTENT_PREVIEW')) {
445 if ($content_preview) {
446 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
450 $reply['content'] .= "</a></span>";
452 $reply['content'] .= $labels_str;
454 $reply['content'] .= "</div>";
456 $reply['content'] .= "<span class=\"hlUpdated\">";
458 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
459 if (@$line["feed_title"]) {
460 $reply['content'] .= "<div class=\"hlFeed\">
461 <a href=\"#\" onclick=\"viewfeed($feed_id)\">".
462 truncate_string($line["feed_title"],30)."</a>
467 $reply['content'] .= "<span title='$date_entered_fmt'>$updated_fmt</span>
470 $reply['content'] .= "<div class=\"hlRight\">";
472 $reply['content'] .= $score_pic;
474 if ($line["feed_title"] && !get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
476 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
477 style=\"cursor : pointer\"
478 title=\"".htmlspecialchars($line['feed_title'])."\">
479 $feed_icon_img<span>";
482 $reply['content'] .= "</div>";
483 $reply['content'] .= "</div>";
487 $line["tags"] = get_article_tags($this->link
, $id, $_SESSION["uid"], $line["tag_cache"]);
488 unset($line["tag_cache"]);
490 $line["content"] = sanitize($this->link
, $line["content_preview"],
491 sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
493 foreach ($pluginhost->get_hooks($pluginhost::HOOK_RENDER_ARTICLE_CDM
) as $p) {
494 $line = $p->hook_render_article_cdm($line);
497 if (get_pref($this->link
, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
498 if ($feed_id != $vgroup_last_feed) {
500 $cur_feed_title = $line["feed_title"];
501 $vgroup_last_feed = $feed_id;
503 $cur_feed_title = htmlspecialchars($cur_feed_title);
505 $vf_catchup_link = "(<a class='catchup' onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
507 $has_feed_icon = feed_has_icon($feed_id);
509 if ($has_feed_icon) {
510 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
512 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
515 $reply['content'] .= "<div class='cdmFeedTitle'>".
516 "<div style=\"float : right\">$feed_icon_img</div>".
517 "<a href=\"#\" class='title' onclick=\"viewfeed($feed_id)\">".
518 $line["feed_title"]."</a> $vf_catchup_link</div>";
522 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
523 onmouseout='postMouseOut($id)'";
525 $expanded_class = $expand_cdm ?
"expanded" : "expandable";
527 $reply['content'] .= "<div class=\"cdm $expanded_class $class\"
528 id=\"RROW-$id\" $mouseover_attrs'>";
530 $reply['content'] .= "<div class=\"cdmHeader\">";
532 $reply['content'] .= "<div style=\"vertical-align : middle\">";
534 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
535 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
538 $reply['content'] .= "$marked_pic";
539 $reply['content'] .= "$published_pic";
541 $reply['content'] .= "</div>";
543 $reply['content'] .= "<span id=\"RTITLE-$id\"
544 onclick=\"return cdmClicked(event, $id);\"
545 class=\"titleWrap$hlc_suffix\">
547 target=\"_blank\" href=\"".
548 htmlspecialchars($line["link"])."\">".
550 " <span class=\"author\">$entry_author</span></a>";
552 $reply['content'] .= $labels_str;
554 $reply['content'] .= "<span class='collapseBtn' style='display : none'>
555 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
556 title=\"".__("Collapse article")."\"/></span>";
559 $content_hidden = "style=\"display : none\"";
561 $excerpt_hidden = "style=\"display : none\"";
563 $reply['content'] .= "<span $excerpt_hidden
564 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
565 $reply['content'] .= "</span>";
567 if (!get_pref($this->link
, 'VFEED_GROUP_BY_FEED')) {
568 if (@$line["feed_title"]) {
569 $reply['content'] .= "<div class=\"hlFeed\">
570 <a href=\"#\" onclick=\"viewfeed($feed_id)\">".
571 truncate_string($line["feed_title"],30)."</a>
576 $reply['content'] .= "<span class='updated' title='$date_entered_fmt'>
577 $updated_fmt</span>";
579 $reply['content'] .= "<div style=\"vertical-align : middle\">";
580 $reply['content'] .= "$score_pic";
582 if (!get_pref($this->link
, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
583 $reply['content'] .= "<span style=\"cursor : pointer\"
584 title=\"".htmlspecialchars($line["feed_title"])."\"
585 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
587 $reply['content'] .= "</div>";
589 $reply['content'] .= "</div>";
591 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
592 onclick=\"return cdmClicked(event, $id);\"
595 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
597 $reply['content'] .= format_article_note($id, $line['note']);
599 $reply['content'] .= "</div>";
602 $reply['content'] .= "<div class=\"cdmContentInner\">";
604 if ($line["orig_feed_id"]) {
606 $tmp_result = db_query($this->link
, "SELECT * FROM ttrss_archived_feeds
607 WHERE id = ".$line["orig_feed_id"]);
609 if (db_num_rows($tmp_result) != 0) {
611 $reply['content'] .= "<div clear='both'>";
612 $reply['content'] .= __("Originally from:");
614 $reply['content'] .= " ";
616 $tmp_line = db_fetch_assoc($tmp_result);
618 $reply['content'] .= "<a target='_blank'
619 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
620 $tmp_line['title'] . "</a>";
622 $reply['content'] .= " ";
624 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
625 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.svg'></a>";
627 $reply['content'] .= "</div>";
631 $reply['content'] .= "<span id=\"CWRAP-$id\">";
633 // if (!$expand_cdm) {
634 $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">";
635 $reply['content'] .= htmlspecialchars($line["content"]);
636 $reply['content'] .= "</span.";
639 // $reply['content'] .= $line["content"];
642 $reply['content'] .= "</span>";
644 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
646 $reply['content'] .= format_article_enclosures($this->link
, $id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"]));
648 $reply['content'] .= "</div>";
650 $reply['content'] .= "<div class=\"cdmFooter\">";
652 foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_LEFT_BUTTON
) as $p) {
653 $reply['content'] .= $p->hook_article_left_button($line);
656 $tags_str = format_tags_string($line["tags"], $id);
658 $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>
659 <span id=\"ATSTR-$id\">$tags_str</span>
660 <a title=\"".__('Edit tags for this article')."\"
661 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
663 $num_comments = $line["num_comments"];
664 $entry_comments = "";
666 if ($num_comments > 0) {
667 if ($line["comments"]) {
668 $comments_url = htmlspecialchars($line["comments"]);
670 $comments_url = htmlspecialchars($line["link"]);
672 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
674 if ($line["comments"] && $line["link"] != $line["comments"]) {
675 $entry_comments = "<a target='_blank' href=\"".htmlspecialchars($line["comments"])."\">comments</a>";
679 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
681 $reply['content'] .= "<div style=\"float : right\">";
683 // $reply['content'] .= "$marked_pic";
684 // $reply['content'] .= "$published_pic";
686 foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON
) as $p) {
687 $reply['content'] .= $p->hook_article_button($line);
690 $reply['content'] .= "</div>";
691 $reply['content'] .= "</div>";
693 $reply['content'] .= "</div>";
695 $reply['content'] .= "</div>";
702 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
707 switch ($view_mode) {
709 $message = __("No unread articles found to display.");
712 $message = __("No updated articles found to display.");
715 $message = __("No starred articles found to display.");
718 if ($feed < LABEL_BASE_INDEX
) {
719 $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.");
721 $message = __("No articles found to display.");
725 if (!$offset && $message) {
726 $reply['content'] .= "<div class='whiteBox'>$message";
728 $reply['content'] .= "<p><span class=\"insensitive\">";
730 $result = db_query($this->link
, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
731 WHERE owner_uid = " . $_SESSION['uid']);
733 $last_updated = db_fetch_result($result, 0, "last_updated");
734 $last_updated = make_local_datetime($this->link
, $last_updated, false);
736 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
738 $result = db_query($this->link
, "SELECT COUNT(id) AS num_errors
739 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
741 $num_errors = db_fetch_result($result, 0, "num_errors");
743 if ($num_errors > 0) {
744 $reply['content'] .= "<br/>";
745 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
746 __('Some feeds have update errors (click for details)')."</a>";
748 $reply['content'] .= "</span></p></div>";
752 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
754 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
755 $vgroup_last_feed, $reply);
758 function catchupAll() {
759 db_query($this->link
, "UPDATE ttrss_user_entries SET
760 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
761 ccache_zero_all($this->link
, $_SESSION["uid"]);
765 $timing_info = microtime(true);
769 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
771 $omode = db_escape_string($this->link
, $_REQUEST["omode"]);
773 $feed = db_escape_string($this->link
, $_REQUEST["feed"]);
774 $method = db_escape_string($this->link
, $_REQUEST["m"]);
775 $view_mode = db_escape_string($this->link
, $_REQUEST["view_mode"]);
777 @$cat_view = $_REQUEST["cat"] == "true";
778 @$next_unread_feed = db_escape_string($this->link
, $_REQUEST["nuf"]);
779 @$offset = db_escape_string($this->link
, $_REQUEST["skip"]);
780 @$vgroup_last_feed = db_escape_string($this->link
, $_REQUEST["vgrlf"]);
781 $order_by = db_escape_string($this->link
, $_REQUEST["order_by"]);
783 if (is_numeric($feed)) $feed = (int) $feed;
785 /* Feed -5 is a special case: it is used to display auxiliary information
786 * when there's nothing to load - e.g. no stuff in fresh feed */
789 print json_encode($this->generate_dashboard_feed($this->link
));
795 if ($feed < LABEL_BASE_INDEX
) {
796 $label_feed = feed_to_label_id($feed);
797 $result = db_query($this->link
, "SELECT id FROM ttrss_labels2 WHERE
798 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
799 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
800 $result = db_query($this->link
, "SELECT id FROM ttrss_feeds WHERE
801 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
802 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
803 $result = db_query($this->link
, "SELECT id FROM ttrss_feed_categories WHERE
804 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
807 if ($result && db_num_rows($result) == 0) {
808 print json_encode($this->generate_error_feed($this->link
, __("Feed not found.")));
812 /* Updating a label ccache means recalculating all of the caches
813 * so for performance reasons we don't do that here */
816 ccache_update($this->link
, $feed, $_SESSION["uid"], $cat_view);
819 set_pref($this->link
, "_DEFAULT_VIEW_MODE", $view_mode);
820 set_pref($this->link
, "_DEFAULT_VIEW_ORDER_BY", $order_by);
822 /* bump login timestamp if needed */
823 if (time() - $_SESSION["last_login_update"] > 3600) {
824 db_query($this->link
, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
826 $_SESSION["last_login_update"] = time();
829 if (!$cat_view && is_numeric($feed) && $feed > 0) {
830 db_query($this->link
, "UPDATE ttrss_feeds SET last_viewed = NOW()
831 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
834 $reply['headlines'] = array();
836 if (!$next_unread_feed)
837 $reply['headlines']['id'] = $feed;
839 $reply['headlines']['id'] = $next_unread_feed;
841 $reply['headlines']['is_cat'] = (bool) $cat_view;
843 $override_order = false;
847 $override_order = "ttrss_entries.title";
850 $override_order = "date_entered, updated";
853 $override_order = "updated DESC";
857 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
859 $ret = $this->format_headlines_list($feed, $method,
860 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
861 $vgroup_last_feed, $override_order, true);
863 //$topmost_article_ids = $ret[0];
864 $headlines_count = $ret[1];
865 $returned_feed = $ret[2];
866 $disable_cache = $ret[3];
867 $vgroup_last_feed = $ret[4];
869 $reply['headlines']['content'] =& $ret[5]['content'];
870 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
872 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
874 $reply['headlines-info'] = array("count" => (int) $headlines_count,
875 "vgroup_last_feed" => $vgroup_last_feed,
876 "disable_cache" => (bool) $disable_cache);
878 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
880 $reply['runtime-info'] = make_runtime_info($this->link
);
882 print json_encode($reply);
886 private function generate_dashboard_feed($link) {
889 $reply['headlines']['id'] = -5;
890 $reply['headlines']['is_cat'] = false;
892 $reply['headlines']['toolbar'] = '';
893 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
895 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
897 $result = db_query($link, "SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
898 WHERE owner_uid = " . $_SESSION['uid']);
900 $last_updated = db_fetch_result($result, 0, "last_updated");
901 $last_updated = make_local_datetime($link, $last_updated, false);
903 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
905 $result = db_query($link, "SELECT COUNT(id) AS num_errors
906 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
908 $num_errors = db_fetch_result($result, 0, "num_errors");
910 if ($num_errors > 0) {
911 $reply['headlines']['content'] .= "<br/>";
912 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
913 __('Some feeds have update errors (click for details)')."</a>";
915 $reply['headlines']['content'] .= "</span></p>";
917 $reply['headlines-info'] = array("count" => 0,
918 "vgroup_last_feed" => '',
920 "disable_cache" => true);
925 private function generate_error_feed($link, $error) {
928 $reply['headlines']['id'] = -6;
929 $reply['headlines']['is_cat'] = false;
931 $reply['headlines']['toolbar'] = '';
932 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
934 $reply['headlines-info'] = array("count" => 0,
935 "vgroup_last_feed" => '',
937 "disable_cache" => true);
942 function quickAddFeed() {
943 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
944 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">";
946 print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
947 print "<div class=\"dlgSecCont\">";
949 print "<div style='float : right'>
950 <img style='display : none'
951 id='feed_add_spinner' src='images/indicator_white.gif'></div>";
953 print "<input style=\"font-size : 16px; width : 20em;\"
954 placeHolder=\"".__("Feed or site URL")."\"
955 dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
959 if (get_pref($this->link
, 'ENABLE_FEED_CATS')) {
960 print __('Place in category:') . " ";
961 print_feed_cat_select($this->link
, "cat", false, 'dojoType="dijit.form.Select"');
966 print '<div id="feedDlg_feedsContainer" style="display : none">
968 <div class="dlgSec">' . __('Available feeds') . '</div>
969 <div class="dlgSecCont">'.
970 '<select id="feedDlg_feedContainerSelect"
971 dojoType="dijit.form.Select" size="3">
972 <script type="dojo/method" event="onChange" args="value">
973 dijit.byId("feedDlg_feedUrl").attr("value", value);
978 print "<div id='feedDlg_loginContainer' style='display : none'>
980 <div class=\"dlgSec\">".__("Authentication")."</div>
981 <div class=\"dlgSecCont\">".
983 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
984 placeHolder=\"".__("Login")."\"
985 style=\"width : 10em;\"> ".
987 placeHolder=\"".__("Password")."\"
988 dojoType=\"dijit.form.TextBox\" type='password'
989 style=\"width : 10em;\" name='pass'\">
993 print "<div style=\"clear : both\">
994 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
995 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
996 <label for=\"feedDlg_loginCheck\">".
997 __('This feed requires authentication.')."</div>";
1001 print "<div class=\"dlgButtons\">
1002 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
1004 if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
)) {
1005 print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
1008 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
1014 function feedBrowser() {
1015 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
) return;
1017 $browser_search = db_escape_string($this->link
, $_REQUEST["search"]);
1019 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
1020 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">";
1022 print "<div dojoType=\"dijit.Toolbar\">
1023 <div style='float : right'>
1024 <img style='display : none'
1025 id='feed_browser_spinner' src='images/indicator_white.gif'>
1026 <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
1027 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
1028 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
1031 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
1032 <option value='1'>" . __('Popular feeds') . "</option>
1033 <option value='2'>" . __('Feed archive') . "</option>
1038 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
1040 foreach (array(25, 50, 100, 200) as $l) {
1041 $issel = ($l == $limit) ?
"selected=\"1\"" : "";
1042 print "<option $issel value=\"$l\">$l</option>";
1049 $owner_uid = $_SESSION["uid"];
1051 require_once "feedbrowser.php";
1053 print "<ul class='browseFeedList' id='browseFeedList'>";
1054 print make_feed_browser($this->link
, $search, 25);
1057 print "<div align='center'>
1058 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
1059 <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
1060 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
1065 $this->params
= explode(":", db_escape_string($this->link
, $_REQUEST["param"]), 2);
1067 $active_feed_id = sprintf("%d", $this->params
[0]);
1068 $is_cat = $this->params
[1] != "false";
1070 print "<div class=\"dlgSec\">".__('Look for')."</div>";
1072 print "<div class=\"dlgSecCont\">";
1074 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1075 style=\"font-size : 16px; width : 20em;\"
1076 required=\"1\" name=\"query\" type=\"search\" value=''>";
1078 print "<hr/>".__('Limit search to:')." ";
1080 print "<select name=\"search_mode\" dojoType=\"dijit.form.Select\">
1081 <option value=\"all_feeds\">".__('All feeds')."</option>";
1083 $feed_title = getFeedTitle($this->link
, $active_feed_id);
1086 $feed_cat_title = getFeedCatTitle($this->link
, $active_feed_id);
1088 $feed_cat_title = getCategoryTitle($this->link
, $active_feed_id);
1091 if ($active_feed_id && !$is_cat) {
1092 print "<option selected=\"1\" value=\"this_feed\">$feed_title</option>";
1094 print "<option disabled=\"1\" value=\"false\">".__('This feed')."</option>";
1098 $cat_preselected = "selected=\"1\"";
1101 if (get_pref($this->link
, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 ||
$is_cat)) {
1102 print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>";
1104 //print "<option disabled>".__('This category')."</option>";
1111 print "<div class=\"dlgButtons\">";
1113 if (!SPHINX_ENABLED
) {
1114 print "<div style=\"float : left\">
1115 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">Search syntax</a>
1119 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
1120 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>