$feedimport_result = $feedimport_result[0]; $feedimport_result['cnt_object'] = @unserialize($feedimport_result['cnt_object']); } if (isset($feedimport_result['cnt_object']['structure_level_id'])) { // retrieve Feed now // Load SimplePie require_once PHPWCMS_ROOT . '/include/inc_ext/simplepie.inc.php'; $rss_obj = new SimplePie(); // Feed URL $rss_obj->set_feed_url($feedimport_result['cnt_text']); // Output Encoding Charset $rss_obj->set_output_encoding(PHPWCMS_CHARSET); // Disable Feed cache $rss_obj->enable_cache(false); // Remove surrounding DIV $rss_obj->remove_div(true); // Init Feed $rss_obj->init(); if ($rss_obj->data) { $feedimport_result['status'] = array('Feed Importer Status - ' . date('Y-m-d, H:i:s') . LF . '===========================================', $feedimport_result['cnt_name'] . LF . $feedimport_result['cnt_text'] . LF); if (!empty($feedimport_result['cnt_object']['image_url_replace'])) { $feedimport_result['cnt_object']['image_url_replace'] = explode('>', $feedimport_result['cnt_object']['image_url_replace']); $feedimport_result['cnt_object']['image_url_replace'][0] = trim(trim($feedimport_result['cnt_object']['image_url_replace'][0]), '"'); if (isset($feedimport_result['cnt_object']['image_url_replace'][1])) { $feedimport_result['cnt_object']['image_url_replace'][1] = trim(trim($feedimport_result['cnt_object']['image_url_replace'][1]), '"'); } } else { $feedimport_result['cnt_object']['image_url_replace'] = array(0 => '', 1 => ''); } if (empty($feedimport_result['cnt_object']['image_folder_id'])) { $feedimport_result['cnt_object']['image_folder_id'] = 0;
function fof_parse($url) { $p =& FoF_Prefs::instance(); $admin_prefs = $p->admin_prefs; $pie = new SimplePie(); $pie->set_cache_duration($admin_prefs["manualtimeout"] * 60); $pie->set_favicon_handler("favicon.php"); $pie->set_feed_url($url); $pie->set_javascript(false); $pie->remove_div(false); $pie->init(); return $pie; }
/** * * @param object $bookmark * @param object $owner */ protected function do_rss($bookmark, $owner) { // no bookmark, no fun if (empty($bookmark) || !is_object($bookmark)) { return false; } // no owner means no email, so no reason to parse if (empty($owner) || !is_object($owner)) { return false; } // instead of the way too simple fetch_feed, we'll use SimplePie itself if (!class_exists('SimplePie')) { require_once ABSPATH . WPINC . '/class-simplepie.php'; } $url = htmlspecialchars_decode($bookmark->link_rss); $last_updated = strtotime($bookmark->link_updated); static::debug('Fetching: ' . $url, 6); $feed = new SimplePie(); $feed->set_feed_url($url); $feed->set_cache_duration(static::revisit_time - 10); $feed->set_cache_location($this->cachedir); $feed->force_feed(true); // optimization $feed->enable_order_by_date(true); $feed->remove_div(true); $feed->strip_comments(true); $feed->strip_htmltags(false); $feed->strip_attributes(true); $feed->set_image_handler(false); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { $err = new WP_Error('simplepie-error', $feed->error()); static::debug('Error: ' . $err->get_error_message(), 4); $this->failed($owner->user_email, $url, $err->get_error_message()); return $err; } // set max items to 12 // especially useful with first runs $maxitems = $feed->get_item_quantity(12); $feed_items = $feed->get_items(0, $maxitems); $feed_title = $feed->get_title(); // set the link name from the RSS title if (!empty($feed_title) && $bookmark->link_name != $feed_title) { global $wpdb; $wpdb->update($wpdb->prefix . 'links', array('link_name' => $feed_title), array('link_id' => $bookmark->link_id)); } // if there's a feed author, get it, we may need it if there's no entry // author $feed_author = $feed->get_author(); $last_updated_ = 0; if ($maxitems > 0) { foreach ($feed_items as $item) { // U stands for Unix Time $date = $item->get_date('U'); if ($date > $last_updated) { $fromname = $feed_title; $author = $item->get_author(); if ($author) { $fromname = $fromname . ': ' . $author->get_name(); } elseif ($feed_author) { $fromname = $fromname . ': ' . $feed_author->get_name(); } // this is to set the sender mail from our own domain $frommail = get_user_meta($owner->ID, 'blogroll2email_email', true); if (!$frommail) { $sitedomain = parse_url(get_bloginfo('url'), PHP_URL_HOST); $frommail = static::schedule . '@' . $sitedomain; } $from = $fromname . '<' . $frommail . '>'; $content = $item->get_content(); $matches = array(); preg_match_all('/farm[0-9]\\.staticflickr\\.com\\/[0-9]+\\/([0-9]+_[0-9a-zA-Z]+_m\\.jpg)/s', $content, $matches); if (!empty($matches[0])) { foreach ($matches[0] as $to_replace) { $clean = str_replace('_m.jpg', '_c.jpg', $to_replace); $content = str_replace($to_replace, $clean, $content); } $content = preg_replace("/(width|height)=\"(.*?)\" ?/is", '', $content); } $content = apply_filters('blogroll2email_message', $content); if ($this->send($owner->user_email, $item->get_link(), $item->get_title(), $from, $url, $item->get_content(), $date)) { if ($date > $last_updated_) { $last_updated_ = $date; } } } } } // poke the link's last update field, so we know what was the last sent // entry's date $this->update_link_date($bookmark, $last_updated_); }
/** Let SimplePie process a feed URL. */ function fof_parse($url) { if (empty($url)) { fof_log("got empty url"); return false; } $p =& FoF_Prefs::instance(); $admin_prefs = $p->admin_prefs; $pie = new SimplePie(); $pie->set_cache_location(dirname(__FILE__) . '/cache'); $pie->set_cache_duration($admin_prefs["manualtimeout"] * 60); $pie->remove_div(true); $pie->set_feed_url($url); $pie->init(); /* A feed might contain data before the <?xml declaration, which will cause * SimplePie to fail to parse it. * In case of an error in parsing, retry after trying to fetch and scrub the * feed data. * XXX: What error does this case report? Could probably check for that, * and only try the scrubbing when it makes sense. */ if ($pie->error()) { fof_log('failed to parse feed url ' . $url . ': ' . $pie->error()); if (($data = file_get_contents($url)) === false) { fof_log("failed to fetch '{$url}'"); return $pie; } $data = preg_replace('~.*<\\?xml~sim', '<?xml', $data); #file_put_contents ('/tmp/text.xml',$data); unset($pie); $pie = new SimplePie(); $pie->set_cache_location(dirname(__FILE__) . '/cache'); $pie->set_cache_duration($admin_prefs["manualtimeout"] * 60); $pie->remove_div(true); $pie->set_raw_data($data); $pie->init(); } return $pie; }