C:\xampp\htdocs\landing\wp-content\plugins\imagify\inc\classes\class-imagify-options.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
defined
'ABSPATH' ) || die( 'Cheatin’ uh?' );

/**
 * Class that handles the plugin options.
 *
 * @since 1.7
 */
class Imagify_Options extends Imagify_Abstract_Options {

    
/**
     * Class version.
     *
     * @var   string
     * @since 1.7
     */
    
const VERSION '1.1';

    
/**
     * Suffix used in the name of the option.
     *
     * @var    string
     * @since  1.7
     * @access protected
     */
    
protected $identifier 'settings';

    
/**
     * The default values for the Imagify main options.
     * These are the "zero state" values.
     * Don't use null as value.
     *
     * @var    array
     * @since  1.7
     * @access protected
     */
    
protected $default_values = array(
        
'api_key'             => '',
        
'optimization_level'  => 0,
        
'auto_optimize'       => 0,
        
'backup'              => 0,
        
'resize_larger'       => 0,
        
'resize_larger_w'     => 0,
        
'convert_to_webp'     => 0,
        
'display_webp'        => 0,
        
'display_webp_method' => 'picture',
        
'cdn_url'             => '',
        
'exif'                => 0,
        
'disallowed-sizes'    => array(),
        
'admin_bar_menu'      => 0,
        
'partner_links'       => 0,
    );

    
/**
     * The Imagify main option values used when they are set the first time or reset.
     * Values identical to default values are not listed.
     *
     * @var    array
     * @since  1.7
     * @access protected
     */
    
protected $reset_values = array(
        
'optimization_level' => 1,
        
'auto_optimize'      => 1,
        
'backup'             => 1,
        
'convert_to_webp'    => 1,
        
'admin_bar_menu'     => 1,
        
'partner_links'      => 1,
    );

    
/**
     * The single instance of the class.
     *
     * @var    object
     * @since  1.7
     * @access protected
     */
    
protected static $_instance;

    
/**
     * The constructor.
     * Side note: $this->hook_identifier value is "option".
     *
     * @since  1.7
     * @author Grégory Viguier
     * @access protected
     */
    
protected function __construct() {
        if ( 
defined'IMAGIFY_API_KEY' ) && IMAGIFY_API_KEY ) {
            
$this->default_values['api_key'] = (string) IMAGIFY_API_KEY;
        }

        if ( 
function_exists'wp_get_original_image_path' ) ) {
            
$this->reset_values['resize_larger'] = 1;

            
$filter_cb = [ imagify_get_context'wp' ), 'get_resizing_threshold' ];
            
$filtered  has_filter'big_image_size_threshold'$filter_cb );

            if ( 
$filtered ) {
                
remove_filter'big_image_size_threshold'$filter_cbIMAGIFY_INT_MAX );
            }

            
/** This filter is documented in wp-admin/includes/image.php */
            
$this->reset_values['resize_larger_w'] = (int) apply_filters'big_image_size_threshold'2560, [ 0], '');
            
$this->reset_values['resize_larger_w'] = $this->sanitize_and_validate_value'resize_larger_w'$this->reset_values['resize_larger_w'], $this->default_values['resize_larger_w'] );

            if ( 
$filtered ) {
                
add_filter'big_image_size_threshold'$filter_cbIMAGIFY_INT_MAX );
            }
        }

        
$this->network_option imagify_is_active_for_network();

        
parent::__construct();
    }

    
/**
     * Get the main Instance.
     *
     * @since  1.7
     * @author Grégory Viguier
     * @access public
     *
     * @return object Main instance.
     */
    
public static function get_instance() {
        if ( ! isset( 
self::$_instance ) ) {
            
self::$_instance = new self();
        }

        return 
self::$_instance;
    }


    
/** ----------------------------------------------------------------------------------------- */
    /** SANITIZATION, VALIDATION ================================================================ */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Sanitize and validate an option value. Basic casts have been made.
     *
     * @since  1.7
     * @author Grégory Viguier
     * @access public
     *
     * @param  string $key     The option key.
     * @param  mixed  $value   The value.
     * @param  mixed  $default The default value.
     * @return mixed
     */
    
public function sanitize_and_validate_value$key$value$default ) {
        static 
$max_sizes;

        switch ( 
$key ) {
            case 
'api_key':
                if ( 
defined'IMAGIFY_API_KEY' ) && IMAGIFY_API_KEY ) {
                    return (string) 
IMAGIFY_API_KEY;
                }
                return 
$value sanitize_key$value ) : '';

            case 
'optimization_level':
                if ( 
$value || $value ) {
                    
// For an invalid value, return the "reset" value.
                    
$reset_values $this->get_reset_values();
                    return 
$reset_values$key ];
                }
                return 
$value;

            case 
'auto_optimize':
            case 
'backup':
            case 
'resize_larger':
            case 
'convert_to_webp':
            case 
'display_webp':
            case 
'exif':
            case 
'admin_bar_menu':
            case 
'partner_links':
                return 
1;

            case 
'resize_larger_w':
                if ( 
$value <= ) {
                    
// Invalid.
                    
return $default;
                }
                if ( ! isset( 
$max_sizes ) ) {
                    
$max_sizes get_imagify_max_intermediate_image_size();
                }
                if ( 
$value $max_sizes['width'] ) {
                    
// Invalid.
                    
return $max_sizes['width'];
                }
                return 
$value;

            case 
'disallowed-sizes':
                if ( ! 
$value ) {
                    return 
$default;
                }

                
$value array_keys$value );
                
$value array_map'sanitize_text_field'$value );
                return 
array_fill_keys$value);

            case 
'display_webp_method':
                
$values = [
                    
'picture' => 1,
                    
'rewrite' => 1,
                ];
                if ( isset( 
$values$value ] ) ) {
                    return 
$value;
                }
                
// For an invalid value, return the "reset" value.
                
$reset_values $this->get_reset_values();
                return 
$reset_values$key ];

            case 
'cdn_url':
                
$cdn_source = \Imagify\Webp\Picture\Display::get_instance()->get_cdn_source$value );

                if ( 
'option' !== $cdn_source['source'] ) {
                    
/**
                     * If the URL is defined via constant or filter, unset the option.
                     * This is useful when the CDN is disabled: there is no need to do anything then.
                     */
                    
return '';
                }

                return 
$cdn_source['url'];
        }

        return 
false;
    }

    
/**
     * Validate Imagify's options before storing them. Basic sanitization and validation have been made, row by row.
     *
     * @since  1.7
     * @author Grégory Viguier
     * @access public
     *
     * @param  string $values The option value.
     * @return array
     */
    
public function validate_values_on_update$values ) {
        
// The max width for the "Resize larger images" option can't be 0.
        
if ( empty( $values['resize_larger_w'] ) ) {
            unset( 
$values['resize_larger'], $values['resize_larger_w'] );
        }

        
// Don't display wepb if conversion is disabled.
        
if ( empty( $values['convert_to_webp'] ) ) {
            unset( 
$values['convert_to_webp'], $values['display_webp'] );
        }

        return 
$values;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586