C:\xampp\htdocs\landing\wp-content\plugins\imagify\inc\functions\common.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
<?php
defined
'ABSPATH' ) || die( 'Cheatin’ uh?' );

/**
 * Get the list of the names of the Imagify context currently in use.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @return array An array of strings.
 */
function imagify_get_context_names() {
    static 
$contexts;

    if ( isset( 
$contexts ) ) {
        return 
$contexts;
    }

    
/**
     * Register new contexts.
     *
     * @since  1.9
     * @author Grégory Viguier
     *
     * @param array $contexts An array of context names.
     */
    
$contexts = (array) apply_filters'imagify_register_context', [] );

    
$contexts array_filter$contexts, function( $context ) {
        return 
$context && is_string$context );
    } );
    
$contexts array_merge( [ 'wp''custom-folders' ], $contexts );

    
sort$contexts );

    return 
$contexts;
}

/**
 * Sanitize an optimization context.
 *
 * @since  1.6.11
 * @author Grégory Viguier
 *
 * @param  string $context The context.
 * @return string
 */
function imagify_sanitize_context$context ) {
    return 
sanitize_key$context );
}

/**
 * Get the Imagify context instance.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @param  string $context  The context name. Default values are 'wp' and 'custom-folders'.
 * @return ContextInterface The context instance.
 */
function imagify_get_context$context ) {
    
$class_name imagify_get_context_class_name$context );
    return 
$class_name::get_instance();
}

/**
 * Get the Imagify context class name.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @param  string $context The context name. Default values are 'wp' and 'custom-folders'.
 * @return string          The context class name.
 */
function imagify_get_context_class_name$context ) {
    
$context imagify_sanitize_context$context );

    switch ( 
$context ) {
        case 
'wp':
            
$class_name '\\Imagify\\Context\\WP';
            break;

        case 
'custom-folders':
            
$class_name '\\Imagify\\Context\\CustomFolders';
            break;

        default:
            
$class_name '\\Imagify\\Context\\Noop';
    }

    
/**
     * Filter the name of the class to use to define a context.
     *
     * @since  1.9
     * @author Grégory Viguier
     *
     * @param int    $class_name The class name.
     * @param string $context    The context name.
     */
    
$class_name apply_filters'imagify_context_class_name'$class_name$context );

    return 
'\\' ltrim$class_name'\\' );
}

/**
 * Get the Imagify process instance depending on a context.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @param  int    $media_id The media ID.
 * @param  string $context  The context name. Default values are 'wp' and 'custom-folders'.
 * @return ProcessInterface The optimization process instance.
 */
function imagify_get_optimization_process$media_id$context ) {
    
$class_name imagify_get_optimization_process_class_name$context );
    return new 
$class_name$media_id );
}

/**
 * Get the Imagify process class name depending on a context.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @param  string $context The context name. Default values are 'wp' and 'custom-folders'.
 * @return string          The optimization process class name.
 */
function imagify_get_optimization_process_class_name$context ) {
    
$context imagify_sanitize_context$context );

    switch ( 
$context ) {
        case 
'wp':
            
$class_name '\\Imagify\\Optimization\\Process\\WP';
            break;

        case 
'custom-folders':
            
$class_name '\\Imagify\\Optimization\\Process\\CustomFolders';
            break;

        default:
            
$class_name '\\Imagify\\Optimization\\Process\\Noop';
    }

    
/**
     * Filter the name of the class to use for the optimization.
     *
     * @since  1.9
     * @author Grégory Viguier
     *
     * @param int    $class_name The class name.
     * @param string $context    The context name.
     */
    
$class_name apply_filters'imagify_process_class_name'$class_name$context );

    return 
'\\' ltrim$class_name'\\' );
}

/**
 * Get WP Direct filesystem object. Also define chmod constants if not done yet.
 *
 * @since  1.6.5
 * @author Grégory Viguier
 *
 * @return object A Imagify_Filesystem object.
 */
function imagify_get_filesystem() {
    return 
Imagify_Filesystem::get_instance();
}

/**
 * Convert a path (or URL) to its webp version.
 * To keep the function simple:
 * - Not tested if it's an image.
 * - File existance is not tested.
 * - If an URL is given, make sure it doesn't contain query args.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @param  string $path A file path or URL.
 * @return string
 */
function imagify_path_to_webp$path ) {
    return 
$path '.webp';
}

