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 $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(strip_tags($feed_title), 30)."</a>";
70 $error = htmlspecialchars($error);
71 $reply .= " <img title=\"$error\" src='images/error.png' alt='error' class=\"noborder\">";
75 $reply .= strip_tags($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>";
95 $reply .= "</span> "; */
97 $reply .= "<select dojoType=\"dijit.form.Select\"
98 onchange=\"headlineActionsChange(this)\">";
100 $reply .= "<option value=\"0\" disabled='1'>".__('Select...')."</option>";
102 $reply .= "<option value=\"$sel_all_link\">".__('All')."</option>";
103 $reply .= "<option value=\"$sel_unread_link\">".__('Unread')."</option>";
104 $reply .= "<option value=\"$sel_inv_link\">".__('Invert')."</option>";
105 $reply .= "<option value=\"$sel_none_link\">".__('None')."</option>";
107 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
109 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
110 <option value=\"$tog_marked_link\">".__('Starred')."</option>
111 <option value=\"$tog_published_link\">".__('Published')."</option>";
113 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
115 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
116 $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>";
118 if ($feed_id != "0") {
119 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
121 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
122 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
126 if (PluginHost
::getInstance()->get_plugin("mail")) {
127 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
131 if (PluginHost
::getInstance()->get_plugin("mailto")) {
132 $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
136 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
138 //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
140 $reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
142 $reply .= "</select>";
146 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_HEADLINE_TOOLBAR_BUTTON
) as $p) {
147 $reply .= $p->hook_headline_toolbar_button($feed_id, $is_cat);
150 $reply .= "</span></span>";
155 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
156 $offset, $vgr_last_feed = false,
157 $override_order = false, $include_children = false, $check_first_id = false,
158 $skip_first_id_check = false) {
160 $disable_cache = false;
164 $rgba_cache = array();
166 $timing_info = microtime(true);
168 $topmost_article_ids = array();
170 if (!$offset) $offset = 0;
171 if ($method == "undefined") $method = "";
173 $method_split = explode(":", $method);
175 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
176 // Update the feed if required with some basic flood control
178 $any_needs_curl = false;
180 if (ini_get("open_basedir")) {
181 $pluginhost = PluginHost
::getInstance();
182 foreach ($pluginhost->get_plugins() as $plugin) {
183 $flags = $plugin->flags();
185 if (isset($flags["needs_curl"]) && $flags["needs_curl"]) {
186 $any_needs_curl = true;
192 //if ($_REQUEST["debug"]) print "<!-- any_needs_curl: $any_needs_curl -->";
194 if (!$any_needs_curl) {
196 $sth = $this->pdo
->prepare("SELECT cache_images," . SUBSTRING_FOR_DATE
. "(last_updated,1,19) AS last_updated
197 FROM ttrss_feeds WHERE id = ?");
198 $sth->execute([$feed]);
200 if ($row = $sth->fetch()) {
201 $last_updated = strtotime($row["last_updated"]);
202 $cache_images = $row["cache_images"];
204 if (!$cache_images && time() - $last_updated > 120) {
205 RSSUtils
::update_rss_feed($feed, true);
207 $sth = $this->pdo
->prepare("UPDATE ttrss_feeds
208 SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
210 $sth->execute([$feed]);
214 $sth = $this->pdo
->prepare("UPDATE ttrss_feeds
215 SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
217 $sth->execute([$feed]);
221 if ($method_split[0] == "MarkAllReadGR") {
222 $this->catchup_feed($method_split[1], false);
225 // FIXME: might break tag display?
227 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
228 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE id = ? LIMIT 1");
229 $sth->execute([$feed]);
231 if (!$sth->fetch()) {
232 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
236 @$search = $_REQUEST["query"];
237 @$search_language = $_REQUEST["search_language"]; // PGSQL only
240 $disable_cache = true;
243 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
245 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX
&& $feed > LABEL_BASE_INDEX
) {
246 $handler = PluginHost
::getInstance()->get_feed_handler(
247 PluginHost
::feed_to_pfeed_id($feed));
252 "view_mode" => $view_mode,
253 "cat_view" => $cat_view,
255 "override_order" => $override_order,
257 "owner_uid" => $_SESSION["uid"],
260 "include_children" => $include_children);
262 $qfh_ret = $handler->get_headlines(PluginHost
::feed_to_pfeed_id($feed),
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 = $this->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];
297 $reply['search_query'] = [$search, $search_language];
299 $vgroup_last_feed = $vgr_last_feed;
301 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
303 $feed, $cat_view, $search,
304 $last_error, $last_updated);
307 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_HEADLINES_BEFORE
) as $p) {
308 $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret);
312 $reply['content'] = '';
314 $headlines_count = 0;
318 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
319 $expand_cdm = get_pref('CDM_EXPANDED');
321 while ($line = $result->fetch()) {
325 $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250);
327 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
328 $line = $p->hook_query_headlines($line, 250, false);
331 if (get_pref('SHOW_CONTENT_PREVIEW')) {
332 $content_preview = $line["content_preview"];
336 $feed_id = $line["feed_id"];
337 $label_cache = $line["label_cache"];
341 $label_cache = json_decode($label_cache, true);
344 if ($label_cache["no-labels"] == 1)
347 $labels = $label_cache;
351 if (!is_array($labels)) $labels = Article
::get_article_labels($id);
353 $labels_str = "<span class=\"HLLCTR-$id\">";
354 $labels_str .= Article
::format_article_labels($labels);
355 $labels_str .= "</span>";
357 if (count($topmost_article_ids) < 3) {
358 array_push($topmost_article_ids, $id);
363 if ($line["unread"]) {
368 if ($line["marked"]) {
370 src=\"images/mark_set.png\"
371 class=\"markedPic\" alt=\"Unstar article\"
372 onclick='toggleMark($id)'>";
376 src=\"images/mark_unset.png\"
377 class=\"markedPic\" alt=\"Star article\"
378 onclick='toggleMark($id)'>";
381 if ($line["published"]) {
382 $published_pic = "<img src=\"images/pub_set.png\"
384 alt=\"Unpublish article\" onclick='togglePub($id)'>";
385 $class .= " published";
387 $published_pic = "<img src=\"images/pub_unset.png\"
389 alt=\"Publish article\" onclick='togglePub($id)'>";
392 $updated_fmt = make_local_datetime($line["updated"], false, false, false, true);
393 $date_entered_fmt = T_sprintf("Imported at %s",
394 make_local_datetime($line["date_entered"], false));
396 $score = $line["score"];
398 $score_pic = "images/" . get_score_pic($score);
400 $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
404 $hlc_suffix = "high";
405 } else if ($score < -100) {
411 $entry_author = $line["author"];
414 $entry_author = " — $entry_author";
417 $has_feed_icon = feeds
::feedHasIcon($feed_id);
419 if ($has_feed_icon) {
420 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
422 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.png\" alt=\"\">";
425 $entry_site_url = $line["site_url"];
427 //setting feed headline background color, needs to change text color based on dark/light
428 $fav_color = $line['favicon_avg_color'];
430 require_once "colors.php";
432 if ($fav_color && $fav_color != 'fail') {
433 if (!isset($rgba_cache[$feed_id])) {
434 $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color));
438 if (!get_pref('COMBINED_DISPLAY_MODE')) {
440 if ($vfeed_group_enabled) {
441 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
443 $vgroup_last_feed = $feed_id;
445 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
447 $reply['content'] .= "<div data-feed-id='$feed_id' id='FTITLE-$feed_id' class='cdmFeedTitle'>".
448 "<div style='float : right'>$feed_icon_img</div>".
449 "<a class='title' href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
450 $line["feed_title"]."</a>
451 $vf_catchup_link</div>";
457 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
458 onmouseout='postMouseOut($id)'";
460 $reply['content'] .= "<div class='hl hlMenuAttach $class' data-orig-feed-id='$feed_id' data-article-id='$id' id='RROW-$id' $mouseover_attrs>";
462 $reply['content'] .= "<div class='hlLeft'>";
464 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
465 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
468 $reply['content'] .= "$marked_pic";
469 $reply['content'] .= "$published_pic";
471 $reply['content'] .= "</div>";
473 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
474 class=\"hlTitle\"><span class='hlContent $hlc_suffix'>";
475 $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title $hlc_suffix\"
476 href=\"" . htmlspecialchars($line["link"]) . "\"
478 truncate_string($line["title"], 200);
480 if (get_pref('SHOW_CONTENT_PREVIEW')) {
481 $reply['content'] .= "<span class=\"contentPreview\">" . $line["content_preview"] . "</span>";
484 $reply['content'] .= "</a></span>";
486 $reply['content'] .= $labels_str;
488 $reply['content'] .= "</div>";
490 if (!$vfeed_group_enabled) {
491 if (@$line["feed_title"]) {
492 $rgba = @$rgba_cache[$feed_id];
494 $reply['content'] .= "<span class=\"hlFeed\"><a style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
495 truncate_string($line["feed_title"],30)."</a></span>";
500 $reply['content'] .= "<span class=\"hlUpdated\">";
502 $reply['content'] .= "<div title='$date_entered_fmt'>$updated_fmt</div>
505 $reply['content'] .= "<div class=\"hlRight\">";
507 $reply['content'] .= $score_pic;
509 if ($line["feed_title"] && !$vfeed_group_enabled) {
511 $reply['content'] .= "<span onclick=\"viewfeed({feed:$feed_id})\"
512 style=\"cursor : pointer\"
513 title=\"".htmlspecialchars($line['feed_title'])."\">
514 $feed_icon_img</span>";
517 $reply['content'] .= "</div>";
518 $reply['content'] .= "</div>";
522 if ($line["tag_cache"])
523 $tags = explode(",", $line["tag_cache"]);
527 $line["content"] = sanitize($line["content"],
528 $line['hide_images'], false, $entry_site_url, $highlight_words, $line["id"]);
530 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_CDM
) as $p) {
531 $line = $p->hook_render_article_cdm($line);
534 if ($vfeed_group_enabled && $line["feed_title"]) {
535 if ($feed_id != $vgroup_last_feed) {
537 $vgroup_last_feed = $feed_id;
539 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
541 $feed_icon_src = Feeds
::getFeedIcon($feed_id);
542 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"$feed_icon_src\">";
544 $reply['content'] .= "<div data-feed-id='$feed_id' id='FTITLE-$feed_id' class='cdmFeedTitle'>".
545 "<div style=\"float : right\">$feed_icon_img</div>".
546 "<a href=\"#\" class='title' onclick=\"viewfeed({feed:$feed_id})\">".
547 $line["feed_title"]."</a> $vf_catchup_link</div>";
552 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)'
553 onmouseout='postMouseOut($id)'";
555 $expanded_class = $expand_cdm ?
"expanded" : "expandable";
557 $tmp_content = "<div class=\"cdm $hlc_suffix $expanded_class $class\"
558 id=\"RROW-$id\" data-article-id='$id' data-orig-feed-id='$feed_id' $mouseover_attrs>";
560 $tmp_content .= "<div class=\"cdmHeader\">";
561 $tmp_content .= "<div style=\"vertical-align : middle\">";
563 $tmp_content .= "<input dojoType=\"dijit.form.CheckBox\"
564 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
567 $tmp_content .= "$marked_pic";
568 $tmp_content .= "$published_pic";
570 $tmp_content .= "</div>";
572 if ($highlight_words && count($highlight_words) > 0) {
573 foreach ($highlight_words as $word) {
574 $line["title"] = preg_replace("/(\Q$word\E)/i",
575 "<span class=\"highlight\">$1</span>", $line["title"]);
579 // data-article-id included for context menu
580 $tmp_content .= "<span id=\"RTITLE-$id\"
581 onclick=\"return cdmClicked(event, $id);\"
582 data-article-id=\"$id\"
583 class=\"titleWrap hlMenuAttach $hlc_suffix\">
584 <a class=\"title $hlc_suffix\"
585 title=\"".htmlspecialchars($line["title"])."\"
586 target=\"_blank\" rel=\"noopener noreferrer\" href=\"".
587 htmlspecialchars($line["link"])."\">".
589 "</a> <span class=\"author\">$entry_author</span>";
591 $tmp_content .= $labels_str;
593 $tmp_content .= "<span class='collapseBtn' style='display : none'>
594 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
595 title=\"".__("Collapse article")."\"/></span>";
598 $content_hidden = "style=\"display : none\"";
600 $excerpt_hidden = "style=\"display : none\"";
602 $tmp_content .= "<span $excerpt_hidden id=\"CEXC-$id\" class=\"cdmExcerpt\">" . $content_preview . "</span>";
604 $tmp_content .= "</span>";
606 if (!$vfeed_group_enabled) {
607 if (@$line["feed_title"]) {
608 $rgba = @$rgba_cache[$feed_id];
610 $tmp_content .= "<div class=\"hlFeed\">
611 <a href=\"#\" style=\"background-color: rgba($rgba,0.3)\"
612 onclick=\"viewfeed({feed:$feed_id})\">".
613 truncate_string($line["feed_title"],30)."</a>
618 $tmp_content .= "<span class='updated' title='$date_entered_fmt'>$updated_fmt</span>";
620 $tmp_content .= "<div class='scoreWrap' style=\"vertical-align : middle\">";
621 $tmp_content .= "$score_pic";
623 if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
624 $tmp_content .= "<span style=\"cursor : pointer\"
625 title=\"".htmlspecialchars($line["feed_title"])."\"
626 onclick=\"viewfeed({feed:$feed_id})\">$feed_icon_img</span>";
628 $tmp_content .= "</div>"; //scoreWrap
630 $tmp_content .= "</div>"; //cdmHeader
632 $tmp_content .= "<div class=\"cdmContent\" $content_hidden
633 onclick=\"return cdmClicked(event, $id, true);\"
636 $tmp_content .= "<div id=\"POSTNOTE-$id\">";
638 $tmp_content .= Article
::format_article_note($id, $line['note']);
640 $tmp_content .= "</div>"; //POSTNOTE
642 if (!$line['lang']) $line['lang'] = 'en';
644 $tmp_content .= "<div class=\"cdmContentInner\" lang=\"".$line['lang']."\">";
646 if ($line["orig_feed_id"]) {
648 $ofgh = $this->pdo
->prepare("SELECT * FROM ttrss_archived_feeds
649 WHERE id = ? AND owner_uid = ?");
650 $ofgh->execute([$line["orig_feed_id"], $_SESSION['uid']]);
652 if ($tmp_line = $ofgh->fetch()) {
654 $tmp_content .= "<div clear='both'>";
655 $tmp_content .= __("Originally from:");
657 $tmp_content .= " ";
659 $tmp_content .= "<a target='_blank' rel='noopener noreferrer'
660 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
661 $tmp_line['title'] . "</a>";
663 $tmp_content .= " ";
665 $tmp_content .= "<a target='_blank' rel='noopener noreferrer' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
666 $tmp_content .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.png'></a>";
668 $tmp_content .= "</div>";
672 $tmp_content .= "<span id=\"CWRAP-$id\">";
673 $tmp_content .= "<span id=\"CENCW-$id\" class=\"cencw\" style=\"display : none\">";
674 $tmp_content .= htmlspecialchars($line["content"]);
675 $tmp_content .= "</span>";
676 $tmp_content .= "</span>";
678 $tmp_content .= "</div>"; //cdmContentInner
680 $tmp_content .= "<div class=\"cdmIntermediate\">";
682 $always_display_enclosures = $line["always_display_enclosures"];
683 $tmp_content .= Article
::format_article_enclosures($id, $always_display_enclosures,
684 $line["content"], $line["hide_images"]);
686 $tmp_content .= "</div>"; // cdmIntermediate
688 $tmp_content .= "<div class=\"cdmFooter\" onclick=\"cdmFooterClick(event)\">";
690 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_LEFT_BUTTON
) as $p) {
691 $tmp_content .= $p->hook_article_left_button($line);
694 $tags_str = Article
::format_tags_string($tags, $id);
696 $tmp_content .= "<span class='left'>";
698 $tmp_content .= "<img src='images/tag.png' alt='Tags' title='Tags'>
699 <span id=\"ATSTR-$id\">$tags_str</span>
700 <a title=\"".__('Edit tags for this article')."\"
701 href=\"#\" onclick=\"editArticleTags($id)\">(+)</a>";
703 $num_comments = (int) $line["num_comments"];
704 $entry_comments = "";
706 if ($num_comments > 0) {
707 if ($line["comments"]) {
708 $comments_url = htmlspecialchars($line["comments"]);
710 $comments_url = htmlspecialchars($line["link"]);
712 $entry_comments = "<a class=\"postComments\"
713 target='_blank' rel='noopener noreferrer' href=\"$comments_url\">$num_comments ".
714 _ngettext("comment", "comments", $num_comments)."</a>";
717 if ($line["comments"] && $line["link"] != $line["comments"]) {
718 $entry_comments = "<a class=\"postComments\" target='_blank' rel='noopener noreferrer' href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
722 if ($entry_comments) $tmp_content .= " ($entry_comments)";
724 $tmp_content .= "</span>";
725 $tmp_content .= "<div>";
727 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_BUTTON
) as $p) {
728 $tmp_content .= $p->hook_article_button($line);
731 $tmp_content .= "</div>"; // buttons
733 $tmp_content .= "</div>"; // cdmFooter
734 $tmp_content .= "</div>"; // cdmContent
735 $tmp_content .= "</div>"; // RROW.cdm
737 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_FORMAT_ARTICLE_CDM
) as $p) {
738 $tmp_content = $p->hook_format_article_cdm($tmp_content, $line);
741 $reply['content'] .= $tmp_content;
747 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
749 if (!$headlines_count) {
751 if (!is_numeric($result)) {
753 switch ($view_mode) {
755 $message = __("No unread articles found to display.");
758 $message = __("No updated articles found to display.");
761 $message = __("No starred articles found to display.");
764 if ($feed < LABEL_BASE_INDEX
) {
765 $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter.");
767 $message = __("No articles found to display.");
771 if (!$offset && $message) {
772 $reply['content'] = "<div class='whiteBox'>$message";
774 $reply['content'] .= "<p><span class=\"insensitive\">";
776 $sth = $this->pdo
->prepare("SELECT " . SUBSTRING_FOR_DATE
. "(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
777 WHERE owner_uid = ?");
778 $sth->execute([$_SESSION['uid']]);
779 $row = $sth->fetch();
781 $last_updated = make_local_datetime($row["last_updated"], false);
783 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
785 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS num_errors
786 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
787 $sth->execute([$_SESSION['uid']]);
788 $row = $sth->fetch();
790 $num_errors = $row["num_errors"];
792 if ($num_errors > 0) {
793 $reply['content'] .= "<br/>";
794 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">" .
795 __('Some feeds have update errors (click for details)') . "</a>";
797 $reply['content'] .= "</span></p></div>";
800 } else if (is_numeric($result) && $result == -1) {
801 $reply['first_id_changed'] = true;
805 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
807 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
808 $vgroup_last_feed, $reply);
811 function catchupAll() {
812 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
813 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = ?");
814 $sth->execute([$_SESSION['uid']]);
816 CCache
::zero_all($_SESSION["uid"]);
820 $timing_info = microtime(true);
824 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
826 $feed = $_REQUEST["feed"];
827 $method = $_REQUEST["m"];
828 $view_mode = $_REQUEST["view_mode"];
830 @$cat_view = $_REQUEST["cat"] == "true";
831 @$next_unread_feed = $_REQUEST["nuf"];
832 @$offset = $_REQUEST["skip"];
833 @$vgroup_last_feed = $_REQUEST["vgrlf"];
834 $order_by = $_REQUEST["order_by"];
835 $check_first_id = $_REQUEST["fid"];
837 if (is_numeric($feed)) $feed = (int) $feed;
839 /* Feed -5 is a special case: it is used to display auxiliary information
840 * when there's nothing to load - e.g. no stuff in fresh feed */
843 print json_encode($this->generate_dashboard_feed());
848 if ($feed < LABEL_BASE_INDEX
) {
850 $label_feed = Labels
::feed_to_label_id($feed);
852 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_labels2 WHERE
853 id = ? AND owner_uid = ?");
854 $sth->execute([$label_feed, $_SESSION['uid']]);
856 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
858 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE
859 id = ? AND owner_uid = ?");
860 $sth->execute([$feed, $_SESSION['uid']]);
862 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
864 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feed_categories WHERE
865 id = ? AND owner_uid = ?");
867 $sth->execute([$feed, $_SESSION['uid']]);
870 if ($sth && !$sth->fetch()) {
871 print json_encode($this->generate_error_feed(__("Feed not found.")));
875 /* Updating a label ccache means recalculating all of the caches
876 * so for performance reasons we don't do that here */
879 CCache
::update($feed, $_SESSION["uid"], $cat_view);
882 set_pref("_DEFAULT_VIEW_MODE", $view_mode);
883 set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by);
885 /* bump login timestamp if needed */
886 if (time() - $_SESSION["last_login_update"] > 3600) {
887 $sth = $this->pdo
->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?");
888 $sth->execute([$_SESSION['uid']]);
890 $_SESSION["last_login_update"] = time();
893 if (!$cat_view && is_numeric($feed) && $feed > 0) {
894 $sth = $this->pdo
->prepare("UPDATE ttrss_feeds SET last_viewed = NOW()
895 WHERE id = ? AND owner_uid = ?");
896 $sth->execute([$feed, $_SESSION['uid']]);
899 $reply['headlines'] = array();
901 $override_order = false;
902 $skip_first_id_check = false;
906 $override_order = "ttrss_entries.title, date_entered, updated";
909 $override_order = "score DESC, date_entered, updated";
910 $skip_first_id_check = true;
913 $override_order = "updated DESC";
917 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
919 $ret = $this->format_headlines_list($feed, $method,
920 $view_mode, $limit, $cat_view, $offset,
921 $vgroup_last_feed, $override_order, true, $check_first_id, $skip_first_id_check);
923 //$topmost_article_ids = $ret[0];
924 $headlines_count = $ret[1];
925 /* $returned_feed = $ret[2]; */
926 $disable_cache = $ret[3];
927 $vgroup_last_feed = $ret[4];
929 //$reply['headlines']['content'] =& $ret[5]['content'];
930 //$reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
932 $reply['headlines'] = $ret[5];
934 if (!$next_unread_feed)
935 $reply['headlines']['id'] = $feed;
937 $reply['headlines']['id'] = $next_unread_feed;
939 $reply['headlines']['is_cat'] = (bool) $cat_view;
941 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
943 $reply['headlines-info'] = array("count" => (int) $headlines_count,
944 "vgroup_last_feed" => $vgroup_last_feed,
945 "disable_cache" => (bool) $disable_cache);
947 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
949 $reply['runtime-info'] = make_runtime_info();
951 print json_encode($reply);
955 private function generate_dashboard_feed() {
958 $reply['headlines']['id'] = -5;
959 $reply['headlines']['is_cat'] = false;
961 $reply['headlines']['toolbar'] = '';
963 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
965 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
967 $sth = $this->pdo
->prepare("SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
968 WHERE owner_uid = ?");
969 $sth->execute([$_SESSION['uid']]);
970 $row = $sth->fetch();
972 $last_updated = make_local_datetime($row["last_updated"], false);
974 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
976 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS num_errors
977 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
978 $sth->execute([$_SESSION['uid']]);
979 $row = $sth->fetch();
981 $num_errors = $row["num_errors"];
983 if ($num_errors > 0) {
984 $reply['headlines']['content'] .= "<br/>";
985 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
986 __('Some feeds have update errors (click for details)')."</a>";
988 $reply['headlines']['content'] .= "</span></p>";
990 $reply['headlines-info'] = array("count" => 0,
991 "vgroup_last_feed" => '',
993 "disable_cache" => true);
998 private function generate_error_feed($error) {
1001 $reply['headlines']['id'] = -7;
1002 $reply['headlines']['is_cat'] = false;
1004 $reply['headlines']['toolbar'] = '';
1005 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
1007 $reply['headlines-info'] = array("count" => 0,
1008 "vgroup_last_feed" => '',
1010 "disable_cache" => true);
1015 function quickAddFeed() {
1016 print_hidden("op", "rpc");
1017 print_hidden("method", "addfeed");
1019 print "<div id='fadd_error_message' style='display : none' class='alert alert-danger'></div>";
1021 print "<div id='fadd_multiple_notify' style='display : none'>";
1022 print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below.");
1025 print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
1026 print "<div class=\"dlgSecCont\">";
1028 print "<div style='float : right'>
1029 <img style='display : none'
1030 id='feed_add_spinner' src='images/indicator_white.gif'></div>";
1032 print "<input style=\"font-size : 16px; width : 20em;\"
1033 placeHolder=\"".__("Feed or site URL")."\"
1034 dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
1038 if (get_pref('ENABLE_FEED_CATS')) {
1039 print __('Place in category:') . " ";
1040 print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
1045 print '<div id="feedDlg_feedsContainer" style="display : none">
1047 <div class="dlgSec">' . __('Available feeds') . '</div>
1048 <div class="dlgSecCont">'.
1049 '<select id="feedDlg_feedContainerSelect"
1050 dojoType="dijit.form.Select" size="3">
1051 <script type="dojo/method" event="onChange" args="value">
1052 dijit.byId("feedDlg_feedUrl").attr("value", value);
1057 print "<div id='feedDlg_loginContainer' style='display : none'>
1059 <div class=\"dlgSec\">".__("Authentication")."</div>
1060 <div class=\"dlgSecCont\">".
1062 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
1063 placeHolder=\"".__("Login")."\"
1064 autocomplete=\"new-password\"
1065 style=\"width : 10em;\"> ".
1067 placeHolder=\"".__("Password")."\"
1068 dojoType=\"dijit.form.TextBox\" type='password'
1069 autocomplete=\"new-password\"
1070 style=\"width : 10em;\" name='pass'\">
1074 print "<div style=\"clear : both\">
1075 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
1076 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
1077 <label for=\"feedDlg_loginCheck\">".
1078 __('This feed requires authentication.')."</div>";
1082 print "<div class=\"dlgButtons\">
1083 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
1085 if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
)) {
1086 print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
1089 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
1095 function feedBrowser() {
1096 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
) return;
1098 $browser_search = $_REQUEST["search"];
1100 print_hidden("op", "rpc");
1101 print_hidden("method", "updateFeedBrowser");
1103 print "<div dojoType=\"dijit.Toolbar\">
1104 <div style='float : right'>
1105 <img style='display : none'
1106 id='feed_browser_spinner' src='images/indicator_white.gif'>
1107 <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
1108 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
1109 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
1112 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
1113 <option value='1'>" . __('Popular feeds') . "</option>
1114 <option value='2'>" . __('Feed archive') . "</option>
1119 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
1121 foreach (array(25, 50, 100, 200) as $l) {
1122 //$issel = ($l == $limit) ? "selected=\"1\"" : "";
1123 print "<option value=\"$l\">$l</option>";
1130 require_once "feedbrowser.php";
1132 print "<ul class='browseFeedList' id='browseFeedList'>";
1133 print make_feed_browser("", 25);
1136 print "<div align='center'>
1137 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
1138 <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
1139 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
1144 $this->params
= explode(":", $_REQUEST["param"], 2);
1146 $active_feed_id = sprintf("%d", $this->params
[0]);
1147 $is_cat = $this->params
[1] != "false";
1149 print "<div class=\"dlgSec\">".__('Look for')."</div>";
1151 print "<div class=\"dlgSecCont\">";
1153 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1154 style=\"font-size : 16px; width : 20em;\"
1155 required=\"1\" name=\"query\" type=\"search\" value=''>";
1157 print "<hr/><span style='float : right'>".T_sprintf('in %s', $this->getFeedTitle($active_feed_id, $is_cat))."</span>";
1159 if (DB_TYPE
== "pgsql") {
1161 print_select("search_language", "", Pref_Feeds
::$feed_languages,
1162 "dojoType='dijit.form.Select' title=\"".__('Used for word stemming')."\"");
1167 print "<div class=\"dlgButtons\">";
1169 if (count(PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SEARCH
)) == 0) {
1170 print "<div style=\"float : left\">
1171 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">".__("Search syntax")."</a>
1175 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
1176 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>
1180 function update_debugger() {
1181 header("Content-type: text/html");
1183 $feed_id = (int)$_REQUEST["feed_id"];
1184 @$do_update = $_REQUEST["action"] == "do_update";
1185 $csrf_token = $_REQUEST["csrf_token"];
1187 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?");
1188 $sth->execute([$feed_id, $_SESSION['uid']]);
1190 if (!$sth->fetch()) {
1191 print "Access denied.";
1195 $refetch_checked = isset($_REQUEST["force_refetch"]) ?
"checked" : "";
1196 $rehash_checked = isset($_REQUEST["force_rehash"]) ?
"checked" : "";
1201 <?php
echo stylesheet_tag("css/default.css") ?
>
1202 <title
>Feed Debugger
</title
>
1204 <body
class="small_margins ttrss_utility claro">
1205 <h1
>Feed Debugger
: <?php
echo "$feed_id: " . $this->getFeedTitle($feed_id) ?
></h1
>
1206 <form method
="GET" action
="">
1207 <input type
="hidden" name
="op" value
="feeds">
1208 <input type
="hidden" name
="method" value
="update_debugger">
1209 <input type
="hidden" name
="xdebug" value
="1">
1210 <input type
="hidden" name
="csrf_token" value
="<?php echo $csrf_token ?>">
1211 <input type
="hidden" name
="action" value
="do_update">
1212 <input type
="hidden" name
="feed_id" value
="<?php echo $feed_id ?>">
1213 <input type
="checkbox" name
="force_refetch" value
="1" <?php
echo $refetch_checked ?
>> Force refetch
<br
/>
1214 <input type
="checkbox" name
="force_rehash" value
="1" <?php
echo $rehash_checked ?
>> Force rehash
<br
/>
1216 <p
/><button type
="submit">Continue</button
>
1224 RSSUtils
::update_rss_feed($feed_id, true);
1235 static function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) {
1237 if (!$owner_uid) $owner_uid = $_SESSION['uid'];
1241 // Todo: all this interval stuff needs some generic generator function
1243 $search_qpart = is_array($search) && $search[0] ?
search_to_sql($search[0], $search[1])[0] : 'true';
1247 if (DB_TYPE
== "pgsql") {
1248 $date_qpart = "date_entered < NOW() - INTERVAL '1 day' ";
1250 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) ";
1254 if (DB_TYPE
== "pgsql") {
1255 $date_qpart = "date_entered < NOW() - INTERVAL '1 week' ";
1257 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) ";
1261 if (DB_TYPE
== "pgsql") {
1262 $date_qpart = "date_entered < NOW() - INTERVAL '2 week' ";
1264 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) ";
1268 $date_qpart = "true";
1271 if (is_numeric($feed)) {
1277 $children = Feeds
::getChildCategories($feed, $owner_uid);
1278 array_push($children, $feed);
1280 $children = join(",", $children);
1282 $cat_qpart = "cat_id IN ($children)";
1284 $cat_qpart = "cat_id IS NULL";
1287 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1288 SET unread = false, last_read = NOW() WHERE ref_id IN
1290 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1291 AND owner_uid = ? AND unread = true AND feed_id IN
1292 (SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart AND $search_qpart) as tmp)");
1293 $sth->execute([$owner_uid]);
1295 } else if ($feed == -2) {
1297 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1298 SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*)
1299 FROM ttrss_user_labels2, ttrss_entries WHERE article_id = ref_id AND id = ref_id AND $date_qpart AND $search_qpart) > 0
1300 AND unread = true AND owner_uid = ?");
1301 $sth->execute([$owner_uid]);
1304 } else if ($feed > 0) {
1306 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1307 SET unread = false, last_read = NOW() WHERE ref_id IN
1309 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1310 AND owner_uid = ? AND unread = true AND feed_id = ? AND $date_qpart AND $search_qpart) as tmp)");
1311 $sth->execute([$owner_uid, $feed]);
1313 } else if ($feed < 0 && $feed > LABEL_BASE_INDEX
) { // special, like starred
1316 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1317 SET unread = false, last_read = NOW() WHERE ref_id IN
1319 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1320 AND owner_uid = ? AND unread = true AND marked = true AND $date_qpart AND $search_qpart) as tmp)");
1321 $sth->execute([$owner_uid]);
1325 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1326 SET unread = false, last_read = NOW() WHERE ref_id IN
1328 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1329 AND owner_uid = ? AND unread = true AND published = true AND $date_qpart AND $search_qpart) as tmp)");
1330 $sth->execute([$owner_uid]);
1335 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE");
1337 if (DB_TYPE
== "pgsql") {
1338 $match_part = "date_entered > NOW() - INTERVAL '$intl hour' ";
1340 $match_part = "date_entered > DATE_SUB(NOW(),
1341 INTERVAL $intl HOUR) ";
1344 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1345 SET unread = false, last_read = NOW() WHERE ref_id IN
1347 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1348 AND owner_uid = ? AND score >= 0 AND unread = true AND $date_qpart AND $match_part AND $search_qpart) as tmp)");
1349 $sth->execute([$owner_uid]);
1353 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1354 SET unread = false, last_read = NOW() WHERE ref_id IN
1356 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1357 AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
1358 $sth->execute([$owner_uid]);
1361 } else if ($feed < LABEL_BASE_INDEX
) { // label
1363 $label_id = Labels
::feed_to_label_id($feed);
1365 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1366 SET unread = false, last_read = NOW() WHERE ref_id IN
1368 (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_user_labels2 WHERE ref_id = id
1369 AND label_id = ? AND ref_id = article_id
1370 AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
1371 $sth->execute([$label_id, $owner_uid]);
1375 CCache
::update($feed, $owner_uid, $cat_view);
1378 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1379 SET unread = false, last_read = NOW() WHERE ref_id IN
1381 (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_tags WHERE ref_id = ttrss_entries.id
1382 AND post_int_id = int_id AND tag_name = ?
1383 AND ttrss_user_entries.owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
1384 $sth->execute([$feed, $owner_uid]);
1389 static function getFeedArticles($feed, $is_cat = false, $unread_only = false,
1390 $owner_uid = false) {
1392 $n_feed = (int) $feed;
1393 $need_entries = false;
1397 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1400 $unread_qpart = "unread = true";
1402 $unread_qpart = "true";
1408 return Feeds
::getCategoryUnread($n_feed, $owner_uid);
1409 } else if ($n_feed == -6) {
1411 } else if ($feed != "0" && $n_feed == 0) {
1413 $sth = $pdo->prepare("SELECT SUM((SELECT COUNT(int_id)
1414 FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
1415 AND ref_id = id AND $unread_qpart)) AS count FROM ttrss_tags
1416 WHERE owner_uid = ? AND tag_name = ?");
1418 $sth->execute([$owner_uid, $feed]);
1419 $row = $sth->fetch();
1421 return $row["count"];
1423 } else if ($n_feed == -1) {
1424 $match_part = "marked = true";
1425 } else if ($n_feed == -2) {
1426 $match_part = "published = true";
1427 } else if ($n_feed == -3) {
1428 $match_part = "unread = true AND score >= 0";
1430 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
1432 if (DB_TYPE
== "pgsql") {
1433 $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
1435 $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
1438 $need_entries = true;
1440 } else if ($n_feed == -4) {
1441 $match_part = "true";
1442 } else if ($n_feed >= 0) {
1445 $match_part = "feed_id = '$n_feed'";
1447 $match_part = "feed_id IS NULL";
1450 } else if ($feed < LABEL_BASE_INDEX
) {
1452 $label_id = Labels
::feed_to_label_id($feed);
1454 return Feeds
::getLabelUnread($label_id, $owner_uid);
1459 if ($need_entries) {
1460 $from_qpart = "ttrss_user_entries,ttrss_entries";
1461 $from_where = "ttrss_entries.id = ttrss_user_entries.ref_id AND";
1463 $from_qpart = "ttrss_user_entries";
1467 $sth = $pdo->prepare("SELECT count(int_id) AS unread
1468 FROM $from_qpart WHERE
1469 $unread_qpart AND $from_where ($match_part) AND ttrss_user_entries.owner_uid = ?");
1470 $sth->execute([$owner_uid]);
1471 $row = $sth->fetch();
1473 return $row["unread"];
1477 $sth = $pdo->prepare("SELECT COUNT(post_int_id) AS unread
1478 FROM ttrss_tags,ttrss_user_entries,ttrss_entries
1479 WHERE tag_name = ? AND post_int_id = int_id AND ref_id = ttrss_entries.id
1480 AND $unread_qpart AND ttrss_tags.owner_uid = ,");
1482 $sth->execute([$feed, $owner_uid]);
1483 $row = $sth->fetch();
1485 return $row["unread"];
1490 * @return array (code => Status code, message => error message if available)
1492 * 0 - OK, Feed already exists
1493 * 1 - OK, Feed added
1495 * 3 - URL content is HTML, no feeds available
1496 * 4 - URL content is HTML which contains multiple feeds.
1497 * Here you should call extractfeedurls in rpc-backend
1498 * to get all possible feeds.
1499 * 5 - Couldn't download the URL content.
1500 * 6 - Content is an invalid XML.
1502 static function subscribe_to_feed($url, $cat_id = 0,
1503 $auth_login = '', $auth_pass = '') {
1505 global $fetch_last_error;
1506 global $fetch_last_error_content;
1510 $url = fix_url($url);
1512 if (!$url ||
!validate_feed_url($url)) return array("code" => 2);
1514 $contents = @fetch_file_contents
($url, false, $auth_login, $auth_pass);
1517 if (preg_match("/cloudflare\.com/", $fetch_last_error_content)) {
1518 $fetch_last_error .= " (feed behind Cloudflare)";
1521 return array("code" => 5, "message" => $fetch_last_error);
1524 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SUBSCRIBE_FEED
) as $plugin) {
1525 $contents = $plugin->hook_subscribe_feed($contents, $url, $auth_login, $auth_pass);
1528 if (is_html($contents)) {
1529 $feedUrls = get_feeds_from_html($url, $contents);
1531 if (count($feedUrls) == 0) {
1532 return array("code" => 3);
1533 } else if (count($feedUrls) > 1) {
1534 return array("code" => 4, "feeds" => $feedUrls);
1536 //use feed url as new URL
1537 $url = key($feedUrls);
1540 if (!$cat_id) $cat_id = null;
1542 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
1543 WHERE feed_url = ? AND owner_uid = ?");
1544 $sth->execute([$url, $_SESSION['uid']]);
1546 if ($row = $sth->fetch()) {
1547 return array("code" => 0, "feed_id" => (int) $row["id"]);
1549 $sth = $pdo->prepare(
1550 "INSERT INTO ttrss_feeds
1551 (owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method,auth_pass_encrypted)
1552 VALUES (?, ?, ?, ?, ?, ?, 0, false)");
1554 $sth->execute([$_SESSION['uid'], $url, "[Unknown]", $cat_id, $auth_login, $auth_pass]);
1556 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
1557 AND owner_uid = ?");
1558 $sth->execute([$url, $_SESSION['uid']]);
1559 $row = $sth->fetch();
1561 $feed_id = $row["id"];
1564 RSSUtils
::set_basic_feed_info($feed_id);
1567 return array("code" => 1, "feed_id" => (int) $feed_id);
1572 static function getIconFile($feed_id) {
1573 return ICONS_DIR
. "/$feed_id.ico";
1576 static function feedHasIcon($id) {
1577 return is_file(ICONS_DIR
. "/$id.ico") && filesize(ICONS_DIR
. "/$id.ico") > 0;
1580 static function getFeedIcon($id) {
1583 return "images/archive.png";
1586 return "images/star.png";
1589 return "images/feed.png";
1592 return "images/fresh.png";
1595 return "images/folder.png";
1598 return "images/time.png";
1601 if ($id < LABEL_BASE_INDEX
) {
1602 return "images/label.png";
1604 $icon = self
::getIconFile($id);
1606 if ($icon && file_exists($icon)) {
1607 return ICONS_URL
. "/" . basename($icon) . "?" . filemtime($icon);
1616 static function getFeedTitle($id, $cat = false) {
1620 return Feeds
::getCategoryTitle($id);
1621 } else if ($id == -1) {
1622 return __("Starred articles");
1623 } else if ($id == -2) {
1624 return __("Published articles");
1625 } else if ($id == -3) {
1626 return __("Fresh articles");
1627 } else if ($id == -4) {
1628 return __("All articles");
1629 } else if ($id === 0 ||
$id === "0") {
1630 return __("Archived articles");
1631 } else if ($id == -6) {
1632 return __("Recently read");
1633 } else if ($id < LABEL_BASE_INDEX
) {
1635 $label_id = Labels
::feed_to_label_id($id);
1637 $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 WHERE id = ?");
1638 $sth->execute([$label_id]);
1640 if ($row = $sth->fetch()) {
1641 return $row["caption"];
1643 return "Unknown label ($label_id)";
1646 } else if (is_numeric($id) && $id > 0) {
1648 $sth = $pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?");
1649 $sth->execute([$id]);
1651 if ($row = $sth->fetch()) {
1652 return $row["title"];
1654 return "Unknown feed ($id)";
1662 static function getCategoryUnread($cat, $owner_uid = false) {
1664 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1670 if (!$cat) $cat = null;
1672 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
1673 WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
1674 AND owner_uid = :uid");
1676 $sth->execute([":cat" => $cat, ":uid" => $owner_uid]);
1678 $cat_feeds = array();
1679 while ($line = $sth->fetch()) {
1680 array_push($cat_feeds, "feed_id = " . $line["id"]);
1683 if (count($cat_feeds) == 0) return 0;
1685 $match_part = implode(" OR ", $cat_feeds);
1687 $sth = $pdo->prepare("SELECT COUNT(int_id) AS unread
1688 FROM ttrss_user_entries
1689 WHERE unread = true AND ($match_part)
1690 AND owner_uid = ?");
1691 $sth->execute([$owner_uid]);
1695 # this needs to be rewritten
1696 while ($line = $sth->fetch()) {
1697 $unread +
= $line["unread"];
1701 } else if ($cat == -1) {
1702 return getFeedUnread(-1) +
getFeedUnread(-2) +
getFeedUnread(-3) +
getFeedUnread(0);
1703 } else if ($cat == -2) {
1705 $sth = $pdo->prepare("SELECT COUNT(unread) AS unread FROM
1706 ttrss_user_entries, ttrss_user_labels2
1707 WHERE article_id = ref_id AND unread = true
1708 AND ttrss_user_entries.owner_uid = ?");
1709 $sth->execute([$owner_uid]);
1710 $row = $sth->fetch();
1712 return $row["unread"];
1716 // only accepts real cats (>= 0)
1717 static function getCategoryChildrenUnread($cat, $owner_uid = false) {
1718 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1722 $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE parent_cat = ?
1723 AND owner_uid = ?");
1724 $sth->execute([$cat, $owner_uid]);
1728 while ($line = $sth->fetch()) {
1729 $unread +
= Feeds
::getCategoryUnread($line["id"], $owner_uid);
1730 $unread +
= Feeds
::getCategoryChildrenUnread($line["id"], $owner_uid);
1736 static function getGlobalUnread($user_id = false) {
1738 if (!$user_id) $user_id = $_SESSION["uid"];
1742 $sth = $pdo->prepare("SELECT SUM(value) AS c_id FROM ttrss_counters_cache
1743 WHERE owner_uid = ? AND feed_id > 0");
1744 $sth->execute([$user_id]);
1745 $row = $sth->fetch();
1747 return $row["c_id"];
1750 static function getCategoryTitle($cat_id) {
1752 if ($cat_id == -1) {
1753 return __("Special");
1754 } else if ($cat_id == -2) {
1755 return __("Labels");
1760 $sth = $pdo->prepare("SELECT title FROM ttrss_feed_categories WHERE
1762 $sth->execute([$cat_id]);
1764 if ($row = $sth->fetch()) {
1765 return $row["title"];
1767 return __("Uncategorized");
1772 static function getLabelUnread($label_id, $owner_uid = false) {
1773 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1777 $sth = $pdo->prepare("SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2
1778 WHERE owner_uid = ? AND unread = true AND label_id = ? AND article_id = ref_id");
1780 $sth->execute([$owner_uid, $label_id]);
1782 if ($row = $sth->fetch()) {
1783 return $row["unread"];
1789 static function queryFeedHeadlines($params) {
1793 // WARNING: due to highly dynamic nature of this query its going to quote parameters
1794 // right before adding them to SQL part
1796 $feed = $params["feed"];
1797 $limit = isset($params["limit"]) ?
$params["limit"] : 30;
1798 $view_mode = $params["view_mode"];
1799 $cat_view = isset($params["cat_view"]) ?
$params["cat_view"] : false;
1800 $search = isset($params["search"]) ?
$params["search"] : false;
1801 $search_language = isset($params["search_language"]) ?
$params["search_language"] : "";
1802 $override_order = isset($params["override_order"]) ?
$params["override_order"] : false;
1803 $offset = isset($params["offset"]) ?
$params["offset"] : 0;
1804 $owner_uid = isset($params["owner_uid"]) ?
$params["owner_uid"] : $_SESSION["uid"];
1805 $since_id = isset($params["since_id"]) ?
$params["since_id"] : 0;
1806 $include_children = isset($params["include_children"]) ?
$params["include_children"] : false;
1807 $ignore_vfeed_group = isset($params["ignore_vfeed_group"]) ?
$params["ignore_vfeed_group"] : false;
1808 $override_strategy = isset($params["override_strategy"]) ?
$params["override_strategy"] : false;
1809 $override_vfeed = isset($params["override_vfeed"]) ?
$params["override_vfeed"] : false;
1810 $start_ts = isset($params["start_ts"]) ?
$params["start_ts"] : false;
1811 $check_first_id = isset($params["check_first_id"]) ?
$params["check_first_id"] : false;
1812 $skip_first_id_check = isset($params["skip_first_id_check"]) ?
$params["skip_first_id_check"] : false;
1814 $ext_tables_part = "";
1815 $limit_query_part = "";
1817 $search_words = array();
1820 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SEARCH
) as $plugin) {
1821 list($search_query_part, $search_words) = $plugin->hook_search($search);
1825 // fall back in case of no plugins
1826 if (!$search_query_part) {
1827 list($search_query_part, $search_words) = search_to_sql($search, $search_language);
1829 $search_query_part .= " AND ";
1831 $search_query_part = "";
1835 $since_id_part = "ttrss_entries.id > ".$pdo->quote($since_id)." AND ";
1837 $since_id_part = "";
1840 $view_query_part = "";
1842 if ($view_mode == "adaptive") {
1844 $view_query_part = " ";
1845 } else if ($feed != -1) {
1847 $unread = getFeedUnread($feed, $cat_view);
1849 if ($cat_view && $feed > 0 && $include_children)
1850 $unread +
= Feeds
::getCategoryChildrenUnread($feed);
1853 $view_query_part = " unread = true AND ";
1858 if ($view_mode == "marked") {
1859 $view_query_part = " marked = true AND ";
1862 if ($view_mode == "has_note") {
1863 $view_query_part = " (note IS NOT NULL AND note != '') AND ";
1866 if ($view_mode == "published") {
1867 $view_query_part = " published = true AND ";
1870 if ($view_mode == "unread" && $feed != -6) {
1871 $view_query_part = " unread = true AND ";
1875 $limit_query_part = "LIMIT " . (int)$limit;
1878 $allow_archived = false;
1880 $vfeed_query_part = "";
1883 if (!is_numeric($feed)) {
1884 $query_strategy_part = "true";
1885 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1886 id = feed_id) as feed_title,";
1887 } else if ($feed > 0) {
1892 if ($include_children) {
1894 $subcats = Feeds
::getChildCategories($feed, $owner_uid);
1896 array_push($subcats, $feed);
1897 $query_strategy_part = "cat_id IN (".
1898 implode(",", $subcats).")";
1901 $query_strategy_part = "cat_id = " . $pdo->quote($feed);
1905 $query_strategy_part = "cat_id IS NULL";
1908 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1911 $query_strategy_part = "feed_id = " . $pdo->quote($feed);
1913 } else if ($feed == 0 && !$cat_view) { // archive virtual feed
1914 $query_strategy_part = "feed_id IS NULL";
1915 $allow_archived = true;
1916 } else if ($feed == 0 && $cat_view) { // uncategorized
1917 $query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL";
1918 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1919 } else if ($feed == -1) { // starred virtual feed
1920 $query_strategy_part = "marked = true";
1921 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1922 $allow_archived = true;
1924 if (!$override_order) {
1925 $override_order = "last_marked DESC, date_entered DESC, updated DESC";
1928 } else if ($feed == -2) { // published virtual feed OR labels category
1931 $query_strategy_part = "published = true";
1932 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1933 $allow_archived = true;
1935 if (!$override_order) {
1936 $override_order = "last_published DESC, date_entered DESC, updated DESC";
1940 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1942 $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,";
1944 $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND
1945 ttrss_user_labels2.article_id = ref_id";
1948 } else if ($feed == -6) { // recently read
1949 $query_strategy_part = "unread = false AND last_read IS NOT NULL";
1951 if (DB_TYPE
== "pgsql") {
1952 $query_strategy_part .= " AND last_read > NOW() - INTERVAL '1 DAY' ";
1954 $query_strategy_part .= " AND last_read > DATE_SUB(NOW(), INTERVAL 1 DAY) ";
1957 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1958 $allow_archived = true;
1959 $ignore_vfeed_group = true;
1961 if (!$override_order) $override_order = "last_read DESC";
1963 } else if ($feed == -3) { // fresh virtual feed
1964 $query_strategy_part = "unread = true AND score >= 0";
1966 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
1968 if (DB_TYPE
== "pgsql") {
1969 $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
1971 $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
1974 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1975 } else if ($feed == -4) { // all articles virtual feed
1976 $allow_archived = true;
1977 $query_strategy_part = "true";
1978 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1979 } else if ($feed <= LABEL_BASE_INDEX
) { // labels
1980 $label_id = Labels
::feed_to_label_id($feed);
1982 $query_strategy_part = "label_id = ".$pdo->quote($label_id)." AND
1983 ttrss_labels2.id = ttrss_user_labels2.label_id AND
1984 ttrss_user_labels2.article_id = ref_id";
1986 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1987 $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,";
1988 $allow_archived = true;
1991 $query_strategy_part = "true";
1994 $order_by = "score DESC, date_entered DESC, updated DESC";
1996 if ($override_order) {
1997 $order_by = $override_order;
2000 if ($override_strategy) {
2001 $query_strategy_part = $override_strategy;
2004 if ($override_vfeed) {
2005 $vfeed_query_part = $override_vfeed;
2009 $feed_title = T_sprintf("Search results: %s", $search);
2012 $feed_title = Feeds
::getCategoryTitle($feed);
2014 if (is_numeric($feed) && $feed > 0) {
2015 $ssth = $pdo->prepare("SELECT title,site_url,last_error,last_updated
2016 FROM ttrss_feeds WHERE id = ? AND owner_uid = ?");
2017 $ssth->execute([$feed, $owner_uid]);
2018 $row = $ssth->fetch();
2020 $feed_title = $row["title"];
2021 $feed_site_url = $row["site_url"];
2022 $last_error = $row["last_error"];
2023 $last_updated = $row["last_updated"];
2025 $feed_title = Feeds
::getFeedTitle($feed);
2030 $content_query_part = "content, ";
2032 if ($limit_query_part) {
2033 $offset_query_part = "OFFSET " . (int)$offset;
2035 $offset_query_part = "";
2038 if (is_numeric($feed)) {
2039 // proper override_order applied above
2040 if ($vfeed_query_part && !$ignore_vfeed_group && get_pref('VFEED_GROUP_BY_FEED', $owner_uid)) {
2041 if (!$override_order) {
2042 $order_by = "ttrss_feeds.title, ".$order_by;
2044 $order_by = "ttrss_feeds.title, ".$override_order;
2048 if (!$allow_archived) {
2049 $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id),ttrss_feeds";
2050 $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
2053 $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id)
2054 LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)";
2057 if ($vfeed_query_part) $vfeed_query_part .= "favicon_avg_color,";
2060 $start_ts_formatted = date("Y/m/d H:i:s", strtotime($start_ts));
2061 $start_ts_query_part = "date_entered >= '$start_ts_formatted' AND";
2063 $start_ts_query_part = "";
2067 $first_id_query_strategy_part = $query_strategy_part;
2070 $first_id_query_strategy_part = "true";
2072 if (DB_TYPE
== "pgsql") {
2073 $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND";
2075 $sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND";
2078 if (!$search && !$skip_first_id_check) {
2079 // if previous topmost article id changed that means our current pagination is no longer valid
2080 $query = "SELECT DISTINCT
2085 ttrss_entries.title,
2097 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
2099 $start_ts_query_part
2101 $sanity_interval_qpart
2102 $first_id_query_strategy_part ORDER BY $order_by LIMIT 1";
2104 if ($_REQUEST["debug"]) {
2108 $res = $pdo->query($query);
2110 if ($row = $res->fetch()) {
2111 $first_id = (int)$row["id"];
2113 if ($offset > 0 && $first_id && $check_first_id && $first_id != $check_first_id) {
2114 return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id);
2119 $query = "SELECT DISTINCT
2122 ttrss_entries.id,ttrss_entries.title,
2126 always_display_enclosures,
2135 unread,feed_id,marked,published,link,last_read,orig_feed_id,
2136 last_marked, last_published,
2144 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
2146 $start_ts_query_part
2149 $query_strategy_part ORDER BY $order_by
2150 $limit_query_part $offset_query_part";
2152 if ($_REQUEST["debug"]) print $query;
2154 $res = $pdo->query($query);
2159 $query = "SELECT DISTINCT
2163 ttrss_entries.id as id,
2179 (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images,
2180 last_marked, last_published,
2185 FROM ttrss_entries, ttrss_user_entries, ttrss_tags
2187 ref_id = ttrss_entries.id AND
2188 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
2189 post_int_id = int_id AND
2190 tag_name = ".$pdo->quote($feed)." AND
2193 $query_strategy_part ORDER BY $order_by
2194 $limit_query_part $offset_query_part";
2196 if ($_REQUEST["debug"]) print $query;
2198 $res = $pdo->query($query);
2201 return array($res, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id);
2205 static function getParentCategories($cat, $owner_uid) {
2210 $sth = $pdo->prepare("SELECT parent_cat FROM ttrss_feed_categories
2211 WHERE id = ? AND parent_cat IS NOT NULL AND owner_uid = ?");
2212 $sth->execute([$cat, $owner_uid]);
2214 while ($line = $sth->fetch()) {
2215 array_push($rv, $line["parent_cat"]);
2216 $rv = array_merge($rv, Feeds
::getParentCategories($line["parent_cat"], $owner_uid));
2222 static function getChildCategories($cat, $owner_uid) {
2227 $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories
2228 WHERE parent_cat = ? AND owner_uid = ?");
2229 $sth->execute([$cat, $owner_uid]);
2231 while ($line = $sth->fetch()) {
2232 array_push($rv, $line["id"]);
2233 $rv = array_merge($rv, Feeds
::getChildCategories($line["id"], $owner_uid));
2239 static function getFeedCategory($feed) {
2242 $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
2244 $sth->execute([$feed]);
2246 if ($row = $sth->fetch()) {
2247 return $row["cat_id"];