Skip to content

Commit f7904dc

Browse files
committed
Migrate to Smarty 5, add support for modern image formats (webp, avif, ...)
1 parent 5bf90a2 commit f7904dc

21 files changed

+251
-138
lines changed

src/wcmf/application/controller/MediaController.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
*/
1111
namespace wcmf\application\controller;
1212

13-
use wcmf\lib\config\ConfigurationException;
1413
use wcmf\lib\io\FileUtil;
1514
use wcmf\lib\presentation\Controller;
1615
use wcmf\lib\util\URIUtil;
1716

1817
if (!class_exists('\elFinder')) {
19-
throw new ConfigurationException(
20-
'wcmf\application\controller\MediaController requires '.
21-
'elFinder. If you are using composer, add studio-42/elfinder '.
18+
throw new \wcmf\lib\config\ConfigurationException(
19+
'\wcmf\application\controller\MediaController requires '.
20+
'\elFinder. If you are using composer, add studio-42/elfinder '.
2221
'as dependency to your project');
2322
}
2423

src/wcmf/application/views/plugins/block.assetic.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* See the LICENSE file distributed with this work for
99
* additional information.
1010
*/
11-
use wcmf\lib\config\ConfigurationException;
1211
use wcmf\lib\core\ObjectFactory;
1312
use wcmf\lib\io\FileUtil;
1413
use wcmf\lib\util\StringUtil;
@@ -24,8 +23,8 @@
2423
use Assetic\Filter\ScssphpFilter;
2524
use Minifier\MinFilter;
2625

27-
if (!class_exists('Assetic\Asset\AssetCollection')) {
28-
throw new ConfigurationException(
26+
if (!class_exists('\Assetic\Asset\AssetCollection')) {
27+
throw new \wcmf\lib\config\ConfigurationException(
2928
'smarty_block_assetic requires '.
3029
'Assetic. If you are using composer, add kriswallsmith/assetic '.
3130
'as dependency to your project');
@@ -55,11 +54,11 @@
5554
* - scssImportPaths: Array of paths to add to the import paths of the scss compiler (relative to WCMF_BASE)
5655
* - debug: Boolean, if true the content will be returned as is
5756
* @param string $content
58-
* @param Smarty_Internal_Template $template Smarty_Internal_Template
57+
* @param \Smarty\Template $template \Smarty\Template
5958
* @param bool $repeat
6059
* @return string
6160
*/
62-
function smarty_block_assetic($params, $content, Smarty_Internal_Template $template, &$repeat) {
61+
function smarty_block_assetic($params, $content, \Smarty\Template $template, &$repeat) {
6362
if (!$repeat) {
6463
if (isset($content)) {
6564
$debug = $params['debug'];

src/wcmf/application/views/plugins/block.if_authorized.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
* - action: The action to process
3030
* - alternative_content: The content to display if not authorized
3131
* @param $content
32-
* @param $template Smarty_Internal_Template
32+
* @param $template \Smarty\Template
3333
* @param $repeat
3434
* @return String
3535
*/
36-
function smarty_block_if_authorized($params, $content, \Smarty_Internal_Template $template, &$repeat) {
36+
function smarty_block_if_authorized($params, $content, \Smarty\Template $template, &$repeat) {
3737
if(!$repeat) {
3838
$permissionManager = ObjectFactory::getInstance('permissionManager');
3939
if ($permissionManager->authorize($params['resource'], $params['context'], $params['action'])) {

src/wcmf/application/views/plugins/function.configvalue.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
* @param $params Array with keys:
2222
* - key: The key in the configuration section
2323
* - section: The name of the configuration section
24-
* @param $template Smarty_Internal_Template
24+
* @param $template \Smarty\Template
2525
* @return String
2626
*/
27-
function smarty_function_configvalue(array $params, Smarty_Internal_Template $template) {
27+
function smarty_function_configvalue(array $params, \Smarty\Template $template) {
2828
$config = ObjectFactory::getInstance('configuration');
2929
echo $config->getValue($params['key'], $params['section']);
3030
}

src/wcmf/application/views/plugins/function.daterange.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
* - formattype: Format type used in formats parameter (optional, 'strftime'|'date'|'auto', default: 'auto')
2929
* - displaytime: Also take time into account (optional, default: false)
3030
* @note The automatic decision for a format type is based on the existance of a % char in the formats parameter.
31-
* @param $template Smarty_Internal_Template
31+
* @param $template \Smarty\Template
3232
* @return String
3333
*/
34-
function smarty_function_daterange(array $params, Smarty_Internal_Template $template) {
34+
function smarty_function_daterange(array $params, \Smarty\Template $template) {
3535
$hasFrom = strlen($params['from']) > 0;
3636
$hasTo = strlen($params['to']) > 0;
3737
if (!$hasFrom && !$hasTo) {

src/wcmf/application/views/plugins/function.image.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,26 @@
7979
* - widths: Comma separated, sorted list of width values to be used in the srcset attribute
8080
* - type: Indicates how width values should be used (optional, default: w)
8181
* - w: Values will be used as pixels, e.g. widths="1600,960" results in srcset="... 1600w, ... 960w"
82-
* - x: Values will be used as pixel ration, e.g. widths="1600,960" results in srcset="... 2x, ... 1x"
82+
* - x: Values will be used as pixel ratio, e.g. widths="1600,960" results in srcset="... 2x, ... 1x"
8383
* - sizes: Media queries to define image size in relation of the viewport (optional)
84+
* - formats: Associative array of with format names ('jpeg', 'webp', 'png', 'gif', 'avif', 'jpeg2000') as keys and quality values as values (optional)
8485
* - useDataAttributes: Boolean indicating whether to replace src, srcset, sizes by data-src, data-srcset, data-sizes (optional, default: __false__)
8586
* - alt: Alternative text (optional)
8687
* - class: Image class (optional)
87-
* - title: Image title (optional
8888
* - data: Associative array of key/value pairs to be used as data attributes
8989
* - width: Width in pixels to output for the width attribute, the height attribute will be calculated according to the aspect ration (optional)
9090
* - default: The default file, if src does not exist (optional)
9191
* - generate: Boolean indicating whether to generate the images or not (optional, default: __false__)
92-
* @param $template Smarty_Internal_Template
92+
* @param $template \Smarty\Template
9393
* @return String
9494
*/
95-
function smarty_function_image($params, Smarty_Internal_Template $template) {
95+
function smarty_function_image($params, \Smarty\Template $template) {
9696
$file = $params['src'];
9797
$default = isset($params['default']) ? $params['default'] : '';
9898
$widths = array_map('trim', isset($params['widths']) ? explode(',', $params['widths']) : []);
9999
$type = isset($params['type']) ? $params['type'] : 'w';
100100
$sizes = isset($params['sizes']) ? $params['sizes'] : '';
101+
$formats = isset($params['formats']) && is_array($params['formats']) ? $params['formats'] : [];
101102
$useDataAttributes = isset($params['useDataAttributes']) ? $params['useDataAttributes'] : false;
102103
$generate = isset($params['generate']) ? $params['generate'] : false;
103104
$alt = isset($params['alt']) ? $params['alt'] : '';
@@ -106,7 +107,7 @@ function smarty_function_image($params, Smarty_Internal_Template $template) {
106107
$data = isset($params['data']) && is_array($params['data']) ? $params['data'] : [];
107108
$width = isset($params['width']) ? $params['width'] : null;
108109

109-
return ImageUtil::getImageTag($file, $widths, $type, $sizes,
110+
return ImageUtil::getImageTag($file, $widths, $type, $sizes, $formats,
110111
$useDataAttributes, $alt, $class, $title, $data, $width, $default, $generate);
111112
}
112113
?>

src/wcmf/application/views/plugins/function.localize.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
* - node: The Node instance to extract the value from
2222
* - attribute: The name of the attribute (will be appended with "_$lang")
2323
* - lang: Language of the attribute
24-
* @param $template Smarty_Internal_Template
24+
* @param $template \Smarty\Template
2525
* @return String
2626
*/
27-
function smarty_function_localize(array $params, Smarty_Internal_Template $template) {
27+
function smarty_function_localize(array $params, \Smarty\Template $template) {
2828
$language = $params['lang'];
2929
$node = $params['node'];
3030
$attribute = $params['attribute'];

src/wcmf/application/views/plugins/function.module.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
* - name: The name of the module that must exist as a key in the configuration section named 'ContentModule'
3636
* + additional module specific parameters
3737
* NOTE: All variables from the including template are passed to the module template.
38-
* @param $template Smarty_Internal_Template
38+
* @param $template \Smarty\Template
3939
* @return String
4040
*/
41-
function smarty_function_module($params, Smarty_Internal_Template $template) {
41+
function smarty_function_module($params, \Smarty\Template $template) {
4242
$requiredInterface = 'wcmf\lib\presentation\ContentModule';
4343
$config = ObjectFactory::getInstance('configuration');
4444
$modules = $config->getSection('ContentModule');

src/wcmf/application/views/plugins/function.translate.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
* - text: The text to translate
2323
* - r0, r1, ...: Values for text variables (%0%, %1%, ...)
2424
* - lang: The language to translate to
25-
* @param $template Smarty_Internal_Template
25+
* @param $template \Smarty\Template
2626
* @return String
2727
*/
28-
function smarty_function_translate($params, Smarty_Internal_Template $template) {
28+
function smarty_function_translate($params, \Smarty\Template $template) {
2929
$variables = [];
3030
foreach (array_keys($params) as $key) {
3131
if (preg_match("/^r[0-9]+$/", $key)) {

src/wcmf/application/views/plugins/modifier.image_cache.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@
1010
*/
1111

1212
/**
13-
* Output the cache location of the given image and width
13+
* Output the cache location of the given image and width, type and quality
1414
*
1515
* Example:
1616
* @code
1717
* <img src={$image|image_cache:800}">
18+
* <img src={$image|image_cache:800:'webp'}">
19+
* <img src={$image|image_cache:800:'webp':85}">
1820
* @endcode
1921
*
2022
* @param $image The path to the image
2123
* @param $width
24+
* @param $type
25+
* @param $quality
2226
* @return String
2327
*/
2428
use wcmf\lib\io\ImageUtil;
2529

26-
function smarty_modifier_image_cache($image, $width) {
27-
return ImageUtil::getCacheLocation($image, $width);
30+
function smarty_modifier_image_cache($image, $width, $type=null, $quality=null) {
31+
return ImageUtil::getCacheLocation($image, $width, $type, $quality);
2832
}
2933
?>

src/wcmf/application/views/plugins/outputfilter.html5_void_tags.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* Remove closing slashes from void tags according to html5.
1414
*
1515
* @param $output
16-
* @param $template Smarty_Internal_Template
16+
* @param $template \Smarty\Template
1717
* @return String
1818
*/
19-
function smarty_outputfilter_html5_void_tags($output, Smarty_Internal_Template $template) {
19+
function smarty_outputfilter_html5_void_tags($output, \Smarty\Template $template) {
2020
// remove slashes from image tags
2121
$output = preg_replace('/<img([^>]+) ?\/\>/i', "<img $1>", $output);
2222
// replace brs

src/wcmf/application/views/plugins/outputfilter.obfuscate_email.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* @see https://stackoverflow.com/questions/12592363/looking-for-a-php-only-email-address-obfuscator-function#12592364
1515
*
1616
* @param $output
17-
* @param $template Smarty_Internal_Template
17+
* @param $template \Smarty\Template
1818
* @return String
1919
*/
20-
function smarty_outputfilter_obfuscate_email($output, Smarty_Internal_Template $template) {
20+
function smarty_outputfilter_obfuscate_email($output, \Smarty\Template $template) {
2121
$encodePercentage = 50;
2222

2323
// encoding functions

src/wcmf/application/views/plugins/prefilter.removeprids.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* Remove protected region ids (used by wCMFGenerator).
1414
*
1515
* @param $output
16-
* @param $template Smarty_Internal_Template
16+
* @param $template \Smarty\Template
1717
* @return String
1818
*/
19-
function smarty_prefilter_removeprids($output, Smarty_Internal_Template $template) {
19+
function smarty_prefilter_removeprids($output, \Smarty\Template $template) {
2020
// remove protected regions
2121
$output = preg_replace("/<!-- PROTECTED REGION .*? -->/U", "", $output);
2222

0 commit comments

Comments
 (0)