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