function list_posts($cfg) { require_once 'inc/simplepie.inc'; $feed = new SimplePie(); // Set which feed to process. // handle the different feeds // blogging if ($cfg['tumblr'] != "") { $feeds[] = 'http://' . $cfg['tumblr'] . '.tumblr.com/rss'; } if ($cfg['blogger'] != "") { $feeds[] = 'http://' . $cfg['blogger'] . '.blogspot.com/feeds/posts/default?alt=rss'; } if ($cfg['medium'] != "") { $feeds[] = 'https://medium.com/feed/@' . $cfg['medium'] . '/'; } if ($cfg['ghost'] != "") { $feeds[] = 'http://' . $cfg['ghost'] . '.ghost.io/rss/'; } if ($cfg['postachio'] != "") { $feeds[] = 'http://' . $cfg['postachio'] . '.postach.io/feed.xml'; } if ($cfg['custom'] != "") { $feeds[] = $cfg['custom']; } // plugins if (file_exists('plugins')) { $plugins = listFiles('plugins'); if (count($plugins) > 0) { foreach ($plugins as $plugin) { $feeds[] = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['PHP_SELF']) . '/plugins/' . $plugin . '/index.php'; } } } $feed->set_feed_url($feeds); // allow iframe embeds $strip_htmltags = $feed->strip_htmltags; array_splice($strip_htmltags, array_search('iframe', $strip_htmltags), 1); $feed->strip_htmltags($strip_htmltags); // Run SimplePie. $feed->init(); // This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it). $feed->handle_content_type(); return $feed; }
/** * returns a simplepie feed object. * */ function feed($feed_url, $limit = 0) { if (!file_exists($this->cache)) { $folder = new Folder(); $folder->mkdir($this->cache); } //setup SimplePie $feed = new SimplePie(); $feed->set_feed_url($feed_url); $feed->set_cache_location($this->cache); $feed->set_item_limit($limit); $feed->strip_htmltags(array('img')); //retrieve the feed $feed->init(); //get the feed items $items = $feed->get_items(); //return if ($items) { return $items; } else { return false; } }
/** * Opens an RSS feed, parses and loads the contents. * * @param string $url The URL of the RSS feed * @param bool $nativeOrder If true, disable order by date to preserve native ordering * @param bool $force Force SimplePie to parse the feed despite errors * * @return object An object that encapsulates the feed contents and operations on those contents. * @throws FeedParserException If opening or parsing feed fails **/ public function parseFeed($url, $nativeOrder = false, $force = false) { require_once PATH_SYSTEM . '/vendors/SimplePie.php'; $feed = new SimplePie(); $feed->set_timeout($this->timeout); $feed->set_feed_url($url); $feed->enable_order_by_date(!$nativeOrder); $feed->force_feed($force); if ($this->cacheDuration != null) { $feed->set_cache_duration(intval($this->cacheDuration)); } if ($this->cacheDirectory != null) { $feed->set_cache_location($this->cacheDirectory); } if ($this->stripHtmlTags != null) { $feed->strip_htmltags($this->stripHtmlTags); } @$feed->init(); if ($err = $feed->error()) { throw new FeedParserException($err); } return $feed; }
function combine_feeds($feed_list, $max_items = 10, $delimiter = '~', $remove_html = true) { if (empty($feed_list)) { return false; } $combined_feed = array(); foreach ($feed_list as $url) { $feed = new SimplePie(); $feed->set_feed_url($url); $feed->set_cache_location(ABSPATH . '/cache'); //$feed->replace_headers(true); if ($remove_html) { $feed->strip_htmltags(array('img', 'a', 'object', 'embed', 'param', 'iframe', 'p', 'br', 'div', 'span', 'li', 'ul')); } $feed->set_output_encoding(CHARSET); $feed->init(); foreach ($feed->get_items(0, $max_items) as $item) { $combined_feed[$item->get_date('U') . $delimiter . $feed->get_title() . $delimiter . $url] = $item; } unset($feed); } krsort($combined_feed); return array_slice($combined_feed, 0, $max_items); }
/** * The actual function that can be called on webpages. */ function SimplePieWP($feed_url, $options = null) { // Quit if the SimplePie class isn't loaded. if (!class_exists('SimplePie')) { die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> There is a problem with the SimplePie Plugin for WordPress. Check your <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">Installation Status</a> for more information.</p>'); } if (isset($locale) && !empty($locale) && $locale != 'auto') { setlocale(LC_TIME, $locale); } // Default general settings $template = get_option('simplepie_template'); $items = get_option('simplepie_items'); $items_per_feed = get_option('simplepie_items_per_feed'); $date_format = get_option('simplepie_date_format'); $enable_cache = get_option('simplepie_enable_cache'); $set_cache_location = get_option('simplepie_set_cache_location'); $set_cache_duration = get_option('simplepie_set_cache_duration'); $enable_order_by_date = get_option('simplepie_enable_order_by_date'); $set_timeout = get_option('simplepie_set_timeout'); // Default text-shortening settings $truncate_feed_title = get_option('simplepie_truncate_feed_title'); $truncate_feed_description = get_option('simplepie_truncate_feed_description'); $truncate_item_title = get_option('simplepie_truncate_item_title'); $truncate_item_description = get_option('simplepie_truncate_item_description'); // Default advanced settings $processing = get_option('simplepie_processing'); $locale = get_option('simplepie_locale'); $local_date_format = get_option('simplepie_local_date_format'); $strip_htmltags = get_option('simplepie_strip_htmltags'); $strip_attributes = get_option('simplepie_strip_attributes'); $set_max_checked_feeds = get_option('simplepie_set_max_checked_feeds'); // Overridden settings if ($options) { // Fix the template location if one was passed in. if (isset($options['template']) && !empty($options['template'])) { $options['template'] = SIMPLEPIE_PLUGINDIR . '/templates/' . strtolower(str_replace(' ', '_', $options['template'])) . '.tmpl'; } // Fix the processing location if one was passed in. if (isset($options['processing']) && !empty($options['processing'])) { $options['processing'] = SIMPLEPIE_PLUGINDIR . '/processing/' . strtolower(str_replace(' ', '_', $options['processing'])) . '.php'; } extract($options); } // Load post-processing file. if ($processing && $processing != '') { include_once $processing; } // If template doesn't exist, die. if (!file_exists($template) || !is_readable($template)) { die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> The SimplePie template file is not readable by WordPress. Check the <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">WordPress Control Panel</a> for more information.</p>'); } // Initialize SimplePie $feed = new SimplePie(); $feed->set_feed_url($feed_url); $feed->enable_cache($enable_cache); $feed->set_item_limit($items_per_feed); $feed->set_cache_location($set_cache_location); $feed->set_cache_duration($set_cache_duration); $feed->enable_order_by_date($enable_order_by_date); $feed->set_timeout($set_timeout); $feed->strip_htmltags(explode(' ', $strip_htmltags)); $feed->strip_attributes(explode(' ', $strip_attributes)); $feed->set_max_checked_feeds($set_max_checked_feeds); $feed->init(); // Load up the selected template file $handle = fopen($template, 'r'); $tmpl = fread($handle, filesize($template)); fclose($handle); /**************************************************************************************************************/ // ERRORS // I'm absolutely sure that there is a better way to do this. // Define what we're looking for $error_start_tag = '{IF_ERROR_BEGIN}'; $error_end_tag = '{IF_ERROR_END}'; $error_start_length = strlen($error_start_tag); $error_end_length = strlen($error_end_tag); // Find what we're looking for $error_start_pos = strpos($tmpl, $error_start_tag); $error_end_pos = strpos($tmpl, $error_end_tag); $error_length_pos = $error_end_pos - $error_start_pos; // Grab what we're looking for $error_string = substr($tmpl, $error_start_pos + $error_start_length, $error_length_pos - $error_start_length); $replacable_string = $error_start_tag . $error_string . $error_end_tag; if ($error_message = $feed->error()) { $tmpl = str_replace($replacable_string, $error_string, $tmpl); $tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', $error_message), $tmpl); } elseif ($feed->get_item_quantity() == 0) { $tmpl = str_replace($replacable_string, $error_string, $tmpl); $tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', 'There are no items in this feed.'), $tmpl); } else { $tmpl = str_replace($replacable_string, '', $tmpl); } /**************************************************************************************************************/ // FEED // FEED_AUTHOR_EMAIL /* if ($author = $feed->get_author()) { if ($email = $author->get_email()) { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('FEED_AUTHOR_EMAIL', $email), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl); } // FEED_AUTHOR_LINK if ($author = $feed->get_author()) { if ($link = $author->get_link()) { $tmpl = str_replace('{FEED_AUTHOR_LINK}', SimplePie_WordPress::post_process('FEED_AUTHOR_LINK', $link), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl); } // FEED_AUTHOR_NAME if ($author = $feed->get_author()) { if ($name = $author->get_name()) { $tmpl = str_replace('{FEED_AUTHOR_NAME}', SimplePie_WordPress::post_process('FEED_AUTHOR_NAME', $name), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_NAME}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_NAME}', '', $tmpl); } // FEED_CONTRIBUTOR_EMAIL if ($contributor = $feed->get_contributor()) { if ($email = $contributor->get_email()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_EMAIL', $email), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', '', $tmpl); } // FEED_CONTRIBUTOR_LINK if ($contributor = $feed->get_contributor()) { if ($link = $contributor->get_link()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_LINK', $link), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', '', $tmpl); } // FEED_CONTRIBUTOR_NAME if ($contributor = $feed->get_contributor()) { if ($name = $contributor->get_name()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_NAME', $name), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', '', $tmpl); } // FEED_COPYRIGHT if ($copyright = $feed->get_copyright()) { $tmpl = str_replace('{FEED_COPYRIGHT}', SimplePie_WordPress::post_process('FEED_COPYRIGHT', $copyright), $tmpl); } else { $tmpl = str_replace('{FEED_COPYRIGHT}', '', $tmpl); } // FEED_DESCRIPTION if ($description = $feed->get_description()) { $tmpl = str_replace('{FEED_DESCRIPTION}', SimplePie_WordPress::post_process('FEED_DESCRIPTION', $description), $tmpl); } else { $tmpl = str_replace('{FEED_DESCRIPTION}', '', $tmpl); } // FEED_ENCODING if ($encoding = $feed->get_encoding()) { $tmpl = str_replace('{FEED_ENCODING}', SimplePie_WordPress::post_process('FEED_ENCODING', $encoding), $tmpl); } else { $tmpl = str_replace('{FEED_ENCODING}', '', $tmpl); } // FEED_FAVICON if ($favicon = $feed->get_favicon()) { $tmpl = str_replace('{FEED_FAVICON}', SimplePie_WordPress::post_process('FEED_FAVICON', $favicon), $tmpl); } else { $tmpl = str_replace('{FEED_FAVICON}', '', $tmpl); } // FEED_IMAGE_HEIGHT if ($image_height = $feed->get_image_height()) { $tmpl = str_replace('{FEED_IMAGE_HEIGHT}', SimplePie_WordPress::post_process('FEED_IMAGE_HEIGHT', $image_height), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_HEIGHT}', '', $tmpl); } // FEED_IMAGE_LINK if ($image_link = $feed->get_image_link()) { $tmpl = str_replace('{FEED_IMAGE_LINK}', SimplePie_WordPress::post_process('FEED_IMAGE_LINK', $image_link), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_LINK}', '', $tmpl); } // FEED_IMAGE_TITLE if ($image_title = $feed->get_image_title()) { $tmpl = str_replace('{FEED_IMAGE_TITLE}', SimplePie_WordPress::post_process('FEED_IMAGE_TITLE', $image_title), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_TITLE}', '', $tmpl); } // FEED_IMAGE_URL if ($image_url = $feed->get_image_url()) { $tmpl = str_replace('{FEED_IMAGE_URL}', SimplePie_WordPress::post_process('FEED_IMAGE_URL', $image_url), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_URL}', '', $tmpl); } // FEED_IMAGE_WIDTH if ($image_width = $feed->get_image_width()) { $tmpl = str_replace('{FEED_IMAGE_WIDTH}', SimplePie_WordPress::post_process('FEED_IMAGE_WIDTH', $image_width), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_WIDTH}', '', $tmpl); } // FEED_LANGUAGE if ($language = $feed->get_language()) { $tmpl = str_replace('{FEED_LANGUAGE}', SimplePie_WordPress::post_process('FEED_LANGUAGE', $language), $tmpl); } else { $tmpl = str_replace('{FEED_LANGUAGE}', '', $tmpl); } // FEED_LATITUDE if ($latitude = $feed->get_latitude()) { $tmpl = str_replace('{FEED_LATITUDE}', SimplePie_WordPress::post_process('FEED_LATITUDE', $latitude), $tmpl); } else { $tmpl = str_replace('{FEED_LATITUDE}', '', $tmpl); } // FEED_LONGITUDE if ($longitude = $feed->get_longitude()) { $tmpl = str_replace('{FEED_LONGITUDE}', SimplePie_WordPress::post_process('FEED_LONGITUDE', $longitude), $tmpl); } else { $tmpl = str_replace('{FEED_LONGITUDE}', '', $tmpl); } // FEED_PERMALINK if ($permalink = $feed->get_permalink()) { $tmpl = str_replace('{FEED_PERMALINK}', SimplePie_WordPress::post_process('FEED_PERMALINK', $permalink), $tmpl); } else { $tmpl = str_replace('{FEED_PERMALINK}', '', $tmpl); } // FEED_TITLE if ($title = $feed->get_title()) { $tmpl = str_replace('{FEED_TITLE}', SimplePie_WordPress::post_process('FEED_TITLE', $title), $tmpl); } else { $tmpl = str_replace('{FEED_TITLE}', '', $tmpl); } // SUBSCRIBE_URL if ($subscribe_url = $feed->subscribe_url()) { $tmpl = str_replace('{SUBSCRIBE_URL}', SimplePie_WordPress::post_process('SUBSCRIBE_URL', $subscribe_url), $tmpl); } else { $tmpl = str_replace('{SUBSCRIBE_URL}', '', $tmpl); } // TRUNCATE_FEED_DESCRIPTION if ($description = $feed->get_description()) { $tmpl = str_replace('{TRUNCATE_FEED_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_FEED_DESCRIPTION', $description), $truncate_feed_description), $tmpl); } else { $tmpl = str_replace('{TRUNCATE_FEED_DESCRIPTION}', '', $tmpl); } // TRUNCATE_FEED_TITLE if ($title = $feed->get_title()) { $tmpl = str_replace('{TRUNCATE_FEED_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_FEED_TITLE', $title), $truncate_feed_title), $tmpl); } else { $tmpl = str_replace('{TRUNCATE_FEED_TITLE}', '', $tmpl); } */ /**************************************************************************************************************/ // ITEMS // Separate out the pre-item template $tmpl = explode('{ITEM_LOOP_BEGIN}', $tmpl); $pre_tmpl = $tmpl[0]; // Separate out the item template $tmpl = explode('{ITEM_LOOP_END}', $tmpl[1]); $item_tmpl = $tmpl[0]; // Separate out the post-item template $post_tmpl = $tmpl[1]; // Clear out the variable unset($tmpl); // Start putting the output string together. $tmpl = $pre_tmpl; // Loop through all of the items that we're supposed to. foreach ($feed->get_items(0, $items) as $item) { // Get a reference to the parent $feed object. $parent = $item->get_feed(); // Get a working copy of the item template. We don't want to edit the original. $working_item = $item_tmpl; // ITEM_CONTRIBUTOR_EMAIL /* if ($contributor = $item->get_contributor()) { if ($email = $contributor->get_email()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', '', $working_item); } // ITEM_CONTRIBUTOR_LINK if ($contributor = $item->get_contributor()) { if ($link = $contributor->get_link()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', '', $working_item); } // ITEM_CONTRIBUTOR_NAME if ($contributor = $item->get_contributor()) { if ($name = $contributor->get_name()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', '', $working_item); } // ITEM_COPYRIGHT if ($copyright = $item->get_copyright()) { $working_item = str_replace('{ITEM_COPYRIGHT}', SimplePie_WordPress::post_process('ITEM_COPYRIGHT', $copyright), $working_item); } else { $working_item = str_replace('{ITEM_COPYRIGHT}', '', $working_item); } // ITEM_PARENT_AUTHOR_EMAIL if ($author = $parent->get_author()) { if ($email = $author->get_email()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', '', $working_item); } // ITEM_PARENT_AUTHOR_LINK if ($author = $parent->get_author()) { if ($link = $author->get_link()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', '', $working_item); } // ITEM_PARENT_AUTHOR_NAME if ($author = $parent->get_author()) { if ($name = $author->get_name()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_EMAIL if ($contributor = $parent->get_contributor()) { if ($email = $contributor->get_email()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_LINK if ($contributor = $parent->get_contributor()) { if ($link = $contributor->get_link()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_NAME if ($contributor = $parent->get_contributor()) { if ($name = $contributor->get_name()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', '', $working_item); } // ITEM_AUTHOR_EMAIL if ($author = $item->get_author()) { if ($email = $author->get_email()) { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_AUTHOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', '', $working_item); } // ITEM_AUTHOR_LINK if ($author = $item->get_author()) { if ($link = $author->get_link()) { $working_item = str_replace('{ITEM_AUTHOR_LINK}', SimplePie_WordPress::post_process('ITEM_AUTHOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_LINK}', '', $working_item); } // ITEM_AUTHOR_NAME if ($author = $item->get_author()) { if ($name = $author->get_name()) { $working_item = str_replace('{ITEM_AUTHOR_NAME}', SimplePie_WordPress::post_process('ITEM_AUTHOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_NAME}', '', $working_item); } // ITEM_CATEGORY if ($category = $item->get_category()) { if ($label = $category->get_label()) { $working_item = str_replace('{ITEM_CATEGORY}', SimplePie_WordPress::post_process('ITEM_CATEGORY', $label), $working_item); } else { $working_item = str_replace('{ITEM_CATEGORY}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CATEGORY}', '', $working_item); } */ // ITEM_CONTENT if ($content = $item->get_content()) { $working_item = str_replace('{ITEM_CONTENT}', SimplePie_WordPress::post_process('ITEM_CONTENT', $content), $working_item); } else { $working_item = str_replace('{ITEM_CONTENT}', '', $working_item); } // ITEM_DATE if ($date = $item->get_date($date_format)) { $working_item = str_replace('{ITEM_DATE}', SimplePie_WordPress::post_process('ITEM_DATE', $date), $working_item); } else { $working_item = str_replace('{ITEM_DATE}', '', $working_item); } // ITEM_DATE_UTC if ($date = $item->get_date('U')) { $date = gmdate($date_format, $date); $working_item = str_replace('{ITEM_DATE_UTC}', SimplePie_WordPress::post_process('ITEM_DATE_UTC', $date), $working_item); } else { $working_item = str_replace('{ITEM_DATE_UTC}', '', $working_item); } // ITEM_DESCRIPTION if ($description = $item->get_description()) { $working_item = str_replace('{ITEM_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_DESCRIPTION', $description), $working_item); } else { $working_item = str_replace('{ITEM_DESCRIPTION}', '', $working_item); } /* // ITEM_ENCLOSURE_EMBED if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->native_embed()) { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EMBED', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', '', $working_item); } // ITEM_ENCLOSURE_EXTENSION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_extension()) { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EXTENSION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', '', $working_item); } // ITEM_ENCLOSURE_HANDLER if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_handler()) { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HANDLER', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', '', $working_item); } // ITEM_ENCLOSURE_LENGTH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_length()) { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LENGTH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', '', $working_item); } // ITEM_ENCLOSURE_LINK if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_link()) { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LINK', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', '', $working_item); } // ITEM_ENCLOSURE_REAL_TYPE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_real_type()) { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_REAL_TYPE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', '', $working_item); } // ITEM_ENCLOSURE_SIZE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_size()) { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_SIZE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', '', $working_item); } // ITEM_ENCLOSURE_TYPE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_type()) { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_TYPE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', '', $working_item); } // ITEM_ENCLOSURE_BITRATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_bitrate()) { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_BITRATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', '', $working_item); } // ITEM_ENCLOSURE_CHANNELS if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_channels()) { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_CHANNELS', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', '', $working_item); } // ITEM_ENCLOSURE_DESCRIPTION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_description()) { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_DESCRIPTION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', '', $working_item); } // ITEM_ENCLOSURE_DURATION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_duration()) { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_DURATION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', '', $working_item); } // ITEM_ENCLOSURE_EXPRESSION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_expression()) { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EXPRESSION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', '', $working_item); } // ITEM_ENCLOSURE_FRAMERATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_framerate()) { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_FRAMERATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', '', $working_item); } // ITEM_ENCLOSURE_HASH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_hash()) { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HASH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', '', $working_item); } // ITEM_ENCLOSURE_HEIGHT if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_height()) { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HEIGHT', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', '', $working_item); } // ITEM_ENCLOSURE_LANGUAGE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_language()) { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LANGUAGE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', '', $working_item); } // ITEM_ENCLOSURE_MEDIUM if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_medium()) { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_MEDIUM', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', '', $working_item); } // ITEM_ENCLOSURE_PLAYER if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_player()) { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_PLAYER', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', '', $working_item); } // ITEM_ENCLOSURE_SAMPLINGRATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_sampling_rate()) { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_SAMPLINGRATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', '', $working_item); } // ITEM_ENCLOSURE_THUMBNAIL if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_thumbnail()) { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_THUMBNAIL', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', '', $working_item); } // ITEM_ENCLOSURE_TITLE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_title()) { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_TITLE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', '', $working_item); } // ITEM_ENCLOSURE_WIDTH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_width()) { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_WIDTH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', '', $working_item); } // ITEM_ID if ($id = $item->get_id()) { $working_item = str_replace('{ITEM_ID}', SimplePie_WordPress::post_process('ITEM_ID', $id), $working_item); } else { $working_item = str_replace('{ITEM_ID}', '', $working_item); } // ITEM_ID if ($latitude = $item->get_latitude()) { $working_item = str_replace('{ITEM_LATITUDE}', SimplePie_WordPress::post_process('ITEM_LATITUDE', $latitude), $working_item); } else { $working_item = str_replace('{ITEM_LATITUDE}', '', $working_item); } // ITEM_LOCAL_DATE if ($local_date = $item->get_local_date($local_date_format)) { $working_item = str_replace('{ITEM_LOCAL_DATE}', SimplePie_WordPress::post_process('ITEM_LOCAL_DATE', $local_date), $working_item); } else { $working_item = str_replace('{ITEM_LOCAL_DATE}', '', $working_item); } // ITEM_LOCAL_DATE_UTC if ($local_date = $item->get_date('U')) { $local_date = gmdate('U', $local_date); $local_date = strftime($local_date_format, $local_date); $working_item = str_replace('{ITEM_LOCAL_DATE_UTC}', SimplePie_WordPress::post_process('ITEM_LOCAL_DATE_UTC', $local_date), $working_item); } else { $working_item = str_replace('{ITEM_LOCAL_DATE_UTC}', '', $working_item); } // ITEM_LONGITUDE if ($longitude = $item->get_longitude()) { $working_item = str_replace('{ITEM_LONGITUDE}', SimplePie_WordPress::post_process('ITEM_LONGITUDE', $longitude), $working_item); } else { $working_item = str_replace('{ITEM_LONGITUDE}', '', $working_item); } */ // ITEM_PERMALINK if ($permalink = $item->get_permalink()) { $working_item = str_replace('{ITEM_PERMALINK}', SimplePie_WordPress::post_process('ITEM_PERMALINK', $permalink), $working_item); } else { $working_item = str_replace('{ITEM_PERMALINK}', '', $working_item); } // ITEM_TITLE if ($title = $item->get_title()) { $working_item = str_replace('{ITEM_TITLE}', SimplePie_WordPress::post_process('ITEM_TITLE', $title), $working_item); } else { $working_item = str_replace('{ITEM_TITLE}', '', $working_item); } /* // ITEM_PARENT_COPYRIGHT if ($copyright = $parent->get_copyright()) { $working_item = str_replace('{ITEM_PARENT_COPYRIGHT}', SimplePie_WordPress::post_process('ITEM_PARENT_COPYRIGHT', $copyright), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_COPYRIGHT}', '', $working_item); } // ITEM_PARENT_DESCRIPTION if ($description = $parent->get_description()) { $working_item = str_replace('{ITEM_PARENT_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_PARENT_DESCRIPTION', $description), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_DESCRIPTION}', '', $working_item); } // ITEM_PARENT_ENCODING if ($encoding = $parent->get_encoding()) { $working_item = str_replace('{ITEM_PARENT_ENCODING}', SimplePie_WordPress::post_process('ITEM_PARENT_ENCODING', $encoding), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_ENCODING}', '', $working_item); } // ITEM_PARENT_FAVICON if ($favicon = $parent->get_favicon()) { $working_item = str_replace('{ITEM_PARENT_FAVICON}', SimplePie_WordPress::post_process('ITEM_PARENT_FAVICON', $favicon), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_FAVICON}', '', $working_item); } // ITEM_PARENT_IMAGE_HEIGHT if ($image_height = $parent->get_image_height()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_HEIGHT}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_HEIGHT', $image_height), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_HEIGHT}', '', $working_item); } // ITEM_PARENT_IMAGE_LINK if ($image_link = $parent->get_image_link()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_LINK', $image_link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_LINK}', '', $working_item); } // ITEM_PARENT_IMAGE_TITLE if ($image_title = $parent->get_image_title()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_TITLE}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_TITLE', $image_title), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_TITLE}', '', $working_item); } // ITEM_PARENT_IMAGE_URL if ($image_url = $parent->get_image_url()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_URL}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_URL', $image_url), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_URL}', '', $working_item); } // ITEM_PARENT_IMAGE_WIDTH if ($image_width = $parent->get_image_width()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_WIDTH}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_WIDTH', $image_width), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_WIDTH}', '', $working_item); } // ITEM_PARENT_LANGUAGE if ($language = $parent->get_language()) { $working_item = str_replace('{ITEM_PARENT_LANGUAGE}', SimplePie_WordPress::post_process('ITEM_PARENT_LANGUAGE', $language), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LANGUAGE}', '', $working_item); } // ITEM_PARENT_LATITUDE if ($latitude = $parent->get_latitude()) { $working_item = str_replace('{ITEM_PARENT_LATITUDE}', SimplePie_WordPress::post_process('ITEM_PARENT_LATITUDE', $latitude), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LATITUDE}', '', $working_item); } // ITEM_PARENT_LONGITUDE if ($longitude = $parent->get_longitude()) { $working_item = str_replace('{ITEM_PARENT_LONGITUDE}', SimplePie_WordPress::post_process('ITEM_PARENT_LONGITUDE', $longitude), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LONGITUDE}', '', $working_item); } // ITEM_PARENT_PERMALINK if ($permalink = $parent->get_permalink()) { $working_item = str_replace('{ITEM_PARENT_PERMALINK}', SimplePie_WordPress::post_process('ITEM_PARENT_PERMALINK', $permalink), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_PERMALINK}', '', $working_item); } // ITEM_PARENT_TITLE if ($title = $parent->get_title()) { $working_item = str_replace('{ITEM_PARENT_TITLE}', SimplePie_WordPress::post_process('ITEM_PARENT_TITLE', $title), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_TITLE}', '', $working_item); } // ITEM_PARENT_SUBSCRIBE_URL if ($subscribe_url = $parent->subscribe_url()) { $working_item = str_replace('{ITEM_PARENT_SUBSCRIBE_URL}', SimplePie_WordPress::post_process('ITEM_PARENT_SUBSCRIBE_URL', $subscribe_url), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_SUBSCRIBE_URL}', '', $working_item); } */ // TRUNCATE_ITEM_DESCRIPTION if ($description = $item->get_description()) { $working_item = str_replace('{TRUNCATE_ITEM_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_DESCRIPTION', $description), $truncate_item_description), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_DESCRIPTION}', '', $working_item); } // TRUNCATE_ITEM_TITLE if ($title = $item->get_title()) { $working_item = str_replace('{TRUNCATE_ITEM_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_TITLE', $title), $truncate_item_title), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_TITLE}', '', $working_item); } /* // TRUNCATE_ITEM_PARENT_DESCRIPTION if ($description = $parent->get_description()) { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_PARENT_DESCRIPTION', $description), $truncate_feed_description), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_DESCRIPTION}', '', $working_item); } // TRUNCATE_ITEM_PARENT_TITLE if ($title = $parent->get_title()) { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_PARENT_TITLE', $title), $truncate_feed_title), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_TITLE}', '', $working_item); } */ $tmpl .= $working_item; } /**************************************************************************************************************/ // LAST STUFF // Start by removing all line breaks and tabs. $tmpl = preg_replace('/(\\n|\\r|\\t)/i', "", $tmpl); // PLUGIN_DIR $tmpl = str_replace('{PLUGIN_DIR}', SIMPLEPIE_PLUGINDIR_WEB, $tmpl); $tmpl .= $post_tmpl; // Kill the object to prevent memory leaks. $feed->__destruct(); unset($feed); unset($encltemp); unset($working_item); // Return the data back to the page. return $tmpl; }
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 import($feedObj, $maxItems = 0) { jimport('simplepie.simplepie'); $config = EasyBlogHelper::getConfig(); $itemMigrated = 0; $isDomSupported = false; $defaultAllowedHTML = '<img>,<a>,<br>,<table>,<tbody>,<th>,<tr>,<td>,<div>,<span>,<p>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>'; if (class_exists('DomDocument')) { $isDomSupported = true; require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'readability' . DIRECTORY_SEPARATOR . 'Readability.php'; } $params = EasyBlogHelper::getRegistry($feedObj->params); $maxItems = $maxItems ? $maxItems : $params->get('feedamount', 0); $feedURL = $feedObj->url; require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'connectors.php'; $connector = new EasyBlogConnectorsHelper(); $connector->addUrl($feedURL); $connector->execute(); $content = $connector->getResult($feedURL); // to ensure the leading no text before the <?xml> tag //$pattern = '/(.*?)(?=<\?xml)/ims'; $pattern = '/(.*?)<\\?xml version/is'; $replacement = '<?xml version'; $content = preg_replace($pattern, $replacement, $content, 1); if (strpos($content, '<?xml version') === false) { // look like the content missing the xml header. lets manually add in. $content = '<?xml version="1.0" encoding="utf-8"?>' . $content; } $parser = new SimplePie(); $parser->strip_htmltags(false); $parser->set_raw_data($content); $parser->init(); $items = ''; $items = $parser->get_items(); if (count($items) > 0) { //lets process the data insert $myCnt = 0; foreach ($items as $item) { @ini_set('max_execution_time', 180); if (!empty($maxItems) && $myCnt == $maxItems) { break; } $timezoneSec = $item->get_date('Z'); $itemdate = $item->get_date('U'); $itemdate = $itemdate - $timezoneSec; $mydate = date('Y-m-d H:i:s', $itemdate); $feedUid = $item->get_id(); $feedPath = $item->get_link(); $feedHistory = EasyBlogHelper::getTable('FeedHistory'); $newHistoryId = ''; if ($feedHistory->isExists($feedObj->id, $feedUid)) { continue; } else { //log the feed item so that in future it will not process again. $date = EasyBlogHelper::getDate(); $newHistory = EasyBlogHelper::getTable('FeedHistory'); $newHistory->feed_id = $feedObj->id; $newHistory->uid = $feedUid; $newHistory->created = $date->toMySQL(); $newHistory->store(); $newHistoryId = $newHistory->id; } $blogObj = new stdClass(); // set the default setting from the feed configuration via backend. $blogObj->category_id = $feedObj->item_category; $blogObj->published = $feedObj->item_published; $blogObj->frontpage = $feedObj->item_frontpage; $blogObj->created_by = $feedObj->item_creator; $blogObj->allowcomment = $config->get('main_comment', 1); $blogObj->subscription = $config->get('main_subscription', 1); $blogObj->issitewide = '1'; $text = $item->get_content(); // @rule: Append copyright text $blogObj->copyrights = $params->get('copyrights', ''); if ($feedObj->item_get_fulltext && $isDomSupported) { $feedItemUrl = urldecode($item->get_link()); $fiConnector = new EasyBlogConnectorsHelper(); $fiConnector->addUrl($feedItemUrl); $fiConnector->execute(); $fiContent = $fiConnector->getResult($feedItemUrl); // to ensure the leading no text before the <?xml> tag $pattern = '/(.*?)<html/is'; $replacement = '<html'; $fiContent = preg_replace($pattern, $replacement, $fiContent, 1); if (!empty($fiContent)) { $fiContent = EasyBlogHelper::getHelper('string')->forceUTF8($fiContent); $readability = new Readability($fiContent); $readability->debug = false; $readability->convertLinksToFootnotes = false; $result = $readability->init(); if ($result) { $content = $readability->getContent()->innerHTML; //$content = EasyBlogHelper::getHelper( 'string' )->fixUTF8( $content ); $content = EasyBlogFeedsHelper::tidyContent($content); if (stristr(html_entity_decode($content), '<!DOCTYPE html') === false) { $text = $content; $text = $this->_processRelLinktoAbs($text, $feedPath); } } } } // strip un-allowed html tag. $text = strip_tags($text, $params->get('allowed', $defaultAllowedHTML)); // Append original source link into article if necessary if ($params->get('sourceLinks')) { JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT); $text .= '<div><a href="' . $item->get_link() . '" target="_blank">' . JText::_('COM_EASYBLOG_FEEDS_ORIGINAL_LINK') . '</a></div>'; } if ($feedObj->author) { $feedAuthor = $item->get_author(); if (!empty($feedAuthor)) { $authorName = $feedAuthor->get_name(); $authorEmail = $feedAuthor->get_email(); if (!empty($authorName)) { // Store it as copyright column instead $text .= '<div>' . JText::sprintf('COM_EASYBLOG_FEEDS_ORIGINAL_AUTHOR', $authorName) . '</div>'; } else { if (!empty($authorEmail)) { $authorArr = explode(' ', $authorEmail); if (isset($authorArr[1])) { $authorName = $authorArr[1]; $authorName = str_replace(array('(', ')'), '', $authorName); $text .= '<div>' . JText::sprintf('COM_EASYBLOG_FEEDS_ORIGINAL_AUTHOR', $authorName) . '</div>'; } } } } } if ($feedObj->item_content == 'intro') { $blogObj->intro = $text; } else { $blogObj->content = $text; } $creationDate = $mydate; $blogObj->created = $mydate; $blogObj->modified = $mydate; $blogObj->title = $item->get_title(); if (empty($blogObj->title)) { $blogObj->title = $this->_getTitleFromLink($item->get_link()); } $blogObj->title = EasyBlogStringHelper::unhtmlentities($blogObj->title); $blogObj->permalink = EasyBlogHelper::getPermalink($blogObj->title); $blogObj->publish_up = $mydate; $blogObj->isnew = !$feedObj->item_published ? true : false; $blog = EasyBlogHelper::getTable('blog'); $blog->bind($blogObj); if ($feedObj->item_published) { $blog->notify(); } if ($blog->store()) { $myCnt++; //update the history with blog id if (!empty($newHistoryId)) { $tmpHistory = EasyBlogHelper::getTable('FeedHistory'); $tmpHistory->load($newHistoryId); $tmpHistory->post_id = $blog->id; $tmpHistory->store(); } $itemMigrated++; if ($feedObj->item_published) { //insert activity here. EasyBlogHelper::addJomSocialActivityBlog($blog, true, true); // Determines if admin wants to auto post this item to the social sites. if ($params->get('autopost')) { $allowed = array(EBLOG_OAUTH_LINKEDIN, EBLOG_OAUTH_FACEBOOK, EBLOG_OAUTH_TWITTER); // @rule: Process centralized options first // See if there are any global postings enabled. $blog->autopost($allowed, $allowed); } } } //end if } } return $itemMigrated; }
function customSimplePie() { $simplePie = new SimplePie(); $simplePie->set_useragent(Minz_Translate::t('freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION); $simplePie->set_cache_location(CACHE_PATH); $simplePie->set_cache_duration(1500); $simplePie->strip_htmltags(array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'link', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'plaintext', 'script', 'style')); $simplePie->strip_attributes(array_merge($simplePie->strip_attributes, array('autoplay', 'onload', 'onunload', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove', 'onmouseout', 'onfocus', 'onblur', 'onkeypress', 'onkeydown', 'onkeyup', 'onselect', 'onchange', 'seamless'))); $simplePie->add_attributes(array('img' => array('lazyload' => ''), 'audio' => array('preload' => 'none'), 'iframe' => array('postpone' => '', 'sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('postpone' => '', 'preload' => 'none'))); $simplePie->set_url_replacements(array('a' => 'href', 'area' => 'href', 'audio' => 'src', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'iframe' => 'src', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite', 'source' => 'src', 'track' => 'src', 'video' => array('poster', 'src'))); return $simplePie; }
function WPZOOM_Dashboard() { ?> <div class="table table_news"> <p class="sub">From our Blog</p> <div class="rss-widget"> <?php /** * Get RSS Feed(s) */ $items = get_transient('wpzoom_dashboard_widget_news'); if (!(is_array($items) && count($items))) { include_once ABSPATH . WPINC . '/class-simplepie.php'; $rss = new SimplePie(); $rss->set_timeout(5); $rss->set_feed_url('http://www.wpzoom.com/feed/'); $rss->strip_htmltags(array_merge($rss->strip_htmltags, array('h1', 'a', 'img'))); $rss->enable_cache(false); $rss->init(); $items = $rss->get_items(0, 3); $cached = array(); foreach ($items as $item) { $cached[] = array('url' => $item->get_permalink(), 'title' => $item->get_title(), 'date' => $item->get_date("d M Y"), 'content' => substr(strip_tags($item->get_content()), 0, 128) . "..."); } $items = $cached; set_transient('wpzoom_dashboard_widget_news', $cached, 60 * 60 * 24); } ?> <ul class="news"> <?php if (empty($items)) { echo '<li>No items</li>'; } else { foreach ($items as $item) { ?> <li class="post"> <a href="<?php echo $item['url']; ?> " class="rsswidget"><?php echo $item['title']; ?> </a> <span class="rss-date"><?php echo $item['date']; ?> </span> <div class="rssSummary"><?php echo $item['content']; ?> </div> </li> <?php } } ?> </ul><!-- end of .news --> </div> </div> <div class="table table_theme"> <p class="sub">Latest Theme</p> <div class="theme_thumb"> <?php $lastTheme = get_transient('wpzoom_dashboard_widget_theme'); if (!$lastTheme) { $lastTheme = @file_get_contents('http://www.wpzoom.com/themes/?last-theme=true'); if ($lastTheme) { set_transient('wpzoom_dashboard_widget_theme', $lastTheme, 60 * 60 * 24); } } ?> <?php if ($lastTheme) { echo $lastTheme; } ?> </div> <a href="http://wpzoom.com/themes/" target="_blank" alt="Browse our wide selection of WordPress themes to find the right one for you" class="button">Browse more →</a> </div> <div class="clear"> </div> <?php }
/** * Parses a feed with SimplePie * * @param boolean $stupidly_fast Set fast mode. Best for checks * @param integer $max Limit of items to fetch * @return SimplePie_Item Feed object **/ public static function fetchFeed($url, $stupidly_fast = false, $max = 0) { # SimplePie $cfg = get_option(WPeMatico::OPTION_KEY); if ($cfg['force_mysimplepie']) { include_once dirname(__FILE__) . '/lib/simplepie.inc.php'; } else { if (!class_exists('SimplePie')) { if (is_file(ABSPATH . WPINC . '/class-simplepie.php')) { include_once ABSPATH . WPINC . '/class-simplepie.php'; } else { if (is_file(ABSPATH . 'wp-admin/includes/class-simplepie.php')) { include_once ABSPATH . 'wp-admin/includes/class-simplepie.php'; } else { include_once dirname(__FILE__) . '/lib/simplepie.inc.php'; } } } } $feed = new SimplePie(); $feed->enable_order_by_date(false); $feed->set_feed_url($url); $feed->feed_url = rawurldecode($feed->feed_url); $feed->set_item_limit($max); $feed->set_stupidly_fast($stupidly_fast); if (!$stupidly_fast) { if ($cfg['simplepie_strip_htmltags']) { $strip_htmltags = sanitize_text_field($cfg['strip_htmltags']); $strip_htmltags = isset($strip_htmltags) && empty($strip_htmltags) ? $strip_htmltags = array() : explode(',', $strip_htmltags); $strip_htmltags = array_map('trim', $strip_htmltags); $feed->strip_htmltags($strip_htmltags); $feed->strip_htmltags = $strip_htmltags; } if ($cfg['simplepie_strip_attributes']) { $feed->strip_attributes($cfg['strip_htmlattr']); } } if (has_filter('wpematico_fetchfeed')) { $feed = apply_filters('wpematico_fetchfeed', $feed, $url); } $feed->enable_cache(false); $feed->init(); $feed->handle_content_type(); return $feed; }
echo $rsswidgetheight; ?> px; overflow:scroll;"> <?php if (!is_dir("/tmp/simplepie")) { mkdir("/tmp/simplepie"); mkdir("/tmp/simplepie/cache"); } exec("chmod a+rw /tmp/simplepie/."); exec("chmod a+rw /tmp/simplepie/cache/."); $feed = new SimplePie(); $feed->set_cache_location("/tmp/simplepie/"); $feed->set_feed_url($rss_feed_s); $feed->init(); $feed->handle_content_type(); $feed->strip_htmltags(); $counter = 1; foreach ($feed->get_items() as $item) { echo "<a target='blank' href='" . $item->get_permalink() . "'>" . $item->get_title() . "</a><br />"; $content = $item->get_content(); $content = strip_tags($content); echo textLimit($content, $rsswidgettextlength) . "<br />"; echo "Source: <a target='_blank' href='" . $item->get_permalink() . "'>" . $feed->get_title() . "</a><br />"; $counter++; if ($counter > $max_items) { break; } echo "<hr/>"; } ?> </div>
/** * Processing the parameters into placeholders * @param string $spie snippet parameters * @return array placeholders */ private function _setSimplePieModxPlaceholders($spie) { /** * @link http://github.com/simplepie/simplepie/tree/one-dot-two */ if (!file_exists($spie['simplePieClassFile'])) { return 'File ' . $spie['simplePieClassFile'] . ' does not exist.'; } include_once $spie['simplePieClassFile']; $feed = new SimplePie(); $joinKey = 0; foreach ($spie['setFeedUrl'] as $setFeedUrl) { $feed->set_cache_location($spie['setCacheLocation']); $feed->set_feed_url($setFeedUrl); if (isset($spie['setInputEncoding'])) { $feed->set_input_encoding($spie['setInputEncoding']); } if (isset($spie['setOutputEncoding'])) { $feed->set_output_encoding($spie['setOutputEncoding']); } // if no cURL, try fsockopen if (isset($spie['forceFSockopen'])) { $feed->force_fsockopen(true); } if (isset($spie['enableCache'])) $feed->enable_cache($spie['enableCache']); if (isset($spie['enableOrderByDate'])) $feed->enable_order_by_date($spie['enableOrderByDate']); if (isset($spie['setCacheDuration'])) $feed->set_cache_duration($spie['setCacheDuration']); if (!empty($spie['setFaviconHandler'])) $feed->set_favicon_handler($spie['setFaviconHandler'][0], $spie['setFaviconHandler'][1]); if (!empty($spie['setImageHandler'])) { // handler_image.php?image=67d5fa9a87bad230fb03ea68b9f71090 $feed->set_image_handler($spie['setImageHandler'][0], $spie['setImageHandler'][1]); } // disabled since these are all splitted into a single fetching // it's been used with different way, see below looping // if (isset($spie['setItemLimit'])) // $feed->set_item_limit((int) $spie['setItemLimit']); if (isset($spie['setJavascript'])) $feed->set_javascript($spie['setJavascript']); if (isset($spie['stripAttributes'])) $feed->strip_attributes(array_merge($feed->strip_attributes, $spie['stripAttributes'])); if (isset($spie['stripComments'])) $feed->strip_comments($spie['stripComments']); if (isset($spie['stripHtmlTags'])) $feed->strip_htmltags(array_merge($feed->strip_htmltags, $spie['stripHtmlTags'])); /** * Initiating the Feeding. * This always be placed AFTER all the settings above. */ if (!$feed->init()) { echo $feed->error(); return FALSE; } $countItems = count($feed->get_items()); if (1 > $countItems) { continue; } $feed->handle_content_type(); $countLimit = 0; foreach ($feed->get_items($getItemStart, $getItemEnd) as $item) { if (isset($spie['setItemLimit']) && $spie['setItemLimit'] == $countLimit) continue; $phArray[$joinKey]['favicon'] = $feed->get_favicon(); $phArray[$joinKey]['link'] = $item->get_link(); $phArray[$joinKey]['title'] = $item->get_title(); $phArray[$joinKey]['description'] = $item->get_description(); $phArray[$joinKey]['content'] = $item->get_content(); $phArray[$joinKey]['permalink'] = $item->get_permalink(); $parsedUrl = parse_url($phArray[$joinKey]['permalink']); $implodedParsedUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; $imageLink = $feed->get_image_link() != '' ? $feed->get_image_link() : $implodedParsedUrl; $phArray[$joinKey]['imageLink'] = $imageLink; $phArray[$joinKey]['imageTitle'] = $feed->get_image_title(); $phArray[$joinKey]['imageUrl'] = $feed->get_image_url(); $phArray[$joinKey]['imageWidth'] = $feed->get_image_width(); $phArray[$joinKey]['imageHeight'] = $feed->get_image_height(); $phArray[$joinKey]['date'] = $item->get_date($spie['dateFormat']); $phArray[$joinKey]['localDate'] = $item->get_local_date($spie['localDateFormat']); $phArray[$joinKey]['copyright'] = $item->get_copyright(); $phArray[$joinKey]['latitude'] = $feed->get_latitude(); $phArray[$joinKey]['longitude'] = $feed->get_longitude(); $phArray[$joinKey]['language'] = $feed->get_language(); $phArray[$joinKey]['encoding'] = $feed->get_encoding(); if ($item->get_authors()) { foreach ($item->get_authors() as $authorObject) { $authorName = $authorObject->get_name(); $authorLink = $authorObject->get_link(); $authorEmail = $authorObject->get_email(); } $phArray[$joinKey]['authorName'] = $authorName; $phArray[$joinKey]['authorLink'] = $authorLink; $phArray[$joinKey]['authorEmail'] = $authorEmail; } $category = $item->get_category(); if ($category) { $phArray[$joinKey]['category'] = htmlspecialchars_decode($category->get_label(), ENT_QUOTES); } $contributor = $item->get_contributor(); $phArray[$joinKey]['contributor'] = ''; if ($contributor) { $phArray[$joinKey]['contributor'] = $contributor->get_name(); } if ($feed->get_type() & SIMPLEPIE_TYPE_NONE) { $phArray[$joinKey]['getType'] = 'Unknown'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) { $phArray[$joinKey]['getType'] = 'RSS'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) { $phArray[$joinKey]['getType'] = 'Atom'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ALL) { $phArray[$joinKey]['getType'] = 'Supported'; } // Media from Flickr RSS stream if ($enclosure = $item->get_enclosure()) { $phArray[$joinKey]['itemImageThumbnailUrl'] = $enclosure->get_thumbnail(); $phArray[$joinKey]['itemImageWidth'] = $enclosure->get_width(); $phArray[$joinKey]['itemImageHeight'] = $enclosure->get_height(); } $countLimit++; $joinKey++; } // foreach ($feed->get_items($getItemStart, $getItemEnd) as $item) } // foreach ($spie['setFeedUrl'] as $setFeedUrl) return $this->_filterModxTags($phArray); }
function GetSimplePieContentEntries($feedUrl, $logger, $channel) { //Include the Simple Pie Framework to get and parse feeds $config = \Swiftriver\Core\Setup::Configuration(); $simplePiePath = $config->ModulesDirectory . "/SimplePie/simplepie.inc"; include_once $simplePiePath; //Include the Simple Pie YouTube Framework $simpleTubePiePath = $config->ModulesDirectory . "/SimplePie/simpletube.inc"; include_once $simpleTubePiePath; $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [END: Including the SimplePie module]", \PEAR_LOG_DEBUG); //Construct a new SimplePie Parser $feed = new \SimplePie(); //Get the cache directory $cacheDirectory = $config->CachingDirectory; $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Setting the caching directory to {$cacheDirectory}]", \PEAR_LOG_DEBUG); //Set the caching directory $feed->set_cache_location($cacheDirectory); $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Setting the feed url to {$feedUrl}]", \PEAR_LOG_DEBUG); //Pass the feed URL to the SImplePie object $feed->set_feed_url($feedUrl); $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Initializing the feed]", \PEAR_LOG_DEBUG); //Run the SimplePie $feed->init(); //Strip HTML $feed->strip_htmltags(array('span', 'font', 'style', 'table', 'td', 'tr', 'div', 'p', 'br', 'a')); //Create the Content array $contentItems = array(); $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [START: Parsing feed items]", \PEAR_LOG_DEBUG); $feeditems = $feed->get_items(); if (!$feeditems || $feeditems == null || !is_array($feeditems) || count($feeditems) < 1) { $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [No feeditems recovered from the feed]", \PEAR_LOG_DEBUG); } $lastSuccess = $channel->lastSuccess; //Loop through the Feed Items foreach ($feeditems as $feedItem) { //Extract the date of the content $contentdate = strtotime($feedItem->get_date()); if (isset($lastSuccess) && is_numeric($lastSuccess) && isset($contentdate) && is_numeric($contentdate)) { if ($contentdate < $lastSuccess) { $textContentDate = date("c", $contentdate); $textlastSuccess = date("c", $lastSuccess); $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Skipped feed item as date {$textContentDate} less than last sucessful run ({$textlastSuccess})]", \PEAR_LOG_DEBUG); continue; } } $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Adding feed item]", \PEAR_LOG_DEBUG); //Get source data $source_name = $feedItem->get_author()->name; $source_name = $source_name == null || $source_name == "" ? "Google News Search -" . $this->searchPhrase : $source_name . " @ " . "Google News Search - " . $this->searchPhrase; $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name, $channel->trusted); $source->name = $source_name; $source->email = $feedItem->get_author()->email; $source->parent = $channel->id; $source->type = $channel->type; $source->subType = $channel->subType; //Extract all the relevant feedItem info $title = $feedItem->get_title(); $description = $feedItem->get_description(); $contentLink = $feedItem->get_permalink(); $date = $feedItem->get_date(); //Create a new Content item $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source); //Fill the Content Item $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $title, array($description)); $item->link = $contentLink; $item->date = strtotime($date); //Add the item to the Content array $contentItems[] = $item; } $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [END: Parsing feed items]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::GoogleNewsParser::GetSimplePieContentEntries [Method finished]", \PEAR_LOG_DEBUG); //return the content array return $contentItems; }
/** * _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'); } }
/** * * @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_); }
} if ($rssfeed["cacheoff"]) { // check if cache enabled or not $rssfeed["timeout"] = 0; } if ($rssfeed["timeout"]) { $rss_obj->enable_cache(true); $rss_obj->set_cache_duration($rssfeed["timeout"]); $rss_obj->set_cache_location(PHPWCMS_RSS); } else { $rss_obj->enable_cache(false); } // Remove surrounding DIV $rss_obj->remove_div(true); // Strip all HTML Tags $rss_obj->strip_htmltags(true); // Limit items if ($rssfeed["item"]) { $rss_obj->set_item_limit($rssfeed["item"]); } // Init Feed $rss_obj->init(); if ($rss_obj->data) { // check RSS image if ($rss_obj->get_image_url()) { $rss['temp_feedinfo'] = '<a href="' . ($rss_obj->get_image_link() ? $rss_obj->get_image_link() : $rss_obj->get_permalink()) . '" target="_blank">'; $rss['temp_feedinfo'] .= '<img src="' . $rss_obj->get_image_url() . '" alt="' . $rss_obj->get_image_title() . '" />'; $rss['temp_feedinfo'] .= '</a>'; $rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'IMAGE', $rss['temp_feedinfo']); } else { $rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'IMAGE', '');
/** * Initializes the parser * * @since 1.0 * @access public * @param string * @return */ public function getParser() { static $parsers = array(); if (!isset($parsers[$this->id])) { $connector = FD::get('Connector'); $connector->addUrl($this->url); $connector->connect(); $contents = $connector->getResult($this->url); // Ensure that there are no leading text before the <?xml> tag. $pattern = '/(.*?)<\\?xml version/is'; $replacement = '<?xml version'; $contents = preg_replace($pattern, $replacement, $contents, 1); // If there's no xml text in the contents, we need to add them if (strpos($contents, '<?xml version') === false) { $contents = '<?xml version="1.0" encoding="utf-8"?>' . $contents; } jimport('simplepie.simplepie'); $parser = new SimplePie(); $parser->strip_htmltags(false); $parser->set_raw_data($contents); $parser->init(); $parsers[$this->id] = $parser; } return $parsers[$this->id]; }
function WPZOOM_Dashboard() { ?> <div class="table table_news"> <p class="sub">From our Blog</p> <div class="rss-widget"> <?php /** * Get RSS Feed(s) */ $items = get_transient('wpzoom_dashboard_widget_news'); if (!(is_array($items) && count($items))) { include_once ABSPATH . WPINC . '/class-simplepie.php'; $rss = new SimplePie(); $rss->set_timeout(5); $rss->set_feed_url('http://www.wpzoom.com/feed/'); $rss->strip_htmltags(array_merge($rss->strip_htmltags, array('h1', 'a', 'img'))); $rss->enable_cache(false); $rss->init(); $items = $rss->get_items(0, 3); $cached = array(); foreach ($items as $item) { $cached[] = array('url' => $item->get_permalink(), 'title' => $item->get_title(), 'date' => $item->get_date("d M Y"), 'content' => substr(strip_tags($item->get_content()), 0, 128) . "..."); } $items = $cached; set_transient('wpzoom_dashboard_widget_news', $cached, 60 * 60 * 24); } ?> <ul class="news"> <?php if (empty($items)) { echo '<li>No items</li>'; } else { foreach ($items as $item) { ?> <li class="post"> <a href="<?php echo $item['url']; ?> " class="rsswidget"><?php echo $item['title']; ?> </a> <span class="rss-date"><?php echo $item['date']; ?> </span> <div class="rssSummary"><?php echo $item['content']; ?> </div> </li> <?php } } ?> </ul><!-- end of .news --> </div> </div> <div class="table table_theme"> <p class="sub">Latest Theme</p> <div class="theme_thumb"> <?php $current = get_transient('wpzoom_dashboard_widget_theme'); if (!is_object($current) || !isset($current->data)) { $current = new stdClass(); $current->lastChecked = 0; } $time_changed = 24 * HOUR_IN_SECONDS < time() - $current->lastChecked; if ($time_changed) { $response = wp_remote_get('http://www.wpzoom.com/frame/latest_theme.html'); if (!is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response)) { $current->data = wp_remote_retrieve_body($response); } $current->lastChecked = time(); set_transient('wpzoom_dashboard_widget_theme', $current); } ?> <?php if ($current) { echo $current->data; } ?> </div> <a href="http://wpzoom.com/themes/" target="_blank" alt="Browse our wide selection of WordPress themes to find the right one for you" class="button">Browse more →</a> </div> <div class="clear"> </div> <?php }
/** * Implementation of IParser::GetAndParse * @param \Swiftriver\Core\ObjectModel\Channel $channel * @param datetime $lassucess */ public function GetAndParse($channel) { $logger = \Swiftriver\Core\Setup::GetLogger(); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Method invoked]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [START: Extracting required parameters]", \PEAR_LOG_DEBUG); if ($channel->subType == "Tag Search" || $channel->subType == "Tag Search with Location") { $rawTags = $channel->parameters["tags"]; if (!isset($rawTags) || $rawTags == null) { $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [the parameter 'tags' was not supplied. Returning null]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); return null; } $tags = \explode(" ", $rawTags); $url = $channel->subType == "Tag Search" ? "http://api.flickr.com/services/feeds/photos_public.gne?format=rss2&tags=" : "http://www.flickr.com/services/feeds/geo?format=rss2&tags="; foreach ($tags as $tag) { $url .= "{$tag},"; } $url = \rtrim($url, ","); } elseif ($channel->subType == "Follow a User") { $userid = $channel->parameters["userid"]; if (!isset($userid) || $userid == null) { $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [the parameter 'userid' was not supplied. Returning null]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); return null; } $url = "http://api.flickr.com/services/feeds/photos_public.gne?id={$userid}"; } else { $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [The subType supplied was not recognised]", \PEAR_LOG_ERR); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); return null; } $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [END: Extracting required parameters]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [START: Including the SimplePie module]", \PEAR_LOG_DEBUG); //Include the Simple Pie Framework to get and parse feeds $config = \Swiftriver\Core\Setup::Configuration(); $simplePiePath = $config->ModulesDirectory . "/SimplePie/simplepie.inc"; include_once $simplePiePath; //Include the Simple Pie YouTube Framework $simpleTubePiePath = $config->ModulesDirectory . "/SimplePie/simpletube.inc"; include_once $simpleTubePiePath; $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [END: Including the SimplePie module]", \PEAR_LOG_DEBUG); //Construct a new SimplePie Parser $feed = new \SimplePie(); //Get the cache directory $cacheDirectory = $config->CachingDirectory; $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Setting the caching directory to {$cacheDirectory}]", \PEAR_LOG_DEBUG); //Set the caching directory $feed->set_cache_location($cacheDirectory); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Setting the feed url to {$url}]", \PEAR_LOG_DEBUG); //Pass the feed URL to the SImplePie object $feed->set_feed_url($url); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Initializing the feed]", \PEAR_LOG_DEBUG); //Run the SimplePie $feed->init(); //Strip HTML $feed->strip_htmltags(array('span', 'font', 'style', 'p')); //Create the Content array $contentItems = array(); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [START: Parsing feed items]", \PEAR_LOG_DEBUG); $feeditems = $feed->get_items(); if (!$feeditems || $feeditems == null || !is_array($feeditems) || count($feeditems) < 1) { $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [No feeditems recovered from the feed]", \PEAR_LOG_DEBUG); } $lastSuccess = $channel->lastSuccess; //Loop through the Feed Items foreach ($feeditems as $feedItem) { //Extract the date of the content $contentdate = strtotime($feedItem->get_date()); if (isset($lastSuccess) && is_numeric($lastSuccess) && isset($contentdate) && is_numeric($contentdate)) { if ($contentdate < $lastSuccess) { $textContentDate = date("c", $contentdate); $textlastSuccess = date("c", $lastSuccess); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Skipped feed item as date {$textContentDate} less than last sucessful run ({$textlastSuccess})]", \PEAR_LOG_DEBUG); continue; } } $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Adding feed item]", \PEAR_LOG_DEBUG); //Get source data $source_name = $feedItem->get_author()->name; if (!isset($source_name) || $source_name == null || $source_name == "") { $source_name = "unknown"; } $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name, $channel->trusted); $source->name = $source_name; $source->email = $feedItem->get_author()->email; $source->parent = $channel->id; $source->type = $channel->type; $source->subType = $channel->subType; //Extract all the relevant feedItem info $title = $feedItem->get_title(); $description = $feedItem->get_description(); $contentLink = $feedItem->get_permalink(); $date = $feedItem->get_date(); $rawLocation = $feedItem->get_item_tags("http://www.georss.org/georss", "point"); $long = 0; $lat = 0; $name = ""; if (is_array($rawLocation)) { $lat_lon_array = split(" ", $rawLocation[0]["data"]); $long = $lat_lon_array[1]; $lat = $lat_lon_array[0]; $location = new \Swiftriver\Core\ObjectModel\GisData($long, $lat, $name); } //Create a new Content item $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source); if (isset($location)) { $item->gisData = array($location); } //Fill the Content Item $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $title, array($description)); $item->link = $contentLink; $item->date = strtotime($date); //Add the item to the Content array $contentItems[] = $item; } $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [END: Parsing feed items]", \PEAR_LOG_DEBUG); $logger->log("Core::Modules::SiSPS::Parsers::FlickrParser::GetAndParse [Method finished]", \PEAR_LOG_DEBUG); //return the content array return $contentItems; }
/** * A clone of the function 'fetch_feed' in wp-includes/feed.php [line #529] * * Called from 'wprss_get_feed_items' * * @since 3.5 */ function wprss_fetch_feed($url, $source = NULL) { // Import SimplePie require_once ABSPATH . WPINC . '/class-feed.php'; // Trim the URL $url = trim($url); // Initialize the Feed $feed = new SimplePie(); // Obselete method calls ? //$feed->set_cache_class( 'WP_Feed_Cache' ); //$feed->set_file_class( 'WP_SimplePie_File' ); $feed->set_feed_url($url); $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL); // If a feed source was passed if ($source !== NULL) { // Get the force feed option for the feed source $force_feed = get_post_meta($source, 'wprss_force_feed', TRUE); // If turned on, force the feed if ($force_feed == 'true') { $feed->force_feed(TRUE); } } // Set timeout to 30s. Default: 15s $feed->set_timeout(30); //$feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) ); $feed->enable_cache(FALSE); // Reference array action hook, for the feed object and the URL do_action_ref_array('wp_feed_options', array(&$feed, $url)); // Prepare the tags to strip from the feed $tags_to_strip = apply_filters('wprss_feed_tags_to_strip', $feed->strip_htmltags, $source); // Strip them $feed->strip_htmltags($tags_to_strip); // Fetch the feed $feed->init(); $feed->handle_content_type(); // Convert the feed error into a WP_Error, if applicable if ($feed->error()) { return new WP_Error('simplepie-error', $feed->error()); } // If no error, return the feed return $feed; }
/** * A clone of the function 'fetch_feed' in wp-includes/feed.php [line #529] * * Called from 'wprss_get_feed_items' * * @since 3.5 */ function wprss_fetch_feed($url, $source = NULL, $param_force_feed = FALSE) { // Trim the URL $url = trim($url); // Initialize the Feed $feed = new SimplePie(); // Obselete method calls ? //$feed->set_cache_class( 'WP_Feed_Cache' ); //$feed->set_file_class( 'WP_SimplePie_File' ); $feed->set_feed_url($url); $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL); // If a feed source was passed if ($source !== NULL || $param_force_feed) { // Get the force feed option for the feed source $force_feed = get_post_meta($source, 'wprss_force_feed', TRUE); // If turned on, force the feed if ($force_feed == 'true' || $param_force_feed) { $feed->force_feed(TRUE); } } // Set timeout limit $fetch_time_limit = wprss_get_feed_fetch_time_limit(); $feed->set_timeout($fetch_time_limit); //$feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) ); $feed->enable_cache(FALSE); // Reference array action hook, for the feed object and the URL do_action_ref_array('wp_feed_options', array(&$feed, $url)); // Prepare the tags to strip from the feed $tags_to_strip = apply_filters('wprss_feed_tags_to_strip', $feed->strip_htmltags, $source); // Strip them $feed->strip_htmltags($tags_to_strip); do_action('wprss_fetch_feed_before', $feed); // Fetch the feed $feed->init(); $feed->handle_content_type(); do_action('wprss_fetch_feed_after', $feed); // Convert the feed error into a WP_Error, if applicable if ($feed->error()) { if ($source !== NULL) { $msg = sprintf(__('Failed to fetch the RSS feed. Error: %s', WPRSS_TEXT_DOMAIN), $feed->error()); update_post_meta($source, 'wprss_error_last_import', $msg); } return new WP_Error('simplepie-error', $feed->error()); } // If no error, return the feed and remove any error meta delete_post_meta($source, "wprss_error_last_import"); return $feed; }
function wpss_mrt_meta_box3(){ ?> <div style="padding:10px;"> <div style="font-size:13pt;text-align:center;">Highest</div> <?php // include('WP_PLUGIN_DIR . '/all-in-one-seo-pack/simplepie.inc'); $feed = new SimplePie(); $feed->set_feed_url('feed://donations.semperfiwebdesign.com/category/highest-donations/feed/'); $feed->enable_cache(false); $feed->strip_htmltags(array('p')); // $feed->set_cache_location(WP_PLUGIN_DIR . '/wp-security-scan/'); $feed->init(); $feed->handle_content_type(); ?> <?php if ($feed->data): ?> <?php $items = $feed->get_items(); ?> <?php foreach($items as $item): ?> <p> <strong><?php echo $item->get_title(); ?></strong> <?php echo $item->get_content(); ?> </p> <?php endforeach; ?> </div> <?php endif; ?> <div style="font-size:13pt;text-align:center;">Recent</div> <?php // include(WP_PLUGIN_DIR . '/all-in-one-seo-pack/simplepie.inc'); $feed = new SimplePie(); $feed->set_feed_url('feed://donations.semperfiwebdesign.com/category/wp-security-scan/feed/'); $feed->enable_cache(false); $feed->strip_htmltags(array('p')); // $feed->set_cache_location(WP_PLUGIN_DIR . '/wp-security-scan/'); $feed->init(); $feed->handle_content_type(); ?> <?php if ($feed->data): ?> <?php $items = $feed->get_items(); ?> <?php foreach($items as $item): ?> <p> <strong><?php echo $item->get_title(); ?></strong> <?php echo $item->get_content(); ?> </p> <?php endforeach; ?> </div> <?php endif; ?> <hr width="75%"/> <div style="text-align:center"><em>This plugin is updated as a free service to the WordPress community. Donations of any size are appreciated.</em> <br /><br /> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=mrtorbert%40gmail%2ecom&item_name=Support%20WordPress%20Security%20Scan%20Plugin&no_shipping=0&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8" target="_blank">Click here to support this plugin.</a> </div> <!-- <br /><br /><h4>Highest Donations</h4></div> --> <?php /*$ch = curl_init("http://semperfiwebdesign.com/top_donations.php"); $fp = fopen("top_donations.php", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); */ /* $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://semperfiwebdesign.com/top_donations.php"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); */ ?> <!-- <br /><br /><div style="text-align:center"><h4>Recent Donations</h4></div> --> <?php /* $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://semperfiwebdesign.com/recent_donations.php"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); */ /* $ch = curl_init("http://semperfiwebdesign.com/recent_donations.php"); $fp = fopen("recent_donations.php", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); */ }
function getItemsFromFeeds($rs, $print) { global $blog_settings, $core; $output = ""; $cron_file = dirname(__FILE__) . '/cron_running.txt'; # Duree de mise a jour $debut = explode(" ", microtime()); $debut = $debut[1] + $debut[0]; $cpt = 0; while ($rs->fetch()) { # On verifie si on n'a pas demandé l'arrêt de l'algo if (file_exists(dirname(__FILE__) . '/STOP')) { $log_msg = logMsg(T_("STOP file detected, trying to shut down cron job"), "", 2, $print); if ($print) { $output .= $log_msg; } break; } $log_msg = logMsg(T_("Check feed : ") . $rs->feed_url, "", 0, $print); if ($print) { $output .= $log_msg; } require_once dirname(__FILE__) . '/lib/simplepie_1.3.compiled.php'; # On cree un objet SimplePie et on ajuste les parametres de base $feed = new SimplePie(); $feed->set_feed_url($rs->feed_url); $feed->set_cache_location(dirname(__FILE__) . '/../admin/cache'); #$feed->enable_cache(false); # $feed->set_cache_duration($item_refresh); $feed->init(); # Pour faire fonctionner les lecteurs flash, non recomande par simplepie $feed->strip_htmltags(false); # Si le flux ne contient pas de donnee #$item_nb = $feed->get_item_quantity(); $error = $feed->error(); if (isset($error)) { # Affichage du message d'erreur if (ereg($rs->feed_url, $error)) { $log_msg = logMsg(T_("No feed found : ") . $error, "", 3, $print); } else { $log_msg = logMsg(sprintf(T_("No feed found on %s (owner : %s)"), $rs->feed_url, $rs->user_id) . $error, "", 3, $print); } if ($print) { $output .= $log_msg; } } else { $items = $feed->get_items(); foreach ($items as $item) { #print $item->get_permalink().'<br>'; #continue; # open log file and write activity down $fp = @fopen($cron_file, 'wb'); if ($fp === false) { throw new Exception(sprintf(T_('Cannot write %s file.'), $cron_file)); } fwrite($fp, time()); fclose($fp); # Analyse the item ##################### # Content $item_content = strip_script($item->get_content()); if (empty($item_content)) { $item_content = $item->get_description(); } $item_content = traitementEncodage($item_content); # Title $item_title = traitementEncodage($item->get_title()); if (strlen($item_title) > 254) { $item_title = substr($item_title, 0, 254); } # Permalink $permalink = $item->get_permalink(); $item_image = getFirstPostImageUrl($item->get_content()); # Analyse the possible tags of the item ########################################## # Get tags defined in the database for all posts of that feed $item_tags = array(); # Get the tags on the feed $rs_feed_tag = $core->con->select("SELECT tag_id FROM " . $core->prefix . "feed_tag\r\n\t\t\t\t\tWHERE feed_id = " . $rs->feed_id); while ($rs_feed_tag->fetch()) { $item_tags[] = strtolower($rs_feed_tag->tag_id); } # Get the reserved tags $reserved_tags = array(); $planet_tags = getArrayFromList($blog_settings->get('planet_reserved_tags')); if (is_array($planet_tags)) { foreach ($planet_tags as $tag) { $reserved_tags[] = strtolower($tag); } } # Get tags defined on the item in the feed $categs = $item->get_categories(); if ($categs) { foreach ($categs as $category) { $label = strtolower($category->get_label()); if (!in_array($label, $item_tags) && !in_array($label, $reserved_tags) && !is_int($label) && strlen($label) > 1) { $item_tags[] = $label; } } } # Find hashtags in title $hashtags = array(); preg_match('/#([\\d\\w]+)/', $item->get_title(), $hashtags); foreach ($hashtags as $tag) { $tag = strtolower($tag); if (!in_array($tag, $item_tags) && !in_array($tag, $reserved_tags) && !is_int($tag) && strlen($tag) > 1) { $item_tags[] = $tag; } } # check if some existing tags are in the title foreach (explode(' ', $item_title) as $word) { $word = strtolower($word); $tagRq = $core->con->select('SELECT tag_id FROM ' . $core->prefix . 'post_tag WHERE tag_id = \'' . $word . "'"); if ($tagRq->count() > 1 && !in_array($word, $item_tags) && !in_array($word, $reserved_tags) && !is_int($word) && strlen($word) > 1) { $item_tags[] = $word; } } if (empty($item_content)) { $log_msg = logMsg(sprintf(T_("No content on feed %s"), $rs->feed_url), "", 3, $print); } elseif (empty($permalink)) { $log_msg = logMsg(T_("Error in link cutting : ") . $permalink, "", 3, $print); } else { $log_msg = insertPostToDatabase($rs, $permalink, $item->get_date("U"), $item_title, $item_content, $item_tags, $item_image, $print, $rs->feed_id); $cpt++; } # fin du $item->get_content() if ($print) { $output .= $log_msg; } } # fin du foreach # Le flux a ete mis a jour, on le marque a la derniere date $cur = $core->con->openCursor($core->prefix . 'feed'); $cur->feed_checked = array('NOW()'); $cur->update("WHERE feed_id = '{$rs->feed_id}'"); $log_msg = logMsg(sprintf(T_("The feed %s is updated"), $rs->feed_url), "", 2, $print); if ($print) { $output .= $log_msg; } # On fait un reset du foreach reset($items); } # fin $feed->error() # Destruction de l'objet feed avant de passer a un autre $feed->__destruct(); unset($feed); if ($blog_settings->get('auto_feed_disabling')) { $toolong = time() - 86400 * 7; # seven days ago $check_sql = "SELECT feed_checked FROM " . $core->prefix . "feed WHERE feed_id=" . $rs->feed_id; $rs_check = $core->con->select($check_sql); $last_checked = mysqldatetime_to_timestamp($rs_check->f('feed_checked')); if ($last_checked < $toolong) { $diff = (time() - $last_checked) / 86400; $log_msg = logMsg(sprintf(T_("The feed was not updated since %d days. It'll be disabled : "), $diff) . $rs->feed_url, "", 2, $print); if ($print) { $output .= $log_msg; } # if feed was in error for too long, let's disable it $cur = $core->con->openCursor($core->prefix . 'feed'); $cur->feed_status = 2; $cur->update("WHERE feed_id = '{$rs->feed_id}'"); $from = $blog_settings->get('author_mail'); $to = $from . ',' . $rs->user_email; $reply_to = $from; $subject = sprintf(T_("Due to errors, a feed has been disabled on %s"), $blog_settings->get('planet_title')); $content = sprintf(T_("The feed of %s has been disabled :\n"), $rs->user_fullname); $content .= $rs->feed_url . "\n"; $content .= sprintf(T_("The feed was in error during more than %d days"), $diff); $content .= "\n\n" . T_("Details :"); $content .= "\n" . T_("User id : ") . $rs->user_id; $content .= "\n" . T_("User name : ") . $rs->user_fullname; $content .= "\n" . T_("User email : ") . $rs->user_email; $content .= "\n" . T_("Feed url : ") . $rs->feed_url; $content .= "\n" . T_("Last checked timestamp : ") . $last_checked; $content .= "\n" . T_("Website : ") . $rs->site_url; if (!sendmail($from, $to, $subject, $content, 'normal', $reply_to)) { $log_msg = logMsg(T_("Email alert could not be send")); if ($print) { $output .= $log_msg; } } else { $log_msg = logMsg(T_("Feed disabled and email alert sent !")); if ($print) { $output .= $log_msg; } } } } } # fin du while # Duree de la mise a jour $fin = explode(" ", microtime()); $fin = $fin[1] + $fin[0]; $temps_passe = round($fin - $debut, 2); $log_msg = logMsg("{$cpt} articles mis a jour en {$temps_passe} secondes", "", 2, $print); if ($print) { $output .= $log_msg; } return $output; }
/** * Main method to import the feed items * * @since 4.0 * @access public * @param string * @return */ public function import(EasyBlogTableFeed &$feed, $limit = 0) { // Load site language file EB::loadLanguages(); // Import simplepie library jimport('simplepie.simplepie'); // We need DomDocument to exist if (!class_exists('DomDocument')) { return false; } // Set the maximum execution time to a higher value @ini_set('max_execution_time', 720); // Get the feed params $params = EB::registry($feed->params); // Determines the limit of items to fetch $limit = $limit ? $limit : $params->get('feedamount', 0); // Setup the outgoing connection to the feed source $connector = EB::connector(); $connector->addUrl($feed->url); $connector->execute(); // Get the contents $contents = $connector->getResult($feed->url); // If contents is empty, we know something failed if (!$contents) { return EB::exception(JText::sprintf('COM_EASYBLOG_FEEDS_UNABLE_TO_REACH_TARGET_URL', $feed->url), EASYBLOG_MSG_ERROR); } // Get the cleaner to clean things up $cleaner = $this->getAdapter('Cleaner'); $contents = $cleaner->cleanup($contents); // Load up the xml parser $parser = new SimplePie(); $parser->strip_htmltags(false); $parser->set_raw_data($contents); @$parser->init(); // Get a list of items // We need to supress errors here because simplepie will throw errors on STRICT mode. $items = @$parser->get_items(); if (!$items) { // TODO: Language string return EB::exception('COM_EASYBLOG_FEEDS_NOTHING_TO_BE_IMPORTED_CURRENTLY', EASYBLOG_MSG_ERROR); } // Get the feeds model $model = EB::model('Feeds'); // Determines the total number of items migrated $total = 0; foreach ($items as $item) { // If it reaches limit, skip processing if ($limit && $total == $limit) { break; } // Get the item's unique id $uid = @$item->get_id(); // If item already exists, skip this if ($model->isFeedItemImported($feed->id, $uid)) { continue; } // Log down a new history record to avoid fetching of the same item again $history = EB::table('FeedHistory'); $history->feed_id = $feed->id; $history->uid = $uid; $history->created = EB::date()->toSql(); $history->store(); // Get the item's link $link = @$item->get_link(); // Load up the post library $post = EB::post(); $createOption = array('overrideDoctType' => 'legacy', 'checkAcl' => false, 'overrideAuthorId' => $feed->item_creator); $post->create($createOption); // Pass this to the adapter to map the items $mapper = $this->getAdapter('Mapper'); $mapper->map($post, $item, $feed, $params); // Now we need to get the content of the blog post $mapper->mapContent($post, $item, $feed, $params); $saveOptions = array('applyDateOffset' => false, 'validateData' => false, 'useAuthorAsRevisionOwner' => true, 'checkAcl' => false, 'overrideAuthorId' => $feed->item_creator); // Try to save the blog post now try { $post->save($saveOptions); // Update the history table $history->post_id = $post->id; $history->store(); $total++; } catch (EasyBlogException $exception) { // do nothing. } } return EB::exception(JText::sprintf('COM_EASYBLOG_FEEDS_POSTS_MIGRATED_FROM_FEED', $total, $feed->url), EASYBLOG_MSG_SUCCESS); }
function feeds($id) { $app = Slim::getInstance(); $app->view()->setData('id_feed_atual', $id); if (!is_numeric($id)) { $errors = "A página não existe"; $app->flash('errors', $errors); $app->redirect(URL_BASE . '/'); exit; } $feeds = new Crud(); $feeds->setTabela('feeds'); $user = $app->view()->getData('user'); $l = $feeds->consultar(array('nome', 'url', 'publico', 'id_categoria'), 'id_user ='******'id'] . ' AND id =' . $id)->fetchAll(PDO::FETCH_ASSOC); if (count($l) > 0) { $read = new SimplePie(); $read->enable_cache(false); $read->set_feed_url($l[0]['url']); $read->set_url_replacements(array('a' => 'href', 'img' => 'src')); $read->strip_htmltags(array('a')); $read->init(); $read->handle_content_type(); $app->render('home.php', array('rss' => $read->get_items(), 'nome' => $l[0]['nome'])); } else { echo "Esta página não existe"; } }