WebP Express - Version 0.16.0

Version Description

(released: 24 sep 2019)

  • Added option to specify CDN urls in Alter HTML. Thanks to Gunnar Peipman from Estonia for suggesting this.
  • Direct Nginx users to Nginx FAQ section on welcome page
  • Fixed Bulk Conversion halting due to nonce expiry
  • Fixed unexpected output upon reactivation
  • Added affiliate link to Optimole in the "Don't despair - You have options!" message
Download this release

Release Info

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

Code changes from version 0.15.3 to 0.16.0

Files changed (37) hide show
  1. README.md +59 -13
  2. README.txt +19 -3
  3. changelog.txt +14 -0
  4. js/0.16.0/plugin-page.js +17 -0
  5. lib/classes/AdminInit.php +23 -5
  6. lib/classes/AlterHtmlHelper.php +53 -13
  7. lib/classes/Config.php +15 -3
  8. lib/classes/Convert.php +21 -3
  9. lib/classes/ConvertHelperIndependent.php +1 -1
  10. lib/classes/HTAccess.php +58 -4
  11. lib/classes/Paths.php +15 -0
  12. lib/classes/PluginActivate.php +6 -15
  13. lib/classes/PluginDeactivate.php +4 -1
  14. lib/classes/PluginPageScript.php +26 -0
  15. lib/classes/SelfTestRedirectToWebPRealizer.php +1 -1
  16. lib/dismissable-messages/0.16.0/nginx-link-to-faq.php +19 -0
  17. lib/migrate/migrate1.php +8 -1
  18. lib/migrate/migrate7.php +1 -1
  19. lib/options/css/webp-express-options-page.css +2 -1
  20. lib/options/enqueue_scripts.php +2 -2
  21. lib/options/js/{0.15.0 → 0.16.0}/authorized_sites_bak.js +0 -0
  22. lib/options/js/{0.15.0 → 0.16.0}/bulk-convert.js +17 -1
  23. lib/options/js/{0.15.0 → 0.16.0}/converters.js +0 -0
  24. lib/options/js/{0.15.0 → 0.16.0}/das-popup.js +0 -0
  25. lib/options/js/{0.15.0 → 0.16.0}/escapeHTML.js +0 -0
  26. lib/options/js/{0.15.0 → 0.16.0}/image-comparison-slider.js +0 -0
  27. lib/options/js/{0.15.0 → 0.16.0}/page.js +0 -0
  28. lib/options/js/{0.15.0 → 0.16.0}/purge-cache.js +0 -0
  29. lib/options/js/{0.15.0 → 0.16.0}/self-test.js +0 -0
  30. lib/options/js/{0.15.0 → 0.16.0}/sortable.min.js +0 -0
  31. lib/options/js/{0.15.0 → 0.16.0}/test-convert.js +0 -0
  32. lib/options/js/{0.15.0 → 0.16.0}/whitelist.js +0 -0
  33. lib/options/options/alter-html/alter-html-options.inc +26 -1
  34. lib/options/page-messages.php +7 -1
  35. lib/options/page-welcome.php +15 -12
  36. lib/options/submit.php +26 -145
  37. webp-express.php +1 -1
README.md CHANGED
@@ -128,8 +128,12 @@ Don't fret - you have options!
128
 
129
  - If you a controlling another WordPress site (where the local conversion methods DO work), you can set up WebP Express there, and then connect to it by configuring the “Remote WebP Express” conversion method.
130
  - You can also setup the ewww conversion method. To use it, you need to purchase an api key. They do not charge credits for webp conversions, so all you ever have to pay is the one dollar start-up fee 🙂 (unless they change their pricing – I have no control over that). You can buy an api key here: https://ewww.io/plans/
