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