Location: PHPKode > projects > Simple Way to Usenet > swun/scripts/rpcbrw_update.php
<?php
//chdir to script folder to keep relative path compatibility
$buf = pathinfo($_SERVER['SCRIPT_FILENAME']);
chdir($buf['dirname']);
unset($buf);

//Site title 
define('SITE_TITLE',			'Simple Way To Usenet');
//dunno if it's possible but anyway let's try something just in case ;)
if ( ! defined('PATH_SEPARATOR') ){
	if ( ereg(';', ini_get('include_path')) ){
		define('PATH_SEPARATOR', ';');
	} else {
		define('PATH_SEPARATOR', ':');
	}
}
//path to folder containing this option set.
define('PATH_OPTS',				implode(PATH_SEPARATOR, Array('../config')));
//path that contains files with db objects structure.
define('PATH_CNF',				implode(PATH_SEPARATOR, Array('../config/CNF')));
//path to librairies.
define('PATH_LIBS',				implode(PATH_SEPARATOR, Array('../libs/core', '../libs/swun/')));
//a writable path, best if reserved to this
define('PATH_CACHE',			'../cache');
//path to temp folder, if defined will overwrite system temp folder
define('PATH_TMP',				PATH_CACHE.'/tmp');
//used in libs
define('CORE_CONTEXT',			'swun-rpcbrw');
//PHP ERROR REDIRECTION 
define('REDIRECT_PHP_ERRORS',	TRUE);
//PEAR ERROR REDIRECTION, require PEARS folder in include path. 
define('REDIRECT_PEAR_ERRORS',	FALSE);
//do we hidde events prefixed with the error suppression directive "@"
define('FOLLOW_ERROR_DIRECTIVE',TRUE);
//do we use core auth engine ?
define('CORE_AUTH',TRUE);

//Include of the main configuration file
//and we try to load the CORE.
$icp = ini_get('include_path');
ini_set('include_path', PATH_LIBS);
if ( ! include('CORE.class.php') ){ die('Missing CORE Librairie, plz check the value of PATH_LIBS in this file !'); }
if ( ! include('misc/chrono.class.php') ){ die('Missing Chrono Librairie, plz check the value of PATH_LIBS in this file !'); }

$RPC=$argv[1];
$rpcrepo = hellarpcs::get_destrepo($RPC);
if ( FALSE === $rpcrepo ){ exit; }
$REPO = new file_abstract($rpcrepo);
$ct = configs::get('newzbinv2', 'cachetype');
$c = 'nb_cache_'.$ct;
$NBRID = new $c();
$err = $REPO->connect();
if ( CORE::isError($err) ){
	errors::broadcast($err);
	exit();
}
$time=time();
$c=0;
while ( FALSE !== ($item = $REPO->readdir('/')) ){
	if ( $REPO->isdir("/$item") ){
		$catid = array_search($item, search_nzbid::$cats);
		if ( FALSE !==  $catid ){
			$cat = $item;
			while ( FALSE !== ($item = $REPO->readdir("/$cat")) ){
				if ( $REPO->isdir("/$cat/$item") ){
					echo ">>> /$cat/$item\n";
					$ITEM = new rpcbrw_item($RPC, "/$cat/$item", $catid);
					do_item(&$ITEM, &$RPC, &$NBRID);
					$c++;
				}
			}
		} else {
			echo ">>> /$item\n";
			$ITEM = new rpcbrw_item($RPC, "/$item");
			do_item(&$ITEM, &$RPC, &$NBRID);
			$c++;
		}
	}
}
hellarpcs::set_lastbrw($RPC, $time);
echo $c." item(s) checked, cleaning.\n";
hellarpcs::clean_browser($RPC);
echo "done.\n";

function do_item(&$ITEM, &$RPC, &$NBRID){
	$h = $ITEM->get_hash();
	$c = $ITEM->get_catid();
	$i = $ITEM->get_id();
	$t = $ITEM->get_title();
	if ( hellarpcs::hash_iscached($RPC, $ITEM->get_catid(), $ITEM->get_hash()) ){
		$d = "=== ";
		hellarpcs::update_item(&$ITEM);
	} else {
		$d = "+++ ";
		hellarpcs::insert_item(&$ITEM);
	}
	if ( 'nbrid' == $ITEM->get_engine() ){
		//nb_cache report date update to prevent drop by expiration
		$NBRID->update_report_date($i); 
	}
	echo "$d [ $h ] [ $c ] [ $i ]\n";
}

exit;
Return current item: Simple Way to Usenet