PageRenderTime 83ms CodeModel.GetById 41ms app.highlight 9ms RepoModel.GetById 31ms app.codeStats 0ms

/includes/misc.inc.php

https://bitbucket.org/hky/bytehoard2
PHP | 111 lines | 78 code | 15 blank | 18 comment | 20 complexity | e53f2508364e783df977d7c1bc4db5b7 MD5 | raw file
  1<?php
  2
  3/*
  4 * ByteHoard 2.1
  5 * Copyright (c) Andrew Godwin & contributors 2003-2004
  6 *
  7 *   Miscellaneous Functions File
  8 *   $Id: misc.inc.php,v 1.4 2005/07/28 23:06:07 andrewgodwin Exp $
  9 *
 10 */
 11
 12# Test for include status
 13if (IN_BH != 1) { header("Location: ../index.php"); die(); }
 14
 15# Fixes ISS request_uri
 16if(!isset($_SERVER['REQUEST_URI'])) {
 17   $arr = explode("/", $_SERVER['PHP_SELF']);
 18   $_SERVER['REQUEST_URI'] = "/" . $arr[count($arr)-1];
 19   if ($_SERVER['argv'][0]!="")
 20    $_SERVER['REQUEST_URI'] .= "?" . $_SERVER['argv'][0];
 21 }
 22 
 23
 24
 25function bh_getskins() {
 26	global $bhconfig;
 27	
 28	# Open layouts folder
 29	$handle = opendir($bhconfig['bhfilepath']."/layouts/");
 30	# For each layout:
 31	while (false !== ($layout = readdir($handle))) {
 32		if (file_exists($bhconfig['bhfilepath']."/layouts/".$layout."/main.inc.php")) {
 33			# Open that layout's skins folder
 34			$handle2 = opendir($bhconfig['bhfilepath']."/layouts/".$layout."/skins/");
 35			# And for each skin:
 36			while (false !== ($skin = readdir($handle2))) {
 37				if (file_exists($bhconfig['bhfilepath']."/layouts/".$layout."/skins/".$skin."/skin.inc.php")) {
 38					# Load the defs file
 39					$bhskin = array();
 40					require $bhconfig['bhfilepath']."/layouts/".$layout."/skins/".$skin."/skin.inc.php";
 41					foreach ($bhskin as $key=>$value) {
 42						$bhskins[$layout.".".$skin][$key] = $value;
 43					}
 44					$bhskins[$layout.".".$skin]['layout'] = $layout;
 45					$bhskins[$layout.".".$skin]['skin'] = $skin;
 46				}
 47			}
 48		}
 49	}
 50	
 51	return $bhskins;
 52}
 53
 54# To fix weird bugs
 55function bh_get_docroot() {
 56	return str_replace($_SERVER['PHP_SELF'], "", $_SERVER['SCRIPT_FILENAME']);
 57}
 58
 59function htmlpath($relative_path) {
 60	$realpath=realpath($relative_path);
 61	$htmlpath=str_replace(bh_get_docroot(),'',$realpath);
 62	return $htmlpath;
 63}
 64
 65function bh_get_weburi() {
 66	global $bhconfig;
 67	
 68	if (!empty($bhconfig['baseuri'])) {
 69		if (substr($bhconfig['baseuri'], -1) != "/") { $bhconfig['baseuri'] .= "/"; }
 70		return $bhconfig['baseuri'];
 71	} else {
 72		if($_SERVER['HTTPS']=='on'){$httpsuff = 's';}
 73		if(defined("BH_ROOT")) { $htmlpath = BH_ROOT; } else { $htmlpath = "."; }
 74		return $sysurl = "http".$httpsuff."://".$_SERVER['HTTP_HOST'].htmlpath($htmlpath)."/";
 75	}
 76}
 77
 78# Humanises times
 79function bh_humanise_time($time) {
 80	if ($time == 0) { $time = "Now"; }
 81	elseif (($time) < (60)) { $time = $time." seconds"; }
 82	elseif (($time) < (60*60)) { $time = ceil($time/60)." mins"; }
 83	elseif (($time) < (60*60*24)) { $time = ceil($time/(60*60))." hours"; }
 84	elseif (($time) < (60*60*24*7)) { $time = ceil($time/(60*60*24))." days"; }
 85	elseif (($time) < (60*60*24*365)) { $time = ceil($time/(60*60*24*7))." weeks"; }
 86	elseif (($time) < (60*60*24*365*5)) { $time = ceil($time/(60*60*24*7*365))." years"; }
 87	elseif (($time) < (60*60*24*365*5*10)) { $time = ceil($time/(60*60*24*7*365))." decades"; }
 88	elseif (($time) < (60*60*24*365*5*100)) { $time = ceil($time/(60*60*24*7*365))." centuries"; }
 89	elseif (($time) < (60*60*24*365*5*1000)) { $time = ceil($time/(60*60*24*7*365))." millenia"; }
 90	else { $time = "Nearly forever"; }
 91	
 92	return $time;
 93}
 94
 95# Humanises file sizes
 96function bh_humanise_filesize($size) {
 97	$counter=0;
 98	while ($size > 1024) {$size=$size/1024; ++$counter;}
 99	switch ($counter) {
100		case 2: $mysymbol="MB"; break;
101		case 1: $mysymbol="KB"; break;
102		case 0: $mysymbol="B"; break;
103		case 3: $mysymbol="GB";  break;
104		case 4: $mysymbol="TB";  break;
105		case 5: $mysymbol="PB";  break;
106		case 6: $mysymbol="EB";  break;
107		case 7: $mysymbol="ZB";  break;
108		case 8: $mysymbol="YB";  break;
109	}
110	return sprintf("%01.1f %s", $size, $mysymbol);
111}