]>
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, |
9090b874 | 16 | $view_mode, $error, $feed_last_updated) { |
6afcbcd1 | 17 | |
6afcbcd1 AD |
18 | $catchup_sel_link = "catchupSelection()"; |
19 | ||
20 | $archive_sel_link = "archiveSelection()"; | |
21 | $delete_sel_link = "deleteSelection()"; | |
22 | ||
23 | $sel_all_link = "selectArticles('all')"; | |
24 | $sel_unread_link = "selectArticles('unread')"; | |
25 | $sel_none_link = "selectArticles('none')"; | |
26 | $sel_inv_link = "selectArticles('invert')"; | |
27 | ||
28 | $tog_unread_link = "selectionToggleUnread()"; | |
29 | $tog_marked_link = "selectionToggleMarked()"; | |
30 | $tog_published_link = "selectionTogglePublished()"; | |
31 | ||
32 | $set_score_link = "setSelectionScore()"; | |
33 | ||
34 | if ($is_cat) $cat_q = "&is_cat=$is_cat"; | |
35 | ||
36 | if ($search) { | |
9090b874 | 37 | $search_q = "&q=$search"; |
6afcbcd1 AD |
38 | } else { |
39 | $search_q = ""; | |
40 | } | |
41 | ||
1bffd106 AD |
42 | $reply .= "<span class=\"holder\">"; |
43 | ||
6afcbcd1 AD |
44 | $rss_link = htmlspecialchars(get_self_url_prefix() . |
45 | "/public.php?op=rss&id=$feed_id$cat_q$search_q"); | |
46 | ||
47 | // right part | |
48 | ||
1a545dcb AD |
49 | $error_class = $error ? "error" : ""; |
50 | ||
1bffd106 AD |
51 | $reply .= "<span class='r'> |
52 | <a href=\"#\" | |
53 | title=\"".__("View as RSS feed")."\" | |
54 | onclick=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\"> | |
55 | <img class=\"noborder\" src=\"images/pub_set.png\"></a>"; | |
56 | ||
57 | ||
58 | # $reply .= "<span>"; | |
1a545dcb | 59 | $reply .= "<span id='feed_title' class='$error_class'>"; |
6afcbcd1 AD |
60 | |
61 | if ($feed_site_url) { | |
6e3e8db9 AD |
62 | $last_updated = T_sprintf("Last updated: %s", |
63 | $feed_last_updated); | |
64 | ||
6afcbcd1 | 65 | $target = "target=\"_blank\""; |
6e3e8db9 | 66 | $reply .= "<a title=\"$last_updated\" $target href=\"$feed_site_url\">". |
878a0083 | 67 | truncate_string($feed_title, 30)."</a>"; |
6afcbcd1 AD |
68 | |
69 | if ($error) { | |
12d17734 | 70 | $error = htmlspecialchars($error); |
8993937d | 71 | $reply .= " <img title=\"$error\" src='images/error.png' alt='error' class=\"noborder\">"; |
6afcbcd1 AD |
72 | } |
73 | ||
74 | } else { | |
75 | $reply .= $feed_title; | |
76 | } | |
77 | ||
78 | $reply .= "</span>"; | |
79 | ||
66684d81 AD |
80 | $reply .= "</span>"; |
81 | ||
1bffd106 | 82 | # $reply .= "</span>"; |
6afcbcd1 AD |
83 | |
84 | // left part | |
85 | ||
1bffd106 | 86 | $reply .= "<span class=\"main\">"; |
4e2f219c | 87 | $reply .= "<span id='selected_prompt'></span>"; |
1bffd106 | 88 | |
6901ec66 | 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 | ||
6901ec66 | 95 | $reply .= "</span> "; |
6afcbcd1 AD |
96 | |
97 | $reply .= "<select dojoType=\"dijit.form.Select\" | |
98 | onchange=\"headlineActionsChange(this)\">"; | |
99 | $reply .= "<option value=\"false\">".__('More...')."</option>"; | |
100 | ||
101 | $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>"; | |
102 | ||
103 | $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option> | |
104 | <option value=\"$tog_marked_link\">".__('Starred')."</option> | |
105 | <option value=\"$tog_published_link\">".__('Published')."</option>"; | |
106 | ||
107 | $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>"; | |
108 | ||
109 | $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>"; | |
110 | $reply .= "<option value=\"$set_score_link\">".__('Set score')."</option>"; | |
111 | ||
112 | if ($feed_id != "0") { | |
113 | $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>"; | |
114 | } else { | |
115 | $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>"; | |
116 | $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>"; | |
117 | ||
118 | } | |
119 | ||
1ffe3391 | 120 | if (PluginHost::getInstance()->get_plugin("mail")) { |
6afcbcd1 AD |
121 | $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email'). |
122 | "</option>"; | |
123 | } | |
124 | ||
1ffe3391 | 125 | if (PluginHost::getInstance()->get_plugin("mailto")) { |
1d5cf085 AD |
126 | $reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email'). |
127 | "</option>"; | |
128 | } | |
129 | ||
6afcbcd1 AD |
130 | $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>"; |
131 | ||
3dd0306f | 132 | //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>"; |
6afcbcd1 | 133 | |
fb54e3b1 | 134 | $reply .= "<option value=\"displayDlg('".__("View as RSS")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>"; |
6afcbcd1 AD |
135 | |
136 | $reply .= "</select>"; | |
137 | ||
6afcbcd1 AD |
138 | //$reply .= "</h2"; |
139 | ||
1ffe3391 | 140 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON) as $p) { |
647a39dd | 141 | $reply .= $p->hook_headline_toolbar_button($feed_id, $is_cat); |
ceb78471 AD |
142 | } |
143 | ||
1bffd106 AD |
144 | $reply .= "</span></span>"; |
145 | ||
6afcbcd1 AD |
146 | return $reply; |
147 | } | |
148 | ||
149 | private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, | |
150 | $next_unread_feed, $offset, $vgr_last_feed = false, | |
19e47ad6 AD |
151 | $override_order = false, $include_children = false, $check_first_id = false, |
152 | $skip_first_id_check = false) { | |
6afcbcd1 | 153 | |
6afcbcd1 AD |
154 | $disable_cache = false; |
155 | ||
156 | $reply = array(); | |
157 | ||
e0deff39 AD |
158 | $rgba_cache = array(); |
159 | ||
fa9e88c3 | 160 | $timing_info = microtime(true); |
6afcbcd1 AD |
161 | |
162 | $topmost_article_ids = array(); | |
163 | ||
164 | if (!$offset) $offset = 0; | |
165 | if ($method == "undefined") $method = ""; | |
166 | ||
167 | $method_split = explode(":", $method); | |
168 | ||
41245888 | 169 | if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) { |
6afcbcd1 AD |
170 | // Update the feed if required with some basic flood control |
171 | ||
41245888 AD |
172 | $any_needs_curl = false; |
173 | ||
174 | if (ini_get("open_basedir")) { | |
175 | $pluginhost = PluginHost::getInstance(); | |
176 | foreach ($pluginhost->get_plugins() as $plugin) { | |
177 | $flags = $plugin->flags(); | |
178 | ||
179 | if (isset($flags["needs_curl"]) && $flags["needs_curl"]) { | |
180 | $any_needs_curl = true; | |
181 | break; | |
182 | } | |
183 | } | |
184 | } | |
185 | ||
186 | //if ($_REQUEST["debug"]) print "<!-- any_needs_curl: $any_needs_curl -->"; | |
187 | ||
188 | if (!$any_needs_curl) { | |
189 | ||
190 | $result = $this->dbh->query( | |
191 | "SELECT cache_images," . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated | |
192 | FROM ttrss_feeds WHERE id = '$feed'"); | |
6afcbcd1 | 193 | |
d9c85e0f AD |
194 | if ($this->dbh->num_rows($result) != 0) { |
195 | $last_updated = strtotime($this->dbh->fetch_result($result, 0, "last_updated")); | |
196 | $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images")); | |
6afcbcd1 | 197 | |
86b05f86 | 198 | if (!$cache_images && time() - $last_updated > 120) { |
6afcbcd1 | 199 | include "rssfuncs.php"; |
a42c55f0 | 200 | update_rss_feed($feed, true, true); |
6afcbcd1 | 201 | } else { |
d9c85e0f | 202 | $this->dbh->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01' |
41245888 | 203 | WHERE id = '$feed'"); |
6afcbcd1 AD |
204 | } |
205 | } | |
d9de136c AD |
206 | } else { |
207 | $this->dbh->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01' | |
208 | WHERE id = '$feed'"); | |
41245888 | 209 | } |
6afcbcd1 AD |
210 | } |
211 | ||
212 | if ($method_split[0] == "MarkAllReadGR") { | |
a42c55f0 | 213 | catchup_feed($method_split[1], false); |
6afcbcd1 AD |
214 | } |
215 | ||
216 | // FIXME: might break tag display? | |
217 | ||
218 | if (is_numeric($feed) && $feed > 0 && !$cat_view) { | |
d9c85e0f | 219 | $result = $this->dbh->query( |
6afcbcd1 AD |
220 | "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1"); |
221 | ||
d9c85e0f | 222 | if ($this->dbh->num_rows($result) == 0) { |
6afcbcd1 AD |
223 | $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>"; |
224 | } | |
225 | } | |
226 | ||
d9c85e0f | 227 | @$search = $this->dbh->escape_string($_REQUEST["query"]); |
60e68059 | 228 | @$search_language = $this->dbh->escape_string($_REQUEST["search_language"]); // PGSQL only |
6afcbcd1 AD |
229 | |
230 | if ($search) { | |
231 | $disable_cache = true; | |
232 | } | |
233 | ||
6afcbcd1 AD |
234 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info); |
235 | ||
a413f53e | 236 | |
e92a353b | 237 | if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
1ffe3391 | 238 | $handler = PluginHost::getInstance()->get_feed_handler( |
a413f53e AD |
239 | PluginHost::feed_to_pfeed_id($feed)); |
240 | ||
a413f53e AD |
241 | if ($handler) { |
242 | $options = array( | |
243 | "limit" => $limit, | |
244 | "view_mode" => $view_mode, | |
245 | "cat_view" => $cat_view, | |
246 | "search" => $search, | |
a413f53e AD |
247 | "override_order" => $override_order, |
248 | "offset" => $offset, | |
249 | "owner_uid" => $_SESSION["uid"], | |
250 | "filter" => false, | |
251 | "since_id" => 0, | |
252 | "include_children" => $include_children); | |
253 | ||
254 | $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), | |
255 | $options); | |
256 | } | |
257 | ||
258 | } else { | |
f5a0fb8b | 259 | /*$qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, |
9090b874 | 260 | $search, false, $override_order, $offset, 0, |
f5a0fb8b AD |
261 | false, 0, $include_children, $topid);*/ |
262 | ||
263 | //function queryFeedHeadlines($feed, $limit, | |
264 | // $view_mode, $cat_view, $search, $search_mode, | |
265 | // $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, | |
266 | // $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) { | |
267 | ||
268 | $params = array( | |
269 | "feed" => $feed, | |
270 | "limit" => $limit, | |
271 | "view_mode" => $view_mode, | |
272 | "cat_view" => $cat_view, | |
273 | "search" => $search, | |
60e68059 | 274 | "search_language" => $search_language, |
f5a0fb8b AD |
275 | "override_order" => $override_order, |
276 | "offset" => $offset, | |
277 | "include_children" => $include_children, | |
19e47ad6 AD |
278 | "check_first_id" => $check_first_id, |
279 | "skip_first_id_check" => $skip_first_id_check | |
f5a0fb8b AD |
280 | ); |
281 | ||
282 | $qfh_ret = queryFeedHeadlines($params); | |
a413f53e | 283 | } |
6afcbcd1 | 284 | |
ad593e43 AD |
285 | $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && $feed != -6; |
286 | ||
6afcbcd1 AD |
287 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info); |
288 | ||
289 | $result = $qfh_ret[0]; | |
290 | $feed_title = $qfh_ret[1]; | |
291 | $feed_site_url = $qfh_ret[2]; | |
292 | $last_error = $qfh_ret[3]; | |
90e5f4f1 AD |
293 | $last_updated = strpos($qfh_ret[4], '1970-') === FALSE ? |
294 | make_local_datetime($qfh_ret[4], false) : __("Never"); | |
dd90eb2c | 295 | $highlight_words = $qfh_ret[5]; |
48fefe2f | 296 | $reply['first_id'] = $qfh_ret[6]; |
6afcbcd1 AD |
297 | |
298 | $vgroup_last_feed = $vgr_last_feed; | |
299 | ||
300 | $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, | |
301 | $feed_title, | |
9090b874 | 302 | $feed, $cat_view, $search, $view_mode, |
6e3e8db9 | 303 | $last_error, $last_updated); |
6afcbcd1 | 304 | |
f61f2a26 | 305 | $headlines_count = is_numeric($result) ? 0 : $this->dbh->num_rows($result); |
6afcbcd1 | 306 | |
7eb87b80 AD |
307 | if ($offset == 0) { |
308 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINES_BEFORE) as $p) { | |
309 | $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret); | |
310 | } | |
311 | } | |
312 | ||
f1706996 | 313 | $reply['content'] = ''; |
9f5eca99 | 314 | |
f61f2a26 | 315 | if ($headlines_count > 0) { |
6afcbcd1 AD |
316 | |
317 | $lnum = $offset; | |
318 | ||
319 | $num_unread = 0; | |
320 | $cur_feed_title = ''; | |
321 | ||
6afcbcd1 AD |
322 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info); |
323 | ||
a42c55f0 | 324 | $expand_cdm = get_pref('CDM_EXPANDED'); |
4ab1eb9c | 325 | |
d9c85e0f | 326 | while ($line = $this->dbh->fetch_assoc($result)) { |
ac4c1383 | 327 | |
bf5bcb8e | 328 | $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); |
4ab1eb9c | 329 | |
891e36f5 | 330 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
425a6edc | 331 | $line = $p->hook_query_headlines($line, 250, false); |
891e36f5 | 332 | } |
4ab1eb9c AD |
333 | |
334 | if (get_pref('SHOW_CONTENT_PREVIEW')) { | |
335 | $content_preview = $line["content_preview"]; | |
336 | } | |
337 | ||
6afcbcd1 AD |
338 | $id = $line["id"]; |
339 | $feed_id = $line["feed_id"]; | |
340 | $label_cache = $line["label_cache"]; | |
341 | $labels = false; | |
6afcbcd1 AD |
342 | |
343 | if ($label_cache) { | |
344 | $label_cache = json_decode($label_cache, true); | |
345 | ||
346 | if ($label_cache) { | |
347 | if ($label_cache["no-labels"] == 1) | |
348 | $labels = array(); | |
349 | else | |
350 | $labels = $label_cache; | |
351 | } | |
352 | } | |
353 | ||
a42c55f0 | 354 | if (!is_array($labels)) $labels = get_article_labels($id); |
6afcbcd1 | 355 | |
65f0eb01 | 356 | $labels_str = "<span class=\"HLLCTR-$id\">"; |
6afcbcd1 AD |
357 | $labels_str .= format_article_labels($labels, $id); |
358 | $labels_str .= "</span>"; | |
359 | ||
360 | if (count($topmost_article_ids) < 3) { | |
361 | array_push($topmost_article_ids, $id); | |
362 | } | |
363 | ||
8d090a91 AD |
364 | $class = ""; |
365 | ||
035d7a5a | 366 | if (sql_bool_to_bool($line["unread"])) { |
6afcbcd1 AD |
367 | $class .= " Unread"; |
368 | ++$num_unread; | |
6afcbcd1 AD |
369 | } |
370 | ||
035d7a5a AD |
371 | if (sql_bool_to_bool($line["marked"])) { |
372 | $marked_pic = "<img | |
2f20dd58 | 373 | src=\"images/mark_set.png\" |
6afcbcd1 | 374 | class=\"markedPic\" alt=\"Unstar article\" |
035d7a5a AD |
375 | onclick='toggleMark($id)'>"; |
376 | $class .= " marked"; | |
6afcbcd1 | 377 | } else { |
035d7a5a | 378 | $marked_pic = "<img |
2f20dd58 | 379 | src=\"images/mark_unset.png\" |
6afcbcd1 | 380 | class=\"markedPic\" alt=\"Star article\" |
035d7a5a | 381 | onclick='toggleMark($id)'>"; |
6afcbcd1 AD |
382 | } |
383 | ||
035d7a5a | 384 | if (sql_bool_to_bool($line["published"])) { |
2f20dd58 | 385 | $published_pic = "<img src=\"images/pub_set.png\" |
035d7a5a AD |
386 | class=\"pubPic\" |
387 | alt=\"Unpublish article\" onclick='togglePub($id)'>"; | |
388 | $class .= " published"; | |
6afcbcd1 | 389 | } else { |
2f20dd58 | 390 | $published_pic = "<img src=\"images/pub_unset.png\" |
035d7a5a AD |
391 | class=\"pubPic\" |
392 | alt=\"Publish article\" onclick='togglePub($id)'>"; | |
6afcbcd1 AD |
393 | } |
394 | ||
395 | # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" . | |
396 | # $line["title"] . "</a>"; | |
397 | ||
398 | # $content_link = "<a | |
399 | # href=\"" . htmlspecialchars($line["link"]) . "\" | |
400 | # onclick=\"view($id,$feed_id);\">" . | |
401 | # $line["title"] . "</a>"; | |
402 | ||
403 | # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" . | |
404 | # $line["title"] . "</a>"; | |
405 | ||
b6714c77 | 406 | $updated_fmt = make_local_datetime($line["updated"], false, false, false, true); |
be574731 | 407 | $date_entered_fmt = T_sprintf("Imported at %s", |
a42c55f0 | 408 | make_local_datetime($line["date_entered"], false)); |
6afcbcd1 | 409 | |
6afcbcd1 AD |
410 | $score = $line["score"]; |
411 | ||
2a3b6de0 | 412 | $score_pic = "images/" . get_score_pic($score); |
6afcbcd1 AD |
413 | |
414 | /* $score_title = __("(Click to change)"); | |
415 | $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" | |
416 | onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */ | |
417 | ||
418 | $score_pic = "<img class='hlScorePic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\" | |
419 | title=\"$score\">"; | |
420 | ||
421 | if ($score > 500) { | |
4b7ebe93 | 422 | $hlc_suffix = "high"; |
6afcbcd1 | 423 | } else if ($score < -100) { |
4b7ebe93 | 424 | $hlc_suffix = "low"; |
6afcbcd1 AD |
425 | } else { |
426 | $hlc_suffix = ""; | |
427 | } | |
428 | ||
429 | $entry_author = $line["author"]; | |
430 | ||
431 | if ($entry_author) { | |
884f2aee | 432 | $entry_author = " — $entry_author"; |
6afcbcd1 AD |
433 | } |
434 | ||
435 | $has_feed_icon = feed_has_icon($feed_id); | |
436 | ||
437 | if ($has_feed_icon) { | |
438 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">"; | |
439 | } else { | |
2f20dd58 | 440 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.png\" alt=\"\">"; |
6afcbcd1 AD |
441 | } |
442 | ||
08dfc223 AD |
443 | $entry_site_url = $line["site_url"]; |
444 | ||
bfaf90e3 AD |
445 | //setting feed headline background color, needs to change text color based on dark/light |
446 | $fav_color = $line['favicon_avg_color']; | |
447 | ||
448 | require_once "colors.php"; | |
449 | ||
db29ea0d | 450 | if ($fav_color && $fav_color != 'fail') { |
e7480cc1 | 451 | if (!isset($rgba_cache[$feed_id])) { |
12a6bd28 | 452 | $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color)); |
e7480cc1 | 453 | } |
bfaf90e3 AD |
454 | } |
455 | ||
a42c55f0 | 456 | if (!get_pref('COMBINED_DISPLAY_MODE')) { |
6afcbcd1 | 457 | |
ad593e43 | 458 | if ($vfeed_group_enabled) { |
6afcbcd1 AD |
459 | if ($feed_id != $vgroup_last_feed && $line["feed_title"]) { |
460 | ||
461 | $cur_feed_title = $line["feed_title"]; | |
462 | $vgroup_last_feed = $feed_id; | |
463 | ||
464 | $cur_feed_title = htmlspecialchars($cur_feed_title); | |
465 | ||
87065739 | 466 | $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>"; |
6afcbcd1 | 467 | |
0d0cb8fe | 468 | $reply['content'] .= "<div id='FTITLE-$feed_id' class='cdmFeedTitle'>". |
87065739 | 469 | "<div style='float : right'>$feed_icon_img</div>". |
dcbe36b2 | 470 | "<a class='title' href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">". |
ac4c1383 | 471 | $line["feed_title"]."</a> |
87065739 | 472 | $vf_catchup_link</div>"; |
6afcbcd1 | 473 | |
ac4c1383 | 474 | |
6afcbcd1 AD |
475 | } |
476 | } | |
477 | ||
d2f3467b | 478 | $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' |
6afcbcd1 AD |
479 | onmouseout='postMouseOut($id)'"; |
480 | ||
f1706996 | 481 | $reply['content'] .= "<div class='hl $class' orig-feed-id='$feed_id' id='RROW-$id' $mouseover_attrs>"; |
6afcbcd1 | 482 | |
f1706996 | 483 | $reply['content'] .= "<div class='hlLeft'>"; |
6afcbcd1 | 484 | |
f1706996 | 485 | $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\" |
524de8dc | 486 | type=\"checkbox\" onclick=\"toggleSelectRow2(this)\" |
7e27c914 | 487 | class='rchk'>"; |
6afcbcd1 | 488 | |
f1706996 AD |
489 | $reply['content'] .= "$marked_pic"; |
490 | $reply['content'] .= "$published_pic"; | |
6afcbcd1 | 491 | |
f1706996 | 492 | $reply['content'] .= "</div>"; |
6afcbcd1 | 493 | |
f1706996 | 494 | $reply['content'] .= "<div onclick='return hlClicked(event, $id)' |
4b7ebe93 | 495 | class=\"hlTitle\"><span class='hlContent $hlc_suffix'>"; |
f1706996 | 496 | $reply['content'] .= "<a id=\"RTITLE-$id\" class=\"title $hlc_suffix\" |
bf1dc420 | 497 | href=\"" . htmlspecialchars($line["link"]) . "\" |
6afcbcd1 AD |
498 | onclick=\"\">" . |
499 | truncate_string($line["title"], 200); | |
500 | ||
a42c55f0 | 501 | if (get_pref('SHOW_CONTENT_PREVIEW')) { |
f1706996 | 502 | $reply['content'] .= "<span class=\"contentPreview\">" . $line["content_preview"] . "</span>"; |
6afcbcd1 AD |
503 | } |
504 | ||
f1706996 | 505 | $reply['content'] .= "</a></span>"; |
6afcbcd1 | 506 | |
f1706996 | 507 | $reply['content'] .= $labels_str; |
6afcbcd1 | 508 | |
f1706996 | 509 | $reply['content'] .= "</div>"; |
e17e99fb | 510 | |
ad593e43 | 511 | if (!$vfeed_group_enabled) { |
b830cca7 | 512 | if (@$line["feed_title"]) { |
d3103484 AD |
513 | $rgba = @$rgba_cache[$feed_id]; |
514 | ||
dcbe36b2 | 515 | $reply['content'] .= "<span class=\"hlFeed\"><a style=\"background : rgba($rgba, 0.3)\" href=\"#\" onclick=\"viewfeed({feed:$feed_id})\">". |
029005c4 | 516 | truncate_string($line["feed_title"],30)."</a></span>"; |
6afcbcd1 | 517 | } |
b830cca7 | 518 | } |
6afcbcd1 | 519 | |
029005c4 | 520 | |
f1706996 | 521 | $reply['content'] .= "<span class=\"hlUpdated\">"; |
029005c4 | 522 | |
f1706996 | 523 | $reply['content'] .= "<div title='$date_entered_fmt'>$updated_fmt</div> |
be574731 AD |
524 | </span>"; |
525 | ||
f1706996 | 526 | $reply['content'] .= "<div class=\"hlRight\">"; |
6afcbcd1 | 527 | |
f1706996 | 528 | $reply['content'] .= $score_pic; |
6afcbcd1 | 529 | |
ad593e43 | 530 | if ($line["feed_title"] && !$vfeed_group_enabled) { |
6afcbcd1 | 531 | |
dcbe36b2 | 532 | $reply['content'] .= "<span onclick=\"viewfeed({feed:$feed_id})\" |
6afcbcd1 AD |
533 | style=\"cursor : pointer\" |
534 | title=\"".htmlspecialchars($line['feed_title'])."\"> | |
a0d9bc16 | 535 | $feed_icon_img</span>"; |
6afcbcd1 AD |
536 | } |
537 | ||
f1706996 AD |
538 | $reply['content'] .= "</div>"; |
539 | $reply['content'] .= "</div>"; | |
6afcbcd1 AD |
540 | |
541 | } else { | |
542 | ||
f8a25082 AD |
543 | if ($line["tag_cache"]) |
544 | $tags = explode(",", $line["tag_cache"]); | |
545 | else | |
546 | $tags = false; | |
84d952f1 | 547 | |
891e36f5 | 548 | $line["content"] = sanitize($line["content"], |
910592b4 | 549 | sql_bool_to_bool($line['hide_images']), false, $entry_site_url, $highlight_words, $line["id"]); |
84d952f1 | 550 | |
1ffe3391 | 551 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) { |
84d952f1 AD |
552 | $line = $p->hook_render_article_cdm($line); |
553 | } | |
554 | ||
ad593e43 | 555 | if ($vfeed_group_enabled && $line["feed_title"]) { |
6afcbcd1 AD |
556 | if ($feed_id != $vgroup_last_feed) { |
557 | ||
558 | $cur_feed_title = $line["feed_title"]; | |
559 | $vgroup_last_feed = $feed_id; | |
560 | ||
561 | $cur_feed_title = htmlspecialchars($cur_feed_title); | |
562 | ||
87065739 | 563 | $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark feed as read')."</a>"; |
6afcbcd1 AD |
564 | |
565 | $has_feed_icon = feed_has_icon($feed_id); | |
566 | ||
567 | if ($has_feed_icon) { | |
568 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">"; | |
569 | } else { | |
570 | //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">"; | |
571 | } | |
572 | ||
0d0cb8fe | 573 | $reply['content'] .= "<div id='FTITLE-$feed_id' class='cdmFeedTitle'>". |
6afcbcd1 | 574 | "<div style=\"float : right\">$feed_icon_img</div>". |
dcbe36b2 | 575 | "<a href=\"#\" class='title' onclick=\"viewfeed({feed:$feed_id})\">". |
6afcbcd1 | 576 | $line["feed_title"]."</a> $vf_catchup_link</div>"; |
ac4c1383 | 577 | |
6afcbcd1 AD |
578 | } |
579 | } | |
580 | ||
d2f3467b | 581 | $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' |
6afcbcd1 AD |
582 | onmouseout='postMouseOut($id)'"; |
583 | ||
a0ddecb9 | 584 | $expanded_class = $expand_cdm ? "expanded" : "expandable"; |
3ac153f1 | 585 | |
f1706996 | 586 | $reply['content'] .= "<div class=\"cdm $hlc_suffix $expanded_class $class\" |
87065739 | 587 | id=\"RROW-$id\" orig-feed-id='$feed_id' $mouseover_attrs>"; |
6afcbcd1 | 588 | |
f1706996 AD |
589 | $reply['content'] .= "<div class=\"cdmHeader\">"; |
590 | $reply['content'] .= "<div style=\"vertical-align : middle\">"; | |
6afcbcd1 | 591 | |
f1706996 | 592 | $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\" |
524de8dc | 593 | type=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\" |
7e27c914 | 594 | class='rchk'>"; |
6afcbcd1 | 595 | |
f1706996 AD |
596 | $reply['content'] .= "$marked_pic"; |
597 | $reply['content'] .= "$published_pic"; | |
6afcbcd1 | 598 | |
f1706996 | 599 | $reply['content'] .= "</div>"; |
6afcbcd1 | 600 | |
34dad844 AD |
601 | if ($highlight_words && count($highlight_words > 0)) { |
602 | foreach ($highlight_words as $word) { | |
603 | $line["title"] = preg_replace("/(\Q$word\E)/i", | |
604 | "<span class=\"highlight\">$1</span>", $line["title"]); | |
605 | } | |
606 | } | |
607 | ||
f1706996 | 608 | $reply['content'] .= "<span id=\"RTITLE-$id\" |
6afcbcd1 | 609 | onclick=\"return cdmClicked(event, $id);\" |
4b7ebe93 AD |
610 | class=\"titleWrap $hlc_suffix\"> |
611 | <a class=\"title $hlc_suffix\" | |
469d9ad1 | 612 | title=\"".htmlspecialchars($line["title"])."\" |
6afcbcd1 AD |
613 | target=\"_blank\" href=\"". |
614 | htmlspecialchars($line["link"])."\">". | |
615 | $line["title"] . | |
13e283ed | 616 | "</a> <span class=\"author\">$entry_author</span>"; |
6afcbcd1 | 617 | |
f1706996 | 618 | $reply['content'] .= $labels_str; |
6afcbcd1 | 619 | |
f1706996 | 620 | $reply['content'] .= "<span class='collapseBtn' style='display : none'> |
414191d4 AD |
621 | <img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, $id)\" |
622 | title=\"".__("Collapse article")."\"/></span>"; | |
623 | ||
6afcbcd1 AD |
624 | if (!$expand_cdm) |
625 | $content_hidden = "style=\"display : none\""; | |
626 | else | |
627 | $excerpt_hidden = "style=\"display : none\""; | |
628 | ||
f1706996 | 629 | $reply['content'] .= "<span $excerpt_hidden id=\"CEXC-$id\" class=\"cdmExcerpt\">" . $content_preview . "</span>"; |
2e188438 | 630 | |
f1706996 | 631 | $reply['content'] .= "</span>"; |
6afcbcd1 | 632 | |
ad593e43 | 633 | if (!$vfeed_group_enabled) { |
d56ec700 | 634 | if (@$line["feed_title"]) { |
d3103484 AD |
635 | $rgba = @$rgba_cache[$feed_id]; |
636 | ||
f1706996 | 637 | $reply['content'] .= "<div class=\"hlFeed\"> |
d3103484 | 638 | <a href=\"#\" style=\"background-color: rgba($rgba,0.3)\" |
dcbe36b2 | 639 | onclick=\"viewfeed({feed:$feed_id})\">". |
af2941db | 640 | truncate_string($line["feed_title"],30)."</a> |
d56ec700 AD |
641 | </div>"; |
642 | } | |
643 | } | |
644 | ||
f1706996 | 645 | $reply['content'] .= "<span class='updated' title='$date_entered_fmt'> |
be574731 | 646 | $updated_fmt</span>"; |
e17e99fb | 647 | |
f1706996 AD |
648 | $reply['content'] .= "<div class='scoreWrap' style=\"vertical-align : middle\">"; |
649 | $reply['content'] .= "$score_pic"; | |
6afcbcd1 | 650 | |
a42c55f0 | 651 | if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) { |
f1706996 | 652 | $reply['content'] .= "<span style=\"cursor : pointer\" |
6afcbcd1 | 653 | title=\"".htmlspecialchars($line["feed_title"])."\" |
dcbe36b2 | 654 | onclick=\"viewfeed({feed:$feed_id})\">$feed_icon_img</span>"; |
6afcbcd1 | 655 | } |
f1706996 | 656 | $reply['content'] .= "</div>"; |
6afcbcd1 | 657 | |
f1706996 | 658 | $reply['content'] .= "</div>"; |
6afcbcd1 | 659 | |
f1706996 | 660 | $reply['content'] .= "<div class=\"cdmContent\" $content_hidden |
6afcbcd1 AD |
661 | onclick=\"return cdmClicked(event, $id);\" |
662 | id=\"CICD-$id\">"; | |
663 | ||
f1706996 | 664 | $reply['content'] .= "<div id=\"POSTNOTE-$id\">"; |
b999f4c7 | 665 | if ($line['note']) { |
f1706996 | 666 | $reply['content'] .= format_article_note($id, $line['note']); |
b999f4c7 | 667 | } |
f1706996 | 668 | $reply['content'] .= "</div>"; |
b999f4c7 | 669 | |
07eb3658 AD |
670 | if (!$line['lang']) $line['lang'] = 'en'; |
671 | ||
f1706996 | 672 | $reply['content'] .= "<div class=\"cdmContentInner\" lang=\"".$line['lang']."\">"; |
6afcbcd1 AD |
673 | |
674 | if ($line["orig_feed_id"]) { | |
675 | ||
d9c85e0f | 676 | $tmp_result = $this->dbh->query("SELECT * FROM ttrss_archived_feeds |
71b75bb7 | 677 | WHERE id = ".$line["orig_feed_id"] . " AND owner_uid = " . $_SESSION["uid"]); |
6afcbcd1 | 678 | |
d9c85e0f | 679 | if ($this->dbh->num_rows($tmp_result) != 0) { |
6afcbcd1 | 680 | |
f1706996 AD |
681 | $reply['content'] .= "<div clear='both'>"; |
682 | $reply['content'] .= __("Originally from:"); | |
6afcbcd1 | 683 | |
f1706996 | 684 | $reply['content'] .= " "; |
6afcbcd1 | 685 | |
d9c85e0f | 686 | $tmp_line = $this->dbh->fetch_assoc($tmp_result); |
6afcbcd1 | 687 | |
f1706996 | 688 | $reply['content'] .= "<a target='_blank' |
6afcbcd1 AD |
689 | href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . |
690 | $tmp_line['title'] . "</a>"; | |
691 | ||
f1706996 | 692 | $reply['content'] .= " "; |
6afcbcd1 | 693 | |
f1706996 AD |
694 | $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>"; |
695 | $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_unset.png'></a>"; | |
6afcbcd1 | 696 | |
f1706996 | 697 | $reply['content'] .= "</div>"; |
6afcbcd1 AD |
698 | } |
699 | } | |
700 | ||
f1706996 | 701 | $reply['content'] .= "<span id=\"CWRAP-$id\">"; |
6afcbcd1 | 702 | |
b74c5134 | 703 | // if (!$expand_cdm) { |
f1706996 AD |
704 | $reply['content'] .= "<span id=\"CENCW-$id\" style=\"display : none\">"; |
705 | $reply['content'] .= htmlspecialchars($line["content"]); | |
706 | $reply['content'] .= "</span."; | |
f0540b59 | 707 | |
b74c5134 | 708 | // } else { |
f1706996 | 709 | // $reply['content'] .= $line["content"]; |
b74c5134 | 710 | // } |
6afcbcd1 | 711 | |
f1706996 | 712 | $reply['content'] .= "</span>"; |
6afcbcd1 | 713 | |
f1706996 | 714 | $reply['content'] .= "</div>"; |
6afcbcd1 | 715 | |
90da4ada AD |
716 | $reply['content'] .= "<div class=\"cdmIntermediate\">"; |
717 | ||
718 | $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]); | |
719 | $reply['content'] .= format_article_enclosures($id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"])); | |
720 | ||
721 | $reply['content'] .= "</div>"; | |
722 | ||
f1706996 | 723 | $reply['content'] .= "<div class=\"cdmFooter\" onclick=\"cdmFooterClick(event)\">"; |
6afcbcd1 | 724 | |
1ffe3391 | 725 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { |
f1706996 | 726 | $reply['content'] .= $p->hook_article_left_button($line); |
ccb2b8dd AD |
727 | } |
728 | ||
f8a25082 | 729 | $tags_str = format_tags_string($tags, $id); |
6afcbcd1 | 730 | |
bc20cb9f AD |
731 | $reply['content'] .= "<span class='left'>"; |
732 | ||
f1706996 | 733 | $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'> |
6afcbcd1 AD |
734 | <span id=\"ATSTR-$id\">$tags_str</span> |
735 | <a title=\"".__('Edit tags for this article')."\" | |
27372dda | 736 | href=\"#\" onclick=\"editArticleTags($id)\">(+)</a>"; |
6afcbcd1 AD |
737 | |
738 | $num_comments = $line["num_comments"]; | |
739 | $entry_comments = ""; | |
740 | ||
741 | if ($num_comments > 0) { | |
742 | if ($line["comments"]) { | |
743 | $comments_url = htmlspecialchars($line["comments"]); | |
744 | } else { | |
745 | $comments_url = htmlspecialchars($line["link"]); | |
746 | } | |
ff04fe06 AD |
747 | $entry_comments = "<a class=\"postComments\" |
748 | target='_blank' href=\"$comments_url\">$num_comments ". | |
749 | _ngettext("comment", "comments", $num_comments)."</a>"; | |
750 | ||
6afcbcd1 AD |
751 | } else { |
752 | if ($line["comments"] && $line["link"] != $line["comments"]) { | |
ff04fe06 | 753 | $entry_comments = "<a class=\"postComments\" target='_blank' href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>"; |
6afcbcd1 AD |
754 | } |
755 | } | |
756 | ||
f1706996 | 757 | if ($entry_comments) $reply['content'] .= " ($entry_comments)"; |
6afcbcd1 | 758 | |
bc20cb9f AD |
759 | $reply['content'] .= "</span>"; |
760 | $reply['content'] .= "<div>"; | |
6afcbcd1 | 761 | |
f1706996 AD |
762 | // $reply['content'] .= "$marked_pic"; |
763 | // $reply['content'] .= "$published_pic"; | |
035d7a5a | 764 | |
1ffe3391 | 765 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) { |
f1706996 | 766 | $reply['content'] .= $p->hook_article_button($line); |
6afcbcd1 AD |
767 | } |
768 | ||
f1706996 AD |
769 | $reply['content'] .= "</div>"; |
770 | $reply['content'] .= "</div>"; | |
6afcbcd1 | 771 | |
f1706996 | 772 | $reply['content'] .= "</div>"; |
6afcbcd1 | 773 | |
f1706996 | 774 | $reply['content'] .= "</div>"; |
6afcbcd1 AD |
775 | |
776 | } | |
777 | ||
778 | ++$lnum; | |
779 | } | |
780 | ||
781 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info); | |
782 | ||
ec57104d | 783 | } else if (!is_numeric($result)) { |
6afcbcd1 AD |
784 | $message = ""; |
785 | ||
786 | switch ($view_mode) { | |
787 | case "unread": | |
788 | $message = __("No unread articles found to display."); | |
789 | break; | |
790 | case "updated": | |
791 | $message = __("No updated articles found to display."); | |
792 | break; | |
793 | case "marked": | |
794 | $message = __("No starred articles found to display."); | |
795 | break; | |
796 | default: | |
f822a8e5 | 797 | if ($feed < LABEL_BASE_INDEX) { |
8d192d02 | 798 | $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter."); |
6afcbcd1 AD |
799 | } else { |
800 | $message = __("No articles found to display."); | |
801 | } | |
802 | } | |
803 | ||
804 | if (!$offset && $message) { | |
f1706996 | 805 | $reply['content'] = "<div class='whiteBox'>$message"; |
6afcbcd1 | 806 | |
f1706996 | 807 | $reply['content'] .= "<p><span class=\"insensitive\">"; |
6afcbcd1 | 808 | |
d9c85e0f | 809 | $result = $this->dbh->query("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds |
6afcbcd1 AD |
810 | WHERE owner_uid = " . $_SESSION['uid']); |
811 | ||
d9c85e0f | 812 | $last_updated = $this->dbh->fetch_result($result, 0, "last_updated"); |
a42c55f0 | 813 | $last_updated = make_local_datetime($last_updated, false); |
6afcbcd1 | 814 | |
f1706996 | 815 | $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); |
6afcbcd1 | 816 | |
d9c85e0f | 817 | $result = $this->dbh->query("SELECT COUNT(id) AS num_errors |
6afcbcd1 AD |
818 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); |
819 | ||
d9c85e0f | 820 | $num_errors = $this->dbh->fetch_result($result, 0, "num_errors"); |
6afcbcd1 AD |
821 | |
822 | if ($num_errors > 0) { | |
f1706996 AD |
823 | $reply['content'] .= "<br/>"; |
824 | $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">". | |
6afcbcd1 AD |
825 | __('Some feeds have update errors (click for details)')."</a>"; |
826 | } | |
f1706996 | 827 | $reply['content'] .= "</span></p></div>"; |
9f5eca99 | 828 | |
6afcbcd1 | 829 | } |
34440201 | 830 | } else if (is_numeric($result) && $result == -1) { |
48fefe2f | 831 | $reply['first_id_changed'] = true; |
6afcbcd1 AD |
832 | } |
833 | ||
834 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info); | |
835 | ||
836 | return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, | |
837 | $vgroup_last_feed, $reply); | |
838 | } | |
839 | ||
840 | function catchupAll() { | |
d9c85e0f | 841 | $this->dbh->query("UPDATE ttrss_user_entries SET |
1bad74ea | 842 | last_read = NOW(), unread = false WHERE unread = true AND owner_uid = " . $_SESSION["uid"]); |
a42c55f0 | 843 | ccache_zero_all($_SESSION["uid"]); |
6afcbcd1 AD |
844 | } |
845 | ||
6afcbcd1 | 846 | function view() { |
fa9e88c3 | 847 | $timing_info = microtime(true); |
6afcbcd1 AD |
848 | |
849 | $reply = array(); | |
850 | ||
851 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info); | |
852 | ||
d9c85e0f AD |
853 | $feed = $this->dbh->escape_string($_REQUEST["feed"]); |
854 | $method = $this->dbh->escape_string($_REQUEST["m"]); | |
855 | $view_mode = $this->dbh->escape_string($_REQUEST["view_mode"]); | |
f17cac6b | 856 | $limit = 30; |
6afcbcd1 | 857 | @$cat_view = $_REQUEST["cat"] == "true"; |
d9c85e0f AD |
858 | @$next_unread_feed = $this->dbh->escape_string($_REQUEST["nuf"]); |
859 | @$offset = $this->dbh->escape_string($_REQUEST["skip"]); | |
860 | @$vgroup_last_feed = $this->dbh->escape_string($_REQUEST["vgrlf"]); | |
861 | $order_by = $this->dbh->escape_string($_REQUEST["order_by"]); | |
48fefe2f | 862 | $check_first_id = $this->dbh->escape_string($_REQUEST["fid"]); |
6afcbcd1 AD |
863 | |
864 | if (is_numeric($feed)) $feed = (int) $feed; | |
865 | ||
866 | /* Feed -5 is a special case: it is used to display auxiliary information | |
867 | * when there's nothing to load - e.g. no stuff in fresh feed */ | |
868 | ||
869 | if ($feed == -5) { | |
6322ac79 | 870 | print json_encode($this->generate_dashboard_feed()); |
6afcbcd1 AD |
871 | return; |
872 | } | |
873 | ||
874 | $result = false; | |
875 | ||
f822a8e5 AD |
876 | if ($feed < LABEL_BASE_INDEX) { |
877 | $label_feed = feed_to_label_id($feed); | |
d9c85e0f | 878 | $result = $this->dbh->query("SELECT id FROM ttrss_labels2 WHERE |
6afcbcd1 AD |
879 | id = '$label_feed' AND owner_uid = " . $_SESSION['uid']); |
880 | } else if (!$cat_view && is_numeric($feed) && $feed > 0) { | |
d9c85e0f | 881 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE |
6afcbcd1 AD |
882 | id = '$feed' AND owner_uid = " . $_SESSION['uid']); |
883 | } else if ($cat_view && is_numeric($feed) && $feed > 0) { | |
d9c85e0f | 884 | $result = $this->dbh->query("SELECT id FROM ttrss_feed_categories WHERE |
6afcbcd1 AD |
885 | id = '$feed' AND owner_uid = " . $_SESSION['uid']); |
886 | } | |
887 | ||
d9c85e0f | 888 | if ($result && $this->dbh->num_rows($result) == 0) { |
a42c55f0 | 889 | print json_encode($this->generate_error_feed(__("Feed not found."))); |
6afcbcd1 AD |
890 | return; |
891 | } | |
892 | ||
893 | /* Updating a label ccache means recalculating all of the caches | |
894 | * so for performance reasons we don't do that here */ | |
895 | ||
896 | if ($feed >= 0) { | |
a42c55f0 | 897 | ccache_update($feed, $_SESSION["uid"], $cat_view); |
6afcbcd1 AD |
898 | } |
899 | ||
a42c55f0 AD |
900 | set_pref("_DEFAULT_VIEW_MODE", $view_mode); |
901 | set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by); | |
6afcbcd1 | 902 | |
06b0777f AD |
903 | /* bump login timestamp if needed */ |
904 | if (time() - $_SESSION["last_login_update"] > 3600) { | |
d9c85e0f | 905 | $this->dbh->query("UPDATE ttrss_users SET last_login = NOW() WHERE id = " . |
06b0777f AD |
906 | $_SESSION["uid"]); |
907 | $_SESSION["last_login_update"] = time(); | |
908 | } | |
909 | ||
6afcbcd1 | 910 | if (!$cat_view && is_numeric($feed) && $feed > 0) { |
d9c85e0f | 911 | $this->dbh->query("UPDATE ttrss_feeds SET last_viewed = NOW() |
6afcbcd1 AD |
912 | WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); |
913 | } | |
914 | ||
915 | $reply['headlines'] = array(); | |
916 | ||
6afcbcd1 | 917 | $override_order = false; |
19e47ad6 | 918 | $skip_first_id_check = false; |
6afcbcd1 | 919 | |
6afcbcd1 | 920 | switch ($order_by) { |
f3b2e7d4 AD |
921 | case "title": |
922 | $override_order = "ttrss_entries.title"; | |
923 | break; | |
924 | case "date_reverse": | |
e9687f67 | 925 | $override_order = "score DESC, date_entered, updated"; |
19e47ad6 | 926 | $skip_first_id_check = true; |
f3b2e7d4 AD |
927 | break; |
928 | case "feed_dates": | |
929 | $override_order = "updated DESC"; | |
930 | break; | |
6afcbcd1 AD |
931 | } |
932 | ||
933 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); | |
934 | ||
935 | $ret = $this->format_headlines_list($feed, $method, | |
936 | $view_mode, $limit, $cat_view, $next_unread_feed, $offset, | |
19e47ad6 | 937 | $vgroup_last_feed, $override_order, true, $check_first_id, $skip_first_id_check); |
6afcbcd1 | 938 | |
b389aeb7 | 939 | //$topmost_article_ids = $ret[0]; |
6afcbcd1 | 940 | $headlines_count = $ret[1]; |
4a80c57c | 941 | /* $returned_feed = $ret[2]; */ |
6afcbcd1 AD |
942 | $disable_cache = $ret[3]; |
943 | $vgroup_last_feed = $ret[4]; | |
944 | ||
34440201 AD |
945 | //$reply['headlines']['content'] =& $ret[5]['content']; |
946 | //$reply['headlines']['toolbar'] =& $ret[5]['toolbar']; | |
947 | ||
1bd552ee | 948 | $reply['headlines'] = $ret[5]; |
34440201 AD |
949 | |
950 | if (!$next_unread_feed) | |
951 | $reply['headlines']['id'] = $feed; | |
952 | else | |
953 | $reply['headlines']['id'] = $next_unread_feed; | |
954 | ||
955 | $reply['headlines']['is_cat'] = (bool) $cat_view; | |
6afcbcd1 AD |
956 | |
957 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); | |
958 | ||
959 | $reply['headlines-info'] = array("count" => (int) $headlines_count, | |
960 | "vgroup_last_feed" => $vgroup_last_feed, | |
961 | "disable_cache" => (bool) $disable_cache); | |
962 | ||
6afcbcd1 AD |
963 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info); |
964 | ||
6322ac79 | 965 | $reply['runtime-info'] = make_runtime_info(); |
6afcbcd1 AD |
966 | |
967 | print json_encode($reply); | |
968 | ||
969 | } | |
970 | ||
6322ac79 | 971 | private function generate_dashboard_feed() { |
6afcbcd1 AD |
972 | $reply = array(); |
973 | ||
974 | $reply['headlines']['id'] = -5; | |
975 | $reply['headlines']['is_cat'] = false; | |
976 | ||
977 | $reply['headlines']['toolbar'] = ''; | |
6afcbcd1 | 978 | |
f1706996 | 979 | $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.'); |
6b954c0a | 980 | |
f1706996 | 981 | $reply['headlines']['content'] .= "<p><span class=\"insensitive\">"; |
6afcbcd1 | 982 | |
d9c85e0f | 983 | $result = $this->dbh->query("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds |
6afcbcd1 AD |
984 | WHERE owner_uid = " . $_SESSION['uid']); |
985 | ||
d9c85e0f | 986 | $last_updated = $this->dbh->fetch_result($result, 0, "last_updated"); |
a42c55f0 | 987 | $last_updated = make_local_datetime($last_updated, false); |
6afcbcd1 | 988 | |
f1706996 | 989 | $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); |
6afcbcd1 | 990 | |
d9c85e0f | 991 | $result = $this->dbh->query("SELECT COUNT(id) AS num_errors |
6afcbcd1 AD |
992 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); |
993 | ||
d9c85e0f | 994 | $num_errors = $this->dbh->fetch_result($result, 0, "num_errors"); |
6afcbcd1 AD |
995 | |
996 | if ($num_errors > 0) { | |
f1706996 AD |
997 | $reply['headlines']['content'] .= "<br/>"; |
998 | $reply['headlines']['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">". | |
6afcbcd1 AD |
999 | __('Some feeds have update errors (click for details)')."</a>"; |
1000 | } | |
f1706996 | 1001 | $reply['headlines']['content'] .= "</span></p>"; |
6afcbcd1 AD |
1002 | |
1003 | $reply['headlines-info'] = array("count" => 0, | |
1004 | "vgroup_last_feed" => '', | |
1005 | "unread" => 0, | |
1006 | "disable_cache" => true); | |
1007 | ||
1008 | return $reply; | |
1009 | } | |
1010 | ||
a42c55f0 | 1011 | private function generate_error_feed($error) { |
6afcbcd1 AD |
1012 | $reply = array(); |
1013 | ||
33c4bd89 | 1014 | $reply['headlines']['id'] = -7; |
6afcbcd1 AD |
1015 | $reply['headlines']['is_cat'] = false; |
1016 | ||
1017 | $reply['headlines']['toolbar'] = ''; | |
1018 | $reply['headlines']['content'] = "<div class='whiteBox'>". $error . "</div>"; | |
1019 | ||
1020 | $reply['headlines-info'] = array("count" => 0, | |
1021 | "vgroup_last_feed" => '', | |
1022 | "unread" => 0, | |
1023 | "disable_cache" => true); | |
1024 | ||
1025 | return $reply; | |
1026 | } | |
1027 | ||
1c9bda91 AD |
1028 | function quickAddFeed() { |
1029 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; | |
1030 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">"; | |
1031 | ||
8f7a020e AD |
1032 | print "<div id='fadd_multiple_notify' style='display : none'>"; |
1033 | print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below."); | |
1034 | print "<p></div>"; | |
1035 | ||
1c9bda91 AD |
1036 | print "<div class=\"dlgSec\">".__("Feed or site URL")."</div>"; |
1037 | print "<div class=\"dlgSecCont\">"; | |
1038 | ||
1039 | print "<div style='float : right'> | |
1040 | <img style='display : none' | |
1041 | id='feed_add_spinner' src='images/indicator_white.gif'></div>"; | |
1042 | ||
1043 | print "<input style=\"font-size : 16px; width : 20em;\" | |
1044 | placeHolder=\"".__("Feed or site URL")."\" | |
1045 | dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">"; | |
1046 | ||
1047 | print "<hr/>"; | |
1048 | ||
a42c55f0 | 1049 | if (get_pref('ENABLE_FEED_CATS')) { |
1c9bda91 | 1050 | print __('Place in category:') . " "; |
a42c55f0 | 1051 | print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"'); |
1c9bda91 AD |
1052 | } |
1053 | ||
1054 | print "</div>"; | |
1055 | ||
1056 | print '<div id="feedDlg_feedsContainer" style="display : none"> | |
1057 | ||
1058 | <div class="dlgSec">' . __('Available feeds') . '</div> | |
1059 | <div class="dlgSecCont">'. | |
1060 | '<select id="feedDlg_feedContainerSelect" | |
1061 | dojoType="dijit.form.Select" size="3"> | |
1062 | <script type="dojo/method" event="onChange" args="value"> | |
1063 | dijit.byId("feedDlg_feedUrl").attr("value", value); | |
1064 | </script> | |
1065 | </select>'. | |
1066 | '</div></div>'; | |
1067 | ||
1068 | print "<div id='feedDlg_loginContainer' style='display : none'> | |
1069 | ||
1070 | <div class=\"dlgSec\">".__("Authentication")."</div> | |
1071 | <div class=\"dlgSecCont\">". | |
1072 | ||
1073 | " <input dojoType=\"dijit.form.TextBox\" name='login'\" | |
1074 | placeHolder=\"".__("Login")."\" | |
1075 | style=\"width : 10em;\"> ". | |
1076 | " <input | |
1077 | placeHolder=\"".__("Password")."\" | |
1078 | dojoType=\"dijit.form.TextBox\" type='password' | |
1079 | style=\"width : 10em;\" name='pass'\"> | |
1080 | </div></div>"; | |
1081 | ||
1082 | ||
1083 | print "<div style=\"clear : both\"> | |
1084 | <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\" | |
1085 | onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'> | |
1086 | <label for=\"feedDlg_loginCheck\">". | |
1087 | __('This feed requires authentication.')."</div>"; | |
1088 | ||
1089 | print "</form>"; | |
1090 | ||
1091 | print "<div class=\"dlgButtons\"> | |
1092 | <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>"; | |
1093 | ||
1094 | if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER)) { | |
1095 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button>"; | |
1096 | } | |
1097 | ||
1098 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button> | |
1099 | </div>"; | |
1100 | ||
1101 | //return; | |
1102 | } | |
1103 | ||
1104 | function feedBrowser() { | |
1105 | if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return; | |
1106 | ||
d9c85e0f | 1107 | $browser_search = $this->dbh->escape_string($_REQUEST["search"]); |
1c9bda91 AD |
1108 | |
1109 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; | |
1110 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">"; | |
1111 | ||
1112 | print "<div dojoType=\"dijit.Toolbar\"> | |
1113 | <div style='float : right'> | |
1114 | <img style='display : none' | |
1115 | id='feed_browser_spinner' src='images/indicator_white.gif'> | |
1116 | <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\" | |
1117 | onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\"> | |
1118 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button> | |
1119 | </div>"; | |
1120 | ||
1121 | print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\"> | |
1122 | <option value='1'>" . __('Popular feeds') . "</option> | |
1123 | <option value='2'>" . __('Feed archive') . "</option> | |
1124 | </select> "; | |
1125 | ||
1126 | print __("limit:"); | |
1127 | ||
1128 | print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">"; | |
1129 | ||
1130 | foreach (array(25, 50, 100, 200) as $l) { | |
4a80c57c AD |
1131 | //$issel = ($l == $limit) ? "selected=\"1\"" : ""; |
1132 | print "<option value=\"$l\">$l</option>"; | |
1c9bda91 AD |
1133 | } |
1134 | ||
1135 | print "</select> "; | |
1136 | ||
1137 | print "</div>"; | |
1138 | ||
1c9bda91 AD |
1139 | require_once "feedbrowser.php"; |
1140 | ||
1141 | print "<ul class='browseFeedList' id='browseFeedList'>"; | |
4a80c57c | 1142 | print make_feed_browser("", 25); |
1c9bda91 AD |
1143 | print "</ul>"; |
1144 | ||
1145 | print "<div align='center'> | |
1146 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button> | |
1147 | <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button> | |
1148 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>"; | |
1149 | ||
1150 | } | |
1151 | ||
1152 | function search() { | |
d9c85e0f | 1153 | $this->params = explode(":", $this->dbh->escape_string($_REQUEST["param"]), 2); |
1c9bda91 AD |
1154 | |
1155 | $active_feed_id = sprintf("%d", $this->params[0]); | |
1156 | $is_cat = $this->params[1] != "false"; | |
1157 | ||
1158 | print "<div class=\"dlgSec\">".__('Look for')."</div>"; | |
1159 | ||
1160 | print "<div class=\"dlgSecCont\">"; | |
1161 | ||
1162 | print "<input dojoType=\"dijit.form.ValidationTextBox\" | |
1163 | style=\"font-size : 16px; width : 20em;\" | |
1164 | required=\"1\" name=\"query\" type=\"search\" value=''>"; | |
1165 | ||
9090b874 | 1166 | print "<hr/><span style='float : right'>".T_sprintf('in %s', getFeedTitle($active_feed_id, $is_cat))."</span>"; |
1c9bda91 | 1167 | |
60e68059 AD |
1168 | if (DB_TYPE == "pgsql") { |
1169 | print "<hr/>"; | |
1170 | print_select("search_language", "", Pref_Feeds::$feed_languages, | |
1171 | "dojoType='dijit.form.Select' title=\"".__('Used for word stemming')."\""); | |
1172 | } | |
1173 | ||
1c9bda91 AD |
1174 | print "</div>"; |
1175 | ||
1176 | print "<div class=\"dlgButtons\">"; | |
1177 | ||
baaf4c30 | 1178 | if (count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0) { |
1c9bda91 | 1179 | print "<div style=\"float : left\"> |
19ab8096 | 1180 | <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/wiki/SearchSyntax\">".__("Search syntax")."</a> |
1c9bda91 AD |
1181 | </div>"; |
1182 | } | |
1183 | ||
1184 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button> | |
1185 | <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button> | |
1186 | </div>"; | |
1187 | } | |
1188 | ||
86b05f86 AD |
1189 | function update_debugger() { |
1190 | header("Content-type: text/html"); | |
1191 | ||
1192 | $feed_id = (int)$_REQUEST["feed_id"]; | |
1193 | @$do_update = $_REQUEST["action"] == "do_update"; | |
1194 | $csrf_token = $_REQUEST["csrf_token"]; | |
1195 | ||
1196 | $refetch_checked = isset($_REQUEST["force_refetch"]) ? "checked" : ""; | |
1197 | $rehash_checked = isset($_REQUEST["force_rehash"]) ? "checked" : ""; | |
1198 | ||
1199 | ?> | |
1200 | <html> | |
1201 | <head> | |
1202 | <link rel="stylesheet" type="text/css" href="css/utility.css"> | |
1203 | <title>Feed Debugger</title> | |
1204 | </head> | |
1205 | <body class="small_margins"> | |
1206 | <h1>Feed Debugger: <?php echo "$feed_id: " . getFeedTitle($feed_id) ?></h1> | |
1207 | <form method="GET" action=""> | |
1208 | <input type="hidden" name="op" value="feeds"> | |
1209 | <input type="hidden" name="method" value="update_debugger"> | |
1210 | <input type="hidden" name="xdebug" value="1"> | |
1211 | <input type="hidden" name="csrf_token" value="<?php echo $csrf_token ?>"> | |
1212 | <input type="hidden" name="action" value="do_update"> | |
1213 | <input type="hidden" name="feed_id" value="<?php echo $feed_id ?>"> | |
1214 | <input type="checkbox" name="force_refetch" value="1" <?php echo $refetch_checked ?>> Force refetch<br/> | |
1215 | <input type="checkbox" name="force_rehash" value="1" <?php echo $rehash_checked ?>> Force rehash<br/> | |
1216 | ||
1217 | <p/><button type="submit">Continue</button> | |
1218 | </form> | |
1219 | ||
1220 | <hr> | |
1221 | ||
1222 | <pre><?php | |
1223 | ||
1224 | if ($do_update) { | |
1225 | include "rssfuncs.php"; | |
1226 | update_rss_feed($feed_id, true, true); | |
1227 | } | |
1228 | ||
1229 | ?></pre> | |
1c9bda91 | 1230 | |
86b05f86 AD |
1231 | </body> |
1232 | </html> | |
1233 | <?php | |
1234 | ||
1235 | } | |
6afcbcd1 AD |
1236 | } |
1237 | ?> |