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 / asset.php

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

113 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The class maps settings and options for assets.
5 *
6 * @package \Optml\Inc
7 * @author Optimole <friends@optimole.com>
8 */
9 class Optml_Asset extends Optml_Resource {
10
11 /**
12 * Quality of the images urls inside the assets.
13 *
14 * @var Optml_Quality Quality;
15 */
16 public $quality = null;
17
18 /**
19 * Minify of the resulting asset.
20 *
21 * @var Optml_Minify Minify;
22 */
23 public $minify = null;
24
25 /**
26 * Type of asset
27 *
28 * @var string
29 */
30 protected $type = '';
31
32 /**
33 * CSS minify
34 *
35 * @var int
36 */
37 protected $minify_css = 1;
38
39 /**
40 * JS minify
41 *
42 * @var int
43 */
44 protected $minify_js = 0;
45
46 /**
47 * Optml_Asset constructor.
48 *
49 * @param string $url Source image url.
50 * @param array $args Transformation arguments.
51 *
52 * @throws \InvalidArgumentException In case that the url is not provided.
53 */
54 public function __construct( $url = '', $args = [], $cache_buster = '', $minify_css = 1, $minify_js = 0 ) {
55 parent::__construct( $url, $cache_buster );
56
57 $this->minify_css = $minify_css;
58 $this->minify_js = $minify_js;
59
60 if ( strpos( $url, '.css' ) ) {
61 $this->type = 'css';
62 }
63
64 if ( strpos( $url, '.js' ) ) {
65 $this->type = 'js';
66 }
67
68 $this->minify->set( $this->{'minify_' . $this->type} );
69
70 if ( isset( $args['quality'] ) ) {
71 $this->quality->set( $args['quality'] );
72 }
73 }
74
75 /**
76 * Set defaults for asset transformations.
77 */
78 protected function set_defaults() {
79 $this->quality = new Optml_Quality();
80 $this->minify = new Optml_Minify();
81 }
82
83 /**
84 * Return transformed url.
85 *
86 * @param array $params Either will be signed or not.
87 *
88 * @return string Transformed asset url.
89 */
90 public function get_url( $params = [] ) {
91 $path_parts = [];
92 if ( ! empty( $this->type ) ) {
93 $path_parts[] = 'f:' . $this->type;
94 }
95
96 $path_parts[] = $this->quality->toString();
97 $path_parts[] = $this->minify->toString();
98
99 $path = '/' . $this->source_url;
100
101 $path = sprintf( '/%s%s', implode( '/', $path_parts ), $path );
102
103 $cache_buster = $this->get_cache_buster();
104 if ( $cache_buster !== false ) {
105 $path = sprintf( '/%s%s', 'cb:' . $cache_buster, $path );
106 }
107
108 return sprintf( '%s%s', Optml_Config::$service_url, $path );
109
110 }
111
112 }
113