/modules/tiled-gallery/tiled-gallery/tiled-gallery-item.php

  1. <?php 
  2. abstract class Jetpack_Tiled_Gallery_Item { 
  3. public $image; 
  4.  
  5. public function __construct( $attachment_image, $needs_attachment_link, $grayscale ) { 
  6. $this->image = $attachment_image; 
  7. $this->grayscale = $grayscale; 
  8.  
  9. $this->image_title = $this->image->post_title; 
  10.  
  11. $this->image_alt = get_post_meta( $this->image->ID, '_wp_attachment_image_alt', true ); 
  12. // If no Alt value, use the caption 
  13. if ( empty( $this->image_alt ) && ! empty( $this->image->post_excerpt ) ) { 
  14. $this->image_alt = trim( strip_tags( $this->image->post_excerpt ) ); 
  15. // If still no Alt value, use the title 
  16. if ( empty( $this->image_alt ) && ! empty( $this->image->post_title ) ) { 
  17. $this->image_alt = trim( strip_tags( $this->image->post_title ) ); 
  18.  
  19. $this->orig_file = wp_get_attachment_url( $this->image->ID ); 
  20. $this->link = $needs_attachment_link ? get_attachment_link( $this->image->ID ) : $this->orig_file; 
  21.  
  22. $this->img_src = add_query_arg( array( 'w' => $this->image->width, 'h' => $this->image->height, 'crop' => true ), $this->orig_file ); 
  23.  
  24.  
  25. public function fuzzy_image_meta() { 
  26. $meta = wp_get_attachment_metadata( $this->image->ID ); 
  27. $img_meta = ( ! empty( $meta['image_meta'] ) ) ? (array) $meta['image_meta'] : array(); 
  28. if ( ! empty( $img_meta ) ) { 
  29. foreach ( $img_meta as $k => $v ) { 
  30. if ( 'latitude' == $k || 'longitude' == $k ) 
  31. unset( $img_meta[$k] ); 
  32.  
  33. return $img_meta; 
  34.  
  35. public function meta_width() { 
  36. $meta = wp_get_attachment_metadata( $this->image->ID ); 
  37. return isset( $meta['width'] ) ? intval( $meta['width'] ) : ''; 
  38.  
  39. public function meta_height() { 
  40. $meta = wp_get_attachment_metadata( $this->image->ID ); 
  41. return isset( $meta['height'] ) ? intval( $meta['height'] ) : ''; 
  42.  
  43. public function medium_file() { 
  44. $medium_file_info = wp_get_attachment_image_src( $this->image->ID, 'medium' ); 
  45. $medium_file = isset( $medium_file_info[0] ) ? $medium_file_info[0] : ''; 
  46. return $medium_file; 
  47.  
  48. public function large_file() { 
  49. $large_file_info = wp_get_attachment_image_src( $this->image->ID, 'large' ); 
  50. $large_file = isset( $large_file_info[0] ) ? $large_file_info[0] : ''; 
  51. return $large_file; 
  52.  
  53. class Jetpack_Tiled_Gallery_Rectangular_Item extends Jetpack_Tiled_Gallery_Item { 
  54. public function __construct( $attachment_image, $needs_attachment_link, $grayscale ) { 
  55. parent::__construct( $attachment_image, $needs_attachment_link, $grayscale ); 
  56. $this->img_src_grayscale = jetpack_photon_url( $this->img_src, array( 'filter' => 'grayscale' ) ); 
  57.  
  58. $this->size = 'large'; 
  59.  
  60. if ( $this->image->width < 250 ) 
  61. $this->size = 'small'; 
  62.  
  63. class Jetpack_Tiled_Gallery_Square_Item extends Jetpack_Tiled_Gallery_Item { 
  64. public function __construct( $attachment_image, $needs_attachment_link, $grayscale ) { 
  65. parent::__construct( $attachment_image, $needs_attachment_link, $grayscale ); 
  66. $this->img_src_grayscale = jetpack_photon_url( $this->img_src, array( 'filter' => 'grayscale', 'resize' => array( $this->image->width, $this->image->height ) ) ); 
  67.  
  68. class Jetpack_Tiled_Gallery_Circle_Item extends Jetpack_Tiled_Gallery_Square_Item { 
.