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