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 == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
\r
181 include "rssfuncs.php";
\r
182 update_rss_feed($this->link, $feed, true);
\r
185 if ($method_split[0] == "MarkAllReadGR") {
\r
186 catchup_feed($this->link, $method_split[1], false);
\r
189 // FIXME: might break tag display?
\r
191 if (is_numeric($feed) && $feed > 0 && !$cat_view) {
\r
192 $result = db_query($this->link,
\r
193 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
\r
195 if (db_num_rows($result) == 0) {
\r
196 $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>";
\r
200 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
\r
202 $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds
\r
203 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
\r
205 if (db_num_rows($result) == 1) {
\r
206 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
\r
208 $rtl_content = false;
\r
211 if ($rtl_content) {
\r
212 $rtl_tag = "dir=\"RTL\"";
\r
218 $rtl_content = false;
\r
221 @$search = db_escape_string($_REQUEST["query"]);
\r
224 $disable_cache = true;
\r
227 @$search_mode = db_escape_string($_REQUEST["search_mode"]);
\r
228 @$match_on = db_escape_string($_REQUEST["match_on"]);
\r
231 $match_on = "both";
\r
234 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H0", $timing_info);
\r
236 // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
\r
237 if( $search_mode == '' && $method != '' ){
\r
238 $search_mode = $method;
\r
240 // error_log("search_mode: " . $search_mode);
\r
241 $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view,
\r
242 $search, $search_mode, $match_on, $override_order, $offset);
\r
244 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H1", $timing_info);
\r
246 $result = $qfh_ret[0];
\r
247 $feed_title = $qfh_ret[1];
\r
248 $feed_site_url = $qfh_ret[2];
\r
249 $last_error = $qfh_ret[3];
\r
251 $vgroup_last_feed = $vgr_last_feed;
\r
255 if (db_num_rows($result) > 0) {
\r
256 $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url,
\r
258 $feed, $cat_view, $search, $match_on, $search_mode, $view_mode,
\r
263 $headlines_count = db_num_rows($result);
\r
265 if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
\r
266 $button_plugins = array();
\r
267 foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
\r
268 $pclass = trim("${p}_button");
\r
270 if (class_exists($pclass)) {
\r
271 $plugin = new $pclass($link);
\r
272 array_push($button_plugins, $plugin);
\r
277 if (db_num_rows($result) > 0) {
\r
282 $cur_feed_title = '';
\r
284 $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
\r
286 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
\r
288 while ($line = db_fetch_assoc($result)) {
\r
290 $class = ($lnum % 2) ? "even" : "odd";
\r
293 $feed_id = $line["feed_id"];
\r
294 $label_cache = $line["label_cache"];
\r
297 if ($label_cache) {
\r
298 $label_cache = json_decode($label_cache, true);
\r
300 if ($label_cache) {
\r
301 if ($label_cache["no-labels"] == 1)
\r
304 $labels = $label_cache;
\r
308 if (!is_array($labels)) $labels = get_article_labels($this->link, $id);
\r
310 $labels_str = "<span id=\"HLLCTR-$id\">";
\r
311 $labels_str .= format_article_labels($labels, $id);
\r
312 $labels_str .= "</span>";
\r
314 if (count($topmost_article_ids) < 3) {
\r
315 array_push($topmost_article_ids, $id);
\r
318 if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
\r
320 $update_pic = "<img id='FUPDPIC-$id' src=\"".
\r
321 theme_image($this->link, 'images/updated.png')."\"
\r
324 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
\r
328 if (sql_bool_to_bool($line["unread"]) &&
\r
329 time() - strtotime($line["updated_noms"]) < $fresh_intl) {
\r
331 $update_pic = "<img id='FUPDPIC-$id' src=\"".
\r
332 theme_image($this->link, 'images/fresh_sign.png')."\" alt=\"Fresh\">";
\r
335 if ($line["unread"] == "t" || $line["unread"] == "1") {
\r
336 $class .= " Unread";
\r
340 $is_unread = false;
\r
343 if ($line["marked"] == "t" || $line["marked"] == "1") {
\r
344 $marked_pic = "<img id=\"FMPIC-$id\"
\r
345 src=\"".theme_image($this->link, 'images/mark_set.png')."\"
\r
346 class=\"markedPic\" alt=\"Unstar article\"
\r
347 onclick='javascript:toggleMark($id)'>";
\r
349 $marked_pic = "<img id=\"FMPIC-$id\"
\r
350 src=\"".theme_image($this->link, 'images/mark_unset.png')."\"
\r
351 class=\"markedPic\" alt=\"Star article\"
\r
352 onclick='javascript:toggleMark($id)'>";
\r
355 if ($line["published"] == "t" || $line["published"] == "1") {
\r
356 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
\r
357 'images/pub_set.png')."\"
\r
358 class=\"markedPic\"
\r
359 alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>";
\r
361 $published_pic = "<img id=\"FPPIC-$id\" src=\"".theme_image($this->link,
\r
362 'images/pub_unset.png')."\"
\r
363 class=\"markedPic\"
\r
364 alt=\"Publish article\" onclick='javascript:togglePub($id)'>";
\r
367 # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
\r
368 # $line["title"] . "</a>";
\r
370 # $content_link = "<a
\r
371 # href=\"" . htmlspecialchars($line["link"]) . "\"
\r
372 # onclick=\"view($id,$feed_id);\">" .
\r
373 # $line["title"] . "</a>";
\r
375 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
\r
376 # $line["title"] . "</a>";
\r
378 $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);
\r
380 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
\r
381 $content_preview = strip_tags($line["content_preview"]);
\r
384 $score = $line["score"];
\r
386 $score_pic = theme_image($this->link,
\r
387 "images/" . get_score_pic($score));
\r
389 /* $score_title = __("(Click to change)");
\r
390 $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
\r
391 onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
\r
393 $score_pic = "<img class='hlScorePic' src=\"$score_pic\"
\r
394 title=\"$score\">";
\r
396 if ($score > 500) {
\r
398 } else if ($score < -100) {
\r
404 $entry_author = $line["author"];
\r
406 if ($entry_author) {
\r
407 $entry_author = " - $entry_author";
\r
410 $has_feed_icon = feed_has_icon($feed_id);
\r
412 if ($has_feed_icon) {
\r
413 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
\r
415 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
\r
418 if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
\r
420 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
\r
421 if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
\r
423 $cur_feed_title = $line["feed_title"];
\r
424 $vgroup_last_feed = $feed_id;
\r
426 $cur_feed_title = htmlspecialchars($cur_feed_title);
\r
428 $vf_catchup_link = "(<a onclick='catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
\r
430 $reply['content'] .= "<div class='cdmFeedTitle'>".
\r
431 "<div style=\"float : right\">$feed_icon_img</div>".
\r
432 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
\r
433 $line["feed_title"]."</a> $vf_catchup_link</div>";
\r
438 $mouseover_attrs = "onmouseover='postMouseIn($id)'
\r
439 onmouseout='postMouseOut($id)'";
\r
441 $reply['content'] .= "<div class='$class' id='RROW-$id' $mouseover_attrs>";
\r
443 $reply['content'] .= "<div class='hlUpdPic'>$update_pic</div>";
\r
445 $reply['content'] .= "<div class='hlLeft'>";
\r
447 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"
\r
450 $reply['content'] .= "$marked_pic";
\r
451 $reply['content'] .= "$published_pic";
\r
453 $reply['content'] .= "</div>";
\r
455 $reply['content'] .= "<div onclick='return hlClicked(event, $id)'
\r
456 class=\"hlTitle\"><span class='hlContent$hlc_suffix'>";
\r
457 $reply['content'] .= "<a id=\"RTITLE-$id\"
\r
458 href=\"" . htmlspecialchars($line["link"]) . "\"
\r
462 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
\r
463 if ($content_preview) {
\r
464 $reply['content'] .= "<span class=\"contentPreview\"> - $content_preview</span>";
\r
468 $reply['content'] .= "</a></span>";
\r
470 $reply['content'] .= $labels_str;
\r
472 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
\r
473 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
\r
474 if (@$line["feed_title"]) {
\r
475 $reply['content'] .= "<span class=\"hlFeed\">
\r
476 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
\r
477 $line["feed_title"]."</a>)
\r
482 $reply['content'] .= "</div>";
\r
484 $reply['content'] .= "<span class=\"hlUpdated\">$updated_fmt</span>";
\r
485 $reply['content'] .= "<div class=\"hlRight\">";
\r
487 $reply['content'] .= $score_pic;
\r
489 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
\r
491 $reply['content'] .= "<span onclick=\"viewfeed($feed_id)\"
\r
492 style=\"cursor : pointer\"
\r
493 title=\"".htmlspecialchars($line['feed_title'])."\">
\r
494 $feed_icon_img<span>";
\r
497 $reply['content'] .= "</div>";
\r
498 $reply['content'] .= "</div>";
\r
502 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
\r
503 if ($feed_id != $vgroup_last_feed) {
\r
505 $cur_feed_title = $line["feed_title"];
\r
506 $vgroup_last_feed = $feed_id;
\r
508 $cur_feed_title = htmlspecialchars($cur_feed_title);
\r
510 $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup($feed_id);' href='#'>".__('mark as read')."</a>)";
\r
512 $has_feed_icon = feed_has_icon($feed_id);
\r
514 if ($has_feed_icon) {
\r
515 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">";
\r
517 //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
\r
520 $reply['content'] .= "<div class='cdmFeedTitle'>".
\r
521 "<div style=\"float : right\">$feed_icon_img</div>".
\r
522 "<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
\r
523 $line["feed_title"]."</a> $vf_catchup_link</div>";
\r
527 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');
\r
529 $mouseover_attrs = "onmouseover='postMouseIn($id)'
\r
530 onmouseout='postMouseOut($id)'";
\r
532 $reply['content'] .= "<div class=\"$class\"
\r
533 id=\"RROW-$id\" $mouseover_attrs'>";
\r
535 $reply['content'] .= "<div class=\"cdmHeader\">";
\r
537 $reply['content'] .= "<div>";
\r
539 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
\r
540 'RROW-$id')\" id=\"RCHK-$id\"/>";
\r
542 $reply['content'] .= "$marked_pic";
\r
543 $reply['content'] .= "$published_pic";
\r
545 $reply['content'] .= "</div>";
\r
547 $reply['content'] .= "<div id=\"PTITLE-FULL-$id\" style=\"display : none\">" .
\r
548 strip_tags($line['title']) . "</div>";
\r
550 $reply['content'] .= "<span id=\"RTITLE-$id\"
\r
551 onclick=\"return cdmClicked(event, $id);\"
\r
552 class=\"titleWrap$hlc_suffix\">
\r
554 title=\"".htmlspecialchars($line['title'])."\"
\r
555 target=\"_blank\" href=\"".
\r
556 htmlspecialchars($line["link"])."\">".
\r
557 truncate_string($line["title"], 100) .
\r
558 " $entry_author</a>";
\r
560 $reply['content'] .= $labels_str;
\r
562 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') &&
\r
563 defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
\r
564 if (@$line["feed_title"]) {
\r
565 $reply['content'] .= "<span class=\"hlFeed\">
\r
566 (<a href=\"#\" onclick=\"viewfeed($feed_id)\">".
\r
567 $line["feed_title"]."</a>)
\r
573 $content_hidden = "style=\"display : none\"";
\r
575 $excerpt_hidden = "style=\"display : none\"";
\r
577 $reply['content'] .= "<span $excerpt_hidden
\r
578 id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
\r
580 $reply['content'] .= "</span>";
\r
582 $reply['content'] .= "<div>";
\r
583 $reply['content'] .= "<span class='updated'>$updated_fmt</span>";
\r
584 $reply['content'] .= "$score_pic";
\r
586 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
\r
587 $reply['content'] .= "<span style=\"cursor : pointer\"
\r
588 title=\"".htmlspecialchars($line["feed_title"])."\"
\r
589 onclick=\"viewfeed($feed_id)\">$feed_icon_img</span>";
\r
591 $reply['content'] .= "<div class=\"updPic\">$update_pic</div>";
\r
592 $reply['content'] .= "</div>";
\r
594 $reply['content'] .= "</div>";
\r
596 $reply['content'] .= "<div class=\"cdmContent\" $content_hidden
\r
597 onclick=\"return cdmClicked(event, $id);\"
\r
600 $reply['content'] .= "<div class=\"cdmContentInner\">";
\r
602 if ($line["orig_feed_id"]) {
\r
604 $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds
\r
605 WHERE id = ".$line["orig_feed_id"]);
\r
607 if (db_num_rows($tmp_result) != 0) {
\r
609 $reply['content'] .= "<div clear='both'>";
\r
610 $reply['content'] .= __("Originally from:");
\r
612 $reply['content'] .= " ";
\r
614 $tmp_line = db_fetch_assoc($tmp_result);
\r
616 $reply['content'] .= "<a target='_blank'
\r
617 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
\r
618 $tmp_line['title'] . "</a>";
\r
620 $reply['content'] .= " ";
\r
622 $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
\r
623 $reply['content'] .= "<img title='".__('Feed URL')."'class='tinyFeedIcon' src='images/pub_set.png'></a>";
\r
625 $reply['content'] .= "</div>";
\r
629 $feed_site_url = $line["site_url"];
\r
631 $article_content = sanitize($this->link, $line["content_preview"],
\r
632 false, false, $feed_site_url);
\r
634 $reply['content'] .= "<div id=\"POSTNOTE-$id\">";
\r
635 if ($line['note']) {
\r
636 $reply['content'] .= format_article_note($id, $line['note']);
\r
638 $reply['content'] .= "</div>";
\r
640 $reply['content'] .= "<span id=\"CWRAP-$id\">";
\r
641 $reply['content'] .= $expand_cdm ? $article_content : '';
\r
642 $reply['content'] .= "</span>";
\r
644 /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
\r
645 ttrss_feeds WHERE id = ".
\r
646 (($line['feed_id'] == null) ? $line['orig_feed_id'] :
\r
647 $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
\r
649 $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
\r
650 0, "always_display_enclosures")); */
\r
652 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
\r
654 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures,
\r
657 $reply['content'] .= "</div>";
\r
659 $reply['content'] .= "<div class=\"cdmFooter\">";
\r
661 $tag_cache = $line["tag_cache"];
\r
663 $tags_str = format_tags_string(
\r
664 get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache),
\r
667 $reply['content'] .= "<img src='".theme_image($this->link,
\r
668 'images/tag.png')."' alt='Tags' title='Tags'>
\r
669 <span id=\"ATSTR-$id\">$tags_str</span>
\r
670 <a title=\"".__('Edit tags for this article')."\"
\r
671 href=\"#\" onclick=\"editArticleTags($id, $feed_id, true)\">(+)</a>";
\r
673 $num_comments = $line["num_comments"];
\r
674 $entry_comments = "";
\r
676 if ($num_comments > 0) {
\r
677 if ($line["comments"]) {
\r
678 $comments_url = $line["comments"];
\r
680 $comments_url = $line["link"];
\r
682 $entry_comments = "<a target='_blank' href=\"$comments_url\">$num_comments comments</a>";
\r
684 if ($line["comments"] && $line["link"] != $line["comments"]) {
\r
685 $entry_comments = "<a target='_blank' href=\"".$line["comments"]."\">comments</a>";
\r
689 if ($entry_comments) $reply['content'] .= " ($entry_comments)";
\r
691 $reply['content'] .= "<div style=\"float : right\">";
\r
693 $reply['content'] .= "<img src=\"images/art-zoom.png\"
\r
694 onclick=\"zoomToArticle(event, $id)\"
\r
695 style=\"cursor : pointer\"
\r
697 title='".__('Open article in new tab')."'>";
\r
699 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
\r
701 foreach ($button_plugins as $p) {
\r
702 $reply['content'] .= $p->render($id, $line);
\r
705 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"
\r
706 style=\"cursor : pointer\" style=\"cursor : pointer\"
\r
707 onclick=\"dismissArticle($id)\"
\r
708 title='".__('Close article')."'>";
\r
710 $reply['content'] .= "</div>";
\r
711 $reply['content'] .= "</div>";
\r
713 $reply['content'] .= "</div>";
\r
715 $reply['content'] .= "</div>";
\r
722 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
\r
727 switch ($view_mode) {
\r
729 $message = __("No unread articles found to display.");
\r
732 $message = __("No updated articles found to display.");
\r
735 $message = __("No starred articles found to display.");
\r
739 $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
\r
741 $message = __("No articles found to display.");
\r
745 if (!$offset && $message) {
\r
746 $reply['content'] .= "<div class='whiteBox'>$message";
\r
748 $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
\r
750 $result = db_query($this->link, "SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds
\r
751 WHERE owner_uid = " . $_SESSION['uid']);
\r
753 $last_updated = db_fetch_result($result, 0, "last_updated");
\r
754 $last_updated = make_local_datetime($this->link, $last_updated, false);
\r
756 $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
\r
758 $result = db_query($this->link, "SELECT COUNT(id) AS num_errors
\r
759 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
\r
761 $num_errors = db_fetch_result($result, 0, "num_errors");
\r
763 if ($num_errors > 0) {
\r
764 $reply['content'] .= "<br/>";
\r
765 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">".
\r
766 __('Some feeds have update errors (click for details)')."</a>";
\r
768 $reply['content'] .= "</span></p></div>";
\r
772 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
\r
774 return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
\r
775 $vgroup_last_feed, $reply);
\r
778 private function outputFeedList($special = true) {
\r
780 $feedlist = array();
\r
782 $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
\r
784 $feedlist['identifier'] = 'id';
\r
785 $feedlist['label'] = 'name';
\r
786 $feedlist['items'] = array();
\r
788 $owner_uid = $_SESSION["uid"];
\r
790 /* virtual feeds */
\r
794 if ($enable_cats) {
\r
795 $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
\r
796 $cat = $this->feedlist_init_cat(-1, $cat_hidden);
\r
798 $cat['items'] = array();
\r
801 foreach (array(-4, -3, -1, -2, 0) as $i) {
\r
802 array_push($cat['items'], $this->feedlist_init_feed($i));
\r
805 if ($enable_cats) {
\r
806 array_push($feedlist['items'], $cat);
\r
808 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
\r
811 $result = db_query($this->link, "SELECT * FROM
\r
812 ttrss_labels2 WHERE owner_uid = '$owner_uid' ORDER by caption");
\r
814 if (db_num_rows($result) > 0) {
\r
816 if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
\r
817 $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
\r
818 $cat = $this->feedlist_init_cat(-2, $cat_hidden);
\r
820 $cat['items'] = array();
\r
823 while ($line = db_fetch_assoc($result)) {
\r
825 $label_id = -$line['id'] - 11;
\r
826 $count = getFeedUnread($this->link, $label_id);
\r
828 $feed = $this->feedlist_init_feed($label_id, false, $count);
\r
830 $feed['fg_color'] = $line['fg_color'];
\r
831 $feed['bg_color'] = $line['bg_color'];
\r
833 array_push($cat['items'], $feed);
\r
836 if ($enable_cats) {
\r
837 array_push($feedlist['items'], $cat);
\r
839 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
\r
844 /* if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
\r
845 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
\r
846 $order_by_qpart = "order_id,category,unread DESC,title";
\r
848 $order_by_qpart = "order_id,category,title";
\r
851 if (get_pref($this->link, "FEEDS_SORT_BY_UNREAD")) {
\r
852 $order_by_qpart = "unread DESC,title";
\r
854 $order_by_qpart = "title";
\r
861 $order_by_qpart = "ttrss_feed_categories.order_id,category,
\r
862 ttrss_feeds.order_id,title";
\r
864 $order_by_qpart = "title";
\r
866 $query = "SELECT ttrss_feeds.id, ttrss_feeds.title,
\r
867 ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
\r
869 COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS category,
\r
870 ttrss_feed_categories.collapsed,
\r
872 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
\r
873 ON (ttrss_feed_categories.id = cat_id)
\r
874 LEFT JOIN ttrss_counters_cache
\r
876 (ttrss_feeds.id = feed_id)
\r
878 ttrss_feeds.owner_uid = '$owner_uid'
\r
879 ORDER BY $order_by_qpart";
\r
881 $result = db_query($this->link, $query);
\r
883 $actid = $_REQUEST["actid"];
\r
885 if (db_num_rows($result) > 0) {
\r
890 $cat['items'] = array();
\r
894 while ($line = db_fetch_assoc($result)) {
\r
896 $feed = htmlspecialchars(trim($line["title"]));
\r
898 if (!$feed) $feed = "[Untitled]";
\r
900 $feed_id = $line["id"];
\r
901 $unread = $line["unread"];
\r
903 $cat_id = $line["cat_id"];
\r
904 $tmp_category = $line["category"];
\r
906 if ($category != $tmp_category && $enable_cats) {
\r
908 $category = $tmp_category;
\r
910 $collapsed = sql_bool_to_bool($line["collapsed"]);
\r
912 // workaround for NULL category
\r
913 if ($category == __("Uncategorized")) {
\r
914 $collapsed = get_pref($this->link, "_COLLAPSED_UNCAT");
\r
917 if ($cat) array_push($feedlist['items'], $cat);
\r
919 $cat = $this->feedlist_init_cat($cat_id, $collapsed);
\r
922 $updated = make_local_datetime($this->link, $line["updated_noms"], false);
\r
924 array_push($cat['items'], $this->feedlist_init_feed($feed_id,
\r
925 $feed, $unread, $line['last_error'], $updated));
\r
928 if ($enable_cats) {
\r
929 array_push($feedlist['items'], $cat);
\r
931 $feedlist['items'] = array_merge($feedlist['items'], $cat['items']);
\r
940 function catchupAll() {
\r
941 db_query($this->link, "UPDATE ttrss_user_entries SET
\r
942 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
\r
943 ccache_zero_all($this->link, $_SESSION["uid"]);
\r
946 function collapse() {
\r
947 $cat_id = db_escape_string($_REQUEST["cid"]);
\r
948 $mode = (int) db_escape_string($_REQUEST['mode']);
\r
949 toggle_collapse_cat($this->link, $cat_id, $mode);
\r
953 $root = (bool)$_REQUEST["root"];
\r
956 print json_encode($this->outputFeedList($this->link));
\r
959 $feeds = $this->outputFeedList($this->link, false);
\r
962 $root['id'] = 'root';
\r
963 $root['name'] = __('Feeds');
\r
964 $root['items'] = $feeds['items'];
\r
967 $fl['identifier'] = 'id';
\r
968 $fl['label'] = 'name';
\r
969 $fl['items'] = array($root);
\r
971 print json_encode($fl);
\r
976 $timing_info = getmicrotime();
\r
980 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info);
\r
982 $omode = db_escape_string($_REQUEST["omode"]);
\r
984 $feed = db_escape_string($_REQUEST["feed"]);
\r
985 $method = db_escape_string($_REQUEST["m"]);
\r
986 $view_mode = db_escape_string($_REQUEST["view_mode"]);
\r
987 $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT");
\r
988 @$cat_view = db_escape_string($_REQUEST["cat"]) == "true";
\r
989 @$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
\r
990 @$offset = db_escape_string($_REQUEST["skip"]);
\r
991 @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
\r
992 $order_by = db_escape_string($_REQUEST["order_by"]);
\r
994 if (is_numeric($feed)) $feed = (int) $feed;
\r
996 /* Feed -5 is a special case: it is used to display auxiliary information
\r
997 * when there's nothing to load - e.g. no stuff in fresh feed */
\r
1000 print json_encode(generate_dashboard_feed($this->link));
\r
1006 if ($feed < -10) {
\r
1007 $label_feed = -11-$feed;
\r
1008 $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE
\r
1009 id = '$label_feed' AND owner_uid = " . $_SESSION['uid']);
\r
1010 } else if (!$cat_view && is_numeric($feed) && $feed > 0) {
\r
1011 $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
\r
1012 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
\r
1013 } else if ($cat_view && is_numeric($feed) && $feed > 0) {
\r
1014 $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE
\r
1015 id = '$feed' AND owner_uid = " . $_SESSION['uid']);
\r
1018 if ($result && db_num_rows($result) == 0) {
\r
1019 print json_encode(generate_error_feed($this->link, __("Feed not found.")));
\r
1023 /* Updating a label ccache means recalculating all of the caches
\r
1024 * so for performance reasons we don't do that here */
\r
1027 ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view);
\r
1030 set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode);
\r
1031 set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit);
\r
1032 set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by);
\r
1034 if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) {
\r
1035 db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()
\r
1036 WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]);
\r
1039 $reply['headlines'] = array();
\r
1041 if (!$next_unread_feed)
\r
1042 $reply['headlines']['id'] = $feed;
\r
1044 $reply['headlines']['id'] = $next_unread_feed;
\r
1046 $reply['headlines']['is_cat'] = (bool) $cat_view;
\r
1048 $override_order = false;
\r
1050 if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
\r
1051 $date_sort_field = "updated";
\r
1053 $date_sort_field = "date_entered";
\r
1056 switch ($order_by) {
\r
1058 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
\r
1059 $override_order = "$date_sort_field";
\r
1061 $override_order = "$date_sort_field DESC";
\r
1066 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
\r
1067 $override_order = "title DESC, $date_sort_field";
\r
1069 $override_order = "title, $date_sort_field DESC";
\r
1074 if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) {
\r
1075 $override_order = "score, $date_sort_field";
\r
1077 $override_order = "score DESC, $date_sort_field DESC";
\r
1082 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info);
\r
1084 $ret = $this->format_headlines_list($feed, $method,
\r
1085 $view_mode, $limit, $cat_view, $next_unread_feed, $offset,
\r
1086 $vgroup_last_feed, $override_order);
\r
1088 $topmost_article_ids = $ret[0];
\r
1089 $headlines_count = $ret[1];
\r
1090 $returned_feed = $ret[2];
\r
1091 $disable_cache = $ret[3];
\r
1092 $vgroup_last_feed = $ret[4];
\r
1094 $reply['headlines']['content'] =& $ret[5]['content'];
\r
1095 $reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
\r
1097 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);
\r
1099 $reply['headlines-info'] = array("count" => (int) $headlines_count,
\r
1100 "vgroup_last_feed" => $vgroup_last_feed,
\r
1101 "disable_cache" => (bool) $disable_cache);
\r
1103 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
\r
1105 if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) {
\r
1106 $articles = array();
\r
1108 foreach ($topmost_article_ids as $id) {
\r
1109 array_push($articles, format_article($this->link, $id, false));
\r
1112 $reply['articles'] = $articles;
\r
1115 if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);
\r
1117 $reply['runtime-info'] = make_runtime_info($this->link);
\r
1119 print json_encode($reply);
\r