@@ -39,16 +39,16 @@ |
||
| 39 | 39 | |
| 40 | 40 | // Primary getter functions |
| 41 | 41 | $fieldObject->addStringField('src') |
| 42 | - ->arguments(function (\markhuot\CraftQL\Builders\Field $field) { |
|
| 42 | + ->arguments(function(\markhuot\CraftQL\Builders\Field $field) { |
|
| 43 | 43 | $field->addIntArgument('width'); |
| 44 | 44 | }) |
| 45 | - ->resolve(function ($root, $args) { |
|
| 45 | + ->resolve(function($root, $args) { |
|
| 46 | 46 | return $root->src(@$args['width'] ?: 0); |
| 47 | 47 | }); |
| 48 | 48 | $fieldObject->addField('srcUrls') |
| 49 | 49 | ->lists() |
| 50 | 50 | ->type($srcObject) |
| 51 | - ->resolve(function ($root, $args) { |
|
| 51 | + ->resolve(function($root, $args) { |
|
| 52 | 52 | $result = []; |
| 53 | 53 | foreach ($root->optimizedImageUrls as $width => $url) { |
| 54 | 54 | $result[] = ['width' => $width, 'url' => $url]; |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public static function RGBToHSL(array $rgb): array |
| 60 | 60 | { |
| 61 | - $r = ((float)$rgb['r']) / 255.0; |
|
| 62 | - $g = ((float)$rgb['g']) / 255.0; |
|
| 63 | - $b = ((float)$rgb['b']) / 255.0; |
|
| 61 | + $r = ((float) $rgb['r']) / 255.0; |
|
| 62 | + $g = ((float) $rgb['g']) / 255.0; |
|
| 63 | + $b = ((float) $rgb['b']) / 255.0; |
|
| 64 | 64 | |
| 65 | 65 | $maxC = max($r, $g, $b); |
| 66 | 66 | $minC = min($r, $g, $b); |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | $h /= 6.0; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $h = (int)round(360.0 * $h); |
|
| 92 | - $s = (int)round(100.0 * $s); |
|
| 93 | - $l = (int)round(100.0 * $l); |
|
| 91 | + $h = (int) round(360.0 * $h); |
|
| 92 | + $s = (int) round(100.0 * $s); |
|
| 93 | + $l = (int) round(100.0 * $l); |
|
| 94 | 94 | |
| 95 | 95 | return ['h' => $h, 's' => $s, 'l' => $l]; |
| 96 | 96 | } |
@@ -51,8 +51,8 @@ |
||
| 51 | 51 | // It takes a bit of time, so if you never plan to use it, you can turn it off |
| 52 | 52 | 'createColorPalette' => true, |
| 53 | 53 | |
| 54 | - // Controls whether SVG placeholder silhouettes should be created for image variants |
|
| 55 | - // It takes a bit of time, so if you never plan to use them, you can turn it off |
|
| 54 | + // Controls whether SVG placeholder silhouettes should be created for image variants |
|
| 55 | + // It takes a bit of time, so if you never plan to use them, you can turn it off |
|
| 56 | 56 | 'createPlaceholderSilhouettes' => false, |
| 57 | 57 | |
| 58 | 58 | // Controls whether retina images are automatically created with reduced quality |
@@ -148,14 +148,14 @@ discard block |
||
| 148 | 148 | { |
| 149 | 149 | $path = $this->decomposeUrl($pathOrUrl); |
| 150 | 150 | $path_parts = pathinfo($path['path']); |
| 151 | - $new_path = ($path_parts['filename'] ?? '') . '.' . ($path_parts['extension'] ?? '') . $extension; |
|
| 151 | + $new_path = ($path_parts['filename'] ?? '').'.'.($path_parts['extension'] ?? '').$extension; |
|
| 152 | 152 | if (!empty($path_parts['dirname']) && $path_parts['dirname'] !== '.') { |
| 153 | 153 | $dirname = $path_parts['dirname']; |
| 154 | 154 | $dirname = $dirname === '/' ? '' : $dirname; |
| 155 | - $new_path = $dirname . DIRECTORY_SEPARATOR . $new_path; |
|
| 155 | + $new_path = $dirname.DIRECTORY_SEPARATOR.$new_path; |
|
| 156 | 156 | $new_path = preg_replace('/([^:])(\/{2,})/', '$1/', $new_path); |
| 157 | 157 | } |
| 158 | - $output = $path['prefix'] . $new_path . $path['suffix']; |
|
| 158 | + $output = $path['prefix'].$new_path.$path['suffix']; |
|
| 159 | 159 | |
| 160 | 160 | return $output; |
| 161 | 161 | } |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | if (filter_var($pathOrUrl, FILTER_VALIDATE_URL)) { |
| 178 | 178 | $url_parts = parse_url($pathOrUrl); |
| 179 | - $result['prefix'] = $url_parts['scheme'] . '://' . $url_parts['host']; |
|
| 179 | + $result['prefix'] = $url_parts['scheme'].'://'.$url_parts['host']; |
|
| 180 | 180 | if (!empty($url_parts['port'])) { |
| 181 | - $result['prefix'] .= ':' . $url_parts['port']; |
|
| 181 | + $result['prefix'] .= ':'.$url_parts['port']; |
|
| 182 | 182 | } |
| 183 | 183 | $result['path'] = $url_parts['path']; |
| 184 | 184 | $result['suffix'] = ''; |
| 185 | - $result['suffix'] .= empty($url_parts['query']) ? '' : '?' . $url_parts['query']; |
|
| 186 | - $result['suffix'] .= empty($url_parts['fragment']) ? '' : '#' . $url_parts['fragment']; |
|
| 185 | + $result['suffix'] .= empty($url_parts['query']) ? '' : '?'.$url_parts['query']; |
|
| 186 | + $result['suffix'] .= empty($url_parts['fragment']) ? '' : '#'.$url_parts['fragment']; |
|
| 187 | 187 | } else { |
| 188 | 188 | $result['prefix'] = ''; |
| 189 | 189 | $result['path'] = $pathOrUrl; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | ); |
| 89 | 89 | $result = ''; |
| 90 | 90 | $width = self::PLACEHOLDER_WIDTH; |
| 91 | - $height = (int)($width / $aspectRatio); |
|
| 91 | + $height = (int) ($width / $aspectRatio); |
|
| 92 | 92 | $placeholderPath = $this->createImageFromPath($tempPath, $width, $height, self::PLACEHOLDER_QUALITY, $position); |
| 93 | 93 | if (!empty($placeholderPath)) { |
| 94 | 94 | $result = base64_encode(file_get_contents($placeholderPath)); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | Craft::beginProfile('generateColorPalette', __METHOD__); |
| 112 | 112 | Craft::info( |
| 113 | - 'Generating color palette for: ' . $tempPath, |
|
| 113 | + 'Generating color palette for: '.$tempPath, |
|
| 114 | 114 | __METHOD__ |
| 115 | 115 | ); |
| 116 | 116 | $colorPalette = []; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $lightness /= $colorCount; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - return $lightness === null ? $lightness : (int)$lightness; |
|
| 159 | + return $lightness === null ? $lightness : (int) $lightness; |
|
| 160 | 160 | } |
| 161 | 161 | /** |
| 162 | 162 | * Generate an SVG image via Potrace |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | __METHOD__ |
| 220 | 220 | ); |
| 221 | 221 | $width = self::TEMP_PLACEHOLDER_WIDTH; |
| 222 | - $height = (int)($width / $aspectRatio); |
|
| 222 | + $height = (int) ($width / $aspectRatio); |
|
| 223 | 223 | $tempPath = $this->createImageFromAsset($asset, $width, $height, self::TEMP_PLACEHOLDER_QUALITY, $position); |
| 224 | 224 | Craft::endProfile('createTempPlaceholderImage', __METHOD__); |
| 225 | 225 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | while ($currentElement < $totalElements) { |
| 92 | 92 | $elements = $paginator->getPageResults(); |
| 93 | 93 | if (Craft::$app instanceof ConsoleApplication) { |
| 94 | - echo 'Query ' . $paginator->getCurrentPage() . '/' . $paginator->getTotalPages() |
|
| 95 | - . ' - assets: ' . $paginator->getTotalResults() |
|
| 94 | + echo 'Query '.$paginator->getCurrentPage().'/'.$paginator->getTotalPages() |
|
| 95 | + . ' - assets: '.$paginator->getTotalResults() |
|
| 96 | 96 | . PHP_EOL; |
| 97 | 97 | } |
| 98 | 98 | /** @var ElementInterface $element */ |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | if ($field instanceof OptimizedImagesField && $element instanceof Asset) { |
| 108 | 108 | if ($this->fieldId === null || $field->id == $this->fieldId) { |
| 109 | 109 | if (Craft::$app instanceof ConsoleApplication) { |
| 110 | - echo $currentElement . '/' . $totalElements |
|
| 111 | - . ' - processing asset: ' . $element->title |
|
| 112 | - . ' from field: ' . $field->name . PHP_EOL; |
|
| 110 | + echo $currentElement.'/'.$totalElements |
|
| 111 | + . ' - processing asset: '.$element->title |
|
| 112 | + . ' from field: '.$field->name.PHP_EOL; |
|
| 113 | 113 | } |
| 114 | 114 | try { |
| 115 | 115 | ImageOptimize::$plugin->optimizedImages->updateOptimizedImageFieldData($field, $element, $this->force); |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | echo '[error]: ' |
| 120 | 120 | . $e->getMessage() |
| 121 | 121 | . ' while processing ' |
| 122 | - . $currentElement . '/' . $totalElements |
|
| 123 | - . ' - processing asset: ' . $element->title |
|
| 124 | - . ' from field: ' . $field->name . PHP_EOL; |
|
| 122 | + . $currentElement.'/'.$totalElements |
|
| 123 | + . ' - processing asset: '.$element->title |
|
| 124 | + . ' from field: '.$field->name.PHP_EOL; |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | array $params = [], |
| 64 | 64 | string $minifier = null |
| 65 | 65 | ): string { |
| 66 | - $template = 'image-optimize/' . $templatePath; |
|
| 66 | + $template = 'image-optimize/'.$templatePath; |
|
| 67 | 67 | $oldMode = Craft::$app->view->getTemplateMode(); |
| 68 | 68 | // Look for the template on the frontend first |
| 69 | 69 | try { |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | */ |
| 555 | 555 | public function getPlaceholderImage(): string |
| 556 | 556 | { |
| 557 | - return (string)$this->placeholderImage(); |
|
| 557 | + return (string) $this->placeholderImage(); |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | */ |
| 592 | 592 | public function getPlaceholderBox(string $color = null): string |
| 593 | 593 | { |
| 594 | - return (string)$this->placeholderBox($color); |
|
| 594 | + return (string) $this->placeholderBox($color); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | */ |
| 633 | 633 | public function getPlaceholderSilhouette(): string |
| 634 | 634 | { |
| 635 | - return (string)$this->placeholderSilhouette(); |
|
| 635 | + return (string) $this->placeholderSilhouette(); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -744,10 +744,10 @@ discard block |
||
| 744 | 744 | foreach ($array as $key => $value) { |
| 745 | 745 | if ($dpr) { |
| 746 | 746 | $descriptor = '1x'; |
| 747 | - if (!empty($array[(int)$key / 2])) { |
|
| 747 | + if (!empty($array[(int) $key / 2])) { |
|
| 748 | 748 | $descriptor = '2x'; |
| 749 | 749 | } |
| 750 | - if (!empty($array[(int)$key / 3])) { |
|
| 750 | + if (!empty($array[(int) $key / 3])) { |
|
| 751 | 751 | $descriptor = '3x'; |
| 752 | 752 | } |
| 753 | 753 | } else { |
@@ -787,13 +787,13 @@ discard block |
||
| 787 | 787 | { |
| 788 | 788 | // Set the class and loading attributes |
| 789 | 789 | if (isset($attrs['class'])) { |
| 790 | - $attrs['class'] = trim($attrs['class'] . ' lazyload'); |
|
| 790 | + $attrs['class'] = trim($attrs['class'].' lazyload'); |
|
| 791 | 791 | } |
| 792 | 792 | // Set the style on this element to be the placeholder image as the background-image |
| 793 | 793 | if (isset($attrs['style']) && !empty($attrs['src'])) { |
| 794 | 794 | $attrs['style'] = trim( |
| 795 | - $attrs['style'] . |
|
| 796 | - 'background-image:url(' . $this->getLazyLoadSrc($placeHolder) . '); background-size: cover;' |
|
| 795 | + $attrs['style']. |
|
| 796 | + 'background-image:url('.$this->getLazyLoadSrc($placeHolder).'); background-size: cover;' |
|
| 797 | 797 | ); |
| 798 | 798 | } |
| 799 | 799 | // Handle attributes that lazy and lazySizesFallback have in common |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | Event::on( |
| 288 | 288 | CraftVariable::class, |
| 289 | 289 | CraftVariable::EVENT_INIT, |
| 290 | - function (Event $event) { |
|
| 290 | + function(Event $event) { |
|
| 291 | 291 | /** @var CraftVariable $variable */ |
| 292 | 292 | $variable = $event->sender; |
| 293 | 293 | $variable->set('imageOptimize', [ |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | Event::on( |
| 302 | 302 | Fields::class, |
| 303 | 303 | Fields::EVENT_REGISTER_FIELD_TYPES, |
| 304 | - function (RegisterComponentTypesEvent $event) { |
|
| 304 | + function(RegisterComponentTypesEvent $event) { |
|
| 305 | 305 | Craft::debug( |
| 306 | 306 | 'Fields::EVENT_REGISTER_FIELD_TYPES', |
| 307 | 307 | __METHOD__ |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | Event::on( |
| 316 | 316 | Utilities::class, |
| 317 | 317 | Utilities::EVENT_REGISTER_UTILITY_TYPES, |
| 318 | - function (RegisterComponentTypesEvent $event) { |
|
| 318 | + function(RegisterComponentTypesEvent $event) { |
|
| 319 | 319 | $event->types[] = ImageOptimizeUtility::class; |
| 320 | 320 | } |
| 321 | 321 | ); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | Event::on( |
| 352 | 352 | Assets::class, |
| 353 | 353 | Assets::EVENT_GET_ASSET_URL, |
| 354 | - function (GetAssetUrlEvent $event) { |
|
| 354 | + function(GetAssetUrlEvent $event) { |
|
| 355 | 355 | Craft::debug( |
| 356 | 356 | 'Assets::EVENT_GET_ASSET_URL', |
| 357 | 357 | __METHOD__ |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | Event::on( |
| 368 | 368 | Assets::class, |
| 369 | 369 | Assets::EVENT_GET_ASSET_THUMB_URL, |
| 370 | - function (GetAssetThumbUrlEvent $event) { |
|
| 370 | + function(GetAssetThumbUrlEvent $event) { |
|
| 371 | 371 | Craft::debug( |
| 372 | 372 | 'Assets::EVENT_GET_ASSET_THUMB_URL', |
| 373 | 373 | __METHOD__ |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | Event::on( |
| 384 | 384 | AssetTransforms::class, |
| 385 | 385 | AssetTransforms::EVENT_GENERATE_TRANSFORM, |
| 386 | - function (GenerateTransformEvent $event) { |
|
| 386 | + function(GenerateTransformEvent $event) { |
|
| 387 | 387 | Craft::debug( |
| 388 | 388 | 'AssetTransforms::EVENT_GENERATE_TRANSFORM', |
| 389 | 389 | __METHOD__ |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | Event::on( |
| 400 | 400 | AssetTransforms::class, |
| 401 | 401 | AssetTransforms::EVENT_AFTER_DELETE_TRANSFORMS, |
| 402 | - function (AssetTransformImageEvent $event) { |
|
| 402 | + function(AssetTransformImageEvent $event) { |
|
| 403 | 403 | Craft::debug( |
| 404 | 404 | 'AssetTransforms::EVENT_AFTER_DELETE_TRANSFORMS', |
| 405 | 405 | __METHOD__ |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | Event::on( |
| 416 | 416 | Assets::class, |
| 417 | 417 | Assets::EVENT_BEFORE_REPLACE_ASSET, |
| 418 | - function (ReplaceAssetEvent $event) { |
|
| 418 | + function(ReplaceAssetEvent $event) { |
|
| 419 | 419 | Craft::debug( |
| 420 | 420 | 'Assets::EVENT_BEFORE_REPLACE_ASSET', |
| 421 | 421 | __METHOD__ |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | Event::on( |
| 435 | 435 | Assets::class, |
| 436 | 436 | Assets::EVENT_AFTER_REPLACE_ASSET, |
| 437 | - function (ReplaceAssetEvent $event) { |
|
| 437 | + function(ReplaceAssetEvent $event) { |
|
| 438 | 438 | Craft::debug( |
| 439 | 439 | 'Assets::EVENT_AFTER_REPLACE_ASSET', |
| 440 | 440 | __METHOD__ |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | Event::on( |
| 458 | 458 | Assets::class, |
| 459 | 459 | Elements::EVENT_BEFORE_SAVE_ELEMENT, |
| 460 | - function (ElementEvent $event) { |
|
| 460 | + function(ElementEvent $event) { |
|
| 461 | 461 | Craft::debug( |
| 462 | 462 | 'Elements::EVENT_BEFORE_SAVE_ELEMENT', |
| 463 | 463 | __METHOD__ |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | Event::on( |
| 479 | 479 | Asset::class, |
| 480 | 480 | Elements::EVENT_BEFORE_DELETE_ELEMENT, |
| 481 | - function (ElementEvent $event) { |
|
| 481 | + function(ElementEvent $event) { |
|
| 482 | 482 | Craft::debug( |
| 483 | 483 | 'Elements::EVENT_BEFORE_DELETE_ELEMENT', |
| 484 | 484 | __METHOD__ |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | Event::on( |
| 504 | 504 | Fields::class, |
| 505 | 505 | Fields::EVENT_AFTER_SAVE_FIELD, |
| 506 | - function (FieldEvent $event) { |
|
| 506 | + function(FieldEvent $event) { |
|
| 507 | 507 | Craft::debug( |
| 508 | 508 | 'Fields::EVENT_AFTER_SAVE_FIELD', |
| 509 | 509 | __METHOD__ |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | Event::on( |
| 521 | 521 | Plugins::class, |
| 522 | 522 | Plugins::EVENT_AFTER_SAVE_PLUGIN_SETTINGS, |
| 523 | - function (PluginEvent $event) { |
|
| 523 | + function(PluginEvent $event) { |
|
| 524 | 524 | if ($event->plugin === $this) { |
| 525 | 525 | Craft::debug( |
| 526 | 526 | 'Plugins::EVENT_AFTER_SAVE_PLUGIN_SETTINGS', |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | Event::on( |
| 540 | 540 | Volumes::class, |
| 541 | 541 | Volumes::EVENT_AFTER_SAVE_VOLUME, |
| 542 | - function (VolumeEvent $event) { |
|
| 542 | + function(VolumeEvent $event) { |
|
| 543 | 543 | Craft::debug( |
| 544 | 544 | 'Volumes::EVENT_AFTER_SAVE_VOLUME', |
| 545 | 545 | __METHOD__ |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | Event::on( |
| 561 | 561 | Plugins::class, |
| 562 | 562 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
| 563 | - function (PluginEvent $event) { |
|
| 563 | + function(PluginEvent $event) { |
|
| 564 | 564 | if ($event->plugin === $this) { |
| 565 | 565 | $request = Craft::$app->getRequest(); |
| 566 | 566 | if ($request->isCpRequest) { |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | Event::on( |
| 595 | 595 | UrlManager::class, |
| 596 | 596 | UrlManager::EVENT_REGISTER_SITE_URL_RULES, |
| 597 | - function (RegisterUrlRulesEvent $event) { |
|
| 597 | + function(RegisterUrlRulesEvent $event) { |
|
| 598 | 598 | Craft::debug( |
| 599 | 599 | 'UrlManager::EVENT_REGISTER_SITE_URL_RULES', |
| 600 | 600 | __METHOD__ |
@@ -617,12 +617,12 @@ discard block |
||
| 617 | 617 | Event::on( |
| 618 | 618 | Plugins::class, |
| 619 | 619 | Plugins::EVENT_AFTER_LOAD_PLUGINS, |
| 620 | - function () { |
|
| 620 | + function() { |
|
| 621 | 621 | // Install these only after all other plugins have loaded |
| 622 | 622 | Event::on( |
| 623 | 623 | View::class, |
| 624 | 624 | View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, |
| 625 | - function (RegisterTemplateRootsEvent $e) { |
|
| 625 | + function(RegisterTemplateRootsEvent $e) { |
|
| 626 | 626 | // Register the root directodies |
| 627 | 627 | $allImageTransformTypes = ImageOptimize::$plugin->optimize->getAllImageTransformTypes(); |
| 628 | 628 | /** @var ImageTransformInterface $imageTransformType */ |