/**
 * Tell if the current user can optimize custom folders.
 *
 * @since  1.7
 * @author Grégory Viguier
 *
 * @return bool
 */
function imagify_can_optimize_custom_folders() {
    static 
$can;

    if ( isset( 
$can ) ) {
        return 
$can;
    }

    
// Check if the DB tables are ready.
    
if ( ! Imagify_Folders_DB::get_instance()->can_operate() || ! Imagify_Files_DB::get_instance()->can_operate() ) {
        
$can false;
        return 
$can;
    }

    
// Check for user capacity.
    
$can imagify_get_context'custom-folders' )->current_user_can'optimize' );

    return 
$can;
}

/**
 * Simple helper to get some external URLs, like to the documentation.
 *
 * @since  1.6.12
 * @author Grégory Viguier
 *
 * @param  string $target     What we want.
 * @param  array  $query_args An array of query arguments.
 * @return string The URL.
 */
function imagify_get_external_url$target$query_args = array() ) {
    
$site_url 'https://imagify.io/';
    
$app_url  'https://app.imagify.io/#/';

    switch ( 
$target ) {
        case 
'plugin':
            
/* translators: Plugin URI of the plugin/theme */
            
$url __'https://wordpress.org/plugins/imagify/''imagify' );
            break;

        case 
'rate':
            
$url 'https://wordpress.org/support/view/plugin-reviews/imagify?rate=5#postform';
            break;

        case 
'share-twitter':
            
$url rawurlencodeimagify_get_external_url'plugin' ) );
            
$url 'https://twitter.com/intent/tweet?source=webclient&original_referer=' $url '&url=' $url '&related=imagify&hastags=performance,web,wordpress';
            break;

        case 
'share-facebook':
            
$url rawurlencodeimagify_get_external_url'plugin' ) );
            
$url 'https://www.facebook.com/sharer/sharer.php?u=' $url;
            break;

        case 
'exif':
            
/* translators: URL to a Wikipedia page explaining what EXIF means. */
            
$url __'https://en.wikipedia.org/wiki/Exchangeable_image_file_format''imagify' );
            break;

        case 
'contact':
            
$lang  imagify_get_current_lang_in'fr' );
            
$paths = array(
                
'en' => 'contact',
                
'fr' => 'fr/contact',
            );

            
$url $site_url $paths$lang ] . '/';
            break;

        case 
'documentation':
            
$url $site_url 'documentation/';
            break;

        case 
'documentation-imagick-gd':
            
$url $site_url 'documentation/solve-imagemagick-gd-required/';
            break;

        case 
'register':
            
$partner imagify_get_partner();

            if ( 
$partner ) {
                
$query_args['partner'] = $partner;
            }

            
$url $app_url 'register';
            break;

        case 
'subscription':
            
$url $app_url 'subscription';
            break;

        case 
'get-api-key':
            
$url $app_url 'api';
            break;

        case 
'payment':
            
// Don't remove the trailing slash.
            
$url $app_url 'plugin/';
            break;

        default:
            return 
'';
    }

    if ( 
$query_args ) {
        
$url add_query_arg$query_args$url );
    }

    return 
$url;
}

/**
 * Get the current lang ('fr', 'en', 'de'...), limited to a given list.
 *
 * @since  1.6.14
 * @author Grégory Viguier
 *
 * @param  array $langs An array of langs, like array( 'de', 'es', 'fr', 'it' ).
 * @return string The current lang. Default is 'en'.
 */
function imagify_get_current_lang_in$langs ) {
    static 
$locale;

    if ( ! isset( 
$locale ) ) {
        
$locale imagify_get_locale();
        
$locale explode'_'strtolower$locale '_' ) ); // Trailing underscore is to make sure $locale[1] is set.
    
}

    foreach ( (array) 
$langs as $lang ) {
        if ( 
$lang === $locale[0] || $lang === $locale[1] ) {
            return 
$lang;
        }
    }

    return 
'en';
}

/**
 * Get the current locale.
 *
 * @since  1.6.14
 * @author Grégory Viguier
 *
 * @return string The current locale.
 */
function imagify_get_locale() {
    
$locale function_exists'get_user_locale' ) ? get_user_locale() : get_locale();
    
