예제 #1
0
 public static function save_post($post_id)
 {
     if (wp_is_post_revision($post_id)) {
         return;
     }
     $post = get_post($post_id);
     if (strpos($post->post_content, '[fbalbum ') !== FALSE) {
         preg_match("/[fbalbum [^>]*url=(.+) /", $post->post_content, $output);
         $facebook_album_url = str_replace('"', '', $output[1]);
         FB_Album::_set_album_url($facebook_album_url);
         $album_id = FB_Album::_get_album_id();
         FB_Album::clear_cache($album_id);
     }
 }
예제 #2
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;
    }