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