/**
     * Filter the locale used by Imagify.
     *
     * @since  1.6.14
     * @author Grégory Viguier
     *
     * @param string $locale The current locale.
     */
    
return apply_filters'imagify_locale'$locale );
}

/**
 * Get the label corresponding to the given optimization label.
 *
 * @since  1.7
 * @author Grégory Viguier
 *
 * @param  int|bool $level  Optimization level (between 0 and 2). False if no level.
 * @param  string   $format Format to display the label. Use %ICON% for the icon and %s for the label.
 * @return string           The label.
 */
function imagify_get_optimization_level_label$level$format '%s' ) {
    if ( ! 
is_numeric$level ) ) {
        return 
'';
    }

    if ( 
strpos$format'%ICON%' ) !== false ) {
        
$icon '<svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg"><g fill="#40B1D0" fill-rule="evenodd">';

        switch ( 
$level ) {
            case 
2:
                
$icon .= '<polygon points="11.6054688 11.6054688 8.7890625 11.6054688 8.7890625 0.39453125 11.6054688 0.39453125"/><polygon points="7.39453125 11.6054688 4.60546875 11.6054688 4.60546875 3.89453125 7.39453125 3.89453125"/><polygon points="3.2109375 11.6054688 0.39453125 11.6054688 0.39453125 6 3.2109375 6"/>';
                break;
            case 
1:
                
$icon .= '<polygon fill="#CCD1D6" points="11.6054688 11.6054688 8.7890625 11.6054688 8.7890625 0.39453125 11.6054688 0.39453125"/><polygon points="7.39453125 11.6054688 4.60546875 11.6054688 4.60546875 3.89453125 7.39453125 3.89453125"/><polygon points="3.2109375 11.6054688 0.39453125 11.6054688 0.39453125 6 3.2109375 6"/>';
                break;
            case 
0:
                
$icon .= '<polygon fill="#CCD1D6" points="11.6054688 11.6054688 8.7890625 11.6054688 8.7890625 0.39453125 11.6054688 0.39453125"/><polygon fill="#CCD1D6" points="7.39453125 11.6054688 4.60546875 11.6054688 4.60546875 3.89453125 7.39453125 3.89453125"/><polygon points="3.2109375 11.6054688 0.39453125 11.6054688 0.39453125 6 3.2109375 6"/>';
        }

        
$icon .= '</g></svg>';

        
$format str_replace'%ICON%'$icon$format );
    }

    switch ( 
$level ) {
        case 
2:
            return 
sprintf$format__'Ultra''imagify' ) );
        case 
1:
            return 
sprintf$format__'Aggressive''imagify' ) );
        case 
0:
            return 
sprintf$format__'Normal''imagify' ) );
    }

    return 
'';
}

/**
 * `array_merge()` + `array_intersect_key()`.
 *
 * @since  1.7
 * @author Grégory Viguier
 *
 * @param  array $values  The array we're interested in.
 * @param  array $default The array we use as boundaries.
 * @return array
 */
function imagify_merge_intersect$values$default ) {
    
$values array_merge$default, (array) $values );
    return 
array_intersect_key$values$default );
}

/**
 * Returns true.
 * Useful for returning true to filters easily.
 * Similar to WP's __return_true() function, it allows to remove it from a filter without removing another one added by another plugin.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @return bool True.
 */
function imagify_return_true() {
    return 
true;
}

/**
 * Returns false.
 * Useful for returning false to filters easily.
 * Similar to WP's __return_false() function, it allows to remove it from a filter without removing another one added by another plugin.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @return bool False.
 */
function imagify_return_false() {
    return 
false;
}

/**
 * Marks a class as deprecated and informs when it has been used.
 * Similar to _deprecated_constructor(), but with different strings.
 * The current behavior is to trigger a user error if `WP_DEBUG` is true.
 *
 * @since  1.9
 * @author Grégory Viguier
 *
 * @param string $class        The class containing the deprecated constructor.
 * @param string $version      The version of WordPress that deprecated the function.
 * @param string $replacement  Optional. The function that should have been called. Default null.
 * @param string $parent_class Optional. The parent class calling the deprecated constructor. Default empty string.
 */
