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