WebP Express - Version 0.14.0

Version Description

New awesome conversion options that gets you even smaller webp files without compromising quality.

Download this release

Release Info

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

Code changes from version 0.13.2 to 0.14.0

Files changed (272) hide show
  1. README.md +14 -1
  2. README.txt +21 -2
  3. composer.json +2 -13
  4. composer.lock +88 -106
  5. lib/classes/AdminInit.php +6 -3
  6. lib/classes/AlterHtmlHelper.php +2 -3
  7. lib/classes/BulkConvert.php +0 -10
  8. lib/classes/CachePurge.php +3 -0
  9. lib/classes/Config.php +144 -44
  10. lib/classes/Convert.php +58 -4
  11. lib/classes/ConvertHelperIndependent.php +111 -3
  12. lib/classes/ConvertLog.php +37 -0
  13. lib/classes/ConvertersHelper.php +185 -11
  14. lib/classes/DismissableMessages.php +82 -0
  15. lib/classes/HTAccess.php +28 -7
  16. lib/classes/HandleDeleteFileHook.php +1 -2
  17. lib/classes/Messenger.php +8 -5
  18. lib/classes/Paths.php +12 -2
  19. lib/classes/PlatformInfo.php +5 -0
  20. lib/classes/TestRun.php +21 -20
  21. lib/dismissable-messages/0.14.0/say-hello-to-vips.php +39 -0
  22. lib/dismissable-messages/0.14.0/suggest-enable-pngs.php +10 -0
  23. lib/dismissable-messages/0.14.0/suggest-wipe-because-lossless.php +45 -0
  24. lib/migrate/migrate9.php +204 -0
  25. lib/options/css/images/checker.png +0 -0
  26. lib/options/css/images/drag-handle.svg +8 -0
  27. lib/options/css/test-convert.css +101 -0
  28. lib/options/css/webp-express-options-page.css +33 -3
  29. lib/options/enqueue_scripts.php +24 -1
  30. lib/options/js/bulk-convert.js +48 -3
  31. lib/options/js/converters.js +55 -19
  32. lib/options/js/image-comparison-slider.js +68 -0
  33. lib/options/js/page.js +68 -6
  34. lib/options/js/test-convert.js +278 -0
  35. lib/options/options/conversion-options/bulk-convert.inc +7 -0
  36. lib/options/options/conversion-options/conversion-options.inc +3 -1
  37. lib/options/options/conversion-options/converter-options/ewww.php +4 -4
  38. lib/options/options/conversion-options/converter-options/gd.php +9 -2
  39. lib/options/options/conversion-options/converter-options/graphicsmagick.php +32 -0
  40. lib/options/options/conversion-options/converter-options/imagemagick.php +30 -0
  41. lib/options/options/conversion-options/converter-options/imagick.php +4 -1
  42. lib/options/options/conversion-options/converter-options/imagickbinary.php +0 -24
  43. lib/options/options/conversion-options/converter-options/vips.php +42 -0
  44. lib/options/options/conversion-options/converter-options/wpc.php +5 -3
  45. lib/options/options/conversion-options/converters.inc +33 -72
  46. lib/options/options/conversion-options/jpeg.inc +164 -0
  47. lib/options/options/conversion-options/metadata.inc +1 -1
  48. lib/options/options/conversion-options/png.inc +98 -0
  49. lib/options/options/conversion-options/quality.inc +63 -20
  50. lib/options/options/general/image-types.inc +1 -1
  51. lib/options/options/redirection-rules/enable-redirection-to-converter.inc +9 -19
  52. lib/options/options/redirection-rules/enable-redirection-to-webp-realizer.inc +7 -5
  53. lib/options/options/redirection-rules/redirect-to-existing.inc +12 -6
  54. lib/options/options/redirection-rules/redirection-rules.inc +2 -12
  55. lib/options/options/serve-options/response-on-failure.inc +1 -1
  56. lib/options/page-messages.php +137 -6
  57. lib/options/page.php +7 -0
  58. lib/options/submit.php +41 -6
  59. test/alphatest.png +0 -0
  60. test/architecture-q85-w600.jpg +0 -0
  61. test/dice.png +0 -0
  62. test/palette-based-colors.png +0 -0
  63. test/{test.jpg → test-pattern-tv.jpg} +0 -0
  64. test/test-run.php +0 -191
  65. test/test.png +0 -0
  66. vendor/composer/autoload_classmap.php +0 -31
  67. vendor/composer/autoload_psr4.php +1 -0
  68. vendor/composer/autoload_static.php +8 -35
  69. vendor/composer/installed.json +93 -109
  70. vendor/rosell-dk/image-mime-type-guesser/.php_cs.dist +19 -0
  71. vendor/rosell-dk/image-mime-type-guesser/LICENSE +9 -0
  72. vendor/rosell-dk/image-mime-type-guesser/README.md +108 -0
  73. vendor/rosell-dk/image-mime-type-guesser/composer.json +55 -0
  74. vendor/rosell-dk/image-mime-type-guesser/phpunit.xml.dist +28 -0
  75. vendor/rosell-dk/image-mime-type-guesser/src/Detectors/AbstractDetector.php +55 -0
  76. vendor/rosell-dk/image-mime-type-guesser/src/Detectors/ExifImageType.php +40 -0
  77. vendor/rosell-dk/image-mime-type-guesser/src/Detectors/FInfo.php +38 -0
  78. vendor/rosell-dk/image-mime-type-guesser/src/Detectors/GetImageSize.php +36 -0
  79. vendor/rosell-dk/image-mime-type-guesser/src/Detectors/MimeContentType.php +41 -0
  80. vendor/rosell-dk/image-mime-type-guesser/src/Detectors/SniffFirstFourBytes.php +48 -0
  81. vendor/rosell-dk/image-mime-type-guesser/src/Detectors/Stack.php +42 -0
  82. vendor/rosell-dk/image-mime-type-guesser/src/GuessFromExtension.php +90 -0
  83. vendor/rosell-dk/image-mime-type-guesser/src/ImageMimeTypeGuesser.php +134 -0
  84. vendor/rosell-dk/webp-convert-cloud-service/README.md +5 -0
  85. vendor/rosell-dk/webp-convert-cloud-service/composer.json +1 -1
  86. vendor/rosell-dk/webp-convert-cloud-service/src/Serve.php +7 -10
  87. vendor/rosell-dk/webp-convert-cloud-service/src/WebPConvertCloudService.php +2 -2
  88. vendor/rosell-dk/webp-convert/.travis.yml +123 -7
  89. vendor/rosell-dk/webp-convert/README.md +52 -38
  90. vendor/rosell-dk/webp-convert/build-scripts/PHPMerger.php +24 -12
  91. vendor/rosell-dk/webp-convert/build-scripts/build-all +0 -1
  92. vendor/rosell-dk/webp-convert/build-scripts/build-webp-on-demand.php +0 -89
  93. vendor/rosell-dk/webp-convert/build-scripts/build.php +122 -0
  94. vendor/rosell-dk/webp-convert/build-scripts/generate-require-all.php +0 -83
  95. vendor/rosell-dk/webp-convert/build-tests-webp-convert/WebPConvertBuildTest.php +46 -0
  96. vendor/rosell-dk/webp-convert/build-tests-wod/WodBuildTest.php +167 -0
  97. vendor/rosell-dk/webp-convert/build/webp-convert.inc +0 -3089
  98. vendor/rosell-dk/webp-convert/build/webp-on-demand-1.inc +0 -295
  99. vendor/rosell-dk/webp-convert/build/webp-on-demand-2.inc +0 -2795
  100. vendor/rosell-dk/webp-convert/composer.json +33 -7
  101. vendor/rosell-dk/webp-convert/docs/development.md +30 -3
  102. vendor/rosell-dk/webp-convert/docs/{converters.md → v1.3/converting/convert-options.md} +106 -20
  103. vendor/rosell-dk/webp-convert/docs/{api → v1.3/converting}/convert.md +8 -6
  104. vendor/rosell-dk/webp-convert/docs/v1.3/converting/converters.md +322 -0
  105. vendor/rosell-dk/webp-convert/docs/{api → v1.3/serving}/convert-and-serve.md +5 -0
  106. vendor/rosell-dk/webp-convert/docs/{webp-on-demand → v1.3/webp-on-demand}/tweaks.md +0 -0
  107. vendor/rosell-dk/webp-convert/docs/{webp-on-demand → v1.3/webp-on-demand}/webp-on-demand.md +6 -6
  108. vendor/rosell-dk/webp-convert/docs/{webp-on-demand → v1.3/webp-on-demand}/without-composer.md +2 -2
  109. vendor/rosell-dk/webp-convert/docs/v2.0/converting/architecture-q50-w600.jpg +0 -0
  110. vendor/rosell-dk/webp-convert/docs/v2.0/converting/converters/stack.md +248 -0
  111. vendor/rosell-dk/webp-convert/docs/v2.0/converting/dice.png +0 -0
  112. vendor/rosell-dk/webp-convert/docs/v2.0/converting/introduction-for-converting.md +214 -0
  113. vendor/rosell-dk/webp-convert/docs/v2.0/converting/mouse-q100.jpg +0 -0
  114. vendor/rosell-dk/webp-convert/docs/v2.0/converting/options.md +298 -0
  115. vendor/rosell-dk/webp-convert/docs/v2.0/migrating-to-2.0.md +73 -0
  116. vendor/rosell-dk/webp-convert/docs/v2.0/serving/introduction-for-serving.md +143 -0
  117. vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/tweaks.md +167 -0
  118. vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/webp-on-demand.md +145 -0
  119. vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/without-composer.md +58 -0
  120. vendor/rosell-dk/webp-convert/install-gmagick-with-webp.sh +74 -0
  121. vendor/rosell-dk/webp-convert/install-imagemagick-with-webp.sh +40 -0
  122. vendor/rosell-dk/webp-convert/install-vips.sh +40 -0
  123. vendor/rosell-dk/webp-convert/phpdox.xml +9 -0
  124. vendor/rosell-dk/webp-convert/phpstan.neon +25 -0
  125. vendor/rosell-dk/webp-convert/phpunit.xml.dist +12 -1
  126. vendor/rosell-dk/webp-convert/src-build/webp-convert.inc +6907 -0
  127. vendor/rosell-dk/webp-convert/src-build/webp-on-demand-1.inc +616 -0
  128. vendor/rosell-dk/webp-convert/src-build/webp-on-demand-2.inc +6292 -0
  129. vendor/rosell-dk/webp-convert/src/Convert/ConverterFactory.php +109 -0
  130. vendor/rosell-dk/webp-convert/src/Convert/Converters/AbstractConverter.php +388 -0
  131. vendor/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/AutoQualityTrait.php +136 -0
  132. vendor/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/DestinationPreparationTrait.php +101 -0
  133. vendor/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/LoggerTrait.php +71 -0
  134. vendor/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/OptionsTrait.php +272 -0
  135. vendor/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/SourceValidationTrait.php +64 -0
  136. vendor/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/WarningLoggerTrait.php +117 -0
  137. vendor/rosell-dk/webp-convert/src/{Converters → Convert/Converters}/Binaries/cwebp-fbsd +0 -0
  138. vendor/rosell-dk/webp-convert/src/{Converters → Convert/Converters}/Binaries/cwebp-linux +0 -0
  139. vendor/rosell-dk/webp-convert/src/{Converters → Convert/Converters}/Binaries/cwebp-mac12 +0 -0
  140. vendor/rosell-dk/webp-convert/src/{Converters → Convert/Converters}/Binaries/cwebp-sol +0 -0
  141. vendor/rosell-dk/webp-convert/src/{Converters → Convert/Converters}/Binaries/cwebp.exe +0 -0
  142. vendor/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CloudConverterTrait.php +72 -0
  143. vendor/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CurlTrait.php +72 -0
  144. vendor/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/EncodingAutoTrait.php +89 -0
  145. vendor/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/ExecTrait.php +73 -0
  146. vendor/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php +469 -0
  147. vendor/rosell-dk/webp-convert/src/{Converters → Convert/Converters}/Ewww.php +114 -76
  148. vendor/rosell-dk/webp-convert/src/Convert/Converters/Gd.php +461 -0
  149. vendor/rosell-dk/webp-convert/src/Convert/Converters/Gmagick.php +151 -0
  150. vendor/rosell-dk/webp-convert/src/Convert/Converters/GmagickBinary.php +28 -0
  151. vendor/rosell-dk/webp-convert/src/Convert/Converters/GraphicsMagick.php +170 -0
  152. vendor/rosell-dk/webp-convert/src/Convert/Converters/ImageMagick.php +183 -0
  153. vendor/rosell-dk/webp-convert/src/Convert/Converters/Imagick.php +169 -0
  154. vendor/rosell-dk/webp-convert/src/Convert/Converters/ImagickBinary.php +28 -0
  155. vendor/rosell-dk/webp-convert/src/Convert/Converters/Stack.php +234 -0
  156. vendor/rosell-dk/webp-convert/src/Convert/Converters/Vips.php +236 -0
  157. vendor/rosell-dk/webp-convert/src/Convert/Converters/Wpc.php +349 -0
  158. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConversionSkippedException.php +10 -0
  159. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/InvalidApiKeyException.php +10 -0
  160. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/SystemRequirementsNotMetException.php +10 -0
  161. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperationalException.php +10 -0
  162. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFileException.php +10 -0
  163. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFolderException.php +10 -0
  164. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblemsException.php +10 -0
  165. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/ConverterNotFoundException.php +10 -0
  166. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/InvalidImageTypeException.php +10 -0
  167. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/TargetNotFoundException.php +10 -0
  168. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInputException.php +10 -0
  169. vendor/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailedException.php +31 -0
  170. vendor/rosell-dk/webp-convert/src/Convert/Helpers/JpegQualityDetector.php +112 -0
  171. vendor/rosell-dk/webp-convert/src/Convert/Helpers/PhpIniSizes.php +70 -0
  172. vendor/rosell-dk/webp-convert/src/Converters/ConverterHelper.php +0 -461
  173. vendor/rosell-dk/webp-convert/src/Converters/Cwebp.php +0 -394
  174. vendor/rosell-dk/webp-convert/src/Converters/Exceptions/ConversionDeclinedException.php +0 -10
  175. vendor/rosell-dk/webp-convert/src/Converters/Exceptions/ConverterFailedException.php +0 -10
  176. vendor/rosell-dk/webp-convert/src/Converters/Exceptions/ConverterNotOperationalException.php +0 -10
  177. vendor/rosell-dk/webp-convert/src/Converters/Gd.php +0 -175
  178. vendor/rosell-dk/webp-convert/src/Converters/Gmagick.php +0 -88
  179. vendor/rosell-dk/webp-convert/src/Converters/Imagick.php +0 -123
  180. vendor/rosell-dk/webp-convert/src/Converters/Imagickbinary.php +0 -155
  181. vendor/rosell-dk/webp-convert/src/Converters/Wpc.php +0 -347
  182. vendor/rosell-dk/webp-convert/src/Exceptions/ConverterNotFoundException.php +0 -10
  183. vendor/rosell-dk/webp-convert/src/Exceptions/CreateDestinationFileException.php +0 -10
  184. vendor/rosell-dk/webp-convert/src/Exceptions/CreateDestinationFolderException.php +0 -10
  185. vendor/rosell-dk/webp-convert/src/Exceptions/InvalidFileExtensionException.php +0 -10
  186. vendor/rosell-dk/webp-convert/src/Exceptions/TargetNotFoundException.php +0 -10
  187. vendor/rosell-dk/webp-convert/src/Exceptions/WebPConvertBaseException.php +0 -7
  188. vendor/rosell-dk/webp-convert/src/Exceptions/WebPConvertException.php +44 -0
  189. vendor/rosell-dk/webp-convert/src/Loggers/BaseLogger.php +27 -9
  190. vendor/rosell-dk/webp-convert/src/Loggers/BufferLogger.php +58 -3
  191. vendor/rosell-dk/webp-convert/src/Loggers/EchoLogger.php +20 -0
  192. vendor/rosell-dk/webp-convert/src/Loggers/VoidLogger.php +0 -14
  193. vendor/rosell-dk/webp-convert/src/Options/ArrayOption.php +31 -0
  194. vendor/rosell-dk/webp-convert/src/Options/BooleanOption.php +27 -0
  195. vendor/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionTypeException.php +10 -0
  196. vendor/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionValueException.php +10 -0
  197. vendor/rosell-dk/webp-convert/src/Options/Exceptions/OptionNotFoundException.php +10 -0
  198. vendor/rosell-dk/webp-convert/src/Options/GhostOption.php +22 -0
  199. vendor/rosell-dk/webp-convert/src/Options/IntegerOption.php +67 -0
  200. vendor/rosell-dk/webp-convert/src/Options/IntegerOrNullOption.php +43 -0
  201. vendor/rosell-dk/webp-convert/src/Options/MetadataOption.php +44 -0
  202. vendor/rosell-dk/webp-convert/src/Options/Option.php +135 -0
  203. vendor/rosell-dk/webp-convert/src/Options/Options.php +135 -0
  204. vendor/rosell-dk/webp-convert/src/Options/QualityOption.php +57 -0
  205. vendor/rosell-dk/webp-convert/src/Options/SensitiveArrayOption.php +32 -0
  206. vendor/rosell-dk/webp-convert/src/Options/SensitiveStringOption.php +35 -0
  207. vendor/rosell-dk/webp-convert/src/Options/StringOption.php +43 -0
  208. vendor/rosell-dk/webp-convert/src/Serve/Exceptions/ServeFailedException.php +10 -0
  209. vendor/rosell-dk/webp-convert/src/Serve/Header.php +51 -0
  210. vendor/rosell-dk/webp-convert/src/Serve/Report.php +11 -145
  211. vendor/rosell-dk/webp-convert/src/Serve/ServeBase.php +0 -224
  212. vendor/rosell-dk/webp-convert/src/Serve/ServeConverted.php +0 -312
  213. vendor/rosell-dk/webp-convert/src/Serve/ServeConvertedWebP.php +200 -0
  214. vendor/rosell-dk/webp-convert/src/Serve/ServeConvertedWebPWithErrorHandling.php +159 -0
  215. vendor/rosell-dk/webp-convert/src/Serve/ServeExistingOrHandOver.php +0 -40
  216. vendor/rosell-dk/webp-convert/src/Serve/ServeFile.php +123 -0
  217. vendor/rosell-dk/webp-convert/src/WebPConvert.php +62 -12
  218. vendor/rosell-dk/webp-convert/src/require-all.inc +0 -27
  219. vendor/rosell-dk/webp-convert/tests/BaseExposer.php +113 -0
  220. vendor/rosell-dk/webp-convert/tests/Convert/Converters/AbstractConverterTest.php +90 -0
  221. vendor/rosell-dk/webp-convert/tests/Convert/Converters/BaseTraits/AutoQualityTraitTest.php +164 -0
  222. vendor/rosell-dk/webp-convert/tests/Convert/Converters/ConverterTestHelper.php +172 -0
  223. vendor/rosell-dk/webp-convert/tests/Convert/Converters/CwebpTest.php +284 -0
  224. vendor/rosell-dk/webp-convert/tests/Convert/Converters/EwwwTest.php +89 -0
  225. vendor/rosell-dk/webp-convert/tests/Convert/Converters/GdTest.php +246 -0
  226. vendor/rosell-dk/webp-convert/tests/Convert/Converters/GmagickTest.php +29 -0
  227. vendor/rosell-dk/webp-convert/tests/Convert/Converters/GraphicsMagickTest.php +59 -0
  228. vendor/rosell-dk/webp-convert/tests/Convert/Converters/ImageMagickTest.php +55 -0
  229. vendor/rosell-dk/webp-convert/tests/Convert/Converters/ImagickTest.php +63 -0
  230. vendor/rosell-dk/webp-convert/tests/Convert/Converters/StackTest.php +46 -0
  231. vendor/rosell-dk/webp-convert/tests/Convert/Converters/VipsTest.php +225 -0
  232. vendor/rosell-dk/webp-convert/tests/Convert/Converters/WPCTest.php +242 -0
  233. vendor/rosell-dk/webp-convert/tests/Convert/Converters/pretend.inc +55 -0
  234. vendor/rosell-dk/webp-convert/tests/Convert/Exposers/AbstractConverterExposer.php +63 -0
  235. vendor/rosell-dk/webp-convert/tests/Convert/Exposers/CwebpExposer.php +23 -0
  236. vendor/rosell-dk/webp-convert/tests/Convert/Exposers/GdExposer.php +110 -0
  237. vendor/rosell-dk/webp-convert/tests/Convert/Exposers/VipsExposer.php +39 -0
  238. vendor/rosell-dk/webp-convert/tests/Convert/Helpers/JpegQualityDetectorTest.php +33 -0
  239. vendor/rosell-dk/webp-convert/tests/Convert/Helpers/PhpIniSizesTest.php +85 -0
  240. vendor/rosell-dk/webp-convert/tests/Convert/TestConverters/ExposedConverter.php +34 -0
  241. vendor/rosell-dk/webp-convert/tests/Convert/TestConverters/ExtendedConverters/EwwwExtended.php +14 -0
  242. vendor/rosell-dk/webp-convert/tests/Convert/TestConverters/FailureGuaranteedConverter.php +14 -0
  243. vendor/rosell-dk/webp-convert/tests/Convert/TestConverters/SuccessGuaranteedConverter.php +13 -0
  244. vendor/rosell-dk/webp-convert/tests/Converters/CwebpTest.php +0 -110
  245. vendor/rosell-dk/webp-convert/tests/Converters/EwwwTest.php +0 -51
  246. vendor/rosell-dk/webp-convert/tests/Converters/GdTest.php +0 -69
  247. vendor/rosell-dk/webp-convert/tests/Converters/ImagickTest.php +0 -66
  248. vendor/rosell-dk/webp-convert/tests/Converters/WPCTest.php +0 -37
  249. vendor/rosell-dk/webp-convert/tests/Helpers/WarningsIntoExceptionsTest.php +64 -0
  250. vendor/rosell-dk/webp-convert/tests/Serve/HeaderTest.php +49 -0
  251. vendor/rosell-dk/webp-convert/tests/Serve/ServeConvertedTest.php +0 -85
  252. vendor/rosell-dk/webp-convert/tests/Serve/ServeConvertedWebPExposer.php +25 -0
  253. vendor/rosell-dk/webp-convert/tests/Serve/ServeConvertedWebPTest.php +408 -0
  254. vendor/rosell-dk/webp-convert/tests/Serve/ServeFileTest.php +179 -0
  255. vendor/rosell-dk/webp-convert/tests/Serve/mock-header.inc +52 -0
  256. vendor/rosell-dk/webp-convert/tests/WebPConvertTest.php +40 -9
  257. vendor/rosell-dk/webp-convert/tests/bootstrap-webp-convert-test.php +20 -0
  258. vendor/rosell-dk/webp-convert/tests/bootstrap-wod-test.php +24 -0
  259. vendor/rosell-dk/webp-convert/tests/images/not-true-color.png +0 -0
  260. vendor/rosell-dk/webp-convert/tests/images/plaintext-with-jpg-extension.jpg +1 -0
  261. vendor/rosell-dk/webp-convert/tests/images/png-with-jpeg-extension.jpg +0 -0
  262. vendor/rosell-dk/webp-convert/tests/images/png-without-extension +0 -0
  263. vendor/rosell-dk/webp-convert/tests/images/small-q61.jpg +0 -0
  264. vendor/rosell-dk/webp-convert/tests/images/test.png +0 -0
  265. vendor/rosell-dk/webp-convert/tests/images/text +0 -0
  266. vendor/rosell-dk/webp-convert/tests/images/text-with-jpg-extension.jpg +0 -0
  267. vendor/rosell-dk/webp-convert/tests/images/text.txt +0 -0
  268. vendor/rosell-dk/webp-convert/tests/images/with%20space.jpg +0 -0
  269. web-service/wpc.php +1 -8
  270. webp-express.php +1 -1
  271. wod/webp-on-demand.php +29 -58
  272. wod/webp-realizer.php +22 -15
