function process_album_code($atts, $content = '')
 {
     $post_id = get_the_ID();
     if (!$post_id) {
         return '';
     }
     $atts = shortcode_atts(array('id' => false, 'limit' => false, 'photo_class' => 'thickbox', 'album_class' => false, 'photo_width' => 75, 'photo_height' => false, 'crop' => false, 'link_to' => 'source', 'columns' => false), $atts);
     if (!$atts['id']) {
         return '';
     }
     // We don't know what album to show
     $img_w = (int) $atts['photo_width'];
     $img_h = (int) $atts['photo_height'];
     $fb_open = 'source' != $atts['link_to'];
     $api = new Wdfb_AlbumPhotosBuffer();
     $photos = $api->get_for($atts['id'], $atts['limit']);
     if (!is_array($photos)) {
         return $content;
     }
     $ret = false;
     $i = 0;
     $display_idx = $img_w >= 130 ? $img_w >= 180 ? 0 : 1 : ($img_w >= 75 ? 2 : 3);
     $columns = (int) $atts['columns'];
     $current = 1;
     foreach ($photos as $photo) {
         $photo_idx = isset($photo['images'][$display_idx]) ? $display_idx : count($photo['images']) - 1;
         $style = $atts['crop'] ? "style='display:block;float:left;height:{$img_h}px;overflow:hidden'" : '';
         $url = $fb_open ? WDFB_PROTOCOL . 'www.facebook.com/photo.php?fbid=' . $photo['id'] : $photo['images'][0]['source'];
         $name = !empty($photo['name']) ? 'title="' . esc_attr($photo['name']) . '"' : '';
         $ret .= '<a href="' . $url . '" class="' . $atts['photo_class'] . '" rel="' . $atts['id'] . '-photo" ' . $style . ' ' . $name . '>' . '<img src="' . $photo['images'][$photo_idx]['source'] . '" ' . ($img_w ? "width='{$img_w}'" : '') . ($img_h && !$atts['crop'] ? "height='{$img_h}'" : '') . ' />' . '</a>';
         if ($columns && ++$i % $columns == 0) {
             $ret .= '<br ' . ($style ? 'style="clear:left"' : '') . '/>';
         }
         if ((int) $atts['limit'] && $current >= (int) $atts['limit']) {
             break;
         }
         $current++;
     }
     return "<div class='{$atts['album_class']}'>{$ret}</div>";
 }
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $limit = (int) $instance['limit'];
     $per_row = (int) $instance['per_row'];
     $img_w = (int) $instance['img_w'];
     $img_h = (int) $instance['img_h'];
     $img_crop = (int) $instance['img_crop'];
     $fb_open = (int) $instance['fb_open'];
     $album_id = $instance['album_id'];
     $api = new Wdfb_AlbumPhotosBuffer();
     $photos = $api->get_for($album_id, $limit);
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     if (is_array($photos)) {
         echo '<table cellspacing="0" cellpadding="0" border="0" class="wdfb_album_photos">';
         $count = $overall = 0;
         echo '<tr>';
         foreach ($photos as $photo) {
             if ($overall >= $limit) {
                 break;
             }
             $style = $img_crop ? "display:block;float:left;height:{$img_h}px;overflow:hidden" : '';
             $url = $fb_open ? WDFB_PROTOCOL . 'www.facebook.com/photo.php?fbid=' . $photo['id'] : $photo['images'][0]['source'];
             echo '<td valign="top">' . '<a href="' . $url . '" style="' . $style . '">' . '<img src="' . $photo['images'][count($photo['images']) - 1]['source'] . '" ' . ($img_w ? "width='{$img_w}'" : '') . ($img_h && !$img_crop ? "height='{$img_h}'" : '') . ' />' . '</a>' . '</td>';
             ++$count;
             ++$overall;
             if ($count == $per_row) {
                 echo '</tr><tr>';
                 $count = 0;
             }
         }
         if ($count < $per_row) {
             echo '<td colspan="' . ($per_row - $count) . '"></td>';
         }
         echo '<tr>';
         echo '</table>';
     }
     echo $after_widget;
 }