Location: PHPKode > projects > Simple Way to Usenet > swun/libs/swun/themes/thm_swun.class.php
<?php
/**
 *  
 * @author  Benjamin Gillissen <hide@address.com>
 * 
 *	**************************************************************

	Copyright (C) 2009  Benjamin Gillissen
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details at:
	http://www.gnu.org/copyleft/gpl.html

 *	**************************************************************
 */
class thm_swun extends thm_helper {
	
	public static $leftblocks = Array(	'realm'=> FALSE,
										'didrate'=>NULL,
										'quicksearch'=>TRUE,
										'searchtree'=>TRUE,
										'did'=>TRUE,
										'nzbupload'=>TRUE,
										'credit'=>NULL
								);
	private static $ajaxcb = Array('swapsearchengine', 'swapsearchtype', 'swapsearchcat', 'storeblockvis', 'didenqueue', 'n_enqueue','n_upload', 'freerateslot', 'tt_didrate');
	private static $tfeats = Array('mediaq', 'nfo', 'imdb', 'nzbdload', 'savedadv', 'savedgrp', 'leftmenu', 'debug', 'ajaxupload', 'ajax');
	private $theme 	= 'swun';			//theme object name
	private $parser, $RDB;
	private static $quickey, $rpc, $REALM;
	
	public function __construct(){ 
		if ( FALSE === @constant('CORE_AUTH') ){ unset(self::$leftblocks['realm']); }
		thm_mediaq::append_js_file('rate_countdown');
		thm_mediaq::append_js_file('tooltip_didrate');
		$pagerealm = pages::get_realm(browsing::get_active());
		$c=0;
		if ( !empty($pagerealm) ){
			$realm = new realm($pagerealm);
			foreach(self::$leftblocks as $block => $dftvis ){
				if ( $realm->checks('leftmenu', 'read', $block) ){
					thm_blockvis::append_block($block, 'leftmenu', "thm_swun::gen_$block", $dftvis);					
					$c++;
				}
			}
		}
		if ( $c==0 ){ thm_blockvis::append_block('credit', 'leftmenu', "thm_swun::gen_credit", TRUE); }
		if ( !isset(self::$REALM) ){ self::$REALM = new realm('gnutopya'); }
		parent::__construct(self::$tfeats, self::$ajaxcb);
	}
	//DEPREC
	public function special_events(){
		
	}
	
	public function send_header(&$data){
		thm_mediaq::append_css_file('style');
		thm_mediaq::append_js_file('d_enqueue');
		thm_mediaq::append_js_file('n_enqueue');
		$tpl = new template();
		$tpl->output_function('langs::output_for_client');
		if ( FALSE === $tpl->load_file('layout/header.tpl') ){ return FALSE; }
		sessions::start('profile');
		if ( isset($data['rpc']) ){ 
			self::$rpc = $data['rpc'];
		} elseif ( sessions::isdefined('lastrpc', 'profile') ){
			self::$rpc = sessions::read('lastrpc', 'profile');
		} else {
			self::$rpc = hellarpcs::getfirst();
		}
		/*
		$this->process_delayed();
		if ( $this->POST_common() ){
			if ( $_POST['enqmethod'] == 'did'){
				$this->did_enqueue();
			} elseif ( $_POST['enqmethod'] == 'upl' ){
				$this->nzb_upload();
			} elseif ( $_POST['enqmethod'] == 'search' ){
				$this->search_enqueue();
			} elseif ( $_POST['enqmethod'] == 'genzb' ){
				$this->nzb_gen();
			} else {
				pagegen::add_event("Unknow Enqueue method, action cancelled");
			}
			sessions::del('quickey', 'profile'); //we use a quickey only once
		}
		if ( ! sessions::isdefined('quickey', 'profile') ){ 
			self::$quickey = CORE::hash(NULL, 10);
			sessions::set('quickey', self::$quickey, 'profile');
		} else {
			self::$quickey = sessions::read('quickey', 'profile');
		}
		*/
		$tpl->setdata( $this->common_header_data() );
		$tpl->appendata($data['title'], 'title');
		unset($data);
		$tpl->appendata(browsing::topmenu_bydepth( browsing::get_active() ), 'topmenu');
		$tpl->parse();
		unset($tpl);
		return TRUE;
	}
	
