<?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');
jimport('joomla.application.component.view');

if (!class_exists('JViewLegacy')) {
    class_alias('JView', 'JViewLegacy');
}

class XMovieViewCategory extends JViewLegacy
{
    protected $cparams;
    protected $subcat;
    protected $state;
    protected $items;
    protected $active;
    protected $category;
    protected $categories;
    protected $pagination;
    protected $div_width;
    
    public function display($tpl = null) 
    {
        $document = JFactory::getDocument();
                
        $this->cparams         = $this->get('ConfigParams');
        $this->subcat         = $this->get('SubCategories');
        $this->state        = $this->get('State');
        $this->items        = $this->get('Items');
        $this->category        = $this->get('Category');
        $this->active         = $this->get('Active');
        $this->children        = $this->get('Children');
        $this->parent         = $this->get('Parent');
        $this->pagination    = $this->get('Pagination');
        $this->main_itemid    = $this->get('MainItemId');

        $levels = JFactory::getUser()->getAuthorisedViewLevels();
        
        if (!in_array($this->category->access, $levels)) {
            return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
        }
        
        for ($i = 0, $n = count($this->items); $i < $n; $i++) {
            $item = &$this->items[$i];
            $itemid = '';
            
            if (!empty($item->itemId)) {            
                $itemid = "&Itemid={$item->itemId}";
            }
            $item->link = JRoute::_("index.php?option=com_xmovie&view=single&catid={$item->catid}:{$item->catalias}&id={$item->id}:{$item->alias}{$itemid}");
        
            if (isset($item->catido) && $item->catidoa !== '') {
                $item->catalias = $item->catidoa;
            } else {
                $item->catalias = $item->catalias;
            }
            
            $imageThumb = parse_url($item->thumb);
                                
            if (!isset($imageThumb['host']) || $imageThumb['host'] == '') {
                if ($this->cparams->get('resize_thumbs')) {
                    $movString = JURI::base(true). "/components/com_xmovie/helpers/img.php?file=".urlencode($item->thumb)."&t=m";    
                } else {
                    $movString = JURI::base(true). "/" . $this->cparams->get('movie_thumb_path') . "/" . $item->thumb;    
                }
            } else {
                $movString = $item->thumb;                        
            }
            $item->thumb = $movString;
        }
        
        echo json_encode($this->items);
        
    }
}
