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