<?php
class rss extends Controller
{
	function rss()
	{
		parent::Controller();
	}

	function index()
	{
		$data['title'] = 'ARCHLine.XP RSS Feed';
        $data['tartalom'] = 'rss/index';
        
        $this->load->model('mevents');
        
        $hirek_lista = array();
        //$hirek_lista = $this->mnews->get_all($this->muser->user['lang'], true, 'fresh');
		$hirek_news = $this->mnews->get_latest(7,$this->muser->user['lang'], true, 'fresh');
		foreach($hirek_news as $hir){
			$hir2 = '';
			
			$datum = $hir->news_y . '-' . $hir->news_m . '-' . $hir->news_d;
			$hir2->datum = date('D, d M Y H:i:s +0200', strtotime($datum));
			$hir2->title = $hir->news_title;
			if( $hir->news_short != "" )
				$hir2->short = $hir->news_short;
			else
				$hir2->short = substr(strip_tags($hir->news_text),0,123);
			if(hun())
			    $hir2->url = "http://www.archline.hu/news/show/" . $hir->news_id;
			elseif(eng())
			    $hir2->url = "http://www.archlinexp.com/news/show/" . $hir->news_id;
			array_push($hirek_lista, $hir2);
		}
		
		$esemenyek = $this->mevents->get_rss($this->muser->user['lang']);
		foreach($esemenyek as $hir){
			$hir2 = '';
			$hir2->datum = date('D, d M Y H:i:s +0200', $hir->datum);
			$hir2->title = $hir->title;
			$hir2->short = substr($hir->short,0,127) . "...";
			/*$hir2->url = "http://www.archlinexp.com/page/show/" . $hir->page;*/
			if( $hir2->title == "Újdonságok 2012" )
				$hir2->url = "http://www.archline.hu/ujdonsagok-2012";
			elseif(hun())
			    $hir2->url = "http://www.archline.hu/page/show/" . $hir->page;
			elseif(eng())
			    $hir2->url = "http://www.archlinexp.com/page/show/" . $hir->page;
			array_push($hirek_lista, $hir2);
		}
		
		// $hirek_lista = array_merge($hirek_news, $esemenyek);
		
		usort( $hirek_lista, "hasonlito" );
		
		$data['hirek_lista'] = $hirek_lista;
		
		$this->load->view('site_rss',$data);
	}
	
}

function hasonlito( $a, $b ){
	if ( strtotime($a->datum) == strtotime($b->datum) )
		return 0;
	if ( strtotime($a->datum) > strtotime($b->datum) )
		return -1;
	return 1;
}

?>