README.md CHANGED
@@ -593,10 +593,23 @@ If you got any further questions, look at, or comment on [this topic](https://wo
593
### When is feature X coming? / Roadmap
594
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.
595
596
- Here are my current plans ahead: 0.13 might be bulk conversion and addition of a diagnose tool this should release some time spend in the forum. 0.14 could be focused on PNG. 0.15 might be displaying rules for NGINX. 0.16 might be supporting Save-Data header (send extra compressed images to clients who wants to use as little bandwidth as possible). 0.17 might be a file manager-like interface for inspecting generated webp files. 0.18 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.19 might be WAMP support. The current milestones, their subtasks and their progress can be viewed here: https://github.com/rosell-dk/webp-express/milestones
597
598
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.
599
600
## Changes in 0.13.2
601
- Fixed Fatal error on image upload in combination with the [Enable Media Replace](https://de.wordpress.org/plugins/enable-media-replace/) plugin. Thanks to Alexander Graef from Germany for reporting.
602
- It seems we finally nailed the blank settings page bug. Thanks to all involved, especially Richard Spenceley from the UK
593
### When is feature X coming? / Roadmap
594
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.
595
596
+ 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
597
598
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.
599
600
+ ## Changes in 0.14.0
601
+ - Added new "encoding" option, which can be set to auto. This can in some cases dramatically reduce the size of the webp. It is supported by all converters except ewww and gd.
602
+ - Added new "near-lossless" option (only for cwebp and vips). Using this is a good idea for reducing size of lossless webps with an acceptable loss of quality
603
+ - Added new "alpha-quality" option (all converters, except ewww and gd). Using this is a good idea when images with transparency are converted to lossy webp - it has the potential to reduce the size up to 50% (depending on the source material) while keeping an acceptable level of quality
604
+ - Added new conversion methods: Vips and GraphicsMagick
605
+ - Imagick conversion method now supports webp options (finally cracked it!)
606
+ - Using MimeType detection instead of relying on file extensions
607
+ - In "test" converter you now change options and also test PNG files
608
+ - Added conversion logs
609
+ - PNGs are now enabled by default (with the new conversion features especially PNGs are compressed much better)
610
+
611
+ For more info, see the closed issues on the 0.14.0 milestone on the github repository: https://github.com/rosell-dk/webp-express/milestone/9?closed=1
612
+
613
## Changes in 0.13.2
614
- Fixed Fatal error on image upload in combination with the [Enable Media Replace](https://de.wordpress.org/plugins/enable-media-replace/) plugin. Thanks to Alexander Graef from Germany for reporting.
615
- It seems we finally nailed the blank settings page bug. Thanks to all involved, especially Richard Spenceley from the UK
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.13.2
8
Requires PHP: 5.6
9
License: GPLv3
10
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -38,6 +38,7 @@ The plugin builds on [WebPConvert](https://github.com/rosell-dk/webp-convert) an
38
- Currently ~73% of all traffic, and ~79% of mobile browsing traffic are done with browsers supporting webp. With Mozilla and Microsoft [finally on board](https://medium.com/@richard_90141/webp-image-support-an-8-year-saga-7aa2bedb8d02), these numbers are bound to increase. Check current numbers on [caniuse.com](https://caniuse.com/webp)).
39
40
### Recent news
41
Feb 2019: Multisite is now supported (0.12.0)
42
Jan 2019: Plugin can now alter HTML (0.11.0)
43
@@ -591,7 +592,7 @@ If you got any further questions, look at, or comment on [this topic](https://wo
591
= When is feature X coming? / Roadmap =
592
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.
593
594
- Here are my current plans ahead: 0.13 might be bulk conversion and addition of a diagnose tool this should release some time spend in the forum. 0.14 could be focused on PNG. 0.15 might be displaying rules for NGINX. 0.16 might be supporting Save-Data header (send extra compressed images to clients who wants to use as little bandwidth as possible). 0.17 might be a file manager-like interface for inspecting generated webp files. 0.18 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.19 might be WAMP support. The current milestones, their subtasks and their progress can be viewed here: https://github.com/rosell-dk/webp-express/milestones
595
596
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.
597
@@ -604,6 +605,21 @@ Easy enough! - [Go here!](https://ko-fi.com/rosell). Or [here](https://buymeacof
604
605
== Changelog ==
606
607
= 0.13.2 =
608
*(released: 16 may 2019)*
609
@@ -781,6 +797,9 @@ For older releases, check out changelog.txt
781
782
== Upgrade Notice ==
783
784
= 0.13.2 =
785
Fixed critical error on upload (can occur in combination with some plugins), and it seems we finally nailed the blank settings page bug.
786
4
Tags: webp, images, performance
5
Requires at least: 4.0
6
Tested up to: 5.2
7
+ Stable tag: 0.14.0
8
Requires PHP: 5.6
9
License: GPLv3
10
License URI: https://www.gnu.org/licenses/gpl-3.0.html
38
- Currently ~73% of all traffic, and ~79% of mobile browsing traffic are done with browsers supporting webp. With Mozilla and Microsoft [finally on board](https://medium.com/@richard_90141/webp-image-support-an-8-year-saga-7aa2bedb8d02), these numbers are bound to increase. Check current numbers on [caniuse.com](https://caniuse.com/webp)).
39
40
### Recent news
41
+ Jun 2019: Better conversions and more conversion options
42
Feb 2019: Multisite is now supported (0.12.0)
43
Jan 2019: Plugin can now alter HTML (0.11.0)
44
592
= When is feature X coming? / Roadmap =
593
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.
594
595
+ 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
596
597
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.
598
605
606
== Changelog ==
607
608
+ = 0.14.0-beta =
609
+ *(released: 15 jun 2019)*
610
+
611
+ * Added new "encoding" option, which can be set to auto. This can in some cases dramatically reduce the size of the webp. It is supported by all converters except ewww and gd.
612
+ * Added new "near-lossless" option (only for cwebp and vips). Using this is a good idea for reducing size of lossless webps with an acceptable loss of quality
613
+ * Added new "alpha-quality" option (all converters, except ewww and gd). Using this is a good idea when images with transparency are converted to lossy webp - it has the potential to reduce the size up to 50% (depending on the source material) while keeping an acceptable level of quality
614
+ * Added new conversion methods: Vips and GraphicsMagick
615
+ * Imagick conversion method now supports webp options (finally cracked it!)
616
+ * Using MimeType detection instead of relying on file extensions
617
+ * In "test" converter you now change options and also test PNG files
618
+ * Added conversion logs
619
+ * PNGs are now enabled by default (with the new conversion features especially PNGs are compressed much better)
620
+
621
+ For more info, see the closed issues on the 0.14.0 milestone on the github repository: https://github.com/rosell-dk/webp-express/milestone/9?closed=1
622
+
623
= 0.13.2 =
624
*(released: 16 may 2019)*
625
797
798
== Upgrade Notice ==
799
800
+ = 0.14.0 =
801
+ New awesome conversion options that gets you even smaller webp files without compromising quality.
802
+
803
= 0.13.2 =
804
Fixed critical error on upload (can occur in combination with some plugins), and it seems we finally nailed the blank settings page bug.
805
composer.json CHANGED
@@ -3,20 +3,9 @@
3
"description": "WebP for the masses",
4
"type": "project",
5
"license": "MIT",
6
- "minimum-stability": "stable",
7
- "repositories": [
8
- {
9
- "type": "vcs",
10
- "url": "https://github.com/rosell-dk/webp-convert"
11
- },
12
- {
13
- "type": "vcs",
14
- "url": "https://github.com/rosell-dk/webp-convert-cloud-service"
15
- }
16
- ],
17
"require": {
18
- "rosell-dk/webp-convert": "^1.3.8",
19
- "rosell-dk/webp-convert-cloud-service": "^1.0.0",
20
"rosell-dk/dom-util-for-webp": "^0.3.0"
21
},
22
"require-dev": {
3
"description": "WebP for the masses",
4
"type": "project",
5
"license": "MIT",
6
"require": {
7
+ "rosell-dk/webp-convert": "^2.0.2",
8
+ "rosell-dk/webp-convert-cloud-service": "^2.0.0",
9
"rosell-dk/dom-util-for-webp": "^0.3.0"
10
},
11
"require-dev": {
composer.lock CHANGED
@@ -4,7 +4,7 @@
4
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
"This file is @generated automatically"
6
],
7
- "content-hash": "b5e5a83c346324652e5f6cb8edf61e11",
8
"packages": [
9
{
10
"name": "rosell-dk/dom-util-for-webp",
@@ -62,22 +62,22 @@
62
"time": "2019-03-07T09:15:07+00:00"
63
},
64
{
65
- "name": "rosell-dk/webp-convert",
66
- "version": "1.3.9",
67
"source": {
68
"type": "git",
69
- "url": "https://github.com/rosell-dk/webp-convert.git",
70
- "reference": "3680c278f08748054b4ab3ea7855be8984f008aa"
71
},
72
"dist": {
73
"type": "zip",
74
- "url": "https://api.github.com/repos/rosell-dk/webp-convert/zipball/3680c278f08748054b4ab3ea7855be8984f008aa",
75
- "reference": "3680c278f08748054b4ab3ea7855be8984f008aa",
76
"shasum": ""
77
},
78
"require-dev": {
79
"friendsofphp/php-cs-fixer": "^2.11",
80
- "phpunit/phpunit": "5.7.27",
81
"squizlabs/php_codesniffer": "3.*"
82
},
83
"type": "library",
@@ -93,53 +93,10 @@
93
},
94
"autoload": {
95
"psr-4": {
96
- "WebPConvert\\": "src/"
97
}
98
},
99
- "autoload-dev": {
100
- "psr-4": {
101
- "WebPConvert\\Tests\\": "tests/"
102
- }
103
- },
104
- "scripts": {
105
- "ci": [
106
- "@build",
107
- "@test",
108
- "@phpcs-all",
109
- "@composer validate --no-check-all --strict"
110
- ],
111
- "build": [
112
- "@build-wod",
113
- "@build-require-all"
114
- ],
115
- "cs-fix-all": [
116
- "php-cs-fixer fix src"
117
- ],
118
- "cs-fix": [
119
- "php-cs-fixer fix"
120
- ],
121
- "cs-dry": [
122
- "php-cs-fixer fix --dry-run --diff"
123
- ],
124
- "test": [
125
- "phpunit"
126
- ],
127
- "phpcs": [
128
- "phpcs --standard=PSR2"
129
- ],
130
- "phpcs-all": [
131
- "phpcs --standard=PSR2 src"
132
- ],
133
- "phpcbf": [
134
- "phpcbf --standard=PSR2"
135
- ],
136
- "build-wod": [
137
- "php build-scripts/build-webp-on-demand.php"
138
- ],
139
- "build-require-all": [
140
- "php build-scripts/generate-require-all.php"
141
- ]
142
- },
143
"license": [
144
"MIT"
145
],
@@ -148,15 +105,81 @@
148
"name": "Bjørn Rosell",
149
"homepage": "https://www.bitwise-it.dk/contact",
150
"role": "Project Author"
151
- },
152
{
153
"name": "Martin Folkers",
154
"homepage": "https://twobrain.io",
155
"role": "Collaborator"
156
}
157
],
158
"description": "Convert JPEG & PNG to WebP with PHP",
159
"keywords": [
160
"cwebp",
161
"gd",
162
"image conversion",
@@ -165,31 +188,26 @@
165
"jpg",
166
"jpg2webp",
167
"png",
168
- "png2webp",
169
- "webp"
170
],
171
- "support": {
172
- "source": "https://github.com/rosell-dk/webp-convert/tree/1.3.9",
173
- "issues": "https://github.com/rosell-dk/webp-convert/issues"
174
- },
175
- "time": "2019-03-21T07:34:21+00:00"
176
},
177
{
178
"name": "rosell-dk/webp-convert-cloud-service",
179
- "version": "1.0.0",
180
"source": {
181
"type": "git",
182
"url": "https://github.com/rosell-dk/webp-convert-cloud-service.git",
183
- "reference": "e250d49f4cb0fd0c07becbfa0abb7a1a31d03e37"
184
},
185
"dist": {
186
"type": "zip",
187
- "url": "https://api.github.com/repos/rosell-dk/webp-convert-cloud-service/zipball/e250d49f4cb0fd0c07becbfa0abb7a1a31d03e37",
188
- "reference": "e250d49f4cb0fd0c07becbfa0abb7a1a31d03e37",
189
"shasum": ""
190
},
191
"require": {
192
- "rosell-dk/webp-convert": "^1.2.1"
193
},
194
"require-dev": {
195
"friendsofphp/php-cs-fixer": "^2.11",
@@ -212,39 +230,7 @@
212
"WebPConvertCloudService\\": "src/"
213
}
214
},
215
- "autoload-dev": {
216
- "psr-4": {
217
- "WebPConvertCloudService\\Tests\\": "tests/"
218
- }
219
- },
220
- "scripts": {
221
- "ci": [
222
- "@test",
223
- "@phpcs-all",
224
- "@composer validate --no-check-all --strict"
225
- ],
226
- "cs-fix-all": [
227
- "php-cs-fixer fix src"
228
- ],
229
- "cs-fix": [
230
- "php-cs-fixer fix"
231
- ],
232
- "cs-dry": [
233
- "php-cs-fixer fix --dry-run --diff"
234
- ],
235
- "test": [
236
- "phpunit tests/"
237
- ],
238
- "phpcs": [
239
- "phpcs --standard=PSR2"
240
- ],
241
- "phpcs-all": [
242
- "phpcs --standard=PSR2 src"
243
- ],
244
- "phpcbf": [
245
- "phpcbf --standard=PSR2"
246
- ]
247
- },
248
"license": [
249
"MIT"
250
],
@@ -257,6 +243,7 @@
257
],
258
"description": "Cloud service for converting JPEG & PNG to WebP",
259
"keywords": [
260
"cwebp",
261
"gd",
262
"image conversion",
@@ -265,14 +252,9 @@
265
"jpg",
266
"jpg2webp",
267
"png",
268
- "png2webp",
269
- "webp"
270
],
271
- "support": {
272
- "source": "https://github.com/rosell-dk/webp-convert-cloud-service/tree/1.0.0",
273
- "issues": "https://github.com/rosell-dk/webp-convert-cloud-service/issues"
274
- },
275
- "time": "2018-11-09T11:17:43+00:00"
276
}
277
],
278
"packages-dev": [],
4
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
"This file is @generated automatically"
6
],
7
+ "content-hash": "d1905bfab23d538f20fae2c74bb476a5",
8
"packages": [
9
{
10
"name": "rosell-dk/dom-util-for-webp",
62
"time": "2019-03-07T09:15:07+00:00"
63
},
64
{
65
+ "name": "rosell-dk/image-mime-type-guesser",
66
+ "version": "0.3",
67
"source": {
68
"type": "git",
69
+ "url": "https://github.com/rosell-dk/image-mime-type-guesser.git",
70
+ "reference": "204fd61ca81e3b0ba46c6165dab8f74816b1fe99"
71
},
72
"dist": {
73
"type": "zip",
74
+ "url": "https://api.github.com/repos/rosell-dk/image-mime-type-guesser/zipball/204fd61ca81e3b0ba46c6165dab8f74816b1fe99",
75
+ "reference": "204fd61ca81e3b0ba46c6165dab8f74816b1fe99",
76
"shasum": ""
77
},
78
"require-dev": {
79
"friendsofphp/php-cs-fixer": "^2.11",
80
+ "phpunit/phpunit": "^5.7.27",
81
"squizlabs/php_codesniffer": "3.*"
82
},
83
"type": "library",
93
},
94
"autoload": {
95
"psr-4": {
96
+ "ImageMimeTypeGuesser\\": "src/"
97
}
98
},
99
+ "notification-url": "https://packagist.org/downloads/",
100
"license": [
101
"MIT"
102
],
105
"name": "Bjørn Rosell",
106
"homepage": "https://www.bitwise-it.dk/contact",
107
"role": "Project Author"
108
+ }
109
+ ],
110
+ "description": "Guess mime type of images",
111
+ "keywords": [
112
+ "image",
113
+ "images",
114
+ "mime",
115
+ "mime type"
116
+ ],
117
+ "time": "2019-03-29T09:33:28+00:00"
118
+ },
119
+ {
120
+ "name": "rosell-dk/webp-convert",
121
+ "version": "2.0.2",
122
+ "source": {
123
+ "type": "git",
124
+ "url": "https://github.com/rosell-dk/webp-convert.git",
125
+ "reference": "50f59ca429ebe2984a4054696db62bcfcf57d299"
126
+ },
127
+ "dist": {
128
+ "type": "zip",
129
+ "url": "https://api.github.com/repos/rosell-dk/webp-convert/zipball/50f59ca429ebe2984a4054696db62bcfcf57d299",
130
+ "reference": "50f59ca429ebe2984a4054696db62bcfcf57d299",
131
+ "shasum": ""
132
+ },
133
+ "require": {
134
+ "php": "^5.6 | ^7.0",
135
+ "rosell-dk/image-mime-type-guesser": "^0.3"
136
+ },
137
+ "require-dev": {
138
+ "friendsofphp/php-cs-fixer": "^2.11",
139
+ "phpunit/phpunit": "5.7.27",
140
+ "squizlabs/php_codesniffer": "3.*"
141
+ },
142
+ "suggest": {
143
+ "ext-gd": "to use GD extension for converting. Note: Gd must be compiled with webp support",
144
+ "ext-imagick": "to use Imagick extension for converting. Note: Gd must be compiled with webp support",
145
+ "ext-vips": "to use Vips extension for converting.",
146
+ "php-stan/php-stan": "Suggested for dev, in order to analyse code before committing"
147
+ },
148
+ "type": "library",
149
+ "extra": {
150
+ "scripts-descriptions": {
151
+ "ci": "Run tests before CI",
152
+ "phpcs": "Checks coding styles (PSR2) of file/dir, which you must supply. To check all, supply 'src'",
153
+ "phpcbf": "Fix coding styles (PSR2) of file/dir, which you must supply. To fix all, supply 'src'",
154
+ "cs-fix-all": "Fix the coding style of all the source files, to comply with the PSR-2 coding standard",
155
+ "cs-fix": "Fix the coding style of a PHP file or directory, which you must specify.",
156
+ "test": "Launches the preconfigured PHPUnit"
157
+ }
158
+ },
159
+ "autoload": {
160
+ "psr-4": {
161
+ "WebPConvert\\": "src/"
162
+ }
163
+ },
164
+ "notification-url": "https://packagist.org/downloads/",
165
+ "license": [
166
+ "MIT"
167
+ ],
168
+ "authors": [
169
{
170
"name": "Martin Folkers",
171
"homepage": "https://twobrain.io",
172
"role": "Collaborator"
173
+ },
174
+ {
175
+ "name": "Bjørn Rosell",
176
+ "homepage": "https://www.bitwise-it.dk/contact",
177
+ "role": "Project Author"
178
}
179
],
180
"description": "Convert JPEG & PNG to WebP with PHP",
181
"keywords": [
182
+ "Webp",
183
"cwebp",
184
"gd",
185
"image conversion",
188
"jpg",
189
"jpg2webp",
190
"png",
191
+ "png2webp"
192
],
193
+ "time": "2019-06-15T11:45:10+00:00"
194
},
195
{
196
"name": "rosell-dk/webp-convert-cloud-service",
197
+ "version": "2.0.0",
198
"source": {
199
"type": "git",
200
"url": "https://github.com/rosell-dk/webp-convert-cloud-service.git",
201
+ "reference": "5345c63d0a44d529591c36ebab33c3bcfc080787"
202
},
203
"dist": {
204
"type": "zip",
205
+ "url": "https://api.github.com/repos/rosell-dk/webp-convert-cloud-service/zipball/5345c63d0a44d529591c36ebab33c3bcfc080787",
206
+ "reference": "5345c63d0a44d529591c36ebab33c3bcfc080787",
207
"shasum": ""
208
},
209
"require": {
210
+ "rosell-dk/webp-convert": "^2.0.0"
211
},
212
"require-dev": {
213
"friendsofphp/php-cs-fixer": "^2.11",
230
"WebPConvertCloudService\\": "src/"
231
}
232
},
233
+ "notification-url": "https://packagist.org/downloads/",
234
"license": [
235
"MIT"
236
],
243
],
244
"description": "Cloud service for converting JPEG & PNG to WebP",
245
"keywords": [
246
+ "Webp",
247
"cwebp",
248
"gd",
249
"image conversion",
252
"jpg",
253
"jpg2webp",
254
"png",
255
+ "png2webp"
256
],
257
+ "time": "2019-06-14T13:05:09+00:00"
258
}
259
],
260
"packages-dev": [],
lib/classes/AdminInit.php CHANGED
@@ -30,7 +30,7 @@ class AdminInit
30
public static function runMigrationIfNeeded()
31
{
32
// When an update requires a migration, the number should be increased
33
- define('WEBPEXPRESS_MIGRATION_VERSION', '8');
34
35
if (WEBPEXPRESS_MIGRATION_VERSION != Option::getOption('webp-express-migration-version', 0)) {
36
// run migration logic
@@ -38,7 +38,7 @@ class AdminInit
38
}
39
40
// uncomment next line to test-run a migration
41
- //include WEBPEXPRESS_PLUGIN_DIR . '/lib/migrate/migrate8.php';
42
}
43
44
public static function adminInitHandler()
@@ -66,6 +66,7 @@ class AdminInit
66
add_action("admin_post_webpexpress_settings_submit", array('\WebPExpress\OptionsPageHooks', 'submitHandler'));
67
add_action("admin_init", array('\WebPExpress\AdminInit', 'adminInitHandler'));
68
69
// Print pending messages, if any
70
if (Option::getOption('webp-express-messages-pending')) {
71
add_action(Multisite::isNetworkActivated() ? 'network_admin_notices' : 'admin_notices', array('\WebPExpress\Messenger', 'printPendingMessages'));
@@ -79,8 +80,10 @@ class AdminInit
79
80
// Ajax actions
81
add_action('wp_ajax_list_unconverted_files', array('\WebPExpress\BulkConvert', 'processAjaxListUnconvertedFiles'));
82
- add_action('wp_ajax_convert_file', array('\WebPExpress\BulkConvert', 'processAjaxConvertFile'));
83
add_action('wp_ajax_webpexpress_purge_cache', array('\WebPExpress\CachePurge', 'processAjaxPurgeCache'));
84
85
// PS:
86
// Filters for processing upload hooks in order to convert images upon upload (wp_handle_upload / image_make_intermediate_size)
30
public static function runMigrationIfNeeded()
31
{
32
// When an update requires a migration, the number should be increased
33
+ define('WEBPEXPRESS_MIGRATION_VERSION', '9');
34
35
if (WEBPEXPRESS_MIGRATION_VERSION != Option::getOption('webp-express-migration-version', 0)) {
36
// run migration logic
38
}
39
40
// uncomment next line to test-run a migration
41
+ //include WEBPEXPRESS_PLUGIN_DIR . '/lib/migrate/migrate9.php';
42
}
43
44
public static function adminInitHandler()
66
add_action("admin_post_webpexpress_settings_submit", array('\WebPExpress\OptionsPageHooks', 'submitHandler'));
67
add_action("admin_init", array('\WebPExpress\AdminInit', 'adminInitHandler'));
68
69
+
70
// Print pending messages, if any
71
if (Option::getOption('webp-express-messages-pending')) {
72
add_action(Multisite::isNetworkActivated() ? 'network_admin_notices' : 'admin_notices', array('\WebPExpress\Messenger', 'printPendingMessages'));
80
81
// Ajax actions
82
add_action('wp_ajax_list_unconverted_files', array('\WebPExpress\BulkConvert', 'processAjaxListUnconvertedFiles'));
83
+ add_action('wp_ajax_convert_file', array('\WebPExpress\Convert', 'processAjaxConvertFile'));
84
+ add_action('wp_ajax_webpexpress_view_log', array('\WebPExpress\ConvertLog', 'processAjaxViewLog'));
85
add_action('wp_ajax_webpexpress_purge_cache', array('\WebPExpress\CachePurge', 'processAjaxPurgeCache'));
86
+ add_action('wp_ajax_webpexpress_dismiss_message', array('\WebPExpress\DismissableMessages', 'processAjaxDismissMessage'));
87
88
// PS:
89
// Filters for processing upload hooks in order to convert images upon upload (wp_handle_upload / image_make_intermediate_size)
lib/classes/AlterHtmlHelper.php CHANGED
@@ -198,9 +198,8 @@ class AlterHtmlHelper
198
* Get url for webp
199
* returns second argument if no webp
200
*
201
- * @param $imageUrl (ie http://example.com/wp-content/image.jpg)
202
- * @param $baseUrl (ie http://example.com/wp-content)
203
- * @param $baseDir (ie /var/www/example.com/wp-content)
204
*/
205
public static function getWebPUrl($sourceUrl, $returnValueOnFail)
206
{
198
* Get url for webp
199
* returns second argument if no webp
200
*
201
+ * @param $sourceUrl
202
+ * @param $returnValueOnFail
203
*/
204
public static function getWebPUrl($sourceUrl, $returnValueOnFail)
205
{
lib/classes/BulkConvert.php CHANGED
@@ -204,14 +204,4 @@ class BulkConvert
204
wp_die();
205
}
206
207
- public static function processAjaxConvertFile()
208
- {
209
- $filename = $_POST['filename'];
210
-
211
- $result = Convert::convertFile($filename);
212
-
213
- echo json_encode($result, JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
214
- wp_die();
215
- }
216
-
217
}
204
wp_die();
205
}
206
207
}
lib/classes/CachePurge.php CHANGED
@@ -4,6 +4,7 @@ namespace WebPExpress;
4
5
use \WebPExpress\Convert;
6
use \WebPExpress\FileHelper;
7
use \WebPExpress\Paths;
8
9
class CachePurge
@@ -15,6 +16,8 @@ class CachePurge
15
*/
16
public static function purge($config, $onlyPng)
17
{
18
$filter = [
19
'only-png' => $onlyPng,
20
'only-with-corresponding-original' => false
4
5
use \WebPExpress\Convert;
6
use \WebPExpress\FileHelper;
7
+ use \WebPExpress\DismissableMessages;
8
use \WebPExpress\Paths;
9
10
class CachePurge
16
*/
17
public static function purge($config, $onlyPng)
18
{
19
+ DismissableMessages::dismissMessage('0.14.0/suggest-wipe-because-lossless');
20
+
21
$filter = [
22
'only-png' => $onlyPng,
23
'only-with-corresponding-original' => false
lib/classes/Config.php CHANGED
@@ -58,7 +58,7 @@ class Config
58
'operation-mode' => 'varied-image-responses',
59
60
// general
61
- 'image-types' => 1,
62
'destination-folder' => 'separate',
63
'destination-extension' => 'append',
64
'cache-control' => 'no-header', /* can be "no-header", "set" or "custom" */
@@ -76,11 +76,22 @@ class Config
76
'enable-redirection-to-webp-realizer' => true,
77
78
// conversion options
79
- 'converters' => [],
80
'quality-auto' => $qualityAuto,
81
'max-quality' => 80,
82
'quality-specific' => 70,
83
'metadata' => 'none',
84
'convert-on-upload' => true,
85
86
// serve options
@@ -127,20 +138,23 @@ class Config
127
128
if ($config['operation-mode'] == 'varied-image-responses') {
129
$config = array_merge($config, [
130
'enable-redirection-to-converter' => true,
131
'only-redirect-to-converter-for-webp-enabled-browsers' => true,
132
'only-redirect-to-converter-on-cache-miss' => false,
133
'do-not-pass-source-in-query-string' => true, // Will be removed in 0.13
134
- //'redirect-to-existing-in-htaccess' => true,
135
'fail' => 'original',
136
'success-response' => 'converted',
137
]);
138
} elseif ($config['operation-mode'] == 'cdn-friendly') {
139
$config = array_merge($config, [
140
'only-redirect-to-converter-for-webp-enabled-browsers' => false,
141
'only-redirect-to-converter-on-cache-miss' => true,
142
'do-not-pass-source-in-query-string' => true, // Will be removed in 0.13
143
- 'redirect-to-existing-in-htaccess' => false,
144
'fail' => 'original',
145
'success-response' => 'original',
146
// cache-control => 'no-header' (we do not need this, as it is not important what it is set to in cdn-friendly mode, and we dont the value to be lost when switching operation mode)
@@ -181,6 +195,10 @@ class Config
181
$config['alter-html'] = array_replace_recursive($defaultConfig['alter-html'], $config['alter-html']);
182
}
183
184
$config = self::applyOperationMode($config);
185
186
if (!isset($config['web-service'])) {
@@ -211,7 +229,10 @@ class Config
211
ConvertersHelper::$defaultConverters
212
);
213
} else {
214
215
// This is first time visit!
216
// We must add converters.
217
// We want to order them according to which ones that are working,
@@ -225,6 +246,7 @@ class Config
225
226
$defaultConverters = ConvertersHelper::$defaultConverters;
227
228
if (count($workingConverters) == 0) {
229
// No converters are working
230
// Send ewww converter to top
@@ -255,6 +277,7 @@ class Config
255
}
256
$config['converters'] = array_merge($resultPart1, $resultPart2);
257
}
258
}
259
260
@@ -274,9 +297,11 @@ class Config
274
/**
275
* Loads Config (if available), fills in the rest with defaults
276
* also applies operation mode.
277
*/
278
public static function loadConfigAndFix($checkQualityDetection = true)
279
{
280
return self::fix(Config::loadConfig(), $checkQualityDetection);
281
}
282
@@ -466,14 +491,26 @@ class Config
466
467
public static function generateWodOptionsFromConfigObj($config)
468
{
469
- $options = $config;
470
- $options['converters'] = [];
471
- foreach ($config['converters'] as $converter) {
472
- if (isset($converter['deactivated']) && ($converter['deactivated'])) continue;
473
474
- $options['converters'][] = $converter;
475
}
476
- foreach ($options['converters'] as &$c) {
477
if ($c['converter'] == 'cwebp') {
478
if (isset($c['options']['set-size']) && $c['options']['set-size']) {
479
unset($c['options']['set-size']);
@@ -482,6 +519,9 @@ class Config
482
unset($c['options']['size-in-percentage']);
483
}
484
}
485
unset ($c['id']);
486
unset($c['working']);
487
unset($c['error']);
@@ -489,56 +529,109 @@ class Config
489
if (isset($c['options']['quality']) && ($c['options']['quality'] == 'inherit')) {
490
unset ($c['options']['quality']);
491
}
492
if (!isset($c['options'])) {
493
$c = $c['converter'];
494
- }
495
}
496
497
- if (isset($options['cache-control'])) {
498
- $options['cache-control-header'] = self::getCacheControlHeader($config);
499
- }
500
501
- $auto = (isset($options['quality-auto']) && $options['quality-auto']);
502
- $qualitySpecific = (isset($options['quality-specific']) ? $options['quality-specific'] : 70);
503
if ($auto) {
504
- $options['quality'] = 'auto';
505
- } else {
506
- $options['quality'] = $qualitySpecific;
507
- unset ($options['max-quality']);
508
}
509
- unset($options['quality-auto']);
510
- unset($options['quality-specific']);
511
512
- unset($options['image-types']);
513
- unset($options['cache-control']);
514
- unset($options['cache-control-custom']);
515
- unset($options['cache-control-public']);
516
- unset($options['cache-control-max-age']);
517
- unset($options['paths-used-in-htaccess']);
518
- unset($options['web-service']);
519
- unset($options['alter-html']);
520
- unset($options['enable-redirection-to-converter']);
521
- unset($options['operation-mode']);
522
- unset($options['only-redirect-to-converter-for-webp-enabled-browsers']);
523
- unset($options['only-redirect-to-converter-on-cache-miss']);
524
- unset($options['enable-redirection-to-webp-realizer']);
525
- unset($options['convert-on-upload']);
526
527
528
- //unset($options['']);
529
- //unset($options['']);
530
- //unset($options['']);
531
532
533
534
- //unset($options['forward-query-string']); // It is used in webp-on-demand.php, so do not unset!
535
- unset($options['do-not-pass-source-in-query-string']);
536
- unset($options['redirect-to-existing-in-htaccess']);
537
538
- $options['paths'] = [
539
- 'uploadDirRel' => Paths::getUploadDirRel()
540
];
541
542
return $options;
543
}
544
@@ -557,6 +650,9 @@ class Config
557
*/
558
public static function saveConfigurationFileAndWodOptions($config)
559
{
560
if (!(self::saveConfigurationFile($config))) {
561
return false;
562
}
@@ -580,6 +676,10 @@ class Config
580
$rewriteRulesNeedsUpdate = HTAccess::doesRewriteRulesNeedUpdate($config);
581
}
582
583
if (self::saveConfigurationFile($config)) {
584
$options = self::generateWodOptionsFromConfigObj($config);
585
if (self::saveWodOptionsFile($options)) {
58
'operation-mode' => 'varied-image-responses',
59
60
// general
61
+ 'image-types' => 3,
62
'destination-folder' => 'separate',
63
'destination-extension' => 'append',
64
'cache-control' => 'no-header', /* can be "no-header", "set" or "custom" */
76
'enable-redirection-to-webp-realizer' => true,
77
78
// conversion options
79
+ 'jpeg-encoding' => 'auto',
80
+ 'jpeg-enable-near-lossless' => true,
81
+ 'jpeg-near-lossless' => 60,
82
'quality-auto' => $qualityAuto,
83
'max-quality' => 80,
84
'quality-specific' => 70,
85
+
86
+ 'png-encoding' => 'auto',
87
+ 'png-enable-near-lossless' => true,
88
+ 'png-near-lossless' => 60,
89
+ 'png-quality' => 85,
90
+ 'alpha-quality' => 80,
91
+
92
+ 'converters' => [],
93
'metadata' => 'none',
94
+ //'log-call-arguments' => true,
95
'convert-on-upload' => true,
96
97
// serve options
138
139
if ($config['operation-mode'] == 'varied-image-responses') {
140
$config = array_merge($config, [
141
+ //'redirect-to-existing-in-htaccess' => true, // this can now be configured, so do not apply
142
'enable-redirection-to-converter' => true,
143
'only-redirect-to-converter-for-webp-enabled-browsers' => true,
144
'only-redirect-to-converter-on-cache-miss' => false,
145
'do-not-pass-source-in-query-string' => true, // Will be removed in 0.13
146
'fail' => 'original',
147
'success-response' => 'converted',
148
]);
149
} elseif ($config['operation-mode'] == 'cdn-friendly') {
150
$config = array_merge($config, [
151
+ 'redirect-to-existing-in-htaccess' => false,
152
+ 'enable-redirection-to-converter' => false,
153
+ /*
154
'only-redirect-to-converter-for-webp-enabled-browsers' => false,
155
'only-redirect-to-converter-on-cache-miss' => true,
156
+ */
157
'do-not-pass-source-in-query-string' => true, // Will be removed in 0.13
158
'fail' => 'original',
159
'success-response' => 'original',
160
// cache-control => 'no-header' (we do not need this, as it is not important what it is set to in cdn-friendly mode, and we dont the value to be lost when switching operation mode)
195
$config['alter-html'] = array_replace_recursive($defaultConfig['alter-html'], $config['alter-html']);
196
}
197
198
+ if (!isset($config['base-htaccess-on-these-capability-tests'])) {
199
+ self::runAndStoreCapabilityTests($config);
200
+ }
201
+
202
$config = self::applyOperationMode($config);
203
204
if (!isset($config['web-service'])) {
229
ConvertersHelper::$defaultConverters
230
);
231
} else {
232
+ // This is first time visit!
233
+ $config['converters'] = ConvertersHelper::$defaultConverters;
234
235
+ /*
236
// This is first time visit!
237
// We must add converters.
238
// We want to order them according to which ones that are working,
246
247
$defaultConverters = ConvertersHelper::$defaultConverters;
248
249
+
250
if (count($workingConverters) == 0) {
251
// No converters are working
252
// Send ewww converter to top
277
}
278
$config['converters'] = array_merge($resultPart1, $resultPart2);
279
}
280
+ */
281
}
282
283
297
/**
298
* Loads Config (if available), fills in the rest with defaults
299
* also applies operation mode.
300
+ * If config is not saved yet, the default config will be returned
301
*/
302
public static function loadConfigAndFix($checkQualityDetection = true)
303
{
304
+ // PS: Yes, loadConfig may return false. "fix" handles this by returning default config
305
return self::fix(Config::loadConfig(), $checkQualityDetection);
306
}
307
491
492
public static function generateWodOptionsFromConfigObj($config)
493
{
494
495
+ // WebP convert options
496
+ // --------------------
497
+ $wc = [
498
+ 'converters' => []
499
+ ];
500
+
501
+ // Add active converters
502
+ foreach ($config['converters'] as $converter) {
503
+ if (isset($converter['deactivated']) && ($converter['deactivated'])) {
504
+ continue;
505
+ }
506
+ $wc['converters'][] = $converter;
507
}
508
+
509
+ // Clean the converter options from junk
510
+ foreach ($wc['converters'] as &$c) {
511
+
512
+ // In cwebp converter options (here in webp express), we have a checkbox "set size"
513
+ // - there is no such option in webp-convert - so remove.
514
if ($c['converter'] == 'cwebp') {
515
if (isset($c['options']['set-size']) && $c['options']['set-size']) {
516
unset($c['options']['set-size']);
519
unset($c['options']['size-in-percentage']);
520
}
521
}
522
+
523
+ // 'id', 'working' and 'error' attributes are used internally in webp-express,
524
+ // no need to have it in the wod configuration file.
525
unset ($c['id']);
526
unset($c['working']);
527
unset($c['error']);
529
if (isset($c['options']['quality']) && ($c['options']['quality'] == 'inherit')) {
530
unset ($c['options']['quality']);
531
}
532
+ /*
533
if (!isset($c['options'])) {
534
$c = $c['converter'];
535
+ }*/
536
}
537
538
+ // Create jpeg options
539
+ // https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#png-og-jpeg-specific-options
540
541
+ $auto = (isset($config['quality-auto']) && $config['quality-auto']);
542
+ $wc['jpeg'] = [
543
+ 'encoding' => $config['jpeg-encoding'],
544
+ 'quality' => ($auto ? 'auto' : $config['quality-specific']),
545
+ ];
546
if ($auto) {
547
+ $wc['jpeg']['default-quality'] = $config['quality-specific'];
548
+ $wc['jpeg']['max-quality'] = $config['max-quality'];
549
+ }
550
+ if ($config['jpeg-encoding'] != 'lossy') {
551
+ if ($config['jpeg-enable-near-lossless']) {
552
+ $wc['jpeg']['near-lossless'] = $config['jpeg-near-lossless'];
553
+ } else {
554
+ $wc['jpeg']['near-lossless'] = 100;
555
+ }
556
}
557
558
+ // Create png options
559
+ // ---
560
+ $wc['png'] = [
561
+ 'encoding' => $config['png-encoding'],
562
+ 'quality' => $config['png-quality'],
563
+ ];
564
+ if ($config['png-encoding'] != 'lossy') {
565
+ if ($config['png-enable-near-lossless']) {
566
+ $wc['png']['near-lossless'] = $config['png-near-lossless'];
567
+ } else {
568
+ $wc['png']['near-lossless'] = 100;
569
+ }
570
+ }
571
+ if ($config['png-encoding'] != 'lossless') {
572
+ // Only relevant for pngs, and only for "lossy" (and thus also "auto")
573
+ $wc['png']['alpha-quality'] = $config['alpha-quality'];
574
+ }
575
576
+ // Other convert options
577
+ $wc['metadata'] = $config['metadata'];
578
+ $wc['log-call-arguments'] = true; // $config['log-call-arguments'];
579
+
580
+ // Serve options
581
+ // -------------
582
+ $serve = [
583
+ 'serve-image' => [
584
+ 'headers' => [
585
+ 'cache-control' => false,
586
+ 'content-length' => true,
587
+ 'content-type' => true,
588
+ 'expires' => false,
589
+ 'last-modified' => true,
590
+ //'vary-accept' => false // This must be different for webp-on-demand and webp-realizer
591
+ ]
592
+ ]
593
+ ];
594
+ if ($config['cache-control'] != 'no-header') {
595
+ $serve['serve-image']['cache-control-header'] = self::getCacheControlHeader($config);
596
+ $serve['serve-image']['headers']['cache-control'] = true;
597
+ $serve['serve-image']['headers']['expires'] = true;
598
+ }
599
+ $serve['fail'] = $config['fail'];
600
+
601
+
602
+ // WOD options
603
+ // -------------
604
+ $wod = [
605
+ 'base-htaccess-on-these-capability-tests' => $config['base-htaccess-on-these-capability-tests'],
606
+ 'destination-extension' => $config['destination-extension'],
607
+ 'destination-folder' => $config['destination-folder'],
608
+ 'forward-query-string' => $config['forward-query-string'],
609
+ //'method-for-passing-source' => $config['method-for-passing-source'],
610
+ 'paths' => [
611
+ 'uploadDirRel' => Paths::getUploadDirRel()
612
+ ],
613
+ 'success-response' => $config['success-response'],
614
+ ];
615
616
617
+ // Put it all together
618
+ // -------------
619
620
+ //$options = array_merge($wc, $serve, $wod);
621
622
+ // I'd like to put the webp-convert options in its own key,
623
+ // but it requires some work. Postponing it to another day that I can uncomment the two next lines (and remove the one above)
624
+ //$wc = array_merge($wc, $serve);
625
+ //$options = array_merge($wod, ['webp-convert' => $wc]);
626
627
+ //$options = array_merge($wod, array_merge($serve, ['conversion' => $wc]));
628
+
629
+ $options = [
630
+ 'wod' => $wod,
631
+ 'webp-convert' => array_merge($serve, ['convert' => $wc])
632
];
633
634
+
635
return $options;
636
}
637
650
*/
651
public static function saveConfigurationFileAndWodOptions($config)
652
{
653
+ if (!isset($config['base-htaccess-on-these-capability-tests'])) {
654
+ self::runAndStoreCapabilityTests($config);
655
+ }
656
if (!(self::saveConfigurationFile($config))) {
657
return false;
658
}
676
$rewriteRulesNeedsUpdate = HTAccess::doesRewriteRulesNeedUpdate($config);
677
}
678
679
+ if (!isset($config['base-htaccess-on-these-capability-tests'])) {
680
+ self::runAndStoreCapabilityTests($config);
681
+ }
682
+
683
if (self::saveConfigurationFile($config)) {
684
$options = self::generateWodOptionsFromConfigObj($config);
685
if (self::saveWodOptionsFile($options)) {
lib/classes/Convert.php CHANGED
@@ -8,6 +8,7 @@ namespace WebPExpress;
8
9
use \WebPExpress\ConvertHelperIndependent;
10
use \WebPExpress\Config;
11
12
class Convert
13
{
@@ -26,19 +27,27 @@ class Convert
26
);
27
}
28
29
- public static function convertFile($source, $config = null)
30
{
31
if (is_null($config)) {
32
$config = Config::loadConfigAndFix();
33
}
34
- $options = Config::generateWodOptionsFromConfigObj($config);
35
36
$destination = self::getDestination($source, $config);
37
38
- $result = ConvertHelperIndependent::convert($source, $destination, $options);
39
40
//$result['destination'] = $destination;
41
- if ($result['success']) {
42
$result['filesize-original'] = @filesize($source);
43
$result['filesize-webp'] = @filesize($destination);
44
}
@@ -58,4 +67,49 @@ class Convert
58
);
59
}
60
61
}
8
9
use \WebPExpress\ConvertHelperIndependent;
10
use \WebPExpress\Config;
11
+ use \WebpExpress\ConvertersHelper;
12
13
class Convert
14
{
27
);
28
}
29
30
+ public static function convertFile($source, $config = null, $convertOptions = null, $converter = null)
31
{
32
if (is_null($config)) {
33
$config = Config::loadConfigAndFix();
34
}
35
+ if (is_null($convertOptions)) {
36
+ $convertOptions = Config::generateWodOptionsFromConfigObj($config)['webp-convert']['convert'];
37
+ }
38
+ /*
39
+ if (isset($config['converter'])) {
40
+ $options['convert']['converter'] = $config['converter'];
41
+ }*/
42
43
$destination = self::getDestination($source, $config);
44
45
+ $logDir = Paths::getWebPExpressContentDirAbs() . '/log';
46
+
47
+ $result = ConvertHelperIndependent::convert($source, $destination, $convertOptions, $logDir, $converter);
48
49
//$result['destination'] = $destination;
50
+ if ($result['success'] === true) {
51
$result['filesize-original'] = @filesize($source);
52
$result['filesize-webp'] = @filesize($destination);
53
}
67
);
68
}
69
70
+ public static function processAjaxConvertFile()
71
+ {
72
+ $filename = $_POST['filename'];
73
+
74
+ if (isset($_POST['config-overrides'])) {
75
+ $config = Config::loadConfigAndFix();
76
+
77
+ // overrides
78
+ $overrides = $_POST['config-overrides'];
79
+ $overrides = preg_replace('/\\\\"/', '"', $overrides); // We got crazy encoding, perhaps by jQuery. This cleans it up
80
+ $overrides = json_decode($overrides, true);
81
+
82
+ $config = array_merge($config, $overrides);
83
+
84
+ // single converter
85
+ $converter = null;
86
+ $convertOptions = null;
87
+ if (isset($_POST['converter'])) {
88
+ $converter = $_POST['converter'];
89
+
90
+ // find converter
91
+ $c = ConvertersHelper::getConverterById($config, $converter);
92
+ if ($c !== false) {
93
+
94
+ $convertOptions = Config::generateWodOptionsFromConfigObj($config)['webp-convert']['convert'];
95
+ $convertOptions = array_merge($convertOptions, $c['options']);
96
+ unset($convertOptions['converters']);
97
+
98
+ $config = array_merge($config, $c['options']);
99
+ //echo 'options: <pre>' . print_r($convertOptions, true) . '</pre>'; exit;
100
+ //echo 'options: <pre>' . print_r($c['options'], true) . '</pre>'; exit;
101
+ }
102
+ }
103
+
104
+ $result = self::convertFile($filename, $config, $convertOptions, $converter);
105
+
106
+ } else {
107
+ $result = self::convertFile($filename);
108
+ }
109
+
110
+
111
+ echo json_encode($result, JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
112
+ wp_die();
113
+ }
114
+
115
}
lib/classes/ConvertHelperIndependent.php CHANGED
@@ -7,8 +7,10 @@ It is used by webp-on-demand.php, which does not register an auto loader. It is
7
namespace WebPExpress;
8
9
use \WebPConvert\WebPConvert;
10
use \WebPConvert\Loggers\BufferLogger;
11
use \WebPExpress\FileHelper;
12
13
14
class ConvertHelperIndependent
@@ -178,18 +180,106 @@ class ConvertHelperIndependent
178
}
179
}
180
181
- public static function convert($source, $destination, $options) {
182
include_once __DIR__ . '/../../vendor/autoload.php';
183
184
$success = false;
185
$msg = '';
186
$logger = new BufferLogger();
187
try {
188
- $success = WebPConvert::convert($source, $destination, $options, $logger);
189
- } catch (\Exception $e) {
190
$msg = $e->getMessage();
191
}
192
193
return [
194
'success' => $success,
195
'msg' => $msg,
@@ -198,4 +288,22 @@ class ConvertHelperIndependent
198
199
}
200
201
}
7
namespace WebPExpress;
8
9
use \WebPConvert\WebPConvert;
10
+ use \WebPConvert\Convert\ConverterFactory;
11
use \WebPConvert\Loggers\BufferLogger;
12
use \WebPExpress\FileHelper;
13
+ use WebPConvert\Exceptions\WebPConvertException;
14
15
16
class ConvertHelperIndependent
180
}
181
}
182
183
+ public static function getLogFilename($source, $logDir)
184
+ {
185
+ // Calculate path for log file
186
+ // ---------------------------
187
+ $logDir .= '/conversions';
188
+ $docRoot = rtrim(realpath($_SERVER["DOCUMENT_ROOT"]), '/');
189
+
190
+ // Check if source is residing inside document root.
191
+ // (it is, if path starts with document root + '/')
192
+ if (self::sourceIsInsideDocRoot($source, $docRoot) ) {
193
+
194
+ // We store relative to document root.
195
+ // "Eat" the left part off the source parameter which contains the document root.
196
+ // and also eat the slash (+1)
197
+ $sourceRel = substr($source, strlen($docRoot) + 1);
198
+ return $logDir . '/doc-root/' . $sourceRel . '.md';
199
+ } else {
200
+ // Source file is residing outside document root.
201
+ // we must add complete path to structure
202
+ return $logDir . '/abs' . $source . '.md';
203
+ }
204
+
205
+ }
206
+
207
+ public static function createLogDir($logDir)
208
+ {
209
+ $logDir = Paths::getLogDirAbs();
210
+
211
+ if (!is_dir($logDir)) {
212
+ @mkdir($logDir, 0775, true);
213
+ @chmod($logDir, 0775);
214
+ @file_put_contents(rtrim($logDir . '/') . '/.htaccess', <<<APACHE
215
+ <IfModule mod_authz_core.c>
216
+ Require all denied
217
+ </IfModule>
218
+ <IfModule !mod_authz_core.c>
219
+ Order deny,allow
220
+ Deny from all
221
+ </IfModule>
222
+ APACHE
223
+ );
224
+ @chmod($logDir . '/.htaccess', 0664);
225
+ }
226
+ return is_dir($logDir);
227
+ }
228
+
229
+ public static function saveLog($source, $logDir, $text, $msgTop)
230
+ {
231
+ if (!file_exists($logDir)) {
232
+ self::createLogDir($logDir);
233
+ }
234
+
235
+ $text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
236
+
237
+ $text = 'WebP Express 0.14.0. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
238
+
239
+ $logFile = self::getLogFilename($source, $logDir);
240
+
241
+ $logFolder = @dirname($logFile);
242
+ if (!@file_exists($logFolder)) {
243
+ mkdir($logFolder, 0777, true);
244
+ }
245
+ if (@file_exists($logFolder)) {
246
+ file_put_contents($logFile, $text);
247
+ }
248
+ }
249
+
250
+ /**
251
+ * To convert with a specific converter, set it in the $converter param.
252
+ */
253
+ public static function convert($source, $destination, $convertOptions, $logDir, $converter = null) {
254
include_once __DIR__ . '/../../vendor/autoload.php';
255
256
$success = false;
257
$msg = '';
258
$logger = new BufferLogger();
259
try {
260
+ if (!is_null($converter)) {
261
+ //if (isset($convertOptions['converter'])) {
262
+ //print_r($convertOptions);exit;
263
+ $logger->logLn('Converter set to: ' . $converter);
264
+ $logger->logLn('');
265
+ $converter = ConverterFactory::makeConverter($converter, $source, $destination, $convertOptions, $logger);
266
+ $converter->doConvert();
267
+ } else {
268
+ WebPConvert::convert($source, $destination, $convertOptions, $logger);
269
+ }
270
+ $success = true;
271
+ } catch (\WebpConvert\Exceptions\WebPConvertException $e) {
272
$msg = $e->getMessage();
273
+ } catch (\Exception $e) {
274
+ $msg = 'An exception was thrown!';
275
+ } catch (Throwable $e) {
276
+ //Executed only in PHP 7, will not match in PHP 5
277
+ //$msg = $e->getMessage();
278
+ //$msg = 'oh no';
279
}
280
281
+ self::saveLog($source, $logDir, $logger->getMarkDown("\n\r"), 'Conversion triggered using bulk conversion');
282
+
283
return [
284
'success' => $success,
285
'msg' => $msg,
288
289
}
290
291
+ public static function serveConverted($source, $destination, $serveOptions, $logDir, $logMsgTop = '')
292
+ {
293
+ include_once __DIR__ . '/../../vendor/autoload.php';
294
+
295
+ // TODO: error_log()
296
+ //ini_set('display_errors', 0);
297
+ //error_reporting(0);
298
+
299
+ //echo '<pre>' . print_r($serveOptions, true) . '</pre>'; exit;
300
+
301
+ $convertLogger = new BufferLogger();
302
+ WebPConvert::serveConverted($source, $destination, $serveOptions, null, $convertLogger);
303
+ $convertLog = $convertLogger->getMarkDown("\n\r");
304
+ if ($convertLog != '') {
305
+ self::saveLog($source, $logDir, $convertLog, $logMsgTop);
306
+ }
307
+
308
+ }
309
}
lib/classes/ConvertLog.php ADDED
@@ -0,0 +1,37 @@
1
+ <?php
2
+
3
+ namespace WebPExpress;
4
+
5
+ use \WebPExpress\ConvertHelperIndependent;
6
+ use \WebPExpress\Paths;
7
+
8
+ class ConvertLog
9
+ {
10
+ public static function processAjaxViewLog()
11
+ {
12
+ $source = $_POST['source'];
13
+
14
+ $logFile = ConvertHelperIndependent::getLogFilename($source, Paths::getLogDirAbs());
15
+ $msg = 'Log file: <i>' . $logFile . '</i><br><br><hr>';
16
+
17
+ if (!file_exists($logFile)) {
18
+ $msg .= '<b>No log file found on that location</b>';
19
+
20
+ } else {
21
+ $log = file_get_contents($logFile);
22
+ if ($log === false) {
23
+ $msg .= '<b>Could not read log file</b>';
24
+ } else {
25
+ $msg .= nl2br($log);
26
+ }
27
+
28
+ }
29
+
30
+ //$log = $source;
31
+ //file_get_contents
32
+
33
+ echo json_encode($msg, JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
34
+ wp_die();
35
+ }
36
+
37
+ }
lib/classes/ConvertersHelper.php CHANGED
@@ -5,25 +5,32 @@ namespace WebPExpress;
5
class ConvertersHelper
6
{
7
public static $defaultConverters = [
8
- ['converter' => 'gd', 'options' => [
9
- 'skip-pngs' => false
10
- ]],
11
['converter' => 'cwebp', 'options' => [
12
'use-nice' => true,
13
'try-common-system-paths' => true,
14
'try-supplied-binary-for-os' => true,
15
'method' => 6,
16
- 'size-in-percentage' => 45,
17
- 'low-memory' => false,
18
- 'command-line-options' => '-low_memory',
19
]],
20
- ['converter' => 'imagick'],
21
- ['converter' => 'gmagick'],
22
- ['converter' => 'wpc'], // we should not set api-version default - it is handled in the javascript
23
- ['converter' => 'ewww'],
24
- ['converter' => 'imagickbinary', 'options' => [
25
'use-nice' => true,
26
]],
27
];
28
29
public static function getDefaultConverterNames()
@@ -58,6 +65,19 @@ class ConvertersHelper
58
$second = self::normalize($second);
59
60
foreach ($second as $converter) {
61
if (!in_array($converter['converter'], $namesInFirst)) {
62
$first[] = $converter;
63
}
@@ -65,4 +85,158 @@ class ConvertersHelper
65
return $first;
66
}
67
68
}
5
class ConvertersHelper
6
{
7
public static $defaultConverters = [
8
['converter' => 'cwebp', 'options' => [
9
'use-nice' => true,
10
'try-common-system-paths' => true,
11
'try-supplied-binary-for-os' => true,
12
'method' => 6,
13
+ 'size-in-percentage' => null,
14
+ 'low-memory' => true,
15
+ 'command-line-options' => '',
16
+ ]],
17
+ ['converter' => 'vips', 'options' => [
18
+ 'smart-subsample' => false,
19
+ 'preset' => 'none'
20
+ ]],
21
+ ['converter' => 'imagemagick', 'options' => [
22
+ 'use-nice' => true,
23
]],
24
+ ['converter' => 'graphicsmagick', 'options' => [
25
'use-nice' => true,
26
]],
27
+ ['converter' => 'wpc', 'options' => []], // we should not set api-version default - it is handled in the javascript
28
+ ['converter' => 'ewww', 'options' => []],
29
+ ['converter' => 'imagick', 'options' => []],
30
+ ['converter' => 'gmagick', 'options' => []],
31
+ ['converter' => 'gd', 'options' => [
32
+ 'skip-pngs' => false,
33
+ ]],
34
];
35
36
public static function getDefaultConverterNames()
65
$second = self::normalize($second);
66
67
foreach ($second as $converter) {
68
+ // migrate9 and this functionality could create two converters.
69
+ // so, for a while, skip graphicsmagick and imagemagick
70
+
71
+ if ($converter['converter'] == 'graphicsmagick') {
72
+ if (in_array('gmagickbinary', $namesInFirst)) {
73
+ continue;
74
+ }
75
+ }
76
+ if ($converter['converter'] == 'imagemagick') {
77
+ if (in_array('imagickbinary', $namesInFirst)) {
78
+ continue;
79
+ }
80
+ }
81
if (!in_array($converter['converter'], $namesInFirst)) {
82
$first[] = $converter;
83
}
85
return $first;
86
}
87
88
+ /**
89
+ * Get converter by id
90
+ *
91
+ * @param object $config
92
+ * @return array|false converter object
93
+ */
94
+ public static function getConverterById($config, $id) {
95
+ if (!isset($config['converters'])) {
96
+ return false;
97
+ }
98
+ $converters = $config['converters'];
99
+
100
+ if (!is_array($converters)) {
101
+ return false;
102
+ }
103
+
104
+ foreach ($converters as $c) {
105
+ if (!isset($c['converter'])) {
106
+ continue;
107
+ }
108
+ if ($c['converter'] == $id) {
109
+ return $c;
110
+ }
111
+ }
112
+ return false;
113
+ }
114
+
115
+ /**
116
+ * Get working converters.
117
+ *
118
+ * @param object $config
119
+ * @return array
120
+ */
121
+ public static function getWorkingConverters($config) {
122
+ if (!isset($config['converters'])) {
123
+ return [];
124
+ }
125
+ $converters = $config['converters'];
126
+
127
+ if (!is_array($converters)) {
128
+ return [];
129
+ }
130
+
131
+ $result = [];
132
+
133
+ foreach ($converters as $c) {
134
+ if (isset($c['working']) && !$c['working']) {
135
+ continue;
136
+ }
137
+ $result[] = $c;
138
+ }
139
+ return $result;
140
+ }
141
+
142
+ /**
143
+ * Get array of working converter ids. Same order as configured.
144
+ */
145
+ public static function getWorkingConverterIds($config)
146
+ {
147
+ $converters = self::getWorkingConverters($config);
148
+ $result = [];
149
+ foreach ($converters as $converter) {
150
+ $result[] = $converter['converter'];
151
+ }
152
+ return $result;
153
+ }
154
+
155
+ /**
156
+ * Get working and active converters.
157
+ *
158
+ * @param object $config
159
+ * @return array
160
+ */
161
+ public static function getWorkingAndActiveConverters($config)
162
+ {
163
+ if (!isset($config['converters'])) {
164
+ return [];
165
+ }
166
+ $converters = $config['converters'];
167
+
168
+ if (!is_array($converters)) {
169
+ return [];
170
+ }
171
+
172
+ $result = [];
173
+
174
+ foreach ($converters as $c) {
175
+ if (isset($c['deactivated']) && $c['deactivated']) {
176
+ continue;
177
+ }
178
+ if (isset($c['working']) && !$c['working']) {
179
+ continue;
180
+ }
181
+ $result[] = $c;
182
+ }
183
+ return $result;
184
+ }
185
+
186
+ public static function getWorkingAndActiveConverterIds($config)
187
+ {
188
+ $converters = self::getWorkingAndActiveConverters($config);
189
+ $result = [];
190
+ foreach ($converters as $converter) {
191
+ $result[] = $converter['converter'];
192
+ }
193
+ return $result;
194
+ }
195
+
196
+ /**
197
+ * Get converter id by converter object
198
+ *
199
+ * @param object $converter
200
+ * @return string converter name, or empty string if not set (it should always be set, however)
201
+ */
202
+ public static function getConverterId($converter) {
203
+ if (!isset($converter['converter'])) {
204
+ return '';
205
+ }
206
+ return $converter['converter'];
207
+ }
208
+
209
+ /**
210
+ * Get first working and active converter.
211
+ *
212
+ * @param object $config
213
+ * @return object|false
214
+ */
215
+ public static function getFirstWorkingAndActiveConverter($config) {
216
+
217
+ $workingConverters = self::getWorkingAndActiveConverters($config);
218
+
219
+ if (count($workingConverters) == 0) {
220
+ return false;
221
+ }
222
+ return $workingConverters[0];
223
+ }
224
+
225
+ /**
226
+ * Get first working and active converter (name)
227
+ *
228
+ * @param object $config
229
+ * @return string|false id of converter, or false if no converter is working and active
230
+ */
231
+ public static function getFirstWorkingAndActiveConverterId($config) {
232
+ $c = self::getFirstWorkingAndActiveConverter($config);
233
+ if ($c === false) {
234
+ return false;
235
+ }
236
+ if (!isset($c['converter'])) {
237
+ return false;
238
+ }
239
+ return $c['converter'];
240
+ }
241
+
242
}
lib/classes/DismissableMessages.php ADDED
@@ -0,0 +1,82 @@
1
+ <?php
2
+
3
+ namespace WebPExpress;
4
+
5
+ use \WebPExpress\Option;
6
+ use \WebPExpress\State;
7
+ use \WebPExpress\Messenger;
8
+
9
+ class DismissableMessages
10
+ {
11
+
12
+ /**
13
+ * Add dismissible message.
14
+ *
15
+ * @param string $id An identifier, ie "suggest_enable_pngs"
16
+ */
17
+ public static function addDismissableMessage($id)
18
+ {
19
+ $dismissableMessageIds = State::getState('dismissableMessageIds', []);
20
+
21
+ // Ensure we do not add a message that is already there
22
+ if (in_array($id, $dismissableMessageIds)) {
23
+ return;
24
+ }
25
+ $dismissableMessageIds[] = $id;
26
+ State::setState('dismissableMessageIds', $dismissableMessageIds);
27
+ }
28
+
29
+ public static function printDismissableMessage($level, $msg, $id, $gotItText = '')
30
+ {
31
+ if ($gotItText != '') {
32
+ $javascript = "jQuery(this).closest('div.notice').slideUp();";
33
+ //$javascript = "console.log(jQuery(this).closest('div.notice'));";
34
+ $javascript .= "jQuery.post(ajaxurl, {'action': 'webpexpress_dismiss_message', 'id': '" . $id . "'});";
35
+
36
+ $msg .= '<button type="button" class="button button-primary" onclick="' . $javascript . '" style="display:block; margin-top:20px">' . $gotItText . '</button>';
37
+ }
38
+ Messenger::printMessage($level, $msg);
39
+ }
40
+
41
+ public static function printMessages()
42
+ {
43
+ $ids = State::getState('dismissableMessageIds', []);
44
+ foreach ($ids as $id) {
45
+ include_once __DIR__ . '/../dismissable-messages/' . $id . '.php';
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Dismiss message
51
+ *
52
+ * @param string $id An identifier, ie "suggest_enable_pngs"
53
+ */
54
+ public static function dismissMessage($id) {
55
+ $messages = State::getState('dismissableMessageIds', []);
56
+ $newQueue = [];
57
+ foreach ($messages as $mid) {
58
+ if ($mid == $id) {
59
+
60
+ } else {
61
+ $newQueue[] = $mid;
62
+ }
63
+ }
64
+ State::setState('dismissableMessageIds', $newQueue);
65
+ }
66
+
67
+ /**
68
+ * Dismiss message
69
+ *
70
+ * @param string $id An identifier, ie "suggest_enable_pngs"
71
+ */
72
+ public static function dismissAll() {
73
+ State::setState('dismissableMessageIds', []);
74
+ }
75
+
76
+ public static function processAjaxDismissMessage() {
77
+ $id = $_POST['id'];
78
+ self::dismissMessage($id);
79
+ }
80
+
81
+
82
+ }
lib/classes/HTAccess.php CHANGED
@@ -36,6 +36,8 @@ class HTAccess
36
return '# WebP Express does not need to write any rules (it has not been set up to redirect to converter, nor to existing webp, and the "convert non-existing webp-files upon request" option has not been enabled)';
37
}
38
39
if (isset($config['base-htaccess-on-these-capability-tests'])) {
40
$capTests = $config['base-htaccess-on-these-capability-tests'];
41
$modHeaderDefinitelyUnavailable = ($capTests['modHeaderWorking'] === false);
@@ -58,6 +60,11 @@ class HTAccess
58
$passRelativeFilePathInQSRealizer = $passRelativeFilePathInQS;
59
60
61
62
/* Calculate $fileExt */
63
$imageTypes = $config['image-types'];
@@ -167,6 +174,7 @@ class HTAccess
167
$uploadsRel = PathHelper::getRelDir(Paths::getIndexDirAbs(), Paths::getUploadDirAbs());
168
169
//$rules .= '# rel: ' . $uploadsRel . "\n";
170
if (strpos($wpContentRel, '.') !== 0) {
171
172
if (strpos($uploadsRel, $wpContentRel) === 0) {
@@ -186,6 +194,10 @@ class HTAccess
186
//$rules .= "# The following SetEnv allows to diagnose if .htaccess files are turned off\n";
187
//$rules .= "SetEnv HTACCESS on\n\n";
188
*/
189
190
$rules .= "<IfModule mod_rewrite.c>\n" .
191
" RewriteEngine On\n\n";
@@ -229,10 +241,10 @@ class HTAccess
229
230
if ($config['destination-extension'] == 'append') {
231
$rules .= " RewriteCond %{DOCUMENT_ROOT}/" . $htaccessDirRel . "/$1.$2.webp -f\n";
232
- $rules .= " RewriteRule " . $rewriteRuleStart . "\.(" . $fileExt . ")$ $1.$2.webp [T=image/webp,E=EXISTING:1,L]\n\n";
233
} else {
234
$rules .= " RewriteCond %{DOCUMENT_ROOT}/" . $htaccessDirRel . "/$1.webp -f\n";
235
- $rules .= " RewriteRule " . $rewriteRuleStart . "\.(" . $fileExt . ")$ $1.webp [T=image/webp,E=EXISTING:1,L]\n\n";
236
//$rules .= " RewriteRule ^(.+)\.(" . $fileExt . ")$ $1.webp [T=image/webp,E=EXISTING:1,L]\n\n";
237
}
238
}
@@ -244,6 +256,14 @@ class HTAccess
244
$rules .= " RewriteRule " . $rewriteRuleStart . "\.(" . $fileExt . ")$ /" . $cacheDirRel . "/" . $htaccessDirRel . "/$1.$2.webp [NC,T=image/webp,E=EXISTING:1,L]\n\n";
245
//$rules .= " RewriteRule ^\/?(.*)\.(" . $fileExt . ")$ /" . $cacheDirRel . "/" . $htaccessDirRel . "/$1.$2.webp [NC,T=image/webp,E=EXISTING:1,L]\n\n";
246
247
$rules .= $ccRules;
248
249
}
@@ -389,22 +409,23 @@ class HTAccess
389
$rules .= "\n";
390
}
391
392
- $addVary = ($config['enable-redirection-to-converter'] && ($config['success-response'] == 'converted')) || ($config['redirect-to-existing-in-htaccess']);
393
394
if ($addVary) {
395
$rules .= " <IfModule mod_headers.c>\n";
396
$rules .= " <IfModule mod_setenvif.c>\n";
397
398
$rules .= " # Set Vary:Accept header for the image types handled by WebP Express.\n" .
399
" # The purpose is to make proxies and CDNs aware that the response varies with the Accept header. \n" .
400
- " SetEnvIf Request_URI \"\.(" . $fileExt . ")\" ADDVARY\n" .
401
" Header append \"Vary\" \"Accept\" env=ADDVARY\n\n";
402
403
if ($config['redirect-to-existing-in-htaccess']) {
404
$rules .= " # Set X-WebP-Express header for diagnose purposes\n" .
405
- " # Apache appends \"REDIRECT_\" in front of the environment variables defined in mod_rewrite, but LiteSpeed does not.\n" .
406
- " # So, the next line is for Apache, in order to set environment variables without \"REDIRECT_\"\n" .
407
- " SetEnvIf REDIRECT_EXISTING 1 EXISTING=1\n" .
408
//" SetEnvIf REDIRECT_WOD 1 WOD=1\n\n" .
409
//" # Set the debug header\n" .
410
" Header set \"X-WebP-Express\" \"Redirected directly to existing webp\" env=EXISTING\n";
36
return '# WebP Express does not need to write any rules (it has not been set up to redirect to converter, nor to existing webp, and the "convert non-existing webp-files upon request" option has not been enabled)';
37
}
38
39
+
40
+
41
if (isset($config['base-htaccess-on-these-capability-tests'])) {
42
$capTests = $config['base-htaccess-on-these-capability-tests'];
43
$modHeaderDefinitelyUnavailable = ($capTests['modHeaderWorking'] === false);
60
$passRelativeFilePathInQSRealizer = $passRelativeFilePathInQS;
61
62
63
+ $addVary = $config['redirect-to-existing-in-htaccess'];
64
+ if ($modHeaderDefinitelyUnavailable) {
65
+ $addVary = false;
66
+ }
67
+
68
69
/* Calculate $fileExt */
70
$imageTypes = $config['image-types'];
174
$uploadsRel = PathHelper::getRelDir(Paths::getIndexDirAbs(), Paths::getUploadDirAbs());
175
176
//$rules .= '# rel: ' . $uploadsRel . "\n";
177
+
178
if (strpos($wpContentRel, '.') !== 0) {
179
180
if (strpos($uploadsRel, $wpContentRel) === 0) {
194
//$rules .= "# The following SetEnv allows to diagnose if .htaccess files are turned off\n";
195
//$rules .= "SetEnv HTACCESS on\n\n";
196
*/
197
+ $rules .= "# The rules below are a result of the WebP Express options, Wordpress configuration and the following .htaccess capability tests:\n" .
198
+ "# - mod_header working?: " . ($capTests['modHeaderWorking'] === true ? 'yes' : ($capTests['modHeaderWorking'] === false ? 'no' : 'could not be determined')) . "\n" .
199
+ "# - pass variable from .htaccess to script through header working?: " . ($capTests['passThroughHeaderWorking'] === true ? 'yes' : ($capTests['passThroughHeaderWorking'] === false ? 'no' : 'could not be determined')) . "\n" .
200
+ "# - pass variable from .htaccess to script through environment variable working?: " . ($capTests['passThroughEnvWorking'] === true ? 'yes' : ($capTests['passThroughEnvWorking'] === false ? 'no' : 'could not be determined')) . "\n";
201
202
$rules .= "<IfModule mod_rewrite.c>\n" .
203
" RewriteEngine On\n\n";
241
242
if ($config['destination-extension'] == 'append') {
243
$rules .= " RewriteCond %{DOCUMENT_ROOT}/" . $htaccessDirRel . "/$1.$2.webp -f\n";
244
+ $rules .= " RewriteRule " . $rewriteRuleStart . "\.(" . $fileExt . ")$ $1.$2.webp [T=image/webp,E=EXISTING:1," . ($addVary ? 'E=ADDVARY:1,' : '') . "L]\n\n";
245
} else {
246
$rules .= " RewriteCond %{DOCUMENT_ROOT}/" . $htaccessDirRel . "/$1.webp -f\n";
247
+ $rules .= " RewriteRule " . $rewriteRuleStart . "\.(" . $fileExt . ")$ $1.webp [T=image/webp,E=EXISTING:1," . ($addVary ? 'E=ADDVARY:1,' : '') . "L]\n\n";
248
//$rules .= " RewriteRule ^(.+)\.(" . $fileExt . ")$ $1.webp [T=image/webp,E=EXISTING:1,L]\n\n";
249
}
250
}
256
$rules .= " RewriteRule " . $rewriteRuleStart . "\.(" . $fileExt . ")$ /" . $cacheDirRel . "/" . $htaccessDirRel . "/$1.$2.webp [NC,T=image/webp,E=EXISTING:1,L]\n\n";
257
//$rules .= " RewriteRule ^\/?(.*)\.(" . $fileExt . ")$ /" . $cacheDirRel . "/" . $htaccessDirRel . "/$1.$2.webp [NC,T=image/webp,E=EXISTING:1,L]\n\n";
258
259
+ if ($addVary) {
260
+ $rules .= " # Make sure that browsers which does not support webp also gets the Vary:Accept header\n" .
261
+ " # when requesting images that would be redirected to existing webp on browsers that does.\n" .
262
+ " <IfModule mod_setenvif.c>\n" .
263
+ " SetEnvIf Request_URI \"\.(" . $fileExt . ")$\" ADDVARY\n" .
264
+ " </IfModule>\n\n";
265
+ }
266
+
267
$rules .= $ccRules;
268
269
}
409
$rules .= "\n";
410
}
411
412
+ //$addVary = ($config['enable-redirection-to-converter'] && ($config['success-response'] == 'converted')) || ($config['redirect-to-existing-in-htaccess']);
413
414
if ($addVary) {
415
$rules .= " <IfModule mod_headers.c>\n";
416
$rules .= " <IfModule mod_setenvif.c>\n";
417
418
+ $rules .= " # Apache appends \"REDIRECT_\" in front of the environment variables defined in mod_rewrite, but LiteSpeed does not.\n" .
419
+ " # So, the next lines are for Apache, in order to set environment variables without \"REDIRECT_\"\n" .
420
+ " SetEnvIf REDIRECT_EXISTING 1 EXISTING=1\n" .
421
+ " SetEnvIf REDIRECT_ADDVARY 1 ADDVARY=1\n\n";
422
+
423
$rules .= " # Set Vary:Accept header for the image types handled by WebP Express.\n" .
424
" # The purpose is to make proxies and CDNs aware that the response varies with the Accept header. \n" .
425
" Header append \"Vary\" \"Accept\" env=ADDVARY\n\n";
426
427
if ($config['redirect-to-existing-in-htaccess']) {
428
$rules .= " # Set X-WebP-Express header for diagnose purposes\n" .
429
//" SetEnvIf REDIRECT_WOD 1 WOD=1\n\n" .
430
//" # Set the debug header\n" .
431
" Header set \"X-WebP-Express\" \"Redirected directly to existing webp\" env=EXISTING\n";
lib/classes/HandleDeleteFileHook.php CHANGED
@@ -21,9 +21,8 @@ class HandleDeleteFileHook
21
}
22
23
$destination = Convert::getDestination($filename);
24
- error_log('deleting webp:' . $destination);
25
if (!unlink($destination)) {
26
- error_log('failed deleting webp:' . $destination);
27
}
28
29
}
21
}
22
23
$destination = Convert::getDestination($filename);
24
if (!unlink($destination)) {
25
+ error_log('WebP Express failed deleting webp:' . $destination);
26
}
27
28
}
lib/classes/Messenger.php CHANGED
@@ -10,8 +10,8 @@ class Messenger
10
private static $printedStyles = false;
11
12
/**
13
- * $level: info | success | warning | error
14
- * $msg: the message (not translated)
15
*
16
* Hm... we should add some sprintf-like support
17
* $msg = sprintf(__( 'You are on a very old version of PHP (%s). WebP Express may not work as intended.', 'webp-express' ), phpversion());
@@ -45,8 +45,9 @@ class Messenger
45
46
//$msg = __( $msg, 'webp-express'); // uncommented. We should add some sprintf-like functionality before making the plugin translatable
47
printf(
48
- '<div class="%1$s"><p>%2$s</p></div>',
49
- esc_attr('notice notice-' . $level . ' is-dismissible'),
50
$msg
51
);
52
}
@@ -66,7 +67,7 @@ class Messenger
66
.notice-error {
67
border-left-color: #dc3232;
68
}
69
- .notice-success {
70
border-left-color: #46b450;
71
}
72
.notice-info {
@@ -88,6 +89,8 @@ class Messenger
88
}
89
90
State::setState('pendingMessages', []);
91
Option::updateOption('webp-express-messages-pending', false, true);
92
}
93
}
10
private static $printedStyles = false;
11
12
/**
13
+ * @param string $level (info | success | warning | error)
14
+ * @param string $msg the message (not translated)
15
*
16
* Hm... we should add some sprintf-like support
17
* $msg = sprintf(__( 'You are on a very old version of PHP (%s). WebP Express may not work as intended.', 'webp-express' ), phpversion());
45
46
//$msg = __( $msg, 'webp-express'); // uncommented. We should add some sprintf-like functionality before making the plugin translatable
47
printf(
48
+ '<div class="%1$s"><div style="margin:10px 0">%2$s</div></div>',
49
+ //esc_attr('notice notice-' . $level . ' is-dismissible'),
50
+ esc_attr('notice notice-' . $level),
51
$msg
52
);
53
}
67
.notice-error {
68
border-left-color: #dc3232;
69
}
70
+ .notice-success {esc_attr('notice notice-' . $level . ' is-dismissible'),
71
border-left-color: #46b450;
72
}
73
.notice-info {
89
}
90
91
State::setState('pendingMessages', []);
92
+
93
Option::updateOption('webp-express-messages-pending', false, true);
94
}
95
+
96
}
lib/classes/Paths.php CHANGED
@@ -247,6 +247,13 @@ APACHE
247
return self::createDirIfMissing(self::getCacheDirAbs());
248
}
249
250
// ------------ Plugin Dir (all plugins) -------------
251
252
public static function getPluginDirAbs()
@@ -382,7 +389,7 @@ APACHE
382
*/
383
public static function getPluginUrl()
384
{
385
- return untrailingslashit(plugins_url('', WEBPEXPRESS_PLUGIN));
386
}
387
388
public static function getPluginUrlPath()
@@ -423,11 +430,14 @@ APACHE
423
return [
424
'urls' => [
425
'webpExpressRoot' => self::getPluginUrlPath(),
426
],
427
'filePaths' => [
428
'webpExpressRoot' => self::getWebPExpressPluginDirAbs(),
429
'destinationRoot' => self::getCacheDirAbs(),
430
- 'configRelToDocRoot' => self::getConfigDirRel()
431
]
432
];
433
}
247
return self::createDirIfMissing(self::getCacheDirAbs());
248
}
249
250
+ // ------------ Cache Dir -------------
251
+
252
+ public static function getLogDirAbs()
253
+ {
254
+ return self::getWebPExpressContentDirAbs() . '/log';
255
+ }
256
+
257
// ------------ Plugin Dir (all plugins) -------------
258
259
public static function getPluginDirAbs()
389
*/
390
public static function getPluginUrl()
391
{