bouncer_r/php/inc utils.inc,NONE,1.1

David Farning (dfarning) fedora-extras-commits at redhat.com
Tue Aug 2 00:10:42 UTC 2005


Author: dfarning

Update of /cvs/fedora/bouncer_r/php/inc
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv21326/php/inc

Added Files:
	utils.inc 
Log Message:
cvs cleanup for fedora initial commit


--- NEW FILE utils.inc ---
<?

/* Convert bytes to a human readable format */
function human_readable($bytes) {
	if ($bytes >= 1024 * 1024 * 1024) {
		$amt = round(($bytes / (1024 * 1024 * 1024)) * 10) / 10 . "G";
	} elseif ($bytes >= 1024 * 1024) {
		$amt = round(($bytes / (1024 * 1024)) * 10) / 10 . "M";
	} elseif ($bytes >= 1024) {
		$amt = round(($bytes / 1024) * 10) / 10 . "K";
	} else {
		$amt = $bytes;
	}
	return $amt;
}

/* determine the path for an object */
function mappath($file) {
	if (substr($file,0,1)=="/"){
		$file = substr($file,1);
	}
	if (strlen($_SERVER["SCRIPT_NAME"])==0) {
		$currentpath = dirname($_ENV["SCRIPT_NAME"]);
	} else {
		$currentpath = dirname($_SERVER["SCRIPT_NAME"]);
        }
	if($currentpath=="/")
		$path = "./";
	else
		$path = str_repeat("../", substr_count($currentpath, "/"));

	return $path.$file;
}

/* figure out the absolute filesystem path */
function basepath()
{
	return realpath(dirname(__File__)."/".mappath("/"));
}

/* determines the page's level automagically */
function determine_level() {
	if (strlen($_SERVER['REQUEST_URI'])==0) {
		$uri_info['complete_path']=$_ENV['REQUEST_URI'];
		$uri_path=explode("/",rtrim($_ENV['REQUEST_URI'],"/"));
	} else {
		$uri_info['complete_path']=$_SERVER['REQUEST_URI'];
		$uri_path=explode("/",rtrim($_SERVER['REQUEST_URI'],"/"));
	}
	$uri_info['depth']=sizeof($uri_path)-1;
	$uri_info['path']=$uri_path;
	$uri_info['parent']=$uri_path[sizeof($uri_path)-2];
	array_pop($uri_path);
	array_push($uri_path,"");
	$uri_info['parent_path']=implode("/",$uri_path);
	return $uri_info;
}

/* a function that is a bit more aggressive than htmlentities */
function encode_everything($string){
	$encoded = "";
	for ($n=0;$n<strlen($string);$n++){
		$check = htmlentities($string[$n],ENT_QUOTES);
		$string[$n] == $check ? $encoded .= "&#".ord($string[$n]).";" : $encoded .= $check;
	}
	return $encoded;
}

?>




More information about the fedora-extras-commits mailing list