<?php
/*
 * @package Joomla 3.0
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @component XMovie Component
 * @copyright Copyright (C) Dana Harris optikool.com
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
defined('_JEXEC') or die('Restricted access');
$currRow = 0;
$currRow2 = 1;
$itemCount = 1;
$movCount = count($this->items);
$image_directory = JComponentHelper::getParams('com_media')->get('image_path', 'images') . '/';

$mainXMShowMovieHeading = $this->params->get('show_movie_heading');
$mainXMShowThumb = $this->params->get('show_thumb');
$mainXMResizeThumbs = $this->cparams->get('resize_thumbs');
$mainXMShowName = $this->params->get('show_name');
$mainXMShowDate = $this->params->get('show_date');
$mainXMShowHits = $this->params->get('show_hits');
$mainXMShowTags = $this -> params -> get('show_tags');
$mainXMShowSubmitter = $this->params->get('show_submitter');
$mainXMMovPerRow = $this->params->get('mov_per_row');

foreach ($this->items as $movie) {
    if($currRow2 == 1) {

?>
<div class="row-fluid xgt">
    <?php
    }

    $catalias = '&catid=' . $movie->catid . ':' . $movie->catidoa;
    $itemid = '';

    if (!empty($movie->itemId)) {
        $itemid = "&Itemid={$movie->itemId}";
    }

    $link = JRoute::_("index.php?option=com_xmovie&view=single{$catalias}&id={$movie->id}:{$movie->alias}{$itemid}");
    ?>
    <div class="movie-item text-center span<?php echo $this -> div_width_mov; ?>">
    <?php if ($movie->thumb != '' && $mainXMShowThumb == 1) {?>
        <a href="<?php echo $link; ?>">
        <?php
        $imageThumb = parse_url($movie -> thumb);

        if (!isset($imageThumb['host']) || $imageThumb['host'] == '') {
            if ($mainXMResizeThumbs) {
                $movString = "components/com_xmovie/helpers/img.php?file=" . urlencode($movie -> thumb) . "&t=m";
            } else {
                $movString = JURI::base(true) . $image_directory . $this -> cparams -> get('movie_thumb_path') . "/" . $movie -> thumb;
            }
        } else {
            $movString = $movie -> thumb;
        }
        ?>
            <img class="thumbnail img-fluid" src="<?php echo $movString; ?>" alt="<?php echo htmlspecialchars($movie -> title); ?>" />
        </a>
    <?php } ?>
    <?php if ($mainXMShowName == 1) { ?>
        <h4>
        <?php if ($movie->thumb == '' || $mainXMShowThumb != 1) { ?>
            <a href="<?php echo $link; ?>">
                <?php echo $movie -> title; ?>
            </a>
        <?php 
        } else {
            echo $movie->title;
        }
        ?>
        </h4>
    <?php } ?>
    <?php if ($mainXMShowDate == 1) {?>
    <div class="movie-date">
        <strong><?php echo JTEXT::_('DATE_ADDED'); ?>:</strong> <?php echo JHTML::Date($movie -> creation_date, 'm-d-Y'); ?>
    </div>
    <?php } ?>
    <?php if ($mainXMShowHits == 1) {?>
    <div class="movie-date">
        <strong><?php echo JTEXT::_('Hits'); ?>:</strong> <?php echo $movie -> hits; ?>
    </div>
    <?php } ?>
    <?php if ($mainXMShowTags) {
		$movie -> tags = new JHelperTags;
		$movie -> tags->getItemTags('com_xmovie.movie' , $movie -> id);
		$movie -> tagLayout = new JLayoutFile('joomla.content.tags');
    ?>
	<div class="movie-tags">
		<strong><?php echo JTEXT::_('TAGS'); ?>:</strong> <?php echo $movie->tagLayout->render($movie->tags->itemTags); ?>
    </div>
	<?php } ?>
</div>
<?php
if ($currRow2 < $mainXMMovPerRow && $itemCount != $movCount) {
    $currRow2++;
} else {
    echo '<div class="clearfix"></div>';
    echo '</div>';
    $currRow2 = 1;
}
$itemCount++;
}
?>

