PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / trunk
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization vtrunk
4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 All 136 releases
← All changes | inc/config.php +52 -15 2.5.7 → trunk View file →
@@ -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.
@@ -69,8 +77,14 @@
69 77 *
70 78 * @var string Service url.
71 79 */
72 80 public static $service_url = '';
81 + /**
82 + * Base domain.
83 + *
84 + * @var string Base domain.
85 + */
86 + public static $base_domain = 'i.optimole.com';
73 87
74 88 /**
75 89 * Service settings.
76 90 *
@@ -86,16 +100,20 @@
86 100 if ( empty( $service_settings['secret'] ) && ! defined( 'OPTML_SECRET' ) ) {
87 101 throw new \InvalidArgumentException( 'Optimole SDK requires service secret key.' ); // @codeCoverageIgnore
88 102 }
89 103
90 - if ( defined( 'OPTML_KEY' ) && constant( 'OPTML_KEY' ) ) {
104 + if ( defined( 'OPTML_KEY' ) ) {
91 105 self::$key = constant( 'OPTML_KEY' );
92 106 }
93 107
94 - if ( defined( 'OPTML_SECRET' ) && constant( 'OPTML_SECRET' ) ) {
108 + if ( defined( 'OPTML_SECRET' ) ) {
95 109 self::$secret = constant( 'OPTML_SECRET' );
96 110 }
97 111
112 + if ( defined( 'OPTML_BASE_DOMAIN' ) ) {
113 + self::$base_domain = constant( 'OPTML_BASE_DOMAIN' );
114 + }
115 +
98 116 if ( ! empty( $service_settings['key'] ) ) {
99 117 self::$key = trim( strtolower( $service_settings['key'] ) );
100 118 }
101 119
@@ -101,13 +119,32 @@
101 119
102 120 if ( ! empty( $service_settings['secret'] ) ) {
103 121 self::$secret = trim( $service_settings['secret'] );
104 122 }
123 + self::$service_url = sprintf( 'https://%s.%s', self::$key, self::$base_domain );
124 + if ( defined( 'OPTML_CUSTOM_DOMAIN' ) ) {
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'] );
128 + }
105 129
106 - self::$service_url = sprintf( 'https://%s.i.optimole.com', self::$key );
107 - if ( isset( $service_settings['domain'] ) && ! empty( $service_settings['domain'] ) ) {
108 - self::$service_url = $service_settings['domain'];
109 - } elseif ( defined( 'OPTML_CUSTOM_DOMAIN' ) && constant( 'OPTML_CUSTOM_DOMAIN' ) ) {
110 - self::$service_url = constant( 'OPTML_CUSTOM_DOMAIN' );
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;
111 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 );
112 149 }
113 150 }