/var/www/hkosl.com/aga/wp-content/plugins/foogallery/includes/class-retina.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
 * FooGallery Retina Support class
 */

if ( !class_exists'FooGallery_Retina' ) ) {

    class 
FooGallery_Retina {

        function 
__construct() {
            
add_filter('foogallery_attachment_html_image_attributes', array($this'add_retina_attributes'), 103);
        }

        
/**
         * @param array $attr
         * @param array $args
         * @param FooGalleryAttachment $attachment
         * @return mixed
         */
        
function add_retina_attributes($attr$args$attachment) {
            global 
$current_foogallery;

            if ( 
$current_foogallery && $current_foogallery->gallery_template ) {

                
//first check if the gallery has saved Retina settings
                
if ( isset($current_foogallery->retina) && is_array$current_foogallery->retina ) ) {
                    
$srcset = array();

                    
//get the original thumb dimensions
                    
$original_thumb_width array_key_exists'width'$args ) ? intval$args['width'] ) : 0;
                    
$original_thumb_height array_key_exists'height'$args ) ? intval$args['height'] ) : 0;

                    
//get the original full size image dimensions
                    
$original_width $attachment->width;
                    
$original_height $attachment->height;

                    
//if we do not have a width, we need to calculate one
                    
if ( === $original_thumb_width ) {
                        
//find closest ratio multiple to image size
                        
if( $original_width $original_height ) {
                            
//landscape
                            
$ratio $original_width $original_height;
                            
$original_thumb_width intval$original_thumb_height $ratio );
                        }else{
                            
//portrait
                            
$ratio $original_height $original_width;
                            
$original_thumb_width intval$original_thumb_height $ratio );
                        }
                    }

                    foreach ( 
foogallery_retina_options() as $pixel_density ) {
                        
$pixel_density_supported array_key_exists$pixel_density$current_foogallery->retina ) ? ('true' === $current_foogallery->retina[$pixel_density]) : false;

                        if ( 
$pixel_density_supported ) {
                            
$pixel_density_int intvalstr_replace'x'''$pixel_density ) );

                            
//apply scaling to the width and height attributes
                            
$retina_width  $original_thumb_width $pixel_density_int;
                            
$retina_height $original_thumb_height $pixel_density_int;

                            
//if the new dimensions are smaller than the full size image dimensions then allow the retina thumb
                            
if ( $retina_width $original_width &&
                                
$retina_height $original_height ) {
                                
$args['width'] = $retina_width;
                                
$args['height'] = $retina_height;

                                
//build up the retina attributes
                                
$srcset[] = $attachment->html_img_src$args ) . ' ' $retina_width 'w';
                            }
                        }
                    }

                    if ( 
count$srcset ) ) {
                        
$attr['srcset'] = implode','$srcset );
                    }
                }
            }

            return 
$attr;
        }
    }
}