Skip to content

Commit 9b4e3b6

Browse files
committed
feat: replace wordpress image subsizes with cdn generated images
1 parent 297dcd2 commit 9b4e3b6

File tree

7 files changed

+1280
-1
lines changed

7 files changed

+1280
-1
lines changed

phpmd.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</rule>
1515
<rule ref="rulesets/codesize.xml">
1616
<exclude name="CyclomaticComplexity" />
17+
<exclude name="ExcessiveClassComplexity" />
1718
<exclude name="NPathComplexity" />
1819
<exclude name="TooManyPublicMethods" />
1920
</rule>
@@ -39,7 +40,7 @@
3940
externalInfoUrl="https://phpmd.org/rules/codesize.html#cyclomaticcomplexity">
4041
<priority>3</priority>
4142
<properties>
42-
<property name="reportLevel" description="The Cyclomatic Complexity reporting threshold" value="11"/>
43+
<property name="reportLevel" description="The Cyclomatic Complexity reporting threshold" value="13"/>
4344
<property name="showClassesComplexity"
4445
description="Indicate if class average violation should be added to the report"
4546
value="true"/>

src/Configuration/EventManagementConfiguration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public function modify(Container $container)
6262
if ($container['query_monitor_active']) {
6363
$subscribers[] = new Subscriber\QueryMonitorSubscriber($container['query_monitor_collectors'], $container['query_monitor_panels'], $container['plugin_dir_path'].'/resources/views/query-monitor');
6464
}
65+
if ($container['ymir_cdn_image_processing_enabled']) {
66+
$subscribers[] = new Subscriber\ContentDeliveryNetworkImageProcessingSubscriber($container['image_sizes'], $container['is_multisite'], $container['uploads_baseurl'], $container['content_width']);
67+
}
6568

6669
return $subscribers;
6770
});

src/Configuration/WordPressConfiguration.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function modify(Container $container)
3232
$container['content_directory'] = defined('WP_CONTENT_DIR') ? WP_CONTENT_DIR : '';
3333
$container['content_directory_name'] = defined('CONTENT_DIR') ? CONTENT_DIR : 'wp-content';
3434
$container['content_url'] = defined('WP_CONTENT_URL') ? WP_CONTENT_URL : '';
35+
$container['content_width'] = $container->service(function () {
36+
return isset($GLOBALS['content_width']) && is_numeric($GLOBALS['content_width']) ? (int) $GLOBALS['content_width'] : null;
37+
});
3538
$container['current_user'] = $container->service(function () {
3639
return wp_get_current_user();
3740
});
@@ -52,6 +55,40 @@ public function modify(Container $container)
5255

5356
return new \WP_Filesystem_Direct(false);
5457
});
58+
$container['image_sizes'] = $container->service(function () {
59+
$sizes = [
60+
'thumb' => [
61+
'width' => (int) get_option('thumbnail_size_w'),
62+
'height' => (int) get_option('thumbnail_size_h'),
63+
'crop' => (bool) get_option('thumbnail_crop'),
64+
],
65+
'medium' => [
66+
'width' => (int) get_option('medium_size_w'),
67+
'height' => (int) get_option('medium_size_h'),
68+
'crop' => false,
69+
],
70+
'medium_large' => [
71+
'width' => (int) get_option('medium_large_size_w'),
72+
'height' => (int) get_option('medium_large_size_h'),
73+
'crop' => false,
74+
],
75+
'large' => [
76+
'width' => (int) get_option('large_size_w'),
77+
'height' => (int) get_option('large_size_h'),
78+
'crop' => false,
79+
],
80+
'full' => [
81+
'width' => null,
82+
'height' => null,
83+
'crop' => false,
84+
],
85+
];
86+
87+
// Compatibility mapping as found in wp-includes/media.php.
88+
$sizes['thumbnail'] = $sizes['thumb'];
89+
90+
return array_merge($sizes, wp_get_additional_image_sizes());
91+
});
5592
$container['is_multisite'] = is_multisite();
5693
$container['phpmailer'] = function () {
5794
if (!class_exists(\PHPMailer::class)) {

src/Configuration/YmirConfiguration.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ class YmirConfiguration implements ContainerConfigurationInterface
2727
*/
2828
public function modify(Container $container)
2929
{
30+
$container['ymir_cdn_image_processing_enabled'] = $container->service(function () {
31+
if (defined('YMIR_CDN_IMAGE_PROCESSING_ENABLED')) {
32+
return (bool) YMIR_CDN_IMAGE_PROCESSING_ENABLED;
33+
} elseif (false !== getenv('YMIR_CDN_IMAGE_PROCESSING_ENABLED')) {
34+
return (bool) getenv('YMIR_CDN_IMAGE_PROCESSING_ENABLED');
35+
}
36+
37+
return false;
38+
});
3039
$container['ymir_environment'] = getenv('YMIR_ENVIRONMENT') ?: '';
3140
$container['ymir_http_client'] = $container->service(function (Container $container) {
3241
return new Client($container['ymir_plugin_version']);

0 commit comments

Comments
 (0)