Example #1
0
    public function widget($args, $instance)
    {
        extract($args);
        echo $before_widget;
        if (!empty($instance['title'])) {
            echo $before_title . esc_attr($instance['title']) . $after_title;
        }
        //Loads up plugin variables
        FB_Album::load_options();
        //We need to see if the widget has been overridden for this page.
        global $post;
        $wp_pages = FB_Album::$options['pages'];
        $facebook_album_url = !empty($wp_pages[$post->ID]) ? $wp_pages[$post->ID] : $instance['url'];
        if ($facebook_album_url != '') {
            FB_Album::_set_album_url($facebook_album_url);
        } else {
            //We didn't have a URL!
            echo 'No Facebook Album specified.';
            echo $after_widget;
            return;
        }
        if (!FB_Album::_get_album_id()) {
            echo 'The Facebook album ID came up empty, double check the URL';
            echo $after_widget;
            return;
        } else {
            //Checks if Facebook API came back with a result
            if (!($fb = FB_Album::_get_graph_results($instance['limit']))) {
                echo 'Sorry, there was an error loading the Facebook album, please refresh the page and try again.';
                echo $after_widget;
                return;
            }
            //Checks if has photo data
            if (!$fb['data']) {
                echo 'Facebook API came back with a faulty result. You may be accessing an album you do not have permissions to access.';
            } else {
                FB_Album::_enqueue_resources();
                ?>
        <?php 
                if ($instance['show_album_title']) {
                    #TODO: Notice
                    echo '<span class="fbalbum-title"><a href="' . FB_Album::_clean_url(FB_Album::_get_album_url()) . '" target="_blank"">' . $fb['data'][0]['album']['name'] . '</a></span>';
                }
                ?>

        <div class="fbalbum fbalbum-widget"> <?php 
                //Reverse array to show oldest to newest
                if (isset(FB_Album::$options['order']) && !empty(FB_Album::$options['order'])) {
                    $fb['data'] = array_reverse($fb['data']);
                }
                foreach ($fb['data'] as $img) {
                    $thumb_size = FB_Album::$options['size'] - 1;
                    $thumbnail_src_url = FB_Album::check_thumbnail_src_size_url($img, $thumb_size);
                    ?>
          <div class="item">
            <a href="<?php 
                    echo FB_Album::_clean_url($img['images'][1]['source']);
                    ?>
" target="_blank" rel="lightbox" class="fbalbum cboxElement">
              <div class="image size-<?php 
                    echo $instance['thumb_size'];
                    ?>
" style="background-image: url('<?php 
                    echo FB_Album::_clean_url($thumbnail_src_url);
                    ?>
');">&nbsp;</div>
            </a>
          </div>

          <?php 
                }
                echo '</div>';
                echo FB_Album::build_colorbox();
            }
        }
        echo $after_widget;
    }
Example #2
0
 /**
  * Sets $album_id within class
  * @param id
  * @return void
  */
 public static function _set_album_id($id)
 {
     self::$album_id = $id;
 }
    _e('App ID', 'facebook-albums');
    ?>
</label><input type="text" name="facebookalbum[app_id]" value="<?php 
    echo $options['app_id'];
    ?>
" /></p>
            <p><label><?php 
    _e('App Secret', 'facebook-albums');
    ?>
</label><input type="text" name="facebookalbum[app_secret]" value="<?php 
    echo $options['app_secret'];
    ?>
" /></p>
            <?php 
} else {
    FB_Album::set_facebook_sdk();
    // Get User ID
    $user = FB_Album::$facebook_sdk->getUser();
    if ($user) {
        try {
            $old_access_token = $options['access_token'];
            // Proceed knowing you have a logged in user who's authenticated.
            $user_profile = FB_Album::$facebook_sdk->api('/me');
            FB_Album::$facebook_sdk->setExtendedAccessToken();
            $options['access_token'] = FB_Album::$facebook_sdk->getAccessToken();
            update_option('facebookalbum', $options);
        } catch (FacebookApiException $e) {
            echo '<div class="error"><p><strong>OAuth Error</strong>Error added to error_log: ' . $e . '</p></div>';
            error_log($e);
            $user = null;
        }