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