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