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