<?php$nodes = array('with all the rows of the sql query nested set');$menu = $this->getSubTree($nodes);function getSubTree(&$nodes, $prevNodeRgt = false){ while($node = current($nodes)){ // No more children? Continue one level up if($prevNodeRgt && $prevNodeRgt < $node['rgt']) return $tree; next($nodes); //Has children? if($node['rgt'] - $node['lft'] > 1) $node['children'] = $this->getSubTree($nodes, $node['rgt']); $tree[] = $node; } return $tree; }?>
<?php/*** Gzip encode css/js files.* Handy when server does not allow or provide this function*///CSS to encodegzip_encode(array('of css files'), $_SERVER['DOCUMENT_ROOT'] . '/styles/%file%.css', $_SERVER['DOCUMENT_ROOT'] . '/styles/gzip/%file%.css.gz');//JS to encodegzip_encode(array('of javascript files'), $_SERVER['DOCUMENT_ROOT'] . '/js/%file%.js', $_SERVER['DOCUMENT_ROOT'] . '/js/gzip/%file%.js.gz'); //Creates gzip compressed files. These files are used in productionfunction gzip_encode($files, $uncompressed, $compressed){ foreach($files AS $file){ $uncompressedFilename = str_replace('%file%', $file, $uncompressed); $compressedFilename = str_replace('%file%', $file, $compressed); if(!is_file($compressedFilename) || (is_file($compressedFilename) && filemtime($uncompressedFilename) > filemtime($compressedFilename))){ file_put_contents($compressedFilename, gzencode(file_get_contents($uncompressedFilename))); } }}?>
<?phpfunction wakeOnLan($ip, $mac, $port) { $ip_byte = explode(':', $mac); $hw_addr = ''; for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($ip_byte[$a])); $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255); for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr; $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($s == false) { echo 'Error creating socket!\n'; echo 'Error code is "'.socket_last_error($s).'" - ' . socket_strerror(socket_last_error($s)); return FALSE; } else { if(socket_sendto($s, $msg, strlen($msg), 0, $ip, $port)) { echo 'Magic Packet sent successfully!'; socket_close($s); return TRUE; } else { echo 'Magic packet failed!'; return FALSE; } }}?>
<?phpif(isset($_GET['check'])){ $this->template = false; $address ='LAN-IP'; //Here you can specify the address you want to check ports $port = 'PortToPing'; //Here you can specify the port you want to check from $address $checkport = @fsockopen($address, $port, $errnum, $errstr, 1); //The 1 is the time of ping in secs @fclose($checkport); die;}?>
<?php/*** Gets total space, free space for all drives (both in percentages and amounts in GB)* IMPORTANT! Leave the @ on windows machines to prevent warnings* @param: 67 = C, 90 = Z*/for($i = 67; $i <= 90; $i++){ $drive = strtolower(chr($i)); if (is_dir($drivePath = $drive . ':')){ @$drives[$drive]['total_space'] = number_format(disk_total_space($drivePath) / 1024 / 1024 / 1024, 2); @$drives[$drive]['free_space'] = number_format(diskfreespace($drivePath) / 1024 / 1024 / 1024, 2); //$drives[$drive]['used_space'] = number_format((disk_total_space($drivePath) / 1024 / 1024 / 1024) - (diskfreespace($drivePath) / 1024 / 1024 / 1024), 2); @$drives[$drive]['free_percentage'] = number_format((diskfreespace($drivePath) / disk_total_space($drivePath)), 2); @$drives[$drive]['used_percentage'] = number_format((disk_total_space($drivePath) - diskfreespace($drivePath)) / disk_total_space($drivePath), 2); @$drives[$drive]['free_percentage'] = $drives[$drive]['free_percentage'] * 100 . '%'; }}?>
<?php/*** This function takes the REQUEST_URI and fills up the $_GET array.* Each directory part (that is /someUrlPart) will be put into $_GET numerically starting at zero.* Each querystring parameter (that is ?someVariable=someValue) will be put into $_GET as $_GET[key] = value* Handy to be used in conjunction with a htaccess redirect.*/function setGetArray(){ $tempUrl = substr_replace($_SERVER['REQUEST_URI'], '', 0, strlen(BASE) + 1); //Get all the directories being requested and put them into $_GET[] starting with 0 $DIRvars = explode('/', $tempUrl); foreach($DIRvars AS $var){ if(($pos = strpos($var, '?')) !== false){ $_GET[] = substr($var, 0, $pos); } else { $_GET[] = $var; } } //Get all the GET requests and put them into $_GET['key'] = 'value' $GETvars = explode('?', $tempUrl); if(isset($GETvars[1])){ $GETvars = explode('=', $GETvars[1]); for($i=0; $i < count($GETvars); $i++){ if($i % 2 == 0){ $key = $GETvars[$i]; } else { $_GET[$key] = $GETvars[$i]; } } }?>