private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, $override_order = false, $include_children = false) { $disable_cache = false; $reply = array(); $timing_info = getmicrotime(); $topmost_article_ids = array(); if (!$offset) { $offset = 0; } if ($method == "undefined") { $method = ""; } $method_split = explode(":", $method); if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) { include "rssfuncs.php"; update_rss_feed($this->link, $feed, true); } if ($method_split[0] == "MarkAllReadGR") { catchup_feed($this->link, $method_split[1], false); } // FIXME: might break tag display? if (is_numeric($feed) && $feed > 0 && !$cat_view) { $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE id = '{$feed}' LIMIT 1"); if (db_num_rows($result) == 0) { $reply['content'] = "<div align='center'>" . __('Feed not found.') . "</div>"; } } if (is_numeric($feed) && $feed > 0) { $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds\r\n\t\t\t\tWHERE id = '{$feed}' AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($result) == 1) { $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); } else { $rtl_content = false; } if ($rtl_content) { $rtl_tag = "dir=\"RTL\""; } else { $rtl_tag = ""; } } else { $rtl_tag = ""; $rtl_content = false; } @($search = db_escape_string($_REQUEST["query"])); if ($search) { $disable_cache = true; } @($search_mode = db_escape_string($_REQUEST["search_mode"])); @($match_on = db_escape_string($_REQUEST["match_on"])); if (!$match_on) { $match_on = "both"; } if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("H0", $timing_info); } // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]"); if ($search_mode == '' && $method != '') { $search_mode = $method; } // error_log("search_mode: " . $search_mode); $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order, $offset, 0, false, 0, $include_children); if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("H1", $timing_info); } $result = $qfh_ret[0]; $feed_title = $qfh_ret[1]; $feed_site_url = $qfh_ret[2]; $last_error = $qfh_ret[3]; $vgroup_last_feed = $vgr_last_feed; // if (!$offset) { if (db_num_rows($result) > 0) { $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, $feed_title, $feed, $cat_view, $search, $match_on, $search_mode, $view_mode, $last_error); } // } $headlines_count = db_num_rows($result); if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) { $button_plugins = array(); foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) { $pclass = trim("button_{$p}"); if (class_exists($pclass)) { $plugin = new $pclass($link); array_push($button_plugins, $plugin); } } } if (db_num_rows($result) > 0) { $lnum = $offset; $num_unread = 0; $cur_feed_title = ''; $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60; if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("PS", $timing_info); } while ($line = db_fetch_assoc($result)) { $class = $lnum % 2 ? "even" : "odd"; $id = $line["id"]; $feed_id = $line["feed_id"]; $label_cache = $line["label_cache"]; $labels = false; if ($label_cache) { $label_cache = json_decode($label_cache, true); if ($label_cache) { if ($label_cache["no-labels"] == 1) { $labels = array(); } else { $labels = $label_cache; } } } if (!is_array($labels)) { $labels = get_article_labels($this->link, $id); } $labels_str = "<span id=\"HLLCTR-{$id}\">"; $labels_str .= format_article_labels($labels, $id); $labels_str .= "</span>"; if (count($topmost_article_ids) < 3) { array_push($topmost_article_ids, $id); } if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) { $update_pic = "<img id='FUPDPIC-{$id}' src=\"" . theme_image($this->link, 'images/updated.png') . "\"\r\n\t\t\t\t\t\talt=\"Updated\">"; } else { $update_pic = "<img id='FUPDPIC-{$id}' src=\"images/blank_icon.gif\"\r\n\t\t\t\t\t\talt=\"Updated\">"; } if (sql_bool_to_bool($line["unread"]) && time() - strtotime($line["updated_noms"]) < $fresh_intl) { $update_pic = "<img id='FUPDPIC-{$id}' src=\"" . theme_image($this->link, 'images/fresh_sign.png') . "\" alt=\"Fresh\">"; } if ($line["unread"] == "t" || $line["unread"] == "1") { $class .= " Unread"; ++$num_unread; $is_unread = true; } else { $is_unread = false; } if ($line["marked"] == "t" || $line["marked"] == "1") { $marked_pic = "<img id=\"FMPIC-{$id}\"\r\n\t\t\t\t\t\tsrc=\"" . theme_image($this->link, 'images/mark_set.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Unstar article\"\r\n\t\t\t\t\t\tonclick='javascript:toggleMark({$id})'>"; } else { $marked_pic = "<img id=\"FMPIC-{$id}\"\r\n\t\t\t\t\t\tsrc=\"" . theme_image($this->link, 'images/mark_unset.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Star article\"\r\n\t\t\t\t\t\tonclick='javascript:toggleMark({$id})'>"; } if ($line["published"] == "t" || $line["published"] == "1") { $published_pic = "<img id=\"FPPIC-{$id}\" src=\"" . theme_image($this->link, 'images/pub_set.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\"\r\n\t\t\t\t\t\talt=\"Unpublish article\" onclick='javascript:togglePub({$id})'>"; } else { $published_pic = "<img id=\"FPPIC-{$id}\" src=\"" . theme_image($this->link, 'images/pub_unset.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\"\r\n\t\t\t\t\t\talt=\"Publish article\" onclick='javascript:togglePub({$id})'>"; } # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" . # $line["title"] . "</a>"; # $content_link = "<a # href=\"" . htmlspecialchars($line["link"]) . "\" # onclick=\"view($id,$feed_id);\">" . # $line["title"] . "</a>"; # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" . # $line["title"] . "</a>"; $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false); if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) { $content_preview = truncate_string(strip_tags($line["content_preview"]), 100); } $score = $line["score"]; $score_pic = theme_image($this->link, "images/" . get_score_pic($score)); /* $score_title = __("(Click to change)"); $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */ $score_pic = "<img class='hlScorePic' src=\"{$score_pic}\"\r\n\t\t\t\t\ttitle=\"{$score}\">"; if ($score > 500) { $hlc_suffix = "H"; } else { if ($score < -100) { $hlc_suffix = "L"; } else { $hlc_suffix = ""; } } $entry_author = $line["author"]; if ($entry_author) { $entry_author = " - {$entry_author}"; } $has_feed_icon = feed_has_icon($feed_id); if ($has_feed_icon) { $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">"; } else { $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">"; } if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) { if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) { if ($feed_id != $vgroup_last_feed && $line["feed_title"]) { $cur_feed_title = $line["feed_title"]; $vgroup_last_feed = $feed_id; $cur_feed_title = htmlspecialchars($cur_feed_title); $vf_catchup_link = "(<a onclick='catchupFeedInGroup({$feed_id});' href='#'>" . __('mark as read') . "</a>)"; $reply['content'] .= "<div class='cdmFeedTitle'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</div>"; } } $mouseover_attrs = "onmouseover='postMouseIn({$id})'\r\n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'"; $reply['content'] .= "<div class='{$class}' id='RROW-{$id}' {$mouseover_attrs}>"; $reply['content'] .= "<div class='hlUpdPic'>{$update_pic}</div>"; $reply['content'] .= "<div class='hlLeft'>"; $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"\r\n\t\t\t\t\t\t\tid=\"RCHK-{$id}\">"; $reply['content'] .= "{$marked_pic}"; $reply['content'] .= "{$published_pic}"; $reply['content'] .= "</div>"; $reply['content'] .= "<div onclick='return hlClicked(event, {$id})'\r\n\t\t\t\t\t\tclass=\"hlTitle\"><span class='hlContent{$hlc_suffix}'>"; $reply['content'] .= "<a id=\"RTITLE-{$id}\"\r\n\t\t\t\t\t\thref=\"" . htmlspecialchars($line["link"]) . "\"\r\n\t\t\t\t\t\tonclick=\"\">" . truncate_string($line["title"], 200); if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) { if ($content_preview) { $reply['content'] .= "<span class=\"contentPreview\"> - {$content_preview}</span>"; } } $reply['content'] .= "</a></span>"; $reply['content'] .= $labels_str; if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') && defined('_SHOW_FEED_TITLE_IN_VFEEDS')) { if (@$line["feed_title"]) { $reply['content'] .= "<span class=\"hlFeed\">\r\n\t\t\t\t\t\t\t\t(<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a>)\r\n\t\t\t\t\t\t\t</span>"; } } $reply['content'] .= "</div>"; $reply['content'] .= "<span class=\"hlUpdated\">{$updated_fmt}</span>"; $reply['content'] .= "<div class=\"hlRight\">"; $reply['content'] .= $score_pic; if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) { $reply['content'] .= "<span onclick=\"viewfeed({$feed_id})\"\r\n\t\t\t\t\t\t\tstyle=\"cursor : pointer\"\r\n\t\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line['feed_title']) . "\">\r\n\t\t\t\t\t\t\t{$feed_icon_img}<span>"; } $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; } else { if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) { if ($feed_id != $vgroup_last_feed) { $cur_feed_title = $line["feed_title"]; $vgroup_last_feed = $feed_id; $cur_feed_title = htmlspecialchars($cur_feed_title); $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup({$feed_id});' href='#'>" . __('mark as read') . "</a>)"; $has_feed_icon = feed_has_icon($feed_id); if ($has_feed_icon) { $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">"; } else { //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">"; } $reply['content'] .= "<div class='cdmFeedTitle'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</div>"; } } $expand_cdm = get_pref($this->link, 'CDM_EXPANDED'); $mouseover_attrs = "onmouseover='postMouseIn({$id})'\r\n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'"; $reply['content'] .= "<div class=\"{$class}\"\r\n\t\t\t\t\t\tid=\"RROW-{$id}\" {$mouseover_attrs}'>"; $reply['content'] .= "<div class=\"cdmHeader\">"; $reply['content'] .= "<div>"; $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,\r\n\t\t\t\t\t\t\t'RROW-{$id}')\" id=\"RCHK-{$id}\"/>"; $reply['content'] .= "{$marked_pic}"; $reply['content'] .= "{$published_pic}"; $reply['content'] .= "</div>"; $reply['content'] .= "<div id=\"PTITLE-FULL-{$id}\" style=\"display : none\">" . strip_tags($line['title']) . "</div>"; $reply['content'] .= "<span id=\"RTITLE-{$id}\"\r\n\t\t\t\t\t\tonclick=\"return cdmClicked(event, {$id});\"\r\n\t\t\t\t\t\tclass=\"titleWrap{$hlc_suffix}\">\r\n\t\t\t\t\t\t<a class=\"title\"\r\n\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line['title']) . "\"\r\n\t\t\t\t\t\ttarget=\"_blank\" href=\"" . htmlspecialchars($line["link"]) . "\">" . truncate_string($line["title"], 100) . " {$entry_author}</a>"; $reply['content'] .= $labels_str; if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') && defined('_SHOW_FEED_TITLE_IN_VFEEDS')) { if (@$line["feed_title"]) { $reply['content'] .= "<span class=\"hlFeed\">\r\n\t\t\t\t\t\t\t\t(<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a>)\r\n\t\t\t\t\t\t\t</span>"; } } if (!$expand_cdm) { $content_hidden = "style=\"display : none\""; } else { $excerpt_hidden = "style=\"display : none\""; } $reply['content'] .= "<span {$excerpt_hidden}\r\n\t\t\t\t\t\tid=\"CEXC-{$id}\" class=\"cdmExcerpt\"> - {$content_preview}</span>"; $reply['content'] .= "</span>"; $reply['content'] .= "<div>"; $reply['content'] .= "<span class='updated'>{$updated_fmt}</span>"; $reply['content'] .= "{$score_pic}"; if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) { $reply['content'] .= "<span style=\"cursor : pointer\"\r\n\t\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line["feed_title"]) . "\"\r\n\t\t\t\t\t\t\tonclick=\"viewfeed({$feed_id})\">{$feed_icon_img}</span>"; } $reply['content'] .= "<div class=\"updPic\">{$update_pic}</div>"; $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; $reply['content'] .= "<div class=\"cdmContent\" {$content_hidden}\r\n\t\t\t\t\t\tonclick=\"return cdmClicked(event, {$id});\"\r\n\t\t\t\t\t\tid=\"CICD-{$id}\">"; $reply['content'] .= "<div class=\"cdmContentInner\">"; if ($line["orig_feed_id"]) { $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds\r\n\t\t\t\t\tWHERE id = " . $line["orig_feed_id"]); if (db_num_rows($tmp_result) != 0) { $reply['content'] .= "<div clear='both'>"; $reply['content'] .= __("Originally from:"); $reply['content'] .= " "; $tmp_line = db_fetch_assoc($tmp_result); $reply['content'] .= "<a target='_blank'\r\n\t\t\t\t\t\t\t\thref=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . $tmp_line['title'] . "</a>"; $reply['content'] .= " "; $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>"; $reply['content'] .= "<img title='" . __('Feed URL') . "'class='tinyFeedIcon' src='images/pub_set.png'></a>"; $reply['content'] .= "</div>"; } } $feed_site_url = $line["site_url"]; $article_content = sanitize($this->link, $line["content_preview"], false, false, $feed_site_url); $reply['content'] .= "<div id=\"POSTNOTE-{$id}\">"; if ($line['note']) { $reply['content'] .= format_article_note($id, $line['note']); } $reply['content'] .= "</div>"; $reply['content'] .= "<span id=\"CWRAP-{$id}\">"; $reply['content'] .= $expand_cdm ? $article_content : ''; $reply['content'] .= "</span>"; /* $tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM ttrss_feeds WHERE id = ". (($line['feed_id'] == null) ? $line['orig_feed_id'] : $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]); $always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result, 0, "always_display_enclosures")); */ $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]); $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures, $article_content); $reply['content'] .= "</div>"; $reply['content'] .= "<div class=\"cdmFooter\">"; $tag_cache = $line["tag_cache"]; $tags_str = format_tags_string(get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache), $id); $reply['content'] .= "<img src='" . theme_image($this->link, 'images/tag.png') . "' alt='Tags' title='Tags'>\r\n\t\t\t\t\t\t<span id=\"ATSTR-{$id}\">{$tags_str}</span>\r\n\t\t\t\t\t\t<a title=\"" . __('Edit tags for this article') . "\"\r\n\t\t\t\t\t\thref=\"#\" onclick=\"editArticleTags({$id}, {$feed_id}, true)\">(+)</a>"; $num_comments = $line["num_comments"]; $entry_comments = ""; if ($num_comments > 0) { if ($line["comments"]) { $comments_url = $line["comments"]; } else { $comments_url = $line["link"]; } $entry_comments = "<a target='_blank' href=\"{$comments_url}\">{$num_comments} comments</a>"; } else { if ($line["comments"] && $line["link"] != $line["comments"]) { $entry_comments = "<a target='_blank' href=\"" . $line["comments"] . "\">comments</a>"; } } if ($entry_comments) { $reply['content'] .= " ({$entry_comments})"; } $reply['content'] .= "<div style=\"float : right\">"; $reply['content'] .= "<img src=\"images/art-zoom.png\"\r\n\t\t\t\t\t\tonclick=\"zoomToArticle(event, {$id})\"\r\n\t\t\t\t\t\tstyle=\"cursor : pointer\"\r\n\t\t\t\t\t\talt='Zoom'\r\n\t\t\t\t\t\ttitle='" . __('Open article in new tab') . "'>"; //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES); foreach ($button_plugins as $p) { $reply['content'] .= $p->render($id, $line); } $reply['content'] .= "<img src=\"images/digest_checkbox.png\"\r\n\t\t\t\t\t\tstyle=\"cursor : pointer\" style=\"cursor : pointer\"\r\n\t\t\t\t\t\tonclick=\"dismissArticle({$id})\"\r\n\t\t\t\t\t\ttitle='" . __('Close article') . "'>"; $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; } ++$lnum; } if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("PE", $timing_info); } } else { $message = ""; switch ($view_mode) { case "unread": $message = __("No unread articles found to display."); break; case "updated": $message = __("No updated articles found to display."); break; case "marked": $message = __("No starred articles found to display."); break; default: if ($feed < -10) { $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter."); } else { $message = __("No articles found to display."); } } if (!$offset && $message) { $reply['content'] .= "<div class='whiteBox'>{$message}"; $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">"; $result = db_query($this->link, "SELECT " . SUBSTRING_FOR_DATE . "(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds\r\n\t\t\t\t\tWHERE owner_uid = " . $_SESSION['uid']); $last_updated = db_fetch_result($result, 0, "last_updated"); $last_updated = make_local_datetime($this->link, $last_updated, false); $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); $result = db_query($this->link, "SELECT COUNT(id) AS num_errors\r\n\t\t\t\t\tFROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION["uid"]); $num_errors = db_fetch_result($result, 0, "num_errors"); if ($num_errors > 0) { $reply['content'] .= "<br/>"; $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">" . __('Some feeds have update errors (click for details)') . "</a>"; } $reply['content'] .= "</span></p></div>"; } } if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("H2", $timing_info); } return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $vgroup_last_feed, $reply); }
/** * @return array (code => Status code, message => error message if available) * * 0 - OK, Feed already exists * 1 - OK, Feed added * 2 - Invalid URL * 3 - URL content is HTML, no feeds available * 4 - URL content is HTML which contains multiple feeds. * Here you should call extractfeedurls in rpc-backend * to get all possible feeds. * 5 - Couldn't download the URL content. * 6 - Content is an invalid XML. */ function subscribe_to_feed($url, $cat_id = 0, $auth_login = '', $auth_pass = '') { global $fetch_last_error; require_once "include/rssfuncs.php"; $url = fix_url($url); if (!$url || !validate_feed_url($url)) { return array("code" => 2); } $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass); if (!$contents) { return array("code" => 5, "message" => $fetch_last_error); } foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SUBSCRIBE_FEED) as $plugin) { $contents = $plugin->hook_subscribe_feed($contents, $url, $auth_login, $auth_pass); } if (is_html($contents)) { $feedUrls = get_feeds_from_html($url, $contents); if (count($feedUrls) == 0) { return array("code" => 3); } else { if (count($feedUrls) > 1) { return array("code" => 4, "feeds" => $feedUrls); } } //use feed url as new URL $url = key($feedUrls); } if ($cat_id == "0" || !$cat_id) { $cat_qpart = "NULL"; } else { $cat_qpart = "'{$cat_id}'"; } $result = db_query("SELECT id FROM ttrss_feeds\n\t\t\tWHERE feed_url = '{$url}' AND owner_uid = " . $_SESSION["uid"]); if (strlen(FEED_CRYPT_KEY) > 0) { require_once "crypt.php"; $auth_pass = substr(encrypt_string($auth_pass), 0, 250); $auth_pass_encrypted = 'true'; } else { $auth_pass_encrypted = 'false'; } $auth_pass = db_escape_string($auth_pass); if (db_num_rows($result) == 0) { $result = db_query("INSERT INTO ttrss_feeds\n\t\t\t\t\t(owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method,auth_pass_encrypted)\n\t\t\t\tVALUES ('" . $_SESSION["uid"] . "', '{$url}',\n\t\t\t\t'[Unknown]', {$cat_qpart}, '{$auth_login}', '{$auth_pass}', 0, {$auth_pass_encrypted})"); $result = db_query("SELECT id FROM ttrss_feeds WHERE feed_url = '{$url}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); $feed_id = db_fetch_result($result, 0, "id"); if ($feed_id) { update_rss_feed($feed_id, true); } return array("code" => 1); } else { return array("code" => 0); } }
function updaterandomfeed() { // Test if the feed need a update (update interval exceded). if (DB_TYPE == "pgsql") { $update_limit_qpart = "AND ((\n\t\t\t\t\tttrss_feeds.update_interval = 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)\n\t\t\t\t) OR (\n\t\t\t\t\tttrss_feeds.update_interval > 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)\n\t\t\t\t) OR ttrss_feeds.last_updated IS NULL\n\t\t\t\tOR last_updated = '1970-01-01 00:00:00')"; } else { $update_limit_qpart = "AND ((\n\t\t\t\t\tttrss_feeds.update_interval = 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)\n\t\t\t\t) OR (\n\t\t\t\t\tttrss_feeds.update_interval > 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)\n\t\t\t\t) OR ttrss_feeds.last_updated IS NULL\n\t\t\t\tOR last_updated = '1970-01-01 00:00:00')"; } // Test if feed is currently being updated by another process. if (DB_TYPE == "pgsql") { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; } else { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; } $random_qpart = sql_random_function(); // We search for feed needing update. $result = db_query($this->link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id\n\t\t\tFROM\n\t\t\t\tttrss_feeds, ttrss_users, ttrss_user_prefs\n\t\t\tWHERE\n\t\t\t\tttrss_feeds.owner_uid = ttrss_users.id\n\t\t\t\tAND ttrss_users.id = ttrss_user_prefs.owner_uid\n\t\t\t\tAND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'\n\t\t\t\tAND ttrss_feeds.owner_uid = " . $_SESSION["uid"] . "\n\t\t\t\t{$update_limit_qpart} {$updstart_thresh_qpart}\n\t\t\tORDER BY {$random_qpart} LIMIT 30"); $feed_id = -1; require_once "rssfuncs.php"; $num_updated = 0; $tstart = time(); while ($line = db_fetch_assoc($result)) { $feed_id = $line["id"]; if (time() - $tstart < ini_get("max_execution_time") * 0.7) { update_rss_feed($this->link, $feed_id, true); ++$num_updated; } else { break; } } if ($num_updated > 0) { print json_encode(array("message" => "UPDATE_COUNTERS", "num_updated" => $num_updated)); } else { print json_encode(array("message" => "NOTHING_TO_UPDATE")); } }
/** * @return array (code => Status code, message => error message if available) * * 0 - OK, Feed already exists * 1 - OK, Feed added * 2 - Invalid URL * 3 - URL content is HTML, no feeds available * 4 - URL content is HTML which contains multiple feeds. * Here you should call extractfeedurls in rpc-backend * to get all possible feeds. * 5 - Couldn't download the URL content. */ function subscribe_to_feed($link, $url, $cat_id = 0, $auth_login = '', $auth_pass = '', $need_auth = false) { global $fetch_last_error; require_once "include/rssfuncs.php"; $url = fix_url($url); if (!$url || !validate_feed_url($url)) { return array("code" => 2); } $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass); if (!$contents) { return array("code" => 5, "message" => $fetch_last_error); } if (is_html($contents)) { $feedUrls = get_feeds_from_html($url, $contents); if (count($feedUrls) == 0) { return array("code" => 3); } else { if (count($feedUrls) > 1) { return array("code" => 4, "feeds" => $feedUrls); } } //use feed url as new URL $url = key($feedUrls); } if ($cat_id == "0" || !$cat_id) { $cat_qpart = "NULL"; } else { $cat_qpart = "'{$cat_id}'"; } $result = db_query($link, "SELECT id FROM ttrss_feeds\n\t\t\tWHERE feed_url = '{$url}' AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($result) == 0) { $result = db_query($link, "INSERT INTO ttrss_feeds\n\t\t\t\t\t(owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method)\n\t\t\t\tVALUES ('" . $_SESSION["uid"] . "', '{$url}',\n\t\t\t\t'[Unknown]', {$cat_qpart}, '{$auth_login}', '{$auth_pass}', 0)"); $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE feed_url = '{$url}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); $feed_id = db_fetch_result($result, 0, "id"); if ($feed_id) { update_rss_feed($link, $feed_id, true); } return array("code" => 1); } else { return array("code" => 0); } }
/** * Update a feed batch. * Used by daemons to update n feeds by run. * Only update feed needing a update, and not being processed * by another process. * * @param mixed $link Database link * @param integer $limit Maximum number of feeds in update batch. Default to DAEMON_FEED_LIMIT. * @param boolean $from_http Set to true if you call this function from http to disable cli specific code. * @param boolean $debug Set to false to disable debug output. Default to true. * @return void */ function update_daemon_common($link, $limit = DAEMON_FEED_LIMIT, $from_http = false, $debug = true) { // Process all other feeds using last_updated and interval parameters // Test if the user has loggued in recently. If not, it does not update its feeds. if (DAEMON_UPDATE_LOGIN_LIMIT > 0) { if (DB_TYPE == "pgsql") { $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '" . DAEMON_UPDATE_LOGIN_LIMIT . " days'"; } else { $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL " . DAEMON_UPDATE_LOGIN_LIMIT . " DAY)"; } } else { $login_thresh_qpart = ""; } // Test if the feed need a update (update interval exceded). if (DB_TYPE == "pgsql") { $update_limit_qpart = "AND ((\n\t\t\t\t\tttrss_feeds.update_interval = 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)\n\t\t\t\t) OR (\n\t\t\t\t\tttrss_feeds.update_interval > 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)\n\t\t\t\t) OR ttrss_feeds.last_updated IS NULL)"; } else { $update_limit_qpart = "AND ((\n\t\t\t\t\tttrss_feeds.update_interval = 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)\n\t\t\t\t) OR (\n\t\t\t\t\tttrss_feeds.update_interval > 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)\n\t\t\t\t) OR ttrss_feeds.last_updated IS NULL)"; } // Test if feed is currently being updated by another process. if (DB_TYPE == "pgsql") { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')"; } else { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; } // Test if there is a limit to number of updated feeds $query_limit = ""; if ($limit) { $query_limit = sprintf("LIMIT %d", $limit); } $random_qpart = sql_random_function(); // We search for feed needing update. $result = db_query($link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id, ttrss_feeds.owner_uid,\n\t\t\t\t" . SUBSTRING_FOR_DATE . "(ttrss_feeds.last_updated,1,19) AS last_updated,\n\t\t\t\tttrss_feeds.update_interval \n\t\t\tFROM \n\t\t\t\tttrss_feeds, ttrss_users, ttrss_user_prefs\n\t\t\tWHERE\n\t\t\t\tttrss_feeds.owner_uid = ttrss_users.id\n\t\t\t\tAND ttrss_users.id = ttrss_user_prefs.owner_uid\n\t\t\t\tAND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'\n\t\t\t\t{$login_thresh_qpart} {$update_limit_qpart}\n\t\t\t {$updstart_thresh_qpart}\n\t\t\tORDER BY {$random_qpart} {$query_limit}"); $user_prefs_cache = array(); if ($debug) { _debug(sprintf("Scheduled %d feeds to update...\n", db_num_rows($result))); } // Here is a little cache magic in order to minimize risk of double feed updates. $feeds_to_update = array(); while ($line = db_fetch_assoc($result)) { $feeds_to_update[$line['id']] = $line; } // We update the feed last update started date before anything else. // There is no lag due to feed contents downloads // It prevent an other process to update the same feed. $feed_ids = array_keys($feeds_to_update); if ($feed_ids) { db_query($link, sprintf("UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\t\tWHERE id IN (%s)", implode(',', $feed_ids))); } // For each feed, we call the feed update function. while ($line = array_pop($feeds_to_update)) { if ($debug) { _debug("Feed: " . $line["feed_url"] . ", " . $line["last_updated"]); } // We setup a alarm to alert if the feed take more than 300s to update. // => HANG alarm. if (!$from_http && function_exists('pcntl_alarm')) { pcntl_alarm(300); } update_rss_feed($link, $line["id"], true); // Cancel the alarm (the update went well) if (!$from_http && function_exists('pcntl_alarm')) { pcntl_alarm(0); } sleep(1); // prevent flood (FIXME make this an option?) } // Send feed digests by email if needed. if (DAEMON_SENDS_DIGESTS) { send_headlines_digests($link); } purge_orphans($link); }
private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, $override_order = false, $include_children = false) { if (isset($_REQUEST["DevForceUpdate"])) { header("Content-Type: text/plain; charset=utf-8"); } $disable_cache = false; $reply = array(); $rgba_cache = array(); $timing_info = microtime(true); $topmost_article_ids = array(); if (!$offset) { $offset = 0; } if ($method == "undefined") { $method = ""; } $method_split = explode(":", $method); if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) { // Update the feed if required with some basic flood control $result = $this->dbh->query("SELECT cache_images," . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated\n\t\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'"); if ($this->dbh->num_rows($result) != 0) { $last_updated = strtotime($this->dbh->fetch_result($result, 0, "last_updated")); $cache_images = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "cache_images")); if (!$cache_images && time() - $last_updated > 120 || isset($_REQUEST['DevForceUpdate'])) { include "rssfuncs.php"; update_rss_feed($feed, true, true); } else { $this->dbh->query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'\n\t\t\t\t\t\t\tWHERE id = '{$feed}'"); } } } if ($method_split[0] == "MarkAllReadGR") { catchup_feed($method_split[1], false); } // FIXME: might break tag display? if (is_numeric($feed) && $feed > 0 && !$cat_view) { $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE id = '{$feed}' LIMIT 1"); if ($this->dbh->num_rows($result) == 0) { $reply['content'] = "<div align='center'>" . __('Feed not found.') . "</div>"; } } @($search = $this->dbh->escape_string($_REQUEST["query"])); if ($search) { $disable_cache = true; } @($search_mode = $this->dbh->escape_string($_REQUEST["search_mode"])); if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("H0", $timing_info); } // error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]"); if ($search_mode == '' && $method != '') { $search_mode = $method; } // error_log("search_mode: " . $search_mode); if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { $handler = PluginHost::getInstance()->get_feed_handler(PluginHost::feed_to_pfeed_id($feed)); // function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false) { if ($handler) { $options = array("limit" => $limit, "view_mode" => $view_mode, "cat_view" => $cat_view, "search" => $search, "search_mode" => $search_mode, "override_order" => $override_order, "offset" => $offset, "owner_uid" => $_SESSION["uid"], "filter" => false, "since_id" => 0, "include_children" => $include_children); $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $options); } } else { $qfh_ret = queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order, $offset, 0, false, 0, $include_children); } $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && $feed != -6; if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("H1", $timing_info); } $result = $qfh_ret[0]; $feed_title = $qfh_ret[1]; $feed_site_url = $qfh_ret[2]; $last_error = $qfh_ret[3]; $last_updated = strpos($qfh_ret[4], '1970-') === FALSE ? make_local_datetime($qfh_ret[4], false) : __("Never"); $highlight_words = $qfh_ret[5]; $vgroup_last_feed = $vgr_last_feed; $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, $feed_title, $feed, $cat_view, $search, $search_mode, $view_mode, $last_error, $last_updated); $headlines_count = $this->dbh->num_rows($result); /* if (get_pref('COMBINED_DISPLAY_MODE')) { $button_plugins = array(); foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) { $pclass = "button_" . trim($p); if (class_exists($pclass)) { $plugin = new $pclass(); array_push($button_plugins, $plugin); } } } */ if ($offset == 0) { foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINES_BEFORE) as $p) { $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret); } } if ($this->dbh->num_rows($result) > 0) { $lnum = $offset; $num_unread = 0; $cur_feed_title = ''; if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("PS", $timing_info); } $expand_cdm = get_pref('CDM_EXPANDED'); while ($line = $this->dbh->fetch_assoc($result)) { $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { $line = $p->hook_query_headlines($line, 250, false); } if (get_pref('SHOW_CONTENT_PREVIEW')) { $content_preview = $line["content_preview"]; } $id = $line["id"]; $feed_id = $line["feed_id"]; $label_cache = $line["label_cache"]; $labels = false; if ($label_cache) { $label_cache = json_decode($label_cache, true); if ($label_cache) { if ($label_cache["no-labels"] == 1) { $labels = array(); } else { $labels = $label_cache; } } } if (!is_array($labels)) { $labels = get_article_labels($id); } $labels_str = "<span class=\"HLLCTR-{$id}\">"; $labels_str .= format_article_labels($labels, $id); $labels_str .= "</span>"; if (count($topmost_article_ids) < 3) { array_push($topmost_article_ids, $id); } $class = ""; if (sql_bool_to_bool($line["unread"])) { $class .= " Unread"; ++$num_unread; } if (sql_bool_to_bool($line["marked"])) { $marked_pic = "<img\n\t\t\t\t\t\tsrc=\"images/mark_set.png\"\n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Unstar article\"\n\t\t\t\t\t\tonclick='toggleMark({$id})'>"; $class .= " marked"; } else { $marked_pic = "<img\n\t\t\t\t\t\tsrc=\"images/mark_unset.png\"\n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Star article\"\n\t\t\t\t\t\tonclick='toggleMark({$id})'>"; } if (sql_bool_to_bool($line["published"])) { $published_pic = "<img src=\"images/pub_set.png\"\n\t\t\t\t\t\tclass=\"pubPic\"\n\t\t\t\t\t\t\talt=\"Unpublish article\" onclick='togglePub({$id})'>"; $class .= " published"; } else { $published_pic = "<img src=\"images/pub_unset.png\"\n\t\t\t\t\t\tclass=\"pubPic\"\n\t\t\t\t\t\talt=\"Publish article\" onclick='togglePub({$id})'>"; } # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" . # $line["title"] . "</a>"; # $content_link = "<a # href=\"" . htmlspecialchars($line["link"]) . "\" # onclick=\"view($id,$feed_id);\">" . # $line["title"] . "</a>"; # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" . # $line["title"] . "</a>"; $updated_fmt = make_local_datetime($line["updated"], false); $date_entered_fmt = T_sprintf("Imported at %s", make_local_datetime($line["date_entered"], false)); $score = $line["score"]; $score_pic = "images/" . get_score_pic($score); /* $score_title = __("(Click to change)"); $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */ $score_pic = "<img class='hlScorePic' score='{$score}' onclick='changeScore({$id}, this)' src=\"{$score_pic}\"\n\t\t\t\t\ttitle=\"{$score}\">"; if ($score > 500) { $hlc_suffix = "high"; } else { if ($score < -100) { $hlc_suffix = "low"; } else { $hlc_suffix = ""; } } $entry_author = $line["author"]; if ($entry_author) { $entry_author = " — {$entry_author}"; } $has_feed_icon = feed_has_icon($feed_id); if ($has_feed_icon) { $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">"; } else { $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/pub_set.png\" alt=\"\">"; } $entry_site_url = $line["site_url"]; //setting feed headline background color, needs to change text color based on dark/light $fav_color = $line['favicon_avg_color']; require_once "colors.php"; if ($fav_color && $fav_color != 'fail') { if (!isset($rgba_cache[$feed_id])) { $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color)); } } if (!get_pref('COMBINED_DISPLAY_MODE')) { if ($vfeed_group_enabled) { if ($feed_id != $vgroup_last_feed && $line["feed_title"]) { $cur_feed_title = $line["feed_title"]; $vgroup_last_feed = $feed_id; $cur_feed_title = htmlspecialchars($cur_feed_title); $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup({$feed_id});' href='#'>" . __('mark feed as read') . "</a>"; $reply['content'] .= "<div id='FTITLE-{$feed_id}' class='cdmFeedTitle'>" . "<div style='float : right'>{$feed_icon_img}</div>" . "<a class='title' href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a>\n\t\t\t\t\t\t\t\t{$vf_catchup_link}</div>"; } } $mouseover_attrs = "onmouseover='postMouseIn(event, {$id})'\n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'"; $reply['content'] .= "<div class='hl {$class}' orig-feed-id='{$feed_id}' id='RROW-{$id}' {$mouseover_attrs}>"; $reply['content'] .= "<div class='hlLeft'>"; $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"\n\t\t\t\t\t\t\ttype=\"checkbox\" onclick=\"toggleSelectRow2(this)\"\n\t\t\t\t\t\t\tclass='rchk'>"; $reply['content'] .= "{$marked_pic}"; $reply['content'] .= "{$published_pic}"; $reply['content'] .= "</div>"; $reply['content'] .= "<div onclick='return hlClicked(event, {$id})'\n\t\t\t\t\t\tclass=\"hlTitle\"><span class='hlContent {$hlc_suffix}'>"; $reply['content'] .= "<a id=\"RTITLE-{$id}\" class=\"title {$hlc_suffix}\"\n\t\t\t\t\t\thref=\"" . htmlspecialchars($line["link"]) . "\"\n\t\t\t\t\t\tonclick=\"\">" . truncate_string($line["title"], 200); if (get_pref('SHOW_CONTENT_PREVIEW')) { $reply['content'] .= "<span class=\"contentPreview\">" . $line["content_preview"] . "</span>"; } $reply['content'] .= "</a></span>"; $reply['content'] .= $labels_str; $reply['content'] .= "</div>"; if (!$vfeed_group_enabled) { if (@$line["feed_title"]) { $rgba = @$rgba_cache[$feed_id]; $reply['content'] .= "<span class=\"hlFeed\"><a style=\"background : rgba({$rgba}, 0.3)\" href=\"#\" onclick=\"viewfeed({$feed_id})\">" . truncate_string($line["feed_title"], 30) . "</a></span>"; } } $reply['content'] .= "<span class=\"hlUpdated\">"; $reply['content'] .= "<div title='{$date_entered_fmt}'>{$updated_fmt}</div>\n\t\t\t\t\t\t</span>"; $reply['content'] .= "<div class=\"hlRight\">"; $reply['content'] .= $score_pic; if ($line["feed_title"] && !$vfeed_group_enabled) { $reply['content'] .= "<span onclick=\"viewfeed({$feed_id})\"\n\t\t\t\t\t\t\tstyle=\"cursor : pointer\"\n\t\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line['feed_title']) . "\">\n\t\t\t\t\t\t\t{$feed_icon_img}</span>"; } $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; } else { if ($line["tag_cache"]) { $tags = explode(",", $line["tag_cache"]); } else { $tags = false; } $line["content"] = sanitize($line["content"], sql_bool_to_bool($line['hide_images']), false, $entry_site_url, $highlight_words, $line["id"]); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) { $line = $p->hook_render_article_cdm($line); } if ($vfeed_group_enabled && $line["feed_title"]) { if ($feed_id != $vgroup_last_feed) { $cur_feed_title = $line["feed_title"]; $vgroup_last_feed = $feed_id; $cur_feed_title = htmlspecialchars($cur_feed_title); $vf_catchup_link = "<a class='catchup' onclick='catchupFeedInGroup({$feed_id});' href='#'>" . __('mark feed as read') . "</a>"; $has_feed_icon = feed_has_icon($feed_id); if ($has_feed_icon) { $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">"; } else { //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">"; } $reply['content'] .= "<div id='FTITLE-{$feed_id}' class='cdmFeedTitle'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"#\" class='title' onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</div>"; } } $mouseover_attrs = "onmouseover='postMouseIn(event, {$id})'\n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'"; $expanded_class = $expand_cdm ? "expanded" : "expandable"; $reply['content'] .= "<div class=\"cdm {$hlc_suffix} {$expanded_class} {$class}\"\n\t\t\t\t\t\tid=\"RROW-{$id}\" orig-feed-id='{$feed_id}' {$mouseover_attrs}>"; $reply['content'] .= "<div class=\"cdmHeader\">"; $reply['content'] .= "<div style=\"vertical-align : middle\">"; $reply['content'] .= "<input dojoType=\"dijit.form.CheckBox\"\n\t\t\t\t\t\t\ttype=\"checkbox\" onclick=\"toggleSelectRow2(this, false, true)\"\n\t\t\t\t\t\t\tclass='rchk'>"; $reply['content'] .= "{$marked_pic}"; $reply['content'] .= "{$published_pic}"; $reply['content'] .= "</div>"; if ($highlight_words && count($highlight_words > 0)) { foreach ($highlight_words as $word) { $line["title"] = preg_replace("/(\\Q{$word}\\E)/i", "<span class=\"highlight\">\$1</span>", $line["title"]); } } $reply['content'] .= "<span id=\"RTITLE-{$id}\"\n\t\t\t\t\t\tonclick=\"return cdmClicked(event, {$id});\"\n\t\t\t\t\t\tclass=\"titleWrap {$hlc_suffix}\">\n\t\t\t\t\t\t<a class=\"title {$hlc_suffix}\"\n\t\t\t\t\t\ttarget=\"_blank\" href=\"" . htmlspecialchars($line["link"]) . "\">" . $line["title"] . "</a> <span class=\"author\">{$entry_author}</span>"; $reply['content'] .= $labels_str; $reply['content'] .= "<span class='collapseBtn' style='display : none'>\n\t\t\t\t\t\t<img src=\"images/collapse.png\" onclick=\"cdmCollapseArticle(event, {$id})\"\n\t\t\t\t\t\ttitle=\"" . __("Collapse article") . "\"/></span>"; if (!$expand_cdm) { $content_hidden = "style=\"display : none\""; } else { $excerpt_hidden = "style=\"display : none\""; } $reply['content'] .= "<span {$excerpt_hidden} id=\"CEXC-{$id}\" class=\"cdmExcerpt\">" . $content_preview . "</span>"; $reply['content'] .= "</span>"; if (!$vfeed_group_enabled) { if (@$line["feed_title"]) { $rgba = @$rgba_cache[$feed_id]; $reply['content'] .= "<div class=\"hlFeed\">\n\t\t\t\t\t\t\t\t<a href=\"#\" style=\"background-color: rgba({$rgba},0.3)\"\n\t\t\t\t\t\t\t\tonclick=\"viewfeed({$feed_id})\">" . truncate_string($line["feed_title"], 30) . "</a>\n\t\t\t\t\t\t\t</div>"; } } $reply['content'] .= "<span class='updated' title='{$date_entered_fmt}'>\n\t\t\t\t\t\t{$updated_fmt}</span>"; $reply['content'] .= "<div class='scoreWrap' style=\"vertical-align : middle\">"; $reply['content'] .= "{$score_pic}"; if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) { $reply['content'] .= "<span style=\"cursor : pointer\"\n\t\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line["feed_title"]) . "\"\n\t\t\t\t\t\t\tonclick=\"viewfeed({$feed_id})\">{$feed_icon_img}</span>"; } $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; $reply['content'] .= "<div class=\"cdmContent\" {$content_hidden}\n\t\t\t\t\t\tonclick=\"return cdmClicked(event, {$id});\"\n\t\t\t\t\t\tid=\"CICD-{$id}\">"; $reply['content'] .= "<div id=\"POSTNOTE-{$id}\">"; if ($line['note']) { $reply['content'] .= format_article_note($id, $line['note']); } $reply['content'] .= "</div>"; if (!$line['lang']) { $line['lang'] = 'en'; } $reply['content'] .= "<div class=\"cdmContentInner\" lang=\"" . $line['lang'] . "\">"; if ($line["orig_feed_id"]) { $tmp_result = $this->dbh->query("SELECT * FROM ttrss_archived_feeds\n\t\t\t\t\tWHERE id = " . $line["orig_feed_id"]); if ($this->dbh->num_rows($tmp_result) != 0) { $reply['content'] .= "<div clear='both'>"; $reply['content'] .= __("Originally from:"); $reply['content'] .= " "; $tmp_line = $this->dbh->fetch_assoc($tmp_result); $reply['content'] .= "<a target='_blank'\n\t\t\t\t\t\t\t\thref=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . $tmp_line['title'] . "</a>"; $reply['content'] .= " "; $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>"; $reply['content'] .= "<img title='" . __('Feed URL') . "'class='tinyFeedIcon' src='images/pub_unset.png'></a>"; $reply['content'] .= "</div>"; } } $reply['content'] .= "<span id=\"CWRAP-{$id}\">"; // if (!$expand_cdm) { $reply['content'] .= "<span id=\"CENCW-{$id}\" style=\"display : none\">"; $reply['content'] .= htmlspecialchars($line["content"]); $reply['content'] .= "</span."; // } else { // $reply['content'] .= $line["content"]; // } $reply['content'] .= "</span>"; $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]); $reply['content'] .= format_article_enclosures($id, $always_display_enclosures, $line["content"], sql_bool_to_bool($line["hide_images"])); $reply['content'] .= "</div>"; $reply['content'] .= "<div class=\"cdmFooter\">"; foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { $reply['content'] .= $p->hook_article_left_button($line); } $tags_str = format_tags_string($tags, $id); $reply['content'] .= "<img src='images/tag.png' alt='Tags' title='Tags'>\n\t\t\t\t\t\t<span id=\"ATSTR-{$id}\">{$tags_str}</span>\n\t\t\t\t\t\t<a title=\"" . __('Edit tags for this article') . "\"\n\t\t\t\t\t\thref=\"#\" onclick=\"editArticleTags({$id})\">(+)</a>"; $num_comments = $line["num_comments"]; $entry_comments = ""; if ($num_comments > 0) { if ($line["comments"]) { $comments_url = htmlspecialchars($line["comments"]); } else { $comments_url = htmlspecialchars($line["link"]); } $entry_comments = "<a class=\"postComments\"\n\t\t\t\t\t\t\ttarget='_blank' href=\"{$comments_url}\">{$num_comments} " . _ngettext("comment", "comments", $num_comments) . "</a>"; } else { if ($line["comments"] && $line["link"] != $line["comments"]) { $entry_comments = "<a class=\"postComments\" target='_blank' href=\"" . htmlspecialchars($line["comments"]) . "\">" . __("comments") . "</a>"; } } if ($entry_comments) { $reply['content'] .= " ({$entry_comments})"; } $reply['content'] .= "<div style=\"float : right\">"; // $reply['content'] .= "$marked_pic"; // $reply['content'] .= "$published_pic"; foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) { $reply['content'] .= $p->hook_article_button($line); } $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; $reply['content'] .= "</div>"; } ++$lnum; } if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("PE", $timing_info); } } else { $message = ""; switch ($view_mode) { case "unread": $message = __("No unread articles found to display."); break; case "updated": $message = __("No updated articles found to display."); break; case "marked": $message = __("No starred articles found to display."); break; default: if ($feed < LABEL_BASE_INDEX) { $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter."); } else { $message = __("No articles found to display."); } } if (!$offset && $message) { $reply['content'] .= "<div class='whiteBox'>{$message}"; $reply['content'] .= "<p><span class=\"insensitive\">"; $result = $this->dbh->query("SELECT " . SUBSTRING_FOR_DATE . "(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds\n\t\t\t\t\tWHERE owner_uid = " . $_SESSION['uid']); $last_updated = $this->dbh->fetch_result($result, 0, "last_updated"); $last_updated = make_local_datetime($last_updated, false); $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); $result = $this->dbh->query("SELECT COUNT(id) AS num_errors\n\t\t\t\t\tFROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION["uid"]); $num_errors = $this->dbh->fetch_result($result, 0, "num_errors"); if ($num_errors > 0) { $reply['content'] .= "<br/>"; $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">" . __('Some feeds have update errors (click for details)') . "</a>"; } $reply['content'] .= "</span></p></div>"; } } if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("H2", $timing_info); } return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $vgroup_last_feed, $reply); }
function updateFeed() { $feed_id = db_escape_string($_REQUEST["feed_id"]); update_rss_feed($this->link, $feed_id, true); print $this->wrap(self::STATUS_OK, array("status" => "OK")); }
array_push($articles, $article); } } print api_wrap_reply(API_STATUS_OK, $seq, $articles); break; case "getConfig": $config = array("icons_dir" => ICONS_DIR, "icons_url" => ICONS_URL); $config["daemon_is_running"] = file_is_locked("update_daemon.lock"); $result = db_query($link, "SELECT COUNT(*) AS cf FROM\n\t\t\t\tttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]); $num_feeds = db_fetch_result($result, 0, "cf"); $config["num_feeds"] = (int) $num_feeds; print api_wrap_reply(API_STATUS_OK, $seq, $config); break; case "updateFeed": $feed_id = db_escape_string($_REQUEST["feed_id"]); update_rss_feed($link, $feed_id, true); print api_wrap_reply(API_STATUS_OK, $seq, array("status" => "OK")); break; case "catchupFeed": $feed_id = db_escape_string($_REQUEST["feed_id"]); $is_cat = db_escape_string($_REQUEST["is_cat"]); catchup_feed($link, $feed_id, $is_cat); print api_wrap_reply(API_STATUS_OK, $seq, array("status" => "OK")); break; case "getPref": $pref_name = db_escape_string($_REQUEST["pref_name"]); print api_wrap_reply(API_STATUS_OK, $seq, array("value" => get_pref($link, $pref_name))); break; default: print api_wrap_reply(API_STATUS_ERR, $seq, array("error" => 'UNKNOWN_METHOD')); break;
$_SESSION['intended_location'] = $_SERVER['PHP_SELF']; } header('location: http://www.siskiyourappellers.com/admin/index.php'); } //------------------------------------------------------------------------------------------- if (isset($_POST['update_text']) && $_POST['update_text'] != '') { $current_text = nl2br(htmlentities($_POST['update_text'], ENT_QUOTES)); $current_sticky = nl2br(htmlentities($_POST['sticky_text'], ENT_QUOTES)); $current_text = filter_var($current_text, FILTER_SANITIZE_STRING); $current_sticky = filter_var($current_sticky, FILTER_SANITIZE_STRING); $query = "INSERT INTO current (name, date, status) VALUES('" . $_POST['name'] . "', NOW(), '" . $current_text . "')"; mydb::cxn()->query($query); $query = "UPDATE current_sticky SET name='" . $_POST['name'] . "', date=NOW(), status='" . $current_sticky . "' WHERE 1"; mydb::cxn()->query($query); //update_rss_feed($current_sticky, $current_text, time()); update_rss_feed(); header('location: http://www.siskiyourappellers.com/current.php'); //header('location: http://www.siskiyourappellers.com/admin/update_facebook_wall.php'); exit; } $query_read_sticky = "SELECT name, unix_timestamp(date) as date, status FROM current_sticky WHERE 1"; if (!($result = mydb::cxn()->query($query_read_sticky))) { $sticky_text = "Error retrieving sticky post: " . mydb::cxn()->error; } else { $row = $result->fetch_assoc(); $sticky_text = str_replace("<br />", "", $row['status']); $sticky_name = $row['name']; $sticky_date = date('d-M-Y H:i', $row['date']); } //--------------------------------------------------------------------------------------------------- ?>
function update_debugger() { header("Content-type: text/html"); $feed_id = (int) $_REQUEST["feed_id"]; @($do_update = $_REQUEST["action"] == "do_update"); $csrf_token = $_REQUEST["csrf_token"]; $refetch_checked = isset($_REQUEST["force_refetch"]) ? "checked" : ""; $rehash_checked = isset($_REQUEST["force_rehash"]) ? "checked" : ""; ?> <html> <head> <link rel="stylesheet" type="text/css" href="css/utility.css"> <title>Feed Debugger</title> </head> <body class="small_margins"> <h1>Feed Debugger: <?php echo "{$feed_id}: " . getFeedTitle($feed_id); ?> </h1> <form method="GET" action=""> <input type="hidden" name="op" value="feeds"> <input type="hidden" name="method" value="update_debugger"> <input type="hidden" name="xdebug" value="1"> <input type="hidden" name="csrf_token" value="<?php echo $csrf_token; ?> "> <input type="hidden" name="action" value="do_update"> <input type="hidden" name="feed_id" value="<?php echo $feed_id; ?> "> <input type="checkbox" name="force_refetch" value="1" <?php echo $refetch_checked; ?> > Force refetch<br/> <input type="checkbox" name="force_rehash" value="1" <?php echo $rehash_checked; ?> > Force rehash<br/> <p/><button type="submit">Continue</button> </form> <hr> <pre><?php if ($do_update) { include "rssfuncs.php"; update_rss_feed($feed_id, true, true); } ?> </pre> </body> </html> <?php }
static function updaterandomfeed_real($dbh) { // Test if the feed need a update (update interval exceded). if (DB_TYPE == "pgsql") { $update_limit_qpart = "AND ((\n ttrss_feeds.update_interval = 0\n AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)\n ) OR (\n ttrss_feeds.update_interval > 0\n AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)\n ) OR ttrss_feeds.last_updated IS NULL\n OR last_updated = '1970-01-01 00:00:00')"; } else { $update_limit_qpart = "AND ((\n ttrss_feeds.update_interval = 0\n AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)\n ) OR (\n ttrss_feeds.update_interval > 0\n AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)\n ) OR ttrss_feeds.last_updated IS NULL\n OR last_updated = '1970-01-01 00:00:00')"; } // Test if feed is currently being updated by another process. if (DB_TYPE == "pgsql") { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; } else { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; } $random_qpart = sql_random_function(); // we could be invoked from public.php with no active session if ($_SESSION["uid"]) { $owner_check_qpart = "AND ttrss_feeds.owner_uid = '" . $_SESSION["uid"] . "'"; } else { $owner_check_qpart = ""; } // We search for feed needing update. $result = $dbh->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id\n FROM\n ttrss_feeds, ttrss_users, ttrss_user_prefs\n WHERE\n ttrss_feeds.owner_uid = ttrss_users.id\n AND ttrss_users.id = ttrss_user_prefs.owner_uid\n AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'\n {$owner_check_qpart}\n {$update_limit_qpart}\n {$updstart_thresh_qpart}\n ORDER BY {$random_qpart} LIMIT 30"); $feed_id = -1; require_once "rssfuncs.php"; $num_updated = 0; $tstart = time(); while ($line = $dbh->fetch_assoc($result)) { $feed_id = $line["id"]; if (time() - $tstart < ini_get("max_execution_time") * 0.7) { update_rss_feed($feed_id, true); ++$num_updated; } else { break; } } // Purge orphans and cleanup tags purge_orphans(); cleanup_tags(14, 50000); if ($num_updated > 0) { print json_encode(array("message" => "UPDATE_COUNTERS", "num_updated" => $num_updated)); } else { print json_encode(array("message" => "NOTHING_TO_UPDATE")); } }
} if (isset($options["list-plugins"])) { $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL, false); $enabled = array_map("trim", explode(",", PLUGINS)); echo "List of all available plugins:\n"; foreach ($tmppluginhost->get_plugins() as $name => $plugin) { $about = $plugin->about(); $status = $about[3] ? "system" : "user"; if (in_array($name, $enabled)) { $name .= "*"; } printf("%-50s %-10s v%.2f (by %s)\n%s\n\n", $name, $status, $about[0], $about[2], $about[1]); } echo "Plugins marked by * are currently enabled for all users.\n"; } if (isset($options["debug-feed"])) { $feed = $options["debug-feed"]; if (isset($options["force-refetch"])) { $_REQUEST["force_refetch"] = true; } if (isset($options["force-rehash"])) { $_REQUEST["force_rehash"] = true; } $_REQUEST['xdebug'] = 1; update_rss_feed($feed); } PluginHost::getInstance()->run_commands($options); if (file_exists(LOCK_DIRECTORY . "/{$lock_filename}")) { unlink(LOCK_DIRECTORY . "/{$lock_filename}"); }
/** * @return integer Status code: * 0 - OK, Feed already exists * 1 - OK, Feed added * 2 - Invalid URL * 3 - URL content is HTML, no feeds available * 4 - URL content is HTML which contains multiple feeds. * Here you should call extractfeedurls in rpc-backend * to get all possible feeds. * 5 - Couldn't download the URL content. */ function subscribe_to_feed($link, $url, $cat_id = 0, $auth_login = '', $auth_pass = '', $need_auth = false) { require_once "include/rssfuncs.php"; $url = fix_url($url); if (!$url || !validate_feed_url($url)) { return 2; } $update_method = 0; $result = db_query($link, "SELECT twitter_oauth FROM ttrss_users\n\t\t\tWHERE id = " . $_SESSION['uid']); $has_oauth = db_fetch_result($result, 0, 'twitter_oauth'); if (!$need_auth || !$has_oauth || strpos($url, '://api.twitter.com') === false) { if (!fetch_file_contents($url, false, $auth_login, $auth_pass)) { return 5; } if (url_is_html($url, $auth_login, $auth_pass)) { $feedUrls = get_feeds_from_html($url, $auth_login, $auth_pass); if (count($feedUrls) == 0) { return 3; } else { if (count($feedUrls) > 1) { return 4; } } //use feed url as new URL $url = key($feedUrls); } } else { if (!fetch_twitter_rss($link, $url, $_SESSION['uid'])) { return 5; } $update_method = 3; } if ($cat_id == "0" || !$cat_id) { $cat_qpart = "NULL"; } else { $cat_qpart = "'{$cat_id}'"; } $result = db_query($link, "SELECT id FROM ttrss_feeds\n\t\t\tWHERE feed_url = '{$url}' AND owner_uid = " . $_SESSION["uid"]); if (db_num_rows($result) == 0) { $result = db_query($link, "INSERT INTO ttrss_feeds\n\t\t\t\t\t(owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method)\n\t\t\t\tVALUES ('" . $_SESSION["uid"] . "', '{$url}',\n\t\t\t\t'[Unknown]', {$cat_qpart}, '{$auth_login}', '{$auth_pass}', '{$update_method}')"); $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE feed_url = '{$url}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); $feed_id = db_fetch_result($result, 0, "id"); if ($feed_id) { update_rss_feed($link, $feed_id, true); } return 1; } else { return 0; } }
/** * Update a feed batch. * Used by daemons to update n feeds by run. * Only update feed needing a update, and not being processed * by another process. * * @param mixed $link Database link * @param integer $limit Maximum number of feeds in update batch. Default to DAEMON_FEED_LIMIT. * @param boolean $from_http Set to true if you call this function from http to disable cli specific code. * @param boolean $debug Set to false to disable debug output. Default to true. * @return void */ function update_daemon_common($limit = DAEMON_FEED_LIMIT, $from_http = false, $debug = true) { // Process all other feeds using last_updated and interval parameters $schema_version = get_schema_version(); if ($schema_version != SCHEMA_VERSION) { die("Schema version is wrong, please upgrade the database.\n"); } define('PREFS_NO_CACHE', true); // Test if the user has loggued in recently. If not, it does not update its feeds. if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) { if (DB_TYPE == "pgsql") { $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '" . DAEMON_UPDATE_LOGIN_LIMIT . " days'"; } else { $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL " . DAEMON_UPDATE_LOGIN_LIMIT . " DAY)"; } } else { $login_thresh_qpart = ""; } // Test if the feed need a update (update interval exceded). if (DB_TYPE == "pgsql") { $update_limit_qpart = "AND ((\n\t\t\t\t\tttrss_feeds.update_interval = 0\n\t\t\t\t\tAND ttrss_user_prefs.value != '-1'\n\t\t\t\t\tAND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)\n\t\t\t\t) OR (\n\t\t\t\t\tttrss_feeds.update_interval > 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)\n\t\t\t\t) OR ttrss_feeds.last_updated IS NULL\n\t\t\t\tOR last_updated = '1970-01-01 00:00:00')"; } else { $update_limit_qpart = "AND ((\n\t\t\t\t\tttrss_feeds.update_interval = 0\n\t\t\t\t\tAND ttrss_user_prefs.value != '-1'\n\t\t\t\t\tAND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)\n\t\t\t\t) OR (\n\t\t\t\t\tttrss_feeds.update_interval > 0\n\t\t\t\t\tAND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)\n\t\t\t\t) OR ttrss_feeds.last_updated IS NULL\n\t\t\t\tOR last_updated = '1970-01-01 00:00:00')"; } // Test if feed is currently being updated by another process. if (DB_TYPE == "pgsql") { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '10 minutes')"; } else { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 10 MINUTE))"; } // Test if there is a limit to number of updated feeds $query_limit = ""; if ($limit) { $query_limit = sprintf("LIMIT %d", $limit); } $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated\n\t\t\tFROM\n\t\t\t\tttrss_feeds, ttrss_users, ttrss_user_prefs\n\t\t\tWHERE\n\t\t\t\tttrss_feeds.owner_uid = ttrss_users.id\n\t\t\t\tAND ttrss_users.id = ttrss_user_prefs.owner_uid\n\t\t\t\tAND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'\n\t\t\t\t{$login_thresh_qpart} {$update_limit_qpart}\n\t\t\t\t{$updstart_thresh_qpart}\n\t\t\t\tORDER BY last_updated {$query_limit}"; // We search for feed needing update. $result = db_query($query); if ($debug) { _debug(sprintf("Scheduled %d feeds to update...", db_num_rows($result))); } // Here is a little cache magic in order to minimize risk of double feed updates. $feeds_to_update = array(); while ($line = db_fetch_assoc($result)) { array_push($feeds_to_update, db_escape_string($line['feed_url'])); } // We update the feed last update started date before anything else. // There is no lag due to feed contents downloads // It prevent an other process to update the same feed. if (count($feeds_to_update) > 0) { $feeds_quoted = array(); foreach ($feeds_to_update as $feed) { array_push($feeds_quoted, "'" . db_escape_string($feed) . "'"); } db_query(sprintf("UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\t\tWHERE feed_url IN (%s)", implode(',', $feeds_quoted))); } $nf = 0; // For each feed, we call the feed update function. foreach ($feeds_to_update as $feed) { if ($debug) { _debug("Base feed: {$feed}"); } //update_rss_feed($line["id"], true); // since we have the data cached, we can deal with other feeds with the same url $tmp_result = db_query("SELECT DISTINCT ttrss_feeds.id,last_updated,ttrss_feeds.owner_uid\n\t\t\tFROM ttrss_feeds, ttrss_users, ttrss_user_prefs WHERE\n\t\t\t\tttrss_user_prefs.owner_uid = ttrss_feeds.owner_uid AND\n\t\t\t\tttrss_users.id = ttrss_user_prefs.owner_uid AND\n\t\t\t\tttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' AND\n\t\t\t\tfeed_url = '" . db_escape_string($feed) . "' AND\n\t\t\t\t(ttrss_feeds.update_interval > 0 OR\n\t\t\t\t\tttrss_user_prefs.value != '-1')\n\t\t\t\t{$login_thresh_qpart}\n\t\t\tORDER BY ttrss_feeds.id {$query_limit}"); if (db_num_rows($tmp_result) > 0) { while ($tline = db_fetch_assoc($tmp_result)) { if ($debug) { _debug(" => " . $tline["last_updated"] . ", " . $tline["id"] . " " . $tline["owner_uid"]); } update_rss_feed($tline["id"], true); ++$nf; } } } require_once "digest.php"; // Send feed digests by email if needed. send_headlines_digests($debug); return $nf; }
/** * @return array (code => Status code, message => error message if available) * * 0 - OK, Feed already exists * 1 - OK, Feed added * 2 - Invalid URL * 3 - URL content is HTML, no feeds available * 4 - URL content is HTML which contains multiple feeds. * Here you should call extractfeedurls in rpc-backend * to get all possible feeds. * 5 - Couldn't download the URL content. * 6 - Content is an invalid XML. */ function subscribe_to_feed($url, $cat_id = 0, $auth_login = '', $auth_pass = '') { global $fetch_last_error; require_once "include/rssfuncs.php"; $url = fix_url($url); if (!$url || !validate_feed_url($url)) { return array("code" => 2); } $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass); if (!$contents) { return array("code" => 5, "message" => $fetch_last_error); } if (is_html($contents)) { $feedUrls = get_feeds_from_html($url, $contents); if (count($feedUrls) == 0) { return array("code" => 3); } else { if (count($feedUrls) > 1) { return array("code" => 4, "feeds" => $feedUrls); } } //use feed url as new URL $url = key($feedUrls); } /* libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc->loadXML($contents); $error = libxml_get_last_error(); libxml_clear_errors(); if ($error) { $error_message = format_libxml_error($error); return array("code" => 6, "message" => $error_message); } */ if ($cat_id == "0" || !$cat_id) { $cat_qpart = "NULL"; } else { $cat_qpart = "'{$cat_id}'"; } $result = db_query("SELECT id FROM ttrss_feeds\n\t\t\tWHERE feed_url = '{$url}' AND owner_uid = " . $_SESSION["uid"]); if (strlen(FEED_CRYPT_KEY) > 0) { require_once "crypt.php"; $auth_pass = substr(encrypt_string($auth_pass), 0, 250); $auth_pass_encrypted = 'true'; } else { $auth_pass_encrypted = 'false'; } $auth_pass = db_escape_string($auth_pass); if (db_num_rows($result) == 0) { $result = db_query("INSERT INTO ttrss_feeds\n\t\t\t\t\t(owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method,auth_pass_encrypted)\n\t\t\t\tVALUES ('" . $_SESSION["uid"] . "', '{$url}',\n\t\t\t\t'[Unknown]', {$cat_qpart}, '{$auth_login}', '{$auth_pass}', 0, {$auth_pass_encrypted})"); $result = db_query("SELECT id FROM ttrss_feeds WHERE feed_url = '{$url}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); $feed_id = db_fetch_result($result, 0, "id"); if ($feed_id) { update_rss_feed($feed_id, true); } return array("code" => 1); } else { return array("code" => 0); } }
static function api_get_headlines($feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, $include_attachments, $since_id, $search = "", $include_nested = false, $sanitize_content = true, $force_update = false, $excerpt_length = 100, $check_first_id = false) { if ($force_update && $feed_id > 0 && is_numeric($feed_id)) { // Update the feed if required with some basic flood control $result = db_query("SELECT cache_images," . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated\n\t\t\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed_id}'"); if (db_num_rows($result) != 0) { $last_updated = strtotime(db_fetch_result($result, 0, "last_updated")); $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); if (!$cache_images && time() - $last_updated > 120) { include "rssfuncs.php"; update_rss_feed($feed_id, true, true); } else { db_query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'\n\t\t\t\t\t\t\tWHERE id = '{$feed_id}'"); } } } /*$qfh_ret = queryFeedHeadlines($feed_id, $limit, $view_mode, $is_cat, $search, false, $order, $offset, 0, false, $since_id, $include_nested);*/ //function queryFeedHeadlines($feed, $limit, // $view_mode, $cat_view, $search, $search_mode, // $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, // $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) { $params = array("feed" => $feed_id, "limit" => $limit, "view_mode" => $view_mode, "cat_view" => $is_cat, "search" => $search, "override_order" => $order, "offset" => $offset, "since_id" => $since_id, "include_children" => $include_nested, "check_first_id" => $check_first_id, "api_request" => true); $qfh_ret = queryFeedHeadlines($params); $result = $qfh_ret[0]; $feed_title = $qfh_ret[1]; $first_id = $qfh_ret[6]; $headlines = array(); $headlines_header = array('id' => $feed_id, 'first_id' => $first_id, 'is_cat' => $is_cat); if (!is_numeric($result)) { while ($line = db_fetch_assoc($result)) { $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { $line = $p->hook_query_headlines($line, $excerpt_length, true); } $is_updated = $line["last_read"] == "" && ($line["unread"] != "t" && $line["unread"] != "1"); $tags = explode(",", $line["tag_cache"]); $label_cache = $line["label_cache"]; $labels = false; if ($label_cache) { $label_cache = json_decode($label_cache, true); if ($label_cache) { if ($label_cache["no-labels"] == 1) { $labels = array(); } else { $labels = $label_cache; } } } if (!is_array($labels)) { $labels = get_article_labels($line["id"]); } //if (!$tags) $tags = get_article_tags($line["id"]); //if (!$labels) $labels = get_article_labels($line["id"]); $headline_row = array("id" => (int) $line["id"], "unread" => sql_bool_to_bool($line["unread"]), "marked" => sql_bool_to_bool($line["marked"]), "published" => sql_bool_to_bool($line["published"]), "updated" => (int) strtotime($line["updated"]), "is_updated" => $is_updated, "title" => $line["title"], "link" => $line["link"], "feed_id" => $line["feed_id"], "tags" => $tags); if ($include_attachments) { $headline_row['attachments'] = get_article_enclosures($line['id']); } if ($show_excerpt) { $headline_row["excerpt"] = $line["content_preview"]; } if ($show_content) { if ($sanitize_content) { $headline_row["content"] = sanitize($line["content"], sql_bool_to_bool($line['hide_images']), false, $line["site_url"], false, $line["id"]); } else { $headline_row["content"] = $line["content"]; } } // unify label output to ease parsing if ($labels["no-labels"] == 1) { $labels = array(); } $headline_row["labels"] = $labels; $headline_row["feed_title"] = $line["feed_title"] ? $line["feed_title"] : $feed_title; $headline_row["comments_count"] = (int) $line["num_comments"]; $headline_row["comments_link"] = $line["comments"]; $headline_row["always_display_attachments"] = sql_bool_to_bool($line["always_display_enclosures"]); $headline_row["author"] = $line["author"]; $headline_row["score"] = (int) $line["score"]; $headline_row["note"] = $line["note"]; $headline_row["lang"] = $line["lang"]; foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) { $headline_row = $p->hook_render_article_api(array("headline" => $headline_row)); } array_push($headlines, $headline_row); } } else { if (is_numeric($result) && $result == -1) { $headlines_header['first_id_changed'] = true; } } return array($headlines, $headlines_header); }
function updateFeed() { require_once "include/rssfuncs.php"; $feed_id = (int) $this->dbh->escape_string($_REQUEST["feed_id"]); update_rss_feed($feed_id, true); $this->wrap(self::STATUS_OK, array("status" => "OK")); }