$result = db_query($link, "SELECT id,update_interval,auth_login,
feed_url,auth_pass,cache_images,last_updated,
- mark_unread_on_update, owner_uid, update_on_checksum_change,
+ mark_unread_on_update, owner_uid,
pubsub_state
FROM ttrss_feeds WHERE id = '$feed'");
$owner_uid = db_fetch_result($result, 0, "owner_uid");
$mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result,
0, "mark_unread_on_update"));
- $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result,
- 0, "update_on_checksum_change"));
$pubsub_state = db_fetch_result($result, 0, "pubsub_state");
db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW()
$feed = db_escape_string($feed);
- if ($auth_login && $auth_pass ){
+ /* if ($auth_login && $auth_pass ){
$url_parts = array();
preg_match("/(^[^:]*):\/\/(.*)/", $fetch_url, $url_parts);
if ($url_parts[1] && $url_parts[2]) {
$fetch_url = $url_parts[1] . "://$auth_login:$auth_pass@" . $url_parts[2];
}
-
- }
+ } */
if ($override_url)
$fetch_url = $override_url;
mkdir($simplepie_cache_dir);
}
+ $feed_data = fetch_file_contents($fetch_url, false,
+ $auth_login, $auth_pass, false, $no_cache ? 15 : 45);
+
+ if (!$feed_data) {
+ global $fetch_last_error;
+
+ if ($debug_enabled) {
+ _debug("update_rss_feed: unable to fetch: $fetch_last_error");
+ }
+
+ $error_escaped = db_escape_string($fetch_last_error);
+
+ db_query($link,
+ "UPDATE ttrss_feeds SET last_error = '$error_escaped',
+ last_updated = NOW() WHERE id = '$feed'");
+
+ return;
+ }
+
+ $pluginhost = new PluginHost($link);
+ $pluginhost->set_debug($debug_enabled);
+ $user_plugins = get_pref($link, "_ENABLED_PLUGINS", $owner_uid);
+
+ $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL);
+ $pluginhost->load($user_plugins, $pluginhost::KIND_USER, $owner_uid);
+ $pluginhost->load_data();
+
+ foreach ($pluginhost->get_hooks($pluginhost::HOOK_FEED_FETCHED) as $plugin) {
+ $feed_data = $plugin->hook_feed_fetched($feed_data);
+ }
+
+ if ($debug_enabled) {
+ _debug("update_rss_feed: fetch done, parsing...");
+ }
+
$rss = new SimplePie();
- $rss->set_useragent(SELF_USER_AGENT);
- $rss->set_timeout($no_cache ? 15 : 60);
- $rss->set_feed_url($fetch_url);
+ $rss->set_sanitize_class("SanitizeDummy");
+ // simplepie ignores the above and creates default sanitizer anyway,
+ // so let's override it...
+ $rss->sanitize = new SanitizeDummy();
$rss->set_output_encoding('UTF-8');
- $rss->force_feed(true);
+ $rss->set_raw_data($feed_data);
if ($debug_enabled) {
_debug("feed update interval (sec): " .
$rss->set_cache_duration($cache_age);
}
- $rss->init();
+ @$rss->init();
// print_r($rss);
- if ($debug_enabled) {
- _debug("update_rss_feed: fetch done, parsing...");
- }
-
$feed = db_escape_string($feed);
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) {
}
foreach ($items as $item) {
- if ($_REQUEST['xdebug'] == 2) {
+ if ($_REQUEST['xdebug'] == 3) {
print_r($item);
}
$entry_title = $item->get_title();
- $entry_link = rewrite_relative_url($site_url, htmlspecialchars_decode($item->get_link()));
+ $entry_link = rewrite_relative_url($site_url, $item->get_link());
if ($debug_enabled) {
_debug("update_rss_feed: title $entry_title");
}
if ($debug_enabled) {
- _debug("update_rss_feed: done collecting data [TITLE:$entry_title]");
+ _debug("update_rss_feed: done collecting data.");
}
// TODO: less memory-hungry implementation
_debug("update_rss_feed: applying plugin filters..");
}
+ // FIXME not sure if owner_uid is a good idea here, we may have a base entry without user entry (?)
+ $result = db_query($link, "SELECT plugin_data,title,content,link,tag_cache,author FROM ttrss_entries, ttrss_user_entries
+ WHERE ref_id = id AND guid = '".db_escape_string($entry_guid)."' AND owner_uid = $owner_uid");
+
+ if (db_num_rows($result) != 0) {
+ $entry_plugin_data = db_fetch_result($result, 0, "plugin_data");
+ $stored_article = array("title" => db_fetch_result($result, 0, "title"),
+ "content" => db_fetch_result($result, 0, "content"),
+ "link" => db_fetch_result($result, 0, "link"),
+ "tags" => explode(",", db_fetch_result($result, 0, "tag_cache")),
+ "author" => db_fetch_result($result, 0, "author"));
+ } else {
+ $entry_plugin_data = "";
+ $stored_article = array();
+ }
+
$article = array("owner_uid" => $owner_uid, // read only
- "guid" => $entry_guid,
+ "guid" => $entry_guid, // read only
"title" => $entry_title,
"content" => $entry_content,
"link" => $entry_link,
"tags" => $entry_tags,
- "author" => $entry_author);
+ "plugin_data" => $entry_plugin_data,
+ "author" => $entry_author,
+ "stored" => $stored_article);
foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_FILTER) as $plugin) {
$article = $plugin->hook_article_filter($article);
}
$entry_tags = $article["tags"];
- $entry_guid = db_escape_string($article["guid"]);
- $entry_content = db_escape_string($article["content"], false);
+ $entry_guid = db_escape_string($entry_guid);
$entry_title = db_escape_string($article["title"]);
$entry_author = db_escape_string($article["author"]);
$entry_link = db_escape_string($article["link"]);
+ $entry_plugin_data = db_escape_string($article["plugin_data"]);
+
+ if ($debug_enabled) {
+ _debug("update_rss_feed: plugin data: $entry_plugin_data");
+ }
if ($cache_images && is_writable(CACHE_DIR . '/images'))
$entry_content = cache_images($entry_content, $site_url, $debug_enabled);
+ $entry_content = db_escape_string($article["content"], false);
+
$content_hash = "SHA1:" . sha1($entry_content);
db_query($link, "BEGIN");
date_entered,
comments,
num_comments,
+ plugin_data,
author)
VALUES
('$entry_title',
NOW(),
'$entry_comments',
'$num_comments',
+ '$entry_plugin_data',
'$entry_author')");
$article_labels = array();
// now it should exist, if not - bad luck then
$result = db_query($link, "SELECT
- id,content_hash,no_orig_date,title,
+ id,content_hash,no_orig_date,title,plugin_data,
".SUBSTRING_FOR_DATE."(date_updated,1,19) as date_updated,
".SUBSTRING_FOR_DATE."(updated,1,19) as updated,
num_comments
$orig_num_comments = db_fetch_result($result, 0, "num_comments");
$orig_date_updated = strtotime(db_fetch_result($result,
0, "date_updated"));
+ $orig_plugin_data = db_fetch_result($result, 0, "plugin_data");
$ref_id = db_fetch_result($result, 0, "id");
$entry_ref_id = $ref_id;
}
}
+ $last_marked = ($marked == 'true') ? 'NOW()' : 'NULL';
+ $last_published = ($published == 'true') ? 'NOW()' : 'NULL';
+
$result = db_query($link,
"INSERT INTO ttrss_user_entries
(ref_id, owner_uid, feed_id, unread, last_read, marked,
- published, score, tag_cache, label_cache, uuid)
+ published, score, tag_cache, label_cache, uuid,
+ last_marked, last_published)
VALUES ('$ref_id', '$owner_uid', '$feed', $unread,
- $last_read_qpart, $marked, $published, '$score', '', '', '')");
+ $last_read_qpart, $marked, $published, '$score', '', '',
+ '', $last_marked, $last_published)");
if (PUBSUBHUBBUB_HUB && $published == 'true') {
$rss_link = get_self_url_prefix() .
$update_insignificant = true;
}
+ if ($entry_plugin_data != $orig_plugin_data) {
+ $post_needs_update = true;
+ $update_insignificant = true;
+ }
+
if ($content_hash != $orig_content_hash) {
$post_needs_update = true;
$update_insignificant = false;
SET title = '$entry_title', content = '$entry_content',
content_hash = '$content_hash',
updated = '$entry_timestamp_fmt',
- num_comments = '$num_comments'
+ num_comments = '$num_comments',
+ plugin_data = '$entry_plugin_data'
WHERE id = '$ref_id'");
if (!$update_insignificant) {
if ($mark_unread_on_update) {
db_query($link, "UPDATE ttrss_user_entries
SET last_read = null, unread = true WHERE ref_id = '$ref_id'");
- } else if ($update_on_checksum_change) {
- db_query($link, "UPDATE ttrss_user_entries
- SET last_read = null WHERE ref_id = '$ref_id'
- AND unread = false");
}
}
}
$node = $doc->getElementsByTagName('body')->item(0);
- return $doc->saveXML($node, LIBXML_NOEMPTYTAG);
+ return $doc->saveXML($node);
}
function expire_lock_files($debug) {
}
}
- function cache_content($link, $url, $login, $pass) {
-
- $content = fetch_file_contents($url, $login, $pass);
-
- if ($content) {
- $doc = new DOMDocument();
- @$doc->loadHTML($content);
- $xpath = new DOMXPath($doc);
-
- $node = $doc->getElementsByTagName('body')->item(0);
-
- if ($node) {
- $content = $doc->saveXML($node, LIBXML_NOEMPTYTAG);
-
- return $content;
- }
- }
-
- return "";
- }
-
function make_guid_from_title($title) {
return preg_replace("/[ \"\',.:;]/", "-",
mb_strtolower(strip_tags($title), 'utf-8'));