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