	private function process_delayed(){
		//NZB RATE / DELAYED HANDLER
		/*
		if ( isset($_GET['remdelay']) ){ return; }
		nzbrate::cleanup();				
		if ( nzbrate::q_count() == 0 ){ return; }
		$r=TRUE;
		while( FALSE !== ( $id = nzbrate::q_list() ) ){
			if ( TRUE === nzbrate::gotfree_slot() AND TRUE === $r ){
				$slot = unserialize(base64_decode($id));
				if ( FALSE === $slot ){
					 
					pagegen::add_event("Slot queue data restore failed, item droped !");
					nzbrate::q_del($id);
					 
				} elseif ( $slot['type'] == 'enqueue') {
					
					pagegen::add_event("Enqueueing delayed item nbrid:".$slot['data'][1]." on RPC ".$slot['data'][0]);
					if ( isset($_POST['rpc']) ){ $tmp = $_POST['rpc']; }
					$_POST['rpc'] = $slot['data'][0]; 
					nzbrate::q_del($id);
					$r = $this->enqueue('nbrid', $slot['data'][1]);
					if ( isset($tmp) ){ $_POST['rpc'] = $tmp; } else { unset($_POST['rpc']); }
					
				} elseif ( $slot['type'] == 'report' ){
					
					pagegen::add_event("Fetching reported NZB : [".$slot['data']['cat']."] ".htmlentities($slot['data']['title']));
					nzbrate::q_del($id);
					nzbrate::add_slot('Report');
					$nzb = nb_fetch::get_nzb(NULL, $slot['data']['fileids']);
					if ( FALSE === $nzb ){ 
						pagegen::add_event("Fetch of Reported NZB failed, item has been redelayed !");
						nzbrate::q_add($id);break; 
					}
					$rpc=NULL;
					if ( isset($slot['data']['rpc']) ){ $rpc = $slot['data']['rpc']; }
					$this->import($nzb, $slot['data']['title'], $slot['data']['cat']);
					
				} else {
					pagegen::add_event("Unknow delayed type, item droped !");
					nzbrate::q_del($id);
				}
			}
		}
		*/
	}
	
	private function POST_common(){
		if ( !isset($_POST['quick_enqueue']) 
			AND !isset($_POST['quick_upload']) 
			AND !isset($_POST['search_enqueue'])
			AND !isset($_POST['genzb']) AND !isset($_POST['unfid_import']) AND !isset($_POST['unfid_enqueue'])
			AND !isset($_POST['del_nzb']) ){ return FALSE; }
		//checking formkey, to prevent double post.
		if ( ! isset($_POST['formkey']) OR ! sessions::isdefined('quickey', 'profile') ){
			pagegen::add_event('Missing Quick Enqueue argument : formkey, wrong template ?, action cancelled');
			return FALSE;
		}
		if ( $_POST['formkey'] != sessions::read('quickey', 'profile') ){
			pagegen::add_event('Wrong Action argument : formkey do not match, page refresh?, action cancelled');
			errors::raise('Wrong Quick Enqueue argument : formkey, refresh on post request ?, post action cancelled', CORE_LOG_DEBUG, 'PGEN');	
			return FALSE;
		}
		if ( isset($_POST['rpc']) AND FALSE !== @constant('CORE_AUTH') ){
			if ( self::$REALM->checks('rpc', 'list', $RRef) AND FALSE !== self::$REALM->checks('rpc', 'enqueue', $RRef) ){
				pagegen::add_event('No enough rights to take action on that RPC, action cancelled');
				errors::raise('No enough rights to take action on that RPC, action cancelled', CORE_LOG_DEBUG, 'PGEN');	
				return FALSE;
			}
		}
		return TRUE;
	}
	
