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