2 class Feeds extends Protected_Handler {
\r
4 function csrf_ignore($method) {
\r
5 $csrf_ignored = array("index");
\r
7 return array_search($method, $csrf_ignored) !== false;
\r
10 private function feedlist_init_cat($cat_id, $hidden = false) {
\r
12 $cat_id = (int) $cat_id;
\r
15 $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);
\r
16 } else if ($cat_id == 0 || $cat_id == -2) {
\r
17 $cat_unread = getCategoryUnread($this->link, $cat_id);
\r
20 $obj['id'] = 'CAT:' . $cat_id;
\r
21 $obj['items'] = array();
\r
22 $obj['name'] = getCategoryTitle($this->link, $cat_id);
\r
23 $obj['type'] = 'feed';
\r
24 $obj['unread'] = (int) $cat_unread;
\r
25 $obj['hidden'] = $hidden;
\r
26 $obj['bare_id'] = $cat_id;
\r
31 private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
\r
33 $feed_id = (int) $feed_id;
\r
36 $title = getFeedTitle($this->link, $feed_id, false);
\r
38 if ($unread === false)
\r
39 $unread = getFeedUnread($this->link, $feed_id, false);
\r
41 $obj['id'] = 'FEED:' . $feed_id;
\r
42 $obj['name'] = $title;
\r
43 $obj['unread'] = (int) $unread;
\r
44 $obj['type'] = 'feed';
\r
45 $obj['error'] = $error;
\r
46 $obj['updated'] = $updated;
\r
47 $obj['icon'] = getFeedIcon($feed_id);
\r
48 $obj['bare_id'] = $feed_id;
\r
53 private function format_headline_subtoolbar($feed_site_url, $feed_title,
\r
54 $feed_id, $is_cat, $search, $match_on,
\r
55 $search_mode, $view_mode, $error) {
\r
57 $page_prev_link = "viewFeedGoPage(-1)";
\r
58 $page_next_link = "viewFeedGoPage(1)";
\r
59 $page_first_link = "viewFeedGoPage(0)";
\r
61 $catchup_page_link = "catchupPage()";
\r
62 $catchup_feed_link = "catchupCurrentFeed()";
\r
63 $catchup_sel_link = "catchupSelection()";
\r
65 $archive_sel_link = "archiveSelection()";
\r
66 $delete_sel_link = "deleteSelection()";
\r
68 $sel_all_link = "selectArticles('all')";
\r
69 $sel_unread_link = "selectArticles('unread')";
\r
70 $sel_none_link = "selectArticles('none')";
\r
71 $sel_inv_link = "selectArticles('invert')";
\r
73 $tog_unread_link = "selectionToggleUnread()";
\r
74 $tog_marked_link = "selectionToggleMarked()";
\r
75 $tog_published_link = "selectionTogglePublished()";
\r
77 if ($is_cat) $cat_q = "&is_cat=$is_cat";
\r
80 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
\r
85 $rss_link = htmlspecialchars(get_self_url_prefix() .
\r
86 "/public.php?op=rss&id=$feed_id$cat_q$search_q");
\r
90 $reply .= "<span class='r'>";
\r
92 if ($feed_site_url) {
\r
93 $target = "target=\"_blank\"";
\r
94 $reply .= "<a title=\"".__("Visit the website")."\" $target href=\"$feed_site_url\">".
\r
95 truncate_string($feed_title,30)."</a>";
\r
98 $reply .= " (<span class=\"error\" title=\"$error\">Error</span>)";
\r
102 $reply .= $feed_title;
\r
107 title=\"".__("View as RSS feed")."\"
\r
108 onclick=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">
\r
109 <img class=\"noborder\" style=\"vertical-align : middle\" src=\"images/feed-icon-12x12.png\"></a>";
\r
111 $reply .= "</span>";
\r
115 $reply .= __('Select:')."
\r
116 <a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
\r
117 <a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
\r
118 <a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
\r
119 <a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
\r
123 $reply .= "<select dojoType=\"dijit.form.Select\"
\r
124 onchange=\"headlineActionsChange(this)\">";
\r
125 $reply .= "<option value=\"false\">".__('Actions...')."</option>";
\r
127 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>";
\r
129 $reply .= "<option value=\"$tog_unread_link\">".__('Unread')."</option>
\r
130 <option value=\"$tog_marked_link\">".__('Starred')."</option>
\r
131 <option value=\"$tog_published_link\">".__('Published')."</option>";
\r
133 $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>";
\r
135 $reply .= "<option value=\"$catchup_sel_link\">".__('Mark as read')."</option>";
\r
137 if ($feed_id != "0") {
\r
138 $reply .= "<option value=\"$archive_sel_link\">".__('Archive')."</option>";
\r
140 $reply .= "<option value=\"$archive_sel_link\">".__('Move back')."</option>";
\r
141 $reply .= "<option value=\"$delete_sel_link\">".__('Delete')."</option>";
\r
145 $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
\r
148 $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
\r
150 $reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
\r
152 $reply .= "<option value=\"displayDlg('generatedFeed', '$feed_id:$is_cat:$rss_link')\">".__('View as RSS')."</option>";
\r
154 $reply .= "</select>";
\r
156 //$reply .= "</div>";
\r
158 //$reply .= "</h2";
\r
163 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view,
\r
164 $next_unread_feed, $offset, $vgr_last_feed = false,
\r
165 $override_order = false) {
\r
167 $disable_cache = false;
\r
171 $timing_info = getmicrotime();
\r
173 $topmost_article_ids = array();
\r
175 if (!$offset) $offset = 0;
\r
176 if ($method == "undefined") $method = "";
\r
178 $method_split = explode(":", $method);
\r
180 /* if ($method == "CatchupSelected") {
\r
181 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
\r
182 $cmode = sprintf("%d", $_REQUEST["cmode"]);
\r
184 catchupArticlesById($this->link, $ids, $cmode);
\r
187 if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
\r
188 include "rssfuncs.php";
\r
189 update_rss_feed($this->link, $feed, true);
\r
192 if ($method == "MarkAllRead") {
\r
193 catchup_feed($this->link, $feed, $cat_view);
\r
195 if (get_pref($this->link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
\r
196 if ($next_unread_feed) {
\r
197 $feed = $next_unread_feed;
\r
202 if ($method_split[0] == "MarkAllReadGR") {
\r
203 catchup_feed($this->link, $method_split[1], false);
\r
206 // FIXME: might break tag display?
\r
208 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
\r
209 $result = db_query($this->link,
\r
210 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
\r
212 if (db_num_rows($result) == 0) {
\r
213 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
\r
217 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
\r
219 $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds
\r
220 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
\r
222 if (db_num_rows($result) == 1) {
\r
223 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
\r
225 $rtl_content = false;
\r
228 if ($rtl_content) {
\r
229 $rtl_tag = "dir=\"RTL\"";
\r
235 $rtl_content = false;
\r
238 @$search = db_escape_string($_REQUEST["query"]);
\r
241 $disable_cache = true;
\r
244 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
\r
245 @$match_on = db_escape_string($_REQUEST["match_on"]);
\r
248 $match_on = "both";
\r
251 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
\r
253 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
\r
254 if( $search_mode == '' && $method != '' ){
\r
255 $search_mode = $method;
\r
257 // error_log("search_mode: " . $search_mode);
\r
258 $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,
\r
259 $search, $search_mode, $match_on, $override_order, $offset);
\r
261 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
\r
263 $result = $qfh_ret[0];
\r
264 $feed_title = $qfh_ret[1];
\r
265 $feed_site_url = $qfh_ret[2];
\r
266 $last_error = $qfh_ret[3];
\r
268 $vgroup_last_feed = $vgr_last_feed;
\r
272 if (db_num_rows($result) > 0) {
\r
273 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
\r
275 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
\r
280 $headlines_count = db_num_rows($result);
\r
282 if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
\r
283 $button_plugins = array();
\r
284 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
\r
285 $pclass = trim("${p}_button");
\r
287 if (class_exists($pclass)) {
\r
288 $plugin = new $pclass($link);
\r
289 array_push($button_plugins, $plugin);
\r
294 if (db_num_rows($result) > 0) {
\r
299 $cur_feed_title = '';
\r
301 $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
\r
303 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
\r
305 while ($line = db_fetch_assoc($result)) {
\r
307 $class = ($lnum % 2) ? "even" : "odd";
\r
310 $feed_id = $line["feed_id"];
\r
311 $label_cache = $line["label_cache"];
\r
314 if ($label_cache) {
\r
315 $label_cache = json_decode($label_cache, true);
\r
317 if ($label_cache) {
\r
318 if ($label_cache["no-labels"] == 1)
\r
321 $labels = $label_cache;
\r
325 if (!is_array($labels)) $labels = get_article_labels($this->link, $id);
\r
327 $labels_str = "<span id=\"HLLCTR-$id\">";
\r
328 $labels_str .= format_article_labels($labels, $id);
\r
329 $labels_str .= "</span>";
\r
331 if (count($topmost_article_ids) < 3) {
\r
332 array_push($topmost_article_ids, $id);
\r
335 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
\r
337 $update_pic = "<img id='FUPDPIC-$id' src=\"".
\r
338 theme_image($this->link, 'images/updated.png')."\"
\r
341 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
\r
345 if (sql_bool_to_bool($line["unread"]) &&
\r
346 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
\r
348 $update_pic = "<img id='FUPDPIC-$id' src=\"".
\r
349 theme_image($this->link, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
\r
352 if ($line["unread"] == "t" || $line["unread"] == "1") {
\r
353 $class .= " Unread";
\r
357 $is_unread = false;
\r
360 if ($line["marked"] == "t" || $line["marked"] == "1") {
\r
361 $marked_pic = "<img id=\"FMPIC-$id\"
\r
362 src=\"".theme_image($this->link, 'images/mark_set.png')."\"
\r
363 class=\"markedPic\" alt=\"Unstar article\"
\r
364 onclick='javascript:toggleMark($id)'>";
\r
366 $marked_pic = "<img id=\"FMPIC-$id\"
\r
367 src=\"".theme_image($this->link, 'images/mark_unset.png')."\"
\r
368 class=\"markedPic\" alt=\"Star article\"
\r
369 onclick='javascript:toggleMark($id)'>";
\r
372 if ($line["published"] == "t" || $line["published"] == "1") {
\r
373 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
\r
374 'images/pub_set.png')."\"
\r
375 class=\"markedPic\"
\r
376 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
\r
378 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
\r
379 'images/pub_unset.png')."\"
\r
380 class=\"markedPic\"
\r
381 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
\r
384 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
\r
385 # $line["title"] . "</a>";
\r
387 # $content_link = "<a
\r
388 # href=\"" . htmlspecialchars($line["link"]) . "\"
\r
389 # onclick=\"view($id,$feed_id);\">" .
\r
390 # $line["title"] . "</a>";
\r
392 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
\r
393 # $line["title"] . "</a>";
\r
395 $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);
\r
397 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
\r
398 $content_preview = truncate_string(strip_tags($line["content_preview"]),
\r
402 $score = $line["score"];
\r
404 $score_pic = theme_image($this->link,
\r
405 "images/" . get_score_pic($score));
\r
407 /* $score_title = __("(Click to change)");
\r
408 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
\r
409 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
\r
411 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
\r
412 title=\"$score\">";
\r
414 if ($score > 500) {
\r
416 } else if ($score < -100) {
\r
422 $entry_author = $line["author"];
\r
424 if ($entry_author) {
\r
425 $entry_author = " - $entry_author";
\r
428 $has_feed_icon = feed_has_icon($feed_id);
\r
430 if ($has_feed_icon) {
\r
431 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
\r
433 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
\r
436 if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
\r
438 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
\r
439 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
\r
441 $cur_feed_title = $line["feed_title"];
\r
442 $vgroup_last_feed = $feed_id;
\r
444 $cur_feed_title = htmlspecialchars($cur_feed_title);
\r
446 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
\r
448 $reply['content'] .= "<div class='cdmFeedTitle'>".
\r
449 "<div style=\"float : right\">$feed_icon_img</div>".
\r
450 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
\r
451 $line["feed_title"]."</a> $vf_catchup_link</div>";
\r
456 $mouseover_attrs = "onmouseover='postMouseIn($id)'
\r
457 onmouseout='postMouseOut($id)'";
\r
459 $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
\r
461 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
\r
463 $reply['content'] .= "<div class='hlLeft'>";
\r
465 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
\r
468 $reply['content'] .= "$marked_pic";
\r
469 $reply['content'] .= "$published_pic";
\r
471 $reply['content'] .= "</div>";
\r
473 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
\r
474 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
\r
475 $reply['content'] .= "<a id=\"RTITLE-$id\"
\r
476 href=\"" . htmlspecialchars($line["link"]) . "\"
\r
478 truncate_string($line["title"], 200);
\r
480 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
\r
481 if ($content_preview) {
\r
482 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
\r
486 $reply['content'] .= "</a></span>";
\r
488 $reply['content'] .= $labels_str;
\r
490 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
\r
491 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
\r
492 if (@$line["feed_title"]) {
\r
493 $reply['content'] .= "<span class=\"hlFeed\">
\r
494 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
\r
495 $line["feed_title"]."</a>)
\r
500 $reply['content'] .= "</div>";
\r
502 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
\r
503 $reply['content'] .= "<div class=\"hlRight\">";
\r
505 $reply['content'] .= $score_pic;
\r
507 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
\r
509 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
\r
510 style=\"cursor : pointer\"
\r
511 title=\"".htmlspecialchars($line['feed_title'])."\">
\r
512 $feed_icon_img<span>";
\r
515 $reply['content'] .= "</div>";
\r
516 $reply['content'] .= "</div>";
\r
520 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
\r
521 if ($feed_id != $vgroup_last_feed) {
\r
523 $cur_feed_title = $line["feed_title"];
\r
524 $vgroup_last_feed = $feed_id;
\r
526 $cur_feed_title = htmlspecialchars($cur_feed_title);
\r
528 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
\r
530 $has_feed_icon = feed_has_icon($feed_id);
\r
532 if ($has_feed_icon) {
\r
533 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
\r
535 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
\r
538 $reply['content'] .= "<div class='cdmFeedTitle'>".
\r
539 "<div style=\"float : right\">$feed_icon_img</div>".
\r
540 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
\r
541 $line["feed_title"]."</a> $vf_catchup_link</div>";
\r
545 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');
\r
547 $mouseover_attrs = "onmouseover='postMouseIn($id)'
\r
548 onmouseout='postMouseOut($id)'";
\r
550 $reply['content'] .= "<div class=\"$class\"
\r
551 id=\"RROW-$id\" $mouseover_attrs'>";
\r
553 $reply['content'] .= "<div class=\"cdmHeader\">";
\r
555 $reply['content'] .= "<div>";
\r
557 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
\r
558 'RROW-$id')\" id=\"RCHK-$id\"/>";
\r
560 $reply['content'] .= "$marked_pic";
\r
561 $reply['content'] .= "$published_pic";
\r
563 $reply['content'] .= "</div>";
\r
565 $reply['content'] .= "<span id=\"RTITLE-$id\"
\r
566 onclick=\"return cdmClicked(event, $id);\"
\r
567 class=\"titleWrap$hlc_suffix\">
\r
569 title=\"".htmlspecialchars($line['title'])."\"
\r
570 target=\"_blank\" href=\"".
\r
571 htmlspecialchars($line["link"])."\">".
\r
572 truncate_string($line["title"], 100) .
\r
573 " $entry_author</a>";
\r
575 $reply['content'] .= $labels_str;
\r
577 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
\r
578 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
\r
579 if (@$line["feed_title"]) {
\r
580 $reply['content'] .= "<span class=\"hlFeed\">
\r
581 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
\r
582 $line["feed_title"]."</a>)
\r
588 $content_hidden = "style=\"display : none\"";
\r
590 $excerpt_hidden = "style=\"display : none\"";
\r
592 $reply['content'] .= "<span $excerpt_hidden
\r
593 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
\r
595 $reply['content'] .= "</span>";
\r
597 $reply['content'] .= "<div>";
\r
598 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
\r
599 $reply['content'] .= "$score_pic";
\r
601 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
\r
602 $reply['content'] .= "<span style=\"cursor : pointer\"
\r
603 title=\"".htmlspecialchars($line["feed_title"])."\"
\r
604 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
\r
606 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
\r
607 $reply['content'] .= "</div>";
\r
609 $reply['content'] .= "</div>";
\r
611 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
\r
612 onclick=\"return cdmClicked(event, $id);\"
\r
615 $reply['content'] .= "<div class=\"cdmContentInner\">";
\r
617 if ($line["orig_feed_id"]) {
\r
619 $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds
\r
620 WHERE id = ".$line["orig_feed_id"]);
\r
622 if (db_num_rows($tmp_result) != 0) {
\r
624 $reply['content'] .= "<div clear='both'>";
\r
625 $reply['content'] .= __("Originally from:");
\r
627 $reply['content'] .= " ";
\r
629 $tmp_line = db_fetch_assoc($tmp_result);
\r
631 $reply['content'] .= "<a target='_blank'
\r
632 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
\r
633 $tmp_line['title'] . "</a>";
\r
635 $reply['content'] .= " ";
\r
637 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
\r
638 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";
\r
640 $reply['content'] .= "</div>";
\r
644 $feed_site_url = $line["site_url"];
\r
646 $article_content = sanitize($this->link, $line["content_preview"],
\r
647 false, false, $feed_site_url);
\r
649 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
\r
650 if ($line['note']) {
\r
651 $reply['content'] .= format_article_note($id, $line['note']);
\r
653 $reply['content'] .= "</div>";
\r
655 $reply['content'] .= "<span id=\"CWRAP-$id\">";
\r
656 $reply['content'] .= $expand_cdm ? $article_content : '';
\r
657 $reply['content'] .= "</span>";
\r
659 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
\r
660 ttrss_feeds WHERE id = ".
\r
661 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
\r
662 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
\r
664 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
\r
665 0, "always_display_enclosures")); */
\r
667 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
\r
669 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,
\r
672 $reply['content'] .= "</div>";
\r
674 $reply['content'] .= "<div class=\"cdmFooter\">";
\r
676 $tag_cache = $line["tag_cache"];
\r
678 $tags_str = format_tags_string(
\r
679 get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),
\r
682 $reply['content'] .= "<img src='".theme_image($this->link,
\r
683 'images/tag.png')."' alt='Tags' title='Tags'>
\r
684 <span id=\"ATSTR-$id\">$tags_str</span>
\r
685 <a title=\"".__('Edit tags for this article')."\"
\r
686 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
\r
688 $num_comments = $line["num_comments"];
\r
689 $entry_comments = "";
\r
691 if ($num_comments > 0) {
\r
692 if ($line["comments"]) {
\r
693 $comments_url = $line["comments"];
\r
695 $comments_url = $line["link"];
\r
697 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
\r
699 if ($line["comments"] && $line["link"] != $line["comments"]) {
\r
700 $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";
\r
704 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
\r
706 $reply['content'] .= "<div style=\"float : right\">";
\r
708 $reply['content'] .= "<img src=\"images/art-zoom.png\"
\r
709 onclick=\"zoomToArticle(event, $id)\"
\r
710 style=\"cursor : pointer\"
\r
712 title='".__('Open article in new tab')."'>";
\r
714 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
\r
716 foreach ($button_plugins as $p) {
\r
717 $reply['content'] .= $p->render($id, $line);
\r
720 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
\r
721 style=\"cursor : pointer\" style=\"cursor : pointer\"
\r
722 onclick=\"dismissArticle($id)\"
\r
723 title='".__('Close article')."'>";
\r
725 $reply['content'] .= "</div>";
\r
726 $reply['content'] .= "</div>";
\r
728 $reply['content'] .= "</div>";
\r
730 $reply['content'] .= "</div>";
\r
737 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
\r
742 switch ($view_mode) {
\r
744 $message = __("No unread articles found to display.");
\r
747 $message = __("No updated articles found to display.");
\r
750 $message = __("No starred articles found to display.");
\r
754 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
\r
756 $message = __("No articles found to display.");
\r
760 if (!$offset && $message) {
\r
761 $reply['content'] .= "<div class='whiteBox'>$message";
\r
763 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
\r
765 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
\r
766 WHERE owner_uid = " . $_SESSION['uid']);
\r
768 $last_updated = db_fetch_result($result, 0, "last_updated");
\r
769 $last_updated = make_local_datetime($this->link, $last_updated, false);
\r
771 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
\r
773 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
\r
774 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
\r
776 $num_errors = db_fetch_result($result, 0, "num_errors");
\r
778 if ($num_errors > 0) {
\r
779 $reply['content'] .= "<br/>";
\r
780 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
\r
781 __('Some feeds have update errors (click for details)')."</a>";
\r
783 $reply['content'] .= "</span></p></div>";
\r
787 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
\r
789 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
\r
790 $vgroup_last_feed, $reply);
\r
793 private function outputFeedList($special = true) {
\r
795 $feedlist = array();
\r
797 $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
\r
799 $feedlist['identifier'] = 'id';
\r
800 $feedlist['label'] = 'name';
\r
801 $feedlist['items'] = array();
\r
803 $owner_uid = $_SESSION["uid"];
\r
805 /* virtual feeds */
\r
809 if ($enable_cats) {
\r
810 $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
\r
811 $cat = $this->feedlist_init_cat(-1, $cat_hidden);
\r
813 $cat['items'] = array();
\r
816 foreach (array(-4, -3, -1, -2, 0) as $i) {
\r
817 array_push($cat['items'], $this->feedlist_init_feed($i));
\r
820 if ($enable_cats) {
\r
821 array_push($feedlist['items'], $cat);
\r
823 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
\r
826 $result = db_query($this->link, "SELECT * FROM
\r
827 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
\r
829 if (db_num_rows($result) > 0) {
\r
831 if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
\r
832 $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
\r
833 $cat = $this->feedlist_init_cat(-2, $cat_hidden);
\r
835 $cat['items'] = array();
\r
838 while ($line = db_fetch_assoc($result)) {
\r
840 $label_id = -$line['id'] - 11;
\r
841 $count = getFeedUnread($this->link, $label_id);
\r
843 $feed = $this->feedlist_init_feed($label_id, false, $count);
\r
845 $feed['fg_color'] = $line['fg_color'];
\r
846 $feed['bg_color'] = $line['bg_color'];
\r
848 array_push($cat['items'], $feed);
\r
851 if ($enable_cats) {
\r
852 array_push($feedlist['items'], $cat);
\r
854 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
\r
859 /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
\r
860 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
\r
861 $order_by_qpart = "order_id,category,unread DESC,title";
\r
863 $order_by_qpart = "order_id,category,title";
\r
866 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
\r
867 $order_by_qpart = "unread DESC,title";
\r
869 $order_by_qpart = "title";
\r
876 $order_by_qpart = "ttrss_feed_categories.order_id,category,
\r
877 ttrss_feeds.order_id,title";
\r
879 $order_by_qpart = "title";
\r
881 $age_qpart = getMaxAgeSubquery();
\r
883 $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
\r
884 ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
\r
886 ttrss_feed_categories.title AS category,
\r
887 ttrss_feed_categories.collapsed,
\r
889 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
\r
890 ON (ttrss_feed_categories.id = cat_id)
\r
891 LEFT JOIN ttrss_counters_cache
\r
893 (ttrss_feeds.id = feed_id)
\r
895 ttrss_feeds.owner_uid = '$owner_uid'
\r
896 ORDER BY $order_by_qpart";
\r
898 $result = db_query($this->link, $query);
\r
900 $actid = $_REQUEST["actid"];
\r
902 if (db_num_rows($result) > 0) {
\r
907 $cat['items'] = array();
\r
911 while ($line = db_fetch_assoc($result)) {
\r
913 $feed = htmlspecialchars(trim($line["title"]));
\r
915 if (!$feed) $feed = "[Untitled]";
\r
917 $feed_id = $line["id"];
\r
918 $unread = $line["unread"];
\r
920 $cat_id = $line["cat_id"];
\r
921 $tmp_category = $line["category"];
\r
922 if (!$tmp_category) $tmp_category = __("Uncategorized");
\r
924 if ($category != $tmp_category && $enable_cats) {
\r
926 $category = $tmp_category;
\r
928 $collapsed = sql_bool_to_bool($line["collapsed"]);
\r
930 // workaround for NULL category
\r
931 if ($category == __("Uncategorized")) {
\r
932 $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT");
\r
935 if ($cat) array_push($feedlist['items'], $cat);
\r
937 $cat = $this->feedlist_init_cat($cat_id, $collapsed);
\r
940 $updated = make_local_datetime($this->link, $line["updated_noms"], false);
\r
942 array_push($cat['items'], $this->feedlist_init_feed($feed_id,
\r
943 $feed, $unread, $line['last_error'], $updated));
\r
946 if ($enable_cats) {
\r
947 array_push($feedlist['items'], $cat);
\r
949 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
\r
958 function catchupAll() {
\r
959 db_query($this->link, "UPDATE ttrss_user_entries SET
\r
960 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
\r
961 ccache_zero_all($this->link, $_SESSION["uid"]);
\r
964 function collapse() {
\r
965 $cat_id = db_escape_string($_REQUEST["cid"]);
\r
966 $mode = (int) db_escape_string($_REQUEST['mode']);
\r
967 toggle_collapse_cat($this->link, $cat_id, $mode);
\r
971 $root = (bool)$_REQUEST["root"];
\r
974 print json_encode($this->outputFeedList($this->link));
\r
977 $feeds = $this->outputFeedList($this->link, false);
\r
980 $root['id'] = 'root';
\r
981 $root['name'] = __('Feeds');
\r
982 $root['items'] = $feeds['items'];
\r
985 $fl['identifier'] = 'id';
\r
986 $fl['label'] = 'name';
\r
987 $fl['items'] = array($root);
\r
989 print json_encode($fl);
\r
994 $timing_info = getmicrotime();
\r
998 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
\r
1000 $omode = db_escape_string($_REQUEST["omode"]);
\r
1002 $feed = db_escape_string($_REQUEST["feed"]);
\r
1003 $method = db_escape_string($_REQUEST["m"]);
\r
1004 $view_mode = db_escape_string($_REQUEST["view_mode"]);
\r
1005 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");
\r
1006 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
\r
1007 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
\r
1008 @$offset = db_escape_string($_REQUEST["skip"]);
\r
1009 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
\r
1010 $order_by = db_escape_string($_REQUEST["order_by"]);
\r
1012 if (is_numeric($feed)) $feed = (int) $feed;
\r
1014 /* Feed -5 is a special case: it is used to display auxiliary information
\r
1015 * when there's nothing to load - e.g. no stuff in fresh feed */
\r
1017 if ($feed == -5) {
\r
1018 print json_encode(generate_dashboard_feed($this->link));
\r
1024 if ($feed < -10) {
\r
1025 $label_feed = -11-$feed;
\r
1026 $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE
\r
1027 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
\r
1028 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
\r
1029 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
\r
1030 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
\r
1031 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
\r
1032 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
\r
1033 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
\r
1036 if ($result && db_num_rows($result) == 0) {
\r
1037 print json_encode(generate_error_feed($this->link, __("Feed not found.")));
\r
1041 /* Updating a label ccache means recalculating all of the caches
\r
1042 * so for performance reasons we don't do that here */
\r
1045 ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);
\r
1048 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);
\r
1049 set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);
\r
1050 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
\r
1052 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
\r
1053 db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()
\r
1054 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
\r
1057 $reply['headlines'] = array();
\r
1059 if (!$next_unread_feed)
\r
1060 $reply['headlines']['id'] = $feed;
\r
1062 $reply['headlines']['id'] = $next_unread_feed;
\r
1064 $reply['headlines']['is_cat'] = (bool) $cat_view;
\r
1066 $override_order = false;
\r
1068 if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
\r
1069 $date_sort_field = "updated";
\r
1071 $date_sort_field = "date_entered";
\r
1074 switch ($order_by) {
\r
1076 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
\r
1077 $override_order = "$date_sort_field";
\r
1079 $override_order = "$date_sort_field DESC";
\r
1084 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
\r
1085 $override_order = "title DESC, $date_sort_field";
\r
1087 $override_order = "title, $date_sort_field DESC";
\r
1092 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
\r
1093 $override_order = "score, $date_sort_field";
\r
1095 $override_order = "score DESC, $date_sort_field DESC";
\r
1100 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
\r
1102 $ret = $this->format_headlines_list($feed, $method,
\r
1103 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
\r
1104 $vgroup_last_feed, $override_order);
\r
1106 $topmost_article_ids = $ret[0];
\r
1107 $headlines_count = $ret[1];
\r
1108 $returned_feed = $ret[2];
\r
1109 $disable_cache = $ret[3];
\r
1110 $vgroup_last_feed = $ret[4];
\r
1112 $reply['headlines']['content'] =& $ret[5]['content'];
\r
1113 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
\r
1115 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
\r
1117 $reply['headlines-info'] = array("count" => (int) $headlines_count,
\r
1118 "vgroup_last_feed" => $vgroup_last_feed,
\r
1119 "disable_cache" => (bool) $disable_cache);
\r
1121 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
\r
1123 if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
\r
1124 $articles = array();
\r
1126 foreach ($topmost_article_ids as $id) {
\r
1127 array_push($articles, format_article($this->link, $id, false));
\r
1130 $reply['articles'] = $articles;
\r
1133 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
\r
1135 $reply['runtime-info'] = make_runtime_info($this->link);
\r
1137 print json_encode($reply);
\r