	private function did_enqueue(){	
		//for full urls
		if ( ereg('fetchthat', $_POST['did']['val']) ){
			$buf = split("/", $_POST['did']['val']);
			$_POST['did']['val'] = $buf[count($buf)-1];		// -- .../.../.../$rid					
			$_POST['did']['type'] = 'ftrid';
			unset($buf);
		} elseif( ereg('newzbin', $_POST['did']['val']) ){
			$buf = split("/", $_POST['did']['val']);
			$_POST['did']['val'] = $buf[count($buf)-2];		// -- .../.../.../$rid/
			$_POST['did']['type'] = 'nbrid';
			unset($buf);
		}
		if ( $_POST['did']['type'] != 'nbrid' AND $_POST['did']['type'] != 'ftrid' AND $_POST['did']['type'] != 'nzbid' ){
			pagegen::add_event('Invalid ID Type : '.$_POST['did']['type'].' action cancelled');
			return;
		}
		sessions::set('lastrpc', $_POST['rpc'], 'profile');
		$this->enqueue($_POST['did']['type'], trim($_POST['did']['val']) );
	}
	
	private function nzb_gen(){
		if ( isset($_POST['genzb']) ){
			//DIRECT NZB OUTPUT
			if ( FALSE === nzbrate::gotfree_slot() ){
				pagegen::add_event('NZB Generation failed : no free DirectID slot available.');
				return;	
			} elseif (!isset($_POST['selection']) OR count($_POST['selection']) < 1 ){
				pagegen::add_event('NZB Generation aborded : no item selected');
				return;	
			} else {
				
				$id = md5(serialize($_POST['selection']));
				nzbrate::add_slot('Generate');
				$nzb = nb_fetch::get_nzb(NULL, $_POST['selection']);
				if ( FALSE === $nzb ){ 
					pagegen::add_event("NZB Generation Failed !");
					return; 
				}
				header('Content-type: text/xml; charset="ISO-8859-1"');
				header('Content-Disposition: attachment; filename="'.urlencode(time()."_$id.nzb").'"');
				echo file_get_contents($nzb);
				unlink($nzb);
				exit;
			}
			
		} elseif (!isset($_POST['selection']) OR count($_POST['selection']) < 1 ){
			pagegen::add_event('NZB Import aborded : no item selected');
			return;	
		} else {
			//NZB IMPORT / ENQUEUE			
			$slot['type'] = 'report';
			$slot['data']['title'] = stripslashes($_POST['title']);
			$slot['data']['cat'] = $_POST['cat'];
			$slot['data']['fileids'] = $_POST['selection'];
			if ( isset($_POST['unfid_enqueue']) ){ $slot['data']['rpc'] = $_POST['rpc']; }
			$id = base64_encode(serialize($slot));
			if ( TRUE === nzbrate::gotfree_slot() ){
				nzbrate::add_slot('Report');
				$nzb = nb_fetch::get_nzb(NULL, $slot['data']['fileids']);
				if ( FALSE === $nzb ){ 
					pagegen::add_event("Fetch of Reported NZB failed, item has been redelayed !");
					nzbrate::q_add($id);
					return; 
				}
				$rpc = NULL;
				if ( isset($_POST['unfid_enqueue']) ){ $rpc = $_POST['rpc']; }
				$this->import($nzb, $slot['data']['title'], $slot['data']['cat'], $rpc);
			} elseif ( FALSE !== nzbrate::q_add($id) ){
				pagegen::add_event('NZB import has been delayed.');
			} else {
				pagegen::add_event('NZB could not be delayed !');
			}
			
		}
	}
	
