]> git.wh0rd.org - tt-rss.git/blame - classes/feeds.php
minor css fixes (mostly for zoom mode)
[tt-rss.git] / classes / feeds.php
CommitLineData
6afcbcd1
AD
1<?php
2require_once "colors.php";
3
4class Feeds extends Handler_Protected {
5
415a3b50
AD
6 private $params;
7
8 function csrf_ignore($method) {
1c9bda91 9 $csrf_ignored = array("index", "feedbrowser", "quickaddfeed", "search");
6afcbcd1
AD
10
11 return array_search($method, $csrf_ignored) !== false;
12 }
13
6afcbcd1 14 private function format_headline_subtoolbar($feed_site_url, $feed_title,
ca5d9be4 15 $feed_id, $is_cat, $search,
7b55001e 16 $error, $feed_last_updated) {
6afcbcd1 17
6afcbcd1
AD
18 $catchup_sel_link = "catchupSelection()";
19
20 $archive_sel_link = "archiveSelection()";
21 $delete_sel_link = "deleteSelection()";
22
23 $sel_all_link = "selectArticles('all')";
24 $sel_unread_link = "selectArticles('unread')";
25 $sel_none_link = "selectArticles('none')";
26 $sel_inv_link = "selectArticles('invert')";
27
28 $tog_unread_link = "selectionToggleUnread()";
29 $tog_marked_link = "selectionToggleMarked()";
30 $tog_published_link = "selectionTogglePublished()";
31
32 $set_score_link = "setSelectionScore()";
33
34 if ($is_cat) $cat_q = "&is_cat=$is_cat";
35
36 if ($search) {
9090b874 37 $search_q = "&q=$search";
6afcbcd1
AD
38 } else {
39 $search_q = "";
40 }
41
c9b6ca8b 42 $reply = "<span class=\"holder\">";
1bffd106 43
6afcbcd1
AD
44 $rss_link = htmlspecialchars(get_self_url_prefix() .
45 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
46
47 // right part
48
1a545dcb
AD
49 $error_class = $error ? "error" : "";
50
1bffd106
AD
51 $reply .= "<span class='r'>
52 <a href=\"#\"
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>";
56
57
58# $reply .= "<span>";
1a545dcb 59 $reply .= "<span id='feed_title' class='$error_class'>";
6afcbcd1
AD
60
61 if ($feed_site_url) {
6e3e8db9
AD
62 $last_updated = T_sprintf("Last updated: %s",
63 $feed_last_updated);
64
6afcbcd1 65 $target = "target=\"_blank\"";
6e3e8db9 66 $reply .= "<a title=\"$last_updated\" $target href=\"$feed_site_url\">".
7c6f7bb0 67 truncate_string(strip_tags($feed_title), 30)."</a>";
6afcbcd1
AD
68
69 if ($error) {
12d17734 70 $error = htmlspecialchars($error);
8993937d 71 $reply .= "&nbsp;<img title=\"$error\" src='images/error.png' alt='error' class=\"noborder\">";
6afcbcd1
AD
72 }
73
74 } else {
7c6f7bb0 75 $reply .= strip_tags($feed_title);
6afcbcd1
AD
76 }
77
78 $reply .= "</span>";
79
66684d81
AD
80 $reply .= "</span>";
81
1bffd106 82# $reply .= "</span>";
6afcbcd1
AD
83
84 // left part
85
1bffd106 86 $reply .= "<span class=\"main\">";
4e2f219c 87 $reply .= "<span id='selected_prompt'></span>";
1bffd106 88
6b06a609 89 /*$reply .= "<span class=\"sel_links\">
6afcbcd1
AD
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>";
94
6b06a609 95 $reply .= "</span> "; */
6afcbcd1
AD
96
97 $reply .= "<select dojoType=\"dijit.form.Select\"
98 onchange=\"headlineActionsChange(this)\">";
6b06a609
AD
99
100 $reply .= "<option value=\"0\" disabled='1'>".__('Select...')."</option>";
101
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>";
6afcbcd1
AD
106
107 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
108
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>";
112
113 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
114
115 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
116 $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>";
117
118 if ($feed_id != "0") {
119 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
120 } else {
121 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
122 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
123
124 }
125
1ffe3391 126 if (PluginHost::getInstance()->get_plugin("mail")) {
6afcbcd1
AD
127 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
128 "</option>";
129 }
130
1ffe3391 131 if (PluginHost::getInstance()->get_plugin("mailto")) {
1d5cf085
AD
132 $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email').
133 "</option>";
134 }
135
6afcbcd1
AD
136 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
137
3dd0306f 138 //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
6afcbcd1 139
fb54e3b1 140 $reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
6afcbcd1
AD
141
142 $reply .= "</select>";
143
6afcbcd1
AD
144 //$reply .= "</h2";
145
1ffe3391 146 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON) as $p) {
647a39dd 147 $reply .= $p->hook_headline_toolbar_button($feed_id, $is_cat);
ceb78471
AD
148 }
149
1bffd106
AD
150 $reply .= "</span></span>";
151
6afcbcd1
AD
152 return $reply;
153 }
154
155 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
7b55001e 156 $offset, $vgr_last_feed = false,
19e47ad6
AD
157 $override_order = false, $include_children = false, $check_first_id = false,
158 $skip_first_id_check = false) {
6afcbcd1 159
6afcbcd1
AD
160 $disable_cache = false;
161
162 $reply = array();
163
e0deff39
AD
164 $rgba_cache = array();
165
fa9e88c3 166 $timing_info = microtime(true);
6afcbcd1
AD
167
168 $topmost_article_ids = array();
169
170 if (!$offset) $offset = 0;
171 if ($method == "undefined") $method = "";
172
173 $method_split = explode(":", $method);
174
41245888 175 if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) {
3a029230 176 $sth = $this->pdo->prepare("UPDATE ttrss_feeds
8dedacf4
AD
177 SET last_updated = '1970-01-01', last_update_started = '1970-01-01'
178 WHERE id = ?");
179 $sth->execute([$feed]);
6afcbcd1
AD
180 }
181
182 if ($method_split[0] == "MarkAllReadGR") {
86a8351c 183 $this->catchup_feed($method_split[1], false);
6afcbcd1
AD
184 }
185
186 // FIXME: might break tag display?
187
188 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
29f1908e
AD
189 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? LIMIT 1");
190 $sth->execute([$feed]);
6afcbcd1 191
29f1908e 192 if (!$sth->fetch()) {
6afcbcd1
AD
193 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
194 }
195 }
196
c9b6ca8b
AD
197 @$search = $_REQUEST["query"];
198 @$search_language = $_REQUEST["search_language"]; // PGSQL only
6afcbcd1
AD
199
200 if ($search) {
201 $disable_cache = true;
202 }
203
6afcbcd1
AD
204 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
205
e92a353b 206 if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) {
1ffe3391 207 $handler = PluginHost::getInstance()->get_feed_handler(
a413f53e
AD
208 PluginHost::feed_to_pfeed_id($feed));
209
a413f53e
AD
210 if ($handler) {
211 $options = array(
212 "limit" => $limit,
213 "view_mode" => $view_mode,
214 "cat_view" => $cat_view,
215 "search" => $search,
a413f53e
AD
216 "override_order" => $override_order,
217 "offset" => $offset,
218 "owner_uid" => $_SESSION["uid"],
219 "filter" => false,
220 "since_id" => 0,
221 "include_children" => $include_children);
222
223 $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed),
224 $options);
225 }
226
227 } else {
f5a0fb8b
AD
228
229 $params = array(
230 "feed" => $feed,
231 "limit" => $limit,
232 "view_mode" => $view_mode,
233 "cat_view" => $cat_view,
234 "search" => $search,
60e68059 235 "search_language" => $search_language,
f5a0fb8b
AD
236 "override_order" => $override_order,
237 "offset" => $offset,
238 "include_children" => $include_children,
19e47ad6
AD
239 "check_first_id" => $check_first_id,
240 "skip_first_id_check" => $skip_first_id_check
f5a0fb8b
AD
241 );
242
aeb1abed 243 $qfh_ret = $this->queryFeedHeadlines($params);
a413f53e 244 }
6afcbcd1 245
ad593e43
AD
246 $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && $feed != -6;
247
6afcbcd1
AD
248 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
249
003a7447 250 $result = $qfh_ret[0]; // this could be either a PDO query result or a -1 if first id changed
6afcbcd1
AD
251 $feed_title = $qfh_ret[1];
252 $feed_site_url = $qfh_ret[2];
253 $last_error = $qfh_ret[3];
90e5f4f1
AD
254 $last_updated = strpos($qfh_ret[4], '1970-') === FALSE ?
255 make_local_datetime($qfh_ret[4], false) : __("Never");
dd90eb2c 256 $highlight_words = $qfh_ret[5];
48fefe2f 257 $reply['first_id'] = $qfh_ret[6];
33753541 258 $reply['search_query'] = [$search, $search_language];
6afcbcd1
AD
259
260 $vgroup_last_feed = $vgr_last_feed;
261
262 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
263 $feed_title,
7b55001e 264 $feed, $cat_view, $search,
6e3e8db9 265 $last_error, $last_updated);
6afcbcd1 266
7eb87b80
AD
267 if ($offset == 0) {
268 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINES_BEFORE) as $p) {
269 $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret);
270 }
271 }
272
f1706996 273 $reply['content'] = '';
9f5eca99 274
b5791f11
AD
275 $headlines_count = 0;
276
277 $lnum = $offset;
278 $num_unread = 0;
279 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
b5791f11 280
003a7447 281 if (is_object($result)) {
b5791f11 282
003a7447 283 while ($line = $result->fetch()) {
b5791f11 284
003a7447 285 ++$headlines_count;
6afcbcd1 286
003a7447 287 $line["content_preview"] = "&mdash; " . truncate_string(strip_tags($line["content"]), 250);
6afcbcd1 288
003a7447
AD
289 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
290 $line = $p->hook_query_headlines($line, 250, false);
291 }
6afcbcd1 292
003a7447
AD
293 if (get_pref('SHOW_CONTENT_PREVIEW')) {
294 $content_preview = $line["content_preview"];
295 }
6afcbcd1 296
003a7447
AD
297 $id = $line["id"];
298 $feed_id = $line["feed_id"];
299 $label_cache = $line["label_cache"];
300 $labels = false;
4ab1eb9c 301
8f92a67e
AD
302 $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' onmouseout='postMouseOut($id)'";
303
003a7447
AD
304 if ($label_cache) {
305 $label_cache = json_decode($label_cache, true);
ac4c1383 306
003a7447
AD
307 if ($label_cache) {
308 if ($label_cache["no-labels"] == 1)
309 $labels = array();
310 else
311 $labels = $label_cache;
312 }
313 }
4ab1eb9c 314
003a7447 315 if (!is_array($labels)) $labels = Article::get_article_labels($id);
4ab1eb9c 316
003a7447
AD
317 $labels_str = "<span class=\"HLLCTR-$id\">";
318 $labels_str .= Article::format_article_labels($labels);
319 $labels_str .= "</span>";
4ab1eb9c 320
003a7447
AD
321 if (count($topmost_article_ids) < 3) {
322 array_push($topmost_article_ids, $id);
323 }
6afcbcd1 324
003a7447 325 $class = "";
6afcbcd1 326
003a7447
AD
327 if ($line["unread"]) {
328 $class .= " Unread";
329 ++$num_unread;
330 }
331
8f92a67e
AD
332 $marked_pic_src = $line["marked"] ? "mark_set.png" : "mark_unset.png";
333 $class .= $line["marked"] ? " marked" : "";
334 $marked_pic = "<img src=\"images/$marked_pic_src\" class=\"markedPic\" onclick='toggleMark($id)'>";
6afcbcd1 335
8f92a67e
AD
336 $published_pic_src = $line["published"] ? "pub_set.png" : "pub_unset.png";
337 $class .= $line["published"] ? " published" : "";
338 $published_pic = "<img src=\"images/$published_pic_src\" class=\"pubPic\" onclick='togglePub($id)'>";
6afcbcd1 339
003a7447
AD
340 $updated_fmt = make_local_datetime($line["updated"], false, false, false, true);
341 $date_entered_fmt = T_sprintf("Imported at %s",
342 make_local_datetime($line["date_entered"], false));
6afcbcd1 343
003a7447 344 $score = $line["score"];
6afcbcd1 345
003a7447 346 $score_pic = "images/" . get_score_pic($score);
8d090a91 347
8359ca6d 348 $score_pic = "<img class='score-pic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\"
b5791f11 349 title=\"$score\">";
6afcbcd1 350
003a7447
AD
351 if ($score > 500) {
352 $hlc_suffix = "high";
353 } else if ($score < -100) {
354 $hlc_suffix = "low";
355 } else {
356 $hlc_suffix = "";
357 }
6afcbcd1 358
003a7447 359 $entry_author = $line["author"];
6afcbcd1 360
003a7447
AD
361 if ($entry_author) {
362 $entry_author = " &mdash; $entry_author";
363 }
6afcbcd1 364
5f211e37 365 if (feeds::feedHasIcon($feed_id)) {
003a7447
AD
366 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
367 } else {
368 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.png\" alt=\"\">";
369 }
6afcbcd1 370
003a7447 371 $entry_site_url = $line["site_url"];
6afcbcd1 372
003a7447
AD
373 //setting feed headline background color, needs to change text color based on dark/light
374 $fav_color = $line['favicon_avg_color'];
6afcbcd1 375
003a7447 376 require_once "colors.php";
6afcbcd1 377
003a7447
AD
378 if ($fav_color && $fav_color != 'fail') {
379 if (!isset($rgba_cache[$feed_id])) {
380 $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color));
381 }
382 }
6afcbcd1 383
003a7447 384 if (!get_pref('COMBINED_DISPLAY_MODE')) {
6afcbcd1 385
003a7447
AD
386 if ($vfeed_group_enabled) {
387 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
6afcbcd1 388
003a7447 389 $vgroup_last_feed = $feed_id;
6afcbcd1 390
003a7447 391 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
6afcbcd1 392
8359ca6d 393 $reply['content'] .= "<div data-feed-id='$feed_id' class='feed-titl'>".
003a7447
AD
394 "<div style='float : right'>$feed_icon_img</div>".
395 "<a class='title' href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
396 $line["feed_title"]."</a>
b5791f11 397 $vf_catchup_link</div>";
6afcbcd1 398
08dfc223 399
003a7447
AD
400 }
401 }
bfaf90e3 402
003a7447 403 $reply['content'] .= "<div class='hl hlMenuAttach $class' data-orig-feed-id='$feed_id' data-article-id='$id' id='RROW-$id' $mouseover_attrs>";
bfaf90e3 404
003a7447 405 $reply['content'] .= "<div class='hlLeft'>";
6afcbcd1 406
003a7447 407 $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"
b5791f11
AD
408 type=\"checkbox\" onclick=\"toggleSelectRow2(this)\"
409 class='rchk'>";
6afcbcd1 410
003a7447
AD
411 $reply['content'] .= "$marked_pic";
412 $reply['content'] .= "$published_pic";
6afcbcd1 413
003a7447 414 $reply['content'] .= "</div>";
6afcbcd1 415
003a7447 416 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
8359ca6d 417 class=\"title\"><span class='hlContent $hlc_suffix'>";
67cdf4cf 418 $reply['content'] .= "<a class=\"title $hlc_suffix\"
b5791f11
AD
419 href=\"" . htmlspecialchars($line["link"]) . "\"
420 onclick=\"\">" .
003a7447 421 truncate_string($line["title"], 200);
6afcbcd1 422
003a7447
AD
423 if (get_pref('SHOW_CONTENT_PREVIEW')) {
424 $reply['content'] .= "<span class=\"contentPreview\">" . $line["content_preview"] . "</span>";
425 }
6afcbcd1 426
003a7447 427 $reply['content'] .= "</a></span>";
ac4c1383 428
003a7447 429 $reply['content'] .= $labels_str;
6afcbcd1 430
003a7447 431 $reply['content'] .= "</div>";
6afcbcd1 432
003a7447
AD
433 if (!$vfeed_group_enabled) {
434 if (@$line["feed_title"]) {
435 $rgba = @$rgba_cache[$feed_id];
6afcbcd1 436
8359ca6d 437 $reply['content'] .= "<span class=\"feed\"><a style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">".
003a7447
AD
438 truncate_string($line["feed_title"],30)."</a></span>";
439 }
440 }
6afcbcd1 441
6afcbcd1 442
003a7447 443 $reply['content'] .= "<span class=\"hlUpdated\">";
6afcbcd1 444
003a7447 445 $reply['content'] .= "<div title='$date_entered_fmt'>$updated_fmt</div>
b5791f11 446 </span>";
6afcbcd1 447
003a7447 448 $reply['content'] .= "<div class=\"hlRight\">";
6afcbcd1 449
003a7447 450 $reply['content'] .= $score_pic;
6afcbcd1 451
003a7447 452 if ($line["feed_title"] && !$vfeed_group_enabled) {
6afcbcd1 453
003a7447 454 $reply['content'] .= "<span onclick=\"viewfeed({feed:$feed_id})\"
b5791f11
AD
455 style=\"cursor : pointer\"
456 title=\"".htmlspecialchars($line['feed_title'])."\">
457 $feed_icon_img</span>";
003a7447 458 }
6afcbcd1 459
003a7447
AD
460 $reply['content'] .= "</div>";
461 $reply['content'] .= "</div>";
e17e99fb 462
003a7447 463 } else {
d3103484 464
003a7447
AD
465 if ($line["tag_cache"])
466 $tags = explode(",", $line["tag_cache"]);
467 else
468 $tags = false;
6afcbcd1 469
003a7447
AD
470 $line["content"] = sanitize($line["content"],
471 $line['hide_images'], false, $entry_site_url, $highlight_words, $line["id"]);
029005c4 472
003a7447
AD
473 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) {
474 $line = $p->hook_render_article_cdm($line);
475 }
029005c4 476
2aef804f
AD
477 $line['content'] = rewrite_cached_urls($line['content']);
478
003a7447
AD
479 if ($vfeed_group_enabled && $line["feed_title"]) {
480 if ($feed_id != $vgroup_last_feed) {
be574731 481
003a7447 482 $vgroup_last_feed = $feed_id;
6afcbcd1 483
003a7447 484 $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>";
6afcbcd1 485
003a7447
AD
486 $feed_icon_src = Feeds::getFeedIcon($feed_id);
487 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"$feed_icon_src\">";
6afcbcd1 488
8359ca6d 489 $reply['content'] .= "<div data-feed-id='$feed_id' class='feed-title'>".
003a7447
AD
490 "<div style=\"float : right\">$feed_icon_img</div>".
491 "<a href=\"#\" class='title' onclick=\"viewfeed({feed:$feed_id})\">".
492 $line["feed_title"]."</a> $vf_catchup_link</div>";
6afcbcd1 493
003a7447
AD
494 }
495 }
84d952f1 496
b9585004 497 $content_encoded = htmlspecialchars($line["content"]);
c8c9a26f 498
9563e3bc 499 $tmp_content = "<div class=\"cdm expanded $hlc_suffix $class\"
c8c9a26f 500 id=\"RROW-$id\" data-content=\"$content_encoded\" data-article-id='$id' data-orig-feed-id='$feed_id' $mouseover_attrs>";
6afcbcd1 501
8359ca6d 502 $tmp_content .= "<div class=\"header\">";
003a7447 503 $tmp_content .= "<div style=\"vertical-align : middle\">";
6afcbcd1 504
003a7447 505 $tmp_content .= "<input dojoType=\"dijit.form.CheckBox\"
b5791f11
AD
506 type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"
507 class='rchk'>";
6afcbcd1 508
003a7447
AD
509 $tmp_content .= "$marked_pic";
510 $tmp_content .= "$published_pic";
6afcbcd1 511
003a7447 512 $tmp_content .= "</div>";
6afcbcd1 513
003a7447
AD
514 if ($highlight_words && count($highlight_words) > 0) {
515 foreach ($highlight_words as $word) {
0f051475
AD
516 $word = preg_quote($word, "/");
517
518 $line["title"] = preg_replace("/($word)/i",
003a7447
AD
519 "<span class=\"highlight\">$1</span>", $line["title"]);
520 }
521 }
6afcbcd1 522
003a7447 523 // data-article-id included for context menu
67cdf4cf 524 $tmp_content .= "<span
b5791f11
AD
525 onclick=\"return cdmClicked(event, $id);\"
526 data-article-id=\"$id\"
3a029230 527 class=\"titleWrap hlMenuAttach $hlc_suffix\">
b5791f11
AD
528 <a class=\"title $hlc_suffix\"
529 title=\"".htmlspecialchars($line["title"])."\"
530 target=\"_blank\" rel=\"noopener noreferrer\" href=\"".
003a7447
AD
531 htmlspecialchars($line["link"])."\">".
532 $line["title"] .
533 "</a> <span class=\"author\">$entry_author</span>";
ac4c1383 534
003a7447 535 $tmp_content .= $labels_str;
6afcbcd1 536
003a7447 537 $tmp_content .= "</span>";
6afcbcd1 538
003a7447
AD
539 if (!$vfeed_group_enabled) {
540 if (@$line["feed_title"]) {
541 $rgba = @$rgba_cache[$feed_id];
6afcbcd1 542
8359ca6d 543 $tmp_content .= "<div class=\"feed\">
b5791f11
AD
544 <a href=\"#\" style=\"background-color: rgba($rgba,0.3)\"
545 onclick=\"viewfeed({feed:$feed_id})\">".
003a7447 546 truncate_string($line["feed_title"],30)."</a>
b5791f11 547 </div>";
003a7447
AD
548 }
549 }
6afcbcd1 550
003a7447 551 $tmp_content .= "<span class='updated' title='$date_entered_fmt'>$updated_fmt</span>";
34dad844 552
8359ca6d 553 $tmp_content .= "<div style=\"vertical-align : middle\">";
003a7447 554 $tmp_content .= "$score_pic";
d56ec700 555
003a7447
AD
556 if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
557 $tmp_content .= "<span style=\"cursor : pointer\"
b5791f11
AD
558 title=\"".htmlspecialchars($line["feed_title"])."\"
559 onclick=\"viewfeed({feed:$feed_id})\">$feed_icon_img</span>";
003a7447 560 }
8359ca6d 561 $tmp_content .= "</div>"; //score wrapper2
e17e99fb 562
8359ca6d 563 $tmp_content .= "</div>"; //header
6afcbcd1 564
8359ca6d 565 $tmp_content .= "<div class=\"content\" onclick=\"return cdmClicked(event, $id, true);\">";
6afcbcd1 566
003a7447
AD
567 $tmp_content .= "<div id=\"POSTNOTE-$id\">";
568 if ($line['note']) {
569 $tmp_content .= Article::format_article_note($id, $line['note']);
570 }
571 $tmp_content .= "</div>"; //POSTNOTE
6afcbcd1 572
003a7447 573 if (!$line['lang']) $line['lang'] = 'en';
6afcbcd1 574
9563e3bc 575 // this is filled from RROW data-content
8359ca6d 576 $tmp_content .= "<div class=\"content-inner\" lang=\"".$line['lang']."\">";
b999f4c7 577
003a7447 578 if ($line["orig_feed_id"]) {
07eb3658 579
003a7447 580 $ofgh = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds
b5791f11 581 WHERE id = ? AND owner_uid = ?");
003a7447 582 $ofgh->execute([$line["orig_feed_id"], $_SESSION['uid']]);
6afcbcd1 583
003a7447 584 if ($tmp_line = $ofgh->fetch()) {
6afcbcd1 585
003a7447
AD
586 $tmp_content .= "<div clear='both'>";
587 $tmp_content .= __("Originally from:");
6afcbcd1 588
003a7447 589 $tmp_content .= "&nbsp;";
6afcbcd1 590
003a7447 591 $tmp_content .= "<a target='_blank' rel='noopener noreferrer'
b5791f11 592 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
003a7447 593 $tmp_line['title'] . "</a>";
6afcbcd1 594
003a7447 595 $tmp_content .= "&nbsp;";
6afcbcd1 596
003a7447
AD
597 $tmp_content .= "<a target='_blank' rel='noopener noreferrer' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
598 $tmp_content .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.png'></a>";
6afcbcd1 599
003a7447
AD
600 $tmp_content .= "</div>";
601 }
602 }
6afcbcd1 603
8359ca6d
AD
604 $tmp_content .= "</div>"; //content-inner
605 $tmp_content .= "<div class=\"intermediate\">";
6afcbcd1 606
003a7447
AD
607 $always_display_enclosures = $line["always_display_enclosures"];
608 $tmp_content .= Article::format_article_enclosures($id, $always_display_enclosures,
609 $line["content"], $line["hide_images"]);
6afcbcd1 610
003a7447 611 $tmp_content .= "</div>"; // cdmIntermediate
90da4ada 612
8359ca6d 613 $tmp_content .= "<div class=\"footer\" onclick=\"event.stopPropagation()\">";
90da4ada 614
003a7447
AD
615 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) {
616 $tmp_content .= $p->hook_article_left_button($line);
617 }
90da4ada 618
003a7447 619 $tags_str = Article::format_tags_string($tags, $id);
6afcbcd1 620
003a7447 621 $tmp_content .= "<span class='left'>";
ccb2b8dd 622
003a7447 623 $tmp_content .= "<img src='images/tag.png' alt='Tags' title='Tags'>
b5791f11
AD
624 <span id=\"ATSTR-$id\">$tags_str</span>
625 <a title=\"".__('Edit tags for this article')."\"
626 href=\"#\" onclick=\"editArticleTags($id)\">(+)</a>";
6afcbcd1 627
003a7447
AD
628 $num_comments = (int) $line["num_comments"];
629 $entry_comments = "";
bc20cb9f 630
003a7447
AD
631 if ($num_comments > 0) {
632 if ($line["comments"]) {
633 $comments_url = htmlspecialchars($line["comments"]);
634 } else {
635 $comments_url = htmlspecialchars($line["link"]);
636 }
07fd4f8d 637 $entry_comments = "<a class=\"comments\"
b5791f11 638 target='_blank' rel='noopener noreferrer' href=\"$comments_url\">$num_comments ".
003a7447 639 _ngettext("comment", "comments", $num_comments)."</a>";
6afcbcd1 640
003a7447
AD
641 } else {
642 if ($line["comments"] && $line["link"] != $line["comments"]) {
07fd4f8d 643 $entry_comments = "<a class=\"comments\" target='_blank' rel='noopener noreferrer' href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
003a7447
AD
644 }
645 }
6afcbcd1 646
003a7447 647 if ($entry_comments) $tmp_content .= "&nbsp;($entry_comments)";
ff04fe06 648
003a7447
AD
649 $tmp_content .= "</span>";
650 $tmp_content .= "<div>";
6afcbcd1 651
003a7447
AD
652 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) {
653 $tmp_content .= $p->hook_article_button($line);
654 }
6afcbcd1 655
003a7447 656 $tmp_content .= "</div>"; // buttons
6afcbcd1 657
8359ca6d 658 $tmp_content .= "</div>"; // cdm footer
003a7447
AD
659 $tmp_content .= "</div>"; // cdmContent
660 $tmp_content .= "</div>"; // RROW.cdm
035d7a5a 661
003a7447
AD
662 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE_CDM) as $p) {
663 $tmp_content = $p->hook_format_article_cdm($tmp_content, $line);
664 }
6afcbcd1 665
003a7447
AD
666 $reply['content'] .= $tmp_content;
667 }
6afcbcd1 668
003a7447
AD
669 ++$lnum;
670 }
b5791f11 671 }
6afcbcd1 672
b5791f11 673 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
6afcbcd1 674
b5791f11 675 if (!$headlines_count) {
6afcbcd1 676
b5791f11 677 if (!is_numeric($result)) {
6afcbcd1 678
b5791f11
AD
679 switch ($view_mode) {
680 case "unread":
681 $message = __("No unread articles found to display.");
682 break;
683 case "updated":
684 $message = __("No updated articles found to display.");
685 break;
686 case "marked":
687 $message = __("No starred articles found to display.");
688 break;
689 default:
690 if ($feed < LABEL_BASE_INDEX) {
691 $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.");
692 } else {
693 $message = __("No articles found to display.");
694 }
695 }
6afcbcd1 696
b5791f11
AD
697 if (!$offset && $message) {
698 $reply['content'] = "<div class='whiteBox'>$message";
6afcbcd1 699
b5791f11 700 $reply['content'] .= "<p><span class=\"insensitive\">";
6afcbcd1 701
b5791f11
AD
702 $sth = $this->pdo->prepare("SELECT " . SUBSTRING_FOR_DATE . "(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
703 WHERE owner_uid = ?");
704 $sth->execute([$_SESSION['uid']]);
705 $row = $sth->fetch();
6afcbcd1 706
b5791f11 707 $last_updated = make_local_datetime($row["last_updated"], false);
6afcbcd1 708
b5791f11 709 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
6afcbcd1 710
b5791f11
AD
711 $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors
712 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
713 $sth->execute([$_SESSION['uid']]);
714 $row = $sth->fetch();
6afcbcd1 715
b5791f11 716 $num_errors = $row["num_errors"];
6afcbcd1 717
b5791f11
AD
718 if ($num_errors > 0) {
719 $reply['content'] .= "<br/>";
720 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">" .
721 __('Some feeds have update errors (click for details)') . "</a>";
722 }
723 $reply['content'] .= "</span></p></div>";
9f5eca99 724
b5791f11
AD
725 }
726 } else if (is_numeric($result) && $result == -1) {
727 $reply['first_id_changed'] = true;
6afcbcd1
AD
728 }
729 }
730
731 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
732
733 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
734 $vgroup_last_feed, $reply);
735 }
736
737 function catchupAll() {
cc9450c3
AD
738 $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
739 last_read = NOW(), unread = false WHERE unread = true AND owner_uid = ?");
740 $sth->execute([$_SESSION['uid']]);
741
2ed0d6c4 742 CCache::zero_all($_SESSION["uid"]);
6afcbcd1
AD
743 }
744
6afcbcd1 745 function view() {
fa9e88c3 746 $timing_info = microtime(true);
6afcbcd1
AD
747
748 $reply = array();
749
750 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
751
c9b6ca8b
AD
752 $feed = $_REQUEST["feed"];
753 $method = $_REQUEST["m"];
754 $view_mode = $_REQUEST["view_mode"];
f17cac6b 755 $limit = 30;
6afcbcd1 756 @$cat_view = $_REQUEST["cat"] == "true";
c9b6ca8b
AD
757 @$next_unread_feed = $_REQUEST["nuf"];
758 @$offset = $_REQUEST["skip"];
759 @$vgroup_last_feed = $_REQUEST["vgrlf"];
760 $order_by = $_REQUEST["order_by"];
761 $check_first_id = $_REQUEST["fid"];
6afcbcd1
AD
762
763 if (is_numeric($feed)) $feed = (int) $feed;
764
765 /* Feed -5 is a special case: it is used to display auxiliary information
766 * when there's nothing to load - e.g. no stuff in fresh feed */
767
768 if ($feed == -5) {
6322ac79 769 print json_encode($this->generate_dashboard_feed());
6afcbcd1
AD
770 return;
771 }
772
cc9450c3 773 $sth = false;
f822a8e5 774 if ($feed < LABEL_BASE_INDEX) {
cc9450c3 775
7c9b5a3f 776 $label_feed = Labels::feed_to_label_id($feed);
cc9450c3
AD
777
778 $sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2 WHERE
779 id = ? AND owner_uid = ?");
780 $sth->execute([$label_feed, $_SESSION['uid']]);
781
6afcbcd1 782 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
cc9450c3
AD
783
784 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
785 id = ? AND owner_uid = ?");
786 $sth->execute([$feed, $_SESSION['uid']]);
787
6afcbcd1 788 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
cc9450c3
AD
789
790 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE
791 id = ? AND owner_uid = ?");
792
793 $sth->execute([$feed, $_SESSION['uid']]);
6afcbcd1
AD
794 }
795
cc9450c3 796 if ($sth && !$sth->fetch()) {
a42c55f0 797 print json_encode($this->generate_error_feed(__("Feed not found.")));
6afcbcd1
AD
798 return;
799 }
800
801 /* Updating a label ccache means recalculating all of the caches
802 * so for performance reasons we don't do that here */
803
804 if ($feed >= 0) {
2ed0d6c4 805 CCache::update($feed, $_SESSION["uid"], $cat_view);
6afcbcd1
AD
806 }
807
a42c55f0
AD
808 set_pref("_DEFAULT_VIEW_MODE", $view_mode);
809 set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by);
6afcbcd1 810
06b0777f
AD
811 /* bump login timestamp if needed */
812 if (time() - $_SESSION["last_login_update"] > 3600) {
cc9450c3
AD
813 $sth = $this->pdo->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?");
814 $sth->execute([$_SESSION['uid']]);
815
06b0777f
AD
816 $_SESSION["last_login_update"] = time();
817 }
818
6afcbcd1 819 if (!$cat_view && is_numeric($feed) && $feed > 0) {
cc9450c3
AD
820 $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET last_viewed = NOW()
821 WHERE id = ? AND owner_uid = ?");
822 $sth->execute([$feed, $_SESSION['uid']]);
6afcbcd1
AD
823 }
824
825 $reply['headlines'] = array();
826
6afcbcd1 827 $override_order = false;
19e47ad6 828 $skip_first_id_check = false;
6afcbcd1 829
6afcbcd1 830 switch ($order_by) {
f3b2e7d4 831 case "title":
81d96c0d 832 $override_order = "ttrss_entries.title, date_entered, updated";
f3b2e7d4
AD
833 break;
834 case "date_reverse":
e9687f67 835 $override_order = "score DESC, date_entered, updated";
19e47ad6 836 $skip_first_id_check = true;
f3b2e7d4
AD
837 break;
838 case "feed_dates":
839 $override_order = "updated DESC";
840 break;
6afcbcd1
AD
841 }
842
843 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
844
845 $ret = $this->format_headlines_list($feed, $method,
7b55001e 846 $view_mode, $limit, $cat_view, $offset,
19e47ad6 847 $vgroup_last_feed, $override_order, true, $check_first_id, $skip_first_id_check);
6afcbcd1 848
b389aeb7 849 //$topmost_article_ids = $ret[0];
6afcbcd1 850 $headlines_count = $ret[1];
4a80c57c 851 /* $returned_feed = $ret[2]; */
6afcbcd1
AD
852 $disable_cache = $ret[3];
853 $vgroup_last_feed = $ret[4];
854
34440201
AD
855 //$reply['headlines']['content'] =& $ret[5]['content'];
856 //$reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
857
1bd552ee 858 $reply['headlines'] = $ret[5];
34440201
AD
859
860 if (!$next_unread_feed)
861 $reply['headlines']['id'] = $feed;
862 else
863 $reply['headlines']['id'] = $next_unread_feed;
864
865 $reply['headlines']['is_cat'] = (bool) $cat_view;
6afcbcd1
AD
866
867 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
868
869 $reply['headlines-info'] = array("count" => (int) $headlines_count,
870 "vgroup_last_feed" => $vgroup_last_feed,
871 "disable_cache" => (bool) $disable_cache);
872
6afcbcd1
AD
873 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
874
6322ac79 875 $reply['runtime-info'] = make_runtime_info();
6afcbcd1
AD
876
877 print json_encode($reply);
878
879 }
880
6322ac79 881 private function generate_dashboard_feed() {
6afcbcd1
AD
882 $reply = array();
883
884 $reply['headlines']['id'] = -5;
885 $reply['headlines']['is_cat'] = false;
886
887 $reply['headlines']['toolbar'] = '';
6afcbcd1 888
f1706996 889 $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.');
6b954c0a 890
f1706996 891 $reply['headlines']['content'] .= "<p><span class=\"insensitive\">";
6afcbcd1 892
cc9450c3
AD
893 $sth = $this->pdo->prepare("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
894 WHERE owner_uid = ?");
895 $sth->execute([$_SESSION['uid']]);
896 $row = $sth->fetch();
6afcbcd1 897
cc9450c3 898 $last_updated = make_local_datetime($row["last_updated"], false);
6afcbcd1 899
f1706996 900 $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
6afcbcd1 901
cc9450c3
AD
902 $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors
903 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
904 $sth->execute([$_SESSION['uid']]);
905 $row = $sth->fetch();
6afcbcd1 906
cc9450c3 907 $num_errors = $row["num_errors"];
6afcbcd1
AD
908
909 if ($num_errors > 0) {
f1706996
AD
910 $reply['headlines']['content'] .= "<br/>";
911 $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
6afcbcd1
AD
912 __('Some feeds have update errors (click for details)')."</a>";
913 }
f1706996 914 $reply['headlines']['content'] .= "</span></p>";
6afcbcd1
AD
915
916 $reply['headlines-info'] = array("count" => 0,
917 "vgroup_last_feed" => '',
918 "unread" => 0,
919 "disable_cache" => true);
920
921 return $reply;
922 }
923
a42c55f0 924 private function generate_error_feed($error) {
6afcbcd1
AD
925 $reply = array();
926
33c4bd89 927 $reply['headlines']['id'] = -7;
6afcbcd1
AD
928 $reply['headlines']['is_cat'] = false;
929
930 $reply['headlines']['toolbar'] = '';
931 $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>";
932
933 $reply['headlines-info'] = array("count" => 0,
934 "vgroup_last_feed" => '',
935 "unread" => 0,
936 "disable_cache" => true);
937
938 return $reply;
939 }
940
1c9bda91 941 function quickAddFeed() {
ef1feb36
AD
942 print "<form onsubmit='return false'>";
943
328118d1
AD
944 print_hidden("op", "rpc");
945 print_hidden("method", "addfeed");
1c9bda91 946
24c7e413
AD
947 print "<div id='fadd_error_message' style='display : none' class='alert alert-danger'></div>";
948
8f7a020e
AD
949 print "<div id='fadd_multiple_notify' style='display : none'>";
950 print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below.");
951 print "<p></div>";
952
1c9bda91
AD
953 print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>";
954 print "<div class=\"dlgSecCont\">";
955
956 print "<div style='float : right'>
957 <img style='display : none'
958 id='feed_add_spinner' src='images/indicator_white.gif'></div>";
959
960 print "<input style=\"font-size : 16px; width : 20em;\"
961 placeHolder=\"".__("Feed or site URL")."\"
962 dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">";
963
964 print "<hr/>";
965
a42c55f0 966 if (get_pref('ENABLE_FEED_CATS')) {
1c9bda91 967 print __('Place in category:') . " ";
a42c55f0 968 print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"');
1c9bda91
AD
969 }
970
971 print "</div>";
972
973 print '<div id="feedDlg_feedsContainer" style="display : none">
974
975 <div class="dlgSec">' . __('Available feeds') . '</div>
976 <div class="dlgSecCont">'.
977 '<select id="feedDlg_feedContainerSelect"
978 dojoType="dijit.form.Select" size="3">
979 <script type="dojo/method" event="onChange" args="value">
980 dijit.byId("feedDlg_feedUrl").attr("value", value);
981 </script>
982 </select>'.
983 '</div></div>';
984
985 print "<div id='feedDlg_loginContainer' style='display : none'>
986
987 <div class=\"dlgSec\">".__("Authentication")."</div>
988 <div class=\"dlgSecCont\">".
989
990 " <input dojoType=\"dijit.form.TextBox\" name='login'\"
991 placeHolder=\"".__("Login")."\"
c9a5903b 992 autocomplete=\"new-password\"
1c9bda91
AD
993 style=\"width : 10em;\"> ".
994 " <input
995 placeHolder=\"".__("Password")."\"
996 dojoType=\"dijit.form.TextBox\" type='password'
c9a5903b 997 autocomplete=\"new-password\"
1c9bda91
AD
998 style=\"width : 10em;\" name='pass'\">
999 </div></div>";
1000
1001
1002 print "<div style=\"clear : both\">
1003 <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
1004 onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
1005 <label for=\"feedDlg_loginCheck\">".
1006 __('This feed requires authentication.')."</div>";
1007
1c9bda91 1008 print "<div class=\"dlgButtons\">
ef1feb36 1009 <button dojoType=\"dijit.form.Button\" class=\"btn-primary\" type=\"submit\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>";
1c9bda91
AD
1010
1011 if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER)) {
1012 print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>";
1013 }
1014
1015 print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>
1016 </div>";
1017
ef1feb36
AD
1018 print "</form>";
1019
1c9bda91
AD
1020 //return;
1021 }
1022
1023 function feedBrowser() {
1024 if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
1025
c9b6ca8b 1026 $browser_search = $_REQUEST["search"];
1c9bda91 1027
328118d1
AD
1028 print_hidden("op", "rpc");
1029 print_hidden("method", "updateFeedBrowser");
1c9bda91
AD
1030
1031 print "<div dojoType=\"dijit.Toolbar\">
1032 <div style='float : right'>
1033 <img style='display : none'
1034 id='feed_browser_spinner' src='images/indicator_white.gif'>
1035 <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\"
1036 onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\">
1037 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button>
1038 </div>";
1039
1040 print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\">
1041 <option value='1'>" . __('Popular feeds') . "</option>
1042 <option value='2'>" . __('Feed archive') . "</option>
1043 </select> ";
1044
1045 print __("limit:");
1046
1047 print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">";
1048
1049 foreach (array(25, 50, 100, 200) as $l) {
4a80c57c
AD
1050 //$issel = ($l == $limit) ? "selected=\"1\"" : "";
1051 print "<option value=\"$l\">$l</option>";
1c9bda91
AD
1052 }
1053
1054 print "</select> ";
1055
1056 print "</div>";
1057
1c9bda91
AD
1058 require_once "feedbrowser.php";
1059
1060 print "<ul class='browseFeedList' id='browseFeedList'>";
4a80c57c 1061 print make_feed_browser("", 25);
1c9bda91
AD
1062 print "</ul>";
1063
1064 print "<div align='center'>
1065 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button>
1066 <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button>
1067 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>";
1068
1069 }
1070
1071 function search() {
c9b6ca8b 1072 $this->params = explode(":", $_REQUEST["param"], 2);
1c9bda91
AD
1073
1074 $active_feed_id = sprintf("%d", $this->params[0]);
1075 $is_cat = $this->params[1] != "false";
1076
320a3ba5
AD
1077 print "<form onsubmit='return false;'>";
1078
1c9bda91
AD
1079 print "<div class=\"dlgSec\">".__('Look for')."</div>";
1080
1081 print "<div class=\"dlgSecCont\">";
1082
1083 print "<input dojoType=\"dijit.form.ValidationTextBox\"
1084 style=\"font-size : 16px; width : 20em;\"
1085 required=\"1\" name=\"query\" type=\"search\" value=''>";
1086
86a8351c 1087 print "<hr/><span style='float : right'>".T_sprintf('in %s', $this->getFeedTitle($active_feed_id, $is_cat))."</span>";
1c9bda91 1088
60e68059
AD
1089 if (DB_TYPE == "pgsql") {
1090 print "<hr/>";
1091 print_select("search_language", "", Pref_Feeds::$feed_languages,
1092 "dojoType='dijit.form.Select' title=\"".__('Used for word stemming')."\"");
1093 }
1094
1c9bda91
AD
1095 print "</div>";
1096
1097 print "<div class=\"dlgButtons\">";
1098
baaf4c30 1099 if (count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0) {
1c9bda91 1100 print "<div style=\"float : left\">
19ab8096 1101 <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">".__("Search syntax")."</a>
1c9bda91
AD
1102 </div>";
1103 }
1104
6fb5ce5e 1105 print "<button dojoType=\"dijit.form.Button\" type=\"submit\" class=\"btn-primary\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button>
1c9bda91
AD
1106 <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>
1107 </div>";
320a3ba5
AD
1108
1109 print "</form>";
1c9bda91
AD
1110 }
1111
86b05f86
AD
1112 function update_debugger() {
1113 header("Content-type: text/html");
1114
c10a4306
AD
1115 Debug::set_enabled(true);
1116 Debug::set_loglevel($_REQUEST["xdebug"]);
1117
86b05f86
AD
1118 $feed_id = (int)$_REQUEST["feed_id"];
1119 @$do_update = $_REQUEST["action"] == "do_update";
1120 $csrf_token = $_REQUEST["csrf_token"];
1121
1f16f9b8
AD
1122 $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?");
1123 $sth->execute([$feed_id, $_SESSION['uid']]);
1124
1125 if (!$sth->fetch()) {
1126 print "Access denied.";
1127 return;
1128 }
1129
86b05f86
AD
1130 $refetch_checked = isset($_REQUEST["force_refetch"]) ? "checked" : "";
1131 $rehash_checked = isset($_REQUEST["force_rehash"]) ? "checked" : "";
1132
1133 ?>
1134 <html>
1135 <head>
09bc54c6 1136 <?php echo stylesheet_tag("css/default.css") ?>
86b05f86
AD
1137 <title>Feed Debugger</title>
1138 </head>
09bc54c6 1139 <body class="small_margins ttrss_utility claro">
86a8351c 1140 <h1>Feed Debugger: <?php echo "$feed_id: " . $this->getFeedTitle($feed_id) ?></h1>
86b05f86
AD
1141 <form method="GET" action="">
1142 <input type="hidden" name="op" value="feeds">
1143 <input type="hidden" name="method" value="update_debugger">
1144 <input type="hidden" name="xdebug" value="1">
1145 <input type="hidden" name="csrf_token" value="<?php echo $csrf_token ?>">
1146 <input type="hidden" name="action" value="do_update">
1147 <input type="hidden" name="feed_id" value="<?php echo $feed_id ?>">
1148 <input type="checkbox" name="force_refetch" value="1" <?php echo $refetch_checked ?>> Force refetch<br/>
1149 <input type="checkbox" name="force_rehash" value="1" <?php echo $rehash_checked ?>> Force rehash<br/>
1150
1151 <p/><button type="submit">Continue</button>
1152 </form>
1153
1154 <hr>
1155
1156 <pre><?php
1157
1158 if ($do_update) {
e6c886bf 1159 RSSUtils::update_rss_feed($feed_id, true);
86b05f86
AD
1160 }
1161
1162 ?></pre>
1c9bda91 1163
86b05f86
AD
1164 </body>
1165 </html>
1166 <?php
1167
1168 }
4122da02 1169
86a8351c
AD
1170 static function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) {
1171
1172 if (!$owner_uid) $owner_uid = $_SESSION['uid'];
1173
cc9450c3
AD
1174 $pdo = Db::pdo();
1175
86a8351c
AD
1176 // Todo: all this interval stuff needs some generic generator function
1177
86a8351c
AD
1178 $search_qpart = is_array($search) && $search[0] ? search_to_sql($search[0], $search[1])[0] : 'true';
1179
1180 switch ($mode) {
1181 case "1day":
1182 if (DB_TYPE == "pgsql") {
1183 $date_qpart = "date_entered < NOW() - INTERVAL '1 day' ";
1184 } else {
1185 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) ";
1186 }
1187 break;
1188 case "1week":
1189 if (DB_TYPE == "pgsql") {
1190 $date_qpart = "date_entered < NOW() - INTERVAL '1 week' ";
1191 } else {
1192 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) ";
1193 }
1194 break;
1195 case "2week":
1196 if (DB_TYPE == "pgsql") {
1197 $date_qpart = "date_entered < NOW() - INTERVAL '2 week' ";
1198 } else {
1199 $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) ";
1200 }
1201 break;
1202 default:
1203 $date_qpart = "true";
1204 }
1205
1206 if (is_numeric($feed)) {
1207 if ($cat_view) {
1208
1209 if ($feed >= 0) {
1210
1211 if ($feed > 0) {
aeb1abed 1212 $children = Feeds::getChildCategories($feed, $owner_uid);
86a8351c 1213 array_push($children, $feed);
bed2d6e0 1214 $children = array_map("intval", $children);
86a8351c
AD
1215
1216 $children = join(",", $children);
1217
1218 $cat_qpart = "cat_id IN ($children)";
1219 } else {
1220 $cat_qpart = "cat_id IS NULL";
1221 }
1222
cc9450c3 1223 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1224 SET unread = false, last_read = NOW() WHERE ref_id IN
1225 (SELECT id FROM
1226 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
cc9450c3 1227 AND owner_uid = ? AND unread = true AND feed_id IN
86a8351c 1228 (SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart AND $search_qpart) as tmp)");
cc9450c3 1229 $sth->execute([$owner_uid]);
86a8351c
AD
1230
1231 } else if ($feed == -2) {
1232
cc9450c3 1233 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1234 SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*)
1235 FROM ttrss_user_labels2, ttrss_entries WHERE article_id = ref_id AND id = ref_id AND $date_qpart AND $search_qpart) > 0
cc9450c3
AD
1236 AND unread = true AND owner_uid = ?");
1237 $sth->execute([$owner_uid]);
86a8351c
AD
1238 }
1239
1240 } else if ($feed > 0) {
1241
cc9450c3 1242 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1243 SET unread = false, last_read = NOW() WHERE ref_id IN
1244 (SELECT id FROM
1245 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
cc9450c3
AD
1246 AND owner_uid = ? AND unread = true AND feed_id = ? AND $date_qpart AND $search_qpart) as tmp)");
1247 $sth->execute([$owner_uid, $feed]);
86a8351c
AD
1248
1249 } else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred
1250
1251 if ($feed == -1) {
cc9450c3 1252 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1253 SET unread = false, last_read = NOW() WHERE ref_id IN
1254 (SELECT id FROM
1255 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
cc9450c3
AD
1256 AND owner_uid = ? AND unread = true AND marked = true AND $date_qpart AND $search_qpart) as tmp)");
1257 $sth->execute([$owner_uid]);
86a8351c
AD
1258 }
1259
1260 if ($feed == -2) {
cc9450c3 1261 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1262 SET unread = false, last_read = NOW() WHERE ref_id IN
1263 (SELECT id FROM
1264 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
cc9450c3
AD
1265 AND owner_uid = ? AND unread = true AND published = true AND $date_qpart AND $search_qpart) as tmp)");
1266 $sth->execute([$owner_uid]);
86a8351c
AD
1267 }
1268
1269 if ($feed == -3) {
1270
cc9450c3 1271 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE");
86a8351c
AD
1272
1273 if (DB_TYPE == "pgsql") {
1274 $match_part = "date_entered > NOW() - INTERVAL '$intl hour' ";
1275 } else {
1276 $match_part = "date_entered > DATE_SUB(NOW(),
1277 INTERVAL $intl HOUR) ";
1278 }
1279
cc9450c3 1280 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1281 SET unread = false, last_read = NOW() WHERE ref_id IN
1282 (SELECT id FROM
1283 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
cc9450c3
AD
1284 AND owner_uid = ? AND score >= 0 AND unread = true AND $date_qpart AND $match_part AND $search_qpart) as tmp)");
1285 $sth->execute([$owner_uid]);
86a8351c
AD
1286 }
1287
1288 if ($feed == -4) {
cc9450c3 1289 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1290 SET unread = false, last_read = NOW() WHERE ref_id IN
1291 (SELECT id FROM
1292 (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id
cc9450c3
AD
1293 AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
1294 $sth->execute([$owner_uid]);
86a8351c
AD
1295 }
1296
1297 } else if ($feed < LABEL_BASE_INDEX) { // label
1298
7c9b5a3f 1299 $label_id = Labels::feed_to_label_id($feed);
86a8351c 1300
cc9450c3 1301 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1302 SET unread = false, last_read = NOW() WHERE ref_id IN
1303 (SELECT id FROM
1304 (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_user_labels2 WHERE ref_id = id
cc9450c3
AD
1305 AND label_id = ? AND ref_id = article_id
1306 AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
1307 $sth->execute([$label_id, $owner_uid]);
86a8351c
AD
1308
1309 }
1310
2ed0d6c4 1311 CCache::update($feed, $owner_uid, $cat_view);
86a8351c
AD
1312
1313 } else { // tag
cc9450c3 1314 $sth = $pdo->prepare("UPDATE ttrss_user_entries
86a8351c
AD
1315 SET unread = false, last_read = NOW() WHERE ref_id IN
1316 (SELECT id FROM
1317 (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_tags WHERE ref_id = ttrss_entries.id
cc9450c3
AD
1318 AND post_int_id = int_id AND tag_name = ?
1319 AND ttrss_user_entries.owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)");
1320 $sth->execute([$feed, $owner_uid]);
86a8351c
AD
1321
1322 }
1323 }
1324
1325 static function getFeedArticles($feed, $is_cat = false, $unread_only = false,
1326 $owner_uid = false) {
1327
1328 $n_feed = (int) $feed;
1329 $need_entries = false;
1330
29f1908e
AD
1331 $pdo = Db::pdo();
1332
86a8351c
AD
1333 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1334
1335 if ($unread_only) {
1336 $unread_qpart = "unread = true";
1337 } else {
1338 $unread_qpart = "true";
1339 }
1340
29f1908e
AD
1341 $match_part = "";
1342
86a8351c
AD
1343 if ($is_cat) {
1344 return Feeds::getCategoryUnread($n_feed, $owner_uid);
1345 } else if ($n_feed == -6) {
1346 return 0;
1347 } else if ($feed != "0" && $n_feed == 0) {
1348
29f1908e 1349 $sth = $pdo->prepare("SELECT SUM((SELECT COUNT(int_id)
86a8351c
AD
1350 FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id
1351 AND ref_id = id AND $unread_qpart)) AS count FROM ttrss_tags
29f1908e
AD
1352 WHERE owner_uid = ? AND tag_name = ?");
1353
1354 $sth->execute([$owner_uid, $feed]);
1355 $row = $sth->fetch();
1356
1357 return $row["count"];
86a8351c
AD
1358
1359 } else if ($n_feed == -1) {
1360 $match_part = "marked = true";
1361 } else if ($n_feed == -2) {
1362 $match_part = "published = true";
1363 } else if ($n_feed == -3) {
1364 $match_part = "unread = true AND score >= 0";
1365
29f1908e 1366 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
86a8351c
AD
1367
1368 if (DB_TYPE == "pgsql") {
1369 $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
1370 } else {
1371 $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
1372 }
1373
1374 $need_entries = true;
1375
1376 } else if ($n_feed == -4) {
1377 $match_part = "true";
1378 } else if ($n_feed >= 0) {
1379
1380 if ($n_feed != 0) {
bed2d6e0 1381 $match_part = "feed_id = " . (int)$n_feed;
86a8351c
AD
1382 } else {
1383 $match_part = "feed_id IS NULL";
1384 }
1385
1386 } else if ($feed < LABEL_BASE_INDEX) {
1387
7c9b5a3f 1388 $label_id = Labels::feed_to_label_id($feed);
86a8351c 1389
a230bf88 1390 return Feeds::getLabelUnread($label_id, $owner_uid);
86a8351c
AD
1391 }
1392
1393 if ($match_part) {
1394
1395 if ($need_entries) {
1396 $from_qpart = "ttrss_user_entries,ttrss_entries";
1397 $from_where = "ttrss_entries.id = ttrss_user_entries.ref_id AND";
1398 } else {
1399 $from_qpart = "ttrss_user_entries";
1400 $from_where = "";
1401 }
1402
29f1908e 1403 $sth = $pdo->prepare("SELECT count(int_id) AS unread
86a8351c 1404 FROM $from_qpart WHERE
29f1908e
AD
1405 $unread_qpart AND $from_where ($match_part) AND ttrss_user_entries.owner_uid = ?");
1406 $sth->execute([$owner_uid]);
1407 $row = $sth->fetch();
86a8351c 1408
29f1908e 1409 return $row["unread"];
86a8351c
AD
1410
1411 } else {
1412
29f1908e 1413 $sth = $pdo->prepare("SELECT COUNT(post_int_id) AS unread
86a8351c 1414 FROM ttrss_tags,ttrss_user_entries,ttrss_entries
29f1908e
AD
1415 WHERE tag_name = ? AND post_int_id = int_id AND ref_id = ttrss_entries.id
1416 AND $unread_qpart AND ttrss_tags.owner_uid = ,");
86a8351c 1417
29f1908e
AD
1418 $sth->execute([$feed, $owner_uid]);
1419 $row = $sth->fetch();
86a8351c 1420
29f1908e
AD
1421 return $row["unread"];
1422 }
86a8351c
AD
1423 }
1424
1425 /**
1426 * @return array (code => Status code, message => error message if available)
1427 *
1428 * 0 - OK, Feed already exists
1429 * 1 - OK, Feed added
1430 * 2 - Invalid URL
1431 * 3 - URL content is HTML, no feeds available
1432 * 4 - URL content is HTML which contains multiple feeds.
1433 * Here you should call extractfeedurls in rpc-backend
1434 * to get all possible feeds.
1435 * 5 - Couldn't download the URL content.
1436 * 6 - Content is an invalid XML.
1437 */
1438 static function subscribe_to_feed($url, $cat_id = 0,
1439 $auth_login = '', $auth_pass = '') {
1440
1441 global $fetch_last_error;
1442 global $fetch_last_error_content;
1443
29f1908e
AD
1444 $pdo = Db::pdo();
1445
86a8351c
AD
1446 $url = fix_url($url);
1447
1448 if (!$url || !validate_feed_url($url)) return array("code" => 2);
1449
1450 $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
1451
5d95676e
M
1452 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SUBSCRIBE_FEED) as $plugin) {
1453 $contents = $plugin->hook_subscribe_feed($contents, $url, $auth_login, $auth_pass);
1454 }
3a029230 1455
86a8351c
AD
1456 if (!$contents) {
1457 if (preg_match("/cloudflare\.com/", $fetch_last_error_content)) {
1458 $fetch_last_error .= " (feed behind Cloudflare)";
1459 }
1460
1461 return array("code" => 5, "message" => $fetch_last_error);
1462 }
1463
86a8351c
AD
1464 if (is_html($contents)) {
1465 $feedUrls = get_feeds_from_html($url, $contents);
1466
1467 if (count($feedUrls) == 0) {
1468 return array("code" => 3);
1469 } else if (count($feedUrls) > 1) {
1470 return array("code" => 4, "feeds" => $feedUrls);
1471 }
1472 //use feed url as new URL
1473 $url = key($feedUrls);
1474 }
1475
7c6f7bb0 1476 if (!$cat_id) $cat_id = null;
86a8351c 1477
29f1908e
AD
1478 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
1479 WHERE feed_url = ? AND owner_uid = ?");
1480 $sth->execute([$url, $_SESSION['uid']]);
86a8351c 1481
29f1908e
AD
1482 if ($row = $sth->fetch()) {
1483 return array("code" => 0, "feed_id" => (int) $row["id"]);
1484 } else {
1485 $sth = $pdo->prepare(
86a8351c
AD
1486 "INSERT INTO ttrss_feeds
1487 (owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method,auth_pass_encrypted)
29f1908e 1488 VALUES (?, ?, ?, ?, ?, ?, 0, false)");
86a8351c 1489
c30f5e18 1490 $sth->execute([$_SESSION['uid'], $url, "[Unknown]", $cat_id, (string)$auth_login, (string)$auth_pass]);
86a8351c 1491
29f1908e
AD
1492 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ?
1493 AND owner_uid = ?");
1494 $sth->execute([$url, $_SESSION['uid']]);
1495 $row = $sth->fetch();
1496
1497 $feed_id = $row["id"];
86a8351c
AD
1498
1499 if ($feed_id) {
e6c886bf 1500 RSSUtils::set_basic_feed_info($feed_id);
86a8351c
AD
1501 }
1502
1503 return array("code" => 1, "feed_id" => (int) $feed_id);
29f1908e 1504
86a8351c
AD
1505 }
1506 }
1507
5f5b0de4
AD
1508 static function getIconFile($feed_id) {
1509 return ICONS_DIR . "/$feed_id.ico";
1510 }
1511
fa3bcfa3
AD
1512 static function feedHasIcon($id) {
1513 return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
1514 }
1515
86a8351c
AD
1516 static function getFeedIcon($id) {
1517 switch ($id) {
1518 case 0:
1519 return "images/archive.png";
1520 break;
1521 case -1:
1522 return "images/star.png";
1523 break;
1524 case -2:
1525 return "images/feed.png";
1526 break;
1527 case -3:
1528 return "images/fresh.png";
1529 break;
1530 case -4:
1531 return "images/folder.png";
1532 break;
1533 case -6:
1534 return "images/time.png";
1535 break;
1536 default:
1537 if ($id < LABEL_BASE_INDEX) {
1538 return "images/label.png";
1539 } else {
5f5b0de4
AD
1540 $icon = self::getIconFile($id);
1541
1542 if ($icon && file_exists($icon)) {
1543 return ICONS_URL . "/" . basename($icon) . "?" . filemtime($icon);
1544 }
86a8351c
AD
1545 }
1546 break;
1547 }
1548
1549 return false;
1550 }
1551
1552 static function getFeedTitle($id, $cat = false) {
cc9450c3
AD
1553 $pdo = Db::pdo();
1554
86a8351c 1555 if ($cat) {
a230bf88 1556 return Feeds::getCategoryTitle($id);
86a8351c
AD
1557 } else if ($id == -1) {
1558 return __("Starred articles");
1559 } else if ($id == -2) {
1560 return __("Published articles");
1561 } else if ($id == -3) {
1562 return __("Fresh articles");
1563 } else if ($id == -4) {
1564 return __("All articles");
1565 } else if ($id === 0 || $id === "0") {
1566 return __("Archived articles");
1567 } else if ($id == -6) {
1568 return __("Recently read");
1569 } else if ($id < LABEL_BASE_INDEX) {
cc9450c3 1570
7c9b5a3f 1571 $label_id = Labels::feed_to_label_id($id);
cc9450c3
AD
1572
1573 $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 WHERE id = ?");
1574 $sth->execute([$label_id]);
1575
1576 if ($row = $sth->fetch()) {
1577 return $row["caption"];
86a8351c
AD
1578 } else {
1579 return "Unknown label ($label_id)";
1580 }
1581
1582 } else if (is_numeric($id) && $id > 0) {
cc9450c3
AD
1583
1584 $sth = $pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?");
1585 $sth->execute([$id]);
1586
1587 if ($row = $sth->fetch()) {
1588 return $row["title"];
86a8351c
AD
1589 } else {
1590 return "Unknown feed ($id)";
1591 }
cc9450c3 1592
86a8351c
AD
1593 } else {
1594 return $id;
1595 }
1596 }
1597
1598 static function getCategoryUnread($cat, $owner_uid = false) {
1599
1600 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1601
29f1908e
AD
1602 $pdo = Db::pdo();
1603
86a8351c
AD
1604 if ($cat >= 0) {
1605
29f1908e
AD
1606 if (!$cat) $cat = null;
1607
1608 $sth = $pdo->prepare("SELECT id FROM ttrss_feeds
1609 WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL))
aee3f0e6 1610 AND owner_uid = :uid");
86a8351c 1611
29f1908e 1612 $sth->execute([":cat" => $cat, ":uid" => $owner_uid]);
86a8351c
AD
1613
1614 $cat_feeds = array();
29f1908e 1615 while ($line = $sth->fetch()) {
bed2d6e0 1616 array_push($cat_feeds, "feed_id = " . (int)$line["id"]);
86a8351c
AD
1617 }
1618
1619 if (count($cat_feeds) == 0) return 0;
1620
1621 $match_part = implode(" OR ", $cat_feeds);
1622
29f1908e 1623 $sth = $pdo->prepare("SELECT COUNT(int_id) AS unread
86a8351c
AD
1624 FROM ttrss_user_entries
1625 WHERE unread = true AND ($match_part)
29f1908e
AD
1626 AND owner_uid = ?");
1627 $sth->execute([$owner_uid]);
86a8351c
AD
1628
1629 $unread = 0;
1630
1631 # this needs to be rewritten
29f1908e 1632 while ($line = $sth->fetch()) {
86a8351c
AD
1633 $unread += $line["unread"];
1634 }
1635
1636 return $unread;
1637 } else if ($cat == -1) {
1638 return getFeedUnread(-1) + getFeedUnread(-2) + getFeedUnread(-3) + getFeedUnread(0);
1639 } else if ($cat == -2) {
1640
29f1908e 1641 $sth = $pdo->prepare("SELECT COUNT(unread) AS unread FROM
86a8351c
AD
1642 ttrss_user_entries, ttrss_user_labels2
1643 WHERE article_id = ref_id AND unread = true
29f1908e
AD
1644 AND ttrss_user_entries.owner_uid = ?");
1645 $sth->execute([$owner_uid]);
1646 $row = $sth->fetch();
86a8351c 1647
29f1908e 1648 return $row["unread"];
86a8351c
AD
1649 }
1650 }
1651
1652 // only accepts real cats (>= 0)
1653 static function getCategoryChildrenUnread($cat, $owner_uid = false) {
1654 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1655
29f1908e
AD
1656 $pdo = Db::pdo();
1657
1658 $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE parent_cat = ?
1659 AND owner_uid = ?");
1660 $sth->execute([$cat, $owner_uid]);
86a8351c
AD
1661
1662 $unread = 0;
1663
29f1908e 1664 while ($line = $sth->fetch()) {
86a8351c
AD
1665 $unread += Feeds::getCategoryUnread($line["id"], $owner_uid);
1666 $unread += Feeds::getCategoryChildrenUnread($line["id"], $owner_uid);
1667 }
1668
1669 return $unread;
1670 }
4122da02 1671
a230bf88
AD
1672 static function getGlobalUnread($user_id = false) {
1673
29f1908e 1674 if (!$user_id) $user_id = $_SESSION["uid"];
a230bf88 1675
29f1908e 1676 $pdo = Db::pdo();
a230bf88 1677
29f1908e
AD
1678 $sth = $pdo->prepare("SELECT SUM(value) AS c_id FROM ttrss_counters_cache
1679 WHERE owner_uid = ? AND feed_id > 0");
1680 $sth->execute([$user_id]);
1681 $row = $sth->fetch();
a230bf88 1682
29f1908e 1683 return $row["c_id"];
a230bf88
AD
1684 }
1685
1686 static function getCategoryTitle($cat_id) {
1687
1688 if ($cat_id == -1) {
1689 return __("Special");
1690 } else if ($cat_id == -2) {
1691 return __("Labels");
1692 } else {
1693
29f1908e
AD
1694 $pdo = Db::pdo();
1695
1696 $sth = $pdo->prepare("SELECT title FROM ttrss_feed_categories WHERE
1697 id = ?");
1698 $sth->execute([$cat_id]);
a230bf88 1699
29f1908e
AD
1700 if ($row = $sth->fetch()) {
1701 return $row["title"];
a230bf88
AD
1702 } else {
1703 return __("Uncategorized");
1704 }
1705 }
1706 }
1707
1708 static function getLabelUnread($label_id, $owner_uid = false) {
1709 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1710
29f1908e
AD
1711 $pdo = Db::pdo();
1712
1713 $sth = $pdo->prepare("SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2
1714 WHERE owner_uid = ? AND unread = true AND label_id = ? AND article_id = ref_id");
1715
1716 $sth->execute([$owner_uid, $label_id]);
a230bf88 1717
29f1908e
AD
1718 if ($row = $sth->fetch()) {
1719 return $row["unread"];
a230bf88
AD
1720 } else {
1721 return 0;
1722 }
1723 }
1724
aeb1abed
AD
1725 static function queryFeedHeadlines($params) {
1726
29f1908e
AD
1727 $pdo = Db::pdo();
1728
1729 // WARNING: due to highly dynamic nature of this query its going to quote parameters
1730 // right before adding them to SQL part
1731
aeb1abed
AD
1732 $feed = $params["feed"];
1733 $limit = isset($params["limit"]) ? $params["limit"] : 30;
1734 $view_mode = $params["view_mode"];
1735 $cat_view = isset($params["cat_view"]) ? $params["cat_view"] : false;
1736 $search = isset($params["search"]) ? $params["search"] : false;
1737 $search_language = isset($params["search_language"]) ? $params["search_language"] : "";
1738 $override_order = isset($params["override_order"]) ? $params["override_order"] : false;
1739 $offset = isset($params["offset"]) ? $params["offset"] : 0;
1740 $owner_uid = isset($params["owner_uid"]) ? $params["owner_uid"] : $_SESSION["uid"];
1741 $since_id = isset($params["since_id"]) ? $params["since_id"] : 0;
1742 $include_children = isset($params["include_children"]) ? $params["include_children"] : false;
1743 $ignore_vfeed_group = isset($params["ignore_vfeed_group"]) ? $params["ignore_vfeed_group"] : false;
1744 $override_strategy = isset($params["override_strategy"]) ? $params["override_strategy"] : false;
1745 $override_vfeed = isset($params["override_vfeed"]) ? $params["override_vfeed"] : false;
1746 $start_ts = isset($params["start_ts"]) ? $params["start_ts"] : false;
1747 $check_first_id = isset($params["check_first_id"]) ? $params["check_first_id"] : false;
1748 $skip_first_id_check = isset($params["skip_first_id_check"]) ? $params["skip_first_id_check"] : false;
1749
1750 $ext_tables_part = "";
29f1908e 1751 $limit_query_part = "";
aeb1abed
AD
1752
1753 $search_words = array();
1754
1755 if ($search) {
1756 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH) as $plugin) {
1757 list($search_query_part, $search_words) = $plugin->hook_search($search);
1758 break;
1759 }
1760
1761 // fall back in case of no plugins
1762 if (!$search_query_part) {
1763 list($search_query_part, $search_words) = search_to_sql($search, $search_language);
1764 }
1765 $search_query_part .= " AND ";
1766 } else {
1767 $search_query_part = "";
1768 }
1769
1770 if ($since_id) {
3623ebb1 1771 $since_id_part = "ttrss_entries.id > ".$pdo->quote($since_id)." AND ";
aeb1abed
AD
1772 } else {
1773 $since_id_part = "";
1774 }
1775
1776 $view_query_part = "";
1777
1778 if ($view_mode == "adaptive") {
1779 if ($search) {
1780 $view_query_part = " ";
1781 } else if ($feed != -1) {
1782
1783 $unread = getFeedUnread($feed, $cat_view);
1784
1785 if ($cat_view && $feed > 0 && $include_children)
1786 $unread += Feeds::getCategoryChildrenUnread($feed);
1787
1788 if ($unread > 0) {
1789 $view_query_part = " unread = true AND ";
1790 }
1791 }
1792 }
1793
1794 if ($view_mode == "marked") {
1795 $view_query_part = " marked = true AND ";
1796 }
1797
1798 if ($view_mode == "has_note") {
1799 $view_query_part = " (note IS NOT NULL AND note != '') AND ";
1800 }
1801
1802 if ($view_mode == "published") {
1803 $view_query_part = " published = true AND ";
1804 }
1805
1806 if ($view_mode == "unread" && $feed != -6) {
1807 $view_query_part = " unread = true AND ";
1808 }
1809
1810 if ($limit > 0) {
7fc303e6 1811 $limit_query_part = "LIMIT " . (int)$limit;
aeb1abed
AD
1812 }
1813
1814 $allow_archived = false;
1815
1816 $vfeed_query_part = "";
1817
1818 /* tags */
1819 if (!is_numeric($feed)) {
1820 $query_strategy_part = "true";
1821 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1822 id = feed_id) as feed_title,";
1823 } else if ($feed > 0) {
1824
1825 if ($cat_view) {
1826
1827 if ($feed > 0) {
1828 if ($include_children) {
1829 # sub-cats
1830 $subcats = Feeds::getChildCategories($feed, $owner_uid);
aeb1abed 1831 array_push($subcats, $feed);
bed2d6e0
AD
1832 $subcats = array_map("intval", $subcats);
1833
aeb1abed
AD
1834 $query_strategy_part = "cat_id IN (".
1835 implode(",", $subcats).")";
1836
1837 } else {
3623ebb1 1838 $query_strategy_part = "cat_id = " . $pdo->quote($feed);
aeb1abed
AD
1839 }
1840
1841 } else {
1842 $query_strategy_part = "cat_id IS NULL";
1843 }
1844
1845 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1846
1847 } else {
3623ebb1 1848 $query_strategy_part = "feed_id = " . $pdo->quote($feed);
aeb1abed
AD
1849 }
1850 } else if ($feed == 0 && !$cat_view) { // archive virtual feed
1851 $query_strategy_part = "feed_id IS NULL";
1852 $allow_archived = true;
1853 } else if ($feed == 0 && $cat_view) { // uncategorized
1854 $query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL";
1855 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1856 } else if ($feed == -1) { // starred virtual feed
1857 $query_strategy_part = "marked = true";
1858 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1859 $allow_archived = true;
1860
1861 if (!$override_order) {
1862 $override_order = "last_marked DESC, date_entered DESC, updated DESC";
1863 }
1864
1865 } else if ($feed == -2) { // published virtual feed OR labels category
1866
1867 if (!$cat_view) {
1868 $query_strategy_part = "published = true";
1869 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1870 $allow_archived = true;
1871
1872 if (!$override_order) {
1873 $override_order = "last_published DESC, date_entered DESC, updated DESC";
1874 }
1875
1876 } else {
1877 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1878
1879 $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,";
1880
1881 $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND
1882 ttrss_user_labels2.article_id = ref_id";
1883
1884 }
1885 } else if ($feed == -6) { // recently read
1886 $query_strategy_part = "unread = false AND last_read IS NOT NULL";
1887
1888 if (DB_TYPE == "pgsql") {
1889 $query_strategy_part .= " AND last_read > NOW() - INTERVAL '1 DAY' ";
1890 } else {
1891 $query_strategy_part .= " AND last_read > DATE_SUB(NOW(), INTERVAL 1 DAY) ";
1892 }
1893
1894 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1895 $allow_archived = true;
1896 $ignore_vfeed_group = true;
1897
1898 if (!$override_order) $override_order = "last_read DESC";
1899
1900 } else if ($feed == -3) { // fresh virtual feed
1901 $query_strategy_part = "unread = true AND score >= 0";
1902
3623ebb1 1903 $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid);
aeb1abed
AD
1904
1905 if (DB_TYPE == "pgsql") {
1906 $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' ";
1907 } else {
1908 $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
1909 }
1910
1911 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1912 } else if ($feed == -4) { // all articles virtual feed
1913 $allow_archived = true;
1914 $query_strategy_part = "true";
1915 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1916 } else if ($feed <= LABEL_BASE_INDEX) { // labels
7c9b5a3f 1917 $label_id = Labels::feed_to_label_id($feed);
aeb1abed 1918
3623ebb1 1919 $query_strategy_part = "label_id = ".$pdo->quote($label_id)." AND
aeb1abed
AD
1920 ttrss_labels2.id = ttrss_user_labels2.label_id AND
1921 ttrss_user_labels2.article_id = ref_id";
1922
1923 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1924 $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,";
1925 $allow_archived = true;
1926
1927 } else {
1928 $query_strategy_part = "true";
1929 }
1930
1931 $order_by = "score DESC, date_entered DESC, updated DESC";
1932
1933 if ($override_order) {
1934 $order_by = $override_order;
1935 }
1936
1937 if ($override_strategy) {
1938 $query_strategy_part = $override_strategy;
1939 }
1940
1941 if ($override_vfeed) {
1942 $vfeed_query_part = $override_vfeed;
1943 }
1944
aeb1abed
AD
1945 if ($search) {
1946 $feed_title = T_sprintf("Search results: %s", $search);
1947 } else {
1948 if ($cat_view) {
1949 $feed_title = Feeds::getCategoryTitle($feed);
1950 } else {
1951 if (is_numeric($feed) && $feed > 0) {
29f1908e
AD
1952 $ssth = $pdo->prepare("SELECT title,site_url,last_error,last_updated
1953 FROM ttrss_feeds WHERE id = ? AND owner_uid = ?");
1954 $ssth->execute([$feed, $owner_uid]);
1955 $row = $ssth->fetch();
1956
1957 $feed_title = $row["title"];
1958 $feed_site_url = $row["site_url"];
1959 $last_error = $row["last_error"];
1960 $last_updated = $row["last_updated"];
aeb1abed
AD
1961 } else {
1962 $feed_title = Feeds::getFeedTitle($feed);
1963 }
1964 }
1965 }
1966
aeb1abed
AD
1967 $content_query_part = "content, ";
1968
1969 if ($limit_query_part) {
7fc303e6 1970 $offset_query_part = "OFFSET " . (int)$offset;
aeb1abed
AD
1971 } else {
1972 $offset_query_part = "";
1973 }
1974
1975 if (is_numeric($feed)) {
1976 // proper override_order applied above
1977 if ($vfeed_query_part && !$ignore_vfeed_group && get_pref('VFEED_GROUP_BY_FEED', $owner_uid)) {
1978 if (!$override_order) {
fa3bcfa3 1979 $order_by = "ttrss_feeds.title, ".$order_by;
aeb1abed 1980 } else {
fa3bcfa3 1981 $order_by = "ttrss_feeds.title, ".$override_order;
aeb1abed
AD
1982 }
1983 }
1984
1985 if (!$allow_archived) {
1986 $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id),ttrss_feeds";
1987 $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
1988
1989 } else {
1990 $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id)
1991 LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)";
1992 }
1993
1994 if ($vfeed_query_part) $vfeed_query_part .= "favicon_avg_color,";
1995
1996 if ($start_ts) {
1997 $start_ts_formatted = date("Y/m/d H:i:s", strtotime($start_ts));
1998 $start_ts_query_part = "date_entered >= '$start_ts_formatted' AND";
1999 } else {
2000 $start_ts_query_part = "";
2001 }
2002
2003 $first_id = 0;
2004 $first_id_query_strategy_part = $query_strategy_part;
2005
2006 if ($feed == -3)
2007 $first_id_query_strategy_part = "true";
2008
2009 if (DB_TYPE == "pgsql") {
2010 $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND";
2011 } else {
2012 $sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND";
2013 }
2014
2015 if (!$search && !$skip_first_id_check) {
2016 // if previous topmost article id changed that means our current pagination is no longer valid
2017 $query = "SELECT DISTINCT
2018 ttrss_feeds.title,
2019 date_entered,
2020 guid,
2021 ttrss_entries.id,
2022 ttrss_entries.title,
2023 updated,
2024 score,
2025 marked,
2026 published,
2027 last_marked,
2028 last_published,
2029 last_read
2030 FROM
2031 $from_qpart
2032 WHERE
2033 $feed_check_qpart
3623ebb1 2034 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
aeb1abed
AD
2035 $search_query_part
2036 $start_ts_query_part
2037 $since_id_part
2038 $sanity_interval_qpart
2039 $first_id_query_strategy_part ORDER BY $order_by LIMIT 1";
2040
bed2d6e0 2041 /*if ($_REQUEST["debug"]) {
aeb1abed 2042 print $query;
bed2d6e0 2043 }*/
aeb1abed 2044
b5791f11 2045 $res = $pdo->query($query);
29f1908e 2046
b5791f11
AD
2047 if ($row = $res->fetch()) {
2048 $first_id = (int)$row["id"];
aeb1abed
AD
2049
2050 if ($offset > 0 && $first_id && $check_first_id && $first_id != $check_first_id) {
2051 return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id);
2052 }
2053 }
2054 }
2055
2056 $query = "SELECT DISTINCT
2057 date_entered,
2058 guid,
2059 ttrss_entries.id,ttrss_entries.title,
2060 updated,
2061 label_cache,
2062 tag_cache,
2063 always_display_enclosures,
2064 site_url,
2065 note,
2066 num_comments,
2067 comments,
2068 int_id,
2069 uuid,
2070 lang,
2071 hide_images,
2072 unread,feed_id,marked,published,link,last_read,orig_feed_id,
2073 last_marked, last_published,
2074 $vfeed_query_part
2075 $content_query_part
2076 author,score
2077 FROM
2078 $from_qpart
2079 WHERE
2080 $feed_check_qpart
3623ebb1 2081 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
aeb1abed
AD
2082 $search_query_part
2083 $start_ts_query_part
2084 $view_query_part
2085 $since_id_part
2086 $query_strategy_part ORDER BY $order_by
2087 $limit_query_part $offset_query_part";
2088
bed2d6e0 2089 //if ($_REQUEST["debug"]) print $query;
aeb1abed 2090
b5791f11 2091 $res = $pdo->query($query);
aeb1abed
AD
2092
2093 } else {
2094 // browsing by tag
2095
2096 $query = "SELECT DISTINCT
2097 date_entered,
2098 guid,
2099 note,
2100 ttrss_entries.id as id,
2101 title,
2102 updated,
2103 unread,
2104 feed_id,
2105 orig_feed_id,
2106 marked,
2107 num_comments,
2108 comments,
2109 int_id,
2110 tag_cache,
2111 label_cache,
2112 link,
2113 lang,
2114 uuid,
2115 last_read,
2116 (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) AS hide_images,
2117 last_marked, last_published,
2118 $since_id_part
2119 $vfeed_query_part
2120 $content_query_part
2121 author, score
2122 FROM ttrss_entries, ttrss_user_entries, ttrss_tags
2123 WHERE
2124 ref_id = ttrss_entries.id AND
3623ebb1 2125 ttrss_user_entries.owner_uid = ".$pdo->quote($owner_uid)." AND
aeb1abed 2126 post_int_id = int_id AND
3623ebb1 2127 tag_name = ".$pdo->quote($feed)." AND
aeb1abed
AD
2128 $view_query_part
2129 $search_query_part
2130 $query_strategy_part ORDER BY $order_by
2131 $limit_query_part $offset_query_part";
2132
2133 if ($_REQUEST["debug"]) print $query;
2134
b5791f11 2135 $res = $pdo->query($query);
aeb1abed
AD
2136 }
2137
b5791f11 2138 return array($res, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id);
aeb1abed
AD
2139
2140 }
2141
2142 static function getParentCategories($cat, $owner_uid) {
2143 $rv = array();
2144
b5791f11
AD
2145 $pdo = Db::pdo();
2146
2147 $sth = $pdo->prepare("SELECT parent_cat FROM ttrss_feed_categories
2148 WHERE id = ? AND parent_cat IS NOT NULL AND owner_uid = ?");
2149 $sth->execute([$cat, $owner_uid]);
aeb1abed 2150
b5791f11 2151 while ($line = $sth->fetch()) {
aeb1abed
AD
2152 array_push($rv, $line["parent_cat"]);
2153 $rv = array_merge($rv, Feeds::getParentCategories($line["parent_cat"], $owner_uid));
2154 }
2155
2156 return $rv;
2157 }
2158
2159 static function getChildCategories($cat, $owner_uid) {
2160 $rv = array();
2161
b5791f11
AD
2162 $pdo = Db::pdo();
2163
2164 $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories
2165 WHERE parent_cat = ? AND owner_uid = ?");
2166 $sth->execute([$cat, $owner_uid]);
aeb1abed 2167
b5791f11 2168 while ($line = $sth->fetch()) {
aeb1abed
AD
2169 array_push($rv, $line["id"]);
2170 $rv = array_merge($rv, Feeds::getChildCategories($line["id"], $owner_uid));
2171 }
2172
2173 return $rv;
2174 }
2175
0086a897 2176 static function getFeedCategory($feed) {
b5791f11 2177 $pdo = Db::pdo();
0086a897 2178
b5791f11
AD
2179 $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
2180 WHERE id = ?");
2181 $sth->execute([$feed]);
2182
2183 if ($row = $sth->fetch()) {
2184 return $row["cat_id"];
0086a897
AD
2185 } else {
2186 return false;
2187 }
2188
2189 }
2190
2191
6afcbcd1 2192}
86a8351c 2193