| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +use Optimole\Sdk\Optimole; | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * Class Optml_Config holds configuration for the service. |
| 5 | 7 | * |
| 6 | 8 | * @package \Optml\Inc |
| @@ -13,15 +15,18 @@ | ||
| 13 | 15 | * |
| 14 | 16 | * @var array |
| 15 | 17 | */ |
| 16 | 18 | public static $image_extensions = [ |
| 17 | - 'jpg' => 'image/jpeg', | |
| 18 | - 'jpeg' => 'image/jpeg', | |
| 19 | - 'jpe' => 'image/jpeg', | |
| 20 | - 'png' => 'image/png', | |
| 21 | - 'webp' => 'image/webp', | |
| 22 | - 'svg' => 'image/svg+xml', | |
| 23 | - 'gif' => 'image/gif', | |
| 19 | + 'jpg' => 'image/jpeg', | |
| 20 | + 'jpeg' => 'image/jpeg', | |
| 21 | + 'jpe' => 'image/jpeg', | |
| 22 | + 'png' => 'image/png', | |
| 23 | + 'heic' => 'image/heif', | |
| 24 | + 'ico' => 'image/x-icon', | |
| 25 | + 'avif' => 'image/avif', | |
| 26 | + 'webp' => 'image/webp', | |
| 27 | + 'svg' => 'image/svg+xml', | |
| 28 | + 'gif' => 'image/gif', | |
| 24 | 29 | ]; |
| 25 | 30 | /** |
| 26 | 31 | * CSS/Js mimetypes. |
| 27 | 32 | * |
| @@ -39,8 +44,11 @@ | ||
| 39 | 44 | public static $all_extensions = [ |
| 40 | 45 | 'jpg|jpeg|jpe' => 'image/jpeg', |
| 41 | 46 | 'png' => 'image/png', |
| 42 | 47 | 'webp' => 'image/webp', |
| 48 | + 'ico' => 'image/x-icon', | |
| 49 | + 'heic' => 'image/heif', | |
| 50 | + 'avif' => 'image/avif', | |
| 43 | 51 | 'svg' => 'image/svg+xml', |
| 44 | 52 | 'gif' => 'image/gif', |
| 45 | 53 | 'css' => 'text/css', |
| 46 | 54 | 'js' => 'text/javascript', |
| @@ -50,9 +58,9 @@ | ||
| 50 | 58 | * |
| 51 | 59 | * @var string |
| 52 | 60 | */ |
| 53 | 61 | |
| 54 | - public static $chars = '\/:,~\\\\.\-\–\d_@%A-Za-z\p{L}\p{M}\p{N}'; | |
| 62 | + public static $chars = '\/:,~\\\\.\-\–\d_@%^A-Za-z\p{L}\p{M}\p{N}\x{0080}-\x{017F}\x{2200}-\x{22FF}\x{2022}'; | |
| 55 | 63 | /** |
| 56 | 64 | * Service api key. |
| 57 | 65 | * |
| 58 | 66 | * @var string Service key. |
| @@ -92,17 +100,17 @@ | ||
| 92 | 100 | if ( empty( $service_settings['secret'] ) && ! defined( 'OPTML_SECRET' ) ) { |
| 93 | 101 | throw new \InvalidArgumentException( 'Optimole SDK requires service secret key.' ); // @codeCoverageIgnore |
| 94 | 102 | } |
| 95 | 103 | |
| 96 | - if ( defined( 'OPTML_KEY' ) && constant( 'OPTML_KEY' ) ) { | |
| 104 | + if ( defined( 'OPTML_KEY' ) ) { | |
| 97 | 105 | self::$key = constant( 'OPTML_KEY' ); |
| 98 | 106 | } |
| 99 | 107 | |
| 100 | - if ( defined( 'OPTML_SECRET' ) && constant( 'OPTML_SECRET' ) ) { | |
| 108 | + if ( defined( 'OPTML_SECRET' ) ) { | |
| 101 | 109 | self::$secret = constant( 'OPTML_SECRET' ); |
| 102 | 110 | } |
| 103 | 111 | |
| 104 | - if ( defined( 'OPTML_BASE_DOMAIN' ) && constant( 'OPTML_BASE_DOMAIN' ) ) { | |
| 112 | + if ( defined( 'OPTML_BASE_DOMAIN' ) ) { | |
| 105 | 113 | self::$base_domain = constant( 'OPTML_BASE_DOMAIN' ); |
| 106 | 114 | } |
| 107 | 115 | |
| 108 | 116 | if ( ! empty( $service_settings['key'] ) ) { |
| @@ -112,11 +120,31 @@ | ||
| 112 | 120 | if ( ! empty( $service_settings['secret'] ) ) { |
| 113 | 121 | self::$secret = trim( $service_settings['secret'] ); |
| 114 | 122 | } |
| 115 | 123 | self::$service_url = sprintf( 'https://%s.%s', self::$key, self::$base_domain ); |
| 116 | - if ( isset( $service_settings['domain'] ) && ! empty( $service_settings['domain'] ) ) { | |
| 117 | - self::$service_url = $service_settings['domain']; | |
| 118 | - } elseif ( defined( 'OPTML_CUSTOM_DOMAIN' ) && constant( 'OPTML_CUSTOM_DOMAIN' ) ) { | |
| 124 | + if ( defined( 'OPTML_CUSTOM_DOMAIN' ) ) { | |
| 119 | 125 | self::$service_url = constant( 'OPTML_CUSTOM_DOMAIN' ); |
| 126 | + } elseif ( isset( $service_settings['domain'] ) && ! empty( $service_settings['domain'] ) ) { | |
| 127 | + self::$service_url = sprintf( 'https://%s', $service_settings['domain'] ); | |
| 120 | 128 | } |
| 129 | + | |
| 130 | + $options = [ 'domain' => parse_url( self::$service_url, PHP_URL_HOST ) ]; | |
| 131 | + | |
| 132 | + if ( defined( 'OPTIML_API_ROOT' ) ) { | |
| 133 | + $options['dashboard_api_url'] = OPTIML_API_ROOT; | |
| 134 | + } | |
| 135 | + | |
| 136 | + if ( defined( 'OPTIML_UPLOAD_API_ROOT' ) ) { | |
| 137 | + $options['upload_api_url'] = OPTIML_UPLOAD_API_ROOT; | |
| 138 | + } | |
| 139 | + | |
| 140 | + if ( isset( $service_settings['key'], $service_settings['secret'], $service_settings['api_key'] ) ) { | |
| 141 | + $options['upload_api_credentials'] = [ | |
| 142 | + 'userKey' => $service_settings['key'], | |
| 143 | + 'secret' => $service_settings['secret'], | |
| 144 | + ]; | |
| 145 | + $options['dashboard_api_key'] = $service_settings['api_key']; | |
| 146 | + } | |
| 147 | + | |
| 148 | + Optimole::init( self::$key, $options ); | |
| 121 | 149 | } |
| 122 | 150 | } |