]> git.wh0rd.org - tt-rss.git/blob - classes/feeds.php
experimental CSRF protection
[tt-rss.git] / classes / feeds.php
1 <?php
2 class Feeds extends Protected_Handler {
3
4 function csrf_ignore($method) {
5 $csrf_ignored = array("index");
6
7 return array_search($method, $csrf_ignored) !== false;
8 }
9
10 private function feedlist_init_cat($cat_id, $hidden = false) {
11 $obj = array();
12 $cat_id = (int) $cat_id;
13
14 if ($cat_id > 0) {
15 $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);
16 } else if ($cat_id == 0 || $cat_id == -2) {
17 $cat_unread = getCategoryUnread($this->link, $cat_id);
18 }
19
20 $obj['id'] = 'CAT:' . $cat_id;
21 $obj['items'] = array();
22 $obj['name'] = getCategoryTitle($this->link, $cat_id);
23 $obj['type'] = 'feed';
24 $obj['unread'] = (int) $cat_unread;
25 $obj['hidden'] = $hidden;
26 $obj['bare_id'] = $cat_id;
27
28 return $obj;
29 }
30
31 private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
32 $obj = array();
33 $feed_id = (int) $feed_id;
34
35 if (!$title)
36 $title = getFeedTitle($this->link, $feed_id, false);
37
38 if ($unread === false)
39 $unread = getFeedUnread($this->link, $feed_id, false);
40
41 $obj['id'] = 'FEED:' . $feed_id;
42 $obj['name'] = $title;
43 $obj['unread'] = (int) $unread;
44 $obj['type'] = 'feed';
45 $obj['error'] = $error;
46 $obj['updated'] = $updated;
47 $obj['icon'] = getFeedIcon($feed_id);
48 $obj['bare_id'] = $feed_id;
49
50 return $obj;
51 }
52
53 private function format_headline_subtoolbar($feed_site_url, $feed_title,
54 $feed_id, $is_cat, $search, $match_on,
55 $search_mode, $view_mode, $error) {
56
57 $page_prev_link = "viewFeedGoPage(-1)";
58 $page_next_link = "viewFeedGoPage(1)";
59 $page_first_link = "viewFeedGoPage(0)";
60
61 $catchup_page_link = "catchupPage()";
62 $catchup_feed_link = "catchupCurrentFeed()";
63 $catchup_sel_link = "catchupSelection()";
64
65 $archive_sel_link = "archiveSelection()";
66 $delete_sel_link = "deleteSelection()";
67
68 $sel_all_link = "selectArticles('all')";
69 $sel_unread_link = "selectArticles('unread')";
70 $sel_none_link = "selectArticles('none')";
71 $sel_inv_link = "selectArticles('invert')";
72
73 $tog_unread_link = "selectionToggleUnread()";
74 $tog_marked_link = "selectionToggleMarked()";
75 $tog_published_link = "selectionTogglePublished()";
76
77 if ($is_cat) $cat_q = "&is_cat=$is_cat";
78
79 if ($search) {
80 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
81 } else {
82 $search_q = "";
83 }
84
85 $rss_link = htmlspecialchars(get_self_url_prefix() .
86 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
87
88 // right part
89
90 $reply .= "<span class='r'>";
91
92 if ($feed_site_url) {
93 $target = "target=\"_blank\"";
94 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
95 truncate_string($feed_title,30)."</a>";
96
97 if ($error) {
98 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
99 }
100
101 } else {
102 $reply .= $feed_title;
103 }
104
105 $reply .= "
106 <a href=\"#\"
107 title=\"".__("View as RSS feed")."\"
108 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
109 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
110
111 $reply .= "</span>";
112
113 // left part
114
115 $reply .= __('Select:')."
116 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
117 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
118 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
119 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
120
121 $reply .= " ";
122
123 $reply .= "<select dojoType=\"dijit.form.Select\"
124 onchange=\"headlineActionsChange(this)\">";
125 $reply .= "<option value=\"false\">".__('Actions...')."</option>";
126
127 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
128
129 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
130 <option value=\"$tog_marked_link\">".__('Starred')."</option>
131 <option value=\"$tog_published_link\">".__('Published')."</option>";
132
133 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
134
135 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
136
137 if ($feed_id != "0") {
138 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
139 } else {
140 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
141 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
142
143 }
144
145 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
146 "</option>";
147
148 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
149
150 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
151
152 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
153
154 $reply .= "</select>";
155
156 //$reply .= "</div>";
157
158 //$reply .= "</h2";
159
160 return $reply;
161 }
162
163 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
164 $next_unread_feed, $offset, $vgr_last_feed = false,
165 $override_order = false) {
166
167 $disable_cache = false;
168
169 $reply = array();
170
171 $timing_info = getmicrotime();
172
173 $topmost_article_ids = array();
174
175 if (!$offset) $offset = 0;
176 if ($method == "undefined") $method = "";
177
178 $method_split = explode(":", $method);
179
180 /* if ($method == "CatchupSelected") {
181 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
182 $cmode = sprintf("%d", $_REQUEST["cmode"]);
183
184 catchupArticlesById($this->link, $ids, $cmode);
185 } */
186
187 //if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
188 // update_rss_feed($this->link, $feed, true);
189 //}
190
191 if ($method == "MarkAllRead") {
192 catchup_feed($this->link, $feed, $cat_view);
193
194 if (get_pref($this->link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
195 if ($next_unread_feed) {
196 $feed = $next_unread_feed;
197 }
198 }
199 }
200
201 if ($method_split[0] == "MarkAllReadGR") {
202 catchup_feed($this->link, $method_split[1], false);
203 }
204
205 // FIXME: might break tag display?
206
207 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
208 $result = db_query($this->link,
209 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
210
211 if (db_num_rows($result) == 0) {
212 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
213 }
214 }
215
216 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
217
218 $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds
219 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
220
221 if (db_num_rows($result) == 1) {
222 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
223 } else {
224 $rtl_content = false;
225 }
226
227 if ($rtl_content) {
228 $rtl_tag = "dir=\"RTL\"";
229 } else {
230 $rtl_tag = "";
231 }
232 } else {
233 $rtl_tag = "";
234 $rtl_content = false;
235 }
236
237 @$search = db_escape_string($_REQUEST["query"]);
238
239 if ($search) {
240 $disable_cache = true;
241 }
242
243 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
244 @$match_on = db_escape_string($_REQUEST["match_on"]);
245
246 if (!$match_on) {
247 $match_on = "both";
248 }
249
250 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
251
252 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
253 if( $search_mode == '' && $method != '' ){
254 $search_mode = $method;
255 }
256 // error_log("search_mode: " . $search_mode);
257 $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,
258 $search, $search_mode, $match_on, $override_order, $offset);
259
260 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
261
262 $result = $qfh_ret[0];
263 $feed_title = $qfh_ret[1];
264 $feed_site_url = $qfh_ret[2];
265 $last_error = $qfh_ret[3];
266
267 $vgroup_last_feed = $vgr_last_feed;
268
269 // if (!$offset) {
270
271 if (db_num_rows($result) > 0) {
272 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
273 $feed_title,
274 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
275 $last_error);
276 }
277 // }
278
279 $headlines_count = db_num_rows($result);
280
281 if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
282 $button_plugins = array();
283 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
284 $pclass = trim("${p}_button");
285
286 if (class_exists($pclass)) {
287 $plugin = new $pclass($link);
288 array_push($button_plugins, $plugin);
289 }
290 }
291 }
292
293 if (db_num_rows($result) > 0) {
294
295 $lnum = $offset;
296
297 $num_unread = 0;
298 $cur_feed_title = '';
299
300 $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
301
302 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
303
304 while ($line = db_fetch_assoc($result)) {
305
306 $class = ($lnum % 2) ? "even" : "odd";
307
308 $id = $line["id"];
309 $feed_id = $line["feed_id"];
310 $label_cache = $line["label_cache"];
311 $labels = false;
312
313 if ($label_cache) {
314 $label_cache = json_decode($label_cache, true);
315
316 if ($label_cache) {
317 if ($label_cache["no-labels"] == 1)
318 $labels = array();
319 else
320 $labels = $label_cache;
321 }
322 }
323
324 if (!is_array($labels)) $labels = get_article_labels($this->link, $id);
325
326 $labels_str = "<span id=\"HLLCTR-$id\">";
327 $labels_str .= format_article_labels($labels, $id);
328 $labels_str .= "</span>";
329
330 if (count($topmost_article_ids) < 3) {
331 array_push($topmost_article_ids, $id);
332 }
333
334 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
335
336 $update_pic = "<img id='FUPDPIC-$id' src=\"".
337 theme_image($this->link, 'images/updated.png')."\"
338 alt=\"Updated\">";
339 } else {
340 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
341 alt=\"Updated\">";
342 }
343
344 if (sql_bool_to_bool($line["unread"]) &&
345 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
346
347 $update_pic = "<img id='FUPDPIC-$id' src=\"".
348 theme_image($this->link, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
349 }
350
351 if ($line["unread"] == "t" || $line["unread"] == "1") {
352 $class .= " Unread";
353 ++$num_unread;
354 $is_unread = true;
355 } else {
356 $is_unread = false;
357 }
358
359 if ($line["marked"] == "t" || $line["marked"] == "1") {
360 $marked_pic = "<img id=\"FMPIC-$id\"
361 src=\"".theme_image($this->link, 'images/mark_set.png')."\"
362 class=\"markedPic\" alt=\"Unstar article\"
363 onclick='javascript:toggleMark($id)'>";
364 } else {
365 $marked_pic = "<img id=\"FMPIC-$id\"
366 src=\"".theme_image($this->link, 'images/mark_unset.png')."\"
367 class=\"markedPic\" alt=\"Star article\"
368 onclick='javascript:toggleMark($id)'>";
369 }
370
371 if ($line["published"] == "t" || $line["published"] == "1") {
372 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
373 'images/pub_set.png')."\"
374 class=\"markedPic\"
375 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
376 } else {
377 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
378 'images/pub_unset.png')."\"
379 class=\"markedPic\"
380 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
381 }
382
383 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
384 # $line["title"] . "</a>";
385
386 # $content_link = "<a
387 # href=\"" . htmlspecialchars($line["link"]) . "\"
388 # onclick=\"view($id,$feed_id);\">" .
389 # $line["title"] . "</a>";
390
391 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
392 # $line["title"] . "</a>";
393
394 $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);
395
396 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
397 $content_preview = truncate_string(strip_tags($line["content_preview"]),
398 100);
399 }
400
401 $score = $line["score"];
402
403 $score_pic = theme_image($this->link,
404 "images/" . get_score_pic($score));
405
406 /* $score_title = __("(Click to change)");
407 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
408 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
409
410 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
411 title=\"$score\">";
412
413 if ($score > 500) {
414 $hlc_suffix = "H";
415 } else if ($score < -100) {
416 $hlc_suffix = "L";
417 } else {
418 $hlc_suffix = "";
419 }
420
421 $entry_author = $line["author"];
422
423 if ($entry_author) {
424 $entry_author = " - $entry_author";
425 }
426
427 $has_feed_icon = feed_has_icon($feed_id);
428
429 if ($has_feed_icon) {
430 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
431 } else {
432 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
433 }
434
435 if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
436
437 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
438 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
439
440 $cur_feed_title = $line["feed_title"];
441 $vgroup_last_feed = $feed_id;
442
443 $cur_feed_title = htmlspecialchars($cur_feed_title);
444
445 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
446
447 $reply['content'] .= "<div class='cdmFeedTitle'>".
448 "<div style=\"float : right\">$feed_icon_img</div>".
449 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
450 $line["feed_title"]."</a> $vf_catchup_link</div>";
451
452 }
453 }
454
455 $mouseover_attrs = "onmouseover='postMouseIn($id)'
456 onmouseout='postMouseOut($id)'";
457
458 $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
459
460 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
461
462 $reply['content'] .= "<div class='hlLeft'>";
463
464 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
465 id=\"RCHK-$id\">";
466
467 $reply['content'] .= "$marked_pic";
468 $reply['content'] .= "$published_pic";
469
470 $reply['content'] .= "</div>";
471
472 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
473 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
474 $reply['content'] .= "<a id=\"RTITLE-$id\"
475 href=\"" . htmlspecialchars($line["link"]) . "\"
476 onclick=\"\">" .
477 truncate_string($line["title"], 200);
478
479 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
480 if ($content_preview) {
481 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
482 }
483 }
484
485 $reply['content'] .= "</a></span>";
486
487 $reply['content'] .= $labels_str;
488
489 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
490 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
491 if (@$line["feed_title"]) {
492 $reply['content'] .= "<span class=\"hlFeed\">
493 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
494 $line["feed_title"]."</a>)
495 </span>";
496 }
497 }
498
499 $reply['content'] .= "</div>";
500
501 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
502 $reply['content'] .= "<div class=\"hlRight\">";
503
504 $reply['content'] .= $score_pic;
505
506 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
507
508 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
509 style=\"cursor : pointer\"
510 title=\"".htmlspecialchars($line['feed_title'])."\">
511 $feed_icon_img<span>";
512 }
513
514 $reply['content'] .= "</div>";
515 $reply['content'] .= "</div>";
516
517 } else {
518
519 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
520 if ($feed_id != $vgroup_last_feed) {
521
522 $cur_feed_title = $line["feed_title"];
523 $vgroup_last_feed = $feed_id;
524
525 $cur_feed_title = htmlspecialchars($cur_feed_title);
526
527 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
528
529 $has_feed_icon = feed_has_icon($feed_id);
530
531 if ($has_feed_icon) {
532 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
533 } else {
534 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
535 }
536
537 $reply['content'] .= "<div class='cdmFeedTitle'>".
538 "<div style=\"float : right\">$feed_icon_img</div>".
539 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
540 $line["feed_title"]."</a> $vf_catchup_link</div>";
541 }
542 }
543
544 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');
545
546 $mouseover_attrs = "onmouseover='postMouseIn($id)'
547 onmouseout='postMouseOut($id)'";
548
549 $reply['content'] .= "<div class=\"$class\"
550 id=\"RROW-$id\" $mouseover_attrs'>";
551
552 $reply['content'] .= "<div class=\"cdmHeader\">";
553
554 $reply['content'] .= "<div>";
555
556 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
557 'RROW-$id')\" id=\"RCHK-$id\"/>";
558
559 $reply['content'] .= "$marked_pic";
560 $reply['content'] .= "$published_pic";
561
562 $reply['content'] .= "</div>";
563
564 $reply['content'] .= "<span id=\"RTITLE-$id\"
565 onclick=\"return cdmClicked(event, $id);\"
566 class=\"titleWrap$hlc_suffix\">
567 <a class=\"title\"
568 title=\"".htmlspecialchars($line['title'])."\"
569 target=\"_blank\" href=\"".
570 htmlspecialchars($line["link"])."\">".
571 truncate_string($line["title"], 100) .
572 " $entry_author</a>";
573
574 $reply['content'] .= $labels_str;
575
576 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
577 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
578 if (@$line["feed_title"]) {
579 $reply['content'] .= "<span class=\"hlFeed\">
580 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
581 $line["feed_title"]."</a>)
582 </span>";
583 }
584 }
585
586 if (!$expand_cdm)
587 $content_hidden = "style=\"display : none\"";
588 else
589 $excerpt_hidden = "style=\"display : none\"";
590
591 $reply['content'] .= "<span $excerpt_hidden
592 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
593
594 $reply['content'] .= "</span>";
595
596 $reply['content'] .= "<div>";
597 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
598 $reply['content'] .= "$score_pic";
599
600 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
601 $reply['content'] .= "<span style=\"cursor : pointer\"
602 title=\"".htmlspecialchars($line["feed_title"])."\"
603 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
604 }
605 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
606 $reply['content'] .= "</div>";
607
608 $reply['content'] .= "</div>";
609
610 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
611 onclick=\"return cdmClicked(event, $id);\"
612 id=\"CICD-$id\">";
613
614 $reply['content'] .= "<div class=\"cdmContentInner\">";
615
616 if ($line["orig_feed_id"]) {
617
618 $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds
619 WHERE id = ".$line["orig_feed_id"]);
620
621 if (db_num_rows($tmp_result) != 0) {
622
623 $reply['content'] .= "<div clear='both'>";
624 $reply['content'] .= __("Originally from:");
625
626 $reply['content'] .= "&nbsp;";
627
628 $tmp_line = db_fetch_assoc($tmp_result);
629
630 $reply['content'] .= "<a target='_blank'
631 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
632 $tmp_line['title'] . "</a>";
633
634 $reply['content'] .= "&nbsp;";
635
636 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
637 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.gif'></a>";
638
639 $reply['content'] .= "</div>";
640 }
641 }
642
643 $feed_site_url = $line["site_url"];
644
645 $article_content = sanitize($this->link, $line["content_preview"],
646 false, false, $feed_site_url);
647
648 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
649 if ($line['note']) {
650 $reply['content'] .= format_article_note($id, $line['note']);
651 }
652 $reply['content'] .= "</div>";
653
654 $reply['content'] .= "<span id=\"CWRAP-$id\">";
655 $reply['content'] .= $expand_cdm ? $article_content : '';
656 $reply['content'] .= "</span>";
657
658 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
659 ttrss_feeds WHERE id = ".
660 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
661 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
662
663 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
664 0, "always_display_enclosures")); */
665
666 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
667
668 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,
669 $article_content);
670
671 $reply['content'] .= "</div>";
672
673 $reply['content'] .= "<div class=\"cdmFooter\">";
674
675 $tag_cache = $line["tag_cache"];
676
677 $tags_str = format_tags_string(
678 get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),
679 $id);
680
681 $reply['content'] .= "<img src='".theme_image($this->link,
682 'images/tag.png')."' alt='Tags' title='Tags'>
683 <span id=\"ATSTR-$id\">$tags_str</span>
684 <a title=\"".__('Edit tags for this article')."\"
685 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
686
687 $num_comments = $line["num_comments"];
688 $entry_comments = "";
689
690 if ($num_comments > 0) {
691 if ($line["comments"]) {
692 $comments_url = $line["comments"];
693 } else {
694 $comments_url = $line["link"];
695 }
696 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
697 } else {
698 if ($line["comments"] && $line["link"] != $line["comments"]) {
699 $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";
700 }
701 }
702
703 if ($entry_comments) $reply['content'] .= "&nbsp;($entry_comments)";
704
705 $reply['content'] .= "<div style=\"float : right\">";
706
707 $reply['content'] .= "<img src=\"images/art-zoom.png\"
708 onclick=\"zoomToArticle(event, $id)\"
709 style=\"cursor : pointer\"
710 alt='Zoom'
711 title='".__('Open article in new tab')."'>";
712
713 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
714
715 foreach ($button_plugins as $p) {
716 $reply['content'] .= $p->render($id, $line);
717 }
718
719 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
720 style=\"cursor : pointer\" style=\"cursor : pointer\"
721 onclick=\"dismissArticle($id)\"
722 title='".__('Close article')."'>";
723
724 $reply['content'] .= "</div>";
725 $reply['content'] .= "</div>";
726
727 $reply['content'] .= "</div>";
728
729 $reply['content'] .= "</div>";
730
731 }
732
733 ++$lnum;
734 }
735
736 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
737
738 } else {
739 $message = "";
740
741 switch ($view_mode) {
742 case "unread":
743 $message = __("No unread articles found to display.");
744 break;
745 case "updated":
746 $message = __("No updated articles found to display.");
747 break;
748 case "marked":
749 $message = __("No starred articles found to display.");
750 break;
751 default:
752 if ($feed < -10) {
753 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
754 } else {
755 $message = __("No articles found to display.");
756 }
757 }
758
759 if (!$offset && $message) {
760 $reply['content'] .= "<div class='whiteBox'>$message";
761
762 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
763
764 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
765 WHERE owner_uid = " . $_SESSION['uid']);
766
767 $last_updated = db_fetch_result($result, 0, "last_updated");
768 $last_updated = make_local_datetime($this->link, $last_updated, false);
769
770 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
771
772 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
773 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
774
775 $num_errors = db_fetch_result($result, 0, "num_errors");
776
777 if ($num_errors > 0) {
778 $reply['content'] .= "<br/>";
779 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
780 __('Some feeds have update errors (click for details)')."</a>";
781 }
782 $reply['content'] .= "</span></p></div>";
783 }
784 }
785
786 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
787
788 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
789 $vgroup_last_feed, $reply);
790 }
791
792 private function outputFeedList($special = true) {
793
794 $feedlist = array();
795
796 $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
797
798 $feedlist['identifier'] = 'id';
799 $feedlist['label'] = 'name';
800 $feedlist['items'] = array();
801
802 $owner_uid = $_SESSION["uid"];
803
804 /* virtual feeds */
805
806 if ($special) {
807
808 if ($enable_cats) {
809 $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
810 $cat = $this->feedlist_init_cat(-1, $cat_hidden);
811 } else {
812 $cat['items'] = array();
813 }
814
815 foreach (array(-4, -3, -1, -2, 0) as $i) {
816 array_push($cat['items'], $this->feedlist_init_feed($i));
817 }
818
819 if ($enable_cats) {
820 array_push($feedlist['items'], $cat);
821 } else {
822 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
823 }
824
825 $result = db_query($this->link, "SELECT * FROM
826 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
827
828 if (db_num_rows($result) > 0) {
829
830 if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
831 $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
832 $cat = $this->feedlist_init_cat(-2, $cat_hidden);
833 } else {
834 $cat['items'] = array();
835 }
836
837 while ($line = db_fetch_assoc($result)) {
838
839 $label_id = -$line['id'] - 11;
840 $count = getFeedUnread($this->link, $label_id);
841
842 $feed = $this->feedlist_init_feed($label_id, false, $count);
843
844 $feed['fg_color'] = $line['fg_color'];
845 $feed['bg_color'] = $line['bg_color'];
846
847 array_push($cat['items'], $feed);
848 }
849
850 if ($enable_cats) {
851 array_push($feedlist['items'], $cat);
852 } else {
853 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
854 }
855 }
856 }
857
858 /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
859 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
860 $order_by_qpart = "order_id,category,unread DESC,title";
861 } else {
862 $order_by_qpart = "order_id,category,title";
863 }
864 } else {
865 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
866 $order_by_qpart = "unread DESC,title";
867 } else {
868 $order_by_qpart = "title";
869 }
870 } */
871
872 /* real feeds */
873
874 if ($enable_cats)
875 $order_by_qpart = "ttrss_feed_categories.order_id,category,
876 ttrss_feeds.order_id,title";
877 else
878 $order_by_qpart = "title";
879
880 $age_qpart = getMaxAgeSubquery();
881
882 $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
883 ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
884 cat_id,last_error,
885 ttrss_feed_categories.title AS category,
886 ttrss_feed_categories.collapsed,
887 value AS unread
888 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
889 ON (ttrss_feed_categories.id = cat_id)
890 LEFT JOIN ttrss_counters_cache
891 ON
892 (ttrss_feeds.id = feed_id)
893 WHERE
894 ttrss_feeds.owner_uid = '$owner_uid'
895 ORDER BY $order_by_qpart";
896
897 $result = db_query($this->link, $query);
898
899 $actid = $_REQUEST["actid"];
900
901 if (db_num_rows($result) > 0) {
902
903 $category = "";
904
905 if (!$enable_cats)
906 $cat['items'] = array();
907 else
908 $cat = false;
909
910 while ($line = db_fetch_assoc($result)) {
911
912 $feed = htmlspecialchars(trim($line["title"]));
913
914 if (!$feed) $feed = "[Untitled]";
915
916 $feed_id = $line["id"];
917 $unread = $line["unread"];
918
919 $cat_id = $line["cat_id"];
920 $tmp_category = $line["category"];
921 if (!$tmp_category) $tmp_category = __("Uncategorized");
922
923 if ($category != $tmp_category && $enable_cats) {
924
925 $category = $tmp_category;
926
927 $collapsed = sql_bool_to_bool($line["collapsed"]);
928
929 // workaround for NULL category
930 if ($category == __("Uncategorized")) {
931 $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT");
932 }
933
934 if ($cat) array_push($feedlist['items'], $cat);
935
936 $cat = $this->feedlist_init_cat($cat_id, $collapsed);
937 }
938
939 $updated = make_local_datetime($this->link, $line["updated_noms"], false);
940
941 array_push($cat['items'], $this->feedlist_init_feed($feed_id,
942 $feed, $unread, $line['last_error'], $updated));
943 }
944
945 if ($enable_cats) {
946 array_push($feedlist['items'], $cat);
947 } else {
948 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
949 }
950
951 }
952
953 return $feedlist;
954 }
955
956
957 function catchupAll() {
958 db_query($this->link, "UPDATE ttrss_user_entries SET
959 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
960 ccache_zero_all($this->link, $_SESSION["uid"]);
961 }
962
963 function collapse() {
964 $cat_id = db_escape_string($_REQUEST["cid"]);
965 $mode = (int) db_escape_string($_REQUEST['mode']);
966 toggle_collapse_cat($this->link, $cat_id, $mode);
967 }
968
969 function index() {
970 $root = (bool)$_REQUEST["root"];
971
972 if (!$root) {
973 print json_encode($this->outputFeedList($this->link));
974 } else {
975
976 $feeds = $this->outputFeedList($this->link, false);
977
978 $root = array();
979 $root['id'] = 'root';
980 $root['name'] = __('Feeds');
981 $root['items'] = $feeds['items'];
982
983 $fl = array();
984 $fl['identifier'] = 'id';
985 $fl['label'] = 'name';
986 $fl['items'] = array($root);
987
988 print json_encode($fl);
989 }
990 }
991
992 function view() {
993 $timing_info = getmicrotime();
994
995 $reply = array();
996
997 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
998
999 $omode = db_escape_string($_REQUEST["omode"]);
1000
1001 $feed = db_escape_string($_REQUEST["feed"]);
1002 $method = db_escape_string($_REQUEST["m"]);
1003 $view_mode = db_escape_string($_REQUEST["view_mode"]);
1004 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");
1005 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
1006 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
1007 @$offset = db_escape_string($_REQUEST["skip"]);
1008 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
1009 $order_by = db_escape_string($_REQUEST["order_by"]);
1010
1011 if (is_numeric($feed)) $feed = (int) $feed;
1012
1013 /* Feed -5 is a special case: it is used to display auxiliary information
1014 * when there's nothing to load - e.g. no stuff in fresh feed */
1015
1016 if ($feed == -5) {
1017 print json_encode(generate_dashboard_feed($this->link));
1018 return;
1019 }
1020
1021 $result = false;
1022
1023 if ($feed < -10) {
1024 $label_feed = -11-$feed;
1025 $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE
1026 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
1027 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
1028 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
1029 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1030 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
1031 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
1032 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
1033 }
1034
1035 if ($result && db_num_rows($result) == 0) {
1036 print json_encode(generate_error_feed($this->link, __("Feed not found.")));
1037 return;
1038 }
1039
1040 /* Updating a label ccache means recalculating all of the caches
1041 * so for performance reasons we don't do that here */
1042
1043 if ($feed >= 0) {
1044 ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);
1045 }
1046
1047 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);
1048 set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);
1049 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
1050
1051 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
1052 db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()
1053 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
1054 }
1055
1056 $reply['headlines'] = array();
1057
1058 if (!$next_unread_feed)
1059 $reply['headlines']['id'] = $feed;
1060 else
1061 $reply['headlines']['id'] = $next_unread_feed;
1062
1063 $reply['headlines']['is_cat'] = (bool) $cat_view;
1064
1065 $override_order = false;
1066
1067 if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
1068 $date_sort_field = "updated";
1069 } else {
1070 $date_sort_field = "date_entered";
1071 }
1072
1073 switch ($order_by) {
1074 case "date":
1075 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1076 $override_order = "$date_sort_field";
1077 } else {
1078 $override_order = "$date_sort_field DESC";
1079 }
1080 break;
1081
1082 case "title":
1083 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1084 $override_order = "title DESC, $date_sort_field";
1085 } else {
1086 $override_order = "title, $date_sort_field DESC";
1087 }
1088 break;
1089
1090 case "score":
1091 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
1092 $override_order = "score, $date_sort_field";
1093 } else {
1094 $override_order = "score DESC, $date_sort_field DESC";
1095 }
1096 break;
1097 }
1098
1099 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
1100
1101 $ret = $this->format_headlines_list($feed, $method,
1102 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
1103 $vgroup_last_feed, $override_order);
1104
1105 $topmost_article_ids = $ret[0];
1106 $headlines_count = $ret[1];
1107 $returned_feed = $ret[2];
1108 $disable_cache = $ret[3];
1109 $vgroup_last_feed = $ret[4];
1110
1111 $reply['headlines']['content'] =& $ret[5]['content'];
1112 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
1113
1114 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
1115
1116 $reply['headlines-info'] = array("count" => (int) $headlines_count,
1117 "vgroup_last_feed" => $vgroup_last_feed,
1118 "disable_cache" => (bool) $disable_cache);
1119
1120 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
1121
1122 if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
1123 $articles = array();
1124
1125 foreach ($topmost_article_ids as $id) {
1126 array_push($articles, format_article($this->link, $id, false));
1127 }
1128
1129 $reply['articles'] = $articles;
1130 }
1131
1132 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
1133
1134 $reply['runtime-info'] = make_runtime_info($this->link);
1135
1136 print json_encode($reply);
1137
1138 }
1139 }
1140 ?>