|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* FooGallery Retina Support class |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
if ( !class_exists( 'FooGallery_Retina' ) ) { |
|
7
|
|
|
|
|
8
|
|
|
class FooGallery_Retina { |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
function __construct() { |
|
|
|
|
|
|
11
|
|
|
add_filter('foogallery_attachment_html_image_attributes', array($this, 'add_retina_attributes'), 10, 3); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param array $attr |
|
16
|
|
|
* @param array $args |
|
17
|
|
|
* @param FooGalleryAttachment $attachment |
|
18
|
|
|
* @return mixed |
|
19
|
|
|
*/ |
|
20
|
|
|
function add_retina_attributes($attr, $args, $attachment) { |
|
|
|
|
|
|
21
|
|
|
global $current_foogallery; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
if ( $current_foogallery && $current_foogallery->gallery_template ) { |
|
24
|
|
|
|
|
25
|
|
|
//first check if the gallery template supports Retina thumbs |
|
26
|
|
|
if ( $current_foogallery->retina ) { |
|
27
|
|
|
$srcset = array(); |
|
28
|
|
|
|
|
29
|
|
|
$original_width = intval( $args['width'] ); |
|
30
|
|
|
$original_height = intval( $args['height'] ); |
|
31
|
|
|
|
|
32
|
|
|
foreach ( foogallery_retina_options() as $pixel_density ) { |
|
33
|
|
|
$pixel_density_supported = array_key_exists( $pixel_density, $current_foogallery->retina ) ? ('true' === $current_foogallery->retina[$pixel_density]) : false; |
|
34
|
|
|
|
|
35
|
|
|
if ( $pixel_density_supported ) { |
|
36
|
|
|
$pixel_density_int = intval( str_replace( 'x', '', $pixel_density ) ); |
|
37
|
|
|
|
|
38
|
|
|
//apply scaling to the width and height attributes |
|
39
|
|
|
$retina_width = $original_width * $pixel_density_int; |
|
40
|
|
|
$retina_height = $original_height * $pixel_density_int; |
|
41
|
|
|
|
|
42
|
|
|
//if the new dimensions are smaller than the full size image dimensions then allow the retina thumb |
|
43
|
|
|
if ( $retina_width < $attachment->width && |
|
44
|
|
|
$retina_height < $attachment->height ) { |
|
45
|
|
|
$args['width'] = $retina_width; |
|
46
|
|
|
$args['height'] = $retina_height; |
|
47
|
|
|
|
|
48
|
|
|
//build up the retina attributes |
|
49
|
|
|
$srcset[] = $attachment->html_img_src( $args ) . ' ' . $retina_width . 'w'; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if ( count( $srcset ) ) { |
|
55
|
|
|
$attr['srcset'] = implode( ',', $srcset ); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $attr; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.