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