<?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');
    
class XMovieViewRss extends JView
{
    protected $items;
    protected $cfgParams;
    
    function display($tpl = null) 
    {
        
        $this->items        = $this->get('Items');
        $this->cfgParams     = $this->get('ConfigParams');
        $document =& JFactory::getDocument();
                
        // set feed title
        $document->setTitle($this->cfgParams->rss_title);
        $document->setLink(JRoute::_('index.php?option=com_xmovie&view=main'));
        
        foreach ($this->items as $movie) {
            // create feed item
            $item = new JFeedItem();

            $item->title = $movie->title;
            $imageThumb = parse_url($movie->thumb);
                            
            if (!isset($imageThumb['host']) || $imageThumb['host'] == '') {
                $movString = JURI::base(true)."components/com_xmovie/helpers/img.php?file=".urlencode($movie->thumb)."&t=m";                                                    
            } else {
                $movString = $movie->thumb;                        
            }
            
            $link = JRoute::_("index.php?option=com_xmovie&view=single&catid={$movie->catid}&id={$movie->id}");
            $linkfull = JURI::base(true).$link;
            $item->link = $linkfull;            
            $img = '<img src="'.$movString.'" width="'.$this->cfgParams->cview_mov_width.'" alt="'.htmlspecialchars($movie->title).'" />';
            $thumb = "<a href='{$linkfull}'>{$img}</a>";
            $item->description = $thumb.$movie->quicktake;
            $item->date = date('r', strtotime($movie->creation_date));
            $item->pubDate = time();

            $document->addItem($item);
        }        
    }
}
