]>
Commit | Line | Data |
---|---|---|
3f363052 | 1 | <?php\r |
46da73c2 AD |
2 | class Feeds extends Protected_Handler {\r |
3 | \r | |
8484ce22 AD |
4 | function csrf_ignore($method) {\r |
5 | $csrf_ignored = array("index");\r | |
6 | \r | |
7 | return array_search($method, $csrf_ignored) !== false;\r | |
8 | }\r | |
9 | \r | |
79178062 AD |
10 | private function feedlist_init_cat($cat_id, $hidden = false) {\r |
11 | $obj = array();\r | |
12 | $cat_id = (int) $cat_id;\r | |
13 | \r | |
14 | if ($cat_id > 0) {\r | |
15 | $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);\r | |
16 | } else if ($cat_id == 0 || $cat_id == -2) {\r | |
17 | $cat_unread = getCategoryUnread($this->link, $cat_id);\r | |
18 | }\r | |
19 | \r | |
20 | $obj['id'] = 'CAT:' . $cat_id;\r | |
21 | $obj['items'] = array();\r | |
22 | $obj['name'] = getCategoryTitle($this->link, $cat_id);\r | |
23 | $obj['type'] = 'feed';\r | |
24 | $obj['unread'] = (int) $cat_unread;\r | |
25 | $obj['hidden'] = $hidden;\r | |
26 | $obj['bare_id'] = $cat_id;\r | |
27 | \r | |
28 | return $obj;\r | |
29 | }\r | |
30 | \r | |
31 | private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {\r | |
32 | $obj = array();\r | |
33 | $feed_id = (int) $feed_id;\r | |
34 | \r | |
35 | if (!$title)\r | |
36 | $title = getFeedTitle($this->link, $feed_id, false);\r | |
37 | \r | |
38 | if ($unread === false)\r | |
39 | $unread = getFeedUnread($this->link, $feed_id, false);\r | |
40 | \r | |
41 | $obj['id'] = 'FEED:' . $feed_id;\r | |
42 | $obj['name'] = $title;\r | |
43 | $obj['unread'] = (int) $unread;\r | |
44 | $obj['type'] = 'feed';\r | |
45 | $obj['error'] = $error;\r | |
46 | $obj['updated'] = $updated;\r | |
47 | $obj['icon'] = getFeedIcon($feed_id);\r | |
48 | $obj['bare_id'] = $feed_id;\r | |
49 | \r | |
50 | return $obj;\r | |
51 | }\r | |
52 | \r | |
53 | private function format_headline_subtoolbar($feed_site_url, $feed_title,\r | |
54 | $feed_id, $is_cat, $search, $match_on,\r | |
55 | $search_mode, $view_mode, $error) {\r | |
56 | \r | |
57 | $page_prev_link = "viewFeedGoPage(-1)";\r | |
58 | $page_next_link = "viewFeedGoPage(1)";\r | |
59 | $page_first_link = "viewFeedGoPage(0)";\r | |
60 | \r | |
61 | $catchup_page_link = "catchupPage()";\r | |
62 | $catchup_feed_link = "catchupCurrentFeed()";\r | |
63 | $catchup_sel_link = "catchupSelection()";\r | |
64 | \r | |
65 | $archive_sel_link = "archiveSelection()";\r | |
66 | $delete_sel_link = "deleteSelection()";\r | |
67 | \r | |
68 | $sel_all_link = "selectArticles('all')";\r | |
69 | $sel_unread_link = "selectArticles('unread')";\r | |
70 | $sel_none_link = "selectArticles('none')";\r | |
71 | $sel_inv_link = "selectArticles('invert')";\r | |
72 | \r | |
73 | $tog_unread_link = "selectionToggleUnread()";\r | |
74 | $tog_marked_link = "selectionToggleMarked()";\r | |
75 | $tog_published_link = "selectionTogglePublished()";\r | |
76 | \r | |
f1080825 AD |
77 | if ($is_cat) $cat_q = "&is_cat=$is_cat";\r |
78 | \r | |
79 | if ($search) {\r | |
80 | $search_q = "&q=$search&m=$match_on&smode=$search_mode";\r | |
81 | } else {\r | |
82 | $search_q = "";\r | |
83 | }\r | |
84 | \r | |
85 | $rss_link = htmlspecialchars(get_self_url_prefix() .\r | |
86 | "/public.php?op=rss&id=$feed_id$cat_q$search_q");\r | |
87 | \r | |
88 | // right part\r | |
89 | \r | |
90 | $reply .= "<span class='r'>";\r | |
91 | \r | |
92 | if ($feed_site_url) {\r | |
93 | $target = "target=\"_blank\"";\r | |
94 | $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".\r | |
95 | truncate_string($feed_title,30)."</a>";\r | |
96 | \r | |
97 | if ($error) {\r | |
98 | $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";\r | |
99 | }\r | |
100 | \r | |
101 | } else {\r | |
102 | $reply .= $feed_title;\r | |
103 | }\r | |
104 | \r | |
105 | $reply .= "\r | |
106 | <a href=\"#\"\r | |
107 | title=\"".__("View as RSS feed")."\"\r | |
108 | onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">\r | |
109 | <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";\r | |
110 | \r | |
111 | $reply .= "</span>";\r | |
112 | \r | |
113 | // left part\r | |
79178062 AD |
114 | \r |
115 | $reply .= __('Select:')."\r | |
116 | <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,\r | |
117 | <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,\r | |
118 | <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,\r | |
119 | <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";\r | |
120 | \r | |
121 | $reply .= " ";\r | |
122 | \r | |
123 | $reply .= "<select dojoType=\"dijit.form.Select\"\r | |
124 | onchange=\"headlineActionsChange(this)\">";\r | |
125 | $reply .= "<option value=\"false\">".__('Actions...')."</option>";\r | |
126 | \r | |
127 | $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";\r | |
128 | \r | |
129 | $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>\r | |
130 | <option value=\"$tog_marked_link\">".__('Starred')."</option>\r | |
131 | <option value=\"$tog_published_link\">".__('Published')."</option>";\r | |
132 | \r | |
133 | $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";\r | |
134 | \r | |
135 | $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";\r | |
136 | \r | |
137 | if ($feed_id != "0") {\r | |
138 | $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";\r | |
139 | } else {\r | |
140 | $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";\r | |
141 | $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";\r | |
142 | \r | |
143 | }\r | |
144 | \r | |
145 | $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').\r | |
146 | "</option>";\r | |
147 | \r | |
79178062 AD |
148 | $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";\r |
149 | \r | |
150 | $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";\r | |
151 | \r | |
152 | $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";\r | |
153 | \r | |
154 | $reply .= "</select>";\r | |
155 | \r | |
f1080825 | 156 | //$reply .= "</div>";\r |
79178062 | 157 | \r |
f1080825 | 158 | //$reply .= "</h2";\r |
79178062 AD |
159 | \r |
160 | return $reply;\r | |
161 | }\r | |
162 | \r | |
163 | private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,\r | |
164 | $next_unread_feed, $offset, $vgr_last_feed = false,\r | |
165 | $override_order = false) {\r | |
166 | \r | |
167 | $disable_cache = false;\r | |
168 | \r | |
169 | $reply = array();\r | |
170 | \r | |
171 | $timing_info = getmicrotime();\r | |
172 | \r | |
173 | $topmost_article_ids = array();\r | |
174 | \r | |
175 | if (!$offset) $offset = 0;\r | |
176 | if ($method == "undefined") $method = "";\r | |
177 | \r | |
178 | $method_split = explode(":", $method);\r | |
179 | \r | |
3c696512 AD |
180 | if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {\r |
181 | include "rssfuncs.php";\r | |
182 | update_rss_feed($this->link, $feed, true);\r | |
183 | }\r | |
79178062 | 184 | \r |
79178062 AD |
185 | if ($method_split[0] == "MarkAllReadGR") {\r |
186 | catchup_feed($this->link, $method_split[1], false);\r | |
187 | }\r | |
188 | \r | |
189 | // FIXME: might break tag display?\r | |
190 | \r | |
191 | if (is_numeric($feed) && $feed > 0 && !$cat_view) {\r | |
192 | $result = db_query($this->link,\r | |
193 | "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");\r | |
194 | \r | |
195 | if (db_num_rows($result) == 0) {\r | |
196 | $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";\r | |
197 | }\r | |
198 | }\r | |
199 | \r | |
200 | if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {\r | |
201 | \r | |
202 | $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds\r | |
203 | WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);\r | |
204 | \r | |
205 | if (db_num_rows($result) == 1) {\r | |
206 | $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));\r | |
207 | } else {\r | |
208 | $rtl_content = false;\r | |
209 | }\r | |
210 | \r | |
211 | if ($rtl_content) {\r | |
212 | $rtl_tag = "dir=\"RTL\"";\r | |
213 | } else {\r | |
214 | $rtl_tag = "";\r | |
215 | }\r | |
216 | } else {\r | |
217 | $rtl_tag = "";\r | |
218 | $rtl_content = false;\r | |
219 | }\r | |
220 | \r | |
221 | @$search = db_escape_string($_REQUEST["query"]);\r | |
222 | \r | |
223 | if ($search) {\r | |
224 | $disable_cache = true;\r | |
225 | }\r | |
226 | \r | |
227 | @$search_mode = db_escape_string($_REQUEST["search_mode"]);\r | |
228 | @$match_on = db_escape_string($_REQUEST["match_on"]);\r | |
229 | \r | |
230 | if (!$match_on) {\r | |
231 | $match_on = "both";\r | |
232 | }\r | |
233 | \r | |
234 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);\r | |
235 | \r | |
236 | // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");\r | |
237 | if( $search_mode == '' && $method != '' ){\r | |
238 | $search_mode = $method;\r | |
239 | }\r | |
240 | // error_log("search_mode: " . $search_mode);\r | |
241 | $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,\r | |
242 | $search, $search_mode, $match_on, $override_order, $offset);\r | |
243 | \r | |
244 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);\r | |
245 | \r | |
246 | $result = $qfh_ret[0];\r | |
247 | $feed_title = $qfh_ret[1];\r | |
248 | $feed_site_url = $qfh_ret[2];\r | |
249 | $last_error = $qfh_ret[3];\r | |
250 | \r | |
251 | $vgroup_last_feed = $vgr_last_feed;\r | |
252 | \r | |
253 | // if (!$offset) {\r | |
254 | \r | |
255 | if (db_num_rows($result) > 0) {\r | |
256 | $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,\r | |
257 | $feed_title,\r | |
258 | $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,\r | |
259 | $last_error);\r | |
260 | }\r | |
261 | // }\r | |
262 | \r | |
263 | $headlines_count = db_num_rows($result);\r | |
264 | \r | |
1baac280 AD |
265 | if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {\r |
266 | $button_plugins = array();\r | |
267 | foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {\r | |
268 | $pclass = trim("${p}_button");\r | |
269 | \r | |
270 | if (class_exists($pclass)) {\r | |
271 | $plugin = new $pclass($link);\r | |
272 | array_push($button_plugins, $plugin);\r | |
273 | }\r | |
274 | }\r | |
275 | }\r | |
276 | \r | |
79178062 AD |
277 | if (db_num_rows($result) > 0) {\r |
278 | \r | |
279 | $lnum = $offset;\r | |
280 | \r | |
281 | $num_unread = 0;\r | |
282 | $cur_feed_title = '';\r | |
283 | \r | |
284 | $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;\r | |
285 | \r | |
286 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);\r | |
287 | \r | |
288 | while ($line = db_fetch_assoc($result)) {\r | |
289 | \r | |
290 | $class = ($lnum % 2) ? "even" : "odd";\r | |
291 | \r | |
292 | $id = $line["id"];\r | |
293 | $feed_id = $line["feed_id"];\r | |
294 | $label_cache = $line["label_cache"];\r | |
295 | $labels = false;\r | |
296 | \r | |
297 | if ($label_cache) {\r | |
298 | $label_cache = json_decode($label_cache, true);\r | |
299 | \r | |
300 | if ($label_cache) {\r | |
301 | if ($label_cache["no-labels"] == 1)\r | |
302 | $labels = array();\r | |
303 | else\r | |
304 | $labels = $label_cache;\r | |
305 | }\r | |
306 | }\r | |
307 | \r | |
308 | if (!is_array($labels)) $labels = get_article_labels($this->link, $id);\r | |
309 | \r | |
310 | $labels_str = "<span id=\"HLLCTR-$id\">";\r | |
311 | $labels_str .= format_article_labels($labels, $id);\r | |
312 | $labels_str .= "</span>";\r | |
313 | \r | |
314 | if (count($topmost_article_ids) < 3) {\r | |
315 | array_push($topmost_article_ids, $id);\r | |
316 | }\r | |
317 | \r | |
318 | if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {\r | |
319 | \r | |
320 | $update_pic = "<img id='FUPDPIC-$id' src=\"".\r | |
321 | theme_image($this->link, 'images/updated.png')."\"\r | |
322 | alt=\"Updated\">";\r | |
323 | } else {\r | |
324 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"\r | |
325 | alt=\"Updated\">";\r | |
326 | }\r | |
327 | \r | |
328 | if (sql_bool_to_bool($line["unread"]) &&\r | |
329 | time() - strtotime($line["updated_noms"]) < $fresh_intl) {\r | |
330 | \r | |
331 | $update_pic = "<img id='FUPDPIC-$id' src=\"".\r | |
332 | theme_image($this->link, 'images/fresh_sign.png')."\" alt=\"Fresh\">";\r | |
333 | }\r | |
334 | \r | |
335 | if ($line["unread"] == "t" || $line["unread"] == "1") {\r | |
336 | $class .= " Unread";\r | |
337 | ++$num_unread;\r | |
338 | $is_unread = true;\r | |
339 | } else {\r | |
340 | $is_unread = false;\r | |
341 | }\r | |
342 | \r | |
343 | if ($line["marked"] == "t" || $line["marked"] == "1") {\r | |
344 | $marked_pic = "<img id=\"FMPIC-$id\"\r | |
345 | src=\"".theme_image($this->link, 'images/mark_set.png')."\"\r | |
346 | class=\"markedPic\" alt=\"Unstar article\"\r | |
347 | onclick='javascript:toggleMark($id)'>";\r | |
348 | } else {\r | |
349 | $marked_pic = "<img id=\"FMPIC-$id\"\r | |
350 | src=\"".theme_image($this->link, 'images/mark_unset.png')."\"\r | |
351 | class=\"markedPic\" alt=\"Star article\"\r | |
352 | onclick='javascript:toggleMark($id)'>";\r | |
353 | }\r | |
354 | \r | |
355 | if ($line["published"] == "t" || $line["published"] == "1") {\r | |
356 | $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,\r | |
357 | 'images/pub_set.png')."\"\r | |
358 | class=\"markedPic\"\r | |
359 | alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";\r | |
360 | } else {\r | |
361 | $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,\r | |
362 | 'images/pub_unset.png')."\"\r | |
363 | class=\"markedPic\"\r | |
364 | alt=\"Publish article\" onclick='javascript:togglePub($id)'>";\r | |
365 | }\r | |
366 | \r | |
367 | # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .\r | |
368 | # $line["title"] . "</a>";\r | |
369 | \r | |
370 | # $content_link = "<a\r | |
371 | # href=\"" . htmlspecialchars($line["link"]) . "\"\r | |
372 | # onclick=\"view($id,$feed_id);\">" .\r | |
373 | # $line["title"] . "</a>";\r | |
374 | \r | |
375 | # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .\r | |
376 | # $line["title"] . "</a>";\r | |
377 | \r | |
378 | $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);\r | |
379 | \r | |
380 | if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {\r | |
26e4b124 | 381 | $content_preview = strip_tags($line["content_preview"]);\r |
79178062 AD |
382 | }\r |
383 | \r | |
384 | $score = $line["score"];\r | |
385 | \r | |
386 | $score_pic = theme_image($this->link,\r | |
387 | "images/" . get_score_pic($score));\r | |
388 | \r | |
389 | /* $score_title = __("(Click to change)");\r | |
390 | $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"\r | |
391 | onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */\r | |
392 | \r | |
393 | $score_pic = "<img class='hlScorePic' src=\"$score_pic\"\r | |
394 | title=\"$score\">";\r | |
395 | \r | |
396 | if ($score > 500) {\r | |
397 | $hlc_suffix = "H";\r | |
398 | } else if ($score < -100) {\r | |
399 | $hlc_suffix = "L";\r | |
400 | } else {\r | |
401 | $hlc_suffix = "";\r | |
402 | }\r | |
403 | \r | |
404 | $entry_author = $line["author"];\r | |
405 | \r | |
406 | if ($entry_author) {\r | |
407 | $entry_author = " - $entry_author";\r | |
408 | }\r | |
409 | \r | |
410 | $has_feed_icon = feed_has_icon($feed_id);\r | |
411 | \r | |
412 | if ($has_feed_icon) {\r | |
413 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";\r | |
414 | } else {\r | |
415 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";\r | |
416 | }\r | |
417 | \r | |
418 | if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {\r | |
419 | \r | |
420 | if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {\r | |
421 | if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {\r | |
422 | \r | |
423 | $cur_feed_title = $line["feed_title"];\r | |
424 | $vgroup_last_feed = $feed_id;\r | |
425 | \r | |
426 | $cur_feed_title = htmlspecialchars($cur_feed_title);\r | |
427 | \r | |
44245618 | 428 | $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";\r |
79178062 AD |
429 | \r |
430 | $reply['content'] .= "<div class='cdmFeedTitle'>".\r | |
431 | "<div style=\"float : right\">$feed_icon_img</div>".\r | |
432 | "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r | |
433 | $line["feed_title"]."</a> $vf_catchup_link</div>";\r | |
434 | \r | |
435 | }\r | |
436 | }\r | |
437 | \r | |
438 | $mouseover_attrs = "onmouseover='postMouseIn($id)'\r | |
439 | onmouseout='postMouseOut($id)'";\r | |
440 | \r | |
441 | $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";\r | |
442 | \r | |
443 | $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";\r | |
444 | \r | |
445 | $reply['content'] .= "<div class='hlLeft'>";\r | |
446 | \r | |
447 | $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"\r | |
448 | id=\"RCHK-$id\">";\r | |
449 | \r | |
450 | $reply['content'] .= "$marked_pic";\r | |
451 | $reply['content'] .= "$published_pic";\r | |
452 | \r | |
453 | $reply['content'] .= "</div>";\r | |
454 | \r | |
455 | $reply['content'] .= "<div onclick='return hlClicked(event, $id)'\r | |
456 | class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";\r | |
457 | $reply['content'] .= "<a id=\"RTITLE-$id\"\r | |
458 | href=\"" . htmlspecialchars($line["link"]) . "\"\r | |
459 | onclick=\"\">" .\r | |
26e4b124 | 460 | $line["title"];\r |
79178062 AD |
461 | \r |
462 | if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {\r | |
463 | if ($content_preview) {\r | |
464 | $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";\r | |
465 | }\r | |
466 | }\r | |
467 | \r | |
468 | $reply['content'] .= "</a></span>";\r | |
469 | \r | |
470 | $reply['content'] .= $labels_str;\r | |
471 | \r | |
472 | if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&\r | |
473 | defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {\r | |
474 | if (@$line["feed_title"]) {\r | |
475 | $reply['content'] .= "<span class=\"hlFeed\">\r | |
476 | (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r | |
477 | $line["feed_title"]."</a>)\r | |
478 | </span>";\r | |
479 | }\r | |
480 | }\r | |
481 | \r | |
482 | $reply['content'] .= "</div>";\r | |
483 | \r | |
484 | $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";\r | |
485 | $reply['content'] .= "<div class=\"hlRight\">";\r | |
486 | \r | |
487 | $reply['content'] .= $score_pic;\r | |
488 | \r | |
489 | if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {\r | |
490 | \r | |
491 | $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"\r | |
492 | style=\"cursor : pointer\"\r | |
493 | title=\"".htmlspecialchars($line['feed_title'])."\">\r | |
494 | $feed_icon_img<span>";\r | |
495 | }\r | |
496 | \r | |
497 | $reply['content'] .= "</div>";\r | |
498 | $reply['content'] .= "</div>";\r | |
499 | \r | |
500 | } else {\r | |
501 | \r | |
502 | if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {\r | |
503 | if ($feed_id != $vgroup_last_feed) {\r | |
504 | \r | |
505 | $cur_feed_title = $line["feed_title"];\r | |
506 | $vgroup_last_feed = $feed_id;\r | |
507 | \r | |
508 | $cur_feed_title = htmlspecialchars($cur_feed_title);\r | |
509 | \r | |
510 | $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";\r | |
511 | \r | |
512 | $has_feed_icon = feed_has_icon($feed_id);\r | |
513 | \r | |
514 | if ($has_feed_icon) {\r | |
515 | $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";\r | |
516 | } else {\r | |
517 | //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";\r | |
518 | }\r | |
519 | \r | |
520 | $reply['content'] .= "<div class='cdmFeedTitle'>".\r | |
521 | "<div style=\"float : right\">$feed_icon_img</div>".\r | |
522 | "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r | |
523 | $line["feed_title"]."</a> $vf_catchup_link</div>";\r | |
524 | }\r | |
525 | }\r | |
526 | \r | |
527 | $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');\r | |
528 | \r | |
529 | $mouseover_attrs = "onmouseover='postMouseIn($id)'\r | |
530 | onmouseout='postMouseOut($id)'";\r | |
531 | \r | |
532 | $reply['content'] .= "<div class=\"$class\"\r | |
533 | id=\"RROW-$id\" $mouseover_attrs'>";\r | |
534 | \r | |
535 | $reply['content'] .= "<div class=\"cdmHeader\">";\r | |
536 | \r | |
537 | $reply['content'] .= "<div>";\r | |
538 | \r | |
539 | $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,\r | |
540 | 'RROW-$id')\" id=\"RCHK-$id\"/>";\r | |
541 | \r | |
542 | $reply['content'] .= "$marked_pic";\r | |
543 | $reply['content'] .= "$published_pic";\r | |
544 | \r | |
545 | $reply['content'] .= "</div>";\r | |
546 | \r | |
aa8b48a0 AD |
547 | $reply['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .\r |
548 | strip_tags($line['title']) . "</div>";\r | |
549 | \r | |
79178062 AD |
550 | $reply['content'] .= "<span id=\"RTITLE-$id\"\r |
551 | onclick=\"return cdmClicked(event, $id);\"\r | |
552 | class=\"titleWrap$hlc_suffix\">\r | |
553 | <a class=\"title\"\r | |
554 | title=\"".htmlspecialchars($line['title'])."\"\r | |
555 | target=\"_blank\" href=\"".\r | |
556 | htmlspecialchars($line["link"])."\">".\r | |
557 | truncate_string($line["title"], 100) .\r | |
558 | " $entry_author</a>";\r | |
559 | \r | |
560 | $reply['content'] .= $labels_str;\r | |
561 | \r | |
562 | if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&\r | |
563 | defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {\r | |
564 | if (@$line["feed_title"]) {\r | |
565 | $reply['content'] .= "<span class=\"hlFeed\">\r | |
566 | (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r | |
567 | $line["feed_title"]."</a>)\r | |
568 | </span>";\r | |
569 | }\r | |
570 | }\r | |
571 | \r | |
572 | if (!$expand_cdm)\r | |
573 | $content_hidden = "style=\"display : none\"";\r | |
574 | else\r | |
575 | $excerpt_hidden = "style=\"display : none\"";\r | |
576 | \r | |
577 | $reply['content'] .= "<span $excerpt_hidden\r | |
578 | id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";\r | |
579 | \r | |
580 | $reply['content'] .= "</span>";\r | |
581 | \r | |
582 | $reply['content'] .= "<div>";\r | |
583 | $reply['content'] .= "<span class='updated'>$updated_fmt</span>";\r | |
584 | $reply['content'] .= "$score_pic";\r | |
585 | \r | |
586 | if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {\r | |
587 | $reply['content'] .= "<span style=\"cursor : pointer\"\r | |
588 | title=\"".htmlspecialchars($line["feed_title"])."\"\r | |
589 | onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";\r | |
590 | }\r | |
591 | $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";\r | |
592 | $reply['content'] .= "</div>";\r | |
593 | \r | |
594 | $reply['content'] .= "</div>";\r | |
595 | \r | |
596 | $reply['content'] .= "<div class=\"cdmContent\" $content_hidden\r | |
597 | onclick=\"return cdmClicked(event, $id);\"\r | |
598 | id=\"CICD-$id\">";\r | |
599 | \r | |
600 | $reply['content'] .= "<div class=\"cdmContentInner\">";\r | |
601 | \r | |
602 | if ($line["orig_feed_id"]) {\r | |
603 | \r | |
604 | $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds\r | |
605 | WHERE id = ".$line["orig_feed_id"]);\r | |
606 | \r | |
607 | if (db_num_rows($tmp_result) != 0) {\r | |
608 | \r | |
609 | $reply['content'] .= "<div clear='both'>";\r | |
610 | $reply['content'] .= __("Originally from:");\r | |
611 | \r | |
612 | $reply['content'] .= " ";\r | |
613 | \r | |
614 | $tmp_line = db_fetch_assoc($tmp_result);\r | |
615 | \r | |
616 | $reply['content'] .= "<a target='_blank'\r | |
617 | href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .\r | |
618 | $tmp_line['title'] . "</a>";\r | |
619 | \r | |
620 | $reply['content'] .= " ";\r | |
621 | \r | |
622 | $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";\r | |
11cb9506 | 623 | $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";\r |
79178062 AD |
624 | \r |
625 | $reply['content'] .= "</div>";\r | |
626 | }\r | |
627 | }\r | |
628 | \r | |
629 | $feed_site_url = $line["site_url"];\r | |
630 | \r | |
631 | $article_content = sanitize($this->link, $line["content_preview"],\r | |
632 | false, false, $feed_site_url);\r | |
633 | \r | |
634 | $reply['content'] .= "<div id=\"POSTNOTE-$id\">";\r | |
635 | if ($line['note']) {\r | |
636 | $reply['content'] .= format_article_note($id, $line['note']);\r | |
637 | }\r | |
638 | $reply['content'] .= "</div>";\r | |
639 | \r | |
640 | $reply['content'] .= "<span id=\"CWRAP-$id\">";\r | |
641 | $reply['content'] .= $expand_cdm ? $article_content : '';\r | |
642 | $reply['content'] .= "</span>";\r | |
643 | \r | |
644 | /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM\r | |
645 | ttrss_feeds WHERE id = ".\r | |
646 | (($line['feed_id'] == null) ? $line['orig_feed_id'] :\r | |
647 | $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);\r | |
648 | \r | |
649 | $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,\r | |
650 | 0, "always_display_enclosures")); */\r | |
651 | \r | |
652 | $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);\r | |
653 | \r | |
654 | $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,\r | |
655 | $article_content);\r | |
656 | \r | |
657 | $reply['content'] .= "</div>";\r | |
658 | \r | |
659 | $reply['content'] .= "<div class=\"cdmFooter\">";\r | |
660 | \r | |
661 | $tag_cache = $line["tag_cache"];\r | |
662 | \r | |
663 | $tags_str = format_tags_string(\r | |
664 | get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),\r | |
665 | $id);\r | |
666 | \r | |
667 | $reply['content'] .= "<img src='".theme_image($this->link,\r | |
668 | 'images/tag.png')."' alt='Tags' title='Tags'>\r | |
669 | <span id=\"ATSTR-$id\">$tags_str</span>\r | |
670 | <a title=\"".__('Edit tags for this article')."\"\r | |
671 | href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";\r | |
672 | \r | |
673 | $num_comments = $line["num_comments"];\r | |
674 | $entry_comments = "";\r | |
675 | \r | |
676 | if ($num_comments > 0) {\r | |
677 | if ($line["comments"]) {\r | |
678 | $comments_url = $line["comments"];\r | |
679 | } else {\r | |
680 | $comments_url = $line["link"];\r | |
681 | }\r | |
682 | $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";\r | |
683 | } else {\r | |
684 | if ($line["comments"] && $line["link"] != $line["comments"]) {\r | |
685 | $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";\r | |
686 | }\r | |
687 | }\r | |
688 | \r | |
689 | if ($entry_comments) $reply['content'] .= " ($entry_comments)";\r | |
690 | \r | |
691 | $reply['content'] .= "<div style=\"float : right\">";\r | |
692 | \r | |
693 | $reply['content'] .= "<img src=\"images/art-zoom.png\"\r | |
694 | onclick=\"zoomToArticle(event, $id)\"\r | |
695 | style=\"cursor : pointer\"\r | |
696 | alt='Zoom'\r | |
697 | title='".__('Open article in new tab')."'>";\r | |
698 | \r | |
699 | //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);\r | |
700 | \r | |
f9ac31d6 | 701 | foreach ($button_plugins as $p) {\r |
1baac280 | 702 | $reply['content'] .= $p->render($id, $line);\r |
79178062 AD |
703 | }\r |
704 | \r | |
79178062 AD |
705 | $reply['content'] .= "<img src=\"images/digest_checkbox.png\"\r |
706 | style=\"cursor : pointer\" style=\"cursor : pointer\"\r | |
707 | onclick=\"dismissArticle($id)\"\r | |
638e27c8 | 708 | title='".__('Close article')."'>";\r |
79178062 AD |
709 | \r |
710 | $reply['content'] .= "</div>";\r | |
711 | $reply['content'] .= "</div>";\r | |
712 | \r | |
713 | $reply['content'] .= "</div>";\r | |
714 | \r | |
715 | $reply['content'] .= "</div>";\r | |
716 | \r | |
717 | }\r | |
718 | \r | |
719 | ++$lnum;\r | |
720 | }\r | |
721 | \r | |
722 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);\r | |
723 | \r | |
724 | } else {\r | |
725 | $message = "";\r | |
726 | \r | |
727 | switch ($view_mode) {\r | |
728 | case "unread":\r | |
729 | $message = __("No unread articles found to display.");\r | |
730 | break;\r | |
731 | case "updated":\r | |
732 | $message = __("No updated articles found to display.");\r | |
733 | break;\r | |
734 | case "marked":\r | |
735 | $message = __("No starred articles found to display.");\r | |
736 | break;\r | |
737 | default:\r | |
738 | if ($feed < -10) {\r | |
739 | $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");\r | |
740 | } else {\r | |
741 | $message = __("No articles found to display.");\r | |
742 | }\r | |
743 | }\r | |
744 | \r | |
745 | if (!$offset && $message) {\r | |
746 | $reply['content'] .= "<div class='whiteBox'>$message";\r | |
747 | \r | |
748 | $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";\r | |
749 | \r | |
750 | $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds\r | |
751 | WHERE owner_uid = " . $_SESSION['uid']);\r | |
752 | \r | |
753 | $last_updated = db_fetch_result($result, 0, "last_updated");\r | |
754 | $last_updated = make_local_datetime($this->link, $last_updated, false);\r | |
755 | \r | |
756 | $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);\r | |
757 | \r | |
758 | $result = db_query($this->link, "SELECT COUNT(id) AS num_errors\r | |
759 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);\r | |
760 | \r | |
761 | $num_errors = db_fetch_result($result, 0, "num_errors");\r | |
762 | \r | |
763 | if ($num_errors > 0) {\r | |
764 | $reply['content'] .= "<br/>";\r | |
765 | $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".\r | |
766 | __('Some feeds have update errors (click for details)')."</a>";\r | |
767 | }\r | |
768 | $reply['content'] .= "</span></p></div>";\r | |
769 | }\r | |
770 | }\r | |
771 | \r | |
772 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);\r | |
773 | \r | |
774 | return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,\r | |
775 | $vgroup_last_feed, $reply);\r | |
776 | }\r | |
777 | \r | |
778 | private function outputFeedList($special = true) {\r | |
779 | \r | |
780 | $feedlist = array();\r | |
781 | \r | |
782 | $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');\r | |
783 | \r | |
784 | $feedlist['identifier'] = 'id';\r | |
785 | $feedlist['label'] = 'name';\r | |
786 | $feedlist['items'] = array();\r | |
787 | \r | |
788 | $owner_uid = $_SESSION["uid"];\r | |
789 | \r | |
790 | /* virtual feeds */\r | |
791 | \r | |
792 | if ($special) {\r | |
793 | \r | |
794 | if ($enable_cats) {\r | |
795 | $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");\r | |
796 | $cat = $this->feedlist_init_cat(-1, $cat_hidden);\r | |
797 | } else {\r | |
798 | $cat['items'] = array();\r | |
799 | }\r | |
800 | \r | |
801 | foreach (array(-4, -3, -1, -2, 0) as $i) {\r | |
802 | array_push($cat['items'], $this->feedlist_init_feed($i));\r | |
803 | }\r | |
804 | \r | |
805 | if ($enable_cats) {\r | |
806 | array_push($feedlist['items'], $cat);\r | |
807 | } else {\r | |
808 | $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);\r | |
809 | }\r | |
810 | \r | |
811 | $result = db_query($this->link, "SELECT * FROM\r | |
812 | ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");\r | |
813 | \r | |
814 | if (db_num_rows($result) > 0) {\r | |
815 | \r | |
816 | if (get_pref($this->link, 'ENABLE_FEED_CATS')) {\r | |
817 | $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");\r | |
818 | $cat = $this->feedlist_init_cat(-2, $cat_hidden);\r | |
819 | } else {\r | |
820 | $cat['items'] = array();\r | |
821 | }\r | |
822 | \r | |
823 | while ($line = db_fetch_assoc($result)) {\r | |
824 | \r | |
825 | $label_id = -$line['id'] - 11;\r | |
826 | $count = getFeedUnread($this->link, $label_id);\r | |
827 | \r | |
828 | $feed = $this->feedlist_init_feed($label_id, false, $count);\r | |
829 | \r | |
830 | $feed['fg_color'] = $line['fg_color'];\r | |
831 | $feed['bg_color'] = $line['bg_color'];\r | |
832 | \r | |
833 | array_push($cat['items'], $feed);\r | |
834 | }\r | |
835 | \r | |
836 | if ($enable_cats) {\r | |
837 | array_push($feedlist['items'], $cat);\r | |
838 | } else {\r | |
839 | $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);\r | |
840 | }\r | |
841 | }\r | |
842 | }\r | |
843 | \r | |
844 | /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {\r | |
845 | if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {\r | |
846 | $order_by_qpart = "order_id,category,unread DESC,title";\r | |
847 | } else {\r | |
848 | $order_by_qpart = "order_id,category,title";\r | |
849 | }\r | |
850 | } else {\r | |
851 | if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {\r | |
852 | $order_by_qpart = "unread DESC,title";\r | |
853 | } else {\r | |
854 | $order_by_qpart = "title";\r | |
855 | }\r | |
856 | } */\r | |
857 | \r | |
858 | /* real feeds */\r | |
859 | \r | |
860 | if ($enable_cats)\r | |
861 | $order_by_qpart = "ttrss_feed_categories.order_id,category,\r | |
862 | ttrss_feeds.order_id,title";\r | |
863 | else\r | |
864 | $order_by_qpart = "title";\r | |
865 | \r | |
79178062 AD |
866 | $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,\r |
867 | ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,\r | |
868 | cat_id,last_error,\r | |
68916212 | 869 | COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS category,\r |
79178062 AD |
870 | ttrss_feed_categories.collapsed,\r |
871 | value AS unread\r | |
872 | FROM ttrss_feeds LEFT JOIN ttrss_feed_categories\r | |
873 | ON (ttrss_feed_categories.id = cat_id)\r | |
874 | LEFT JOIN ttrss_counters_cache\r | |
875 | ON\r | |
876 | (ttrss_feeds.id = feed_id)\r | |
877 | WHERE\r | |
878 | ttrss_feeds.owner_uid = '$owner_uid'\r | |
879 | ORDER BY $order_by_qpart";\r | |
880 | \r | |
881 | $result = db_query($this->link, $query);\r | |
882 | \r | |
883 | $actid = $_REQUEST["actid"];\r | |
884 | \r | |
885 | if (db_num_rows($result) > 0) {\r | |
886 | \r | |
887 | $category = "";\r | |
888 | \r | |
889 | if (!$enable_cats)\r | |
890 | $cat['items'] = array();\r | |
891 | else\r | |
892 | $cat = false;\r | |
893 | \r | |
894 | while ($line = db_fetch_assoc($result)) {\r | |
895 | \r | |
896 | $feed = htmlspecialchars(trim($line["title"]));\r | |
897 | \r | |
898 | if (!$feed) $feed = "[Untitled]";\r | |
899 | \r | |
900 | $feed_id = $line["id"];\r | |
901 | $unread = $line["unread"];\r | |
902 | \r | |
903 | $cat_id = $line["cat_id"];\r | |
904 | $tmp_category = $line["category"];\r | |
79178062 AD |
905 | \r |
906 | if ($category != $tmp_category && $enable_cats) {\r | |
907 | \r | |
908 | $category = $tmp_category;\r | |
909 | \r | |
910 | $collapsed = sql_bool_to_bool($line["collapsed"]);\r | |
911 | \r | |
912 | // workaround for NULL category\r | |
913 | if ($category == __("Uncategorized")) {\r | |
914 | $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT");\r | |
915 | }\r | |
916 | \r | |
917 | if ($cat) array_push($feedlist['items'], $cat);\r | |
918 | \r | |
919 | $cat = $this->feedlist_init_cat($cat_id, $collapsed);\r | |
920 | }\r | |
921 | \r | |
922 | $updated = make_local_datetime($this->link, $line["updated_noms"], false);\r | |
923 | \r | |
924 | array_push($cat['items'], $this->feedlist_init_feed($feed_id,\r | |
925 | $feed, $unread, $line['last_error'], $updated));\r | |
926 | }\r | |
927 | \r | |
928 | if ($enable_cats) {\r | |
929 | array_push($feedlist['items'], $cat);\r | |
930 | } else {\r | |
931 | $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);\r | |
932 | }\r | |
933 | \r | |
934 | }\r | |
935 | \r | |
936 | return $feedlist;\r | |
937 | }\r | |
938 | \r | |
939 | \r | |
3f363052 AD |
940 | function catchupAll() {\r |
941 | db_query($this->link, "UPDATE ttrss_user_entries SET\r | |
942 | last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);\r | |
943 | ccache_zero_all($this->link, $_SESSION["uid"]);\r | |
46da73c2 | 944 | }\r |
3f363052 AD |
945 | \r |
946 | function collapse() {\r | |
947 | $cat_id = db_escape_string($_REQUEST["cid"]);\r | |
948 | $mode = (int) db_escape_string($_REQUEST['mode']);\r | |
949 | toggle_collapse_cat($this->link, $cat_id, $mode);\r | |
950 | }\r | |
951 | \r | |
952 | function index() {\r | |
953 | $root = (bool)$_REQUEST["root"];\r | |
46da73c2 | 954 | \r |
3f363052 | 955 | if (!$root) {\r |
79178062 | 956 | print json_encode($this->outputFeedList($this->link));\r |
3f363052 | 957 | } else {\r |
46da73c2 | 958 | \r |
79178062 | 959 | $feeds = $this->outputFeedList($this->link, false);\r |
46da73c2 | 960 | \r |
3f363052 AD |
961 | $root = array();\r |
962 | $root['id'] = 'root';\r | |
963 | $root['name'] = __('Feeds');\r | |
964 | $root['items'] = $feeds['items'];\r | |
46da73c2 | 965 | \r |
3f363052 AD |
966 | $fl = array();\r |
967 | $fl['identifier'] = 'id';\r | |
968 | $fl['label'] = 'name';\r | |
969 | $fl['items'] = array($root);\r | |
46da73c2 | 970 | \r |
3f363052 AD |
971 | print json_encode($fl);\r |
972 | }\r | |
46da73c2 AD |
973 | }\r |
974 | \r | |
3f363052 AD |
975 | function view() {\r |
976 | $timing_info = getmicrotime();\r | |
46da73c2 | 977 | \r |
3f363052 | 978 | $reply = array();\r |
46da73c2 | 979 | \r |
3f363052 | 980 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);\r |
46da73c2 | 981 | \r |
3f363052 | 982 | $omode = db_escape_string($_REQUEST["omode"]);\r |
46da73c2 | 983 | \r |
3f363052 AD |
984 | $feed = db_escape_string($_REQUEST["feed"]);\r |
985 | $method = db_escape_string($_REQUEST["m"]);\r | |
986 | $view_mode = db_escape_string($_REQUEST["view_mode"]);\r | |
987 | $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");\r | |
988 | @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";\r | |
989 | @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);\r | |
990 | @$offset = db_escape_string($_REQUEST["skip"]);\r | |
991 | @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);\r | |
992 | $order_by = db_escape_string($_REQUEST["order_by"]);\r | |
46da73c2 | 993 | \r |
3f363052 | 994 | if (is_numeric($feed)) $feed = (int) $feed;\r |
46da73c2 | 995 | \r |
3f363052 AD |
996 | /* Feed -5 is a special case: it is used to display auxiliary information\r |
997 | * when there's nothing to load - e.g. no stuff in fresh feed */\r | |
46da73c2 | 998 | \r |
3f363052 AD |
999 | if ($feed == -5) {\r |
1000 | print json_encode(generate_dashboard_feed($this->link));\r | |
1001 | return;\r | |
1002 | }\r | |
46da73c2 | 1003 | \r |
3f363052 | 1004 | $result = false;\r |
46da73c2 | 1005 | \r |
3f363052 AD |
1006 | if ($feed < -10) {\r |
1007 | $label_feed = -11-$feed;\r | |
1008 | $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE\r | |
1009 | id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);\r | |
1010 | } else if (!$cat_view && is_numeric($feed) && $feed > 0) {\r | |
1011 | $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE\r | |
1012 | id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r | |
1013 | } else if ($cat_view && is_numeric($feed) && $feed > 0) {\r | |
1014 | $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE\r | |
1015 | id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r | |
1016 | }\r | |
46da73c2 | 1017 | \r |
3f363052 AD |
1018 | if ($result && db_num_rows($result) == 0) {\r |
1019 | print json_encode(generate_error_feed($this->link, __("Feed not found.")));\r | |
1020 | return;\r | |
1021 | }\r | |
46da73c2 | 1022 | \r |
3f363052 AD |
1023 | /* Updating a label ccache means recalculating all of the caches\r |
1024 | * so for performance reasons we don't do that here */\r | |
46da73c2 | 1025 | \r |
3f363052 AD |
1026 | if ($feed >= 0) {\r |
1027 | ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);\r | |
1028 | }\r | |
46da73c2 | 1029 | \r |
3f363052 AD |
1030 | set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);\r |
1031 | set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);\r | |
1032 | set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);\r | |
46da73c2 | 1033 | \r |
3f363052 AD |
1034 | if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {\r |
1035 | db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()\r | |
1036 | WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);\r | |
1037 | }\r | |
46da73c2 | 1038 | \r |
3f363052 | 1039 | $reply['headlines'] = array();\r |
46da73c2 | 1040 | \r |
3f363052 AD |
1041 | if (!$next_unread_feed)\r |
1042 | $reply['headlines']['id'] = $feed;\r | |
1043 | else\r | |
1044 | $reply['headlines']['id'] = $next_unread_feed;\r | |
46da73c2 | 1045 | \r |
3f363052 | 1046 | $reply['headlines']['is_cat'] = (bool) $cat_view;\r |
46da73c2 | 1047 | \r |
3f363052 | 1048 | $override_order = false;\r |
46da73c2 | 1049 | \r |
3f363052 AD |
1050 | if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {\r |
1051 | $date_sort_field = "updated";\r | |
1052 | } else {\r | |
1053 | $date_sort_field = "date_entered";\r | |
1054 | }\r | |
46da73c2 | 1055 | \r |
3f363052 AD |
1056 | switch ($order_by) {\r |
1057 | case "date":\r | |
1058 | if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r | |
1059 | $override_order = "$date_sort_field";\r | |
1060 | } else {\r | |
1061 | $override_order = "$date_sort_field DESC";\r | |
1062 | }\r | |
1063 | break;\r | |
46da73c2 | 1064 | \r |
3f363052 AD |
1065 | case "title":\r |
1066 | if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r | |
1067 | $override_order = "title DESC, $date_sort_field";\r | |
1068 | } else {\r | |
1069 | $override_order = "title, $date_sort_field DESC";\r | |
1070 | }\r | |
1071 | break;\r | |
46da73c2 | 1072 | \r |
3f363052 AD |
1073 | case "score":\r |
1074 | if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r | |
1075 | $override_order = "score, $date_sort_field";\r | |
1076 | } else {\r | |
1077 | $override_order = "score DESC, $date_sort_field DESC";\r | |
1078 | }\r | |
1079 | break;\r | |
1080 | }\r | |
46da73c2 | 1081 | \r |
3f363052 | 1082 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);\r |
46da73c2 | 1083 | \r |
79178062 | 1084 | $ret = $this->format_headlines_list($feed, $method,\r |
3f363052 AD |
1085 | $view_mode, $limit, $cat_view, $next_unread_feed, $offset,\r |
1086 | $vgroup_last_feed, $override_order);\r | |
46da73c2 | 1087 | \r |
3f363052 AD |
1088 | $topmost_article_ids = $ret[0];\r |
1089 | $headlines_count = $ret[1];\r | |
1090 | $returned_feed = $ret[2];\r | |
1091 | $disable_cache = $ret[3];\r | |
1092 | $vgroup_last_feed = $ret[4];\r | |
46da73c2 | 1093 | \r |
3f363052 AD |
1094 | $reply['headlines']['content'] =& $ret[5]['content'];\r |
1095 | $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];\r | |
46da73c2 | 1096 | \r |
3f363052 | 1097 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);\r |
46da73c2 | 1098 | \r |
3f363052 AD |
1099 | $reply['headlines-info'] = array("count" => (int) $headlines_count,\r |
1100 | "vgroup_last_feed" => $vgroup_last_feed,\r | |
1101 | "disable_cache" => (bool) $disable_cache);\r | |
46da73c2 | 1102 | \r |
3f363052 | 1103 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);\r |
46da73c2 | 1104 | \r |
3f363052 AD |
1105 | if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {\r |
1106 | $articles = array();\r | |
46da73c2 | 1107 | \r |
3f363052 AD |
1108 | foreach ($topmost_article_ids as $id) {\r |
1109 | array_push($articles, format_article($this->link, $id, false));\r | |
1110 | }\r | |
46da73c2 | 1111 | \r |
3f363052 AD |
1112 | $reply['articles'] = $articles;\r |
1113 | }\r | |
46da73c2 | 1114 | \r |
3f363052 | 1115 | if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);\r |
46da73c2 | 1116 | \r |
3f363052 | 1117 | $reply['runtime-info'] = make_runtime_info($this->link);\r |
46da73c2 | 1118 | \r |
3f363052 | 1119 | print json_encode($reply);\r |
46da73c2 | 1120 | \r |
3f363052 AD |
1121 | }\r |
1122 | }\r | |
46da73c2 | 1123 | ?>\r |