Ejemplo n.º 1
0
    public function output($atts = array())
    {
        $opts = rfbp_get_settings();
        $posts = $this->get_posts();
        if (isset($atts['show_link'])) {
            $atts['show_page_link'] = $atts['show_link'];
        }
        extract(shortcode_atts(array('number' => '5', 'likes' => 1, 'comments' => 1, 'excerpt_length' => 140, 'el' => 'div', 'origin' => 'shortcode', 'show_page_link' => false, 'show_link_previews' => $opts['load_css']), $atts));
        ob_start();
        ?>
		<!-- Recent Facebook Posts v<?php 
        echo RFBP_VERSION;
        ?>
 - http://wordpress.org/plugins/recent-facebook-posts/ -->
		<div class="recent-facebook-posts rfbp rfbp-container rfbp-<?php 
        echo $origin;
        ?>
">
			<?php 
        if ($posts && !empty($posts)) {
            if ($el == 'li') {
                echo '<ul class="rfbp-posts-wrap">';
            }
            $posts = array_slice($posts, 0, $number);
            $link_target = $opts['link_new_window'] ? "_blank" : '';
            foreach ($posts as $p) {
                $content = utf8_decode($p['content']);
                $shortened = false;
                if (strlen($content) > $excerpt_length) {
                    $limit = strpos($content, ' ', $excerpt_length);
                    if ($limit) {
                        $content = substr($content, 0, $limit);
                        $shortened = true;
                    }
                }
                ?>

					<<?php 
                echo $el;
                ?>
 class="rfbp-post">
					<div class="rfbp-text">

						<?php 
                $content = make_clickable($content, $link_target);
                $content = $shortened ? $content . apply_filters('rfbp_read_more', '..', $p['url']) : $content;
                $content = apply_filters('rfbp_content', $content, $p['url']);
                echo $content;
                ?>

					</div>

					<?php 
                if ($show_link_previews && isset($p['link_url']) && !empty($p['link_url']) && !empty($p['link_name'])) {
                    ?>

					<p class="rfbp-link-wrap">
						<a class="rfbp-link" href="<?php 
                    echo $p['link_url'];
                    ?>
" rel="external nofollow" target="<?php 
                    echo $link_target;
                    ?>
">
							<?php 
                    if (!empty($p['link_image']) && apply_filters('rfbp_show_link_images', true) !== false) {
                        ?>
							<span class="rfbp-link-image-wrap">
								<img class="rfbp-link-image" src="<?php 
                        echo esc_attr($p['link_image']);
                        ?>
" width="114" />
							</span>
							<?php 
                    }
                    ?>

							<span class="rfbp-link-text-wrap">
								<span class="rfbp-link-name"><?php 
                    echo $p['link_name'];
                    ?>
</span>
								<?php 
                    if (isset($p['link_caption'])) {
                        ?>
<span class="rfbp-link-caption"><?php 
                        echo $p['link_caption'];
                        ?>
</span><?php 
                    }
                    ?>
								<?php 
                    if (isset($p['link_description']) && !empty($p['link_description'])) {
                        ?>
<span class="rfbp-link-description"><?php 
                        echo $p['link_description'];
                        ?>
</span><?php 
                    }
                    ?>
							</span>
						</a>
					</p>

					<?php 
                }
                ?>

					<?php 
                if ($opts['img_size'] != 'dont_show' && isset($p['image']) && !empty($p['image'])) {
                    ?>
					<p class="rfbp-image-wrap">
						<a class="rfbp-image-link" target="<?php 
                    echo $link_target;
                    ?>
" href="<?php 
                    echo $p['url'];
                    ?>
" rel="external nofollow">
							<?php 
                    $max_img_width = !empty($opts['img_width']) ? $opts['img_width'] . 'px' : '100%';
                    $max_img_height = !empty($opts['img_height']) ? $opts['img_height'] . 'px' : 'none';
                    ?>
							<img class="rfbp-image" src="<?php 
                    echo esc_attr($p['image'] . '?type=' . $opts['img_size']);
                    ?>
" style="max-width: <?php 
                    echo $max_img_width;
                    ?>
; max-height: <?php 
                    echo $max_img_height;
                    ?>
" alt="" />
						</a>
					</p>
					<?php 
                }
                ?>
					<p class="rfbp-post-link-wrap">
						<a target="<?php 
                echo $link_target;
                ?>
" class="rfbp-post-link" href="<?php 
                echo $p['url'];
                ?>
" rel="external nofolloW">
							<?php 
                if ($likes) {
                    ?>
<span class="rfbp-like-count"><?php 
                    echo $p['like_count'];
                    ?>
 <span><?php 
                    _e("likes", 'recent-facebook-posts');
                    if ($comments) {
                        ?>
, <?php 
                    }
                    ?>
</span></span><?php 
                }
                ?>
							<?php 
                if ($comments) {
                    ?>
<span class="rfbp-comment-count"><?php 
                    echo $p['comment_count'];
                    ?>
 <span><?php 
                    _e("comments", 'recent-facebook-posts');
                    ?>
</span></span><?php 
                }
                ?>
							<?php 
                if ($likes || $comments) {
                    ?>
 &sdot; <?php 
                }
                ?>
							<span class="rfbp-timestamp" title="<?php 
                printf(__('%1$s at %2$s', 'recent-facebook-posts'), date('l, F j, Y', $p['timestamp']), date('G:i', $p['timestamp']));
                ?>
"><?php 
                echo rfbp_time_ago($p['timestamp']);
                ?>
</span>
						</a>
					</p>
					</<?php 
                echo $el;
                ?>
>
				<?php 
            }
            // end foreach $posts
            if ($el == 'li') {
                echo '</ul>';
            }
        } else {
            ?>
<p><?php 
            _e("No recent Facebook posts to show", 'recent-facebook-posts');
            ?>
</p><?php 
            if (current_user_can('manage_options')) {
                ?>
<p><strong><?php 
                _e("Admins only notice", 'recent-facebook-posts');
                ?>
:</strong> Did you <a href="<?php 
                echo admin_url('options-general.php?page=rfbp');
                ?>
">configure the plugin</a> properly?</p><?php 
            }
        }
        ?>

			<?php 
        if ($show_page_link) {
            ?>
				<p class="rfbp-page-link-wrap"><a class="rfbp-page-link" href="http://www.facebook.com/<?php 
            echo $opts['fb_id'];
            ?>
/" rel="external nofollow" target="<?php 
            echo $link_target;
            ?>
"><?php 
            echo $opts['page_link_text'];
            ?>
</a></p>
			<?php 
        }
        ?>

			</div>
			<!-- / Recent Facebook Posts -->
			<?php 
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }
Ejemplo n.º 2
0
    /**
     * Outputs the HTML with the facebook posts
     *
     * @param array $atts
     *
     * @return string
     */
    public function output($atts = array())
    {
        $opts = $this->options;
        $posts = $this->get_posts();
        // upgrade from old `show_link` parameter.
        if (isset($atts['show_link'])) {
            $atts['show_page_link'] = $atts['show_link'];
        }
        $defaults = array('number' => '5', 'likes' => 1, 'comments' => 1, 'excerpt_length' => 140, 'el' => 'div', 'origin' => 'shortcode', 'show_page_link' => false, 'show_link_previews' => $opts['load_css']);
        $atts = shortcode_atts($defaults, $atts);
        ob_start();
        ?>
		<!-- Recent Facebook Posts v<?php 
        echo RFBP_VERSION;
        ?>
 - https://wordpress.org/plugins/recent-facebook-posts/ -->
		<div class="recent-facebook-posts rfbp rfbp-container rfbp-<?php 
        echo $atts['origin'];
        ?>
">
			<?php 
        if ($posts && !empty($posts)) {
            if ($atts['el'] == 'li') {
                echo '<ul class="rfbp-posts-wrap">';
            }
            $posts = array_slice($posts, 0, $atts['number']);
            $link_target = $opts['link_new_window'] ? "_blank" : '';
            foreach ($posts as $p) {
                $shortened = false;
                $content = $p['content'];
                // shorten content if it exceed the set excerpt length
                if (strlen($content) > $atts['excerpt_length']) {
                    $limit = strpos($content, ' ', $atts['excerpt_length']);
                    if ($limit) {
                        $content = substr($content, 0, $limit);
                        $shortened = true;
                    }
                }
                ?>

					<<?php 
                echo $atts['el'];
                ?>
 class="rfbp-post">
					<h4 class="rfbp-heading"><a class="rfbp-link" href="<?php 
                echo $p['post_link'];
                ?>
" rel="external nofollow" target="<?php 
                echo $link_target;
                ?>
">
						<?php 
                echo $p['name'];
                ?>
					</a></h4>
					<div class="rfbp-text">

						<?php 
                $content = make_clickable($content, $link_target);
                $content = $shortened ? $content . apply_filters('rfbp_read_more', '..', $p['url']) : $content;
                $content = apply_filters('rfbp_content', $content, $p['url']);
                echo $content;
                ?>

					</div>

					<?php 
                if ($atts['show_link_previews'] && isset($p['link_url']) && !empty($p['link_url']) && !empty($p['link_name'])) {
                    ?>

					<p class="rfbp-link-wrap">
						<a class="rfbp-link" href="<?php 
                    echo $p['link_url'];
                    ?>
" rel="external nofollow" target="<?php 
                    echo $link_target;
                    ?>
">
							<?php 
                    if (!empty($p['link_image']) && apply_filters('rfbp_show_link_images', true) !== false) {
                        ?>
							<span class="rfbp-link-image-wrap">
								<img class="rfbp-link-image" src="<?php 
                        echo esc_attr($p['link_image']);
                        ?>
" width="114" />
							</span>
							<?php 
                    }
                    ?>

							<span class="rfbp-link-text-wrap">
								<span class="rfbp-link-name"><?php 
                    echo esc_html($p['link_name']);
                    ?>
</span>
								<?php 
                    if (isset($p['link_caption'])) {
                        ?>
<span class="rfbp-link-caption"><?php 
                        echo esc_html($p['link_caption']);
                        ?>
</span><?php 
                    }
                    ?>
								<?php 
                    if (isset($p['link_description']) && !empty($p['link_description'])) {
                        ?>
<span class="rfbp-link-description"><?php 
                        echo esc_html($p['link_description']);
                        ?>
</span><?php 
                    }
                    ?>
							</span>
						</a>
					</p>

					<?php 
                }
                ?>

					<?php 
                if ($opts['img_size'] !== 'dont_show' && isset($p['image']) && !empty($p['image'])) {
                    // grab bigger video thumbnail (hacky)
                    if ($p['type'] === 'video' && $opts['img_size'] == 'normal') {
                        $p['image'] = str_ireplace(array("_s.jpg", "_s.png"), array("_n.jpg", "_n.png"), $p['image']);
                    }
                    ?>
					<p class="rfbp-image-wrap">
						<a class="rfbp-image-link" target="<?php 
                    echo $link_target;
                    ?>
" href="<?php 
                    echo $p['url'];
                    ?>
" rel="external nofollow">
							<?php 
                    $max_img_width = !empty($opts['img_width']) ? $opts['img_width'] . 'px' : '100%';
                    $max_img_height = !empty($opts['img_height']) ? $opts['img_height'] . 'px' : 'none';
                    ?>
							<img class="rfbp-image" src="<?php 
                    echo $p['image'];
                    ?>
" style="<?php 
                    echo esc_attr("max-width: {$max_img_width}; max-height: {$max_img_height}");
                    ?>
" alt="" />
						</a>
						<?php 
                    if ($p['type'] === 'video') {
                        ?>
						<span class="rfbp-video-link"></span>
						<?php 
                    }
                    ?>
					</p>
					<?php 
                }
                ?>
					<p class="rfbp-post-link-wrap">
						<a target="<?php 
                echo $link_target;
                ?>
" class="rfbp-post-link" href="<?php 
                echo esc_url($p['url']);
                ?>
" rel="external nofolloW">
							<?php 
                if ($atts['likes']) {
                    ?>
<span class="rfbp-like-count"><?php 
                    echo absint($p['like_count']);
                    ?>
 <span><?php 
                    _e("likes", 'recent-facebook-posts');
                    if ($atts['comments']) {
                        ?>
, <?php 
                    }
                    ?>
</span></span><?php 
                }
                ?>
							<?php 
                if ($atts['comments']) {
                    ?>
<span class="rfbp-comment-count"><?php 
                    echo absint($p['comment_count']);
                    ?>
 <span><?php 
                    _e("comments", 'recent-facebook-posts');
                    ?>
</span></span><?php 
                }
                ?>
							<?php 
                if ($atts['likes'] || $atts['comments']) {
                    ?>
 &sdot; <?php 
                }
                ?>
							<span class="rfbp-timestamp" title="<?php 
                printf(__('%1$s at %2$s', 'recent-facebook-posts'), date('l, F j, Y', $p['timestamp']), date('G:i', $p['timestamp']));
                ?>
"><?php 
                echo rfbp_time_ago($p['timestamp']);
                ?>
</span>
						</a>
					</p>
					</<?php 
                echo $atts['el'];
                ?>
>
				<?php 
            }
            // end foreach $posts
            // close list
            if ($atts['el'] === 'li') {
                echo '</ul>';
            }
        } else {
            ?>
<p><?php 
            _e("No recent Facebook posts to show", 'recent-facebook-posts');
            ?>
</p><?php 
            if (current_user_can('manage_options')) {
                ?>
<p><strong><?php 
                _e("Admins only notice", 'recent-facebook-posts');
                ?>
:</strong> <?php 
                printf(__('Did you <a href="%s">configure the plugin</a> properly?', 'recent-facebook-posts'), admin_url('options-general.php?page=rfbp'));
                ?>
</p><?php 
            }
        }
        ?>

			<?php 
        if ($atts['show_page_link']) {
            ?>
				<p class="rfbp-page-link-wrap"><a class="rfbp-page-link" href="<?php 
            echo esc_url('https://www.facebook.com/' . $opts['fb_id'] . '/');
            ?>
" rel="external nofollow" target="<?php 
            echo esc_attr($link_target);
            ?>
"><?php 
            echo esc_html($opts['page_link_text']);
            ?>
</a></p>
			<?php 
        }
        ?>

			</div>
			<!-- / Recent Facebook Posts -->
			<?php 
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }