Location: PHPKode > projects > Simple Way to Usenet > swun/libs/swun/pages/pg_brwupdate.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_brwupdate extends pg_helper {

	public static $PFEAT= Array();
	public static $AJAX = Array();
	public static $PARG = Array('rpc');
	private $REPO, $NBRID;
		
	public function __construct($pageid=NULL, $args=NULL){ 
		if ( $pageid === NULL OR $args === NULL ){ return; }
		parent::__construct($pageid, $args, self::$PFEAT, self::$AJAX);
	}
	
	public static function getpfeats(){ return self::$PFEAT; }
	
	public function send_header(){
		if ( client::host() !== hellarpcs::get_host($this->args['rpc']) ){
			errors::raise('Invalid host source for a browser update request on RPC '.$this->args['rpc'], CORE_LOG_ALERT, 'PGEN');
		}
		if ( FALSE == hellarpcs::isactif($this->args['rpc']) ){
			errors::raise('RPC is marked inactif, no update possible', CORE_LOG_ALERT, 'PGEN');
		}
		$rpcrepo = hellarpcs::get_destrepo($this->args['rpc']);
		if ( FALSE === $rpcrepo ){ 
			errors::raise('Invalid RPC repo, abording for rpc '.$this->args['rpc'].'', CORE_LOG_ALERT, 'PGEN');
		} 
		$this->REPO = new file_abstract($rpcrepo);
		$err = $this->REPO->connect();
		if ( CORE::isError($err) ){ errors::raise($err->getmsg(), CORE_LOG_ALERT, 'PGEN'); }
		$ct = configs::get('newzbinv2', 'cachetype');
		$c = 'nb_cache_'.$ct;
		$this->NBRID = new $c();
		echo '<!DOCTYPE html 
						PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
						"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
		echo '<html xmlns="http://www.w3.org/1999/xhtml">'."<head></head><body><pre>\n";
	}
	
	public function send_footer(){ echo "</pre></body></html>\n"; }

	public function send_content($pdata){
		ini_set("max_execution_time", 0);
		$time=time();
		$c=0;
		
		while ( FALSE !== ($item = $this->REPO->readdir('/')) ){
			if ( $this->REPO->isdir("/$item") ){
				$catid = array_search($item, search_nzbid::$cats);
				if ( FALSE !==  $catid ){
					$cat = $item;
					while ( FALSE !== ($item = $this->REPO->readdir("/$cat")) ){
						if ( $this->REPO->isdir("/$cat/$item") ){
							echo ">>> /$cat/$item\n";
							$ITEM = new rpcbrw_item($this->args['rpc'], "/$cat/$item", $catid);
							$this->do_item(&$ITEM);
							$c++;
						}
					}
				} else {
					echo ">>> /$item\n";
					$ITEM = new rpcbrw_item($this->args['rpc'], "/$item");
					$this->do_item(&$ITEM);
					$c++;
				}
			}
		}
		hellarpcs::set_lastbrw($this->args['rpc'], $time);
		echo $c." item(s) checked, cleaning.\n";
		hellarpcs::clean_browser($this->args['rpc']);
		echo "done, took ".(time()-$time)."s\n";
		return TRUE;
	}
	
	private function do_item(&$ITEM){
		$h = $ITEM->get_hash();
		$c = $ITEM->get_catid();
		$i = $ITEM->get_id();
		$t = $ITEM->get_title();
		if ( hellarpcs::hash_iscached($this->args['rpc'], $ITEM->get_catid(), $ITEM->get_hash()) ){
			$d = "=== ";
			hellarpcs::update_item(&$ITEM);
		} else {
			$d = "+++ ";
			hellarpcs::insert_item(&$ITEM);
		}
		if ( 'nbrid' == $ITEM->get_engine() ){ $this->NBRID->update_report_date($i); }
		echo "$d [ $h ] [ $c ] [ $i ]\n";
	}
}
Return current item: Simple Way to Usenet