/** * _displayRSS * * @param string $url * @param int $num_items */ protected function _displayRSS($url, $num_items = -1) { $rss = new SimplePie(); $rss->strip_htmltags(array_diff($rss->strip_htmltags, array('style'))); $rss->strip_attributes(array_diff($rss->strip_attributes, array('style', 'class', 'id'))); $rss->set_feed_url($url); $rss->set_cache_class('WP_Feed_Cache'); $rss->set_file_class('WP_SimplePie_File'); $rss->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200, $url)); do_action_ref_array('wp_feed_options', array(&$rss, $url)); $rss->init(); $rss->handle_content_type(); if (!$rss->error()) { $maxitems = $rss->get_item_quantity(25); $rss_items = $rss->get_items(0, $maxitems); echo '<ul>'; if ($num_items !== -1) { $rss_items = array_slice($rss_items, 0, $num_items); } if ($rss_items) { foreach ((array) $rss_items as $item) { printf('<li><div class="date">%4$s</div><div class="thethefly-news-item">%2$s</div></li>', esc_url($item->get_permalink()), $item->get_description(), esc_html($item->get_title()), $item->get_date('D, d M Y')); } } else { echo "<li>"; _e('Unfortunately the news channel is temporarily closed', 'thethe-captcha'); echo "</li>"; } echo '</ul>'; } else { _e('An error has occurred, which probably means the feed is down. Try again later.', 'thethe-captcha'); } }
function 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; }
/** * 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; }
/** * 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; }
/** * Reads in the pages RSS feed as determined by the settings * and adds/updates/deletes based on that feed, also sets * the external source for the item so that it doesn't get deleted * or edited by the user. The page content can then be placed * within other pages using the ikit page shortcode. */ function ikit_national_remote_fetch_page() { $page_feed_url = IKIT_NATIONAL_FEED_PAGE_URL; // Use SimplePie to parse the feeds // note that we turn off cacheing, because this fetch // is called at the proper interval and should always // be freshest $feed = new SimplePie(); $feed->set_feed_url($page_feed_url); $feed->enable_cache(false); $feed->strip_attributes(false); $feed->init(); $feed->handle_content_type(); $feed_page_slugs = array(); foreach ($feed->get_items() as $item) { $page_title = $item->get_title(); $page_description = $item->get_description(); // Extract the slug $page_slug_el = $item->get_item_tags(IKIT_XML_NAMESPACE_URI, 'pageSlug'); $page_slug = $page_slug_el[0]['data']; $feed_page_slugs[$page_slug] = true; // Add or update existing sponsor $associated_post = array('post_title' => $page_title, 'post_name' => $page_slug, 'post_type' => 'page', 'post_status' => 'publish', 'post_content' => $page_description); $existing_associated_post = ikit_get_post_by_slug($page_slug, 'page'); if ($existing_associated_post == null) { $new_associated_post_id = wp_insert_post($associated_post); if ($new_associated_post_id > 0) { // Add custom fields add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, IKIT_EXTERNAL_SOURCE_NATIONAL, true); } } else { $associated_post['ID'] = $existing_associated_post->ID; $updated_associated_post_id = wp_update_post($associated_post); if ($updated_associated_post_id > 0) { ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, IKIT_EXTERNAL_SOURCE_NATIONAL, true); } } } if (count($feed_page_slugs) > 0 && count($feed->get_items()) == count($feed_page_slugs)) { // Safety check to not just delete randomly, should be at least one page in the feed // Delete any non-existing sponsors marked with same external source $args = array('post_type' => 'page', 'meta_key' => IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, 'meta_value' => IKIT_EXTERNAL_SOURCE_NATIONAL); $pages = get_posts($args); foreach ($pages as $page) { if (array_key_exists($page->post_name, $feed_page_slugs) == false) { // Delete wp_delete_post($page->ID, true); } } } }
/** * * @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_); }
private function GetRssItems($isPreview, $text) { // Make sure we have the cache location configured $file = new File($this->db); File::EnsureLibraryExists(); // Make sure we have a $media/$layout object to use $media = new Media(); $layout = new Layout(); // Parse the text template $matches = ''; preg_match_all('/\\[.*?\\]/', $text, $matches); Debug::LogEntry('audit', 'Loading SimplePie to handle RSS parsing.' . urldecode($this->GetOption('uri'))); // Use SimplePie to get the feed include_once '3rdparty/simplepie/autoloader.php'; $feed = new SimplePie(); $feed->set_cache_location($file->GetLibraryCacheUri()); $feed->set_feed_url(urldecode($this->GetOption('uri'))); $feed->force_feed(true); $feed->set_cache_duration($this->GetOption('updateInterval', 3600) * 60); $feed->handle_content_type(); // Get a list of allowed attributes if ($this->GetOption('allowedAttributes') != '') { $attrsStrip = array_diff($feed->strip_attributes, explode(',', $this->GetOption('allowedAttributes'))); //Debug::Audit(var_export($attrsStrip, true)); $feed->strip_attributes($attrsStrip); } // Disable date sorting? if ($this->GetOption('disableDateSort') == 1) { $feed->enable_order_by_date(false); } // Init $feed->init(); $dateFormat = $this->GetOption('dateFormat'); if ($feed->error()) { Debug::LogEntry('audit', 'Feed Error: ' . $feed->error()); return array(); } // Set an expiry time for the media $expires = time() + $this->GetOption('updateInterval', 3600) * 60; // Store our formatted items $items = array(); foreach ($feed->get_items() as $item) { /* @var SimplePie_Item $item */ // Substitute for all matches in the template $rowString = $text; // Substitute foreach ($matches[0] as $sub) { $replace = ''; // Pick the appropriate column out if (strstr($sub, '|') !== false) { // Use the provided name space to extract a tag $attribs = NULL; if (substr_count($sub, '|') > 1) { list($tag, $namespace, $attribs) = explode('|', $sub); } else { list($tag, $namespace) = explode('|', $sub); } // What are we looking at Debug::Audit('Namespace: ' . str_replace(']', '', $namespace) . '. Tag: ' . str_replace('[', '', $tag) . '. '); // Are we an image place holder? if (strstr($namespace, 'image') != false) { // Try to get a link for the image $link = null; switch (str_replace('[', '', $tag)) { case 'Link': if ($enclosure = $item->get_enclosure()) { // Use the link to get the image $link = $enclosure->get_link(); } break; default: // Default behaviour just tries to get the content from the tag provided (without a name space). $tags = $item->get_item_tags('', str_replace('[', '', $tag)); if ($tags != null) { $link = is_array($tags) ? $tags[0]['data'] : ''; } } if ($link == NULL) { $dom = new DOMDocument(); $dom->loadHTML($item->get_content()); // Full $images = $dom->getElementsByTagName('img'); foreach ($images as $key => $value) { if ($key == 0) { $link = html_entity_decode($images->item($key)->getAttribute('src')); } } } if ($link == NULL) { $dom = new DOMDocument(); $dom->loadHTML($item->get_description()); //Summary $images = $dom->getElementsByTagName('img'); foreach ($images as $key => $value) { if ($key == 0) { $link = html_entity_decode($images->item($key)->getAttribute('src')); } } } // If we have managed to resolve a link, download it and replace the tag with the downloaded // image url if ($link != NULL) { // Grab the profile image $file = $media->addModuleFileFromUrl($link, 'ticker_' . md5($this->GetOption('url') . $link), $expires); // Tag this layout with this file $layout->AddLk($this->layoutid, 'module', $file['mediaId']); $replace = $isPreview ? '<img src="index.php?p=module&mod=image&q=Exec&method=GetResource&mediaid=' . $file['mediaId'] . '" ' . $attribs . '/>' : '<img src="' . $file['storedAs'] . '" ' . $attribs . ' />'; } } else { $tags = $item->get_item_tags(str_replace(']', '', $namespace), str_replace('[', '', $tag)); Debug::LogEntry('audit', 'Tags:' . var_export($tags, true)); // If we find some tags then do the business with them if ($tags != NULL) { if ($attribs != NULL) { $replace = is_array($tags) ? $tags[0]['attribs'][''][str_replace(']', '', $attribs)] : ''; } else { $replace = is_array($tags) ? $tags[0]['data'] : ''; } } } } else { // Use the pool of standard tags switch ($sub) { case '[Name]': $replace = $this->GetOption('name'); break; case '[Title]': $replace = $item->get_title(); break; case '[Description]': $replace = $item->get_description(); break; case '[Content]': $replace = $item->get_content(); break; case '[Copyright]': $replace = $item->get_copyright(); break; case '[Date]': $replace = DateManager::getLocalDate($item->get_date('U'), $dateFormat); break; case '[PermaLink]': $replace = $item->get_permalink(); break; case '[Link]': $replace = $item->get_link(); break; } if ($this->GetOption('stripTags') != '') { require_once '3rdparty/htmlpurifier/library/HTMLPurifier.auto.php'; $config = HTMLPurifier_Config::createDefault(); $config->set('HTML.ForbiddenElements', array_merge($feed->strip_htmltags, explode(',', $this->GetOption('stripTags')))); $purifier = new HTMLPurifier($config); $replace = $purifier->purify($replace); } } // Substitute the replacement we have found (it might be '') $rowString = str_replace($sub, $replace, $rowString); } $items[] = $rowString; } // Copyright information? if ($this->GetOption('copyright', '') != '') { $items[] = '<span id="copyright">' . $this->GetOption('copyright') . '</span>'; } // Return the formatted items return $items; }
/** * 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); }
} else { if ($newsType == 'entertainment') { // Entertainment $feed = new SimplePie(); $feed->set_feed_url(array('http://www.eonline.com/syndication/feeds/rssfeeds/topstories.xml', 'http://rss.news.yahoo.com/rss/entertainment', 'http://rss.news.yahoo.com/rss/fashion', 'http://feeds.digg.com/digg/container/entertainment/popular.rss', 'http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&topic=e&output=rss', 'http://rss.ew.com/web/ew/rss/todayslatest/index.xml', 'http://www.tmz.com/rss.xml')); $feed->set_stupidly_fast(true); $feed->set_cache_location('./cache'); $feed->set_cache_duration(900); // $feed->strip_htmltags(array_merge($feed->strip_htmltags, array('center')); $feed->strip_attributes(array_merge($feed->strip_attributes, array('border'))); $feed->enable_order_by_date(true); $feed->init(); $plug = 'Entertainment'; } else { // Regular News $feed = new SimplePie(); $feed->set_feed_url(array('http://feeds.reuters.com/reuters/topNews', 'http://rss.cnn.com/rss/cnn_topstories.rss', 'http://online.wsj.com/xml/rss/3_7011.xml', 'http://feeds.digg.com/digg/popular.rss', 'http://www.businessweek.com/rss/bwdaily.rss', 'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml', 'http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss')); $feed->set_stupidly_fast(true); $feed->set_cache_location('./cache'); $feed->set_cache_duration(900); // $feed->strip_htmltags(array_merge($feed->strip_htmltags, array('center')); $feed->strip_attributes(array_merge($feed->strip_attributes, array('border'))); $feed->enable_order_by_date(true); $feed->init(); $plug = 'News'; } } } } } $feed->handle_content_type();
<div class="col-sm-5" id="home-outputs"> <h2 class="home-list-cat-name"><a href="http://www.apn-gcr.org/resources/items/browse?collection=2"><?php _e('Updates from E-Lib', 'APN2015'); ?> </a></h2> <ul class="home-list-ul"> <?php $feed = new SimplePie(); $feed->set_feed_url('http://www.apn-gcr.org/resources/items?output=atom&sort_field=modified&sort_dir=d'); $feed->strip_attributes(false); $success = $feed->init(); $feed->handle_content_type(); if ($success) { foreach ($feed->get_items(0, 3) as $item) { ?> <li class="home-list-li"> <div class="home-list-meta"> <?php $content = $item->get_content(); $html = str_get_html($content); $section_pj_ref = $html->find('#project-item-type-metadata-project-reference-nos', 0); //get the last line of Project Reference Number if exists if (strlen($section_pj_ref) > 0) { $pj_ref = $section_pj_ref->children(1)->innertext; $pos = strripos($pj_ref, '<br>') ? strripos($pj_ref, '<br>') + 4 : 0; $pj_ref = substr($pj_ref, $pos); ?> <span class="entry-meta-heavy"><i class="glyphicon glyphicon-book"> </i> <?php echo $pj_ref; ?> </span>