	private function nzb_upload(){	
		$repo = new file_abstract('NZB');
		$_FILES['nzb']['name'] = stripslashes($_FILES['nzb']['name']);
		//$uplcats = ;
		if ( $_FILES['nzb']['error'] ){
			pagegen::add_event('NZB Upload Failed, to big ?');
		} elseif ( FALSE === nzb::isnzb($_FILES['nzb']['tmp_name']) ){
			pagegen::add_event('Uploaded file is not an NZB !');
		} elseif ( !isset($_POST['nzbcatid']) ){
			pagegen::add_event('Missing NZB category, expected as $_POST[nzbcatid] !');
		} elseif ( !isset(search_nzbid::$cats[$_POST['nzbcatid']]) ){
			pagegen::add_event('Invalid NZB category !');
		} else {
			$rpc=NULL;
			if ( isset($_POST['quick_enqueue']) ){ $rpc = $_POST['rpc']; }
			$this->import($_FILES['nzb']['tmp_name'], str_replace('.nzb', '', $_FILES['nzb']['name']), $_POST['nzbcatid'], $rpc);
		}
	}
	
	private function search_enqueue(){
		if ( !isset($_POST['search_enqueue']) AND !isset($_POST['del_nzb']) ){ return; }
		if ( !is_array($_POST['selection']) ){ 
			pagegen::add_event('No item were selected, action aborded.');
			return; 
		}
		if ( isset($_POST['del_nzb']) AND $_POST['engine'] == 'nzbid' ){
			$nzdb = new nzbdb();
			$repo = new file_abstract('NZB');
			foreach($_POST['selection'] as $k => $id){ 
				if ( !empty($id) ){
					$nzb = $nzdb->get_infos($id);
					if ( $repo->isfile('/'.$nzb['file']) ){ $repo->remove('/'.$nzb['file'], FALSE); }
					$nzdb->remove_nzb($id);
					pagegen::add_event("NZB $id has been removed.");
				}
			}
			
		} elseif ( $_POST['engine'] == 'nbrid' OR $_POST['engine'] == 'nzbid' ){
			pagegen::add_event('Enqueuing '.count($_POST['selection']).' Items.');
			sessions::set('lastrpc', $_POST['rpc'], 'profile');
			foreach($_POST['selection'] as $k => $id){ $this->enqueue($_POST['engine'], $id); }
			
		}
	}
	
	private function enqueue($type, $id){
		if ( !isset($_POST['rpc']) ){
			pagegen::add_event('Missing argument : RPCRef, enqueue aborded. Check your template! ');
			return FALSE;
		}
		$rpcs = hellarpcs::listall();
		if ( FALSE === array_search($_POST['rpc'], $rpcs) ){
			pagegen::add_event('Invalid argument : RPCRef, enqueue aborded.');
			return FALSE;
		}
		//hmm realm acl ?
		$id = trim($id);
		if ( empty($id) ){
			pagegen::add_event('Invalid argument : DID is empty, enqueue aborded.');
			return FALSE;
		}
		if ( $type === 'nbrid' AND FALSE === nzbrate::gotfree_slot() ){
			$data['type'] = 'enqueue';
			$data['data'] = Array($_POST['rpc'], $id);
			$slot = base64_encode(serialize($data));
			if ( FALSE === nzbrate::q_add($slot) ){
				pagegen::add_event($id.' could not be added to delayed list, enqueue failed.');
			} else {
				pagegen::add_event($id.' has been delayed, maximun nzb rate reached.');
			}
			return FALSE;
		}
		$did = hellarpcs::gendid($type, $id);
		hellarpcs::load($_POST['rpc'], 0);
		if ( FALSE === hellarpcs::enqueue($_POST['rpc'], $did) ){
			pagegen::add_event($did.' could not be enqueued on rpc '.$_POST['rpc']);
			if ( $type === 'nbrid' ){
				$data['type'] = 'enqueue';
				$data['data'] = Array($_POST['rpc'], $id);
				$slot = base64_encode(serialize($data));
				if ( FALSE === nzbrate::q_add($slot) ){
					pagegen::add_event($id.' could not be added to delayed list, enqueue failed.');
					return FALSE;
				}
				pagegen::add_event($id.' has been delayed.');
				return FALSE;
			}
			return FALSE;
		} elseif ( $type === 'nbrid' ){
			$slot = base64_encode(serialize(Array($_POST['rpc'], $id)));
			if ( FALSE === nzbrate::add_slot('Enqueue') ){
				pagegen::add_event('Slock Locking Failed !');
				return FALSE;
			}
		} 
		pagegen::add_event($did.' has been enqueued on rpc '.$_POST['rpc']);
		return TRUE;
	}
	
