| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 2 | +defined( 'ABSPATH' ) || exit; | |
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Get the list of the names of the Imagify context currently in use. |
| 6 | 6 | * |
| @@ -25,11 +25,14 @@ | ||
| 25 | 25 | * @param array $contexts An array of context names. |
| 26 | 26 | */ |
| 27 | 27 | $contexts = (array) apply_filters( 'imagify_register_context', [] ); |
| 28 | 28 | |
| 29 | - $contexts = array_filter( $contexts, function( $context ) { | |
| 30 | - return $context && is_string( $context ); | |
| 31 | - } ); | |
| 29 | + $contexts = array_filter( | |
| 30 | + $contexts, | |
| 31 | + function ( $context ) { | |
| 32 | + return $context && is_string( $context ); | |
| 33 | + } | |
| 34 | + ); | |
| 32 | 35 | $contexts = array_merge( [ 'wp', 'custom-folders' ], $contexts ); |
| 33 | 36 | |
| 34 | 37 | sort( $contexts ); |
| 35 | 38 | |
| @@ -55,9 +58,9 @@ | ||
| 55 | 58 | * @since 1.9 |
| 56 | 59 | * @author Grégory Viguier |
| 57 | 60 | * |
| 58 | 61 | * @param string $context The context name. Default values are 'wp' and 'custom-folders'. |
| 59 | - * @return ContextInterface The context instance. | |
| 62 | + * @return \Imagify\Context\ContextInterface The context instance. | |
| 60 | 63 | */ |
| 61 | 64 | function imagify_get_context( $context ) { |
| 62 | 65 | $class_name = imagify_get_context_class_name( $context ); |
| 63 | 66 | return $class_name::get_instance(); |
| @@ -109,9 +112,9 @@ | ||
| 109 | 112 | * @author Grégory Viguier |
| 110 | 113 | * |
| 111 | 114 | * @param int $media_id The media ID. |
| 112 | 115 | * @param string $context The context name. Default values are 'wp' and 'custom-folders'. |
| 113 | - * @return ProcessInterface The optimization process instance. | |
| 116 | + * @return \Imagify\Optimization\Process\ProcessInterface The optimization process instance. | |
| 114 | 117 | */ |
| 115 | 118 | function imagify_get_optimization_process( $media_id, $context ) { |
| 116 | 119 | $class_name = imagify_get_optimization_process_class_name( $context ); |
| 117 | 120 | return new $class_name( $media_id ); |
| @@ -185,8 +188,34 @@ | ||
| 185 | 188 | return $path . '.webp'; |
| 186 | 189 | } |
| 187 | 190 | |
| 188 | 191 | /** |
| 192 | + * Convert a path (or URL) to its next-gen version. | |
| 193 | + * To keep the function simple: | |
| 194 | + * - Not tested if it's an image. | |
| 195 | + * - File existance is not tested. | |
| 196 | + * - If an URL is given, make sure it doesn't contain query args. | |
| 197 | + * | |
| 198 | + * @since 2.2 | |
| 199 | + * | |
| 200 | + * @param string $path A file path or URL. | |
| 201 | + * @param string $format format we are targeting. | |
| 202 | + * @return string | |
| 203 | + */ | |
| 204 | +function imagify_path_to_nextgen( $path, string $format ) { | |
| 205 | + switch ( $format ) { | |
| 206 | + case 'webp': | |
| 207 | + $path = $path . '.webp'; | |
| 208 | + break; | |
| 209 | + case 'avif': | |
| 210 | + $path = $path . '.avif'; | |
| 211 | + break; | |
| 212 | + } | |
| 213 | + | |
| 214 | + return $path; | |
| 215 | +} | |
| 216 | + | |
| 217 | +/** | |
| 189 | 218 | * Tell if the current user can optimize custom folders. |
| 190 | 219 | * |
| 191 | 220 | * @since 1.7 |
| 192 | 221 | * @author Grégory Viguier |
| @@ -221,10 +250,10 @@ | ||
| 221 | 250 | * @param string $target What we want. |
| 222 | 251 | * @param array $query_args An array of query arguments. |
| 223 | 252 | * @return string The URL. |
| 224 | 253 | */ |
| 225 | -function imagify_get_external_url( $target, $query_args = array() ) { | |
| 226 | - $site_url = IMAGIFY_APP_DOMAIN . '/'; | |
| 254 | +function imagify_get_external_url( $target, $query_args = [] ) { | |
| 255 | + $site_url = IMAGIFY_SITE_DOMAIN . '/'; | |
| 227 | 256 | $app_url = IMAGIFY_APP_DOMAIN . '/#/'; |
| 228 | 257 | |
| 229 | 258 | switch ( $target ) { |
| 230 | 259 | case 'plugin': |
| @@ -235,29 +264,14 @@ | ||
| 235 | 264 | case 'rate': |
| 236 | 265 | $url = 'https://wordpress.org/support/view/plugin-reviews/imagify?rate=5#postform'; |
| 237 | 266 | break; |
| 238 | 267 | |
| 239 | - case 'share-twitter': | |
| 240 | - $url = rawurlencode( imagify_get_external_url( 'plugin' ) ); | |
| 241 | - $url = 'https://twitter.com/intent/tweet?source=webclient&original_referer=' . $url . '&url=' . $url . '&related=imagify&hastags=performance,web,wordpress'; | |
| 242 | - break; | |
| 243 | - | |
| 244 | - case 'share-facebook': | |
| 245 | - $url = rawurlencode( imagify_get_external_url( 'plugin' ) ); | |
| 246 | - $url = 'https://www.facebook.com/sharer/sharer.php?u=' . $url; | |
| 247 | - break; | |
| 248 | - | |
| 249 | - case 'exif': | |
| 250 | - /* translators: URL to a Wikipedia page explaining what EXIF means. */ | |
| 251 | - $url = __( 'https://en.wikipedia.org/wiki/Exchangeable_image_file_format', 'imagify' ); | |
| 252 | - break; | |
| 253 | - | |
| 254 | 268 | case 'contact': |
| 255 | 269 | $lang = imagify_get_current_lang_in( 'fr' ); |
| 256 | - $paths = array( | |
| 270 | + $paths = [ | |
| 257 | 271 | 'en' => 'contact', |
| 258 | 272 | 'fr' => 'fr/contact', |
| 259 | - ); | |
| 273 | + ]; | |
| 260 | 274 | |
| 261 | 275 | $url = $site_url . $paths[ $lang ] . '/'; |
| 262 | 276 | break; |
| 263 | 277 | |
| @@ -369,13 +383,11 @@ | ||
| 369 | 383 | $icon = '<svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg"><g fill="#40B1D0" fill-rule="evenodd">'; |
| 370 | 384 | |
| 371 | 385 | switch ( $level ) { |
| 372 | 386 | case 2: |
| 387 | + case 1: | |
| 373 | 388 | $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"/>'; |
| 374 | 389 | break; |
| 375 | - case 1: | |
| 376 | - $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"/>'; | |
| 377 | - break; | |
| 378 | 390 | case 0: |
| 379 | 391 | $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"/>'; |
| 380 | 392 | } |
| 381 | 393 | |
| @@ -385,13 +397,12 @@ | ||
| 385 | 397 | } |
| 386 | 398 | |
| 387 | 399 | switch ( $level ) { |
| 388 | 400 | case 2: |
| 389 | - return sprintf( $format, __( 'Ultra', 'imagify' ) ); | |
| 390 | 401 | case 1: |
| 391 | - return sprintf( $format, __( 'Aggressive', 'imagify' ) ); | |
| 402 | + return sprintf( $format, __( 'Smart', 'imagify' ) ); | |
| 392 | 403 | case 0: |
| 393 | - return sprintf( $format, __( 'Normal', 'imagify' ) ); | |
| 404 | + return sprintf( $format, __( 'Lossless', 'imagify' ) ); | |
| 394 | 405 | } |
| 395 | 406 | |
| 396 | 407 | return ''; |
| 397 | 408 | } |
| @@ -401,15 +412,15 @@ | ||
| 401 | 412 | * |
| 402 | 413 | * @since 1.7 |
| 403 | 414 | * @author Grégory Viguier |
| 404 | 415 | * |
| 405 | - * @param array $values The array we're interested in. | |
| 406 | - * @param array $default The array we use as boundaries. | |
| 416 | + * @param array $values The array we're interested in. | |
| 417 | + * @param array $default_values The array we use as boundaries. | |
| 407 | 418 | * @return array |
| 408 | 419 | */ |
| 409 | -function imagify_merge_intersect( $values, $default ) { | |
| 410 | - $values = array_merge( $default, (array) $values ); | |
| 411 | - return array_intersect_key( $values, $default ); | |
| 420 | +function imagify_merge_intersect( $values, $default_values ) { | |
| 421 | + $values = array_merge( $default_values, (array) $values ); | |
| 422 | + return array_intersect_key( $values, $default_values ); | |
| 412 | 423 | } |
| 413 | 424 | |
| 414 | 425 | /** |
| 415 | 426 | * Returns true. |
| @@ -446,14 +457,14 @@ | ||
| 446 | 457 | * |
| 447 | 458 | * @since 1.9 |
| 448 | 459 | * @author Grégory Viguier |
| 449 | 460 | * |
| 450 | - * @param string $class The class containing the deprecated constructor. | |
| 461 | + * @param string $class_name The class containing the deprecated constructor. | |
| 451 | 462 | * @param string $version The version of WordPress that deprecated the function. |
| 452 | 463 | * @param string $replacement Optional. The function that should have been called. Default null. |
| 453 | 464 | * @param string $parent_class Optional. The parent class calling the deprecated constructor. Default empty string. |
| 454 | 465 | */ |
| 455 | -function imagify_deprecated_class( $class, $version, $replacement = null, $parent_class = '' ) { | |
| 466 | +function imagify_deprecated_class( $class_name, $version, $replacement = null, $parent_class = '' ) { | |
| 456 | 467 | |
| 457 | 468 | /** |
| 458 | 469 | * Fires when a deprecated class is called. |
| 459 | 470 | * |
| @@ -459,14 +470,14 @@ | ||
| 459 | 470 | * |
| 460 | 471 | * @since 1.9 |
| 461 | 472 | * @author Grégory Viguier |
| 462 | 473 | * |
| 463 | - * @param string $class The class containing the deprecated constructor. | |
| 474 | + * @param string $class_name The class containing the deprecated constructor. | |
| 464 | 475 | * @param string $version The version of WordPress that deprecated the function. |
| 465 | 476 | * @param string $replacement Optional. The function that should have been called. |
| 466 | 477 | * @param string $parent_class The parent class calling the deprecated constructor. |
| 467 | 478 | */ |
| 468 | - do_action( 'imagify_deprecated_class_run', $class, $version, $replacement, $parent_class ); | |
| 479 | + do_action( 'imagify_deprecated_class_run', $class_name, $version, $replacement, $parent_class ); | |
| 469 | 480 | |
| 470 | 481 | if ( ! WP_DEBUG ) { |
| 471 | 482 | return; |
| 472 | 483 | } |
| @@ -498,9 +509,9 @@ | ||
| 498 | 509 | 'trigger_error', |
| 499 | 510 | sprintf( |
| 500 | 511 | /* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: replacement class name. */ |
| 501 | 512 | __( 'The called class %1$s extending %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.', 'imagify' ), |
| 502 | - '<code>' . $class . '</code>', | |
| 513 | + '<code>' . $class_name . '</code>', | |
| 503 | 514 | '<code>' . $parent_class . '</code>', |
| 504 | 515 | '<strong>' . $version . '</strong>', |
| 505 | 516 | '<code>' . $replacement . '</code>' |
| 506 | 517 | ) |
| @@ -515,9 +526,9 @@ | ||
| 515 | 526 | 'trigger_error', |
| 516 | 527 | sprintf( |
| 517 | 528 | /* translators: 1: PHP class name, 2: PHP parent class name, 3: version number. */ |
| 518 | 529 | __( 'The called class %1$s extending %2$s is <strong>deprecated</strong> since version %3$s!', 'imagify' ), |
| 519 | - '<code>' . $class . '</code>', | |
| 530 | + '<code>' . $class_name . '</code>', | |
| 520 | 531 | '<code>' . $parent_class . '</code>', |
| 521 | 532 | '<strong>' . $version . '</strong>' |
| 522 | 533 | ) |
| 523 | 534 | ); |
| @@ -535,9 +546,9 @@ | ||
| 535 | 546 | 'trigger_error', |
| 536 | 547 | sprintf( |
| 537 | 548 | /* translators: 1: PHP class name, 2: version number, 3: replacement class name. */ |
| 538 | 549 | __( 'The called class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', 'imagify' ), |
| 539 | - '<code>' . $class . '</code>', | |
| 550 | + '<code>' . $class_name . '</code>', | |
| 540 | 551 | '<strong>' . $version . '</strong>', |
| 541 | 552 | '<code>' . $replacement . '</code>' |
| 542 | 553 | ) |
| 543 | 554 | ); |
| @@ -551,9 +562,9 @@ | ||
| 551 | 562 | 'trigger_error', |
| 552 | 563 | sprintf( |
| 553 | 564 | /* translators: 1: PHP class name, 2: version number. */ |
| 554 | 565 | __( 'The called class %1$s is <strong>deprecated</strong> since version %2$s!', 'imagify' ), |
| 555 | - '<code>' . $class . '</code>', | |
| 566 | + '<code>' . $class_name . '</code>', | |
| 556 | 567 | '<strong>' . $version . '</strong>' |
| 557 | 568 | ) |
| 558 | 569 | ); |
| 559 | 570 | return; |
| @@ -570,9 +581,9 @@ | ||
| 570 | 581 | call_user_func( |
| 571 | 582 | 'trigger_error', |
| 572 | 583 | sprintf( |
| 573 | 584 | 'The called class %1$s extending %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.', |
| 574 | - '<code>' . $class . '</code>', | |
| 585 | + '<code>' . $class_name . '</code>', | |
| 575 | 586 | '<code>' . $parent_class . '</code>', |
| 576 | 587 | '<strong>' . $version . '</strong>', |
| 577 | 588 | '<code>' . $replacement . '</code>' |
| 578 | 589 | ) |
| @@ -586,9 +597,9 @@ | ||
| 586 | 597 | call_user_func( |
| 587 | 598 | 'trigger_error', |
| 588 | 599 | sprintf( |
| 589 | 600 | 'The called class %1$s extending %2$s is <strong>deprecated</strong> since version %3$s!', |
| 590 | - '<code>' . $class . '</code>', | |
| 601 | + '<code>' . $class_name . '</code>', | |
| 591 | 602 | '<code>' . $parent_class . '</code>', |
| 592 | 603 | '<strong>' . $version . '</strong>' |
| 593 | 604 | ) |
| 594 | 605 | ); |
| @@ -605,9 +616,9 @@ | ||
| 605 | 616 | call_user_func( |
| 606 | 617 | 'trigger_error', |
| 607 | 618 | sprintf( |
| 608 | 619 | 'The called class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', |
| 609 | - '<code>' . $class . '</code>', | |
| 620 | + '<code>' . $class_name . '</code>', | |
| 610 | 621 | '<strong>' . $version . '</strong>', |
| 611 | 622 | '<code>' . $replacement . '</code>' |
| 612 | 623 | ) |
| 613 | 624 | ); |
| @@ -620,9 +631,9 @@ | ||
| 620 | 631 | call_user_func( |
| 621 | 632 | 'trigger_error', |
| 622 | 633 | sprintf( |
| 623 | 634 | 'The called class %1$s is <strong>deprecated</strong> since version %2$s!', |
| 624 | - '<code>' . $class . '</code>', | |
| 635 | + '<code>' . $class_name . '</code>', | |
| 625 | 636 | '<strong>' . $version . '</strong>' |
| 626 | 637 | ) |
| 627 | 638 | ); |
| 628 | 639 | } |