WebP Express - Version 0.25.4

Version Description

(released 6 May 2022) * AlterHTML (when using picture tags): Fixed charset problems for special characters in alt and title attributes. The bug was introduced in 0.25.2. Thanks to Cruglk for first pointing this out.

Download this release

Release Info

Developer rosell.dk
Plugin Icon 128x128 WebP Express
Version 0.25.4
Comparing to
See all releases

Code changes from version 0.25.3 to 0.25.4

README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://ko-fi.com/rosell
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.8
7
- Stable tag: 0.25.3
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -816,9 +816,13 @@ If you want to make sure that my coffee supplies don't run dry, you can even buy
816
 
817
  == Changelog ==
818
 
 
 
 
 
819
  = 0.25.3 =
820
  (released 4 May 2022)
821
- * AlterHTML: Fixed BIG BUG introduced in 0.25.2
822
 
823
  = 0.25.2 =
824
  (released 4 May 2022)
@@ -921,6 +925,9 @@ For older releases, check out changelog.txt
921
 
922
  == Upgrade Notice ==
923
 
 
 
 
924
  = 0.25.3 =
925
  * AlterHTML: Fixed BIG BUG introduced in 0.25.2
926
 
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.8
7
+ Stable tag: 0.25.4
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
816
 
817
  == Changelog ==
818
 
819
+ = 0.25.4 =
820
+ (released 6 May 2022)
821
+ * AlterHTML (when using picture tags): Fixed charset problems for special characters in alt and title attributes. The bug was introduced in 0.25.2. Thanks to Cruglk for first pointing this out.
822
+
823
  = 0.25.3 =
824
  (released 4 May 2022)
825
+ * AlterHTML: Fixed BIG BUG introduced in 0.25.2 (the webp urls was wrong when using picture tags). So sorry! Thankfully, I was quickly made aware of this and quickly patched it.
826
 
827
  = 0.25.2 =
828
  (released 4 May 2022)
925
 
926
  == Upgrade Notice ==
927
 
928
+ = 0.25.4 =
929
+ * AlterHTML (when using picture tags): Fixed charset problems for special characters in alt and title attributes.
930
+
931
  = 0.25.3 =
932
  * AlterHTML: Fixed BIG BUG introduced in 0.25.2
933
 
changelog.txt CHANGED
@@ -1,6 +1,9 @@
 
 
 
1
  = 0.25.3 =
2
  (released 4 May 2022)
3
- * AlterHTML: Fixed BIG BUG introduced in 0.25.2
4
 
5
  = 0.25.2 =
6
  (released 4 May 2022)
1
+ = 0.25.4 =
2
+ * AlterHTML (when using picture tags): Fixed charset problems for special characters in alt and title attributes. The bug was introduced in 0.25.2. Thanks to Cruglk for first pointing this out.
3
+
4
  = 0.25.3 =
5
  (released 4 May 2022)
6
+ * AlterHTML: Fixed BIG BUG introduced in 0.25.2 (the webp urls was wrong when using picture tags). So sorry! Thankfully, I was quickly made aware of this and quickly patched it.
7
 
8
  = 0.25.2 =
9
  (released 4 May 2022)
composer.json CHANGED
@@ -7,7 +7,7 @@
7
  "composer/installers": "^1.12.0",
8
  "rosell-dk/webp-convert": "^2.9.0",
9
  "rosell-dk/webp-convert-cloud-service": "^2.0.0",
10
- "rosell-dk/dom-util-for-webp": "^0.6.0",
11
  "rosell-dk/htaccess-capability-tester": "^0.9.0",
12
  "rosell-dk/image-mime-type-guesser": "^0.4.0"
13
  },
7
  "composer/installers": "^1.12.0",
8
  "rosell-dk/webp-convert": "^2.9.0",
9
  "rosell-dk/webp-convert-cloud-service": "^2.0.0",
10
+ "rosell-dk/dom-util-for-webp": "^0.6.3",
11
  "rosell-dk/htaccess-capability-tester": "^0.9.0",
12
  "rosell-dk/image-mime-type-guesser": "^0.4.0"
13
  },
