From c4e10cf59f643806daea8b2009c3fcfe42e8d9e1 Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Fri, 11 Feb 2022 10:26:11 +0100 Subject: [PATCH 1/5] Add Vector image auto_sizes support --- .../Grav/Common/Page/Medium/MediumFactory.php | 3 +- .../Common/Page/Medium/VectorImageMedium.php | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 system/src/Grav/Common/Page/Medium/VectorImageMedium.php diff --git a/system/src/Grav/Common/Page/Medium/MediumFactory.php b/system/src/Grav/Common/Page/Medium/MediumFactory.php index 620446b70..913f198f1 100644 --- a/system/src/Grav/Common/Page/Medium/MediumFactory.php +++ b/system/src/Grav/Common/Page/Medium/MediumFactory.php @@ -159,8 +159,9 @@ class MediumFactory return new ImageMedium($items, $blueprint); case 'thumbnail': return new ThumbnailImageMedium($items, $blueprint); - case 'animated': case 'vector': + return new VectorImageMedium($items, $blueprint); + case 'animated': return new StaticImageMedium($items, $blueprint); case 'video': return new VideoMedium($items, $blueprint); diff --git a/system/src/Grav/Common/Page/Medium/VectorImageMedium.php b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php new file mode 100644 index 000000000..b43c38214 --- /dev/null +++ b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php @@ -0,0 +1,63 @@ +get('filepath'); + if (!$path || !file_exists($path) || !filesize($path)) { + return; + } + + $xml = simplexml_load_string(file_get_contents($path)); + $attr = $xml->attributes(); + + if (!$attr instanceof \SimpleXMLElement) { + return; + } + + if ($attr->width > 0 && $attr->height > 0) { + $width = (int)$attr->width; + $height = (int)$attr->height; + } elseif ($attr->viewBox && count($size = explode(' ', $attr->viewBox)) === 4) { + $width = (int)$size[2]; + $height = (int)$size[3]; + } + + if ($width && $height) { + $this->def('width', $width); + $this->def('height', $height); + } + } +} From 3a45748ce68070819f1d05fdef20c494911e3353 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Sat, 12 Feb 2022 10:41:34 +0200 Subject: [PATCH 2/5] Added auto_sizes support for SVG vector images [#3533] --- CHANGELOG.md | 6 ++++++ .../Common/Page/Medium/VectorImageMedium.php | 18 +++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c394dadf0..fa2f0ef60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.7.31 +## mm/dd/2022 + +1. [](#new) + * Added auto_sizes support for SVG vector images [#3533](https://github.com/getgrav/grav/pull/3533) + # v1.7.30 ## 02/07/2022 diff --git a/system/src/Grav/Common/Page/Medium/VectorImageMedium.php b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php index b43c38214..b2cfc07f9 100644 --- a/system/src/Grav/Common/Page/Medium/VectorImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php @@ -28,10 +28,7 @@ class VectorImageMedium extends StaticImageMedium { parent::__construct($items, $blueprint); - $height = false; - $width = false; - - if (!extension_loaded('simplexml')) { + if ($this->mime !== 'image/svg+xml' || !\extension_loaded('simplexml')) { return; } @@ -41,7 +38,7 @@ class VectorImageMedium extends StaticImageMedium } $xml = simplexml_load_string(file_get_contents($path)); - $attr = $xml->attributes(); + $attr = $xml ? $xml->attributes() : null; if (!$attr instanceof \SimpleXMLElement) { return; @@ -50,14 +47,13 @@ class VectorImageMedium extends StaticImageMedium if ($attr->width > 0 && $attr->height > 0) { $width = (int)$attr->width; $height = (int)$attr->height; - } elseif ($attr->viewBox && count($size = explode(' ', $attr->viewBox)) === 4) { - $width = (int)$size[2]; - $height = (int)$size[3]; + } elseif ($attr->viewBox && \count($size = explode(' ', $attr->viewBox)) === 4) { + [,$width,$height,] = $size; } - if ($width && $height) { - $this->def('width', $width); - $this->def('height', $height); + if (isset($width, $height)) { + $this->def('width', (int)$width); + $this->def('height', (int)$height); } } } From ec884997eff805e1c92374745a81620fe414e10b Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Sat, 12 Feb 2022 10:49:52 +0200 Subject: [PATCH 3/5] Improve vector image code [#3533] --- CHANGELOG.md | 2 +- .../Common/Page/Medium/VectorImageMedium.php | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa2f0ef60..dd1fd9d5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## mm/dd/2022 1. [](#new) - * Added auto_sizes support for SVG vector images [#3533](https://github.com/getgrav/grav/pull/3533) + * Added support to get image size for SVG vector images [#3533](https://github.com/getgrav/grav/pull/3533) # v1.7.30 ## 02/07/2022 diff --git a/system/src/Grav/Common/Page/Medium/VectorImageMedium.php b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php index b2cfc07f9..846870131 100644 --- a/system/src/Grav/Common/Page/Medium/VectorImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php @@ -28,10 +28,19 @@ class VectorImageMedium extends StaticImageMedium { parent::__construct($items, $blueprint); + // If we already have the image size, we do not need to do anything else. + $width = $this->get('width'); + $height = $this->get('height'); + if ($width && $height) { + return; + } + + // Make sure that getting image size is supported. if ($this->mime !== 'image/svg+xml' || !\extension_loaded('simplexml')) { return; } + // Make sure that the image exists. $path = $this->get('filepath'); if (!$path || !file_exists($path) || !filesize($path)) { return; @@ -39,19 +48,19 @@ class VectorImageMedium extends StaticImageMedium $xml = simplexml_load_string(file_get_contents($path)); $attr = $xml ? $xml->attributes() : null; - if (!$attr instanceof \SimpleXMLElement) { return; } + // Get the size from svg image. if ($attr->width > 0 && $attr->height > 0) { - $width = (int)$attr->width; - $height = (int)$attr->height; + $width = $attr->width; + $height = $attr->height; } elseif ($attr->viewBox && \count($size = explode(' ', $attr->viewBox)) === 4) { [,$width,$height,] = $size; } - if (isset($width, $height)) { + if ($width && $height) { $this->def('width', (int)$width); $this->def('height', (int)$height); } From b3b5fca16cee7339cd11c8aa6dd86d9490b43222 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 14 Feb 2022 09:38:22 +0200 Subject: [PATCH 4/5] Fixed `'mbstring' extension is not loaded` error, use Polyfill instead [#3504] --- CHANGELOG.md | 2 ++ bin/gpm | 8 ++------ bin/grav | 8 ++------ bin/plugin | 8 ++------ index.php | 23 ++++++++--------------- 5 files changed, 16 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd1fd9d5f..08737d2bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 1. [](#new) * Added support to get image size for SVG vector images [#3533](https://github.com/getgrav/grav/pull/3533) +2. [](#bugfix) + * Fixed `'mbstring' extension is not loaded` error, use Polyfill instead [#3504](https://github.com/getgrav/grav/pull/3504) # v1.7.30 ## 02/07/2022 diff --git a/bin/gpm b/bin/gpm index 9e58706f6..12d0c3d36 100755 --- a/bin/gpm +++ b/bin/gpm @@ -25,14 +25,10 @@ if (!file_exists(__DIR__ . '/../vendor/autoload.php')){ $autoload = require __DIR__ . '/../vendor/autoload.php'; -if (!ini_get('date.timezone')) { - date_default_timezone_set('UTC'); -} +// Set timezone to default, falls back to system if php.ini not set +date_default_timezone_set(@date_default_timezone_get()); // Set internal encoding. -if (!\extension_loaded('mbstring')) { - die("'mbstring' extension is not loaded. This is required for Grav to run correctly"); -} @ini_set('default_charset', 'UTF-8'); mb_internal_encoding('UTF-8'); diff --git a/bin/grav b/bin/grav index cc925c394..1bcba715a 100755 --- a/bin/grav +++ b/bin/grav @@ -25,14 +25,10 @@ if (!file_exists(__DIR__ . '/../vendor/autoload.php')){ $autoload = require __DIR__ . '/../vendor/autoload.php'; -if (!ini_get('date.timezone')) { - date_default_timezone_set('UTC'); -} +// Set timezone to default, falls back to system if php.ini not set +date_default_timezone_set(@date_default_timezone_get()); // Set internal encoding. -if (!\extension_loaded('mbstring')) { - die("'mbstring' extension is not loaded. This is required for Grav to run correctly"); -} @ini_set('default_charset', 'UTF-8'); mb_internal_encoding('UTF-8'); diff --git a/bin/plugin b/bin/plugin index 3a784af57..4a3683858 100755 --- a/bin/plugin +++ b/bin/plugin @@ -25,14 +25,10 @@ if (!file_exists(__DIR__ . '/../vendor/autoload.php')){ $autoload = require __DIR__ . '/../vendor/autoload.php'; -if (!ini_get('date.timezone')) { - date_default_timezone_set('UTC'); -} +// Set timezone to default, falls back to system if php.ini not set +date_default_timezone_set(@date_default_timezone_get()); // Set internal encoding. -if (!\extension_loaded('mbstring')) { - die("'mbstring' extension is not loaded. This is required for Grav to run correctly"); -} @ini_set('default_charset', 'UTF-8'); mb_internal_encoding('UTF-8'); diff --git a/index.php b/index.php index 3e308312f..5393b8cff 100644 --- a/index.php +++ b/index.php @@ -20,16 +20,6 @@ if (PHP_SAPI === 'cli-server') { } } -// Set timezone to default, falls back to system if php.ini not set -date_default_timezone_set(@date_default_timezone_get()); - -// Set internal encoding. -if (!\extension_loaded('mbstring')) { - die("'mbstring' extension is not loaded. This is required for Grav to run correctly"); -} -@ini_set('default_charset', 'UTF-8'); -mb_internal_encoding('UTF-8'); - // Ensure vendor libraries exist $autoload = __DIR__ . '/vendor/autoload.php'; if (!is_file($autoload)) { @@ -39,15 +29,18 @@ if (!is_file($autoload)) { // Register the auto-loader. $loader = require $autoload; +// Set timezone to default, falls back to system if php.ini not set +date_default_timezone_set(@date_default_timezone_get()); + +// Set internal encoding. +@ini_set('default_charset', 'UTF-8'); +mb_internal_encoding('UTF-8'); + use Grav\Common\Grav; use RocketTheme\Toolbox\Event\Event; // Get the Grav instance -$grav = Grav::instance( - array( - 'loader' => $loader - ) -); +$grav = Grav::instance(array('loader' => $loader)); // Process the page try { From 7cafeb2870bfbfdaa63c6e4fd109ce77e40d561a Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 16 Feb 2022 09:53:11 +0200 Subject: [PATCH 5/5] Composer update --- composer.lock | 60 +++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/composer.lock b/composer.lock index 1f73769f4..a90114272 100644 --- a/composer.lock +++ b/composer.lock @@ -840,22 +840,21 @@ }, { "name": "itsgoingd/clockwork", - "version": "v5.1.4", + "version": "v5.1.5", "source": { "type": "git", "url": "https://github.com/itsgoingd/clockwork.git", - "reference": "7252aa771b77ac8678b44290fd7ec7577435cce6" + "reference": "6a7b3942224fa53cf3704d9adba636e1f3dfeb9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/7252aa771b77ac8678b44290fd7ec7577435cce6", - "reference": "7252aa771b77ac8678b44290fd7ec7577435cce6", + "url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/6a7b3942224fa53cf3704d9adba636e1f3dfeb9a", + "reference": "6a7b3942224fa53cf3704d9adba636e1f3dfeb9a", "shasum": "" }, "require": { "ext-json": "*", - "php": ">=5.6", - "psr/log": "1.* || ^2.0" + "php": ">=5.6" }, "type": "library", "extra": { @@ -897,7 +896,7 @@ ], "support": { "issues": "https://github.com/itsgoingd/clockwork/issues", - "source": "https://github.com/itsgoingd/clockwork/tree/v5.1.4" + "source": "https://github.com/itsgoingd/clockwork/tree/v5.1.5" }, "funding": [ { @@ -905,7 +904,7 @@ "type": "github" } ], - "time": "2022-01-30T12:36:18+00:00" + "time": "2022-02-13T22:57:42+00:00" }, { "name": "league/climate", @@ -1105,25 +1104,26 @@ }, { "name": "maximebf/debugbar", - "version": "v1.17.3", + "version": "v1.18.0", "source": { "type": "git", "url": "https://github.com/maximebf/php-debugbar.git", - "reference": "e8ac3499af0ea5b440908e06cc0abe5898008b3c" + "reference": "0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/e8ac3499af0ea5b440908e06cc0abe5898008b3c", - "reference": "e8ac3499af0ea5b440908e06cc0abe5898008b3c", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6", + "reference": "0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6", "shasum": "" }, "require": { "php": "^7.1|^8", "psr/log": "^1|^2|^3", - "symfony/var-dumper": "^2.6|^3|^4|^5" + "symfony/var-dumper": "^2.6|^3|^4|^5|^6" }, "require-dev": { - "phpunit/phpunit": "^7.5.20 || ^9.4.2" + "phpunit/phpunit": "^7.5.20 || ^9.4.2", + "twig/twig": "^1.38|^2.7|^3.0" }, "suggest": { "kriswallsmith/assetic": "The best way to manage assets", @@ -1164,9 +1164,9 @@ ], "support": { "issues": "https://github.com/maximebf/php-debugbar/issues", - "source": "https://github.com/maximebf/php-debugbar/tree/v1.17.3" + "source": "https://github.com/maximebf/php-debugbar/tree/v1.18.0" }, - "time": "2021-10-19T12:33:27+00:00" + "time": "2021-12-27T18:49:48+00:00" }, { "name": "miljar/php-exif", @@ -2730,12 +2730,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -4019,12 +4019,12 @@ } }, "autoload": { - "psr-4": { - "GuzzleHttp\\": "src/" - }, "files": [ "src/functions_include.php" - ] + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -5725,16 +5725,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.3", + "version": "5.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49" + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23bd5951f7ff26f12d4e3242864df3e08dec4e49", - "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", "shasum": "" }, "require": { @@ -5777,7 +5777,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.3" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" }, "funding": [ { @@ -5785,7 +5785,7 @@ "type": "github" } ], - "time": "2021-06-11T13:31:12+00:00" + "time": "2022-02-14T08:28:10+00:00" }, { "name": "sebastian/lines-of-code",