131
- - If you are up to it, you can try to get one of the local converters working. Check out [this page](https://github.com/rosell-dk/webp-convert/wiki/Meeting-the-requirements-of-the-converters) on the webp-convert wiki
132
- - Finally, if you have access to a server and are comfortable with installing projects with composer, you can install [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service). It's open source.
 
 
 
 
133
 
134
  ### It doesn't work - Although test conversions work, it still serves jpeg images.
135
  Actually, you might be mistaking, so first, make sure that you didn't make the very common mistake of thinking that something with the URL *example.com/image.jpg* must be a jpeg image. The plugin serves webp images on same URL as the original (unconverted) images, so do not let appearances fool you! Confused? See next FAQ item.
@@ -151,30 +155,48 @@ Easy enough. Browsers looks at the *content type* header rather than the URL to
151
  I am btw considering making an option to have the plugin redirect to the webp instead of serving immediately. That would remove the apparent mismatch between file extension and content type header. However, the cost of doing that will be an extra request for each image, which means extra time and worse performance. I believe you'd be ill advised to use that option, so I guess I will not implement it. But perhaps you have good reasons to use it? If you do, please let me know!
152
 
153
  ### Blank images in Safari?
154
- WebP Express has three ways of distributing webp to webp-enabled browsers while still sending the originals to webp-disabled browsers.
155
 
156
- Method 1: Varied image responses
157
- This method adds rewrites to the .htaccess which redirects jpegs and pngs to the corresponding webps (if they exist). - but only when the browser supports webp images (this is established by examining the "accept" header).
158
 
159
- Method 2: Altering HTML to use picture tags
160
- IMG tags are replaced with PICTURE tags which has two sources. One of them points to the webp and has the "content-type" set to "image/webp". The other points to the original. The browser will select the webp source if it supports webp and the other source if it doesn't.
161
 
162
- Method 3: Altering HTML to point directly to webps in webp enabled browsers, but not altering for browsers not supporting webp. Again, the "accept" header is examined to determine if the browser supports webp.
163
 
 
164
 
165
- Can some of these go wrong?
166
- Yes. All!
167
 
168
- Method 1 can go wrong if you are using a CDN and it hasn't been set up to handle varied image responses. Check out the CDN section in this FAQ (PS: If your CDN has conflated the caches, it is critical that you purge the CDN cache!). I do not believe it can go wrong in other ways. To be certain, please check out [this test page](http://toste.dk/rh.php). When visiting the test-page with Safari, you should see two images with the “JPG” label over them. When visiting the test-page with a browser that supports webp, you should see two images with the “WEBP” label over them. If you do not see one of these things, please report! (no-one has yet experienced that)
 
 
 
 
 
 
 
 
 
 
169
 
170
  Method 2 can go wrong on old browser that doesn't support the picture tag syntax. However, simply enable the "Dynamically load picturefill.js on older browsers" option, and it will take care of that issue.
171
 
 
 
 
172
  Method 3 can go wrong if you are using a page caching plugin if that plugin does not create a separate webp cache for webp-enabled browsers. The *Cache Enabler* plugin handles this. I don't believe there are other page caching plugins that does. There is a FAQ section in this FAQ describing how to set *Cache Enabler* up to work in tandem with WebP Express.
173
 
 
 
 
174
  ### I am on NGINX or OpenResty
175
 
 
 
176
  #### The simple way (no redirecting rules)
177
- The easy solution is simply to use the plugin in "CDN friendly" mode, do a bulk conversion (takes care of converting existing images) and activate the "Convert on upload" option (takes care of converting new images in the media library).
178
 
179
  *PRO*: Very easy to set up.
180
  *CON*: Images in external CSS and images being dynamically added with javascript will not be served as webp.
@@ -230,6 +252,8 @@ __BEWARE:__
230
 
231
  - Beware that if you have moved wp-content to a non-standard place, you must change accordingly. Note that you must then also change the "wp-content" parameter to the script. It expects a relative path to wp-content (from document root) and is needed so the script can find the configuration file.
232
 
 
 
233
  - I have put in an expires statement for caching. You might want to modify or disable that.
234
 
235
  - The rules contains all redirections (as if you enabled all three redirection options in settings). If you do not wish to redirect to converter, remove the last line in the try_files block. If you do not wish to create webp files upon request, remove the last location block.
@@ -293,6 +317,8 @@ __BEWARE:__
293
 
294
  - Beware that if you have moved wp-content to a non-standard place, you must change accordingly. Note that you must then also change the "wp-content" parameter to the script. It expects a relative path to wp-content (from document root) and is needed so the script can find the configuration file.
295
 
 
 
296
  - I have put in an expires statement for caching. You might want to modify or disable that.
297
 
298
  - I have not set any expire on the webp-on-demand.php request. This is not needed, as the script sets this according to what you set up in WebP Express settings. Also, trying to do it would require a new location block matching webp-on-demand.php, but that would override the location block handling php files, and thus break the functionality.
@@ -608,10 +634,28 @@ If you got any further questions, look at, or comment on [this topic](https://wo
608
  ### When is feature X coming? / Roadmap
609
  No schedule. I move forward as time allows. I currently spend a lot of time answering questions in the support forum. If someone would be nice and help out answering questions here, it would allow me to spend that time developing. Also, donations would allow me to turn down some of the more boring requests from my customers, and speed things up here.
610
 
611
- Here are my current plans ahead: 0.15 will probably be a file manager-like interface for converting / bulk converting / viewing conversion logs / comparing original vs webp visually - kind of a merge of current "test converter" and "bulk conversion" interfaces, and with an addition of a file explorer. 0.16 might be various improvements such as option to choose which folders webp express should process (Just uploads / Just uploads and templates / Whole wp-content / Whole system) and options to exclude certain files and folders. 0.17 could be supporting Save-Data header in Varied Image Responses mode (send extra compressed images to clients who wants to use as little bandwidth as possible). 0.18 might be a diagnose tool – this should release some time spend in the forum. 0.18 might be displaying rules for NGINX. 0.19 might be an effort to allow webp for all browsers using [this javascript library](http://libwebpjs.hohenlimburg.org/v0.6.0/). Unfortunately, the javascript librare does not (currently) support srcset attributes, which is why I moved this item down the priority list. We need srcset to be supported for the feature to be useful. 0.20 might be WAMP support. The current milestones, their subtasks and their progress can be viewed here: https://github.com/rosell-dk/webp-express/milestones
612
 
613
  If you wish to affect priorities, it is certainly possible. You can try to argue your case in the forum or you can simply let the money do the talking. By donating as little as a cup of coffee on [ko-fi.com/rosell](https://ko-fi.com/rosell), you can leave a wish. I shall take these wishes into account when prioritizing between new features.
614
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615
  ## Changes in 0.15.1
616
  *(released: 17 sep 2019)*
617
 
@@ -622,6 +666,8 @@ If you wish to affect priorities, it is certainly possible. You can try to argue
622
 
623
 
624
  ## Changes in 0.15.0
 
 
625
  - Provided test-buttons for checking if the redirects works.
626
  - You can now choose which folders WebP Express is active in. Ie "Uploads and Themes".
627
  - You can now choose an alternative file structure for the webps which does not rely on DOCUMENT_ROOT being available.
128
 
129
  - If you a controlling another WordPress site (where the local conversion methods DO work), you can set up WebP Express there, and then connect to it by configuring the “Remote WebP Express” conversion method.
130
  - You can also setup the ewww conversion method. To use it, you need to purchase an api key. They do not charge credits for webp conversions, so all you ever have to pay is the one dollar start-up fee 🙂 (unless they change their pricing – I have no control over that). You can buy an api key here: https://ewww.io/plans/
131
+ - I have written a [template letter](https://github.com/rosell-dk/webp-convert/wiki/A-template-letter-for-shared-hosts) which you can send to your webhost
132
+ - You can try to get one of the local converters working. Check out [this page](https://github.com/rosell-dk/webp-convert/wiki/Meeting-the-requirements-of-the-converters) on the webp-convert wiki. There is also this [test/troubleshooting script](https://github.com/rosell-dk/webp-convert/wiki/A-PHP-script-for-the-webhost) which is handy when messing around with this.
133
+ - Finally, if you have access to another server and are comfortable with installing projects with composer, you can install [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service). It's open source.
134
+
135
+ Of course, there is also the option of using another plugin altogether. I can recommend [Optimole](https://optimole.pxf.io/20b0M).
136
+
137
 
138
  ### It doesn't work - Although test conversions work, it still serves jpeg images.
139
  Actually, you might be mistaking, so first, make sure that you didn't make the very common mistake of thinking that something with the URL *example.com/image.jpg* must be a jpeg image. The plugin serves webp images on same URL as the original (unconverted) images, so do not let appearances fool you! Confused? See next FAQ item.
155
  I am btw considering making an option to have the plugin redirect to the webp instead of serving immediately. That would remove the apparent mismatch between file extension and content type header. However, the cost of doing that will be an extra request for each image, which means extra time and worse performance. I believe you'd be ill advised to use that option, so I guess I will not implement it. But perhaps you have good reasons to use it? If you do, please let me know!
156
 
157
  ### Blank images in Safari?
158
+ WebP Express has three ways of distributing webp to webp-enabled browsers while still sending the originals to webp-disabled browsers. While method 1 can be combined with any of the other methods, you would usually just pick method 1 or one of the others if method 1 cannot be used for you.
159
 
160
+ Can some of these go wrong?
161
+ Yes. All!
162
 
163
+ #### Method 1: Varied image responses
164
+ The "Varied image responses" method adds rules to the `.htaccess` which redirects jpegs and pngs to the corresponding webps (if they exist). The rules have a condition that makes sure they only trigger for browsers supports webp images (this is established by examining the "accept" header).
165
 
166
+ I the method "varied image responses" because the response on a given image URL *varies* (the webp is served on the same URL as the jpeg/png).
167
 
168
+ In the cases where method 1 fails, it is due to systems that cache images by the URL alone. To prevent this from happening, the `.htaccess` rules adds a `Vary:Accept` response header. However, most CDNs does not respect that header unless they are configured to do so. Fortunately proxy servers respects it nicely (however often by throwing out the cached image if the accept header doesn't match)
169
 
170
+ Method 1 can go wrong if:
 
171
 
172
+ 1. You are using a CDN and it hasn't been set up to handle varied image responses. If this has happened, it is critical that you purge the CDN cache! For information regarding CDN setups, check out the CDN section in this FAQ
173
+ 2. Your server doesn't support adding response headers in `.htaccess`. On Apache, the "mod_headers" module needs to be enabled. Otherwise the all important `Vary:Accept` response header will not be set on the response.
174
+ 3. Your server doesn't support SetEnv. However, that module is fortunately very common. I have posted a possible solution to make the rules work without SetEnv [here](https://wordpress.org/support/topic/setenv/).
175
+ 4. You are on Nginx and you haven't created rules that adds the `Vary:Accept` header.
176
+
177
+ I do not believe it can go wrong in other ways. To be certain, please check out [this test page](http://toste.dk/rh.php). When visiting the test-page with Safari, you should see two images with the “JPG” label over them. When visiting the test-page with a browser that supports webp, you should see two images with the “WEBP” label over them. If you do not see one of these things, please report! (no-one has yet experienced that).
178
+
179
+ Since WebP Express 0.15.0 you can use the "Live test" button to check that browsers not supporting webp gets the original files and that the Vary:Accept header is returned. Note however that it may not detect CDN caching problems if the CDN doesn't cache a new image immediately - and across all its nodes.
180
+
181
+ #### Method 2: Altering HTML to use picture tags
182
+ IMG tags are replaced with PICTURE tags which has two sources. One of them points to the webp and has the "content-type" set to "image/webp". The other points to the original. The browser will select the webp source if it supports webp and the other source if it doesn't.
183
 
184
  Method 2 can go wrong on old browser that doesn't support the picture tag syntax. However, simply enable the "Dynamically load picturefill.js on older browsers" option, and it will take care of that issue.
185
 
186
+ #### Method 3: Altering HTML to point directly to webps in webp enabled browsers
187
+ In this solution, the URLs in the HTML are modified for browsers that supports webp. Again, this is determined by examining the "accept" header. So, actually the complete page HTML varies with this method.
188
+
189
  Method 3 can go wrong if you are using a page caching plugin if that plugin does not create a separate webp cache for webp-enabled browsers. The *Cache Enabler* plugin handles this. I don't believe there are other page caching plugins that does. There is a FAQ section in this FAQ describing how to set *Cache Enabler* up to work in tandem with WebP Express.
190
 
191
+ Note that Firefox 66+ unfortunately stopped including "image/webp" in the "accept" header it sends when requesting *the page*. While Firefox 66+ fortunately still includes "image/webp" in its accept header *for images*. That will however not get it webp images when using method 3.
192
+
193
+
194
  ### I am on NGINX or OpenResty
195
 
196
+ WebP Express works well on NGINX, however the UI is not streamlined NGINX yet. And of course, NGINX does not process the .htaccess files that WebP Express generates. WebP Express can be used without redirection, as it can alter HTML to use picture tags which links to the webp alternative. See "The simple way" below. Or, you can get your hands dirty and set up redirection in NGINX guided by the "The advanced way" section below.
197
+
198
  #### The simple way (no redirecting rules)
199
+ The easy solution is simply to use the plugin in "CDN friendly" mode, do a bulk conversion (takes care of converting existing images), activate the "Convert on upload" option (takes care of converting new images in the media library) and enable Alter HTML (takes care of delivering webp to webp enabled browsers while still delivering the original jpeg/png to browsers not supporting webp).
200
 
201
  *PRO*: Very easy to set up.
202
  *CON*: Images in external CSS and images being dynamically added with javascript will not be served as webp.
252
 
253
  - Beware that if you have moved wp-content to a non-standard place, you must change accordingly. Note that you must then also change the "wp-content" parameter to the script. It expects a relative path to wp-content (from document root) and is needed so the script can find the configuration file.
254
 
255
+ - Beware that there is a hack out there for permalinks which is based on "rewrite" (rather than the usual solution which is based on try_files). If you are using that hack to redirect missing files to index.php, you need to modify it as specified [here](https://wordpress.org/support/topic/nginx-server-404-not-found-when-convert-test-images/page/2/#post-11952444)
256
+
257
  - I have put in an expires statement for caching. You might want to modify or disable that.
258
 
259
  - The rules contains all redirections (as if you enabled all three redirection options in settings). If you do not wish to redirect to converter, remove the last line in the try_files block. If you do not wish to create webp files upon request, remove the last location block.
317
 
318
  - Beware that if you have moved wp-content to a non-standard place, you must change accordingly. Note that you must then also change the "wp-content" parameter to the script. It expects a relative path to wp-content (from document root) and is needed so the script can find the configuration file.
319
 
320
+ - Beware that there is a hack out there for permalinks which is based on "rewrite" (rather than the usual solution which is based on try_files). If you are using that hack to redirect missing files to index.php, you need to modify it as specified [here](https://wordpress.org/support/topic/nginx-server-404-not-found-when-convert-test-images/page/2/#post-11952444)
321
+
322
  - I have put in an expires statement for caching. You might want to modify or disable that.
323
 
324
  - I have not set any expire on the webp-on-demand.php request. This is not needed, as the script sets this according to what you set up in WebP Express settings. Also, trying to do it would require a new location block matching webp-on-demand.php, but that would override the location block handling php files, and thus break the functionality.
634
  ### When is feature X coming? / Roadmap
635
  No schedule. I move forward as time allows. I currently spend a lot of time answering questions in the support forum. If someone would be nice and help out answering questions here, it would allow me to spend that time developing. Also, donations would allow me to turn down some of the more boring requests from my customers, and speed things up here.
636
 
637
+ Here are my current plans ahead: 0.17 will probably be a file manager-like interface for converting / bulk converting / viewing conversion logs / comparing original vs webp visually - kind of a merge of current "test converter" and "bulk conversion" interfaces, and with an addition of a file explorer. 0.18 might allow excluding certain files and folders. 0.19 could be supporting Save-Data header in Varied Image Responses mode (send extra compressed images to clients who wants to use as little bandwidth as possible). 0.19 might be displaying rules for NGINX. 0.20 might be an effort to allow webp for all browsers using [this javascript library](http://libwebpjs.hohenlimburg.org/v0.6.0/). Unfortunately, the javascript librare does not (currently) support srcset attributes, which is why I moved this item down the priority list. We need srcset to be supported for the feature to be useful. 0.21 might be WAMP support. The current milestones, their subtasks and their progress can be viewed here: https://github.com/rosell-dk/webp-express/milestones
638
 
639
  If you wish to affect priorities, it is certainly possible. You can try to argue your case in the forum or you can simply let the money do the talking. By donating as little as a cup of coffee on [ko-fi.com/rosell](https://ko-fi.com/rosell), you can leave a wish. I shall take these wishes into account when prioritizing between new features.
640
 
641
+ ## Changes in 0.16.0 =
642
+ *(released: 24 sep 2019)*
643
+
644
+ - Added option to specify CDN urls in Alter HTML. Thanks to Gunnar Peipman from Estonia for suggesting this.
645
+ - Direct Nginx users to Nginx FAQ section on welcome page
646
+ - Fixed Bulk Conversion halting due to nonce expiry
647
+ - Fixed unexpected output upon reactivation
648
+ - Added affiliate link to [Optimole](https://optimole.pxf.io/20b0M) in the "Don't despair - You have options!" message
649
+
650
+ ## Changes in 0.15.3
651
+ *(released: 19 sep 2019)*
652
+
653
+ * Fixed fatal error upon activation for systems which cannot use document root for structuring (rare)
654
+
655
+ ## Changes in 0.15.2
656
+
657
+ * Fixed the bug when File extension was set to "Set to .webp". It was buggy when file extension contained uppercase letters.
658
+
659
  ## Changes in 0.15.1
660
  *(released: 17 sep 2019)*
661
 
666
 
667
 
668
  ## Changes in 0.15.0
669
+ *(released: 17 sep 2019)*
670
+
671
  - Provided test-buttons for checking if the redirects works.
672
  - You can now choose which folders WebP Express is active in. Ie "Uploads and Themes".
673
  - You can now choose an alternative file structure for the webps which does not rely on DOCUMENT_ROOT being available.
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.2
7
- Stable tag: 0.15.3
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -134,6 +134,8 @@ Don't fret - you have options!
134
  - You can try to get one of the local converters working. Check out [this page](https://github.com/rosell-dk/webp-convert/wiki/Meeting-the-requirements-of-the-converters) on the webp-convert wiki. There is also this [test/troubleshooting script](https://github.com/rosell-dk/webp-convert/wiki/A-PHP-script-for-the-webhost) which is handy when messing around with this.
135
  - Finally, if you have access to another server and are comfortable with installing projects with composer, you can install [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service). It's open source.
136
 
 
 
137
  = It doesn't work - Although test conversions work, it still serves jpeg images =
138
  Actually, you might be mistaking, so first, make sure that you didn't make the very common mistake of thinking that something with the URL *example.com/image.jpg* must be a jpeg image. The plugin serves webp images on same URL as the original (unconverted) images, so do not let appearances fool you! Confused? See next FAQ item.
139
 
@@ -192,8 +194,10 @@ Note that Firefox 66+ unfortunately stopped including "image/webp" in the "accep
192
 
193
  = I am on NGINX or OpenResty =
194
 
 
 
195
  **The simple way (no redirecting rules)**
196
- The easy solution is simply to use the plugin in "CDN friendly" mode, do a bulk conversion (takes care of converting existing images) and activate the "Convert on upload" option (takes care of converting new images in the media library).
197
 
198
  *PRO*: Very easy to set up.
199
  *CON*: Images in external CSS and images being dynamically added with javascript will not be served as webp.
@@ -628,7 +632,7 @@ If you got any further questions, look at, or comment on [this topic](https://wo
628
  = When is feature X coming? / Roadmap =
629
  No schedule. I move forward as time allows. I currently spend a lot of time answering questions in the support forum. If someone would be nice and help out answering questions here, it would allow me to spend that time developing. Also, donations would allow me to turn down some of the more boring requests from my customers, and speed things up here.
630
 
631
- Here are my current plans ahead: 0.15 will probably be a file manager-like interface for converting / bulk converting / viewing conversion logs / comparing original vs webp visually - kind of a merge of current "test converter" and "bulk conversion" interfaces, and with an addition of a file explorer. 0.16 might be various improvements such as option to choose which folders webp express should process (Just uploads / Just uploads and templates / Whole wp-content / Whole system) and options to exclude certain files and folders. 0.17 could be supporting Save-Data header in Varied Image Responses mode (send extra compressed images to clients who wants to use as little bandwidth as possible). 0.18 might be a diagnose tool – this should release some time spend in the forum. 0.18 might be displaying rules for NGINX. 0.19 might be an effort to allow webp for all browsers using [this javascript library](http://libwebpjs.hohenlimburg.org/v0.6.0/). Unfortunately, the javascript librare does not (currently) support srcset attributes, which is why I moved this item down the priority list. We need srcset to be supported for the feature to be useful. 0.20 might be WAMP support. The current milestones, their subtasks and their progress can be viewed here: https://github.com/rosell-dk/webp-express/milestones
632
 
633
  If you wish to affect priorities, it is certainly possible. You can try to argue your case in the forum or you can simply let the money do the talking. By donating as little as a cup of coffee on [ko-fi.com/rosell](https://ko-fi.com/rosell), you can leave a wish. I shall take these wishes into account when prioritizing between new features.
634
 
@@ -641,6 +645,15 @@ Easy enough! - [Go here!](https://ko-fi.com/rosell). Or [here](https://buymeacof
641
 
642
  == Changelog ==
643
 
 
 
 
 
 
 
 
 
 
644
  = 0.15.3 =
645
  *(released: 19 sep 2019)*
646
 
@@ -1006,6 +1019,9 @@ For older releases, check out changelog.txt
1006
 
1007
  == Upgrade Notice ==
1008
 
 
 
 
1009
  = 0.15.3 =
1010
  * Fixed fatal error upon activation for systems which cannot use document root for structuring (rare)
1011
 
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
+ Stable tag: 0.16.0
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
134
  - You can try to get one of the local converters working. Check out [this page](https://github.com/rosell-dk/webp-convert/wiki/Meeting-the-requirements-of-the-converters) on the webp-convert wiki. There is also this [test/troubleshooting script](https://github.com/rosell-dk/webp-convert/wiki/A-PHP-script-for-the-webhost) which is handy when messing around with this.
135
  - Finally, if you have access to another server and are comfortable with installing projects with composer, you can install [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service). It's open source.
136
 
137
+ Of course, there is also the option of using another plugin altogether. I can recommend [Optimole](https://optimole.pxf.io/20b0M).
138
+
139
  = It doesn't work - Although test conversions work, it still serves jpeg images =
140
  Actually, you might be mistaking, so first, make sure that you didn't make the very common mistake of thinking that something with the URL *example.com/image.jpg* must be a jpeg image. The plugin serves webp images on same URL as the original (unconverted) images, so do not let appearances fool you! Confused? See next FAQ item.
141
 
194
 
195
  = I am on NGINX or OpenResty =
196
 
197
+ WebP Express works well on NGINX, however the UI is not streamlined NGINX yet. And of course, NGINX does not process the .htaccess files that WebP Express generates. WebP Express can be used without redirection, as it can alter HTML to use picture tags which links to the webp alternative. See "The simple way" below. Or, you can get your hands dirty and set up redirection in NGINX guided by the "The advanced way" section below.
198
+
199
  **The simple way (no redirecting rules)**
200
+ The easy solution is simply to use the plugin in "CDN friendly" mode, do a bulk conversion (takes care of converting existing images), activate the "Convert on upload" option (takes care of converting new images in the media library) and enable Alter HTML (takes care of delivering webp to webp enabled browsers while still delivering the original jpeg/png to browsers not supporting webp).
201
 
202
  *PRO*: Very easy to set up.
203
  *CON*: Images in external CSS and images being dynamically added with javascript will not be served as webp.
632
  = When is feature X coming? / Roadmap =
633
  No schedule. I move forward as time allows. I currently spend a lot of time answering questions in the support forum. If someone would be nice and help out answering questions here, it would allow me to spend that time developing. Also, donations would allow me to turn down some of the more boring requests from my customers, and speed things up here.
634
 
635
+ Here are my current plans ahead: 0.17 will probably be a file manager-like interface for converting / bulk converting / viewing conversion logs / comparing original vs webp visually - kind of a merge of current "test converter" and "bulk conversion" interfaces, and with an addition of a file explorer. 0.18 might allow excluding certain files and folders. 0.19 could be supporting Save-Data header in Varied Image Responses mode (send extra compressed images to clients who wants to use as little bandwidth as possible). 0.19 might be displaying rules for NGINX. 0.20 might be an effort to allow webp for all browsers using [this javascript library](http://libwebpjs.hohenlimburg.org/v0.6.0/). Unfortunately, the javascript librare does not (currently) support srcset attributes, which is why I moved this item down the priority list. We need srcset to be supported for the feature to be useful. 0.21 might be WAMP support. The current milestones, their subtasks and their progress can be viewed here: https://github.com/rosell-dk/webp-express/milestones
636
 
637
  If you wish to affect priorities, it is certainly possible. You can try to argue your case in the forum or you can simply let the money do the talking. By donating as little as a cup of coffee on [ko-fi.com/rosell](https://ko-fi.com/rosell), you can leave a wish. I shall take these wishes into account when prioritizing between new features.
638
 
645
 
646
  == Changelog ==
647
 
648
+ = 0.16.0 =
649
+ *(released: 24 sep 2019)*
650
+
651
+ * Added option to specify CDN urls in Alter HTML. Thanks to Gunnar Peipman from Estonia for suggesting this.
652
+ * Direct Nginx users to Nginx FAQ section on welcome page
653
+ * Fixed Bulk Conversion halting due to nonce expiry
654
+ * Fixed unexpected output upon reactivation
655
+ * Added affiliate link to [Optimole](https://optimole.pxf.io/20b0M) in the "Don't despair - You have options!" message
656
+
657
  = 0.15.3 =
658
  *(released: 19 sep 2019)*
659
 
1019
 
1020
  == Upgrade Notice ==
1021
 
1022
+ = 0.16.0 =
1023
+ * Various improvements and fixes
1024
+
1025
  = 0.15.3 =
1026
  * Fixed fatal error upon activation for systems which cannot use document root for structuring (rare)
1027
 
changelog.txt CHANGED
@@ -1,3 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  = 0.15.2 =
2
 
3
  * Fixed the bug when File extension was set to "Set to .webp". It was buggy when file extension contained uppercase letters.
1
+ = 0.16.0 =
2
+ *(released: 24 sep 2019)*
3
+
4
+ * Added option to specify CDN urls in Alter HTML. Thanks to Gunnar Peipman from Estonia for suggesting this.
5
+ * Direct Nginx users to Nginx FAQ section on welcome page
6
+ * Fixed Bulk Conversion halting due to nonce expiry
7
+ * Fixed unexpected output upon reactivation
8
+ * Added affiliate link to [Optimole](https://optimole.pxf.io/20b0M) in the "Don't despair - You have options!" message
9
+
10
+ = 0.15.3 =
11
+ *(released: 19 sep 2019)*
12
+
13
+ * Fixed fatal error upon activation for systems which cannot use document root for structuring (rare)
14
+
15
  = 0.15.2 =
16
 
17
  * Fixed the bug when File extension was set to "Set to .webp". It was buggy when file extension contained uppercase letters.
js/0.16.0/plugin-page.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($) {
2
+ $(document).ready(function () {
3
+ /*
4
+ TODO:
5
+ Add link to Optimole when "deactivate" link is clicked / uninstalled #356
6
+ https://github.com/rosell-dk/webp-express/issues/356
7
+
8
+ var linkEl = $('tr[data-plugin^="webp-express/"] span.deactivate a');
9
+ //console.log(el);
10
+ linkEl.on('click', function (e) {
11
+ //e.preventDefault();
12
+ //e.stopPropagation();
13
+ //alert('NO!');
14
+ });
15
+ */
16
+ });
17
+ })(jQuery);
lib/classes/AdminInit.php CHANGED
@@ -25,6 +25,8 @@ class AdminInit
25
  }
26
 
27
  self::addHooks();
 
 
28
  }
29
 
30
  public static function runMigrationIfNeeded()
@@ -41,16 +43,31 @@ class AdminInit
41
  //include WEBPEXPRESS_PLUGIN_DIR . '/lib/migrate/migrate11.php';
42
  }
43
 
44
- public static function adminInitHandler()
 
 
 
 
 
 
 
 
 
 
45
  {
46
 
47
  if (current_user_can('manage_options')) {
48
 
49
  // Hooks related to options page
 
 
 
 
 
50
 
51
- global $pagenow;
52
- if ((('options-general.php' === $pagenow) || (('settings.php' === $pagenow))) && (isset($_GET['page'])) && ('webp_express_settings_page' === $_GET['page'])) {
53
- add_action('admin_enqueue_scripts', array('\WebPExpress\OptionsPage', 'enqueueScripts'));
54
  }
55
 
56
  add_action("admin_post_webpexpress_settings_submit", array('\WebPExpress\OptionsPageHooks', 'submitHandler'));
@@ -82,7 +99,8 @@ class AdminInit
82
  register_deactivation_hook(WEBPEXPRESS_PLUGIN, array('\WebPExpress\PluginDeactivate', 'deactivate'));
83
  register_uninstall_hook(WEBPEXPRESS_PLUGIN, array('\WebPExpress\PluginUninstall', 'uninstall'));
84
 
85
- add_action("admin_init", array('\WebPExpress\AdminInit', 'adminInitHandler'));
 
86
 
87
  if (Multisite::isNetworkActivated()) {
88
  add_action("network_admin_menu", array('\WebPExpress\AdminUi', 'networAdminMenuHook'));
25
  }
26
 
27
  self::addHooks();
28
+
29
+
30
  }
31
 
32
  public static function runMigrationIfNeeded()
43
  //include WEBPEXPRESS_PLUGIN_DIR . '/lib/migrate/migrate11.php';
44
  }
45
 
46
+ public static function pageNowIs($pageId)
47
+ {
48
+ global $pagenow;
49
+
50
+ if ((!isset($pagenow)) || (empty($pagenow))) {
51
+ return false;
52
+ }
53
+ return ($pageId == $pagenow);
54
+ }
55
+
56
+ public static function addHooksAfterAdminInit()
57
  {
58
 
59
  if (current_user_can('manage_options')) {
60
 
61
  // Hooks related to options page
62
+ if (self::pageNowIs('options-general.php') || self::pageNowIs('settings.php')) {
63
+ if (isset($_GET['page']) && ('webp_express_settings_page' === $_GET['page'])) {
64
+ add_action('admin_enqueue_scripts', array('\WebPExpress\OptionsPage', 'enqueueScripts'));
65
+ }
66
+ }
67
 
68
+ // Hooks related to plugins page
69
+ if (self::pageNowIs('plugins.php')) {
70
+ add_action('admin_enqueue_scripts', array('\WebPExpress\PluginPageScript', 'enqueueScripts'));
71
  }
72
 
73
  add_action("admin_post_webpexpress_settings_submit", array('\WebPExpress\OptionsPageHooks', 'submitHandler'));
99
  register_deactivation_hook(WEBPEXPRESS_PLUGIN, array('\WebPExpress\PluginDeactivate', 'deactivate'));
100
  register_uninstall_hook(WEBPEXPRESS_PLUGIN, array('\WebPExpress\PluginUninstall', 'uninstall'));
101
 
102
+ // Some hooks must be registered AFTER admin_init...
103
+ add_action("admin_init", array('\WebPExpress\AdminInit', 'addHooksAfterAdminInit'));
104
 
105
  if (Multisite::isNetworkActivated()) {
106
  add_action("network_admin_menu", array('\WebPExpress\AdminUi', 'networAdminMenuHook'));
lib/classes/AlterHtmlHelper.php CHANGED
@@ -130,7 +130,7 @@ class AlterHtmlHelper
130
 
131
 
132
  /**
133
- * Get url for webp, given a certain baseUrl / baseDir.
134
  * Base can for example be uploads or wp-content.
135
  *
136
  * returns false
@@ -142,9 +142,9 @@ class AlterHtmlHelper
142
  * @param string $baseUrl Base url of source image (ie http://example.com/wp-content)
143
  * @param string $baseDir Base dir of source image (ie /var/www/example.com/wp-content)
144
  */
145
- public static function getWebPUrlInBase($sourceUrl, $rootId, $baseUrl, $baseDir)
146
  {
147
- //error_log('getWebPUrlInBase:' . $sourceUrl . ':' . $baseUrl . ':' . $baseDir);
148
 
149
  $srcPathRel = self::getRelUrlPath($sourceUrl, $baseUrl);
150
 
@@ -208,16 +208,23 @@ class AlterHtmlHelper
208
  */
209
  public static function getWebPUrl($sourceUrl, $returnValueOnFail)
210
  {
211
- if (!isset(self::$options)) {
212
- self::$options = json_decode(Option::getOption('webp-express-alter-html-options', null), true);
213
- }
214
 
 
 
 
 
215
 
216
- // Currently we do not handle relative urls - so we skip
217
  if (!preg_match('#^https?://#', $sourceUrl)) {
218
  return $returnValueOnFail;
219
  }
220
 
 
 
 
 
 
 
221
  switch (self::$options['image-types']) {
222
  case 0:
223
  return $returnValueOnFail;
@@ -238,21 +245,54 @@ class AlterHtmlHelper
238
  break;
239
  }
240
 
241
- if ((self::$options['only-for-webp-enabled-browsers']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') === false)) {
242
- return $returnValueOnFail;
243
- }
244
 
245
- foreach (self::$options['bases'] as $id => list($baseDir, $baseUrl)) {
246
- if (Multisite::isMultisite() && ($id == 'uploads')) {
 
 
247
  $baseUrl = Paths::getUploadUrl();
248
  $baseDir = Paths::getUploadDirAbs();
249
  }
250
 
251
- $result = self::getWebPUrlInBase($sourceUrl, $id, $baseUrl, $baseDir);
252
  if ($result !== false) {
253
  return $result;
254
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  }
 
256
  return $returnValueOnFail;
257
  }
258
 
130
 
131
 
132
  /**
133
+ * Get url for webp from source url, (if ), given a certain baseUrl / baseDir.
134
  * Base can for example be uploads or wp-content.
135
  *
136
  * returns false
142
  * @param string $baseUrl Base url of source image (ie http://example.com/wp-content)
143
  * @param string $baseDir Base dir of source image (ie /var/www/example.com/wp-content)
144
  */
145
+ public static function getWebPUrlInImageRoot($sourceUrl, $rootId, $baseUrl, $baseDir)
146
  {
147
+ //error_log('getWebPUrlInImageRoot:' . $sourceUrl . ':' . $baseUrl . ':' . $baseDir);
148
 
149
  $srcPathRel = self::getRelUrlPath($sourceUrl, $baseUrl);
150
 
208
  */
209
  public static function getWebPUrl($sourceUrl, $returnValueOnFail)
210
  {
 
 
 
211
 
212
+ // Fail for webp-disabled browsers (when "only-for-webp-enabled-browsers" is set)
213
+ if ((self::$options['only-for-webp-enabled-browsers']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') === false)) {
214
+ return $returnValueOnFail;
215
+ }
216
 
217
+ // Fail for relative urls. Wordpress doesn't use such very much anyway
218
  if (!preg_match('#^https?://#', $sourceUrl)) {
219
  return $returnValueOnFail;
220
  }
221
 
222
+ // Get the options
223
+ if (!isset(self::$options)) {
224
+ self::$options = json_decode(Option::getOption('webp-express-alter-html-options', null), true);
225
+ }
226
+
227
+ // Fail if the image type isn't enabled
228
  switch (self::$options['image-types']) {
229
  case 0:
230
  return $returnValueOnFail;
245
  break;
246
  }
247
 
248
+ //error_log('source url:' . $sourceUrl);
 
 
249
 
250
+ // Try all image roots
251
+ foreach (self::$options['bases'] as $rootId => list($baseDir, $baseUrl)) {
252
+ //error_log('baseurl: ' . $baseUrl);
253
+ if (Multisite::isMultisite() && ($rootId == 'uploads')) {
254
  $baseUrl = Paths::getUploadUrl();
255
  $baseDir = Paths::getUploadDirAbs();
256
  }
257
 
258
+ $result = self::getWebPUrlInImageRoot($sourceUrl, $rootId, $baseUrl, $baseDir);
259
  if ($result !== false) {
260
  return $result;
261
  }
262
+
263
+ // Try the hostname aliases.
264
+ if (!isset(self::$options['hostname-aliases'])) {
265
+ continue;
266
+ }
267
+ $hostnameAliases = self::$options['hostname-aliases'];
268
+
269
+ $hostname = Paths::getHostNameOfUrl($baseUrl);
270
+ $baseUrlComponents = parse_url($baseUrl);
271
+ $sourceUrlComponents = parse_url($sourceUrl);
272
+ // ie: [scheme] => http, [host] => we0, [path] => /wordpress/uploads-moved
273
+
274
+ if ((!isset($baseUrlComponents['host'])) || (!isset($sourceUrlComponents['host']))) {
275
+ continue;
276
+ }
277
+
278
+ foreach ($hostnameAliases as $hostnameAlias) {
279
+
280
+ if ($sourceUrlComponents['host'] != $hostnameAlias) {
281
+ continue;
282
+ }
283
+ //error_log('hostname alias:' . $hostnameAlias);
284
+
285
+ $baseUrlOnAlias = $baseUrlComponents['scheme'] . '://' . $hostnameAlias . $baseUrlComponents['path'];
286
+ //error_log('baseurl (alias):' . $baseUrlOnAlias);
287
+
288
+ $result = self::getWebPUrlInImageRoot($sourceUrl, $rootId, $baseUrlOnAlias, $baseDir);
289
+ if ($result !== false) {
290
+ $resultUrlComponents = parse_url($result);
291
+ return $sourceUrlComponents['scheme'] . '://' . $hostnameAlias . $resultUrlComponents['path'];
292
+ }
293
+ }
294
  }
295
+
296
  return $returnValueOnFail;
297
  }
298
 
lib/classes/Config.php CHANGED
@@ -114,6 +114,7 @@ class Config
114
  'only-for-webp-enabled-browsers' => true, // If true, there will be two HTML versions of each page
115
  'only-for-webps-that-exists' => false,
116
  'alter-html-add-picturefill-js' => true,
 
117
  ],
118
 
119
  // web service
@@ -231,6 +232,14 @@ class Config
231
  $config['operation-mode'] = 'varied-image-responses';
232
  }
233
 
 
 
 
 
 
 
 
 
234
  $config = self::applyOperationMode($config);
235
 
236
  // Fix scope: Remove invalid and put in correct order
@@ -259,6 +268,10 @@ class Config
259
  $config['cache-control-max-age'] = 'one-week';
260
  }
261
 
 
 
 
 
262
  if (!is_array($config['converters'])) {
263
  $config['converters'] = [];
264
  }
@@ -468,7 +481,6 @@ class Config
468
  $obj['destination-extension'] = $config['destination-extension'];
469
  $obj['destination-structure'] = $config['destination-structure'];
470
 
471
-
472
  $obj['bases'] = [];
473
  foreach ($config['scope'] as $rootId) {
474
  $obj['bases'][$rootId] = [
@@ -751,7 +763,7 @@ class Config
751
  $options = self::generateWodOptionsFromConfigObj($config);
752
  if (self::saveWodOptionsFile($options)) {
753
  if ($rewriteRulesNeedsUpdate) {
754
- $rulesResult = HTAccess::saveRules($config);
755
  return [
756
  'saved-both-config' => true,
757
  'saved-main-config' => true,
@@ -760,7 +772,7 @@ class Config
760
  ];
761
  }
762
  else {
763
- $rulesResult = HTAccess::saveRules($config);
764
  return [
765
  'saved-both-config' => true,
766
  'saved-main-config' => true,
114
  'only-for-webp-enabled-browsers' => true, // If true, there will be two HTML versions of each page
115
  'only-for-webps-that-exists' => false,
116
  'alter-html-add-picturefill-js' => true,
117
+ 'hostname-aliases' => []
118
  ],
119
 
120
  // web service
232
  $config['operation-mode'] = 'varied-image-responses';
233
  }
234
 
235
+ // In case doc root no longer can be used, use image-roots
236
+ // Or? No, changing here will not fix it for WebPOnDemand.php.
237
+ // An invalid setting requires that config is saved again and .htaccess files regenerated.
238
+ /*
239
+ if (($config['operation-mode'] == 'doc-root') && (!Paths::canUseDocRootForRelPaths())) {
240
+ $config['destination-structure'] = 'image-roots';
241
+ }*/
242
+
243
  $config = self::applyOperationMode($config);
244
 
245
  // Fix scope: Remove invalid and put in correct order
268
  $config['cache-control-max-age'] = 'one-week';
269
  }
270
 
271
+ /*if (is_null($config['alter-html']['hostname-aliases'])) {
272
+ $config['alter-html']['hostname-aliases'] = [];
273
+ }*/
274
+
275
  if (!is_array($config['converters'])) {
276
  $config['converters'] = [];
277
  }
481
  $obj['destination-extension'] = $config['destination-extension'];
482
  $obj['destination-structure'] = $config['destination-structure'];
483
 
 
484
  $obj['bases'] = [];
485
  foreach ($config['scope'] as $rootId) {
486
  $obj['bases'][$rootId] = [
763
  $options = self::generateWodOptionsFromConfigObj($config);
764
  if (self::saveWodOptionsFile($options)) {
765
  if ($rewriteRulesNeedsUpdate) {
766
+ $rulesResult = HTAccess::saveRules($config, false);
767
  return [
768
  'saved-both-config' => true,
769
  'saved-main-config' => true,
772
  ];
773
  }
774
  else {
775
+ $rulesResult = HTAccess::saveRules($config, false);
776
  return [
777
  'saved-both-config' => true,
778
  'saved-main-config' => true,
lib/classes/Convert.php CHANGED
@@ -44,7 +44,7 @@ class Convert
44
  $activeRootIds = Paths::getImageRootIds(); // Currently, root ids cannot be selected, so all root ids are active.
45
  $rootId = Paths::findImageRootOfPath($source, $activeRootIds);
46
  if ($rootId === false) {
47
- throw new Exception('Path of source is not within a valid image root');
48
  }
49
 
50
  // Check config
@@ -111,7 +111,7 @@ class Convert
111
  );
112
  $relPathFromImageRootToDest = ConvertHelperIndependent::appendOrSetExtension(
113
  $relPathFromImageRootToSource,
114
- $config['destination-folder'],
115
  $config['destination-extension'],
116
  ($rootId == 'uploads')
117
  );
@@ -162,7 +162,17 @@ class Convert
162
  {
163
 
164
  if (!check_ajax_referer('webpexpress-ajax-convert-nonce', 'nonce', false)) {
165
- wp_send_json_error('Invalid security nonce (it has probably expired - try refreshing)');
 
 
 
 
 
 
 
 
 
 
166
  wp_die();
167
  }
168
 
@@ -254,6 +264,14 @@ class Convert
254
  $result = self::convertFile($filename);
255
  }
256
 
 
 
 
 
 
 
 
 
257
  echo json_encode($result, JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
258
  wp_die();
259
  }
44
  $activeRootIds = Paths::getImageRootIds(); // Currently, root ids cannot be selected, so all root ids are active.
45
  $rootId = Paths::findImageRootOfPath($source, $activeRootIds);
46
  if ($rootId === false) {
47
+ throw new \Exception('Path of source is not within a valid image root');
48
  }
49
 
50
  // Check config
111
  );
112
  $relPathFromImageRootToDest = ConvertHelperIndependent::appendOrSetExtension(
113
  $relPathFromImageRootToSource,
114
+ $config['destination-folder'],
115
  $config['destination-extension'],
116
  ($rootId == 'uploads')
117
  );
162
  {
163
 
164
  if (!check_ajax_referer('webpexpress-ajax-convert-nonce', 'nonce', false)) {
165
+ //if (true) {
166
+ //wp_send_json_error('Invalid security nonce (it has probably expired - try refreshing)');
167
+ //wp_die();
168
+
169
+ $result = [
170
+ 'success' => false,
171
+ 'msg' => 'Invalid security nonce (it has probably expired - try refreshing)',
172
+ 'stop' => true
173
+ ];
174
+
175
+ echo json_encode($result, JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
176
  wp_die();
177
  }
178
 
264
  $result = self::convertFile($filename);
265
  }
266
 
267
+ $nonceTick = wp_verify_nonce($_REQUEST['nonce'], 'webpexpress-ajax-convert-nonce');
268
+ if ($nonceTick == 2) {
269
+ $result['new-convert-nonce'] = wp_create_nonce('webpexpress-ajax-convert-nonce');
270
+ // wp_create_nonce('webpexpress-ajax-convert-nonce')
271
+ }
272
+
273
+ $result['nonce-tick'] = $nonceTick;
274
+
275
  echo json_encode($result, JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
276
  wp_die();
277
  }
lib/classes/ConvertHelperIndependent.php CHANGED
@@ -569,7 +569,7 @@ APACHE
569
 
570
  $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
571
 
572
- $text = 'WebP Express 0.15.3. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
573
 
574
  $logFile = self::getLogFilename($source, $logDir);
575
 
569
 
570
  $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
571
 
572
+ $text = 'WebP Express 0.16.0. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
573
 
574
  $logFile = self::getLogFilename($source, $logDir);
575
 
lib/classes/HTAccess.php CHANGED
@@ -303,6 +303,7 @@ class HTAccess
303
 
304
  $rootsToClean = Paths::getImageRootIds();
305
  $rootsToClean[] = 'home';
 
306
  $failures = [];
307
  $successes = [];
308
 
@@ -329,6 +330,7 @@ class HTAccess
329
  }
330
 
331
  public static function testLinks($config) {
 
332
  if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false )) {
333
  if ($config['operation-mode'] != 'no-conversion') {
334
  if ($config['image-types'] != 0) {
@@ -351,7 +353,7 @@ class HTAccess
351
  return $links;
352
  }
353
  }
354
- }
355
  return '';
356
  }
357
 
@@ -386,7 +388,7 @@ class HTAccess
386
  ];
387
  }
388
 
389
- public static function saveRules($config) {
390
  list($success, $failedDeactivations, $successfulDeactivations) = self::deactivateHTAccessRules('# The rules have left the building');
391
 
392
  $rootsToPutRewritesIn = $config['scope'];
@@ -396,6 +398,7 @@ class HTAccess
396
  }
397
 
398
  $dirsContainingWebps = [];
 
399
  $mingled = ($config['destination-folder'] == 'mingled');
400
  if ($mingled) {
401
  $dirsContainingWebps[] = 'uploads';
@@ -406,7 +409,7 @@ class HTAccess
406
  $dirsContainingWebps[] = 'cache';
407
  }
408
 
409
- $dirsToPutRewritesIn = array_merge($rootsToPutRewritesIn, $dirsContainingWebps);
410
 
411
  $failedWrites = [];
412
  $successfullWrites = [];
@@ -443,7 +446,58 @@ class HTAccess
443
  }
444
 
445
  $success = ((count($failedDeactivations) == 0) && (count($failedWrites) == 0));
446
- return [$success, $successfullWrites, $successfulDeactivations, $failedWrites, $failedDeactivations];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
  }
448
 
449
  }
303
 
304
  $rootsToClean = Paths::getImageRootIds();
305
  $rootsToClean[] = 'home';
306
+ $rootsToClean[] = 'cache';
307
  $failures = [];
308
  $successes = [];
309
 
330
  }
331
 
332
  public static function testLinks($config) {
333
+ /*
334
  if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false )) {
335
  if ($config['operation-mode'] != 'no-conversion') {
336
  if ($config['image-types'] != 0) {
353
  return $links;
354
  }
355
  }
356
+ }*/
357
  return '';
358
  }
359
 
388
  ];
389
  }
390
 
391
+ public static function saveRules($config, $showMessage = true) {
392
  list($success, $failedDeactivations, $successfulDeactivations) = self::deactivateHTAccessRules('# The rules have left the building');
393
 
394
  $rootsToPutRewritesIn = $config['scope'];
398
  }
399
 
400
  $dirsContainingWebps = [];
401
+
402
  $mingled = ($config['destination-folder'] == 'mingled');
403
  if ($mingled) {
404
  $dirsContainingWebps[] = 'uploads';
409
  $dirsContainingWebps[] = 'cache';
410
  }
411
 
412
+ $dirsToPutRewritesIn = array_unique(array_merge($rootsToPutRewritesIn, $dirsContainingWebps));
413
 
414
  $failedWrites = [];
415
  $successfullWrites = [];
446
  }
447
 
448
  $success = ((count($failedDeactivations) == 0) && (count($failedWrites) == 0));
449
+
450
+ $return = [$success, $successfullWrites, $successfulDeactivations, $failedWrites, $failedDeactivations];
451
+ if ($showMessage) {
452
+ self::showSaveRulesMessages($return);
453
+ }
454
+ return $return;
455
+ }
456
+
457
+ public static function showSaveRulesMessages($saveRulesResult)
458
+ {
459
+ list($success, $successfullWrites, $successfulDeactivations, $failedWrites, $failedDeactivations) = $saveRulesResult;
460
+
461
+ $msg = '';
462
+ if (count($successfullWrites) > 0) {
463
+ $msg .= '<p>Rewrite rules were saved to the following files:</p>';
464
+ foreach ($successfullWrites as $rootId) {
465
+ $msg .= '<i>' . Paths::getAbsDirById($rootId) . '/.htaccess</i> (' . $rootId . ')<br>';
466
+ }
467
+ }
468
+
469
+ if (count($successfulDeactivations) > 0) {
470
+ $msg .= '<p>Rewrite rules were removed from the following files:</p>';
471
+ foreach ($successfulDeactivations as $rootId) {
472
+ $msg .= '<i>' . Paths::getAbsDirById($rootId) . '/.htaccess</i> (' . $rootId . ')<br>';
473
+ }
474
+ }
475
+
476
+ if ($msg != '') {
477
+ Messenger::addMessage(
478
+ ($success ? 'success' : 'info'),
479
+ $msg
480
+ );
481
+ }
482
+
483
+ if (count($failedWrites) > 0) {
484
+ $msg = '<p>Failed writing rewrite rules to the following files:</p>';
485
+ foreach ($failedWrites as $rootId) {
486
+ $msg .= '<i>' . Paths::getAbsDirById($rootId) . '/.htaccess</i> (' . $rootId . ')<br>';
487
+ }
488
+ $msg .= 'You need to change the file permissions to allow WebP Express to save the rules.';
489
+ Messenger::addMessage('error', $msg);
490
+ } else {
491
+ if (count($failedDeactivations) > 0) {
492
+ $msg = '<p>Failed deleting unused rewrite rules in the following files:</p>';
493
+ foreach ($failedDeactivations as $rootId) {
494
+ $msg .= '<i>' . Paths::getAbsDirById($rootId) . '/.htaccess</i> (' . $rootId . ')<br>';
495
+ }
496
+ $msg .= 'You need to change the file permissions to allow WebP Express to remove the rules or ' .
497
+ 'remove them manually';
498
+ Messenger::addMessage('error', $msg);
499
+ }
500
+ }
501
  }
502
 
503
  }
lib/classes/Paths.php CHANGED
@@ -608,6 +608,21 @@ APACHE
608
  return self::getUrlPathFromUrl(self::getUrlById($dirId));
609
  }
610
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
611
 
612
  // Get complete home url (no trailing slash). Ie: "http://example.com/blog"
613
  public static function getHomeUrl()
608
  return self::getUrlPathFromUrl(self::getUrlById($dirId));
609
  }
610
 
611
+ public static function getHostNameOfUrl($url) {
612
+ $urlComponents = parse_url($url);
613
+ /* ie:
614
+ (
615
+ [scheme] => http
616
+ [host] => we0
617
+ [path] => /wordpress/uploads-moved
618
+ )*/
619
+
620
+ if (!isset($urlComponents['host'])) {
621
+ return '';
622
+ } else {
623
+ return $urlComponents['host'];
624
+ }
625
+ }
626
 
627
  // Get complete home url (no trailing slash). Ie: "http://example.com/blog"
628
  public static function getHomeUrl()
lib/classes/PluginActivate.php CHANGED
@@ -37,20 +37,10 @@ class PluginActivate
37
  '<a href="' . Paths::getSettingsUrl() . '">(here)</a>.'
38
  );
39
  } else {
40
- $rulesResult = HTAccess::saveRules($config);
41
- /*
42
- 'mainResult' // 'index', 'wp-content' or 'failed'
43
- 'minRequired' // 'index' or 'wp-content'
44
- 'pluginToo' // 'yes', 'no' or 'depends'
45
- 'pluginFailed' // true if failed to write to plugin folder (it only tries that, if pluginToo == 'yes')
46
- 'pluginFailedBadly' // true if plugin failed AND it seems we have rewrite rules there
47
- 'overidingRulesInWpContentWarning' // true if main result is 'index' but we cannot remove those in wp-content
48
- 'rules' // the rules that were generated
49
- */
50
- $mainResult = $rulesResult['mainResult'];
51
- $rules = $rulesResult['rules'];
52
-
53
- if ($mainResult != 'failed') {
54
  Messenger::addMessage(
55
  'success',
56
  'WebP Express re-activated successfully.<br>' .
@@ -67,8 +57,9 @@ class PluginActivate
67
  '<a href="' . Paths::getSettingsUrl() . '">settings page</a> ' .
68
  'and try to save the settings there (it will provide more information about the problem)'
69
  );
70
-
71
  }
 
 
72
  }
73
  }
74
 
37
  '<a href="' . Paths::getSettingsUrl() . '">(here)</a>.'
38
  );
39
  } else {
40
+ $rulesResult = HTAccess::saveRules($config, false);
41
+
42
+ $rulesSaveSuccess = $rulesResult[0];
43
+ if ($rulesSaveSuccess) {
 
 
 
 
 
 
 
 
 
 
44
  Messenger::addMessage(
45
  'success',
46
  'WebP Express re-activated successfully.<br>' .
57
  '<a href="' . Paths::getSettingsUrl() . '">settings page</a> ' .
58
  'and try to save the settings there (it will provide more information about the problem)'
59
  );
 
60
  }
61
+
62
+ HTAccess::showSaveRulesMessages($rulesResult);
63
  }
64
  }
65
 
lib/classes/PluginDeactivate.php CHANGED
@@ -9,7 +9,10 @@ class PluginDeactivate
9
 
10
  list($success, $failures, $successes) = HTAccess::deactivateHTAccessRules();
11
 
12
- if (!$success) {
 
 
 
13
  // Oh no. We failed removing the rules
14
  $msg = "<b>Sorry, can't let you disable WebP Express!</b><br>" .
15
  'There are rewrite rules in the <i>.htaccess</i> that could not be removed. If these are not removed, it would break all images.<br>' .
9
 
10
  list($success, $failures, $successes) = HTAccess::deactivateHTAccessRules();
11
 
12
+ if ($success) {
13
+ // Oh, it would be nice to be able to add a goodbye message here...
14
+ // But well, that cannot be done here.
15
+ } else {
16
  // Oh no. We failed removing the rules
17
  $msg = "<b>Sorry, can't let you disable WebP Express!</b><br>" .
18
  'There are rewrite rules in the <i>.htaccess</i> that could not be removed. If these are not removed, it would break all images.<br>' .
lib/classes/PluginPageScript.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WebPExpress;
4
+
5
+ class PluginPageScript
6
+ {
7
+ // The hook was registred in AdminInit
8
+ public static function enqueueScripts() {
9
+ $ver = '1'; // note: Minimum 1
10
+ $jsDir = 'js/0.16.0'; // We change dir when it is critical that no-one gets the cached version (there is a plugin that strips version strings out there...)
11
+
12
+ if (!function_exists('webp_express_add_inline_script')) {
13
+ function webp_express_add_inline_script($id, $script, $position) {
14
+ if (function_exists('wp_add_inline_script')) {
15
+ // wp_add_inline_script is available from Wordpress 4.5
16
+ wp_add_inline_script($id, $script, $position);
17
+ } else {
18
+ echo '<script>' . $script . '</script>';
19
+ }
20
+ }
21
+ }
22
+
23
+ wp_register_script('webpexpress-plugin-page', plugins_url($jsDir . '/plugin-page.js', dirname(dirname(__FILE__))), [], '1.9.0');
24
+ wp_enqueue_script('webpexpress-plugin-page');
25
+ }
26
+ }
lib/classes/SelfTestRedirectToWebPRealizer.php CHANGED
@@ -39,7 +39,7 @@ class SelfTestRedirectToWebPRealizer extends SelfTestRedirectAbstract
39
  AlterHtmlHelper::$options = json_decode(Option::getOption('webp-express-alter-html-options', null), true);
40
  AlterHtmlHelper::$options['only-for-webps-that-exists'] = false;
41
 
42
- $requestUrl = AlterHtmlHelper::getWebPUrlInBase(
43
  $sourceUrl,
44
  $rootId,
45
  Paths::getUrlById($rootId),
39
  AlterHtmlHelper::$options = json_decode(Option::getOption('webp-express-alter-html-options', null), true);
40
  AlterHtmlHelper::$options['only-for-webps-that-exists'] = false;
41
 
42
+ $requestUrl = AlterHtmlHelper::getWebPUrlInImageRoot(
43
  $sourceUrl,
44
  $rootId,
45
  Paths::getUrlById($rootId),
lib/dismissable-messages/0.16.0/nginx-link-to-faq.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WebPExpress;
4
+
5
+ /*echo '<p>You are running on NGINX. WebP Express works well on NGINX, however this UI is not streamlined NGINX yet. </p>' .
6
+ '<p><b>You should head over to the </b>' .
7
+ '<a href="https://wordpress.org/plugins/webp-express/#i%20am%20on%20nginx%20or%20openresty" target="_blank"><b>NGINX section in the FAQ</b></a>' .
8
+ '<b> to learn how to use WebP Express on NGINX</b></p>';*/
9
+
10
+
11
+ DismissableMessages::printDismissableMessage(
12
+ 'warning',
13
+ '<p>You are running on NGINX. WebP Express works well on NGINX, however this UI is not streamlined NGINX yet. </p>' .
14
+ '<p><b>You should head over to the </b>' .
15
+ '<a href="https://wordpress.org/plugins/webp-express/#i%20am%20on%20nginx%20or%20openresty" target="_blank"><b>NGINX section in the FAQ</b></a>' .
16
+ '<b> to learn how to use WebP Express on NGINX</b></p>',
17
+ '0.16.0/nginx-link-to-faq',
18
+ 'Got it!'
19
+ );
lib/migrate/migrate1.php CHANGED
@@ -86,8 +86,13 @@ function webpexpress_migrate1_migrateOptions()
86
  $options = Config::generateWodOptionsFromConfigObj($config);
87
  if (Config::saveWodOptionsFile($options)) {
88
 
 
 
 
 
 
89
  //Config::saveConfigurationAndHTAccessFilesWithMessages($config, 'migrate');
90
- $rulesResult = HTAccess::saveRules($config);
91
  /*
92
  'mainResult' // 'index', 'wp-content' or 'failed'
93
  'minRequired' // 'index' or 'wp-content'
@@ -97,6 +102,7 @@ function webpexpress_migrate1_migrateOptions()
97
  'overidingRulesInWpContentWarning' // true if main result is 'index' but we cannot remove those in wp-content
98
  'rules' // the rules that were generated
99
  */
 
100
  $mainResult = $rulesResult['mainResult'];
101
  $rules = $rulesResult['rules'];
102
 
@@ -115,6 +121,7 @@ function webpexpress_migrate1_migrateOptions()
115
  'and try to save the settings there (it will provide more information about the problem)'
116
  );
117
  }
 
118
  } else {
119
  Messenger::addMessage(
120
  'error',
86
  $options = Config::generateWodOptionsFromConfigObj($config);
87
  if (Config::saveWodOptionsFile($options)) {
88
 
89
+ Messenger::addMessage(
90
+ 'success',
91
+ 'WebP Express has successfully migrated its configuration to 0.5.0'
92
+ );
93
+
94
  //Config::saveConfigurationAndHTAccessFilesWithMessages($config, 'migrate');
95
+ //$rulesResult = HTAccess::saveRules($config); // Commented out because rules are going to be saved in migrate12
96
  /*
97
  'mainResult' // 'index', 'wp-content' or 'failed'
98
  'minRequired' // 'index' or 'wp-content'
102
  'overidingRulesInWpContentWarning' // true if main result is 'index' but we cannot remove those in wp-content
103
  'rules' // the rules that were generated
104
  */
105
+ /*
106
  $mainResult = $rulesResult['mainResult'];
107
  $rules = $rulesResult['rules'];
108
 
121
  'and try to save the settings there (it will provide more information about the problem)'
122
  );
123
  }
124
+ */
125
  } else {
126
  Messenger::addMessage(
127
  'error',
lib/migrate/migrate7.php CHANGED
@@ -39,7 +39,7 @@ function webpexpress_migrate7() {
39
  // The webp realizer rules where errornous, so recreate rules, if necessary. (see issue #195)
40
 
41
  if (($config['enable-redirection-to-webp-realizer']) && ($config['destination-folder'] != 'mingled')) {
42
- HTAccess::saveRules($config);
43
  $msg .= 'Also fixed <a target="_blank" href="https://github.com/rosell-dk/webp-express/issues/195">buggy</a> <i>.htaccess</i> rules. ';
44
  }
45
 
39
  // The webp realizer rules where errornous, so recreate rules, if necessary. (see issue #195)
40
 
41
  if (($config['enable-redirection-to-webp-realizer']) && ($config['destination-folder'] != 'mingled')) {
42
+ //HTAccess::saveRules($config); // Commented out because rules are going to be saved in migrate12
43
  $msg .= 'Also fixed <a target="_blank" href="https://github.com/rosell-dk/webp-express/issues/195">buggy</a> <i>.htaccess</i> rules. ';
44
  }
45
 
lib/options/css/webp-express-options-page.css CHANGED
@@ -543,7 +543,8 @@ input + .help {
543
  .form-table th.header-section p,
544
  .form-table th.header-section h2,
545
  fieldset.block p,
546
- fieldset.block div.p {
 
547
  max-width: 750px;
548
  }
549
 
543
  .form-table th.header-section p,
544
  .form-table th.header-section h2,
545
  fieldset.block p,
546
+ fieldset.block div.p,
547
+ input {
548
  max-width: 750px;
549
  }
550
 
lib/options/enqueue_scripts.php CHANGED
@@ -6,7 +6,7 @@ use \WebPExpress\Paths;
6
  use \WebPExpress\Config;
7
 
8
  $ver = '1'; // note: Minimum 1
9
- $jsDir = 'js/0.15.0'; // We change dir when it is critical that no-one gets the cached version (there is a plugin that strips version strings out there...)
10
 
11
  if (!function_exists('webp_express_add_inline_script')) {
12
  function webp_express_add_inline_script($id, $script, $position) {
@@ -82,7 +82,7 @@ if (!(isset($config['operation-mode']) && ($config['operation-mode'] == 'no-conv
82
  $canDisplayWebp = (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false ));
83
 
84
  /*
85
- AlterHTMLHelper::getWebPUrlInBase(
86
  Paths::getPluginUrl() . '/webp-express', // source url
87
  $baseId,
88
  Paths::getPluginUrl(), // base url
6
  use \WebPExpress\Config;
7
 
8
  $ver = '1'; // note: Minimum 1
9
+ $jsDir = 'js/0.16.0'; // We change dir when it is critical that no-one gets the cached version (there is a plugin that strips version strings out there...)
10
 
11
  if (!function_exists('webp_express_add_inline_script')) {
12
  function webp_express_add_inline_script($id, $script, $position) {
82
  $canDisplayWebp = (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false ));
83
 
84
  /*
85
+ AlterHTMLHelper::getWebPUrlInImageRoot(
86
  Paths::getPluginUrl() . '/webp-express', // source url
87
  $baseId,
88
  Paths::getPluginUrl(), // base url
lib/options/js/{0.15.0 → 0.16.0}/authorized_sites_bak.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/bulk-convert.js RENAMED
@@ -14,7 +14,7 @@ function openBulkConvertPopup() {
14
  html += webpexpress_escapeHTML(response['data']);
15
  }
16
  document.getElementById('bulkconvertcontent').innerHTML = html;
17
- return
18
  }
19
  var bulkInfo = {
20
  'groups': JSON.parse(response),
@@ -246,6 +246,7 @@ function convertNextInBulkQueue() {
246
  var filename = group.files[bulkInfo.filePointer];
247
 
248
  var result = JSON.parse(response);
 
249
  //console.log(result);
250
 
251
  var html = '';
@@ -256,6 +257,13 @@ function convertNextInBulkQueue() {
256
  //var htmlViewLog = '&nbsp;&nbsp;<a style="cursor:pointer" onclick="webpexpress_viewLog(' + bulkInfo.groupPointer + ',' + bulkInfo.filePointer + ')">view log</a>';
257
  if (result['success']) {
258
 
 
 
 
 
 
 
 
259
  var orgSize = result['filesize-original'];
260
  var webpSize = result['filesize-webp'];
261
  var orgSizePrint, webpSizePrint;
@@ -277,6 +285,14 @@ function convertNextInBulkQueue() {
277
  getReductionHtml(orgSize, webpSize, 'Size of original', 'Size of webp')
278
  } else {
279
  html += ' <span style="color:red">failed</span>' + htmlViewLog;
 
 
 
 
 
 
 
 
280
  /*
281
  if (result['msg'] != '') {
282
  html += ' <span style="">' + result['msg'] + '</span>';
14
  html += webpexpress_escapeHTML(response['data']);
15
  }
16
  document.getElementById('bulkconvertcontent').innerHTML = html;
17
+ return;
18
  }
19
  var bulkInfo = {
20
  'groups': JSON.parse(response),
246
  var filename = group.files[bulkInfo.filePointer];
247
 
248
  var result = JSON.parse(response);
249
+
250
  //console.log(result);
251
 
252
  var html = '';
257
  //var htmlViewLog = '&nbsp;&nbsp;<a style="cursor:pointer" onclick="webpexpress_viewLog(' + bulkInfo.groupPointer + ',' + bulkInfo.filePointer + ')">view log</a>';
258
  if (result['success']) {
259
 
260
+ //console.log('nonce tick:' + result['nonce-tick']);
261
+
262
+ if (result['new-convert-nonce']) {
263
+ //console.log('new convert nonce:' + result['new-convert-nonce']);
264
+ window.webpExpress['ajax-nonces']['convert'] = result['new-convert-nonce'];
265
+ }
266
+
267
  var orgSize = result['filesize-original'];
268
  var webpSize = result['filesize-webp'];
269
  var orgSizePrint, webpSizePrint;
285
  getReductionHtml(orgSize, webpSize, 'Size of original', 'Size of webp')
286
  } else {
287
  html += ' <span style="color:red">failed</span>' + htmlViewLog;
288
+
289
+ if (result['msg']) {
290
+ logLn(html);
291
+ logLn('<br><br><span style="color:red; font-size:15px">' + webpexpress_escapeHTML(result['msg']) + '</span>');
292
+ }
293
+ if (result['stop']) {
294
+ return;
295
+ }
296
  /*
297
  if (result['msg'] != '') {
298
  html += ' <span style="">' + result['msg'] + '</span>';
lib/options/js/{0.15.0 → 0.16.0}/converters.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/das-popup.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/escapeHTML.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/image-comparison-slider.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/page.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/purge-cache.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/self-test.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/sortable.min.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/test-convert.js RENAMED
File without changes
lib/options/js/{0.15.0 → 0.16.0}/whitelist.js RENAMED
File without changes
lib/options/options/alter-html/alter-html-options.inc CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  <tr>
2
  <th scope="row">Alter HTML?</span><?php echo helpIcon(
3
  '<p>Alter HTML to either use picture tag syntax for pointing to webp versions or point directly to webps.</p>' .
@@ -173,7 +176,7 @@
173
  'Reference webps that hasn\'t been converted yet',
174
  'If you enable this option, there will be references to webp files that doesnt exist yet. ' .
175
  'And that will be ok! - Just make sure to enable the option to convert missing webp files ' .
176
- 'upon request'
177
  );
178
  echo '</div></div>';
179
  }
@@ -192,6 +195,28 @@
192
  );
193
  ?>
194
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
  </div>
197
 
1
+ <?php
2
+ namespace WebPExpress;
3
+ ?>
4
  <tr>
5
  <th scope="row">Alter HTML?</span><?php echo helpIcon(
6
  '<p>Alter HTML to either use picture tag syntax for pointing to webp versions or point directly to webps.</p>' .
176
  'Reference webps that hasn\'t been converted yet',
177
  'If you enable this option, there will be references to webp files that doesnt exist yet. ' .
178
  'And that will be ok! - Just make sure to enable the option to convert missing webp files ' .
179
+ 'upon request in the "Redirection rules" section.'
180
  );
181
  echo '</div></div>';
182
  }
195
  );
196
  ?>
197
  </div>
198
+ <div style="margin-top: 20px">
199
+ <label>CDN hostname(s) / hostname alias(es) <?php echo helpIcon(
200
+ '<p>If images can be reached on another hostname than that of your site' .
201
+ (Multisite::isMultisite() ? '' : ' ("' . Paths::getHostNameOfUrl(Paths::getHomeUrl()) . '")') .
202
+ ', you should specify that hostname here. ' .
203
+ 'This ensures that image URLs pointing to that hostname also gets replaced.</p>' .
204
+ '<p>PS: If you wonder why your images URLs to your CDN gets processed by WebP Express even though you ' .
205
+ 'have not entered anything here, the answer is probably that you are using a plugin that changes ' .
206
+ 'your URLs to point to the CDN and that WebP Express gets to do the replacement before your plugin. ' .
207
+ 'Do not rely on this. A future update to your plugin could change that order.</p>'
208
+ );
209
+ ?></label>
210
+ </div>
211
+ <?php
212
+ $aliases = $config['alter-html']['hostname-aliases'];
213
+ $aliasInputs = array_merge($aliases, ['']);
214
+ foreach ($aliasInputs as $i => $alias) {
215
+ ?>
216
+ http(s)://<input name="alter-html-hostname-alias-<?php echo $i ?>" value="<?php echo esc_attr($alias); ?>"/><br>
217
+ <?php
218
+ }
219
+ ?>
220
 
221
  </div>
222
 
lib/options/page-messages.php CHANGED
@@ -13,10 +13,16 @@ use \WebPExpress\Paths;
13
  use \WebPExpress\PlatformInfo;
14
  use \WebPExpress\State;
15
 
16
- if ((!State::getState('configured', false))) {
17
  include __DIR__ . "/page-welcome.php";
 
 
 
 
 
18
  }
19
 
 
20
  /*
21
  if (CapabilityTest::modRewriteWorking()) {
22
  echo 'mod rewrite works. that is nice';
13
  use \WebPExpress\PlatformInfo;
14
  use \WebPExpress\State;
15
 
16
+ if (!(State::getState('configured', false))) {
17
  include __DIR__ . "/page-welcome.php";
18
+
19
+ if (PlatformInfo::isNginx()) {
20
+ DismissableMessages::addDismissableMessage('0.16.0/nginx-link-to-faq');
21
+ }
22
+
23
  }
24
 
25
+
26
  /*
27
  if (CapabilityTest::modRewriteWorking()) {
28
  echo 'mod rewrite works. that is nice';
lib/options/page-welcome.php CHANGED
@@ -1,13 +1,8 @@
1
  <?php
2
 
3
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
-
5
- use \WebPExpress\Paths;
6
- use \WebPExpress\Config;
7
- use \WebPExpress\State;
8
- use \WebPExpress\Messenger;
9
- use \WebPExpress\PlatformInfo;
10
 
 
11
 
12
  $indexDir = Paths::getIndexDirAbs();
13
  $homeDir = Paths::getHomeDirAbs();
@@ -29,19 +24,27 @@ echo '<h3>Welcome!</h3>';
29
  //}
30
 
31
  if ($weKnowThereAreNoWorkingConverters) {
32
- echo '<p>Unfortunately none of the local conversion methods are available on your server. ' .
33
- 'but do not despear! - You have options!' .
 
34
  '<ol style="list-style-position:outside">' .
35
  '<li>You can install this plugin on another website, which supports a local conversion method and connect to that using the "Remote WebP Express" conversion method' .
36
  '<li>You can purchase a key for the <a target="_blank" href="https://ewww.io/plans/">ewww cloud converter</a>. They do not charge credits for webp conversions, so all you ever have to pay is the one dollar start-up fee :)</li>' .
 
37
  '<li>You can set up a <a target="_blank" href="https://github.com/rosell-dk/webp-convert-cloud-service">webp-convert-cloud-service</a> on another server and connect to that. Its open source.</li>' .
38
- '<li>You can try to meet the server requirements of cwebp, gd, imagick or gmagick. Check out <a target="_blank" href="https://github.com/rosell-dk/webp-convert/wiki/Meeting-the-requirements-of-the-converters">this wiki page</a> on how to do that</li>' .
39
- '</ol></p>' .
 
 
 
 
40
  "<p>Btw, don't worry, your images still works. The rewrite rules will not be saved until you click the " .
41
- '"Save settings" button (and you also have "Response on failure" set to "Original image", so they will work even if you click save)</p>';
 
42
  } else {
43
  echo '<p>The rewrite rules are not active yet. They will be activated the first time you click the "Save settings" button.</p>';
44
  }
 
45
  //echo 'working converters:';
46
  //print_r($workingConverters);
47
 
1
  <?php
2
 
3
+ namespace WebPExpress;
 
 
 
 
 
 
4
 
5
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
6
 
7
  $indexDir = Paths::getIndexDirAbs();
8
  $homeDir = Paths::getHomeDirAbs();
24
  //}
25
 
26
  if ($weKnowThereAreNoWorkingConverters) {
27
+ echo '<p>Unfortunately none of the "local" conversion methods are available on your server. That is: ' .
28
+ 'Your server cannot convert webp files in PHP without resorting to cloud conversion.</p>' .
29
+ '<p>But do not despear! - You have options!</p>' .
30
  '<ol style="list-style-position:outside">' .
31
  '<li>You can install this plugin on another website, which supports a local conversion method and connect to that using the "Remote WebP Express" conversion method' .
32
  '<li>You can purchase a key for the <a target="_blank" href="https://ewww.io/plans/">ewww cloud converter</a>. They do not charge credits for webp conversions, so all you ever have to pay is the one dollar start-up fee :)</li>' .
33
+ '<li>I have written a <a target="_blank" href="https://github.com/rosell-dk/webp-convert/wiki/A-template-letter-for-shared-hosts">template letter</a> which you can try sending to your webhost</li>' .
34
  '<li>You can set up a <a target="_blank" href="https://github.com/rosell-dk/webp-convert-cloud-service">webp-convert-cloud-service</a> on another server and connect to that. Its open source.</li>' .
35
+ '<li>You can try to meet the server requirements of cwebp, imagick, vips, gmagick or gd. Check out <a target="_blank" href="https://github.com/rosell-dk/webp-convert/wiki/Meeting-the-requirements-of-the-converters">this wiki page</a> on how to do that</li>' .
36
+ '</ol>' .
37
+ '<p>Of course, there is also the option of using another plugin altogether. ' .
38
+ 'I can recommend ' .
39
+ '<a href="https://optimole.pxf.io/20b0M">Optimole</a>. ' .
40
+ '</p>' .
41
  "<p>Btw, don't worry, your images still works. The rewrite rules will not be saved until you click the " .
42
+ '"Save settings" button.</p>';
43
+ //'(and you also have "Response on failure" set to "Original image", so they will work even if you click save)</p>';
44
  } else {
45
  echo '<p>The rewrite rules are not active yet. They will be activated the first time you click the "Save settings" button.</p>';
46
  }
47
+
48
  //echo 'working converters:';
49
  //print_r($workingConverters);
50
 
lib/options/submit.php CHANGED
@@ -286,6 +286,26 @@ function webpexpress_getSanitizedConverters() {
286
  return $convertersSanitized;
287
  }
288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
 
290
  /*
291
  ------------------------------------------------------
@@ -369,6 +389,7 @@ $sanitized = [
369
  'only-redirect-to-converter-for-webp-enabled-browsers' => isset($_POST['only-redirect-to-converter-for-webp-enabled-browsers']),
370
  'only-redirect-to-converter-on-cache-miss' => isset($_POST['only-redirect-to-converter-on-cache-miss']),
371
  'do-not-pass-source-in-query-string' => isset($_POST['do-not-pass-source-in-query-string']),
 
372
 
373
 
374
  // Conversion options
@@ -435,7 +456,7 @@ $sanitized = [
435
  'content-hooks',
436
  'ob'
437
  ]),
438
- 'enable-redirection-to-webp-realizer' => isset($_POST['enable-redirection-to-webp-realizer']),
439
 
440
 
441
  // Web service
@@ -507,6 +528,7 @@ if ($sanitized['operation-mode'] != 'no-conversion') {
507
 
508
  $config['alter-html']['replacement'] = $sanitized['alter-html-replacement'];
509
  $config['alter-html']['hooks'] = $sanitized['alter-html-hooks'];
 
510
 
511
 
512
  // Set options that are available in all operation modes, except the "no-conversion" mode
@@ -762,152 +784,11 @@ if (!$result['saved-both-config']) {
762
  'Configuration saved. Rewrite rules did not need to be updated. ' . HTAccess::testLinks($config)
763
  );
764
  } else {
765
- $rulesResult = $result['htaccess-result'];
766
- list($success, $successfullWrites, $successfulDeactivations, $failedWrites, $failedDeactivations) = $rulesResult;
767
-
768
- $msg = '<p>Configuration was saved</p>';
769
-
770
- if (count($successfullWrites) > 0) {
771
- $msg .= '<p>Rewrite rules were saved to the following files:</p>';
772
- foreach ($successfullWrites as $rootId) {
773
- $msg .= '<i>' . Paths::getAbsDirById($rootId) . '/.htaccess</i> (' . $rootId . ')<br>';
774
- }
775
- }
776
-
777
- if (count($successfulDeactivations) > 0) {
778
- $msg .= '<p>Rewrite rules were removed from the following files:</p>';
779
- foreach ($successfulDeactivations as $rootId) {
780
- $msg .= '<i>' . Paths::getAbsDirById($rootId) . '/.htaccess</i> (' . $rootId . ')<br>';
781
- }
782
- }
783
-
784
  Messenger::addMessage(
785
- ($success ? 'success' : 'info'),
786
- $msg
787
  );
788
-
789
-
790
- if (count($failedWrites) > 0) {
791
- $msg = '<p>Failed writing rewrite rules to the following files:</p>';
792
- foreach ($failedWrites as $rootId) {
793
- $msg .= '<i>' . Paths::getAbsDirById($rootId) . '/.htaccess</i> (' . $rootId . ')<br>';
794
- }
795
- $msg .= 'You need to change the file permissions to allow WebP Express to save the rules.';
796
- Messenger::addMessage('error', $msg);
797
- } else {
798
- if (count($failedDeactivations) > 0) {
799
- $msg = '<p>Failed deleting unused rewrite rules in the following files:</p>';
800
- foreach ($failedDeactivations as $rootId) {
801
- $msg .= '<i>' . Paths::getAbsDirById($rootId) . '/.htaccess</i> (' . $rootId . ')<br>';
802
- }
803
- $msg .= 'You need to change the file permissions to allow WebP Express to remove the rules or ' .
804
- 'remove them manually';
805
- Messenger::addMessage('error', $msg);
806
- }
807
- }
808
-
809
- /*
810
- 'mainResult' // 'index', 'wp-content' or 'failed'
811
- 'minRequired' // 'index' or 'wp-content'
812
- 'pluginToo' // 'yes', 'no' or 'depends'
813
- 'uploadToo' // 'yes', 'no' or 'depends'
814
- 'overidingRulesInWpContentWarning' // true if main result is 'index' but we cannot remove those in wp-content
815
- 'rules' // the rules that were generated
816
- 'pluginFailed' // true if failed to write to plugin folder (it only tries that, if pluginToo == 'yes')
817
- 'pluginFailedBadly' // true if plugin failed AND it seems we have rewrite rules there
818
- 'uploadFailed' // true if failed to write to plugin folder (it only tries that, if pluginToo == 'yes')
819
- 'uploadFailedBadly' // true if plugin failed AND it seems we have rewrite rules there
820
- */
821
- /*
822
- $mainResult = $rulesResult['mainResult'];
823
- $rules = $rulesResult['rules'];
824
-
825
- if ($mainResult == 'failed') {
826
- if ($rulesResult['minRequired'] == 'wp-content') {
827
- Messenger::addMessage(
828
- 'error',
829
- 'Configuration saved, but failed saving rewrite rules. ' .
830
- 'Please grant us write access to your <i>wp-content</i> dir (we need that, because you have moved <i>wp-content</i> out of the Wordpress dir) ' .
831
- '- or, alternatively insert the following rules directly in that <i>.htaccess</i> file, or your Apache configuration:' .
832
- '<pre>' . htmlentities(print_r($rules, true)) . '</pre>'
833
- );
834
-
835
- } else {
836
- Messenger::addMessage(
837
- 'error',
838
- 'Configuration saved, but failed saving rewrite rules. ' .
839
- 'Please grant us write access to either write rules to an <i>.htaccess</i> in your <i>wp-content</i> dir (preferably), ' .
840
- 'or your main <i>.htaccess</i> file. ' .
841
- '- or, alternatively insert the following rules directly in that <i>.htaccess</i> file, or your Apache configuration:' .
842
- '<pre>' . htmlentities(print_r($rules, true)) . '</pre>'
843
- );
844
- }
845
- } else {
846
- $savedToPluginsToo = (($rulesResult['pluginToo'] == 'yes') && !($rulesResult['pluginFailed']));
847
- $savedToUploadsToo = (($rulesResult['uploadToo'] == 'yes') && !($rulesResult['uploadFailed']));
848
-
849
- Messenger::addMessage(
850
- 'success',
851
- 'Configuration saved.<br>Rewrite rules were saved to your <i>.htaccess</i> in your <i>' . $mainResult . '</i> folder' .
852
- (Paths::isWPContentDirMoved() ? ' (which you moved, btw)' : '') .
853
- ($savedToPluginsToo ? ' as well as in your <i>plugins</i> folder' : '') .
854
- ((Paths::isWPContentDirMoved() && $savedToPluginsToo) ? ' (you moved that as well!)' : '.') .
855
- ($savedToUploadsToo ? ' as well as in your <i>uploads</i> folder' : '') .
856
- ((Paths::isWPContentDirMoved() && $savedToUploadsToo) ? ' (you moved that as well!)' : '.') .
857
- HTAccess::testLinks($config)
858
- );
859
- }
860
- if ($rulesResult['mainResult'] == 'index') {
861
- if ($rulesResult['overidingRulesInWpContentWarning']) {
862
- Messenger::addMessage(
863
- 'warning',
864
- 'We have rewrite rules in the <i>wp-content</i> folder, which we cannot remove. ' .
865
- 'These are overriding those just saved. ' .
866
- 'Please change file permissions or remove the rules from the <i>.htaccess</i> file manually'
867
- );
868
- } else {
869
- Messenger::addMessage(
870
- 'info',
871
- 'The rewrite rules are currently stored in your root. ' .
872
- 'WebP Express would prefer to store them in your wp-content folder, ' .
873
- 'but your current file permissions does not allow that.'
874
- );
875
- }
876
- }
877
- if ($rulesResult['pluginFailed']) {
878
- if ($rulesResult['pluginFailedBadly']) {
879
- Messenger::addMessage(
880
- 'warning',
881
- 'The <i>.htaccess</i> rules in your plugins folder could not be updated (no write access). ' .
882
- 'This is not so good, because we have rules there already...' .
883
- 'You should update them. Here they are: ' .
884
- '<pre>' . htmlentities(print_r($rules, true)) . '</pre>'
885
- );
886
- } else {
887
- Messenger::addMessage(
888
- 'info',
889
- '<i>.htaccess</i> rules could not be written into your plugins folder. ' .
890
- 'Images stored in your plugins will not be converted to webp'
891
- );
892
- }
893
- }
894
- if ($rulesResult['uploadFailed']) {
895
- if ($rulesResult['uploadFailedBadly']) {
896
- Messenger::addMessage(
897
- 'error',
898
- 'The <i>.htaccess</i> rules in your uploads folder could not be updated (no write access). ' .
899
- 'This is not so good, because we have rules there already...' .
900
- 'You should update them. Here they are: ' .
901
- '<pre>' . htmlentities(print_r($rules, true)) . '</pre>'
902
- );
903
- } else {
904
- Messenger::addMessage(
905
- 'warning',
906
- '<i>.htaccess</i> rules could not be written into your uploads folder (this is needed, because you have moved it outside your <i>wp-content</i> folder). ' .
907
- 'Please grant write permmissions to you uploads folder. Otherwise uploaded mages will not be converted to webp'
908
- );
909
- }
910
- }*/
911
  }
912
  }
913
 
286
  return $convertersSanitized;
287
  }
288
 
289
+ /**
290
+ * Get sanitized converters.
291
+ *
292
+ * @return array Sanitized array of the converters json array received in $_POST
293
+ */
294
+ function webpexpress_getSanitizedAlterHtmlHostnameAliases() {
295
+ $index = 0;
296
+
297
+ $result = [];
298
+ while (isset($_POST['alter-html-hostname-alias-' . $index])) {
299
+ $alias = webpexpress_getSanitizedText('alter-html-hostname-alias-' . $index, '');
300
+ $alias = preg_replace('#^https?\\:\\/\\/#', '', $alias);
301
+ //$alias .= 'hm';
302
+ if ($alias != '') {
303
+ $result[] = $alias;
304
+ }
305
+ $index++;
306
+ }
307
+ return $result;
308
+ }
309
 
310
  /*
311
  ------------------------------------------------------
389
  'only-redirect-to-converter-for-webp-enabled-browsers' => isset($_POST['only-redirect-to-converter-for-webp-enabled-browsers']),
390
  'only-redirect-to-converter-on-cache-miss' => isset($_POST['only-redirect-to-converter-on-cache-miss']),
391
  'do-not-pass-source-in-query-string' => isset($_POST['do-not-pass-source-in-query-string']),
392
+ 'enable-redirection-to-webp-realizer' => isset($_POST['enable-redirection-to-webp-realizer']),
393
 
394
 
395
  // Conversion options
456
  'content-hooks',
457
  'ob'
458
  ]),
459
+ 'alter-html-hostname-aliases' => webpexpress_getSanitizedAlterHtmlHostnameAliases(),
460
 
461
 
462
  // Web service
528
 
529
  $config['alter-html']['replacement'] = $sanitized['alter-html-replacement'];
530
  $config['alter-html']['hooks'] = $sanitized['alter-html-hooks'];
531
+ $config['alter-html']['hostname-aliases'] = $sanitized['alter-html-hostname-aliases'];
532
 
533
 
534
  // Set options that are available in all operation modes, except the "no-conversion" mode
784
  'Configuration saved. Rewrite rules did not need to be updated. ' . HTAccess::testLinks($config)
785
  );
786
  } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787
  Messenger::addMessage(
788
+ 'success',
789
+ 'Configuration was saved.'
790
  );
791
+ HTAccess::showSaveRulesMessages($result['htaccess-result']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
792
  }
793
  }
794
 
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.15.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.16.0
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2