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