<?php

/**
* @version 2.8.14
* @package Joomla 2.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

defined( '_JEXEC' ) or die( 'Restricted access' );
class DtregisterViewCpanel extends DtrView {
   
   	function display($tpl = null){
			
			parent::display($tpl);
				
	}
	function cpanelbutton( $link, $image, $text, $path='/images/', $target='', $onclick='' ) {
	 	if( $target != '' ) {
	 		$target = 'target="' .$target. '"';
	 	}
	 	if( $onclick != '' ) {
	 		$onclick = 'onclick="' .$onclick. '"';
	 	}
	 	if( $path === null || $path === '' ) {
	 		$path = '/administrator/images/';
	 	}
		?>
		<div style="float:left;">
			<div class="icon">
				<a href="<?php echo $link; ?>" <?php echo $target;?>  <?php echo $onclick;?>>
					<?php echo JHTML::_('image.administrator', $image, $path, NULL, NULL, $text ); ?>
					<span><?php echo $text; ?></span>
				</a>
			</div>
		</div>
		<?php
	}
	
	/**
	 * render News feed from JEvents portal
	 */
	function renderDTNews()
	{
		$cache = JFactory::getCache('DTreg', 'view');
		$cache->setLifeTime(86400);
		
		$cache->setCaching(true);

		$app = JFactory::getApplication();
		if (!isset($app->registeredurlparams))
		{
			$app->registeredurlparams = new stdClass();
		}

		
			$cache->get($this, 'renderDTNewsCached');
	
	}

function renderDTNewsCached()
	{

		$output = '';

		//  get RSS parsed object
		$options = array();
		$options['rssUrl'] = 'http://www.dthdevelopment.com/index.php?option=com_ninjarsssyndicator&feed_id=2&format=raw';
		$options['cache_time'] = 0;

		error_reporting(0);
		ini_set('display_errors',0);

		$rssDoc = JFactory::getFeedParser($options['rssUrl'], $options['cache_time']);

		if ($rssDoc == false)
		{
			$output = JText::_('Error: Feed not retrieved');
		}
		else
		{
// channel header and link
			$title = $rssDoc->get_title();
			$link = $rssDoc->get_link();

			$output = '<table class="adminlist   table table-striped">';
			//$output .= '<tr><th><a href="' . $link . '" target="_blank">' . JText::_($title) . '</th></tr>';

			$items = array_slice($rssDoc->get_items(), 0, 3);
			$numItems = count($items);
			if ($numItems == 0)
			{
				$output .= '<tr><th>' . JText::_('DT_NO_NEWS') . '</th></tr>';
			}
			else
			{
				$k = 0;
				for ($j = 0; $j < $numItems; $j++)
				{
					$item = $items[$j];
					$output .= '<tr><td class="row' . $k . '">';
					$output .= '<a href="' . $item->get_link() . '" target="_blank">' . $item->get_title() . '</a>';
					if ($item->get_description())
					{
						$text = JFilterOutput::stripImages($item->get_description());

							$text = JHtml::_('string.truncate', $text,200);
							$description = str_replace('&apos;', "'", $text);
						
						$output .= '<br />' . $description;
					}
					$output .= '</td></tr>';
					$k = 1 - $k;
				}
			}

			$output .= '</table>';
		}
		// do not return the output because of differences between J15 and J17
		echo $output;

	}

	function renderDTNewsCached_old()
	{

		$output = '';
         $feed = new JFeedFactory;
		 $rssDoc = $feed->getFeed('http://www.npr.org/rss/rss.php?id=1001');
		

		if ($rssDoc == false)
		{
			$output = JText::_('Error: Feed not retrieved');
		}
		else
		{
			
			$title = str_replace(" ", "_", $rssDoc->title);
			$link = $rssDoc->link;

			$output = '<table class="adminlist   table table-striped">';
			$output .= '<tr><th><a href="' . $link . '" target="_blank">' . JText::_($title) . '</th></tr>';

           $items = array();
		   $i= 0;
		   while(1){
		      if($rssDoc->offsetExists($i)){
			  
			     $items[] = $rssDoc->offsetGet($i);
			  }else {
				  break;
				  }
			  
			  $i++;
		   }
			$items = array_slice($items, 0, 3);
			$numItems = count($items);
			if ($numItems == 0)
			{
				$output .= '<tr><th>' . JText::_('DT_NO_NEWS') . '</th></tr>';
			}
			else
			{
				$k = 0;
				for ($j = 0; $j < $numItems; $j++)
				{
					$item = $items[$j];
					$uri  = (!empty($item->uri) || !is_null($item->uri)) ? $item->uri : $item->guid;
			
			        $text = !empty($item->content) ||  !is_null($item->content) ? $item->content : $item->description;

					$output .= '<tr><td class="row' . $k . '">';
					$output .= '<a href="' . $uri . '" target="_blank">' . $item->title. '</a>';
					
					if ($text)
					{
						$text = JFilterOutput::stripImages($text);

							$text = JHtml::_('string.truncate', $text,50);
							$description =  str_replace('&apos;', "'", $text);
						
						  $output .= '<br />' . $description;
					}
					$output .= '</td></tr>';
					$k = 1 - $k;
				}
			}

			$output .= '</table>';
		}
		// do not return the output because of differences between J15 and J17
		echo $output;

	}
   
}
?>