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