function social_media_mashup($count = null, $echo = true)
{
$output = "\n<!-- Social Media Mashup plugin by Brave New Media -->\n";
$output .= '<div class="social-media-mashup icons-' . smm_option('show_icons') . '">' . "\n";
if (!$count) {
$count = 5;
}
// The $feeds array is what we pass to SimplePie - an array of feed URLs
$feeds = array();
$feed_keys = array('twitter', 'facebook', 'google', 'flickr', 'youtube', 'rss1', 'rss2', 'rss3');
// Check which feeds are specified
foreach ($feed_keys as $key) {
if (smm_option($key) != '') {
$feeds[] = smm_feed_url($key);
}
}
// Include this site's posts if option is set in the admin
if (smm_option('blog')) {
$feeds[] = get_bloginfo('rss2_url');
}
// SimplePie magic starts here.
if (!class_exists('SimplePie')) {
require_once SMM_DIR . '/simplepie.inc';
}
$feed = new SimplePie();
$feed->set_feed_url($feeds);
// Make sure feeds are getting local timestamps
if (get_option('timezone_string') && strpos(get_option('timezone_string'), 'UTC') === false) {
date_default_timezone_set(get_option('timezone_string'));
}
// Encode HTML tags instead of stripping them.
$feed->encode_instead_of_strip(false);
// If a cache time is set in the admin AND the "smm-cache" folder is writeable,
// set up the cache.
if ((int) smm_option('cache_time') > 0 && is_writable(SMM_DIR . '/smm-cache')) {
$feed->enable_cache(true);
$feed->set_cache_duration((int) smm_option('cache_time') * 60);
$feed->set_cache_location(SMM_DIR . '/smm-cache');
$output .= "\t<!-- Social Media Mashup cache is enabled. Duration: " . smm_option('cache_time') . " minutes -->\n";
} else {
$feed->enable_cache(false);
$output .= "\t<!-- Social Media Mashup cache is disabled. -->\n";
}
// Start SimplePie's engines.
$feed->init();
$feed->handle_content_type();
// Loop through the items in the combined feed
foreach ($feed->get_items(0, $count) as $item) {
// Make links out of URLs in the text
$final = preg_replace('/\\s(http:\\/\\/[^\\s]+)/', ' <a href="$1">$1</a>', $item->get_description());
// If the description is blank, use the title
if ($final == '') {
$final = preg_replace('/\\s(http:\\/\\/[^\\s]+)/', ' <a href="$1">$1</a>', $item->get_title());
// Some items have embeddable media - that usually comes with a thumbnail.
// In the case of custom YouTube feeds, there's no formatted description
// like in a "user uploads" YouTube feed.
$enclosure = $item->get_enclosure();
if ($enclosure != '') {
$final .= '<br /><a href="' . $item->get_permalink() . '"><img src="' . $enclosure->get_thumbnail() . '" /></a>';
}
}
// Facebook adds <br/> tags up the wazoo. This makes it a little better.
$final = str_replace(array('<br/><br/>', '<br><br>', '<br /><br />'), '</p><p>', $final);
$final = str_replace(array('<br/>', '<br>', '<br />'), '</p><p>', $final);
$item_class = smm_feed_class($item->get_feed()->get_permalink());
if ($item_class == 'twitter') {
// Remove "Username: "******"http://twitter.com/$1">@$1</a>', $final);
// Add links to all hash tags
$final = preg_replace('/#([^\\s]+)/', '<a href="http://twitter.com/search/%23$1">#$1</a>', $final);
// I <3 Regular Expressions.
}
// Decide whether to show the feed source. If someone enters a YouTube feed in one of
// the custom RSS fields, it needs to show the YouTube icon ($item_class = 'youtube custom')
// but still show the feed source if "RSS feeds only" is selected in the admin.
$source = '';
if (smm_option('show_source') == 'all' || smm_option('show_source') == 'rss' && in_array($item_class, array('rss', 'youtube custom'))) {
$source = $item->get_feed()->get_title() . ' <span class="sep">|</span> ';
}
// Make this entry consistent with the site's text formatting
$final = apply_filters('the_content', $final);
// Engage!
$output .= "\n\t" . '<div class="smm-item smm-' . $item_class . '">
' . $final . '
<p class="entry-meta">' . $source . '<a href="' . $item->get_permalink() . '">' . smm_friendly_date($item->get_date('c')) . ' →</a></p>
</div>' . "\n";
}
$output .= "</div>\n";
$output .= "<!-- End Social Media Mashup plugin -->\n";
if ($echo) {
echo $output;
} else {
return $output;
}
}