	private function import($src, $title, $cat, $rpc=NULL){
		$repo = new file_abstract('NZB');
		$db = new nzbdb();
		if ( FALSE === $repo->connect() ){
			pagegen::add_event('Could not connect to NZB file repository, plz contact an admin.');
			$r=FALSE;
		} elseif ( $repo->isfile('/'.$title.'.nzb') ){
			pagegen::add_event('A File with that name already exists in NZB database, plz rename it and try again.');
			$r=FALSE;
		} elseif ( FALSE === nzb::isnzb($src) ){
			pagegen::add_event('File "'.$title.'.nzb" is not a valid nzb file.');
			$r=FALSE;
		} elseif ( FALSE === $repo->move(NULL, $src, 'NZB', '/'.$title.'.nzb') ){
			pagegen::add_event('NZB File "'.$title.'" could not be imported to collection folder');
			$r=FALSE;
		} elseif( FALSE === $db->import_nzb($title.'.nzb', $cat) ){
			$repo->remove('/'.$title.'.nzb', FALSE);
			pagegen::add_event('NZB File "'.$title.'" could not be imported to nzb database');
			$r=FALSE;
		} else {
			$nzbid = $db->get_idbyfile($title.'.nzb');
			pagegen::add_event('NZB File '.$title.' has been imported to nzbdb as nzbid "'.$nzbid.'" with category '.search_nzbid::$cats[$cat]);
			$r=TRUE;
			if ( $rpc !== NULL ){
				if ( isset($_POST['rpc']) ){ $tmp = $_POST['rpc']; }
				$_POST['rpc'] = $rpc;
				$r = $this->enqueue('nzbid', $nzbid);
				if ( isset($tmp) ){ $_POST['rpc'] = $tmp; }
			}
		}
		return $r;
	}
	
	public function send_content(&$content){
		@define('THEME_CONTENT_ISSENT', TRUE);
		echo langs::recode_for_client( $content );
	}
	
	public function send_footer(&$data){
		$tpl = new template();
		$tpl->output_function('langs::output_for_client');
		if ( FALSE === $tpl->load_file('layout/footer.tpl') ){ return FALSE; }
		$tpl->setdata( $this->common_footer_data() );
		$tpl->parse();
		unset($tpl);
		sessions::store('profile');
		return TRUE;
	}
	

//-----------------------------------------------------------  Leftmenu BLOCKVIS GEN	
	public static function gen_didrate($of=FALSE){ 
		$tpl = new template();
		if ($of !== FALSE ){ $tpl->output_function($of); }
		if ( FALSE === $tpl->load_file('leftmenu/didrate.tpl') ){ return FALSE; }
		$data = hellarpcs::list_slot();
		for($i=4;$i>=0;$i--){
			if ( !isset($data[$i]) ){
				$buf['nbslots'][$i] = Array('why'=>'-','freein'=>'-');
			} else {
				$buf['nbslots'][$i] = $data[$i];
			}
			$buf['nbslots'][$i]['unic'] = CORE::hash(NULL, 5);
		}
		$tpl->setdata( $buf );
		$o = $tpl->parse(($of === FALSE )); 
		unset($tpl);
		return $o;
	}
	
