Skip to content

Commit a873747

Browse files
[6.0] Enable support for multiple image extensions in Random Image module (joomla#45200)
* Enable Multi extension random image * fix style * Update RandomImageHelper.php * CS fix ---------
1 parent e93c78c commit a873747

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

modules/mod_random_image/src/Helper/RandomImageHelper.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ public static function getRandomImage(&$params, $images)
8282
*/
8383
public static function getImages(&$params, $folder)
8484
{
85-
$type = $params->get('type', 'jpg');
85+
$type = $params->get('type', 'jpg');
86+
$extensions = array_map('trim', explode(',', $type));
87+
88+
// Normalize to lowercase and strip leading dots
89+
$extensions = array_map(function ($ext) {
90+
return ltrim(strtolower($ext), '.');
91+
}, $extensions);
92+
8693
$files = [];
8794
$images = [];
8895

@@ -103,9 +110,14 @@ public static function getImages(&$params, $folder)
103110
$i = 0;
104111

105112
foreach ($files as $img) {
106-
if (!is_dir($dir . '/' . $img) && preg_match('/' . $type . '/', $img)) {
107-
$images[$i] = new \stdClass();
113+
if (is_dir($dir . '/' . $img)) {
114+
continue;
115+
}
116+
117+
$ext = pathinfo($img, PATHINFO_EXTENSION);
108118

119+
if (\in_array(strtolower($ext), $extensions, true)) {
120+
$images[$i] = new \stdClass();
109121
$images[$i]->name = $img;
110122
$images[$i]->folder = $folder;
111123
$i++;

0 commit comments

Comments
 (0)