docs/publishing.md CHANGED
@@ -116,7 +116,7 @@ svn status | grep '^!' | awk '{print $2}' | xargs svn delete --force (t
116
  Then add a new tag
117
  ```
118
  cd svn
119
- svn cp trunk tags/0.25.2 (this will copy trunk into a new tag)
120
  ```
121
 
122
  And commit!
116
  Then add a new tag
117
  ```
118
  cd svn
119
+ svn cp trunk tags/0.25.3 (this will copy trunk into a new tag)
120
  ```
121
 
122
  And commit!
lib/classes/ConvertHelperIndependent.php CHANGED
@@ -571,7 +571,7 @@ APACHE
571
  $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
572
 
573
  // TODO: Put version number somewhere else. Ie \WebPExpress\VersionNumber::version
574
- $text = 'WebP Express 0.25.3. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
575
 
576
  $logFile = self::getLogFilename($source, $logDir);
577
 
571
  $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
572
 
573
  // TODO: Put version number somewhere else. Ie \WebPExpress\VersionNumber::version
574
+ $text = 'WebP Express 0.25.4. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
575
 
576
  $logFile = self::getLogFilename($source, $logDir);
577
 
lib/options/page-messages.php CHANGED
@@ -69,6 +69,11 @@ if ($cacheEnablerActivated && !$webpEnabled) {
69
  'for webp-enabled browsers.'
70
  );
71
  }
 
 
 
 
 
72
 
73
  $elementorActivated = in_array('elementor/elementor.php', get_option('active_plugins', []));
74
  if ($elementorActivated) {
@@ -83,7 +88,7 @@ if ($elementorActivated) {
83
  // Well, just bad luck.
84
  }
85
  }
86
-
87
 
88
  if (($config['operation-mode'] == 'cdn-friendly') && !$config['alter-html']['enabled']) {
89
  //echo print_r(get_option('cache-enabler'), true);
69
  'for webp-enabled browsers.'
70
  );
71
  }
72
+ /*
73
+ Commented out
74
+ In newer PHP, it generates a fatal (uncatchable) error:
75
+ Fatal error: Uncaught Error: Call to a member function is_feature_active() on null
76
+ See #562
77
 
78
  $elementorActivated = in_array('elementor/elementor.php', get_option('active_plugins', []));
79
  if ($elementorActivated) {
88
  // Well, just bad luck.
89
  }
90
  }
91
+ */
92
 
93
  if (($config['operation-mode'] == 'cdn-friendly') && !$config['alter-html']['enabled']) {
94
  //echo print_r(get_option('cache-enabler'), true);
vendor/composer/installed.json CHANGED
@@ -209,17 +209,17 @@
209
  },
