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