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