encode_instead_of_strip() публичный Метод

public encode_instead_of_strip ( $enable = true )
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')) . ' &rarr;</a></p>
	</div>' . "\n";
    }
    $output .= "</div>\n";
    $output .= "<!-- End Social Media Mashup plugin -->\n";
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
Пример #2
0
    /**
     * Display BNM goodies in the sidebar
     *
     * @since 1.0
     */
    public function sidebar()
    {
        echo '<div id="side-info-column" class="inner-sidebar" style="width: 25%;">';
        /* Instructions
        		========================================================*/
        echo '<div class="postbox">
				<h3 class="hndle">' . __('How to Use', BNM_LOCALE) . '</h3>
				<div class="inside">';
        echo '<h4>' . __('Shortcode', BNM_LOCALE) . '</h4>
		<p>' . __('To insert a mashup into any post or page, use this shortcode in the content area:', BNM_LOCALE) . '</p>
		<pre class="smm-pre">[social-media-mashup count="5"]</pre>
		<p>' . sprintf(__('Change %s to customize the number of items displayed.', BNM_LOCALE), '<code>count</code>') . '</p>
		<h4>' . __('Template Tag', BNM_LOCALE) . '</h4>
		<p>' . __('Insert this code into your theme to display a mashup:', BNM_LOCALE) . '</p>' . "<pre class='smm-pre'>&lt;?php\nif (function_exists('social_media_mashup'))\n\tsocial_media_mashup(5);\n?&gt;</pre>" . '<p>' . sprintf(__('Change %s to customize the number of items displayed.', BNM_LOCALE), '<code>5</code>') . '</p>';
        echo '</div>
			</div>';
        /* About BNM
        		========================================================*/
        echo '<div class="postbox">
				<h3 class="hndle">' . sprintf(__('About %s', BNM_LOCALE), 'Brave New Media') . '</h3>
				<div class="inside">';
        echo '<p>' . sprintf(__('Based in Minneapolis, %s is a content development and management company founded in 1998. Rooted in design and video and around since the inception of the internet, %s works with local, national and international companies in creating compelling stories that support their brands in all digital media.', BNM_LOCALE), 'Brave New Media', 'Brave New Media') . '</p>
		<p><a href="http://bravenewmedia.net/" target="_blank" class="button">' . __('Visit Our Website', BNM_LOCALE) . '</a>
		<a href="http://bnm.zendesk.com/" target="_blank" class="button">' . __('Get Support', BNM_LOCALE) . '</a></p>';
        echo '</div>
			</div>';
        /* BNM Blog
        		========================================================*/
        echo '<div class="postbox">
				<h3 class="hndle">' . sprintf(__('The %s Blog', BNM_LOCALE), 'Brave New Media') . '</h3>
				<div class="inside">';
        if (!class_exists('SimplePie')) {
            require_once SMM_DIR . '/simplepie.inc';
        }
        $feed = new SimplePie();
        $feed->set_feed_url('http://blog.bravenewmedia.net/feed/');
        date_default_timezone_set(get_option('America/Chicago'));
        $feed->encode_instead_of_strip(false);
        $feed->enable_cache(false);
        $feed->set_cache_location(SMM_DIR . '/cache');
        $feed->init();
        $feed->handle_content_type();
        echo '<div class="rss-widget"><ul>';
        foreach ($feed->get_items(0, 3) as $item) {
            echo '<li><a class="rsswidget" href="' . $item->get_permalink() . '" target="_blank">' . $item->get_title() . '</a> <span class="rss-date">' . $item->get_date('F j, Y') . '</span></li>';
        }
        echo '</ul></div>';
        echo '</div>
			</div>';
        /* Credits
        		========================================================*/
        echo '<div class="postbox credits">
				<h3 class="hndle">' . __('Credits', BNM_LOCALE) . '</h3>
				<div class="inside">';
        echo '<ul>
			<li>' . __('Author:', BNM_LOCALE) . ' <a href="http://profiles.wordpress.org/users/bravenewmedia/" target="_blank">bravenewmedia</a></li>
			<li>' . __('Contributor:', BNM_LOCALE) . ' <a href="http://profiles.wordpress.org/users/aliso/" target="_blank">aliso</a></li>
		</ul>
		
		<h4>' . __('Special Thanks', BNM_LOCALE) . '</h4>
		<ul>
			<li>' . sprintf(__('Icons by %s', BNM_LOCALE), '<a href="http://picons.me/" target="_blank">Picons.me</a>') . '</li>
			<li>' . sprintf(__('Icons by %s', BNM_LOCALE), '<a href="http://www.fasticon.com/" target="_blank">FastIcon.com</a>') . '</li>
			<li>' . sprintf(__('Icons by %s', BNM_LOCALE), '<a href="http://www.komodomedia.com/blog/2008/12/social-media-mini-iconpack/">Komodo Media</a>') . '</li>
			<li>' . sprintf(__('Settings API class by %s', BNM_LOCALE), '<a href="http://alisothegeek.com/2011/01/wordpress-settings-api-tutorial-1/" target="_blank">Aliso the Geek</a>') . '</li>
			<li>' . sprintf(__('RSS feed mashing by %s', BNM_LOCALE), '<a href="http://simplepie.org/" target="_blank">SimplePie</a>') . '</li>
		</ul>';
        echo '</div>
			</div>';
        /* That's it!
        		========================================================*/
        echo '</div>';
    }