Exemple #1
0
 public function Build_Gallery($arr_images, $attributes)
 {
     # Prepare Gallery Array
     $this->gallery = (object) array('attributes' => (object) $attributes, 'images' => array());
     # Generate Gallery HTML ID
     if (!empty($attributes['post_parent'])) {
         # this gallery uses the post attachments
         $this->gallery->id = $attributes['post_parent'];
     } else {
         # this gallery only includes images
         $this->gallery->id = Sanitize_Title($attributes['include']);
     }
     # Build the Gallery object
     foreach ($arr_images as $id => &$image) {
         # Thumb URL, width, height
         list($src, $width, $height) = WP_Get_Attachment_Image_Src($image->ID, $attributes['size']);
         $image->width = $width;
         $image->height = $height;
         $image->src = $src;
         $image->title = $image->post_title;
         $image->caption = $image->post_excerpt;
         $image->description = $image->post_content;
         $image->class = 'attachment-' . $attributes['size'];
         # Image Link
         if (empty($image->href)) {
             $image->href = WP_Get_Attachment_URL($image->ID);
         }
         # Run filter
         $image->attributes = Apply_Filters('wp_get_attachment_image_attributes', array('src' => $image->src, 'width' => $image->width, 'height' => $image->height, 'class' => $image->class, 'alt' => $image->title, 'title' => $image->title), $image);
         # Write in Object
         $this->gallery->images[] = $image;
     }
 }
 function Build_Gallery($arr_images, $attributes)
 {
     // Prepare Gallery Array
     $this->gallery = new StdClass();
     $this->gallery->attributes = new StdClass();
     $this->gallery->images = array();
     // Fill Attributes
     foreach ($attributes as $key => $value) {
         $this->gallery->attributes->{$key} = $value;
     }
     // Generate Gallery HTML ID
     if (!empty($attributes['post_parent'])) {
         // this gallery uses the post attachments
         $this->gallery->id = $attributes['post_parent'];
     } else {
         // this gallery only includes images
         $this->gallery->id = Str_Replace(',', '-', $attributes['include']);
     }
     // Build the Gallery object
     foreach ($arr_images as $id => &$image) {
         // Thumb URL, width, height
         list($src, $width, $height) = wp_get_attachment_image_src($image->ID, $attributes['size']);
         if ($width != $attributes['thumb_width'] || $height != $attributes['thumb_height'] || $attributes['thumb_grayscale'] || $attributes['thumb_negate']) {
             $width = $attributes['thumb_width'];
             $height = $attributes['thumb_height'];
             $src = $this->Resampled_Image_URL($image->ID, $width, $height, True, $attributes['thumb_grayscale'] == True, $attributes['thumb_negate'] == True);
         }
         $image->width = $width;
         $image->height = $height;
         $image->src = $src;
         // Image title
         $image->title = $this->get_image_title($image);
         // CSS Class
         $image->class = 'attachment-' . $attributes['size'];
         // Image Link
         if (empty($image->href)) {
             $image->href = WP_Get_Attachment_URL($image->ID);
         }
         // Run filter
         $image->attributes = Apply_Filters('wp_get_attachment_image_attributes', array('src' => $image->src, 'width' => $image->width, 'height' => $image->height, 'class' => $image->class, 'alt' => $image->title, 'title' => $image->title), $image);
         // Write in Object
         $this->gallery->images[] = $image;
     }
 }