function tweetimport_import_twitter_feed($twitter_account) { require_once (ABSPATH . WPINC . '/class-feed.php'); $feed = new SimplePie(); $account_parts = explode ('/', $twitter_account['twitter_name'], 2); if ($twitter_account['account_type'] == 1): //Account is Favorites $feed->set_feed_url(str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_FAVORITES_URL)); elseif ($twitter_account['account_type'] == 0 && count($account_parts) == 1): //User timeline $feed->set_feed_url(str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_USER_TIMELINE_URL)); elseif ($twitter_account['account_type'] == 2 && count($account_parts) == 2): //Account is list $feed_url = str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_LIST_URL); $feed_url = str_replace('#=#LIST#=#', $account_parts[1], $feed_url); $feed->set_feed_url($feed_url); else : return '<strong>ERROR: Account information not correct. Account type wrong?</strong>'; endif; $feed->set_useragent('Tweet Import http://skinju.com/wordpress/tweetimport'); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->enable_cache(true); $feed->set_cache_duration (apply_filters('tweetimport_cache_duration', 880)); $feed->enable_order_by_date(false); $feed->init(); $feed->handle_content_type(); if ($feed->error()): return '<strong>ERROR: Feed Reading Error.</strong>'; endif; $rss_items = $feed->get_items(); $imported_count = 0; foreach ($rss_items as $item) { $item = apply_filters ('tweetimport_tweet_before_new_post', $item); //return false to stop processing an item. if (!$item) continue; $processed_description = $item->get_description(); //Get the twitter author from the beginning of the tweet text $twitter_author = trim(preg_replace("~^(\w+):(.*?)$~", "\\1", $processed_description)); if ($twitter_account['strip_name'] == 1): $processed_description = preg_replace("~^(\w+):(.*?)~i", "\\2", $processed_description); endif; if ($twitter_account['names_clickable'] == 1): $processed_description = preg_replace("~@(\w+)~", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $processed_description); $processed_description = preg_replace("~^(\w+):~", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>:", $processed_description); endif; if ($twitter_account['hashtags_clickable'] == 1): if ($twitter_account['hashtags_clickable_twitter'] == 1): $processed_description = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $processed_description); else: $processed_description = preg_replace("/#(\w+)/", "<a href=\"" . skinju_get_tag_link("\\1") . "\">#\\1</a>", $processed_description); endif; endif; $processed_description = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $processed_description); $processed_description = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $processed_description); $new_post = array('post_title' => trim (substr (preg_replace("~{$account_parts[0]}: ~i", "", $item->get_title()), 0, 25) . '...'), 'post_content' => trim ($processed_description), 'post_date' => $item->get_date('Y-m-d H:i:s'), 'post_author' => $twitter_account['author'], 'post_category' => array($twitter_account['category']), 'post_status' => 'publish'); $new_post = apply_filters('tweetimport_new_post_before_create', $new_post); // Offer the chance to manipulate new post data. return false to skip if (!$new_post) continue; $new_post_id = wp_insert_post($new_post); $imported_count++; add_post_meta ($new_post_id, 'tweetimport_twitter_author', $twitter_author, true); add_post_meta ($new_post_id, 'tweetimport_date_imported', date ('Y-m-d H:i:s'), true); add_post_meta ($new_post_id, 'tweetimport_twitter_id', $item->get_id(), true); add_post_meta ($new_post_id, 'tweetimport_twitter_id', $item->get_id(), true); add_post_meta ($new_post_id, '_tweetimport_twitter_id_hash', $item->get_id(true), true); add_post_meta ($new_post_id, 'tweetimport_twitter_post_uri', $item->get_link(0)); add_post_meta ($new_post_id, 'tweetimport_author_avatar', $item->get_link(0, 'image')); preg_match_all ('~#([A-Za-z0-9_]+)(?=\s|\Z)~', $item->get_description(), $out); if ($twitter_account['add_tag']) $out[0][] = $twitter_account['add_tag']; wp_set_post_tags($new_post_id, implode (',', $out[0])); } return $imported_count; }
function fetch_feed2($url) { require_once ABSPATH . WPINC . '/class-feed.php'; $feed = new SimplePie(); $feed->set_sanitize_class('WP_SimplePie_Sanitize_KSES'); // We must manually overwrite $feed->sanitize because SimplePie's // constructor sets it before we have a chance to set the sanitization class $feed->sanitize = new WP_SimplePie_Sanitize_KSES(); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->set_feed_url($url); $feed->force_feed(true); /** This filter is documented in wp-includes/class-feed.php */ $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url)); /** * Fires just before processing the SimplePie feed object. * * @since 3.0.0 * * @param object &$feed SimplePie feed object, passed by reference. * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged. */ do_action_ref_array('wp_feed_options', array(&$feed, $url)); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { return new WP_Error('simplepie-error', $feed->error()); } return $feed; }
public function import($forceResync) { if (get_option('goodreads_user_id')) { if (!class_exists('SimplePie')) { require_once ABSPATH . WPINC . '/class-feed.php'; } $rss_source = sprintf(self::$apiurl, get_option('goodreads_user_id')); /* Create the SimplePie object */ $feed = new SimplePie(); /* Set the URL of the feed you're retrieving */ $feed->set_feed_url($rss_source); /* Tell SimplePie to cache the feed using WordPress' cache class */ $feed->set_cache_class('WP_Feed_Cache'); /* Tell SimplePie to use the WordPress class for retrieving feed files */ $feed->set_file_class('WP_SimplePie_File'); /* Tell SimplePie how long to cache the feed data in the WordPress database */ $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', get_option('reclaim_update_interval'), $rss_source)); /* Run any other functions or filters that WordPress normally runs on feeds */ do_action_ref_array('wp_feed_options', array(&$feed, $rss_source)); /* Initiate the SimplePie instance */ $feed->init(); /* Tell SimplePie to send the feed MIME headers */ $feed->handle_content_type(); if ($feed->error()) { parent::log(sprintf(__('no %s data', 'reclaim'), $this->shortname)); parent::log($feed->error()); } else { $data = self::map_data($feed); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); } } else { parent::log(sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname)); } }
/** * @expectedException Exception_Success */ public function testDirectOverrideLegacy() { $feed = new SimplePie(); $feed->set_cache_class('Mock_CacheLegacy'); $feed->get_registry()->register('File', 'MockSimplePie_File'); $feed->set_feed_url('http://example.com/feed/'); $feed->init(); }
function powerpress_get_news($feed_url, $limit = 10) { include_once ABSPATH . WPINC . '/feed.php'; $rss = fetch_feed($feed_url); // If feed doesn't work... if (is_wp_error($rss)) { require_once ABSPATH . WPINC . '/class-feed.php'; // Try fetching the feed using CURL directly... $content = powerpress_remote_fopen($feed_url, false, array(), 3, false, true); if (!$content) { return false; } // Load the content in a fetch_feed object... $rss = new SimplePie(); $rss->set_sanitize_class('WP_SimplePie_Sanitize_KSES'); // We must manually overwrite $feed->sanitize because SimplePie's // constructor sets it before we have a chance to set the sanitization class $rss->sanitize = new WP_SimplePie_Sanitize_KSES(); $rss->set_cache_class('WP_Feed_Cache'); $rss->set_file_class('WP_SimplePie_File'); $rss->set_raw_data($content); $rss->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $feed_url)); do_action_ref_array('wp_feed_options', array(&$rss, $feed_url)); $rss->init(); $rss->set_output_encoding(get_option('blog_charset')); $rss->handle_content_type(); if ($rss->error()) { return false; } } $rss_items = $rss->get_items(0, $rss->get_item_quantity($limit)); // If the feed was erroneously if (!$rss_items) { $md5 = md5($this->feed); delete_transient('feed_' . $md5); delete_transient('feed_mod_' . $md5); $rss->__destruct(); unset($rss); $rss = fetch_feed($this->feed); $rss_items = $rss->get_items(0, $rss->get_item_quantity($num)); $rss->__destruct(); unset($rss); } return $rss_items; }
function get_rss_feed($url) { require_once ABSPATH . WPINC . '/class-feed.php'; $feed = new SimplePie(); $feed->set_sanitize_class('WP_SimplePie_Sanitize_KSES'); $feed->sanitize = new WP_SimplePie_Sanitize_KSES(); $feed->set_useragent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36'); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->set_feed_url($url); $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url)); do_action_ref_array('wp_feed_options', array(&$feed, $url)); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { return new WP_Error('simplepie-error', $feed->error()); } return $feed; }
/** * Build SimplePie object based on RSS or Atom feed from URL. * * @since 2.8 * * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged * using SimplePie's multifeed feature. * See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas} * * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success */ function fetch_feed($url) { require_once ABSPATH . WPINC . '/class-feed.php'; $feed = new SimplePie(); $feed->set_sanitize_class('WP_SimplePie_Sanitize_KSES'); // We must manually overwrite $feed->sanitize because SimplePie's // constructor sets it before we have a chance to set the sanitization class $feed->sanitize = new WP_SimplePie_Sanitize_KSES(); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->set_feed_url($url); $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url)); do_action_ref_array('wp_feed_options', array(&$feed, $url)); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { return new WP_Error('simplepie-error', $feed->error()); } return $feed; }
/** * _displayRSS * * @param string $url * @param int $num_items */ protected function _displayRSS($url, $num_items = -1) { $rss = new SimplePie(); $rss->strip_htmltags(array_diff($rss->strip_htmltags, array('style'))); $rss->strip_attributes(array_diff($rss->strip_attributes, array('style', 'class', 'id'))); $rss->set_feed_url($url); $rss->set_cache_class('WP_Feed_Cache'); $rss->set_file_class('WP_SimplePie_File'); $rss->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200, $url)); do_action_ref_array('wp_feed_options', array(&$rss, $url)); $rss->init(); $rss->handle_content_type(); if (!$rss->error()) { $maxitems = $rss->get_item_quantity(25); $rss_items = $rss->get_items(0, $maxitems); echo '<ul>'; if ($num_items !== -1) { $rss_items = array_slice($rss_items, 0, $num_items); } if ($rss_items) { foreach ((array) $rss_items as $item) { printf('<li><div class="date">%4$s</div><div class="thethefly-news-item">%2$s</div></li>', esc_url($item->get_permalink()), $item->get_description(), esc_html($item->get_title()), $item->get_date('D, d M Y')); } } else { echo "<li>"; _e('Unfortunately the news channel is temporarily closed', 'thethe-captcha'); echo "</li>"; } echo '</ul>'; } else { _e('An error has occurred, which probably means the feed is down. Try again later.', 'thethe-captcha'); } }
function fetch($url, $force_feed = true) { $feed = new SimplePie(); $feed->set_feed_url($url); if (version_compare(SIMPLEPIE_VERSION, '1.3-dev', '>')) { $feed->set_cache_location('wp-transient'); $feed->registry->register('Cache', 'WP_Feed_Cache_Transient'); $feed->registry->register('File', 'FeedWordPress_File'); } else { $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('FeedWordPress_File'); } $feed->set_content_type_sniffer_class('FeedWordPress_Content_Type_Sniffer'); $feed->set_file_class('FeedWordPress_File'); $feed->force_feed($force_feed); $feed->set_cache_duration(FeedWordPress::cache_duration()); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { $ret = new WP_Error('simplepie-error', $feed->error()); } else { $ret = $feed; } return $ret; }
/** * Build SimplePie object based on RSS or Atom feed from URL. * * @since 2.8 * * @param string $url URL to retrieve feed * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success */ function fetch_feed($url) { require_once ABSPATH . WPINC . '/class-feed.php'; $feed = new SimplePie(); if (version_compare(SIMPLEPIE_VERSION, '1.3-dev', '>')) { $feed->set_cache_location('wp-transient'); $feed->registry->register('Cache', 'WP_Feed_Cache_Transient'); $feed->registry->register('File', 'WP_SimplePie_File'); } else { $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); } $feed->set_feed_url($url); $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200, $url)); do_action_ref_array('wp_feed_options', array(&$feed, $url)); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { return new WP_Error('simplepie-error', $feed->error()); } return $feed; }
function bebop_rss_import($extension, $user_metas = null) { global $wpdb, $bp; $itemCounter = 0; if (empty($extension)) { bebop_tables::log_general('Importer', 'The $extension parameter is empty.'); return false; } else { $this_extension = bebop_extensions::bebop_get_extension_config_by_name($extension); } require_once ABSPATH . WPINC . '/class-feed.php'; //if user_metas is not defined, get some user meta. if (!isset($user_metas)) { $user_metas = bebop_tables::get_user_ids_from_meta_type($this_extension['name']); } else { $secondary_importers = true; } if (isset($user_metas)) { foreach ($user_metas as $user_meta) { //Ensure the user is wanting to import items. if (bebop_tables::get_user_meta_value($user_meta->user_id, 'bebop_' . $this_extension['name'] . '_active_for_user')) { if (isset($secondary_importers) && $secondary_importers === true) { $feeds = bebop_tables::get_initial_import_feeds($user_meta->user_id, $this_extension['name']); $user_feeds = bebop_tables::get_user_feeds_from_array($user_meta->user_id, $this_extension['name'], $feeds); } else { $user_feeds = bebop_tables::get_user_feeds($user_meta->user_id, $this_extension['name']); } foreach ($user_feeds as $user_feed) { $errors = null; $items = null; $feed_name = $user_feed->meta_name; $feed_url = $user_feed->meta_value; $import_username = stripslashes($feed_name); //Check the user has not gone past their import limit for the day. if (!bebop_filters::import_limit_reached($this_extension['name'], $user_meta->user_id, $import_username)) { if (bebop_tables::check_for_first_import($user_meta->user_id, $this_extension['name'], 'bebop_' . $this_extension['name'] . '_' . $import_username . '_do_initial_import')) { bebop_tables::delete_from_first_importers($user_meta->user_id, $this_extension['name'], 'bebop_' . $this_extension['name'] . '_' . $import_username . '_do_initial_import'); } /* * ****************************************************************************************************************** * Depending on the data source, you will need to switch how the data is retrieved. If the feed is RSS, use the * * SimplePie method, as shown in the youtube extension. If the feed is oAuth API based, use the oAuth implementation* * as shown in the twitter extension. If the feed is an API without oAuth authentication, use SlideShare * * ****************************************************************************************************************** */ //import the url //Configure the feed $feed = new SimplePie(); $feed->set_feed_url($feed_url); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->enable_cache(false); $feed->set_cache_duration(0); do_action_ref_array('wp_feed_options', array($feed, $feed_url)); $feed->init(); $feed->handle_content_type(); /* * ****************************************************************************************************************** * We can get as far as loading the items, but you will need to adjust the values of the variables below to match * * the values from the extension's feed. * * This is because each feed return data under different parameter names, and the simplest way to get around this is* * to quickly match the values. To find out what values you should be using, consult the provider's documentation. * * You can also contact us if you get stuck - details are in the 'support' section of the admin homepage. * * ****************************************************************************************************************** * * Values you will need to check and update are: * $errors - Must point to the error boolean value (true/false) * $id - Must be the ID of the item returned through the data feed. * $description - The actual content of the imported item. * $item_published - The time the item was published. * $action_link - This is where the link will point to - i.e. where the user can click to get more info. */ //Edit the following variables to point to where the relevant content is being stored in the feed: $errors = $feed->error; if (!$errors) { //Edit the following variable to point to where the relevant content is being stored in the feed: $items = $feed->get_items(); if ($items) { foreach ($items as $item) { if (!bebop_filters::import_limit_reached($this_extension['name'], $user_meta->user_id, $import_username)) { //Edit the following variables to point to where the relevant content is being stored: //$description = $item->get_content(); $item_published = date('Y-m-d H:i:s', strtotime($item->get_date())); $title = $item->get_title(); $action_link = $item->get_permalink(); $id_array = array_reverse(explode('/', $action_link)); $id = $id_array[1]; //Stop editing - you should be all done. //generate an $item_id $item_id = bebop_generate_secondary_id($user_meta->user_id, $id, $item_published); //if the id is not found, import the content. if (!bebop_tables::check_existing_content_id($user_meta->user_id, $this_extension['name'], $item_id)) { $item_content = $title . ' ' . $action_link; if (bebop_create_buffer_item(array('user_id' => $user_meta->user_id, 'extension' => $this_extension['name'], 'type' => $this_extension['content_type'], 'username' => $import_username, 'content' => $item_content, 'content_oembed' => $this_extension['content_oembed'], 'item_id' => $item_id, 'raw_date' => $item_published, 'actionlink' => $action_link))) { $itemCounter++; } } //End if ( ! empty( $secondary->secondary_item_id ) ) { } unset($item); } } } else { bebop_tables::log_error(sprintf(__('Importer - %1$s', 'bebop'), $this_extension['display_name']), sprintf(__('RSS Error: %1$s', 'bebop'), $errors)); } } } //End foreach ($user_feeds as $user_feed ) { unset($user_meta); } } } //return the result return $itemCounter . ' ' . $this_extension['content_type'] . 's'; }
function loadTwitterFeed($instance) { require_once ABSPATH . WPINC . '/class-feed.php'; $url = 'http://twitter.com/statuses/user_timeline/' . $instance['username'] . '.rss'; $cache_duration = $instance['refresh'] * 60; $feed = new SimplePie(); $feed->set_feed_url($url); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->set_cache_duration($cache_duration); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { return new WP_Error('simplepie-error', $feed->error()); } return $feed; }
function piratenkleider_fetch_feed($url, $lifetime = 0) { global $defaultoptions; global $options; if ($lifetime == 0) { $lifetime = $options['feed_cache_lifetime']; } if ($lifetime < 600) { $lifetime = 1800; } // Das holen von feeds sollte auf keinen Fall haeufiger als alle 10 Minuten erfolgen require_once ABSPATH . WPINC . '/class-feed.php'; $feed = new SimplePie(); if ($defaultoptions['use_wp_feed_defaults']) { $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); } else { if (isset($defaultoptions['dir_feed_cache']) && !empty($defaultoptions['dir_feed_cache'])) { if (is_dir($defaultoptions['dir_feed_cache'])) { $feed->set_cache_location($defaultoptions['dir_feed_cache']); } else { mkdir($defaultoptions['dir_feed_cache']); if (!is_dir($defaultoptions['dir_feed_cache'])) { echo "Wasnt able to create Feed-Cache directory"; } else { $feed->set_cache_location($defaultoptions['dir_feed_cache']); } } } } $feed->set_feed_url($url); $feed->set_cache_duration($lifetime); do_action_ref_array('wp_feed_options', array($feed, $url)); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { return new WP_Error('simplepie-error', $feed->error()); } return $feed; }
<?php /** @version $Id: inc.sidebar.themes.php 972 2011-08-25 18:31:32Z lexx-ua $ */ /** Require RSS lib */ require_once ABSPATH . WPINC . '/class-simplepie.php'; require_once ABSPATH . WPINC . '/class-feed.php'; require_once ABSPATH . WPINC . '/feed.php'; $_theme_rss_url = 'http://thethefly.com/index-themes-rss.php'; $_theme_rss_data = array(); $_theme_rss = new SimplePie(); $_theme_rss->set_feed_url($_theme_rss_url); $_theme_rss->set_cache_class('WP_Feed_Cache'); $_theme_rss->set_file_class('WP_SimplePie_File'); $_theme_rss->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200, $_theme_rss_url)); do_action_ref_array('wp_feed_options', array(&$_theme_rss, $_theme_rss_url)); $_theme_rss->init(); $_theme_rss->handle_content_type(); if (!$_theme_rss->error()) { $maxitems = $_theme_rss->get_item_quantity(50); $rss_items = $_theme_rss->get_items(0, $maxitems); if ($rss_items) { $_theme_rss_data = (array) $rss_items; } } if (is_array($_theme_rss_data)) { ?> <div class="thethe-themes postbox"> <div class="handlediv" title="<?php _e('Click to toggle'); ?> "><br />
*/ $kb_queries = array(__('How-To Articles', 'yikes-inc-easy-mailchimp-extender') => esc_url_raw('https://yikesplugins.com/feed/?post_type=kbe_knowledgebase&kbe_taxonomy=easy-forms-for-mailchimp&kbe_taxonomy=how-tos'), __('Usage Articles', 'yikes-inc-easy-mailchimp-extender') => esc_url_raw('https://yikesplugins.com/feed/?post_type=kbe_knowledgebase&kbe_taxonomy=easy-forms-for-mailchimp&kbe_taxonomy=usage-easy-forms-for-mailchimp'), __('Troubleshooting Articles', 'yikes-inc-easy-mailchimp-extender') => esc_url_raw('https://yikesplugins.com/feed/?post_type=kbe_knowledgebase&kbe_taxonomy=easy-forms-for-mailchimp&kbe_taxonomy=troubleshooting'), __('Code Snippets', 'yikes-inc-easy-mailchimp-extender') => esc_url_raw('https://yikesplugins.com/feed/?post_type=kbe_knowledgebase&kbe_taxonomy=easy-forms-for-mailchimp&kbe_taxonomy=snippet-library'), __('Setting Articles', 'yikes-inc-easy-mailchimp-extender') => esc_url_raw('https://yikesplugins.com/feed/?post_type=kbe_knowledgebase&kbe_taxonomy=easy-forms-for-mailchimp&kbe_taxonomy=settings'), __('Integration Articles', 'yikes-inc-easy-mailchimp-extender') => esc_url_raw('https://yikesplugins.com/feed/?post_type=kbe_knowledgebase&kbe_taxonomy=easy-forms-for-mailchimp&kbe_taxonomy=integrations'), __('Designer Articles', 'yikes-inc-easy-mailchimp-extender') => esc_url_raw('https://yikesplugins.com/feed/?post_type=kbe_knowledgebase&kbe_taxonomy=easy-forms-for-mailchimp&kbe_taxonomy=designer-documentation')); /** * Loop over all of our queries set above * @sicne 6.0.3.8 */ foreach ($kb_queries as $article_title => $rss_feed_url) { $page = isset($_GET['page']) ? $_GET['page'] : 'yikes-inc-easy-mailchimp-support'; /* Create the SimplePie object */ $article_feed = new SimplePie(); $article_feed->enable_cache(true); // temporary /* Set the URL of the feed you're retrieving */ $article_feed->set_feed_url($rss_feed_url); /* Tell SimplePie to cache the feed using WordPress' cache class */ $article_feed->set_cache_class('WP_Feed_Cache'); /* Tell SimplePie to use the WordPress class for retrieving feed files */ $article_feed->set_file_class('WP_SimplePie_File'); /* Tell SimplePie how long to cache the feed data in the WordPress database - Cached for 8 hours */ $article_feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 28800, $rss_feed_url)); /* Run any other functions or filters that WordPress normally runs on feeds */ do_action_ref_array('wp_feed_options', array($article_feed, $rss_feed_url)); /* Initiate the SimplePie instance */ $article_feed->init(); /* Tell SimplePie to send the feed MIME headers */ $article_feed->handle_content_type(); if ($article_feed->error()) { return $article_feed = new WP_Error('simplepie-error', $article_feed->error()); } // loop over latest items if ($article_feed->get_items()) {
/** * Build SimplePie object based on RSS or Atom feed from URL. * * @since 2.8 * * @param string $url URL to retrieve feed * @return nxt_Error|SimplePie nxt_Error object on failure or SimplePie object on success */ function fetch_feed($url) { require_once ABSPATH . nxtINC . '/class-feed.php'; $feed = new SimplePie(); $feed->set_feed_url($url); $feed->set_cache_class('nxt_Feed_Cache'); $feed->set_file_class('nxt_SimplePie_File'); $feed->set_cache_duration(apply_filters('nxt_feed_cache_transient_lifetime', 43200, $url)); do_action_ref_array('nxt_feed_options', array(&$feed, $url)); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { return new nxt_Error('simplepie-error', $feed->error()); } return $feed; }
/** * Build SimplePie object based on RSS or Atom feed from URL. * * @since 2.8 * * @param string $url URL to retrieve feed * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success */ function fetch_feed($url) { require_once ABSPATH . WPINC . '/class-feed.php'; $feed = new SimplePie(); $feed->set_feed_url($url); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200)); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { return new WP_Error('simplepie-error', $feed->error()); } return $feed; }
<?php /* * SimplePie strips out all query strings * we had to implement a workaround * https://github.com/simplepie/simplepie/issues/317 */ // Get RSS Feed(s) require_once ABSPATH . WPINC . '/class-feed.php'; /* Create the SimplePie object */ $feed = new SimplePie(); $feed_url = esc_url('https://yikesplugins.com/feed/?post_type=download&download_category=MailChimp&download_tag=add-on'); /* Set the URL of the feed you're retrieving */ $feed->set_feed_url($feed_url); /* Tell SimplePie to cache the feed using WordPress' cache class */ $feed->set_cache_class('WP_Feed_Cache'); /* Tell SimplePie to use the WordPress class for retrieving feed files */ $feed->set_file_class('WP_SimplePie_File'); $feed->enable_cache(true); // temporary /* Tell SimplePie how long to cache the feed data in the WordPress database */ $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200, $feed_url)); /* Run any other functions or filters that WordPress normally runs on feeds */ do_action_ref_array('wp_feed_options', array($feed, $feed_url)); /* Initiate the SimplePie instance */ $feed->init(); /* Tell SimplePie to send the feed MIME headers */ $feed->handle_content_type(); if ($feed->error()) { return $feed = new WP_Error('simplepie-error', $feed->error()); }
function feedzy_rss($atts, $content = '') { global $feedzyStyle; $feedzyStyle = true; $count = 0; //Load SimplePie if not already if (!class_exists('SimplePie')) { require_once ABSPATH . WPINC . '/class-feed.php'; } //Retrieve & extract shorcode parameters extract(shortcode_atts(array("feeds" => '', "max" => '5', "feed_title" => 'yes', "target" => '_blank', "title" => '', "meta" => 'yes', "summary" => 'yes', "summarylength" => '', "thumb" => 'yes', "default" => '', "size" => '', "keywords_title" => ''), $atts, 'feedzy_default')); //Use "shortcode_atts_feedzy_default" filter to edit shortcode parameters default values or add your owns. if (!empty($feeds)) { $feeds = rtrim($feeds, ','); $feeds = explode(',', $feeds); //Remove SSL from HTTP request to prevent fetching errors foreach ($feeds as $feed) { $feedURL[] = preg_replace("/^https:/i", "http:", $feed); } if (count($feedURL) === 1) { $feedURL = $feedURL[0]; } } if ($max == '0') { $max = '999'; } else { if (empty($max) || !ctype_digit($max)) { $max = '5'; } } if (empty($size) || !ctype_digit($size)) { $size = '150'; } $sizes = array('width' => $size, 'height' => $size); $sizes = apply_filters('feedzy_thumb_sizes', $sizes, $feedURL); if (!empty($title) && !ctype_digit($title)) { $title = ''; } if (!empty($keywords_title)) { $keywords_title = rtrim($keywords_title, ','); $keywords_title = array_map('trim', explode(',', $keywords_title)); } if (!empty($summarylength) && !ctype_digit($summarylength)) { $summarylength = ''; } if (!empty($default)) { $default = $default; } else { $default = apply_filters('feedzy_default_image', $default, $feedURL); } //Load SimplePie Instance $feed = new SimplePie(); $feed->set_feed_url($feedURL); $feed->enable_cache(true); $feed->enable_order_by_date(true); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 7200, $feedURL)); do_action_ref_array('wp_feed_options', array($feed, $feedURL)); $feed->strip_comments(true); $feed->strip_htmltags(array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style')); $feed->init(); $feed->handle_content_type(); // Display the error message if ($feed->error()) { $content .= apply_filters('feedzy_default_error', $feed->error(), $feedURL); } $content .= '<div class="feedzy-rss">'; if ($feed_title == 'yes') { $content .= '<div class="rss_header">'; $content .= '<h2><a href="' . $feed->get_permalink() . '" class="rss_title">' . html_entity_decode($feed->get_title()) . '</a> <span class="rss_description"> ' . $feed->get_description() . '</span></h2>'; $content .= '</div>'; } $content .= '<ul>'; //Loop through RSS feed $items = apply_filters('feedzy_feed_items', $feed->get_items(), $feedURL); foreach ((array) $items as $item) { $continue = apply_filters('feedzy_item_keyword', true, $keywords_title, $item, $feedURL); if ($continue == true) { //Count items if ($count >= $max) { break; } $count++; //Fetch image thumbnail if ($thumb == 'yes' || $thumb == 'auto') { $thethumbnail = feedzy_retrieve_image($item); } $itemAttr = apply_filters('feedzy_item_attributes', $itemAttr = '', $sizes, $item, $feedURL); //Build element DOM $content .= '<li ' . $itemAttr . '>'; if ($thumb == 'yes' || $thumb == 'auto') { $contentThumb = ''; if (!empty($thethumbnail) && $thumb == 'auto' || $thumb == 'yes') { $contentThumb .= '<div class="rss_image" style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px;">'; $contentThumb .= '<a href="' . $item->get_permalink() . '" target="' . $target . '" title="' . $item->get_title() . '" >'; if (!empty($thethumbnail)) { $thethumbnail = feedzy_image_encode($thethumbnail); $contentThumb .= '<span class="default" style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px; background-image: url(' . $default . ');" alt="' . $item->get_title() . '"></span>'; $contentThumb .= '<span class="fetched" style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px; background-image: url(' . $thethumbnail . ');" alt="' . $item->get_title() . '"></span>'; } else { if (empty($thethumbnail) && $thumb == 'yes') { $contentThumb .= '<span style="width:' . $sizes['width'] . 'px; height:' . $sizes['height'] . 'px; background-image:url(' . $default . ');" alt="' . $item->get_title() . '"></span>'; } } $contentThumb .= '</a>'; $contentThumb .= '</div>'; } //Filter: feedzy_thumb_output $content .= apply_filters('feedzy_thumb_output', $contentThumb, $feedURL); } $contentTitle = ''; $contentTitle .= '<span class="title"><a href="' . $item->get_permalink() . '" target="' . $target . '">'; if (is_numeric($title) && strlen($item->get_title()) > $title) { $contentTitle .= preg_replace('/\\s+?(\\S+)?$/', '', substr($item->get_title(), 0, $title)) . '...'; } else { $contentTitle .= $item->get_title(); } $contentTitle .= '</a></span>'; //Filter: feedzy_title_output $content .= apply_filters('feedzy_title_output', $contentTitle, $feedURL); $content .= '<div class="rss_content">'; //Define Meta args $metaArgs = array('author' => true, 'date' => true, 'date_format' => get_option('date_format'), 'time_format' => get_option('time_format')); //Filter: feedzy_meta_args $metaArgs = apply_filters('feedzy_meta_args', $metaArgs, $feedURL); if ($meta == 'yes' && ($metaArgs['author'] || $metaArgs['date'])) { $contentMeta = ''; $contentMeta .= '<small>' . __('Posted', 'feedzy_rss_translate') . ' '; if ($item->get_author() && $metaArgs['author']) { $author = $item->get_author(); if (!($authorName = $author->get_name())) { $authorName = $author->get_email(); } if ($authorName) { $domain = parse_url($item->get_permalink()); $contentMeta .= __('by', 'feedzy_rss_translate') . ' <a href="http://' . $domain['host'] . '" target="' . $target . '" title="' . $domain['host'] . '" >' . $authorName . '</a> '; } } if ($metaArgs['date']) { $contentMeta .= __('on', 'feedzy_rss_translate') . ' ' . date_i18n($metaArgs['date_format'], $item->get_date('U')); $contentMeta .= ' '; $contentMeta .= __('at', 'feedzy_rss_translate') . ' ' . date_i18n($metaArgs['time_format'], $item->get_date('U')); } $contentMeta .= '</small>'; //Filter: feedzy_meta_output $content .= apply_filters('feedzy_meta_output', $contentMeta, $feedURL); } if ($summary == 'yes') { $contentSummary = ''; $contentSummary .= '<p>'; //Filter: feedzy_summary_input $description = $item->get_description(); $description = apply_filters('feedzy_summary_input', $description, $item->get_content(), $feedURL); if (is_numeric($summarylength) && strlen($description) > $summarylength) { $contentSummary .= preg_replace('/\\s+?(\\S+)?$/', '', substr($description, 0, $summarylength)) . ' […]'; } else { $contentSummary .= $description . ' […]'; } $contentSummary .= '</p>'; //Filter: feedzy_summary_output $content .= apply_filters('feedzy_summary_output', $contentSummary, $item->get_permalink(), $feedURL); } $content .= '</div>'; $content .= '</li>'; } //endContinue } //endforeach $content .= '</ul>'; $content .= '</div>'; return apply_filters('feedzy_global_output', $content, $feedURL); }
function getRSS($settings) { require_once ABSPATH . WPINC . '/class-feed.php'; // get the feeds if ($settings['type'] == "user") { $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $settings['id'] . '&tags=' . $settings['tags'] . '&format=rss_200'; } elseif ($settings['type'] == "favorite") { $rss_url = 'http://api.flickr.com/services/feeds/photos_faves.gne?id=' . $settings['id'] . '&format=rss_200'; } elseif ($settings['type'] == "set") { $rss_url = 'http://api.flickr.com/services/feeds/photoset.gne?set=' . $settings['set'] . '&nsid=' . $settings['id'] . '&format=rss_200'; } elseif ($settings['type'] == "group") { $rss_url = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=' . $settings['id'] . '&format=rss_200'; } elseif ($settings['type'] == "public" || $settings['type'] == "community") { $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags=' . $settings['tags'] . '&format=rss_200'; } else { print '<strong>No "type" parameter has been setup. Check your settings, or provide the parameter as an argument.</strong>'; } $feed = new SimplePie(); $feed->set_feed_url($rss_url); $feed->set_cache_class('WP_Feed_Cache'); $feed->set_file_class('WP_SimplePie_File'); $feed->init(); $feed->handle_content_type(); if ($feed->error()) { printf('There was an error while connecting to Feed server, please, try again!'); } # get rss file return $feed->get_items(0, $settings['num_items']); }