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