]> git.wh0rd.org Git - tt-rss.git/blob - classes/feeds.php
simplify catching up of feeds, do not reload headlines buffer on catchup unless on_ca...
[tt-rss.git] / classes / feeds.php
1 <?php\r
2 class Feeds extends Protected_Handler {\r
3 \r
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
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
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
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
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
156                 //$reply .= "</div>";\r
157 \r
158                 //$reply .= "</h2";\r
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 == "ForceUpdate" && $feed && is_numeric($feed) > 0) {\r
181                         include "rssfuncs.php";\r
182                         update_rss_feed($this->link, $feed, true);\r
183                 }\r
184 \r
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
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
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
381                                         $content_preview = truncate_string(strip_tags($line["content_preview"]),\r
382                                                 100);\r
383                                 }\r
384 \r
385                                 $score = $line["score"];\r
386 \r
387                                 $score_pic = theme_image($this->link,\r
388                                         "images/" . get_score_pic($score));\r
389 \r
390 /*                              $score_title = __("(Click to change)");\r
391                                 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"\r
392                                         onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */\r
393 \r
394                                 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"\r
395                                         title=\"$score\">";\r
396 \r
397                                 if ($score > 500) {\r
398                                         $hlc_suffix = "H";\r
399                                 } else if ($score < -100) {\r
400                                         $hlc_suffix = "L";\r
401                                 } else {\r
402                                         $hlc_suffix = "";\r
403                                 }\r
404 \r
405                                 $entry_author = $line["author"];\r
406 \r
407                                 if ($entry_author) {\r
408                                         $entry_author = " - $entry_author";\r
409                                 }\r
410 \r
411                                 $has_feed_icon = feed_has_icon($feed_id);\r
412 \r
413                                 if ($has_feed_icon) {\r
414                                         $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";\r
415                                 } else {\r
416                                         $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";\r
417                                 }\r
418 \r
419                                 if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {\r
420 \r
421                                         if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {\r
422                                                 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {\r
423 \r
424                                                         $cur_feed_title = $line["feed_title"];\r
425                                                         $vgroup_last_feed = $feed_id;\r
426 \r
427                                                         $cur_feed_title = htmlspecialchars($cur_feed_title);\r
428 \r
429                                                         $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";\r
430 \r
431                                                         $reply['content'] .= "<div class='cdmFeedTitle'>".\r
432                                                                 "<div style=\"float : right\">$feed_icon_img</div>".\r
433                                                                 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
434                                                                 $line["feed_title"]."</a> $vf_catchup_link</div>";\r
435 \r
436                                                 }\r
437                                         }\r
438 \r
439                                         $mouseover_attrs = "onmouseover='postMouseIn($id)'\r
440                                                 onmouseout='postMouseOut($id)'";\r
441 \r
442                                         $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";\r
443 \r
444                                         $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";\r
445 \r
446                                         $reply['content'] .= "<div class='hlLeft'>";\r
447 \r
448                                         $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"\r
449                                                         id=\"RCHK-$id\">";\r
450 \r
451                                         $reply['content'] .= "$marked_pic";\r
452                                         $reply['content'] .= "$published_pic";\r
453 \r
454                                         $reply['content'] .= "</div>";\r
455 \r
456                                         $reply['content'] .= "<div onclick='return hlClicked(event, $id)'\r
457                                                 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";\r
458                                         $reply['content'] .= "<a id=\"RTITLE-$id\"\r
459                                                 href=\"" . htmlspecialchars($line["link"]) . "\"\r
460                                                 onclick=\"\">" .\r
461                                                 truncate_string($line["title"], 200);\r
462 \r
463                                         if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {\r
464                                                 if ($content_preview) {\r
465                                                         $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";\r
466                                                 }\r
467                                         }\r
468 \r
469                                         $reply['content'] .= "</a></span>";\r
470 \r
471                                         $reply['content'] .= $labels_str;\r
472 \r
473                                         if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&\r
474                                                 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {\r
475                                                 if (@$line["feed_title"]) {\r
476                                                         $reply['content'] .= "<span class=\"hlFeed\">\r
477                                                                 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
478                                                                 $line["feed_title"]."</a>)\r
479                                                         </span>";\r
480                                                 }\r
481                                         }\r
482 \r
483                                         $reply['content'] .= "</div>";\r
484 \r
485                                         $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";\r
486                                         $reply['content'] .= "<div class=\"hlRight\">";\r
487 \r
488                                         $reply['content'] .= $score_pic;\r
489 \r
490                                         if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {\r
491 \r
492                                                 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"\r
493                                                         style=\"cursor : pointer\"\r
494                                                         title=\"".htmlspecialchars($line['feed_title'])."\">\r
495                                                         $feed_icon_img<span>";\r
496                                         }\r
497 \r
498                                         $reply['content'] .= "</div>";\r
499                                         $reply['content'] .= "</div>";\r
500 \r
501                                 } else {\r
502 \r
503                                         if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {\r
504                                                 if ($feed_id != $vgroup_last_feed) {\r
505 \r
506                                                         $cur_feed_title = $line["feed_title"];\r
507                                                         $vgroup_last_feed = $feed_id;\r
508 \r
509                                                         $cur_feed_title = htmlspecialchars($cur_feed_title);\r
510 \r
511                                                         $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";\r
512 \r
513                                                         $has_feed_icon = feed_has_icon($feed_id);\r
514 \r
515                                                         if ($has_feed_icon) {\r
516                                                                 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";\r
517                                                         } else {\r
518                                                                 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";\r
519                                                         }\r
520 \r
521                                                         $reply['content'] .= "<div class='cdmFeedTitle'>".\r
522                                                                 "<div style=\"float : right\">$feed_icon_img</div>".\r
523                                                                 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
524                                                                 $line["feed_title"]."</a> $vf_catchup_link</div>";\r
525                                                 }\r
526                                         }\r
527 \r
528                                         $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');\r
529 \r
530                                         $mouseover_attrs = "onmouseover='postMouseIn($id)'\r
531                                                 onmouseout='postMouseOut($id)'";\r
532 \r
533                                         $reply['content'] .= "<div class=\"$class\"\r
534                                                 id=\"RROW-$id\" $mouseover_attrs'>";\r
535 \r
536                                         $reply['content'] .= "<div class=\"cdmHeader\">";\r
537 \r
538                                         $reply['content'] .= "<div>";\r
539 \r
540                                         $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,\r
541                                                         'RROW-$id')\" id=\"RCHK-$id\"/>";\r
542 \r
543                                         $reply['content'] .= "$marked_pic";\r
544                                         $reply['content'] .= "$published_pic";\r
545 \r
546                                         $reply['content'] .= "</div>";\r
547 \r
548                                         $reply['content'] .= "<span id=\"RTITLE-$id\"\r
549                                                 onclick=\"return cdmClicked(event, $id);\"\r
550                                                 class=\"titleWrap$hlc_suffix\">\r
551                                                 <a class=\"title\"\r
552                                                 title=\"".htmlspecialchars($line['title'])."\"\r
553                                                 target=\"_blank\" href=\"".\r
554                                                 htmlspecialchars($line["link"])."\">".\r
555                                                 truncate_string($line["title"], 100) .\r
556                                                 " $entry_author</a>";\r
557 \r
558                                         $reply['content'] .= $labels_str;\r
559 \r
560                                         if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&\r
561                                                 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {\r
562                                                 if (@$line["feed_title"]) {\r
563                                                         $reply['content'] .= "<span class=\"hlFeed\">\r
564                                                                 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".\r
565                                                                 $line["feed_title"]."</a>)\r
566                                                         </span>";\r
567                                                 }\r
568                                         }\r
569 \r
570                                         if (!$expand_cdm)\r
571                                                 $content_hidden = "style=\"display : none\"";\r
572                                         else\r
573                                                 $excerpt_hidden = "style=\"display : none\"";\r
574 \r
575                                         $reply['content'] .= "<span $excerpt_hidden\r
576                                                 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";\r
577 \r
578                                         $reply['content'] .= "</span>";\r
579 \r
580                                         $reply['content'] .= "<div>";\r
581                                         $reply['content'] .= "<span class='updated'>$updated_fmt</span>";\r
582                                         $reply['content'] .= "$score_pic";\r
583 \r
584                                         if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {\r
585                                                 $reply['content'] .= "<span style=\"cursor : pointer\"\r
586                                                         title=\"".htmlspecialchars($line["feed_title"])."\"\r
587                                                         onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";\r
588                                         }\r
589                                         $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";\r
590                                         $reply['content'] .= "</div>";\r
591 \r
592                                         $reply['content'] .= "</div>";\r
593 \r
594                                         $reply['content'] .= "<div class=\"cdmContent\" $content_hidden\r
595                                                 onclick=\"return cdmClicked(event, $id);\"\r
596                                                 id=\"CICD-$id\">";\r
597 \r
598                                         $reply['content'] .= "<div class=\"cdmContentInner\">";\r
599 \r
600                         if ($line["orig_feed_id"]) {\r
601 \r
602                                 $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds\r
603                                         WHERE id = ".$line["orig_feed_id"]);\r
604 \r
605                                                 if (db_num_rows($tmp_result) != 0) {\r
606 \r
607                                                         $reply['content'] .= "<div clear='both'>";\r
608                                                         $reply['content'] .= __("Originally from:");\r
609 \r
610                                                         $reply['content'] .= "&nbsp;";\r
611 \r
612                                                         $tmp_line = db_fetch_assoc($tmp_result);\r
613 \r
614                                                         $reply['content'] .= "<a target='_blank'\r
615                                                                 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .\r
616                                                                 $tmp_line['title'] . "</a>";\r
617 \r
618                                                         $reply['content'] .= "&nbsp;";\r
619 \r
620                                                         $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";\r
621                                                         $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";\r
622 \r
623                                                         $reply['content'] .= "</div>";\r
624                                                 }\r
625                                         }\r
626 \r
627                                         $feed_site_url = $line["site_url"];\r
628 \r
629                                         $article_content = sanitize($this->link, $line["content_preview"],\r
630                                                         false, false, $feed_site_url);\r
631 \r
632                                         $reply['content'] .= "<div id=\"POSTNOTE-$id\">";\r
633                                         if ($line['note']) {\r
634                                                 $reply['content'] .= format_article_note($id, $line['note']);\r
635                                         }\r
636                                         $reply['content'] .= "</div>";\r
637 \r
638                                         $reply['content'] .= "<span id=\"CWRAP-$id\">";\r
639                                         $reply['content'] .= $expand_cdm ? $article_content : '';\r
640                                         $reply['content'] .= "</span>";\r
641 \r
642 /*                                      $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM\r
643                                                 ttrss_feeds WHERE id = ".\r
644                                                 (($line['feed_id'] == null) ? $line['orig_feed_id'] :\r
645                                                         $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);\r
646 \r
647                                         $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,\r
648                                                 0, "always_display_enclosures")); */\r
649 \r
650                                         $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);\r
651 \r
652                                         $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,\r
653                                                 $article_content);\r
654 \r
655                                         $reply['content'] .= "</div>";\r
656 \r
657                                         $reply['content'] .= "<div class=\"cdmFooter\">";\r
658 \r
659                                         $tag_cache = $line["tag_cache"];\r
660 \r
661                                         $tags_str = format_tags_string(\r
662                                                 get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),\r
663                                                 $id);\r
664 \r
665                                         $reply['content'] .= "<img src='".theme_image($this->link,\r
666                                                         'images/tag.png')."' alt='Tags' title='Tags'>\r
667                                                 <span id=\"ATSTR-$id\">$tags_str</span>\r
668                                                 <a title=\"".__('Edit tags for this article')."\"\r
669                                                 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";\r
670 \r
671                                         $num_comments = $line["num_comments"];\r
672                                         $entry_comments = "";\r
673 \r
674                                         if ($num_comments > 0) {\r
675                                                 if ($line["comments"]) {\r
676                                                         $comments_url = $line["comments"];\r
677                                                 } else {\r
678                                                         $comments_url = $line["link"];\r
679                                                 }\r
680                                                 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";\r
681                                         } else {\r
682                                                 if ($line["comments"] && $line["link"] != $line["comments"]) {\r
683                                                         $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";\r
684                                                 }\r
685                                         }\r
686 \r
687                                         if ($entry_comments) $reply['content'] .= "&nbsp;($entry_comments)";\r
688 \r
689                                         $reply['content'] .= "<div style=\"float : right\">";\r
690 \r
691                                         $reply['content'] .= "<img src=\"images/art-zoom.png\"\r
692                                                 onclick=\"zoomToArticle(event, $id)\"\r
693                                                 style=\"cursor : pointer\"\r
694                                                 alt='Zoom'\r
695                                                 title='".__('Open article in new tab')."'>";\r
696 \r
697                                         //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);\r
698 \r
699                                         foreach ($button_plugins as $p) {\r
700                                                 $reply['content'] .= $p->render($id, $line);\r
701                                         }\r
702 \r
703                                         $reply['content'] .= "<img src=\"images/digest_checkbox.png\"\r
704                                                 style=\"cursor : pointer\" style=\"cursor : pointer\"\r
705                                                 onclick=\"dismissArticle($id)\"\r
706                                                 title='".__('Close article')."'>";\r
707 \r
708                                         $reply['content'] .= "</div>";\r
709                                         $reply['content'] .= "</div>";\r
710 \r
711                                         $reply['content'] .= "</div>";\r
712 \r
713                                         $reply['content'] .= "</div>";\r
714 \r
715                                 }\r
716 \r
717                                 ++$lnum;\r
718                         }\r
719 \r
720                         if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);\r
721 \r
722                 } else {\r
723                         $message = "";\r
724 \r
725                         switch ($view_mode) {\r
726                                 case "unread":\r
727                                         $message = __("No unread articles found to display.");\r
728                                         break;\r
729                                 case "updated":\r
730                                         $message = __("No updated articles found to display.");\r
731                                         break;\r
732                                 case "marked":\r
733                                         $message = __("No starred articles found to display.");\r
734                                         break;\r
735                                 default:\r
736                                         if ($feed < -10) {\r
737                                                 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");\r
738                                         } else {\r
739                                                 $message = __("No articles found to display.");\r
740                                         }\r
741                         }\r
742 \r
743                         if (!$offset && $message) {\r
744                                 $reply['content'] .= "<div class='whiteBox'>$message";\r
745 \r
746                                 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";\r
747 \r
748                                 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds\r
749                                         WHERE owner_uid = " . $_SESSION['uid']);\r
750 \r
751                                 $last_updated = db_fetch_result($result, 0, "last_updated");\r
752                                 $last_updated = make_local_datetime($this->link, $last_updated, false);\r
753 \r
754                                 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);\r
755 \r
756                                 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors\r
757                                         FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);\r
758 \r
759                                 $num_errors = db_fetch_result($result, 0, "num_errors");\r
760 \r
761                                 if ($num_errors > 0) {\r
762                                         $reply['content'] .= "<br/>";\r
763                                         $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".\r
764                                                 __('Some feeds have update errors (click for details)')."</a>";\r
765                                 }\r
766                                 $reply['content'] .= "</span></p></div>";\r
767                         }\r
768                 }\r
769 \r
770                 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);\r
771 \r
772                 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,\r
773                         $vgroup_last_feed, $reply);\r
774         }\r
775 \r
776         private function outputFeedList($special = true) {\r
777 \r
778                 $feedlist = array();\r
779 \r
780                 $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');\r
781 \r
782                 $feedlist['identifier'] = 'id';\r
783                 $feedlist['label'] = 'name';\r
784                 $feedlist['items'] = array();\r
785 \r
786                 $owner_uid = $_SESSION["uid"];\r
787 \r
788                 /* virtual feeds */\r
789 \r
790                 if ($special) {\r
791 \r
792                         if ($enable_cats) {\r
793                                 $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");\r
794                                 $cat = $this->feedlist_init_cat(-1, $cat_hidden);\r
795                         } else {\r
796                                 $cat['items'] = array();\r
797                         }\r
798 \r
799                         foreach (array(-4, -3, -1, -2, 0) as $i) {\r
800                                 array_push($cat['items'], $this->feedlist_init_feed($i));\r
801                         }\r
802 \r
803                         if ($enable_cats) {\r
804                                 array_push($feedlist['items'], $cat);\r
805                         } else {\r
806                                 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);\r
807                         }\r
808 \r
809                         $result = db_query($this->link, "SELECT * FROM\r
810                                 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");\r
811 \r
812                         if (db_num_rows($result) > 0) {\r
813 \r
814                                 if (get_pref($this->link, 'ENABLE_FEED_CATS')) {\r
815                                         $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");\r
816                                         $cat = $this->feedlist_init_cat(-2, $cat_hidden);\r
817                                 } else {\r
818                                         $cat['items'] = array();\r
819                                 }\r
820 \r
821                                 while ($line = db_fetch_assoc($result)) {\r
822 \r
823                                         $label_id = -$line['id'] - 11;\r
824                                         $count = getFeedUnread($this->link, $label_id);\r
825 \r
826                                         $feed = $this->feedlist_init_feed($label_id, false, $count);\r
827 \r
828                                         $feed['fg_color'] = $line['fg_color'];\r
829                                         $feed['bg_color'] = $line['bg_color'];\r
830 \r
831                                         array_push($cat['items'], $feed);\r
832                                 }\r
833 \r
834                                 if ($enable_cats) {\r
835                                         array_push($feedlist['items'], $cat);\r
836                                 } else {\r
837                                         $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);\r
838                                 }\r
839                         }\r
840                 }\r
841 \r
842 /*              if (get_pref($this->link, 'ENABLE_FEED_CATS')) {\r
843                         if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {\r
844                                 $order_by_qpart = "order_id,category,unread DESC,title";\r
845                         } else {\r
846                                 $order_by_qpart = "order_id,category,title";\r
847                         }\r
848                 } else {\r
849                         if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {\r
850                                 $order_by_qpart = "unread DESC,title";\r
851                         } else {\r
852                                 $order_by_qpart = "title";\r
853                         }\r
854                 } */\r
855 \r
856                 /* real feeds */\r
857 \r
858                 if ($enable_cats)\r
859                         $order_by_qpart = "ttrss_feed_categories.order_id,category,\r
860                                 ttrss_feeds.order_id,title";\r
861                 else\r
862                         $order_by_qpart = "title";\r
863 \r
864                 $age_qpart = getMaxAgeSubquery();\r
865 \r
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
869                         ttrss_feed_categories.title AS category,\r
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
905                                 if (!$tmp_category) $tmp_category = __("Uncategorized");\r
906 \r
907                                 if ($category != $tmp_category && $enable_cats) {\r
908 \r
909                                         $category = $tmp_category;\r
910 \r
911                                         $collapsed = sql_bool_to_bool($line["collapsed"]);\r
912 \r
913                                         // workaround for NULL category\r
914                                         if ($category == __("Uncategorized")) {\r
915                                                 $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT");\r
916                                         }\r
917 \r
918                                         if ($cat) array_push($feedlist['items'], $cat);\r
919 \r
920                                         $cat = $this->feedlist_init_cat($cat_id, $collapsed);\r
921                                 }\r
922 \r
923                                 $updated = make_local_datetime($this->link, $line["updated_noms"], false);\r
924 \r
925                                 array_push($cat['items'], $this->feedlist_init_feed($feed_id,\r
926                                         $feed, $unread, $line['last_error'], $updated));\r
927                         }\r
928 \r
929                         if ($enable_cats) {\r
930                                 array_push($feedlist['items'], $cat);\r
931                         } else {\r
932                                 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);\r
933                         }\r
934 \r
935                 }\r
936 \r
937                 return $feedlist;\r
938         }\r
939 \r
940 \r
941         function catchupAll() {\r
942                 db_query($this->link, "UPDATE ttrss_user_entries SET\r
943                                                 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);\r
944                 ccache_zero_all($this->link, $_SESSION["uid"]);\r
945         }\r
946 \r
947         function collapse() {\r
948                 $cat_id = db_escape_string($_REQUEST["cid"]);\r
949                 $mode = (int) db_escape_string($_REQUEST['mode']);\r
950                 toggle_collapse_cat($this->link, $cat_id, $mode);\r
951         }\r
952 \r
953         function index() {\r
954                 $root = (bool)$_REQUEST["root"];\r
955 \r
956                 if (!$root) {\r
957                         print json_encode($this->outputFeedList($this->link));\r
958                 } else {\r
959 \r
960                         $feeds = $this->outputFeedList($this->link, false);\r
961 \r
962                         $root = array();\r
963                         $root['id'] = 'root';\r
964                         $root['name'] = __('Feeds');\r
965                         $root['items'] = $feeds['items'];\r
966 \r
967                         $fl = array();\r
968                         $fl['identifier'] = 'id';\r
969                         $fl['label'] = 'name';\r
970                         $fl['items'] = array($root);\r
971 \r
972                         print json_encode($fl);\r
973                 }\r
974         }\r
975 \r
976         function view() {\r
977                 $timing_info = getmicrotime();\r
978 \r
979                 $reply = array();\r
980 \r
981                 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);\r
982 \r
983                 $omode = db_escape_string($_REQUEST["omode"]);\r
984 \r
985                 $feed = db_escape_string($_REQUEST["feed"]);\r
986                 $method = db_escape_string($_REQUEST["m"]);\r
987                 $view_mode = db_escape_string($_REQUEST["view_mode"]);\r
988                 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");\r
989                 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";\r
990                 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);\r
991                 @$offset = db_escape_string($_REQUEST["skip"]);\r
992                 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);\r
993                 $order_by = db_escape_string($_REQUEST["order_by"]);\r
994 \r
995                 if (is_numeric($feed)) $feed = (int) $feed;\r
996 \r
997                 /* Feed -5 is a special case: it is used to display auxiliary information\r
998                  * when there's nothing to load - e.g. no stuff in fresh feed */\r
999 \r
1000                 if ($feed == -5) {\r
1001                         print json_encode(generate_dashboard_feed($this->link));\r
1002                         return;\r
1003                 }\r
1004 \r
1005                 $result = false;\r
1006 \r
1007                 if ($feed < -10) {\r
1008                         $label_feed = -11-$feed;\r
1009                         $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE\r
1010                                                         id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);\r
1011                 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {\r
1012                         $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE\r
1013                                                         id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r
1014                 } else if ($cat_view && is_numeric($feed) && $feed > 0) {\r
1015                         $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE\r
1016                                                         id = '$feed' AND owner_uid = " . $_SESSION['uid']);\r
1017                 }\r
1018 \r
1019                 if ($result && db_num_rows($result) == 0) {\r
1020                         print json_encode(generate_error_feed($this->link, __("Feed not found.")));\r
1021                         return;\r
1022                 }\r
1023 \r
1024                 /* Updating a label ccache means recalculating all of the caches\r
1025                  * so for performance reasons we don't do that here */\r
1026 \r
1027                 if ($feed >= 0) {\r
1028                         ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);\r
1029                 }\r
1030 \r
1031                 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);\r
1032                 set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);\r
1033                 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);\r
1034 \r
1035                 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {\r
1036                         db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()\r
1037                                                         WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);\r
1038                 }\r
1039 \r
1040                 $reply['headlines'] = array();\r
1041 \r
1042                 if (!$next_unread_feed)\r
1043                         $reply['headlines']['id'] = $feed;\r
1044                 else\r
1045                         $reply['headlines']['id'] = $next_unread_feed;\r
1046 \r
1047                 $reply['headlines']['is_cat'] = (bool) $cat_view;\r
1048 \r
1049                 $override_order = false;\r
1050 \r
1051                 if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {\r
1052                         $date_sort_field = "updated";\r
1053                 } else {\r
1054                         $date_sort_field = "date_entered";\r
1055                 }\r
1056 \r
1057                 switch ($order_by) {\r
1058                         case "date":\r
1059                                 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
1060                                         $override_order = "$date_sort_field";\r
1061                                 } else {\r
1062                                         $override_order = "$date_sort_field DESC";\r
1063                                 }\r
1064                                 break;\r
1065 \r
1066                         case "title":\r
1067                                 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
1068                                         $override_order = "title DESC, $date_sort_field";\r
1069                                 } else {\r
1070                                         $override_order = "title, $date_sort_field DESC";\r
1071                                 }\r
1072                                 break;\r
1073 \r
1074                         case "score":\r
1075                                 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {\r
1076                                         $override_order = "score, $date_sort_field";\r
1077                                 } else {\r
1078                                         $override_order = "score DESC, $date_sort_field DESC";\r
1079                                 }\r
1080                                 break;\r
1081                 }\r
1082 \r
1083                 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);\r
1084 \r
1085                 $ret = $this->format_headlines_list($feed, $method,\r
1086                         $view_mode, $limit, $cat_view, $next_unread_feed, $offset,\r
1087                         $vgroup_last_feed, $override_order);\r
1088 \r
1089                 $topmost_article_ids = $ret[0];\r
1090                 $headlines_count = $ret[1];\r
1091                 $returned_feed = $ret[2];\r
1092                 $disable_cache = $ret[3];\r
1093                 $vgroup_last_feed = $ret[4];\r
1094 \r
1095                 $reply['headlines']['content'] =& $ret[5]['content'];\r
1096                 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];\r
1097 \r
1098                 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);\r
1099 \r
1100                 $reply['headlines-info'] = array("count" => (int) $headlines_count,\r
1101                                                 "vgroup_last_feed" => $vgroup_last_feed,\r
1102                                                 "disable_cache" => (bool) $disable_cache);\r
1103 \r
1104                 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);\r
1105 \r
1106                 if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {\r
1107                         $articles = array();\r
1108 \r
1109                         foreach ($topmost_article_ids as $id) {\r
1110                                 array_push($articles, format_article($this->link, $id, false));\r
1111                         }\r
1112 \r
1113                         $reply['articles'] = $articles;\r
1114                 }\r
1115 \r
1116                 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);\r
1117 \r
1118                 $reply['runtime-info'] = make_runtime_info($this->link);\r
1119 \r
1120                 print json_encode($reply);\r
1121 \r
1122         }\r
1123 }\r
1124 ?>\r