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