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) {
206 RSSUtils
::update_rss_feed($feed, true);
207 } catch (PDOException
$e) {
208 user_error("PDO Exception while doing on-demand feed update for $feed: " . $e->getMessage(), E_USER_NOTICE
);
211 $sth = $this->pdo
->prepare("UPDATE ttrss_feeds
212 SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
214 $sth->execute([$feed]);
218 $sth = $this->pdo
->prepare("UPDATE ttrss_feeds
219 SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
221 $sth->execute([$feed]);
225 if ($method_split[0] == "MarkAllReadGR") {
226 $this->catchup_feed($method_split[1], false);
229 // FIXME: might break tag display?
231 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
232 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE id = ? LIMIT 1");
233 $sth->execute([$feed]);
235 if (!$sth->fetch()) {
236 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
240 @$search = $_REQUEST["query"];
241 @$search_language = $_REQUEST["search_language"]; // PGSQL only
244 $disable_cache = true;
247 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
249 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX
&& $feed > LABEL_BASE_INDEX
) {
250 $handler = PluginHost
::getInstance()->get_feed_handler(
251 PluginHost
::feed_to_pfeed_id($feed));
256 "view_mode" => $view_mode,
257 "cat_view" => $cat_view,
259 "override_order" => $override_order,
261 "owner_uid" => $_SESSION["uid"],
264 "include_children" => $include_children);
266 $qfh_ret = $handler->get_headlines(PluginHost
::feed_to_pfeed_id($feed),
275 "view_mode" => $view_mode,
276 "cat_view" => $cat_view,
278 "search_language" => $search_language,
279 "override_order" => $override_order,
281 "include_children" => $include_children,
282 "check_first_id" => $check_first_id,
283 "skip_first_id_check" => $skip_first_id_check
286 $qfh_ret = $this->queryFeedHeadlines($params);
289 $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && $feed != -6;
291 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
293 $result = $qfh_ret[0]; // this could be either a PDO query result or a -1 if first id changed
294 $feed_title = $qfh_ret[1];
295 $feed_site_url = $qfh_ret[2];
296 $last_error = $qfh_ret[3];
297 $last_updated = strpos($qfh_ret[4], '1970-') === FALSE ?
298 make_local_datetime($qfh_ret[4], false) : __("Never");
299 $highlight_words = $qfh_ret[5];
300 $reply['first_id'] = $qfh_ret[6];
301 $reply['search_query'] = [$search, $search_language];
303 $vgroup_last_feed = $vgr_last_feed;
305 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
307 $feed, $cat_view, $search,
308 $last_error, $last_updated);
311 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_HEADLINES_BEFORE
) as $p) {
312 $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret);
316 $reply['content'] = '';
318 $headlines_count = 0;
322 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
323 $expand_cdm = get_pref('CDM_EXPANDED');
325 if (is_object($result)) {
327 while ($line = $result->fetch()) {
331 $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250);
333 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
334 $line = $p->hook_query_headlines($line, 250, false);
337 if (get_pref('SHOW_CONTENT_PREVIEW')) {
338 $content_preview = $line["content_preview"];
342 $feed_id = $line["feed_id"];
343 $label_cache = $line["label_cache"];
346 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' onmouseout='postMouseOut($id)'";
349 $label_cache = json_decode($label_cache, true);
352 if ($label_cache["no-labels"] == 1)
355 $labels = $label_cache;
359 if (!is_array($labels)) $labels = Article
::get_article_labels($id);
361 $labels_str = "<span class=\"HLLCTR-$id\">";
362 $labels_str .= Article
::format_article_labels($labels);
363 $labels_str .= "</span>";
365 if (count($topmost_article_ids) < 3) {
366 array_push($topmost_article_ids, $id);
371 if ($line["unread"]) {
376 $marked_pic_src = $line["marked"] ?
"mark_set.png" : "mark_unset.png";
377 $class .= $line["marked"] ?
" marked" : "";
378 $marked_pic = "<img src=\"images/$marked_pic_src\" class=\"markedPic\" onclick='toggleMark($id)'>";
380 $published_pic_src = $line["published"] ?
"pub_set.png" : "pub_unset.png";
381 $class .= $line["published"] ?
" published" : "";
382 $published_pic = "<img src=\"images/$published_pic_src\" class=\"pubPic\" onclick='togglePub($id)'>";
384 $updated_fmt = make_local_datetime($line["updated"], false, false, false, true);
385 $date_entered_fmt = T_sprintf("Imported at %s",
386 make_local_datetime($line["date_entered"], false));
388 $score = $line["score"];
390 $score_pic = "images/" . get_score_pic($score);
392 $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
396 $hlc_suffix = "high";
397 } else if ($score < -100) {
403 $entry_author = $line["author"];
406 $entry_author = " — $entry_author";
409 $has_feed_icon = feeds
::feedHasIcon($feed_id);
411 if ($has_feed_icon) {
412 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL
."/$feed_id.ico\" alt=\"\">";
414 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.png\" alt=\"\">";
417 $entry_site_url = $line["site_url"];
419 //setting feed headline background color, needs to change text color based on dark/light
420 $fav_color = $line['favicon_avg_color'];
422 require_once "colors.php";
424 if ($fav_color && $fav_color != 'fail') {
425 if (!isset($rgba_cache[$feed_id])) {
426 $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color));
430 if (!get_pref('COMBINED_DISPLAY_MODE')) {
432 if ($vfeed_group_enabled) {
433 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
435 $vgroup_last_feed = $feed_id;
437 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
439 $reply['content'] .= "<div data-feed-id='$feed_id' id='FTITLE-$feed_id' class='cdmFeedTitle'>".
440 "<div style='float : right'>$feed_icon_img</div>".
441 "<a class='title' href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
442 $line["feed_title"]."</a>
443 $vf_catchup_link</div>";
449 $reply['content'] .= "<div class='hl hlMenuAttach $class' data-orig-feed-id='$feed_id' data-article-id='$id' id='RROW-$id' $mouseover_attrs>";
451 $reply['content'] .= "<div class='hlLeft'>";
453 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
454 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
457 $reply['content'] .= "$marked_pic";
458 $reply['content'] .= "$published_pic";
460 $reply['content'] .= "</div>";
462 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
463 class=\"hlTitle\"><span class='hlContent $hlc_suffix'>";
464 $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title $hlc_suffix\"
465 href=\"" . htmlspecialchars($line["link"]) . "\"
467 truncate_string($line["title"], 200);
469 if (get_pref('SHOW_CONTENT_PREVIEW')) {
470 $reply['content'] .= "<span class=\"contentPreview\">" . $line["content_preview"] . "</span>";
473 $reply['content'] .= "</a></span>";
475 $reply['content'] .= $labels_str;
477 $reply['content'] .= "</div>";
479 if (!$vfeed_group_enabled) {
480 if (@$line["feed_title"]) {
481 $rgba = @$rgba_cache[$feed_id];
483 $reply['content'] .= "<span class=\"hlFeed\"><a style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
484 truncate_string($line["feed_title"],30)."</a></span>";
489 $reply['content'] .= "<span class=\"hlUpdated\">";
491 $reply['content'] .= "<div title='$date_entered_fmt'>$updated_fmt</div>
494 $reply['content'] .= "<div class=\"hlRight\">";
496 $reply['content'] .= $score_pic;
498 if ($line["feed_title"] && !$vfeed_group_enabled) {
500 $reply['content'] .= "<span onclick=\"viewfeed({feed:$feed_id})\"
501 style=\"cursor : pointer\"
502 title=\"".htmlspecialchars($line['feed_title'])."\">
503 $feed_icon_img</span>";
506 $reply['content'] .= "</div>";
507 $reply['content'] .= "</div>";
511 if ($line["tag_cache"])
512 $tags = explode(",", $line["tag_cache"]);
516 $line["content"] = sanitize($line["content"],
517 $line['hide_images'], false, $entry_site_url, $highlight_words, $line["id"]);
519 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE_CDM
) as $p) {
520 $line = $p->hook_render_article_cdm($line);
523 if ($vfeed_group_enabled && $line["feed_title"]) {
524 if ($feed_id != $vgroup_last_feed) {
526 $vgroup_last_feed = $feed_id;
528 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
530 $feed_icon_src = Feeds
::getFeedIcon($feed_id);
531 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"$feed_icon_src\">";
533 $reply['content'] .= "<div data-feed-id='$feed_id' id='FTITLE-$feed_id' class='cdmFeedTitle'>".
534 "<div style=\"float : right\">$feed_icon_img</div>".
535 "<a href=\"#\" class='title' onclick=\"viewfeed({feed:$feed_id})\">".
536 $line["feed_title"]."</a> $vf_catchup_link</div>";
541 $expanded_class = $expand_cdm ?
"expanded" : "expandable";
543 $tmp_content = "<div class=\"cdm $hlc_suffix $expanded_class $class\"
544 id=\"RROW-$id\" data-article-id='$id' data-orig-feed-id='$feed_id' $mouseover_attrs>";
546 $tmp_content .= "<div class=\"cdmHeader\">";
547 $tmp_content .= "<div style=\"vertical-align : middle\">";
549 $tmp_content .= "<input dojoType=\"dijit.form.CheckBox\"
550 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
553 $tmp_content .= "$marked_pic";
554 $tmp_content .= "$published_pic";
556 $tmp_content .= "</div>";
558 if ($highlight_words && count($highlight_words) > 0) {
559 foreach ($highlight_words as $word) {
560 $line["title"] = preg_replace("/(\Q$word\E)/i",
561 "<span class=\"highlight\">$1</span>", $line["title"]);
565 // data-article-id included for context menu
566 $tmp_content .= "<span id=\"RTITLE-$id\"
567 onclick=\"return cdmClicked(event, $id);\"
568 data-article-id=\"$id\"
569 class=\"titleWrap hlMenuAttach $hlc_suffix\">
570 <a class=\"title $hlc_suffix\"
571 title=\"".htmlspecialchars($line["title"])."\"
572 target=\"_blank\" rel=\"noopener noreferrer\" href=\"".
573 htmlspecialchars($line["link"])."\">".
575 "</a> <span class=\"author\">$entry_author</span>";
577 $tmp_content .= $labels_str;
579 $tmp_content .= "<span class='collapseBtn' style='display : none'>
580 <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\"
581 title=\"".__("Collapse article")."\"/></span>";
584 $content_hidden = "style=\"display : none\"";
586 $excerpt_hidden = "style=\"display : none\"";
588 $tmp_content .= "<span $excerpt_hidden id=\"CEXC-$id\" class=\"cdmExcerpt\">" . $content_preview . "</span>";
590 $tmp_content .= "</span>";
592 if (!$vfeed_group_enabled) {
593 if (@$line["feed_title"]) {
594 $rgba = @$rgba_cache[$feed_id];
596 $tmp_content .= "<div class=\"hlFeed\">
597 <a href=\"#\" style=\"background-color: rgba($rgba,0.3)\"
598 onclick=\"viewfeed({feed:$feed_id})\">".
599 truncate_string($line["feed_title"],30)."</a>
604 $tmp_content .= "<span class='updated' title='$date_entered_fmt'>$updated_fmt</span>";
606 $tmp_content .= "<div class='scoreWrap' style=\"vertical-align : middle\">";
607 $tmp_content .= "$score_pic";
609 if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
610 $tmp_content .= "<span style=\"cursor : pointer\"
611 title=\"".htmlspecialchars($line["feed_title"])."\"
612 onclick=\"viewfeed({feed:$feed_id})\">$feed_icon_img</span>";
614 $tmp_content .= "</div>"; //scoreWrap
616 $tmp_content .= "</div>"; //cdmHeader
618 $tmp_content .= "<div class=\"cdmContent\" $content_hidden
619 onclick=\"return cdmClicked(event, $id, true);\"
622 $tmp_content .= "<div id=\"POSTNOTE-$id\">";
624 $tmp_content .= Article
::format_article_note($id, $line['note']);
626 $tmp_content .= "</div>"; //POSTNOTE
628 if (!$line['lang']) $line['lang'] = 'en';
630 $tmp_content .= "<div class=\"cdmContentInner\" lang=\"".$line['lang']."\">";
632 if ($line["orig_feed_id"]) {
634 $ofgh = $this->pdo
->prepare("SELECT * FROM ttrss_archived_feeds
635 WHERE id = ? AND owner_uid = ?");
636 $ofgh->execute([$line["orig_feed_id"], $_SESSION['uid']]);
638 if ($tmp_line = $ofgh->fetch()) {
640 $tmp_content .= "<div clear='both'>";
641 $tmp_content .= __("Originally from:");
643 $tmp_content .= " ";
645 $tmp_content .= "<a target='_blank' rel='noopener noreferrer'
646 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
647 $tmp_line['title'] . "</a>";
649 $tmp_content .= " ";
651 $tmp_content .= "<a target='_blank' rel='noopener noreferrer' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
652 $tmp_content .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.png'></a>";
654 $tmp_content .= "</div>";
658 $tmp_content .= "<span id=\"CWRAP-$id\">";
659 $tmp_content .= "<span id=\"CENCW-$id\" class=\"cencw\" style=\"display : none\">";
660 $tmp_content .= htmlspecialchars($line["content"]);
661 $tmp_content .= "</span>";
662 $tmp_content .= "</span>";
664 $tmp_content .= "</div>"; //cdmContentInner
666 $tmp_content .= "<div class=\"cdmIntermediate\">";
668 $always_display_enclosures = $line["always_display_enclosures"];
669 $tmp_content .= Article
::format_article_enclosures($id, $always_display_enclosures,
670 $line["content"], $line["hide_images"]);
672 $tmp_content .= "</div>"; // cdmIntermediate
674 $tmp_content .= "<div class=\"cdmFooter\" onclick=\"cdmFooterClick(event)\">";
676 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_LEFT_BUTTON
) as $p) {
677 $tmp_content .= $p->hook_article_left_button($line);
680 $tags_str = Article
::format_tags_string($tags, $id);
682 $tmp_content .= "<span class='left'>";
684 $tmp_content .= "<img src='images/tag.png' alt='Tags' title='Tags'>
685 <span id=\"ATSTR-$id\">$tags_str</span>
686 <a title=\"".__('Edit tags for this article')."\"
687 href=\"#\" onclick=\"editArticleTags($id)\">(+)</a>";
689 $num_comments = (int) $line["num_comments"];
690 $entry_comments = "";
692 if ($num_comments > 0) {
693 if ($line["comments"]) {
694 $comments_url = htmlspecialchars($line["comments"]);
696 $comments_url = htmlspecialchars($line["link"]);
698 $entry_comments = "<a class=\"postComments\"
699 target='_blank' rel='noopener noreferrer' href=\"$comments_url\">$num_comments ".
700 _ngettext("comment", "comments", $num_comments)."</a>";
703 if ($line["comments"] && $line["link"] != $line["comments"]) {
704 $entry_comments = "<a class=\"postComments\" target='_blank' rel='noopener noreferrer' href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
708 if ($entry_comments) $tmp_content .= " ($entry_comments)";
710 $tmp_content .= "</span>";
711 $tmp_content .= "<div>";
713 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_BUTTON
) as $p) {
714 $tmp_content .= $p->hook_article_button($line);
717 $tmp_content .= "</div>"; // buttons
719 $tmp_content .= "</div>"; // cdmFooter
720 $tmp_content .= "</div>"; // cdmContent
721 $tmp_content .= "</div>"; // RROW.cdm
723 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_FORMAT_ARTICLE_CDM
) as $p) {
724 $tmp_content = $p->hook_format_article_cdm($tmp_content, $line);
727 $reply['content'] .= $tmp_content;
734 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
736 if (!$headlines_count) {
738 if (!is_numeric($result)) {
740 switch ($view_mode) {
742 $message = __("No unread articles found to display.");
745 $message = __("No updated articles found to display.");
748 $message = __("No starred articles found to display.");
751 if ($feed < LABEL_BASE_INDEX
) {
752 $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.");
754 $message = __("No articles found to display.");
758 if (!$offset && $message) {
759 $reply['content'] = "<div class='whiteBox'>$message";
761 $reply['content'] .= "<p><span class=\"insensitive\">";
763 $sth = $this->pdo
->prepare("SELECT " . SUBSTRING_FOR_DATE
. "(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
764 WHERE owner_uid = ?");
765 $sth->execute([$_SESSION['uid']]);
766 $row = $sth->fetch();
768 $last_updated = make_local_datetime($row["last_updated"], false);
770 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
772 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS num_errors
773 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
774 $sth->execute([$_SESSION['uid']]);
775 $row = $sth->fetch();
777 $num_errors = $row["num_errors"];
779 if ($num_errors > 0) {
780 $reply['content'] .= "<br/>";
781 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">" .
782 __('Some feeds have update errors (click for details)') . "</a>";
784 $reply['content'] .= "</span></p></div>";
787 } else if (is_numeric($result) && $result == -1) {
788 $reply['first_id_changed'] = true;
792 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
794 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
795 $vgroup_last_feed, $reply);
798 function catchupAll() {
799 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
800 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = ?");
801 $sth->execute([$_SESSION['uid']]);
803 CCache
::zero_all($_SESSION["uid"]);
807 $timing_info = microtime(true);
811 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
813 $feed = $_REQUEST["feed"];
814 $method = $_REQUEST["m"];
815 $view_mode = $_REQUEST["view_mode"];
817 @$cat_view = $_REQUEST["cat"] == "true";
818 @$next_unread_feed = $_REQUEST["nuf"];
819 @$offset = $_REQUEST["skip"];
820 @$vgroup_last_feed = $_REQUEST["vgrlf"];
821 $order_by = $_REQUEST["order_by"];
822 $check_first_id = $_REQUEST["fid"];
824 if (is_numeric($feed)) $feed = (int) $feed;
826 /* Feed -5 is a special case: it is used to display auxiliary information
827 * when there's nothing to load - e.g. no stuff in fresh feed */
830 print json_encode($this->generate_dashboard_feed());
835 if ($feed < LABEL_BASE_INDEX
) {
837 $label_feed = Labels
::feed_to_label_id($feed);
839 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_labels2 WHERE
840 id = ? AND owner_uid = ?");
841 $sth->execute([$label_feed, $_SESSION['uid']]);
843 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
845 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE
846 id = ? AND owner_uid = ?");
847 $sth->execute([$feed, $_SESSION['uid']]);
849 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
851 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feed_categories WHERE
852 id = ? AND owner_uid = ?");
854 $sth->execute([$feed, $_SESSION['uid']]);
857 if ($sth && !$sth->fetch()) {
858 print json_encode($this->generate_error_feed(__("Feed not found.")));
862 /* Updating a label ccache means recalculating all of the caches
863 * so for performance reasons we don't do that here */
866 CCache
::update($feed, $_SESSION["uid"], $cat_view);
869 set_pref("_DEFAULT_VIEW_MODE", $view_mode);
870 set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by);
872 /* bump login timestamp if needed */
873 if (time() - $_SESSION["last_login_update"] > 3600) {
874 $sth = $this->pdo
->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?");
875 $sth->execute([$_SESSION['uid']]);
877 $_SESSION["last_login_update"] = time();
880 if (!$cat_view && is_numeric($feed) && $feed > 0) {
881 $sth = $this->pdo
->prepare("UPDATE ttrss_feeds SET last_viewed = NOW()
882 WHERE id = ? AND owner_uid = ?");
883 $sth->execute([$feed, $_SESSION['uid']]);
886 $reply['headlines'] = array();
888 $override_order = false;
889 $skip_first_id_check = false;
893 $override_order = "ttrss_entries.title, date_entered, updated";
896 $override_order = "score DESC, date_entered, updated";
897 $skip_first_id_check = true;
900 $override_order = "updated DESC";
904 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
906 $ret = $this->format_headlines_list($feed, $method,
907 $view_mode, $limit, $cat_view, $offset,
908 $vgroup_last_feed, $override_order, true, $check_first_id, $skip_first_id_check);
910 //$topmost_article_ids = $ret[0];
911 $headlines_count = $ret[1];
912 /* $returned_feed = $ret[2]; */
913 $disable_cache = $ret[3];
914 $vgroup_last_feed = $ret[4];
916 //$reply['headlines']['content'] =& $ret[5]['content'];
917 //$reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
919 $reply['headlines'] = $ret[5];
921 if (!$next_unread_feed)
922 $reply['headlines']['id'] = $feed;
924 $reply['headlines']['id'] = $next_unread_feed;
926 $reply['headlines']['is_cat'] = (bool) $cat_view;
928 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
930 $reply['headlines-info'] = array("count" => (int) $headlines_count,
931 "vgroup_last_feed" => $vgroup_last_feed,
932 "disable_cache" => (bool) $disable_cache);
934 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
936 $reply['runtime-info'] = make_runtime_info();
938 print json_encode($reply);
942 private function generate_dashboard_feed() {
945 $reply['headlines']['id'] = -5;
946 $reply['headlines']['is_cat'] = false;
948 $reply['headlines']['toolbar'] = '';
950 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
952 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
954 $sth = $this->pdo
->prepare("SELECT ".SUBSTRING_FOR_DATE
."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
955 WHERE owner_uid = ?");
956 $sth->execute([$_SESSION['uid']]);
957 $row = $sth->fetch();
959 $last_updated = make_local_datetime($row["last_updated"], false);
961 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
963 $sth = $this->pdo
->prepare("SELECT COUNT(id) AS num_errors
964 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
965 $sth->execute([$_SESSION['uid']]);
966 $row = $sth->fetch();
968 $num_errors = $row["num_errors"];
970 if ($num_errors > 0) {
971 $reply['headlines']['content'] .= "<br/>";
972 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
973 __('Some feeds have update errors (click for details)')."</a>";
975 $reply['headlines']['content'] .= "</span></p>";
977 $reply['headlines-info'] = array("count" => 0,
978 "vgroup_last_feed" => '',
980 "disable_cache" => true);
985 private function generate_error_feed($error) {
988 $reply['headlines']['id'] = -7;
989 $reply['headlines']['is_cat'] = false;
991 $reply['headlines']['toolbar'] = '';
992 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
994 $reply['headlines-info'] = array("count" => 0,
995 "vgroup_last_feed" => '',
997 "disable_cache" => true);
1002 function quickAddFeed() {
1003 print_hidden("op", "rpc");
1004 print_hidden("method", "addfeed");
1006 print "<div id='fadd_error_message' style='display : none' class='alert alert-danger'></div>";
1008 print "<div id='fadd_multiple_notify' style='display : none'>";
1009 print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below.");
1012 print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
1013 print "<div class=\"dlgSecCont\">";
1015 print "<div style='float : right'>
1016 <img style='display : none'
1017 id='feed_add_spinner' src='images/indicator_white.gif'></div>";
1019 print "<input style=\"font-size : 16px; width : 20em;\"
1020 placeHolder=\"".__("Feed or site URL")."\"
1021 dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
1025 if (get_pref('ENABLE_FEED_CATS')) {
1026 print __('Place in category:') . " ";
1027 print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
1032 print '<div id="feedDlg_feedsContainer" style="display : none">
1034 <div class="dlgSec">' . __('Available feeds') . '</div>
1035 <div class="dlgSecCont">'.
1036 '<select id="feedDlg_feedContainerSelect"
1037 dojoType="dijit.form.Select" size="3">
1038 <script type="dojo/method" event="onChange" args="value">
1039 dijit.byId("feedDlg_feedUrl").attr("value", value);
1044 print "<div id='feedDlg_loginContainer' style='display : none'>
1046 <div class=\"dlgSec\">".__("Authentication")."</div>
1047 <div class=\"dlgSecCont\">".
1049 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
1050 placeHolder=\"".__("Login")."\"
1051 autocomplete=\"new-password\"
1052 style=\"width : 10em;\"> ".
1054 placeHolder=\"".__("Password")."\"
1055 dojoType=\"dijit.form.TextBox\" type='password'
1056 autocomplete=\"new-password\"
1057 style=\"width : 10em;\" name='pass'\">
1061 print "<div style=\"clear : both\">
1062 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
1063 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
1064 <label for=\"feedDlg_loginCheck\">".
1065 __('This feed requires authentication.')."</div>";
1069 print "<div class=\"dlgButtons\">
1070 <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
1072 if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
)) {
1073 print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
1076 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
1082 function feedBrowser() {
1083 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER
) return;
1085 $browser_search = $_REQUEST["search"];
1087 print_hidden("op", "rpc");
1088 print_hidden("method", "updateFeedBrowser");
1090 print "<div dojoType=\"dijit.Toolbar\">
1091 <div style='float : right'>
1092 <img style='display : none'
1093 id='feed_browser_spinner' src='images/indicator_white.gif'>
1094 <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
1095 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
1096 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
1099 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
1100 <option value='1'>" . __('Popular feeds') . "</option>
1101 <option value='2'>" . __('Feed archive') . "</option>
1106 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
1108 foreach (array(25, 50, 100, 200) as $l) {
1109 //$issel = ($l == $limit) ? "selected=\"1\"" : "";
1110 print "<option value=\"$l\">$l</option>";
1117 require_once "feedbrowser.php";
1119 print "<ul class='browseFeedList' id='browseFeedList'>";
1120 print make_feed_browser("", 25);
1123 print "<div align='center'>
1124 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
1125 <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
1126 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
1131 $this->params
= explode(":", $_REQUEST["param"], 2);
1133 $active_feed_id = sprintf("%d", $this->params
[0]);
1134 $is_cat = $this->params
[1] != "false";
1136 print "<form onsubmit='return false;'>";
1138 print "<div class=\"dlgSec\">".__('Look for')."</div>";
1140 print "<div class=\"dlgSecCont\">";
1142 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1143 style=\"font-size : 16px; width : 20em;\"
1144 required=\"1\" name=\"query\" type=\"search\" value=''>";
1146 print "<hr/><span style='float : right'>".T_sprintf('in %s', $this->getFeedTitle($active_feed_id, $is_cat))."</span>";
1148 if (DB_TYPE
== "pgsql") {
1150 print_select("search_language", "", Pref_Feeds
::$feed_languages,
1151 "dojoType='dijit.form.Select' title=\"".__('Used for word stemming')."\"");
1156 print "<div class=\"dlgButtons\">";
1158 if (count(PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SEARCH
)) == 0) {
1159 print "<div style=\"float : left\">
1160 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">".__("Search syntax")."</a>
1164 print "<button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"btn-primary\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
1165 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>
1171 function update_debugger() {
1172 header("Content-type: text/html");
1174 $feed_id = (int)$_REQUEST["feed_id"];
1175 @$do_update = $_REQUEST["action"] == "do_update";
1176 $csrf_token = $_REQUEST["csrf_token"];
1178 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?");
1179 $sth->execute([$feed_id, $_SESSION['uid']]);
1181 if (!$sth->fetch()) {
1182 print "Access denied.";
1186 $refetch_checked = isset($_REQUEST["force_refetch"]) ?
"checked" : "";
1187 $rehash_checked = isset($_REQUEST["force_rehash"]) ?
"checked" : "";
1192 <?php
echo stylesheet_tag("css/default.css") ?
>
1193 <title
>Feed Debugger
</title
>
1195 <body
class="small_margins ttrss_utility claro">
1196 <h1
>Feed Debugger
: <?php
echo "$feed_id: " . $this->getFeedTitle($feed_id) ?
></h1
>
1197 <form method
="GET" action
="">
1198 <input type
="hidden" name
="op" value
="feeds">
1199 <input type
="hidden" name
="method" value
="update_debugger">
1200 <input type
="hidden" name
="xdebug" value
="1">
1201 <input type
="hidden" name
="csrf_token" value
="<?php echo $csrf_token ?>">
1202 <input type
="hidden" name
="action" value
="do_update">
1203 <input type
="hidden" name
="feed_id" value
="<?php echo $feed_id ?>">
1204 <input type
="checkbox" name
="force_refetch" value
="1" <?php
echo $refetch_checked ?
>> Force refetch
<br
/>
1205 <input type
="checkbox" name
="force_rehash" value
="1" <?php
echo $rehash_checked ?
>> Force rehash
<br
/>
1207 <p
/><button type
="submit">Continue</button
>
1215 RSSUtils
::update_rss_feed($feed_id, true);
1226 static function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) {
1228 if (!$owner_uid) $owner_uid = $_SESSION['uid'];
1232 // Todo: all this interval stuff needs some generic generator function
1234 $search_qpart = is_array($search) && $search[0] ?
search_to_sql($search[0], $search[1])[0] : 'true';
1238 if (DB_TYPE
== "pgsql") {
1239 $date_qpart = "date_entered < NOW() - INTERVAL '1 day' ";
1241 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) ";
1245 if (DB_TYPE
== "pgsql") {
1246 $date_qpart = "date_entered < NOW() - INTERVAL '1 week' ";
1248 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) ";
1252 if (DB_TYPE
== "pgsql") {
1253 $date_qpart = "date_entered < NOW() - INTERVAL '2 week' ";
1255 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) ";
1259 $date_qpart = "true";
1262 if (is_numeric($feed)) {
1268 $children = Feeds
::getChildCategories($feed, $owner_uid);
1269 array_push($children, $feed);
1271 $children = join(",", $children);
1273 $cat_qpart = "cat_id IN ($children)";
1275 $cat_qpart = "cat_id IS NULL";
1278 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1279 SET unread = false, last_read = NOW() WHERE ref_id IN
1281 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1282 AND owner_uid = ? AND unread = true AND feed_id IN
1283 (SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart AND $search_qpart) as tmp)");
1284 $sth->execute([$owner_uid]);
1286 } else if ($feed == -2) {
1288 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1289 SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*)
1290 FROM ttrss_user_labels2, ttrss_entries WHERE article_id = ref_id AND id = ref_id AND $date_qpart AND $search_qpart) > 0
1291 AND unread = true AND owner_uid = ?");
1292 $sth->execute([$owner_uid]);
1295 } else if ($feed > 0) {
1297 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1298 SET unread = false, last_read = NOW() WHERE ref_id IN
1300 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1301 AND owner_uid = ? AND unread = true AND feed_id = ? AND $date_qpart AND $search_qpart) as tmp)");
1302 $sth->execute([$owner_uid, $feed]);
1304 } else if ($feed < 0 && $feed > LABEL_BASE_INDEX
) { // special, like starred
1307 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1308 SET unread = false, last_read = NOW() WHERE ref_id IN
1310 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1311 AND owner_uid = ? AND unread = true AND marked = true AND $date_qpart AND $search_qpart) as tmp)");
1312 $sth->execute([$owner_uid]);
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 published = true AND $date_qpart AND $search_qpart) as tmp)");
1321 $sth->execute([$owner_uid]);
1326 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE");
1328 if (DB_TYPE
== "pgsql") {
1329 $match_part = "date_entered > NOW() - INTERVAL '$intl hour' ";
1331 $match_part = "date_entered > DATE_SUB(NOW(),
1332 INTERVAL $intl HOUR) ";
1335 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1336 SET unread = false, last_read = NOW() WHERE ref_id IN
1338 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
1339 AND owner_uid = ? AND score >= 0 AND unread = true AND $date_qpart AND $match_part AND $search_qpart) as tmp)");
1340 $sth->execute([$owner_uid]);
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 unread = true AND $date_qpart AND $search_qpart) as tmp)");
1349 $sth->execute([$owner_uid]);
1352 } else if ($feed < LABEL_BASE_INDEX
) { // label
1354 $label_id = Labels
::feed_to_label_id($feed);
1356 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1357 SET unread = false, last_read = NOW() WHERE ref_id IN
1359 (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_user_labels2 WHERE ref_id = id
1360 AND label_id = ? AND ref_id = article_id
1361 AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
1362 $sth->execute([$label_id, $owner_uid]);
1366 CCache
::update($feed, $owner_uid, $cat_view);
1369 $sth = $pdo->prepare("UPDATE ttrss_user_entries
1370 SET unread = false, last_read = NOW() WHERE ref_id IN
1372 (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_tags WHERE ref_id = ttrss_entries.id
1373 AND post_int_id = int_id AND tag_name = ?
1374 AND ttrss_user_entries.owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
1375 $sth->execute([$feed, $owner_uid]);
1380 static function getFeedArticles($feed, $is_cat = false, $unread_only = false,
1381 $owner_uid = false) {
1383 $n_feed = (int) $feed;
1384 $need_entries = false;
1388 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1391 $unread_qpart = "unread = true";
1393 $unread_qpart = "true";
1399 return Feeds
::getCategoryUnread($n_feed, $owner_uid);
1400 } else if ($n_feed == -6) {
1402 } else if ($feed != "0" && $n_feed == 0) {
1404 $sth = $pdo->prepare("SELECT SUM((SELECT COUNT(int_id)
1405 FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
1406 AND ref_id = id AND $unread_qpart)) AS count FROM ttrss_tags
1407 WHERE owner_uid = ? AND tag_name = ?");
1409 $sth->execute([$owner_uid, $feed]);
1410 $row = $sth->fetch();
1412 return $row["count"];
1414 } else if ($n_feed == -1) {
1415 $match_part = "marked = true";
1416 } else if ($n_feed == -2) {
1417 $match_part = "published = true";
1418 } else if ($n_feed == -3) {
1419 $match_part = "unread = true AND score >= 0";
1421 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
1423 if (DB_TYPE
== "pgsql") {
1424 $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
1426 $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
1429 $need_entries = true;
1431 } else if ($n_feed == -4) {
1432 $match_part = "true";
1433 } else if ($n_feed >= 0) {
1436 $match_part = "feed_id = '$n_feed'";
1438 $match_part = "feed_id IS NULL";
1441 } else if ($feed < LABEL_BASE_INDEX
) {
1443 $label_id = Labels
::feed_to_label_id($feed);
1445 return Feeds
::getLabelUnread($label_id, $owner_uid);
1450 if ($need_entries) {
1451 $from_qpart = "ttrss_user_entries,ttrss_entries";
1452 $from_where = "ttrss_entries.id = ttrss_user_entries.ref_id AND";
1454 $from_qpart = "ttrss_user_entries";
1458 $sth = $pdo->prepare("SELECT count(int_id) AS unread
1459 FROM $from_qpart WHERE
1460 $unread_qpart AND $from_where ($match_part) AND ttrss_user_entries.owner_uid = ?");
1461 $sth->execute([$owner_uid]);
1462 $row = $sth->fetch();
1464 return $row["unread"];
1468 $sth = $pdo->prepare("SELECT COUNT(post_int_id) AS unread
1469 FROM ttrss_tags,ttrss_user_entries,ttrss_entries
1470 WHERE tag_name = ? AND post_int_id = int_id AND ref_id = ttrss_entries.id
1471 AND $unread_qpart AND ttrss_tags.owner_uid = ,");
1473 $sth->execute([$feed, $owner_uid]);
1474 $row = $sth->fetch();
1476 return $row["unread"];
1481 * @return array (code => Status code, message => error message if available)
1483 * 0 - OK, Feed already exists
1484 * 1 - OK, Feed added
1486 * 3 - URL content is HTML, no feeds available
1487 * 4 - URL content is HTML which contains multiple feeds.
1488 * Here you should call extractfeedurls in rpc-backend
1489 * to get all possible feeds.
1490 * 5 - Couldn't download the URL content.
1491 * 6 - Content is an invalid XML.
1493 static function subscribe_to_feed($url, $cat_id = 0,
1494 $auth_login = '', $auth_pass = '') {
1496 global $fetch_last_error;
1497 global $fetch_last_error_content;
1501 $url = fix_url($url);
1503 if (!$url ||
!validate_feed_url($url)) return array("code" => 2);
1505 $contents = @fetch_file_contents
($url, false, $auth_login, $auth_pass);
1508 if (preg_match("/cloudflare\.com/", $fetch_last_error_content)) {
1509 $fetch_last_error .= " (feed behind Cloudflare)";
1512 return array("code" => 5, "message" => $fetch_last_error);
1515 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SUBSCRIBE_FEED
) as $plugin) {
1516 $contents = $plugin->hook_subscribe_feed($contents, $url, $auth_login, $auth_pass);
1519 if (is_html($contents)) {
1520 $feedUrls = get_feeds_from_html($url, $contents);
1522 if (count($feedUrls) == 0) {
1523 return array("code" => 3);
1524 } else if (count($feedUrls) > 1) {
1525 return array("code" => 4, "feeds" => $feedUrls);
1527 //use feed url as new URL
1528 $url = key($feedUrls);
1531 if (!$cat_id) $cat_id = null;
1533 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
1534 WHERE feed_url = ? AND owner_uid = ?");
1535 $sth->execute([$url, $_SESSION['uid']]);
1537 if ($row = $sth->fetch()) {
1538 return array("code" => 0, "feed_id" => (int) $row["id"]);
1540 $sth = $pdo->prepare(
1541 "INSERT INTO ttrss_feeds
1542 (owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method,auth_pass_encrypted)
1543 VALUES (?, ?, ?, ?, ?, ?, 0, false)");
1545 $sth->execute([$_SESSION['uid'], $url, "[Unknown]", $cat_id, $auth_login, $auth_pass]);
1547 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
1548 AND owner_uid = ?");
1549 $sth->execute([$url, $_SESSION['uid']]);
1550 $row = $sth->fetch();
1552 $feed_id = $row["id"];
1555 RSSUtils
::set_basic_feed_info($feed_id);
1558 return array("code" => 1, "feed_id" => (int) $feed_id);
1563 static function getIconFile($feed_id) {
1564 return ICONS_DIR
. "/$feed_id.ico";
1567 static function feedHasIcon($id) {
1568 return is_file(ICONS_DIR
. "/$id.ico") && filesize(ICONS_DIR
. "/$id.ico") > 0;
1571 static function getFeedIcon($id) {
1574 return "images/archive.png";
1577 return "images/star.png";
1580 return "images/feed.png";
1583 return "images/fresh.png";
1586 return "images/folder.png";
1589 return "images/time.png";
1592 if ($id < LABEL_BASE_INDEX
) {
1593 return "images/label.png";
1595 $icon = self
::getIconFile($id);
1597 if ($icon && file_exists($icon)) {
1598 return ICONS_URL
. "/" . basename($icon) . "?" . filemtime($icon);
1607 static function getFeedTitle($id, $cat = false) {
1611 return Feeds
::getCategoryTitle($id);
1612 } else if ($id == -1) {
1613 return __("Starred articles");
1614 } else if ($id == -2) {
1615 return __("Published articles");
1616 } else if ($id == -3) {
1617 return __("Fresh articles");
1618 } else if ($id == -4) {
1619 return __("All articles");
1620 } else if ($id === 0 ||
$id === "0") {
1621 return __("Archived articles");
1622 } else if ($id == -6) {
1623 return __("Recently read");
1624 } else if ($id < LABEL_BASE_INDEX
) {
1626 $label_id = Labels
::feed_to_label_id($id);
1628 $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 WHERE id = ?");
1629 $sth->execute([$label_id]);
1631 if ($row = $sth->fetch()) {
1632 return $row["caption"];
1634 return "Unknown label ($label_id)";
1637 } else if (is_numeric($id) && $id > 0) {
1639 $sth = $pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?");
1640 $sth->execute([$id]);
1642 if ($row = $sth->fetch()) {
1643 return $row["title"];
1645 return "Unknown feed ($id)";
1653 static function getCategoryUnread($cat, $owner_uid = false) {
1655 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1661 if (!$cat) $cat = null;
1663 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
1664 WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
1665 AND owner_uid = :uid");
1667 $sth->execute([":cat" => $cat, ":uid" => $owner_uid]);
1669 $cat_feeds = array();
1670 while ($line = $sth->fetch()) {
1671 array_push($cat_feeds, "feed_id = " . $line["id"]);
1674 if (count($cat_feeds) == 0) return 0;
1676 $match_part = implode(" OR ", $cat_feeds);
1678 $sth = $pdo->prepare("SELECT COUNT(int_id) AS unread
1679 FROM ttrss_user_entries
1680 WHERE unread = true AND ($match_part)
1681 AND owner_uid = ?");
1682 $sth->execute([$owner_uid]);
1686 # this needs to be rewritten
1687 while ($line = $sth->fetch()) {
1688 $unread +
= $line["unread"];
1692 } else if ($cat == -1) {
1693 return getFeedUnread(-1) +
getFeedUnread(-2) +
getFeedUnread(-3) +
getFeedUnread(0);
1694 } else if ($cat == -2) {
1696 $sth = $pdo->prepare("SELECT COUNT(unread) AS unread FROM
1697 ttrss_user_entries, ttrss_user_labels2
1698 WHERE article_id = ref_id AND unread = true
1699 AND ttrss_user_entries.owner_uid = ?");
1700 $sth->execute([$owner_uid]);
1701 $row = $sth->fetch();
1703 return $row["unread"];
1707 // only accepts real cats (>= 0)
1708 static function getCategoryChildrenUnread($cat, $owner_uid = false) {
1709 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1713 $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE parent_cat = ?
1714 AND owner_uid = ?");
1715 $sth->execute([$cat, $owner_uid]);
1719 while ($line = $sth->fetch()) {
1720 $unread +
= Feeds
::getCategoryUnread($line["id"], $owner_uid);
1721 $unread +
= Feeds
::getCategoryChildrenUnread($line["id"], $owner_uid);
1727 static function getGlobalUnread($user_id = false) {
1729 if (!$user_id) $user_id = $_SESSION["uid"];
1733 $sth = $pdo->prepare("SELECT SUM(value) AS c_id FROM ttrss_counters_cache
1734 WHERE owner_uid = ? AND feed_id > 0");
1735 $sth->execute([$user_id]);
1736 $row = $sth->fetch();
1738 return $row["c_id"];
1741 static function getCategoryTitle($cat_id) {
1743 if ($cat_id == -1) {
1744 return __("Special");
1745 } else if ($cat_id == -2) {
1746 return __("Labels");
1751 $sth = $pdo->prepare("SELECT title FROM ttrss_feed_categories WHERE
1753 $sth->execute([$cat_id]);
1755 if ($row = $sth->fetch()) {
1756 return $row["title"];
1758 return __("Uncategorized");
1763 static function getLabelUnread($label_id, $owner_uid = false) {
1764 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1768 $sth = $pdo->prepare("SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2
1769 WHERE owner_uid = ? AND unread = true AND label_id = ? AND article_id = ref_id");
1771 $sth->execute([$owner_uid, $label_id]);
1773 if ($row = $sth->fetch()) {
1774 return $row["unread"];
1780 static function queryFeedHeadlines($params) {
1784 // WARNING: due to highly dynamic nature of this query its going to quote parameters
1785 // right before adding them to SQL part
1787 $feed = $params["feed"];
1788 $limit = isset($params["limit"]) ?
$params["limit"] : 30;
1789 $view_mode = $params["view_mode"];
1790 $cat_view = isset($params["cat_view"]) ?
$params["cat_view"] : false;
1791 $search = isset($params["search"]) ?
$params["search"] : false;
1792 $search_language = isset($params["search_language"]) ?
$params["search_language"] : "";
1793 $override_order = isset($params["override_order"]) ?
$params["override_order"] : false;
1794 $offset = isset($params["offset"]) ?
$params["offset"] : 0;
1795 $owner_uid = isset($params["owner_uid"]) ?
$params["owner_uid"] : $_SESSION["uid"];
1796 $since_id = isset($params["since_id"]) ?
$params["since_id"] : 0;
1797 $include_children = isset($params["include_children"]) ?
$params["include_children"] : false;
1798 $ignore_vfeed_group = isset($params["ignore_vfeed_group"]) ?
$params["ignore_vfeed_group"] : false;
1799 $override_strategy = isset($params["override_strategy"]) ?
$params["override_strategy"] : false;
1800 $override_vfeed = isset($params["override_vfeed"]) ?
$params["override_vfeed"] : false;
1801 $start_ts = isset($params["start_ts"]) ?
$params["start_ts"] : false;
1802 $check_first_id = isset($params["check_first_id"]) ?
$params["check_first_id"] : false;
1803 $skip_first_id_check = isset($params["skip_first_id_check"]) ?
$params["skip_first_id_check"] : false;
1805 $ext_tables_part = "";
1806 $limit_query_part = "";
1808 $search_words = array();
1811 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SEARCH
) as $plugin) {
1812 list($search_query_part, $search_words) = $plugin->hook_search($search);
1816 // fall back in case of no plugins
1817 if (!$search_query_part) {
1818 list($search_query_part, $search_words) = search_to_sql($search, $search_language);
1820 $search_query_part .= " AND ";
1822 $search_query_part = "";
1826 $since_id_part = "ttrss_entries.id > ".$pdo->quote($since_id)." AND ";
1828 $since_id_part = "";
1831 $view_query_part = "";
1833 if ($view_mode == "adaptive") {
1835 $view_query_part = " ";
1836 } else if ($feed != -1) {
1838 $unread = getFeedUnread($feed, $cat_view);
1840 if ($cat_view && $feed > 0 && $include_children)
1841 $unread +
= Feeds
::getCategoryChildrenUnread($feed);
1844 $view_query_part = " unread = true AND ";
1849 if ($view_mode == "marked") {
1850 $view_query_part = " marked = true AND ";
1853 if ($view_mode == "has_note") {
1854 $view_query_part = " (note IS NOT NULL AND note != '') AND ";
1857 if ($view_mode == "published") {
1858 $view_query_part = " published = true AND ";
1861 if ($view_mode == "unread" && $feed != -6) {
1862 $view_query_part = " unread = true AND ";
1866 $limit_query_part = "LIMIT " . (int)$limit;
1869 $allow_archived = false;
1871 $vfeed_query_part = "";
1874 if (!is_numeric($feed)) {
1875 $query_strategy_part = "true";
1876 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1877 id = feed_id) as feed_title,";
1878 } else if ($feed > 0) {
1883 if ($include_children) {
1885 $subcats = Feeds
::getChildCategories($feed, $owner_uid);
1887 array_push($subcats, $feed);
1888 $query_strategy_part = "cat_id IN (".
1889 implode(",", $subcats).")";
1892 $query_strategy_part = "cat_id = " . $pdo->quote($feed);
1896 $query_strategy_part = "cat_id IS NULL";
1899 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1902 $query_strategy_part = "feed_id = " . $pdo->quote($feed);
1904 } else if ($feed == 0 && !$cat_view) { // archive virtual feed
1905 $query_strategy_part = "feed_id IS NULL";
1906 $allow_archived = true;
1907 } else if ($feed == 0 && $cat_view) { // uncategorized
1908 $query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL";
1909 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1910 } else if ($feed == -1) { // starred virtual feed
1911 $query_strategy_part = "marked = true";
1912 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1913 $allow_archived = true;
1915 if (!$override_order) {
1916 $override_order = "last_marked DESC, date_entered DESC, updated DESC";
1919 } else if ($feed == -2) { // published virtual feed OR labels category
1922 $query_strategy_part = "published = true";
1923 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1924 $allow_archived = true;
1926 if (!$override_order) {
1927 $override_order = "last_published DESC, date_entered DESC, updated DESC";
1931 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1933 $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,";
1935 $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND
1936 ttrss_user_labels2.article_id = ref_id";
1939 } else if ($feed == -6) { // recently read
1940 $query_strategy_part = "unread = false AND last_read IS NOT NULL";
1942 if (DB_TYPE
== "pgsql") {
1943 $query_strategy_part .= " AND last_read > NOW() - INTERVAL '1 DAY' ";
1945 $query_strategy_part .= " AND last_read > DATE_SUB(NOW(), INTERVAL 1 DAY) ";
1948 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1949 $allow_archived = true;
1950 $ignore_vfeed_group = true;
1952 if (!$override_order) $override_order = "last_read DESC";
1954 } else if ($feed == -3) { // fresh virtual feed
1955 $query_strategy_part = "unread = true AND score >= 0";
1957 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
1959 if (DB_TYPE
== "pgsql") {
1960 $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
1962 $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
1965 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1966 } else if ($feed == -4) { // all articles virtual feed
1967 $allow_archived = true;
1968 $query_strategy_part = "true";
1969 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1970 } else if ($feed <= LABEL_BASE_INDEX
) { // labels
1971 $label_id = Labels
::feed_to_label_id($feed);
1973 $query_strategy_part = "label_id = ".$pdo->quote($label_id)." AND
1974 ttrss_labels2.id = ttrss_user_labels2.label_id AND
1975 ttrss_user_labels2.article_id = ref_id";
1977 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1978 $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,";
1979 $allow_archived = true;
1982 $query_strategy_part = "true";
1985 $order_by = "score DESC, date_entered DESC, updated DESC";
1987 if ($override_order) {
1988 $order_by = $override_order;
1991 if ($override_strategy) {
1992 $query_strategy_part = $override_strategy;
1995 if ($override_vfeed) {
1996 $vfeed_query_part = $override_vfeed;
2000 $feed_title = T_sprintf("Search results: %s", $search);
2003 $feed_title = Feeds
::getCategoryTitle($feed);
2005 if (is_numeric($feed) && $feed > 0) {
2006 $ssth = $pdo->prepare("SELECT title,site_url,last_error,last_updated
2007 FROM ttrss_feeds WHERE id = ? AND owner_uid = ?");
2008 $ssth->execute([$feed, $owner_uid]);
2009 $row = $ssth->fetch();
2011 $feed_title = $row["title"];
2012 $feed_site_url = $row["site_url"];
2013 $last_error = $row["last_error"];
2014 $last_updated = $row["last_updated"];
2016 $feed_title = Feeds
::getFeedTitle($feed);
2021 $content_query_part = "content, ";
2023 if ($limit_query_part) {
2024 $offset_query_part = "OFFSET " . (int)$offset;
2026 $offset_query_part = "";
2029 if (is_numeric($feed)) {
2030 // proper override_order applied above
2031 if ($vfeed_query_part && !$ignore_vfeed_group && get_pref('VFEED_GROUP_BY_FEED', $owner_uid)) {
2032 if (!$override_order) {
2033 $order_by = "ttrss_feeds.title, ".$order_by;
2035 $order_by = "ttrss_feeds.title, ".$override_order;
2039 if (!$allow_archived) {
2040 $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id),ttrss_feeds";
2041 $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
2044 $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id)
2045 LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)";
2048 if ($vfeed_query_part) $vfeed_query_part .= "favicon_avg_color,";
2051 $start_ts_formatted = date("Y/m/d H:i:s", strtotime($start_ts));
2052 $start_ts_query_part = "date_entered >= '$start_ts_formatted' AND";
2054 $start_ts_query_part = "";
2058 $first_id_query_strategy_part = $query_strategy_part;
2061 $first_id_query_strategy_part = "true";
2063 if (DB_TYPE
== "pgsql") {
2064 $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND";
2066 $sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND";
2069 if (!$search && !$skip_first_id_check) {
2070 // if previous topmost article id changed that means our current pagination is no longer valid
2071 $query = "SELECT DISTINCT
2076 ttrss_entries.title,
2088 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
2090 $start_ts_query_part
2092 $sanity_interval_qpart
2093 $first_id_query_strategy_part ORDER BY $order_by LIMIT 1";
2095 if ($_REQUEST["debug"]) {
2099 $res = $pdo->query($query);
2101 if ($row = $res->fetch()) {
2102 $first_id = (int)$row["id"];
2104 if ($offset > 0 && $first_id && $check_first_id && $first_id != $check_first_id) {
2105 return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id);
2110 $query = "SELECT DISTINCT
2113 ttrss_entries.id,ttrss_entries.title,
2117 always_display_enclosures,
2126 unread,feed_id,marked,published,link,last_read,orig_feed_id,
2127 last_marked, last_published,
2135 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
2137 $start_ts_query_part
2140 $query_strategy_part ORDER BY $order_by
2141 $limit_query_part $offset_query_part";
2143 if ($_REQUEST["debug"]) print $query;
2145 $res = $pdo->query($query);
2150 $query = "SELECT DISTINCT
2154 ttrss_entries.id as id,
2170 (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images,
2171 last_marked, last_published,
2176 FROM ttrss_entries, ttrss_user_entries, ttrss_tags
2178 ref_id = ttrss_entries.id AND
2179 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
2180 post_int_id = int_id AND
2181 tag_name = ".$pdo->quote($feed)." AND
2184 $query_strategy_part ORDER BY $order_by
2185 $limit_query_part $offset_query_part";
2187 if ($_REQUEST["debug"]) print $query;
2189 $res = $pdo->query($query);
2192 return array($res, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id);
2196 static function getParentCategories($cat, $owner_uid) {
2201 $sth = $pdo->prepare("SELECT parent_cat FROM ttrss_feed_categories
2202 WHERE id = ? AND parent_cat IS NOT NULL AND owner_uid = ?");
2203 $sth->execute([$cat, $owner_uid]);
2205 while ($line = $sth->fetch()) {
2206 array_push($rv, $line["parent_cat"]);
2207 $rv = array_merge($rv, Feeds
::getParentCategories($line["parent_cat"], $owner_uid));
2213 static function getChildCategories($cat, $owner_uid) {
2218 $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories
2219 WHERE parent_cat = ? AND owner_uid = ?");
2220 $sth->execute([$cat, $owner_uid]);
2222 while ($line = $sth->fetch()) {
2223 array_push($rv, $line["id"]);
2224 $rv = array_merge($rv, Feeds
::getChildCategories($line["id"], $owner_uid));
2230 static function getFeedCategory($feed) {
2233 $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
2235 $sth->execute([$feed]);
2237 if ($row = $sth->fetch()) {
2238 return $row["cat_id"];