Skip to content
18 changes: 15 additions & 3 deletions modules/mod_random_image/src/Helper/RandomImageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ public static function getRandomImage(&$params, $images)
*/
public static function getImages(&$params, $folder)
{
$type = $params->get('type', 'jpg');
$type = $params->get('type', 'jpg');
$extensions = array_map('trim', explode(',', $type));

// Normalize to lowercase and strip leading dots
$extensions = array_map(function ($ext) {
return ltrim(strtolower($ext), '.');
}, $extensions);

$files = [];
$images = [];

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

foreach ($files as $img) {
if (!is_dir($dir . '/' . $img) && preg_match('/' . $type . '/', $img)) {
$images[$i] = new \stdClass();
if (is_dir($dir . '/' . $img)) {
continue;
}

$ext = pathinfo($img, PATHINFO_EXTENSION);

if (\in_array(strtolower($ext), $extensions, true)) {
$images[$i] = new \stdClass();
$images[$i]->name = $img;
$images[$i]->folder = $folder;
$i++;
Expand Down