<?php

/**
 * @copyright
 * @package     RIE - Random Image Extended for Joomla! 3.x
 * @author      Viktor Vogel <admin@kubik-rubik.de>
 * @version     3.4.0-FREE - 2020-09-01
 * @link        https://kubik-rubik.de/rie-random-image-extended
 *
 * @license     GNU/GPL
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') || die('Restricted access');

use Joomla\CMS\Helper\ModuleHelper;
use RandomImageExtended\Helper;

require_once __DIR__ . '/src/Helper.php';

$allPics = (bool)$params->get('allPics', true);
$caption = htmlspecialchars($params->get('caption'));
$height = (int)$params->get('height', 200);
$imageName = (bool)$params->get('imageName', false);
$imageRotator = (bool)$params->get('imageRotator', false);
$imageRotatorDuration = (int)$params->get('imageRotatorDuration', 6);
$informationFile = (bool)$params->get('informationFile', false);
$lightbox = (bool)$params->get('lightbox', true);
$lightboxShow = $params->get('lightboxShow', 'venobox');
$link = $params->get('link', '');
$linkFolder = (bool)$params->get('linkFolder', false);
$moduleclassSfx = htmlspecialchars($params->get('moduleclass_sfx'));
$newWindow = (bool)$params->get('newWindow', false);
$subFolder = (bool)$params->get('subFolder', false);
$width = (int)$params->get('width', 200);

$start = new Helper();
$folder = $start->getFolder($params);
$images = $start->getImages($params, $folder, $subFolder);
$start->loadHeadData($lightboxShow, 1);

$layout = 'noimages';

if (count($images)) {
    $linksInfo = [];

    if (!empty($informationFile)) {
        $linksInfo = $start->getFileInfo($folder);
    }

    $imagesDisplay = $start->getRandomImages($params, $images, $width, $height, $imageRotator, $linksInfo);

    if ($lightbox) {
        $start->loadHeadData($lightboxShow, 2);
        $lightboxAttribute = $start->lightboxAttribute($lightboxShow);
    }

    if ($imageRotator) {
        $start->loadHeadData($lightboxShow, 3, $width, $height, $imageRotatorDuration);
    }

    $layout = 'default';
}

require ModuleHelper::getLayoutPath('mod_random_image_extended', $layout);
