/**
  * Callback: show the metabox content
  *
  * @param $post
  */
 public function add_metabox_content($post)
 {
     wp_nonce_field('apg_metabox_nonce', 'apg_metabox_nonce');
     $viewer = new Viewer();
     $photos = $viewer->get_photos($post->ID);
     if (count($photos) >= 1) {
         $photo_hidden = array();
         echo '<div style="width: 95%; padding: 0;">';
         echo '<ul id="apg-sortable" class="apg-sortable">';
         foreach ($photos as $photo) {
             if (empty($photo['ID'])) {
                 continue;
             }
             echo '<li id="apg-photo-' . esc_attr($photo['ID']) . '" data-apgid="' . esc_attr($photo['ID']) . '" style="float: left;width: 80px; height: 80px; display: block; position:relative; border: 1px solid #e5e5e5; background-color: #fff; cursor: move; padding: 0; margin-right: 10px; margin-bottom: 10px;">';
             echo '<p style="padding: 3px; margin: 0; display: block;">';
             echo wp_get_attachment_image($photo['ID'], 'apg-thumbnail-75-75');
             echo '</p>';
             echo '<div class="apg-delete-photo" data-apgid="' . esc_attr($photo['ID']) . '" style="cursor: pointer;display:block;position:absolute;top:-5px;margin-left: 67px;width: 16px;height:16px;border-radius:10px;padding:0;padding-top:-4px;border: 2px solid #ccc;font-size: 7px;background-color:#333;color:#fff;text-align:center;">X</div>';
             echo '</li>';
             $photo_hidden[] = $photo['ID'];
         }
         echo '</ul></div><div style="clear: both;"></div>';
         echo '<input type="hidden" name="apg_photo_order" id="apg_photo_order" value="' . implode(',', $photo_hidden) . '" />';
         echo '<p><i>' . __('If you want to upload new photos to this album, please use the "Upload photo(s)" menu item on the left.', 'apg') . '</i></p>';
     } else {
         echo '<p><strong>' . __('No photos where uploaded, yet. Please use the submenu item "Upload photo(s)" in the menu to upload new photos, or use the button below.', 'apg') . '</strong></p>';
     }
     echo '<p>' . __('You can add or upload new photo\'s into this album on the upload page.', 'apg') . ' <a href="' . admin_url('edit.php?post_type=apg_photo_albums&page=apg_upload') . '" class="button">' . __('Add new Photo\'s', 'apg') . '</a></p>';
 }
 /**
  * Build up the photos
  *
  * @return string
  */
 public function apg_build_preview()
 {
     $viewer = new Viewer();
     $photos = $this->get_html_comment('start');
     $photos .= '<div id="apg-preview" class="apg-thumb-preview">';
     $photos .= apply_filters('apg_before_preview', '');
     $count = 1;
     foreach ($viewer->get_photos($this->post->ID) as $photo) {
         if (empty($photo['ID']) || $count > (int) $this->settings->get('archive_limit')) {
             continue;
         }
         $photos .= str_replace('%%photo_url%%', wp_get_attachment_url($photo['ID']), apply_filters('apg_before_image', ''));
         $photos .= wp_get_attachment_image($photo['ID'], apply_filters('apg_photo_size', $this->apg_get_thumb_setting_name()));
         $photos .= apply_filters('apg_after_image', '');
         $count++;
     }
     $photos .= apply_filters('apg_after_preview', '');
     $photos .= '</div>';
     $photos .= $this->get_html_comment('end');
     return $photos;
 }
 /**
  * Show an album preview
  *
  * @param array $args
  *
  * @return null|string
  */
 public function apg_albums_preview($args = array())
 {
     $widget = null;
     $full_gallery = false;
     if (!isset($args['id'])) {
         return '<p>Missing Album ID in shortcode apg_album</p>';
     }
     $album_args = array('post_type' => 'apg_photo_albums', 'post_status' => 'publish', 'posts_per_page' => 5000);
     $albums = get_posts($album_args);
     /**
      * Argument: thumbsize (valid values between 50 and 150)
      */
     $thumbsize = $this->helper->get_setting('thumb_size');
     $imagelimit = 4;
     if (isset($args['imagelimit'])) {
         if (intval($args['imagelimit']) >= 1 && intval($args['imagelimit']) <= 30) {
             $imagelimit = intval($args['imagelimit']) - 1;
         }
     }
     if (isset($args['thumbsize'])) {
         if (intval($args['thumbsize']) >= 50 && intval($args['thumbsize']) <= 150) {
             $thumbsize = intval($args['thumbsize']);
         }
     }
     if (isset($args['preview'])) {
         if ($args['preview'] === 'false') {
             $imagelimit = 9999;
             $full_gallery = true;
         }
     }
     foreach ($albums as $album) {
         if ($album->ID != $args['id']) {
             continue;
         }
         $viewer = new Viewer();
         $photos = $viewer->get_photos($album->ID);
         $widget .= $this->get_html_comment('start');
         if ($full_gallery === true) {
             $widget .= '<div id="apg-gallery" class="apg-thumb apg-' . esc_attr($this->helper->get_setting('gallery')) . '">';
             $widget .= '<h3 class="apg-album-title">' . esc_attr($album->post_title) . '</h3>';
             $photo_class = 'apg-photo-url';
         } else {
             $widget .= '<div class="apg-album-shortcode">';
             $widget .= '<a href="' . get_permalink($album->ID) . '" class="apg-photo-short-thumb"><h3 class="apg-album-title">' . esc_attr($album->post_title) . '</h3></a>';
             $photo_class = 'apg-photo-url apg-goto-link';
         }
         $widget .= '<div class="apg-thumb apg-' . esc_attr($this->helper->get_setting('gallery')) . '">';
         $shown_images = 0;
         foreach ($photos as $p) {
             if ($shown_images > $imagelimit) {
                 continue;
             }
             $widget .= '<div class="' . esc_attr($this->helper->get_setting('gallery')) . '-block">';
             if ($full_gallery === true) {
                 $widget .= '<a href="' . wp_get_attachment_url($p['ID']) . '" class="' . $photo_class . '">';
             } else {
                 $widget .= '<a href="' . get_permalink($album->ID) . '" class="' . $photo_class . '">';
             }
             $widget .= wp_get_attachment_image($p['ID'], array($thumbsize, $thumbsize));
             $widget .= '</a></div>';
             $shown_images++;
         }
         $widget .= '<div class="apg-clear"></div>';
         $widget .= '</div>';
         $widget .= '</div>';
         $widget .= $this->get_html_comment('end');
     }
     /**
      * Add the photo viewer for full screen images
      */
     if ($full_gallery === true) {
         $render = new Render(array());
         if ($this->helper->get_setting('enable_slideshow') === true) {
             add_filter('apg_below_lightbox_buttons', array($render, 'apg_add_slideshow'), 15, 1);
         }
         $widget .= $render->add_photo_viewer();
     }
     return $widget;
 }