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