C:\xampp\htdocs\landing\wp-content\plugins\imagify\inc\classes\class-imagify-requirements.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?php
defined
'ABSPATH' ) || die( 'Cheatin’ uh?' );

/**
 * Class used to check that Imagify has everything it needs.
 *
 * @since  1.7.1
 * @author Grégory Viguier
 */
class Imagify_Requirements {
    
/**
     * Cache the test results.
     *
     * @var    object
     * @access protected
     * @since  1.7.1
     * @author Grégory Viguier
     */
    
protected static $supports = array();


    
/** ----------------------------------------------------------------------------------------- */
    /** SERVER ================================================================================== */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Test for cURL.
     *
     * @since  1.7.1
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool
     */
    
public static function supports_curl$reset_cache false ) {
        if ( 
$reset_cache || ! isset( self::$supports['curl'] ) ) {
            
self::$supports['curl'] = function_exists'curl_init' ) && function_exists'curl_exec' );
        }

        return 
self::$supports['curl'];
    }

    
/**
     * Test for imageMagick and GD.
     * Similar to _wp_image_editor_choose(), but allows to test for multiple mime types at once.
     *
     * @since  1.7.1
     * @access public
     * @see    _wp_image_editor_choose()
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool
     */
    
public static function supports_image_editor$reset_cache false ) {
        if ( ! 
$reset_cache && isset( self::$supports['image_editor'] ) ) {
            return 
self::$supports['image_editor'];
        }

        require_once 
ABSPATH WPINC '/class-wp-image-editor.php';
        require_once 
ABSPATH WPINC '/class-wp-image-editor-gd.php';
        require_once 
ABSPATH WPINC '/class-wp-image-editor-imagick.php';

        
self::$supports['image_editor'] = false;

        
$args = array(
            
'path'       => IMAGIFY_PATH 'assets/images/imagify-logo.png',
            
'mime_types' => imagify_get_mime_types'image' ),
            
'methods'    => Imagify_Attachment::get_editor_methods(),
        );

        
/** This filter is documented in /wp-includes/media.php. */
        
$implementations apply_filters'wp_image_editors', array( 'WP_Image_Editor_Imagick''WP_Image_Editor_GD' ) );

        foreach ( 
$implementations as $implementation ) {
            if ( ! 
call_user_func( array( $implementation'test' ), $args ) ) {
                continue;
            }

            foreach ( 
$args['mime_types'] as $mime_type ) {
                if ( ! 
call_user_func( array( $implementation'supports_mime_type' ), $mime_type ) ) {
                    continue 
2;
                }
            }

            if ( 
array_diff$args['methods'], get_class_methods$implementation ) ) ) {
                continue;
            }

            
self::$supports['image_editor'] = true;
            break;
        }

        return 
self::$supports['image_editor'];
    }


    
/** ----------------------------------------------------------------------------------------- */
    /** WORDPRESS =============================================================================== */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Test for the uploads directory.
     *
     * @since  1.7.1
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool
     */
    
public static function supports_uploads$reset_cache false ) {
        if ( ! 
$reset_cache && isset( self::$supports['uploads'] ) ) {
            return 
self::$supports['uploads'];
        }

        
self::$supports['uploads'] = Imagify_Filesystem::get_instance()->get_upload_basedir();

        if ( 
self::$supports['uploads'] ) {
            
self::$supports['uploads'] = Imagify_Filesystem::get_instance()->is_writableself::$supports['uploads'] );
        }

        return 
self::$supports['uploads'];
    }

    
/**
     * Test if external requests are blocked for Imagify.
     *
     * @since  1.7.1
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool
     */
    
public static function is_imagify_blocked$reset_cache false ) {
        if ( ! 
$reset_cache && isset( self::$supports['imagify_blocked'] ) ) {
            return 
self::$supports['imagify_blocked'];
        }

        if ( ! 
defined'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) {
            
self::$supports['imagify_blocked'] = false;
            return 
self::$supports['imagify_blocked'];
        }

        if ( ! 
defined'WP_ACCESSIBLE_HOSTS' ) ) {
            
self::$supports['imagify_blocked'] = true;
            return 
self::$supports['imagify_blocked'];
        }

        
$accessible_hosts explode','WP_ACCESSIBLE_HOSTS );
        
$accessible_hosts array_map'trim'$accessible_hosts );
        
$accessible_hosts array_flip$accessible_hosts );

        if ( isset( 
$accessible_hosts['*.imagify.io'] ) ) {
            
self::$supports['imagify_blocked'] = false;
            return 
self::$supports['imagify_blocked'];
        }

        if ( isset( 
$accessible_hosts['imagify.io'], $accessible_hosts['app.imagify.io'], $accessible_hosts['storage.imagify.io'] ) ) {
            
self::$supports['imagify_blocked'] = false;
            return 
self::$supports['imagify_blocked'];
        }

        
