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