function update_rss_feed($feed, $ignore_daemon = false, $no_cache = false,
$override_url = false) {
- require_once "lib/simplepie/simplepie.inc";
-
$debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
_debug("start", $debug_enabled);
$date_feed_processed = date('Y-m-d H:i');
- $cache_filename = CACHE_DIR . "/simplepie/" . sha1($fetch_url) . ".feed";
+ $cache_filename = CACHE_DIR . "/simplepie/" . sha1($fetch_url) . ".feed2";
// Ignore cache if new feed or manual update.
$cache_age = ($no_cache || is_null($last_updated) || strpos($last_updated, '1970-01-01') === 0) ? 30 : get_feed_update_interval($feed) * 60;
_debug("using local cache.", $debug_enabled);
if ($cache_timestamp > $last_article_timestamp) {
- @$rss_data = file_get_contents($cache_filename);
+ @$feed_data = file_get_contents($cache_filename);
- if ($rss_data) {
- $rss_hash = sha1($rss_data);
- @$rss = unserialize($rss_data);
+ if ($feed_data) {
+ $rss_hash = sha1($feed_data);
}
} else if (!$force_refetch) {
_debug("local cache valid and older than last_updated, nothing to do.", $debug_enabled);
}
if (!$rss) {
- $rss = new SimplePie();
- $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->set_raw_data($feed_data);
- $rss->enable_cache(false);
-
- @$rss->init();
+ $rss = new FeedParser($feed_data);
+ $rss->init();
}
// print_r($rss);
// cache data for later
if (!$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) {
- $rss_data = serialize($rss);
$new_rss_hash = sha1($rss_data);
- if ($new_rss_hash != $rss_hash) {
+ if ($new_rss_hash != $rss_hash && count($rss->get_items()) > 0 ) {
_debug("saving $cache_filename", $debug_enabled);
- @file_put_contents($cache_filename, serialize($rss));
+ @file_put_contents($cache_filename, $feed_data);
}
}
$site_url = db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245));
+ _debug("site_url: $site_url", $debug_enabled);
+ _debug("feed_title: " . $rss->get_title(), $debug_enabled);
+
if ($favicon_needs_check || $force_refetch) {
/* terrible hack: if we crash on floicon shit here, we won't check
if (!$entry_guid) $entry_guid = $item->get_link();
if (!$entry_guid) $entry_guid = make_guid_from_title($item->get_title());
+ _debug("f_guid $entry_guid", $debug_enabled);
+
if (!$entry_guid) continue;
$entry_guid = "$owner_uid,$entry_guid";
$entry_timestamp = "";
- $entry_timestamp = strtotime($item->get_date());
+ $entry_timestamp = $item->get_date();
+
+ _debug("orig date: " . $item->get_date(), $debug_enabled);
if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) {
$entry_timestamp = time();
_debug("date $entry_timestamp [$entry_timestamp_fmt]", $debug_enabled);
- $entry_title = html_entity_decode($item->get_title(), ENT_COMPAT, 'UTF-8');
- $entry_title = decode_numeric_entities($entry_title);
+// $entry_title = html_entity_decode($item->get_title(), ENT_COMPAT, 'UTF-8');
+// $entry_title = decode_numeric_entities($entry_title);
+ $entry_title = $item->get_title();
$entry_link = rewrite_relative_url($site_url, $item->get_link());
print "\n";
}
- $entry_comments = $item->data["comments"];
-
- if ($item->get_author()) {
- $entry_author_item = $item->get_author();
- $entry_author = $entry_author_item->get_name();
- if (!$entry_author) $entry_author = $entry_author_item->get_email();
- }
+ $entry_comments = $item->get_comments_url();
+ $entry_author = $item->get_author();
$entry_guid = db_escape_string(mb_substr($entry_guid, 0, 245));
$entry_comments = db_escape_string(mb_substr(trim($entry_comments), 0, 245));
$entry_author = db_escape_string(mb_substr(trim($entry_author), 0, 245));
- $num_comments = $item->get_item_tags('http://purl.org/rss/1.0/modules/slash/', 'comments');
+ $num_comments = $item->get_comments_count();
if (is_array($num_comments) && is_array($num_comments[0])) {
$num_comments = (int) $num_comments[0]["data"];
if (is_array($additional_tags_src)) {
foreach ($additional_tags_src as $tobj) {
- array_push($additional_tags, $tobj->get_term());
+ array_push($additional_tags, $tobj);
}
}
_debug("Cleaned $rc cached tags.");
}
-
- function utf8_entity_decode($entity){
- $convmap = array(0x0, 0x10000, 0, 0xfffff);
- return mb_decode_numericentity($entity, $convmap, 'UTF-8');
- }
-
- function decode_numeric_entities($body) {
- $body = preg_replace('/&#\d{2,5};/ue', "utf8_entity_decode('$0')", $body );
- $body = preg_replace('/&#x([a-fA-F0-7]{2,8});/ue', "utf8_entity_decode('&#'.hexdec('$1').';')", $body );
- return $body;
- }
?>