self::$supports['imagify_blocked'] = true;
        return 
self::$supports['imagify_blocked'];
    }


    
/** ----------------------------------------------------------------------------------------- */
    /** IMAGIFY BACKUP DIRECTORIES ============================================================== */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Test for the attachments backup directory.
     *
     * @since  1.7.1
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool
     */
    
public static function attachments_backup_dir_is_writable$reset_cache false ) {
        if ( 
$reset_cache || ! isset( self::$supports['attachment_backups'] ) ) {
            
self::$supports['attachment_backups'] = imagify_backup_dir_is_writable();
        }

        return 
self::$supports['attachment_backups'];
    }

    
/**
     * Test for the custom folders backup directory.
     *
     * @since  1.7.1
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool
     */
    
public static function custom_folders_backup_dir_is_writable$reset_cache false ) {
        if ( 
$reset_cache || ! isset( self::$supports['custom_folder_backups'] ) ) {
            
self::$supports['custom_folder_backups'] = Imagify_Custom_Folders::backup_dir_is_writable();
        }

        return 
self::$supports['custom_folder_backups'];
    }


    
/** ----------------------------------------------------------------------------------------- */
    /** IMAGIFY API ============================================================================= */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Determine if the Imagify API is available by checking the API version.
     * The result is cached for 3 minutes.
     *
     * @since  1.7.1
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool
     */
    
public static function is_api_up$reset_cache false ) {
        if ( ! 
$reset_cache && isset( self::$supports['api_up'] ) ) {
            return 
self::$supports['api_up'];
        }

        
$transient_name       'imagify_check_api_version';
        
$transient_expiration MINUTE_IN_SECONDS;
        
$transient_value      $reset_cache false get_site_transient$transient_name );

        if ( 
false !== $transient_value ) {
            
self::$supports['api_up'] = (bool) $transient_value;
            return 
self::$supports['api_up'];
        }

        
self::$supports['api_up'] = ! is_wp_errorget_imagify_api_version() );
        
$transient_value          = (int) self::$supports['api_up'];

        
set_site_transient$transient_name$transient_value$transient_expiration );

        return 
self::$supports['api_up'];
    }

    
/**
     * Test for the Imagify API key validity.
     * A positive result is cached for 1 year.
     *
     * @since  1.7.1
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool
     */
    
public static function is_api_key_valid$reset_cache false ) {
        if ( 
$reset_cache ) {
            
self::reset_cache'api_key_valid' );
        }

        if ( isset( 
self::$supports['api_key_valid'] ) ) {
            return 
self::$supports['api_key_valid'];
        }

        if ( ! 
Imagify_Options::get_instance()->get'api_key' ) ) {
            
self::$supports['api_key_valid'] = false;
            return 
self::$supports['api_key_valid'];
        }

        if ( 
get_site_transient'imagify_check_licence_1' ) ) {
            
self::$supports['api_key_valid'] = true;
            return 
self::$supports['api_key_valid'];
        }

        if ( 
is_wp_errorget_imagify_user() ) ) {
            
self::$supports['api_key_valid'] = false;
            return 
self::$supports['api_key_valid'];
        }

        
self::$supports['api_key_valid'] = true;
        
set_site_transient'imagify_check_licence_1'1YEAR_IN_SECONDS );

        return 
self::$supports['api_key_valid'];
    }

    
/**
     * Test for the Imagify account quota.
     *
     * @since  1.7.1
     * @since  1.9.9 Return false when the API cannot be reached.
     * @access public
     * @author Grégory Viguier
     *
     * @param  bool $reset_cache True to get a fresh value.
     * @return bool              True when over quota. False otherwise, even when the API cannot be reached.
     */
    
public static function is_over_quota$reset_cache false ) {
        if ( ! 
$reset_cache && isset( self::$supports['over_quota'] ) ) {
            return 
self::$supports['over_quota'];
        }

        
$user = new Imagify_User();

        
self::$supports['over_quota'] = $user->get_error() ? false $user->is_over_quota();

        return 
self::$supports['over_quota'];
    }


    
/** ----------------------------------------------------------------------------------------- */
    /** CLASS CACHE ============================================================================= */
    /** ----------------------------------------------------------------------------------------- */

    /**
     * Reset a test cache.
     *
     * @since  1.7.1
     * @access public
     * @author Grégory Viguier
     *
     * @param string $cache_key Cache key.
     */
    
public static function reset_cache$cache_key ) {
        unset( 
self::$supports$cache_key ] );

        
$transients = array(
            
'api_up'        => 'imagify_check_api_version',
            
'api_key_valid' => 'imagify_check_licence_1',
        );

        if ( isset( 
$transients$cache_key ] ) && get_site_transient$transients$cache_key ] ) ) {
            
delete_site_transient$transients$cache_key ] );
        }
    }
}
x

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