function imagify_deprecated_class$class$version$replacement null$parent_class '' ) {

    
/**
     * Fires when a deprecated class is called.
     *
     * @since  1.9
     * @author Grégory Viguier
     *
     * @param string $class        The class containing the deprecated constructor.
     * @param string $version      The version of WordPress that deprecated the function.
     * @param string $replacement  Optional. The function that should have been called.
     * @param string $parent_class The parent class calling the deprecated constructor.
     */
    
do_action'imagify_deprecated_class_run'$class$version$replacement$parent_class );

    if ( ! 
WP_DEBUG ) {
        return;
    }

    
/**
     * Filters whether to trigger an error for deprecated classes.
     *
     * `WP_DEBUG` must be true in addition to the filter evaluating to true.
     *
     * @since  1.9
     * @author Grégory Viguier
     *
     * @param bool $trigger Whether to trigger the error for deprecated classes. Default true.
     */
    
if ( ! apply_filters'imagify_deprecated_class_trigger_error'true ) ) {
        return;
    }

    if ( 
function_exists'__' ) ) {
        if ( ! empty( 
$parent_class ) ) {
            
/**
             * With parent class.
             */
            
if ( ! empty( $replacement ) ) {
                
/**
                 * With replacement.
                 */
                
call_user_func(
                    
'trigger_error',
                    
sprintf(
                        
/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: replacement class name. */
                        
__'The called class %1$s extending %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.''imagify' ),
                        
'<code>' $class '</code>',
                        
'<code>' $parent_class '</code>',
                        
'<strong>' $version '</strong>',
                        
'<code>' $replacement '</code>'
                    
)
                );
                return;
            }

            
/**
             * Without replacement.
             */
            
call_user_func(
                
'trigger_error',
                
sprintf(
                    
/* translators: 1: PHP class name, 2: PHP parent class name, 3: version number. */
                    
__'The called class %1$s extending %2$s is <strong>deprecated</strong> since version %3$s!''imagify' ),
                    
'<code>' $class '</code>',
                    
'<code>' $parent_class '</code>',
                    
'<strong>' $version '</strong>'
                
)
            );
            return;
        }

        
/**
         * Without parent class.
         */
        
if ( ! empty( $replacement ) ) {
            
/**
             * With replacement.
             */
            
call_user_func(
                
'trigger_error',
                
sprintf(
                    
/* translators: 1: PHP class name, 2: version number, 3: replacement class name. */
                    
__'The called class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.''imagify' ),
                    
'<code>' $class '</code>',
                    
'<strong>' $version '</strong>',
                    
'<code>' $replacement '</code>'
                
)
            );
            return;
        }

        
/**
         * Without replacement.
         */
        
call_user_func(
            
'trigger_error',
            
sprintf(
                
/* translators: 1: PHP class name, 2: version number. */
                
__'The called class %1$s is <strong>deprecated</strong> since version %2$s!''imagify' ),
                
'<code>' $class '</code>',
                
'<strong>' $version '</strong>'
            
)
        );
        return;
    }

    if ( ! empty( 
$parent_class ) ) {
        
/**
         * With parent class.
         */
        
if ( ! empty( $replacement ) ) {
            
/**
             * With replacement.
             */
            
call_user_func(
                
'trigger_error',
                
sprintf(
                    
'The called class %1$s extending %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
                    
'<code>' $class '</code>',
                    
'<code>' $parent_class '</code>',
                    
'<strong>' $version '</strong>',
                    
'<code>' $replacement '</code>'
                
)
            );
            return;
        }

        
/**
         * Without replacement.
         */
        
call_user_func(
            
'trigger_error',
            
sprintf(
                
'The called class %1$s extending %2$s is <strong>deprecated</strong> since version %3$s!',
                
'<code>' $class '</code>',
                
'<code>' $parent_class '</code>',
                
'<strong>' $version '</strong>'
            
)
        );
        return;
    }

    
/**
     * Without parent class.
     */
    
if ( ! empty( $replacement ) ) {
        
/**
         * With replacement.
         */
        
call_user_func(
            
'trigger_error',
            
sprintf(
                
'The called class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
                
'<code>' $class '</code>',
                
'<strong>' $version '</strong>',
                
'<code>' $replacement '</code>'
            
)
        );
        return;
    }

    
/**
     * Without replacement.
     */
    
call_user_func(
        
'trigger_error',
        
sprintf(
            
'The called class %1$s is <strong>deprecated</strong> since version %2$s!',
            
'<code>' $class '</code>',
            
'<strong>' $version '</strong>'
        
)
    );
}
x

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