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