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