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