	public static function gen_quicksearch($of=FALSE){ 
		$tpl = new template();
		if ($of !== FALSE ){ $tpl->output_function($of); }
		if ( FALSE === $tpl->load_file('leftmenu/quicksearch.tpl') ){ return FALSE; }
		$args=Array();
		if ( browsing::get_active() == '2') { $args = browsing::getargs(); }
		$s = new search($args);
		$tpl->setdata( $s->get_searchbar() );
		unset($s);
		$o = $tpl->parse(($of === FALSE )); 
		unset($tpl);
		return $o;
	}

	public static function gen_nbcats($of=FALSE){
		$tpl = new template();
		if ($of !== FALSE ){ $tpl->output_function($of); }
		if ( FALSE === $tpl->load_file('leftmenu/nbcats.tpl') ){ return FALSE; }
		while( FALSE !== ( $nbcat = self::fetch_nbmenuroot() ) ){
			$tpl->setdata( $nbcat );
			$o = $tpl->parse(($of === FALSE )); 
			if ( $of === FALSE ){ $o .= $o;}
		}
		return $o;		
	}
	
	public static function gen_searchtree($of=FALSE){
		$tpl = new template();
		if ($of !== FALSE ){ $tpl->output_function($of); }
		if ( FALSE === $tpl->load_file('leftmenu/searchtree.tpl') ){ return FALSE; }
		while( FALSE !== ( $nbcat = self::fetch_nbmenurootv2() ) ){
			$tpl->setdata( $nbcat );
			$o = $tpl->parse(($of === FALSE )); 
			if ( $of === FALSE ){ $o .= $o;}
		}
		return $o;		
	}
	
	public static function gen_did($of=FALSE){ 
		$tpl = new template();
		if ($of !== FALSE ){ $tpl->output_function($of); }
		if ( FALSE === $tpl->load_file('leftmenu/did.tpl') ){ return FALSE; }
		$data = self::get_multirpcdata();
		$data['quickey'] = self::$quickey;
		$data['rpc'] = self::$rpc;
		$tpl->setdata( $data );
		unset($data);
		$o = $tpl->parse(($of === FALSE )); 
		unset($tpl);
		return $o;
	}
	
	public static function gen_nzbupload($of=FALSE){ 
		$tpl = new template();
		if ($of !== FALSE ){ $tpl->output_function($of); }
		if ( FALSE === $tpl->load_file('leftmenu/nzbupload.tpl') ){ return FALSE; }
		$data = self::get_multirpcdata();
		$data['uplcats'] = search_nzbid::$cats;
		foreach($data['uplcats'] as $k => &$cat){ $cat = langs::dico_translate("cat_$cat", NULL, "search"); }
		$data['quickey'] = self::$quickey;
		$data['maxsize'] = ini_get('upload_max_filesize');
		$tpl->setdata( $data );
		unset($data);
		$o = $tpl->parse(($of === FALSE )); 
		unset($tpl);
		return $o;
	}
	
	private static function get_multirpcdata(){
		$rpcs = hellarpcs::listall();
		foreach($rpcs as $k => &$RRef ){
			if ( FALSE !== self::$REALM->checks('rpc', 'list', $RRef) ){
				$tmp['enabled'] = ( self::$REALM->checks('rpc', 'use', $RRef) AND 0 != hellarpcs::isactif($RRef) );
				$tmp['rpc'] =  hellarpcs::getname($RRef);
				$data['rpcs'][$RRef] = $tmp;
				unset($tmp);
			}
		}
		$data['inuse'] = isset($data['rpcs']);
		if ( FALSE === $data['inuse'] ){ return $data; }
		$data['multirpc'] = ( 1 < count($data['rpcs']) );
		$data['activerpc'] = self::$rpc;
		return $data;
	}
	
	public static function gen_credit($of=FALSE){
		$tpl = new template();
		if ($of !== FALSE ){ $tpl->output_function($of); }
		if ( FALSE === $tpl->load_file('leftmenu/credits.tpl') ){ return FALSE; }
		$tpl->setdata( Array() );
		$o = $tpl->parse(($of === FALSE )); 
		unset($tpl);
		return $o;
	}

