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