sleep(1); // prevent flood (FIXME make this an option?)
}
+ require_once "digest.php";
+
// Send feed digests by email if needed.
send_headlines_digests($link, $debug);
$rss->set_timeout($no_cache ? 15 : 60);
$rss->set_feed_url($fetch_url);
$rss->set_output_encoding('UTF-8');
- //$rss->force_feed(true);
+ $rss->force_feed(true);
if ($debug_enabled) {
_debug("feed update interval (sec): " .
if (!$rss->error()) {
+ // We use local pluginhost here because we need to load different per-user feed plugins
+ $user_plugins = get_pref($link, "_ENABLED_PLUGINS", $owner_uid);
+
+ $pluginhost = new PluginHost($link);
+
+ $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
+ $pluginhost->load($user_plugins, $pluginhost::KIND_USER, $owner_uid);
+ $pluginhost->load_data();
+
+ $pluginhost->run_hooks($pluginhost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss);
+
if ($debug_enabled) {
_debug("update_rss_feed: processing feed data...");
}
$owner_uid = db_fetch_result($result, 0, "owner_uid");
- $site_url = db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 250));
+ $site_url = db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245));
if ($debug_enabled) {
_debug("update_rss_feed: checking favicon...");
}
$icon_url = db_escape_string(mb_substr(
- rewrite_relative_url($fetch_url, $rss->get_image_url()), 0, 250));
+ rewrite_relative_url($fetch_url, $rss->get_image_url()), 0, 245));
if ($icon_url && $orig_icon_url != $icon_url) {
db_query($link, "UPDATE ttrss_feeds SET icon_url = '$icon_url' WHERE id = '$feed'");
if (!$entry_guid) $entry_guid = $item->get_link();
if (!$entry_guid) $entry_guid = make_guid_from_title($item->get_title());
- if ($cache_content) {
- $entry_guid = "ccache:$entry_guid";
- }
-
- if ($auth_login || $auth_pass) {
- $entry_guid = "auth,$owner_uid:$entry_guid";
- }
-
if ($debug_enabled) {
_debug("update_rss_feed: guid $entry_guid");
}
if (!$entry_guid) continue;
+ $entry_guid = "$owner_uid,$entry_guid";
+
$entry_timestamp = "";
$entry_timestamp = strtotime($item->get_date());
$entry_author = db_escape_string($entry_author);
}
- $entry_guid = db_escape_string(mb_substr($entry_guid, 0, 250));
-
- $result = db_query($link, "SELECT id FROM ttrss_entries
- WHERE guid = '$entry_guid'");
+ $entry_guid = db_escape_string(mb_substr($entry_guid, 0, 245));
- $entry_comments = db_escape_string(mb_substr($entry_comments, 0, 250));
- $entry_author = db_escape_string(mb_substr($entry_author, 0, 250));
+ $entry_comments = db_escape_string(mb_substr($entry_comments, 0, 245));
+ $entry_author = db_escape_string(mb_substr($entry_author, 0, 245));
$num_comments = $item->get_item_tags('http://purl.org/rss/1.0/modules/slash/', 'comments');
_debug("update_rss_feed: looking for tags [2]...");
}
- /* taaaags */
- // <a href="..." rel="tag">Xorg</a>, //
-
- $entry_tags = null;
-
- preg_match_all("/<a.*?rel=['\"]tag['\"].*?\>([^<]+)<\/a>/i",
- $entry_content, $entry_tags);
-
- $entry_tags = $entry_tags[1];
-
- $entry_tags = array_merge($entry_tags, $additional_tags);
- $entry_tags = array_unique($entry_tags);
+ $entry_tags = array_unique($additional_tags);
for ($i = 0; $i < count($entry_tags); $i++)
$entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
}
// TODO: less memory-hungry implementation
- global $pluginhost;
if ($debug_enabled) {
_debug("update_rss_feed: applying plugin filters..");
}
- $article = array("owner_uid" => $owner_uid,
+ $article = array("owner_uid" => $owner_uid, // read only
+ "guid" => $entry_guid,
"title" => $entry_title,
"content" => $entry_content,
"link" => $entry_link,
}
$entry_tags = $article["tags"];
+ $entry_guid = db_escape_string($article["guid"]);
$entry_content = db_escape_string($article["content"], false);
$entry_title = db_escape_string($article["title"]);
$entry_author = db_escape_string($article["author"]);
$entry_link = db_escape_string($article["link"]);
- $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
+ $content_hash = "SHA1:" . sha1($entry_content);
db_query($link, "BEGIN");
+ $result = db_query($link, "SELECT id FROM ttrss_entries
+ WHERE guid = '$entry_guid'");
+
if (db_num_rows($result) == 0) {
if ($debug_enabled) {
- _debug("update_rss_feed: base guid not found");
+ _debug("update_rss_feed: base guid [$entry_guid] not found");
}
- if ($cache_content) {
+ if (defined('_FEEDS_CONTENT_CACHE') && _FEEDS_CONTENT_CACHE && $cache_content) {
if ($debug_enabled) {
_debug("update_rss_feed: caching content (initial)...");
}
if (db_num_rows($result) == 1) {
if ($debug_enabled) {
- _debug("update_rss_feed: base guid found, checking for user record");
+ _debug("update_rss_feed: base guid [$entry_guid] found, checking for user record");
}
// this will be used below in update handler
$cached_content_needs_update = true;
}
- if ($cache_content) {
+ if (defined('_FEEDS_CONTENT_CACHE') && _FEEDS_CONTENT_CACHE && $cache_content) {
if ($debug_enabled) {
_debug("update_rss_feed: caching content because original checksum changed...");
}
} else {
- $error_msg = mb_substr($rss->error(), 0, 250);
+ $error_msg = db_escape_string(mb_substr($rss->error(), 0, 245));
if ($debug_enabled) {
_debug("update_rss_feed: error fetching feed: $error_msg");
}
- $error_msg = db_escape_string($error_msg);
-
db_query($link,
"UPDATE ttrss_feeds SET last_error = '$error_msg',
last_updated = NOW() WHERE id = '$feed'");
return "";
}
+
+ function make_guid_from_title($title) {
+ return preg_replace("/[ \"\',.:;]/", "-",
+ mb_strtolower(strip_tags($title), 'utf-8'));
+ }
+
+
?>