	public static function gen_realm($of=FALSE){
		$tpl = new template();
		if ($of !== FALSE ){ $tpl->output_function($of); }
		if ( FALSE === $tpl->load_file('leftmenu/realm.tpl') ){ return FALSE; }
		$pagerealm = pages::get_realm(browsing::get_active());
		if ( !empty($pagerealm) ){
			$o['realm']=$pagerealm;
			$realm = new realm($pagerealm);
			$o['isloged'] = ( TRUE === $realm->authenticate() );
			$o['logedas'] = $realm->logedas();
			$o['login'] = $realm->loginbyuid($o['logedas']);
			$buf = $realm->logedpassive();
			if ( is_array($buf) ){
				foreach($buf as $k => $ruid){ $o['passive'][$ruid] = $realm->loginbyuid($ruid);	}
			}
			if ( !isset($o['passive']) ){ $o['passive'] = FALSE; }
			unset($buf);
		}
		$tpl->setdata( $o );
		unset($o);
		$o = $tpl->parse(($of === FALSE )); 
		unset($tpl);
		return $o;

	}
//-----------------------------------------------------------  Leftmenu BLOCKVIS GEN

	
	
//-----------------------------------------------------------  XML SearchTree	
	
	private static function fetch_nbmenurootv2(){
		
		static $XML;
		if ( !isset($XML) ){
			$p = CORE::getdeps(PATH_OPTS, 'search_tree', NULL, NULL, 'xml');
			if ( FALSE === $p ){
				errors::raise('Missing Config File : Leftmenu Search Tree, search_tree.xml', CORE_LOG_ERROR, 'PGEN'); 
				return FALSE;
			}
			$XML = new XMLReader();
			if ( FALSE === $XML->open( $p ) ){ unset($XML);return FALSE; }
			$XML->setParserProperty(XMLReader::LOADDTD,  FALSE);
			$XML->setParserProperty(XMLReader::VALIDATE, FALSE); 
		}
		while( $XML->read() ) {
			if ( $XML->nodeType == 1 AND $XML->depth == 1 ){ 
				$o['engine'] = $XML->getAttribute('eng');
				$o['type'] = $XML->getAttribute('type');
				$o['cat'] = $XML->getAttribute('cat');
				$o['id'] = md5($o['engine'].':'.$o['type'].':'.$o['cat']);
				$o['dsp'] = $XML->getAttribute('dsp');
				$o['lang'] = $XML->getAttribute('lang');
				if ( !empty($o['lang']) ){ $o['dsp'] = langs::dico_translate($o['lang'], NULL, 'search'); }
				$o['img'] = $XML->getAttribute('img');
				$o['sub'] = self::get_nbmenusubv2(&$XML);
				$o['open'] = thm_blockvis::blockisopen('leftmenu', 'st'.$o['id']);
				if ( $o['open'] ){ $o['open']  = 'open'; } else { $o['open'] = 'close'; }
			}
			if ( isset($o) ){ break; }
		}
		if ( !isset($o) ){  unset($XML);return FALSE; }
		return $o;
	}
	
