|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ImageOptimize plugin for Craft CMS 3.x |
|
4
|
|
|
* |
|
5
|
|
|
* Automatically optimize images after they've been transformed |
|
6
|
|
|
* |
|
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2020 nystudio107 |
|
|
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace nystudio107\imageoptimize\utilities; |
|
12
|
|
|
|
|
13
|
|
|
use nystudio107\imageoptimize\helpers\Settings as SettingsHelper; |
|
|
|
|
|
|
14
|
|
|
use nystudio107\imageoptimize\ImageOptimize; |
|
15
|
|
|
use nystudio107\imageoptimize\assetbundles\imageoptimizeutility\ImageOptimizeUtilityAsset; |
|
16
|
|
|
|
|
17
|
|
|
use Craft; |
|
18
|
|
|
use craft\base\Utility; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* ImageOptimize Utility |
|
22
|
|
|
* |
|
23
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
24
|
|
|
* @package ImageOptimize |
|
|
|
|
|
|
25
|
|
|
* @since 1.0.0 |
|
|
|
|
|
|
26
|
|
|
*/ |
|
|
|
|
|
|
27
|
|
|
class ImageOptimizeUtility extends Utility |
|
28
|
|
|
{ |
|
29
|
|
|
// Static |
|
30
|
|
|
// ========================================================================= |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
|
|
|
|
|
33
|
|
|
* @inheritdoc |
|
34
|
|
|
*/ |
|
|
|
|
|
|
35
|
|
|
public static function displayName(): string |
|
36
|
|
|
{ |
|
37
|
|
|
return Craft::t('image-optimize', 'ImageOptimize Info'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
|
|
|
|
|
41
|
|
|
* @inheritdoc |
|
42
|
|
|
*/ |
|
|
|
|
|
|
43
|
|
|
public static function id(): string |
|
44
|
|
|
{ |
|
45
|
|
|
return 'imageoptimize-image-optimize-utility'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
|
|
|
|
|
49
|
|
|
* @inheritdoc |
|
50
|
|
|
*/ |
|
|
|
|
|
|
51
|
|
|
public static function iconPath() |
|
52
|
|
|
{ |
|
53
|
|
|
return Craft::getAlias("@nystudio107/imageoptimize/assetbundles/imageoptimizeutility/dist/img/ImageOptimizeUtility-icon.svg"); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
|
|
|
|
|
57
|
|
|
* @inheritdoc |
|
58
|
|
|
*/ |
|
|
|
|
|
|
59
|
|
|
public static function badgeCount(): int |
|
60
|
|
|
{ |
|
61
|
|
|
return 0; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
|
|
|
|
|
65
|
|
|
* @inheritdoc |
|
66
|
|
|
*/ |
|
|
|
|
|
|
67
|
|
|
public static function contentHtml(): string |
|
68
|
|
|
{ |
|
69
|
|
|
Craft::$app->getView()->registerAssetBundle(ImageOptimizeUtilityAsset::class); |
|
70
|
|
|
|
|
71
|
|
|
$imageProcessors = ImageOptimize::$plugin->optimize->getActiveImageProcessors(); |
|
72
|
|
|
$variantCreators = ImageOptimize::$plugin->optimize->getActiveVariantCreators(); |
|
73
|
|
|
|
|
74
|
|
|
return Craft::$app->getView()->renderTemplate( |
|
75
|
|
|
'image-optimize/_components/utilities/ImageOptimizeUtility_content', |
|
76
|
|
|
[ |
|
77
|
|
|
'imageProcessors' => $imageProcessors, |
|
78
|
|
|
'variantCreators' => $variantCreators, |
|
79
|
|
|
] |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|