Location: PHPKode > projects > Simple Way to Usenet > swun/libs/swun/pages/pg_search.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 pg_search extends pg_helper {
	
	public static $PFEAT= Array('resultbp' => Array('nbrid' => '100:25',
													'nzbid' => '100:25',
													'unfid' => '2000:75'),
								'tooltip' => NULL );
	public static $AJAX = Array('tt_imdb', 'unfidimport', 'deluplnzb');
	public static $PARG = Array('engine', 'type', 'cat', 'filter');	

	private $SEARCH;
	
	public static function getpfeats(){ return self::$PFEAT; }
	
	public function __construct($pageid=NULL, $args=NULL){ 
		if ( $pageid === NULL OR $args === NULL ){ return; }
		$this->SEARCH = new search($args);
		if ( $this->SEARCH->get_engine() === 'nbrid' ){
			self::$AJAX[] = 'didenqueue';
		}
		parent::__construct($pageid, $args, self::$PFEAT, self::$AJAX);
	}
	
	public function send_header(){
		$js = Array('set_blockvis','swap_destrpc','swap_itemsel','tooltip_imdb','tooltip_nfo','swap_itemsel', 'search_selector', 's_enqueue', 'unfid_import', 'deluplnzb');
		foreach($js as &$f ){ thm_mediaq::append_js_file($f); }
		unset($js, $f);
		$hdata['title'] = $this->SEARCH->get_engname($this->SEARCH->get_engine());
		return themes::send_header($hdata);
	}

	public function send_footer(){ return themes::send_footer(); }

	public function send_content($pdata){
		ob_start();
		$tpl = new template();
		$tpl->output_function('langs::output_for_client');
		if ( FALSE === $tpl->load_file('pages/search/pg_search.tpl') ){ return FALSE; }
		$data['engine'] = $this->SEARCH->get_engine();
		$rpcs = hellarpcs::listall();
		$REALM = new realm('gnutopya');
		foreach($rpcs as $k => &$RRef ){
			if ( FALSE !== $REALM->checks('rpc', 'list', $RRef) ){
				$tmp['enabled'] = ( $REALM->checks('rpc', 'use', $RRef) AND 0 != hellarpcs::isactif($RRef) );
				$tmp['rpc'] =  hellarpcs::getname($RRef);
				$data['rpcs'][$RRef] = $tmp;
				unset($tmp);
			}
		}
		unset($rpcs, $REALM);
		$data['multirpc'] = ( 1 < count($data['rpcs']) );
		if ( sessions::isdefined('lastrpc', 'profile') ){
			$data['activerpc'] = sessions::read('lastrpc', 'profile');
		} else {
			$tmp = array_keys($data['rpcs']);
			$data['activerpc'] = $tmp[0];
		}
		if ( $data['engine'] == 'unfid' ){
			$tmp = $data;
			$data['unfid_data'] = $tmp;unset($tmp);
			$data['unfid_data']['cats'] = $this->SEARCH->get_cats(1);
		}
		$data['formkey'] = sessions::read('quickey', 'profile');
		
		$ref = $this->SEARCH->send();
		//Paged stuff
		if ( !isset($_GET['page']) OR @$_GET['page'] == 0 ){ $_GET['page'] = 1; }
		$bp=pfeat_resultbp::get_client_conf($data['engine']);
		$data['paged'] = $this->handle_paged($bp, $this->SEARCH->count_result($ref), $_GET['page']);
		$tpl->setdata($data);
		$tpl->parse_before('items');
		$c=0;
		while ( $item = $this->SEARCH->fetch($ref, $data['paged']['start'], $data['paged']['end']) ){
			$item['title'] = htmlspecialchars($item['title'], ENT_QUOTES);
			$item['idisdload'] 	= Array();
			$item['idisinq'] 	= Array();
			$item['idisdel'] 	= Array();
			$item['idisproc'] 	= Array();
			$item['idonrpcs'] 	= Array();
			if ( $data['engine'] == 'nzbid' OR $data['engine'] == "nbrid" ){
				foreach($data['rpcs'] as $rref => &$rpc){
					if ( hellarpcs::idisdloading($rref, $data['engine'], $item['id']) ){
						$item['idisdload'][$rref] = $rpc;
					}
					if ( hellarpcs::idisqueued($rref, $data['engine'], $item['id']) ){
						$item['idisinq'][$rref] = $rpc;
					}
					if ( hellarpcs::idisdelayed($rref, $data['engine'], $item['id']) ){
						$item['idisdel'][$rref] = $rpc;
					}
					if ( hellarpcs::idisprocessing($rref, $data['engine'], $item['id']) ){
						$item['idisproc'][$rref] = $rpc;
					}
					if ( hellarpcs::idisonrpc($rref, $data['engine'], $item['id']) ){
						$item['idonrpcs'][$rpc] = hellarpcs::get_repobaseurl($rref)."/".$item['category']."/".rawurlencode($item['title']);
					}
				}
			}
			if ( isset($item['category']) ){
				$item['category'] = htmlspecialchars($item['category'], ENT_QUOTES);
			}
			$item['detail'] = 'open';
			$tpl->parse_once('items', $item, $c);
			$c++;
		}
		$tpl->appendata(($c ==0), 'showempty');
		$tpl->parse_after('items');
		ob_end_flush();
		return TRUE;
	}

}
Return current item: Simple Way to Usenet