PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 3.11.2
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v3.11.2
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 3.12.0 3.12.1 All 134 releases
optimole-wp / inc / config.php

config.php in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 3.11.2, at inc/config.php

129 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Optml_Config holds configuration for the service.
5 *
6 * @package \Optml\Inc
7 * @author Optimole <friends@optimole.com>
8 */
9 class Optml_Config {
10
11 /**
12 * A list of allowed extensions.
13 *
14 * @var array
15 */
16 public static $image_extensions = [
17 'jpg' => 'image/jpeg',
18 'jpeg' => 'image/jpeg',
19 'jpe' => 'image/jpeg',
20 'png' => 'image/png',
21 'heic' => 'image/heif',
22 'ico' => 'image/x-icon',
23 'avif' => 'image/avif',
24 'webp' => 'image/webp',
25 'svg' => 'image/svg+xml',
26 'gif' => 'image/gif',
27 ];
28 /**
29 * CSS/Js mimetypes.
30 *
31 * @var string[]
32 */
33 public static $assets_extensions = [
34 'css' => 'text/css',
35 'js' => 'text/javascript',
36 ];
37 /**
38 * All extensions that Optimole process.
39 *
40 * @var string[]
41 */
42 public static $all_extensions = [
43 'jpg|jpeg|jpe' => 'image/jpeg',
44 'png' => 'image/png',
45 'webp' => 'image/webp',
46 'ico' => 'image/x-icon',
47 'heic' => 'image/heif',
48 'avif' => 'image/avif',
49 'svg' => 'image/svg+xml',
50 'gif' => 'image/gif',
51 'css' => 'text/css',
52 'js' => 'text/javascript',
53 ];
54 /**
55 * A string of allowed chars.
56 *
57 * @var string
58 */
59
60 public static $chars = '\/:,~\\\\.\-\–\d_@%^A-Za-z\p{L}\p{M}\p{N}\x{0080}-\x{017F}\x{2200}-\x{22FF}\x{2022}';
61 /**
62 * Service api key.
63 *
64 * @var string Service key.
65 */
66 public static $key = '';
67 /**
68 * Service secret key used for signing the requests.
69 *
70 * @var string Secret key.
71 */
72 public static $secret = '';
73 /**
74 * Service url.
75 *
76 * @var string Service url.
77 */
78 public static $service_url = '';
79 /**
80 * Base domain.
81 *
82 * @var string Base domain.
83 */
84 public static $base_domain = 'i.optimole.com';
85
86 /**
87 * Service settings.
88 *
89 * @param array $service_settings Service settings.
90 *
91 * @throws \InvalidArgumentException In case that key or secret is not provided.
92 */
93 public static function init( $service_settings = [] ) {
94
95 if ( empty( $service_settings['key'] ) && ! defined( 'OPTML_KEY' ) ) {
96 throw new \InvalidArgumentException( 'Optimole SDK requires service api key.' ); // @codeCoverageIgnore
97 }
98 if ( empty( $service_settings['secret'] ) && ! defined( 'OPTML_SECRET' ) ) {
99 throw new \InvalidArgumentException( 'Optimole SDK requires service secret key.' ); // @codeCoverageIgnore
100 }
101
102 if ( defined( 'OPTML_KEY' ) && constant( 'OPTML_KEY' ) ) {
103 self::$key = constant( 'OPTML_KEY' );
104 }
105
106 if ( defined( 'OPTML_SECRET' ) && constant( 'OPTML_SECRET' ) ) {
107 self::$secret = constant( 'OPTML_SECRET' );
108 }
109
110 if ( defined( 'OPTML_BASE_DOMAIN' ) && constant( 'OPTML_BASE_DOMAIN' ) ) {
111 self::$base_domain = constant( 'OPTML_BASE_DOMAIN' );
112 }
113
114 if ( ! empty( $service_settings['key'] ) ) {
115 self::$key = trim( strtolower( $service_settings['key'] ) );
116 }
117
118 if ( ! empty( $service_settings['secret'] ) ) {
119 self::$secret = trim( $service_settings['secret'] );
120 }
121 self::$service_url = sprintf( 'https://%s.%s', self::$key, self::$base_domain );
122 if ( isset( $service_settings['domain'] ) && ! empty( $service_settings['domain'] ) ) {
123 self::$service_url = sprintf( 'https://%s', $service_settings['domain'] );
124 } elseif ( defined( 'OPTML_CUSTOM_DOMAIN' ) && constant( 'OPTML_CUSTOM_DOMAIN' ) ) {
125 self::$service_url = constant( 'OPTML_CUSTOM_DOMAIN' );
126 }
127 }
128 }
129