	private static function get_nbmenusubv2(&$XML){
		$mindepth = $XML->depth;
		while( $XML->read() ) {
			if ( $XML->depth <= $mindepth ){ break; }
			if ( $XML->nodeType == 1 AND $XML->depth == ($mindepth+1) ){
				$b['engine'] = $XML->getAttribute('eng');
				$b['type'] = $XML->getAttribute('type');
				$b['cat'] = $XML->getAttribute('cat');
				$b['dsp'] = $XML->getAttribute('dsp');
				$b['lang'] = $XML->getAttribute('lang');
				$b['img'] = $XML->getAttribute('img');
				$b['id'] = md5($b['engine'].':'.$b['type'].':'.$b['cat']);
				$b['open'] = thm_blockvis::blockisopen('leftmenu', 'st'.$b['id']);
				if ( $b['open'] ){ $b['open']  = 'open'; } else { $b['open'] = 'close'; }
				$b['sub'] = self::get_nbmenusubv2(&$XML);
				if ( $b['cat'] == '*' ){
					if ( empty($b['engine']) ){
						errors::raise('SeachTree : Autogen call is missing engine attribut', CORE_LOG_WARNING, 'PGEN');
					} elseif ( $b['engine'] == 'nzbid'){
						if ( $b['type'] != 1 ){
							errors::raise('SeachTree : Autogen for nzbid only support type 1', CORE_LOG_WARNING, 'PGEN');
						} else {
							$subs = search_nzbid::$cats;
							foreach($subs as $cat => &$name ){
								$c = $b;
								if ( !empty($c['lang']) ){ 
									$c['lang'] = str_replace('%dsp%', $name, $c['lang']);
									$c['dsp'] = langs::dico_translate($c['lang'], NULL, 'search'); 
								} else {
									$c['dsp'] = $name;
								}
								$c['cat'] = $cat;
								$c['img'] = str_replace('%dsp%', $name, $c['img']);
								$o[] = $c;
							}
						}
					} elseif ( $b['engine'] == 'nbrid'){
						if ( $b['type'] == 1 ){	//adv
							$prof = new profile('site_profile');
							$subs = $prof->read('savedadv');
							unset($prof);
						} elseif ( $b['type'] == 2 ){	//cats
							$subs = configs::get('newzbinv2', 'cats');
						} elseif ( $b['type'] == 3 ){	//gl
							$subs = configs::get('newzbinv2', 'grouplist');
						} elseif ( $b['type'] == 4 ){	//subcats
							$subs = configs::get('newzbinv2', 'subcats');
						} elseif ( $b['type'] == 5 ){	//my groups
							$prof = new profile('site_profile');
							$subs = $prof->read('savedgrp');
							unset($prof);
						}
						if ( is_array($subs) ){
							foreach($subs as $cat => &$data ){
								$c = $b;
								if ( !empty($c['lang']) ){ 
									$c['lang'] = str_replace('%dsp%', $data['name'], $c['lang']);
									$c['dsp'] = langs::dico_translate($c['lang'], NULL, 'search'); 
								} else {
									$c['dsp'] = $data['name'];
								}
								$c['cat'] = $cat;
								$c['img'] = str_replace('%dsp%', $data['name'], $c['img']);
								$o[] = $c;
							}
						}
					} elseif ( $b['engine'] == 'unfid'){
						if ( $b['type'] == 1 ){	//cats
							$subs = configs::get('newzbinv2', 'cats');
						} elseif ( $b['type'] == 2 ){	//my groups
							$prof = new profile('site_profile');
							$subs = $prof->read('savedgrp');
							unset($prof);
						}
						if ( is_array($subs) ){
							foreach($subs as $cat => &$data ){
								$c = $b;
								if ( !empty($c['lang']) ){ 
									$c['lang'] = str_replace('%dsp%', $data['name'], $c['lang']);
									$c['dsp'] = langs::dico_translate($c['lang'], NULL, 'search'); 
								} else {
									$c['dsp'] = $data['name'];
								}
								$c['cat'] = $cat;
								$c['img'] = str_replace('%dsp%', $data['name'], $c['img']);
								$o[] = $c;
							}
						}
						
					} 
				} else {
					if ( !empty($b['lang']) ){ $b['dsp'] = langs::dico_translate($b['lang'], NULL, 'search'); }
					$b['img'] = str_replace('%dsp%', $b['dsp'], $b['img']);
					$o[] = $b;	
				}
				
			}
		}
		if ( isset($o) ){ return $o; }
		return FALSE;
	}
//-----------------------------------------------------------  XML SearchTree
}
return TRUE;
Return current item: Simple Way to Usenet