Ejemplo n.º 1
0
 public function settings_page()
 {
     $opts = rfbp_get_settings();
     // show user-friendly error message
     if ($this->cache_cleared) {
         $notice = __("<strong>Cache cleared!</strong> You succesfully cleared the cache.", 'recent-facebook-posts');
     }
     include_once RFBP_PLUGIN_DIR . 'includes/views/settings_page.html.php';
 }
Ejemplo n.º 2
0
function rfbp_valid_config()
{
    $opts = rfbp_get_settings();
    return !empty($opts['fb_id']) && !empty($opts['app_id']) && !empty($opts['app_secret']);
}
Ejemplo n.º 3
0
 /**
  * Ping the Facebook API for a quick test
  *
  * @param string $app_id
  * @param string $app_secret
  * @param string $page_id
  * @return bool
  */
 public function test_facebook_api($app_id = '', $app_secret = '', $page_id = '')
 {
     $opts = rfbp_get_settings();
     if ('' === $app_id) {
         $app_id = $opts['app_id'];
     }
     if ('' === $app_secret) {
         $app_secret = $opts['app_secret'];
     }
     if ('' === $page_id) {
         $page_id = $opts['fb_id'];
     }
     require_once RFBP_PLUGIN_DIR . 'includes/class-api.php';
     $api = new RFBP_API($app_id, $app_secret, $page_id);
     $ping = $api->ping();
     if ($ping) {
         add_settings_error('rfbp', 'rfbp-api-success', __('Your configuration seems to be okay and working. Nice work!.', 'recent-facebook-posts'), "updated");
     } else {
         add_settings_error('rfbp', 'rfbp-api-error', __('The following error was encountered when testing your configuration.', 'recent-facebook-posts') . '<br /><br />' . $api->get_error_message());
     }
     return $ping;
 }
Ejemplo n.º 4
0
    public function form($instance)
    {
        $instance = array_merge($this->defaults, $instance);
        $opts = rfbp_get_settings();
        if (!rfbp_valid_config()) {
            ?>
 			<p style="color:red;"><?php 
            printf(__('You need to <a href="%s">configure Recent Facebook Posts</a> first.', 'recent-facebook-posts'), admin_url('options-general.php?page=rfbp'));
            ?>
</p>
 		<?php 
        }
        ?>

		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:', 'recent-facebook-posts');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($instance['title']);
        ?>
" />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('number_of_posts');
        ?>
"><?php 
        _e('Number of posts:', 'recent-facebook-posts');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('number_of_posts');
        ?>
" name="<?php 
        echo $this->get_field_name('number_of_posts');
        ?>
" type="number" min="1" max="99" value="<?php 
        echo esc_attr($instance['number_of_posts']);
        ?>
" />
		</p>

		<p>
			<label for="<?php 
        echo $this->get_field_id('excerpt_length');
        ?>
"><?php 
        _e('Excerpt length:', 'recent-facebook-posts');
        ?>
</label>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('excerpt_length');
        ?>
" name="<?php 
        echo $this->get_field_name('excerpt_length');
        ?>
" type="number" min="1" max="9999"value="<?php 
        echo esc_attr($instance['excerpt_length']);
        ?>
" />
		</p>

		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('show_like_count');
        ?>
" name="<?php 
        echo $this->get_field_name('show_like_count');
        ?>
" value="1" <?php 
        checked($instance['show_like_count'], 1);
        ?>
  />
			<label for="<?php 
        echo $this->get_field_id('show_like_count');
        ?>
"><?php 
        _e('Show like count?', 'recent-facebook-posts');
        ?>
</label>
		</p>

		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('show_comment_count');
        ?>
" name="<?php 
        echo $this->get_field_name('show_comment_count');
        ?>
" value="1" <?php 
        checked($instance['show_comment_count'], 1);
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('show_comment_count');
        ?>
"><?php 
        _e('Show comment count?', 'recent-facebook-posts');
        ?>
</label>
		</p>

		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('show_page_link');
        ?>
" name="<?php 
        echo $this->get_field_name('show_page_link');
        ?>
" value="1" <?php 
        if ($instance['show_page_link']) {
            ?>
checked="1"<?php 
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('show_page_link');
        ?>
"><?php 
        _e('Show link to Facebook page?', 'recent-facebook-posts');
        ?>
</label>
		</p>

		<p>
			<input type="checkbox" id="<?php 
        echo $this->get_field_id('show_link_previews');
        ?>
" name="<?php 
        echo $this->get_field_name('show_link_previews');
        ?>
" value="1" <?php 
        if ($instance['show_link_previews']) {
            ?>
checked="1"<?php 
        }
        ?>
 />
			<label for="<?php 
        echo $this->get_field_id('show_link_previews');
        ?>
"><?php 
        _e('Show link previews?', 'recent-facebook-posts');
        ?>
</label>
		</p>

		<?php 
    }
Ejemplo n.º 5
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.º 6
0
 /**
  * Constructor
  */
 private function __construct()
 {
     $this->options = rfbp_get_settings();
 }