210
  {
211
  "name": "rosell-dk/dom-util-for-webp",
212
- "version": "0.6.0",
213
- "version_normalized": "0.6.0.0",
214
  "source": {
215
  "type": "git",
216
  "url": "https://github.com/rosell-dk/dom-util-for-webp.git",
217
- "reference": "2c87ff72d8ce49408ed5b2fc1a2e13ee16ab7613"
218
  },
219
  "dist": {
220
  "type": "zip",
221
- "url": "https://api.github.com/repos/rosell-dk/dom-util-for-webp/zipball/2c87ff72d8ce49408ed5b2fc1a2e13ee16ab7613",
222
- "reference": "2c87ff72d8ce49408ed5b2fc1a2e13ee16ab7613",
223
  "shasum": ""
224
  },
225
  "require": {
@@ -231,7 +231,7 @@
231
  "phpunit/phpunit": "^9.3",
232
  "squizlabs/php_codesniffer": "3.*"
233
  },
234
- "time": "2022-05-04T08:15:56+00:00",
235
  "type": "library",
236
  "extra": {
237
  "scripts-descriptions": {
@@ -269,7 +269,7 @@
269
  ],
270
  "support": {
271
  "issues": "https://github.com/rosell-dk/dom-util-for-webp/issues",
272
- "source": "https://github.com/rosell-dk/dom-util-for-webp/tree/0.6.0"
273
  },
274
  "funding": [
275
  {
209
  },
210
  {
211
  "name": "rosell-dk/dom-util-for-webp",
212
+ "version": "0.6.5",
213
+ "version_normalized": "0.6.5.0",
214
  "source": {
215
  "type": "git",
216
  "url": "https://github.com/rosell-dk/dom-util-for-webp.git",
217
+ "reference": "618d8cb26e744135934b6837e6b0ed9acc925f1e"
218
  },
219
  "dist": {
220
  "type": "zip",
221
+ "url": "https://api.github.com/repos/rosell-dk/dom-util-for-webp/zipball/618d8cb26e744135934b6837e6b0ed9acc925f1e",
222
+ "reference": "618d8cb26e744135934b6837e6b0ed9acc925f1e",
223
  "shasum": ""
224
  },
225
  "require": {
231
  "phpunit/phpunit": "^9.3",
232
  "squizlabs/php_codesniffer": "3.*"
233
  },
234
+ "time": "2022-05-06T08:19:46+00:00",
235
  "type": "library",
236
  "extra": {
237
  "scripts-descriptions": {
269
  ],
270
  "support": {
271
  "issues": "https://github.com/rosell-dk/dom-util-for-webp/issues",
272
+ "source": "https://github.com/rosell-dk/dom-util-for-webp/tree/0.6.5"
273
  },
274
  "funding": [
275
  {
vendor/composer/installed.php CHANGED
@@ -5,7 +5,7 @@
5
  'type' => 'wordpress-plugin',
6
  'install_path' => __DIR__ . '/../../',
7
  'aliases' => array(),
8
- 'reference' => '58c4e035f587f8caa4c9f27faea0c91ce74fc1dc',
9
  'name' => 'rosell-dk/webp-express',
10
  'dev' => true,
11
  ),
@@ -29,12 +29,12 @@
29
  'dev_requirement' => false,
30
  ),
31
  'rosell-dk/dom-util-for-webp' => array(
32
- 'pretty_version' => '0.6.0',
33
- 'version' => '0.6.0.0',
34
  'type' => 'library',
35
  'install_path' => __DIR__ . '/../rosell-dk/dom-util-for-webp',
36
  'aliases' => array(),
37
- 'reference' => '2c87ff72d8ce49408ed5b2fc1a2e13ee16ab7613',
38
  'dev_requirement' => false,
39
  ),
40
  'rosell-dk/exec-with-fallback' => array(
@@ -88,7 +88,7 @@
88
  'type' => 'wordpress-plugin',
89
  'install_path' => __DIR__ . '/../../',
90
  'aliases' => array(),
91
- 'reference' => '58c4e035f587f8caa4c9f27faea0c91ce74fc1dc',
92
  'dev_requirement' => false,
93
  ),
94
  'roundcube/plugin-installer' => array(
5
  'type' => 'wordpress-plugin',
6
  'install_path' => __DIR__ . '/../../',
7
  'aliases' => array(),
8
+ 'reference' => '79efca228f2cb7d40e830a9519c4dca1b3dda66f',
9
  'name' => 'rosell-dk/webp-express',
10
  'dev' => true,
11
  ),
29
  'dev_requirement' => false,
30
  ),
31
  'rosell-dk/dom-util-for-webp' => array(
32
+ 'pretty_version' => '0.6.5',
33
+ 'version' => '0.6.5.0',
34
  'type' => 'library',
35
  'install_path' => __DIR__ . '/../rosell-dk/dom-util-for-webp',
36
  'aliases' => array(),
37
+ 'reference' => '618d8cb26e744135934b6837e6b0ed9acc925f1e',
38
  'dev_requirement' => false,
39
  ),
40
  'rosell-dk/exec-with-fallback' => array(
88
  'type' => 'wordpress-plugin',
89
  'install_path' => __DIR__ . '/../../',
90
  'aliases' => array(),
91
+ 'reference' => '79efca228f2cb7d40e830a9519c4dca1b3dda66f',
92
  'dev_requirement' => false,
93
  ),
94
  'roundcube/plugin-installer' => array(
vendor/rosell-dk/dom-util-for-webp/README.md CHANGED
@@ -158,3 +158,9 @@ So it is correct behaviour not to copy the *style*, *width*, *class* or any othe
158
  As with `ImageUrlReplacer`, you can override the *replaceUrl* function. There is however currently no other methods to override.
159
 
160
  `PictureTags` currently uses regular expressions to do the replacing. There are plans to change implementation to use `Sunra\PhpSimple\HtmlDomParser`, like our `ImageUrlReplacer` class does.
 
 
 
 
 
 
158
  As with `ImageUrlReplacer`, you can override the *replaceUrl* function. There is however currently no other methods to override.
159
 
160
  `PictureTags` currently uses regular expressions to do the replacing. There are plans to change implementation to use `Sunra\PhpSimple\HtmlDomParser`, like our `ImageUrlReplacer` class does.
161
+
162
+ ## Do you like what I do?
163
+ Perhaps you want to support my work, so I can continue doing it :)
164
+
165
+ - [Become a backer or sponsor on Patreon](https://www.patreon.com/rosell).
166
+ - [Buy me a Coffee](https://ko-fi.com/rosell)
vendor/rosell-dk/dom-util-for-webp/composer.json CHANGED
@@ -8,7 +8,7 @@
8
  "scripts": {
9
  "ci": [
10
  "@build",
11
- "@test",
12
  "@phpcs-all",
13
  "@composer validate --no-check-all --strict",
14
  "@phpstan"
@@ -19,6 +19,7 @@
19
  "cs-fix": "php-cs-fixer fix",
20
  "cs-dry": "php-cs-fixer fix --dry-run --diff",
21
  "test": "phpunit --coverage-text=build/coverage.txt --coverage-clover=build/coverage.clover --coverage-html=build/coverage --whitelist=src tests",
 
22
  "test-41": "phpunit --coverage-text --configuration 'phpunit-41.xml.dist'",
23
  "test-no-cov": "phpunit --no-coverage tests",
24
  "phpunit": "phpunit --no-coverage",
8
  "scripts": {
9
  "ci": [
10
  "@build",
11
+ "@test-cov-console",
12
  "@phpcs-all",
13
  "@composer validate --no-check-all --strict",
14
  "@phpstan"
19
  "cs-fix": "php-cs-fixer fix",
20
  "cs-dry": "php-cs-fixer fix --dry-run --diff",
21
  "test": "phpunit --coverage-text=build/coverage.txt --coverage-clover=build/coverage.clover --coverage-html=build/coverage --whitelist=src tests",
22
+ "test-cov-console": "phpunit --coverage-text --whitelist=src tests",
23
  "test-41": "phpunit --coverage-text --configuration 'phpunit-41.xml.dist'",
24
  "test-no-cov": "phpunit --no-coverage tests",
25
  "phpunit": "phpunit --no-coverage",
vendor/rosell-dk/dom-util-for-webp/src/PictureTags.php CHANGED
@@ -112,10 +112,33 @@ class PictureTags
112
  return $result;
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  private static function getAttributes($html)
116
  {
117
  if (class_exists('\\DOMDocument')) {
118
  $dom = new \DOMDocument();
 
 
 
 
 
 
 
119
  @$dom->loadHTML($html);
120
  $image = $dom->getElementsByTagName('img')->item(0);
121
  $attributes = [];
@@ -124,16 +147,13 @@ class PictureTags
124
  }
125
  return $attributes;
126
  } else {
127
- //$dom = HtmlDomParser::str_get_html($html, false, false, 'UTF-8', false);
128
- /*if (!function_exists('str_get_html')) {
129
- require_once __DIR__ . '/../src-vendor/simple_html_dom/simple_html_dom.inc';
130
- }*/
131
-
132
- // Took detection from here:
133
- // https://github.com/symfony/symfony/blob/d31ea7c230160b3930f4789ed38c959c5db4f723/src/Symfony/Component/DomCrawler/Crawler.php
134
- $charset = preg_match('//u', $html) ? 'UTF-8' : 'ISO-8859-1';
135
-
136
- $dom = HtmlDomParser::str_get_html($html, false, false, $charset, false);
137
  if ($dom !== false) {
138
  $elems = $dom->find('img,IMG');
139
  foreach ($elems as $index => $elem) {
@@ -251,35 +271,6 @@ class PictureTags
251
  . '<source' . self::createAttributes($sourceTagAttributes) . ' type="image/webp">'
252
  . '<img' . self::createAttributes($imgAttributes) . '>'
253
  . '</picture>';
254
-
255
- /*
256
- //if ($srcsetInfo['value']) {
257
- if (isset($srcSetAttributes['srcset'])) {
258
- $sourceTagAttributes = $srcSetAttributes;
259
-
260
-
261
- return '<picture>'
262
- . '<source' . self::createAttributes($sourceTagAttributes) . ' type="image/webp">'
263
- . '<img' . self::createAttributes($imgAttributes) . '>'
264
- . '</picture>';
265
- } else {
266
- $srcWebP = $this->replaceUrlOr($srcInfo['value'], false);
267
- if ($srcWebP === false) {
268
- // No reason to create <picture> tag
269
- return $imgTag;
270
- }
271
-
272
- $sourceSrcAttrName = $srcInfo['attrName'];
273
- if ($sourceSrcAttrName == 'src') {
274
- // "src" isn't allowed in <source> tag with <picture> tag as parent.
275
- $sourceSrcAttrName = 'srcset';
276
- }
277
-
278
- return '<picture>'
279
- . '<source ' . $sourceSrcAttrName . '="' . $srcWebP . '" type="image/webp">'
280
- . '<img' . self::createAttributes($imgAttributes) . '>'
281
- . '</picture>';
282
- }*/
283
  }
284
 
285
  /*
@@ -307,6 +298,14 @@ class PictureTags
307
  */
308
  public function replaceHtml($content)
309
  {
 
 
 
 
 
 
 
 
310
  $this->existingPictureTags = [];
311
 
312
  // Tempororily remove existing <picture> tags
112
  return $result;
113
  }
114
 
115
+ /**
116
+ * Convert to UTF-8 and encode chars outside of ascii-range
117
+ *
118
+ * Input: html that might be in any character encoding and might contain non-ascii characters
119
+ * Output: html in UTF-8 encding, where non-ascii characters are encoded
120
+ *
121
+ */
122
+ private static function textToUTF8WithNonAsciiEncoded($html)
123
+ {
124
+ if (function_exists("mb_convert_encoding")) {
125
+ $html = mb_convert_encoding($html, 'UTF-8');
126
+ $html = mb_encode_numericentity($html, array (0x7f, 0xffff, 0, 0xffff), 'UTF-8');
127
+ }
128
+ return $html;
129
+ }
130
+
131
  private static function getAttributes($html)
132
  {
133
  if (class_exists('\\DOMDocument')) {
134
  $dom = new \DOMDocument();
135
+
136
+ if (function_exists("mb_encode_numericentity")) {
137
+ // I'm in doubt if I should add the following line (see #41)
138
+ // $html = mb_convert_encoding($html, 'UTF-8');
139
+ $html = mb_encode_numericentity($html, array (0x7f, 0xffff, 0, 0xffff)); // #41
140
+ }
141
+
142
  @$dom->loadHTML($html);
143
  $image = $dom->getElementsByTagName('img')->item(0);
144
  $attributes = [];
147
  }
148
  return $attributes;
149
  } else {
150
+ // Convert to UTF-8 because HtmlDomParser::str_get_html needs to be told the
151
+ // encoding. As UTF-8 might conflict with the charset set in the meta, we must
152
+ // encode all characters outside the ascii-range.
153
+ // It would perhaps have been better to try to guess the encoding rather than
154
+ // changing it (see #39), but I'm reluctant to introduce changes.
155
+ $html = self::textToUTF8WithNonAsciiEncoded($html);
156
+ $dom = HtmlDomParser::str_get_html($html, false, false, 'UTF-8', false);
 
 
 
157
  if ($dom !== false) {
158
  $elems = $dom->find('img,IMG');
159
  foreach ($elems as $index => $elem) {
271
  . '<source' . self::createAttributes($sourceTagAttributes) . ' type="image/webp">'
272
  . '<img' . self::createAttributes($imgAttributes) . '>'
273
  . '</picture>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  }
275
 
276
  /*
298
  */
299
  public function replaceHtml($content)
300
  {
301
+ if (!class_exists('\\DOMDocument') && function_exists('mb_detect_encoding')) {
302
+ // PS: Correctly identifying Windows-1251 encoding only works on some systems
303
+ // But at least I'm not aware of any false positives
304
+ if (mb_detect_encoding($content, ["ASCII", "UTF8", "Windows-1251"]) == 'Windows-1251') {
305
+ $content = mb_convert_encoding($content, 'UTF-8', 'Windows-1251');
306
+ }
307
+ }
308
+
309
  $this->existingPictureTags = [];
310
 
311
  // Tempororily remove existing <picture> tags
webp-express.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WebP Express
4
  * Plugin URI: https://github.com/rosell-dk/webp-express
5
  * Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
6
- * Version: 0.25.3
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2
3
  * Plugin Name: WebP Express
4
  * Plugin URI: https://github.com/rosell-dk/webp-express
5
  * Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
6
+ * Version: 0.25.4
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2