@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+/i', $emailadres)){ $emailArray = explode("@",$emailadres); if (checkdnsrr($emailArray[1])){ return TRUE; } } return FALSE; } function htmlmail($to, $subject, $message) { global $config; $headers = "From: " . $config['mail']['from_header'] . "\r\n"; $headers .= "Reply-To: admin@".$config['app']['url']."\r\n"; $headers .= "Return-Path: admin@".$config['app']['url']."\r\n"; $headers .= "X-Mailer: ". $config['app']['name']."\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $msg = "\n\n".$subject."\n\n\n".$message."\n"; if (mail($to,$subject,$msg,$headers)) return true; else return false; } function random($charnum = 10) { $chars = "ABCDEFGHJKMNPQRSTUVWXYZ123456789"; for ($i = 0; $i <= $charnum; $i++) $rand .= ((mt_rand(0,1) == 0) ? $chars[mt_rand(0,strlen($chars))] : strtolower($chars[mt_rand(0,strlen($chars))])); $rand = substr($rand,0,10); return $rand; } function logged_in() { return (($_SESSION['logged_in']) ? TRUE : FALSE); } function array_trim($array) { while (!empty($array) and strlen(reset($array)) === 0) { array_shift($array); } while (!empty($array) and strlen(end($array)) === 0) { array_pop($array); } return $array; } function in_arrayi( $needle, $haystack ) { $found = false; foreach( $haystack as $value ) { if( strtolower( $value ) == strtolower( $needle ) ) { $found = true; } } return $found; } function array_nsearch($needle, $haystack) { $it = new IteratorIterator(new ArrayIterator($haystack)); foreach($it as $key => $val) { if($val == "Onbekend") $onb = $key; if(strcasecmp($val,$needle) === 0) { return $key; } } return $key; } function parseFloat($ptString) { if (strlen($ptString) == 0) { return false; } $pString = str_replace(" ", "", $ptString); if (substr_count($pString, ",") > 1) $pString = str_replace(",", "", $pString); if (substr_count($pString, ".") > 1) $pString = str_replace(".", "", $pString); $pregResult = array(); $commaset = strpos($pString,','); if ($commaset === false) {$commaset = -1;} $pointset = strpos($pString,'.'); if ($pointset === false) {$pointset = -1;} $pregResultA = array(); $pregResultB = array(); if ($pointset < $commaset) { preg_match('#(([-]?[0-9]+(\.[0-9])?)+(,[0-9]+)?)#', $pString, $pregResultA); } preg_match('#(([-]?[0-9]+(,[0-9])?)+(\.[0-9]+)?)#', $pString, $pregResultB); if ((isset($pregResultA[0]) && (!isset($pregResultB[0]) || strstr($preResultA[0],$pregResultB[0]) == 0 || !$pointset))) { $numberString = $pregResultA[0]; $numberString = str_replace('.','',$numberString); $numberString = str_replace(',','.',$numberString); } elseif (isset($pregResultB[0]) && (!isset($pregResultA[0]) || strstr($pregResultB[0],$preResultA[0]) == 0 || !$commaset)) { $numberString = $pregResultB[0]; $numberString = str_replace(',','',$numberString); } else { return false; } $result = (float)$numberString; return $result; } function berekenLeeftijd($geboortedatum) { list($Y,$m,$d) = explode("-",$geboortedatum); return(date("md") < $m.$d ? date("Y")-$Y-1 : date("Y")-$Y); } function _make_url_clickable_cb($matches) { $ret = ''; $url = $matches[2]; if ( empty($url) ) return $matches[0]; // removed trailing [.,;:] from URL if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) { $ret = substr($url, -1); $url = substr($url, 0, strlen($url)-1); } return $matches[1] . "$url" . $ret; } function _make_web_ftp_clickable_cb($matches) { $ret = ''; $dest = $matches[2]; //$dest = 'http://' . $dest; if ( empty($dest) ) return $matches[0]; // removed trailing [,;:] from URL if ( in_array(substr($dest, -1), array('.', ',', ';', ':')) === true ) { $ret = substr($dest, -1); $dest = substr($dest, 0, strlen($dest)-1); } return $matches[1] . "$dest" . $ret; } function _make_email_clickable_cb($matches) { $email = $matches[2] . '@' . $matches[3]; return $matches[1] . "$email"; } function make_clickable($ret) { $ret = ' ' . $ret; // in testing, using arrays here was found to be faster $ret = preg_replace_callback('#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret); $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret); $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret); // this one is not in an array because we need it to run last, for cleanup of accidental links within links $ret = preg_replace("#(]+?>|>))]+?>([^>]+?)#i", "$1$3", $ret); $ret = trim($ret); return rewriteRelative($ret,"http://".$_SERVER['HTTP_HOST']."/"); } function veldTypen($tabel,$kolom) { $result = mysql_query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$tabel."' AND COLUMN_NAME = '".$kolom."'") or trigger_error(mysql_error()); $raw = mysql_result($result,0); $types = explode("','",substr($raw,strpos($raw,"(")+2,-2)); return $types; } function secure($var,$including_tags = FALSE) { $var = ((is_array($var)) ? array_map("mysql_real_escape_string",$var) : mysql_real_escape_string($var)); return (($including_tags) ? strip_tags($var) : $var); } function unsecure($str) { return html_entity_decode($str); } function tbl($value) { global $config; return (($config['tbl'][$value]) ? $config['tbl'][$value] : FALSE); } function print_a($subject){ echo str_replace("=>","⇒",str_replace("Array","Array",nl2br(str_replace(" ","   ",print_r($subject,true))))); } function dayToNL($day_of_the_week_number) { $names = array("Zondag","Maandag","Dinsdag","Woensdag","Donderdag","Vrijdag","Zaterdag"); return $names[$day_of_the_week_number]; } function monthToNL($month_number) { $names = array("Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December"); return $names[$month_number-1]; } function MergeArrays($Arr1, $Arr2) { foreach($Arr2 as $key => $Value) { if(array_key_exists($key, $Arr1) && is_array($Value)) $Arr1[$key] = MergeArrays($Arr1[$key], $Arr2[$key]); else $Arr1[$key] = $Value; } return $Arr1; } function rewriteRelative($html, $base) { // generate server-only replacement for root-relative URLs $server = preg_replace('@^([^\:]*)://([^/*]*)(/|$).*@', '\1://\2/', $base); // replace root-relative URLs $html = preg_replace('@\<([^>]*) (href|src)="/([^"]*)"@i', '<\1 \2="' . $server . '\3"', $html); // replace base-relative URLs (kludgy, but I couldn't get ! to work) $html = preg_replace('@\<([^>]*) (href|src)="(([^\:"])*|([^"]*:[^/"].*))"@i', '<\1 \2="' . $base . '\3"', $html); return $html; } function mres($str) { return mysql_real_escape_string($str); } function s($str) { return mysql_real_escape_string($str); } function sqlValue($str) { if (($str === NULL || empty($str)) && $str != "0") return "NULL"; else return "'".mysql_real_escape_string($str)."'"; } function hsc_utf8($str) { return htmlspecialchars(utf8_encode($str)); } function hsc_utf8_dec($str) { return htmlspecialchars(utf8_decode($str)); } function resize_image_from_data($image_data, $resize_type, $width, $height) { $srcImg = imagecreatefromstring($image_data); $orgWidth = imagesx($srcImg); $orgHeight = imagesy($srcImg); switch ($resize_type) { case "PRESERVE_RATIO": $newWidth = $width; $newHeight = $width; if ($orgWidth > $orgHeight) //Landscape { $newWidth = $newWidth * 1; $newHeight = (int) ($newHeight * ($orgHeight / $orgWidth)); } elseif ($orgHeight >= $orgWidth) //Portrait { $newWidth = (int) ($newWidth * ($orgWidth / $orgHeight)); $newHeight = $newHeight * 1; } $newImg = imagecreatetruecolor($newWidth, $newHeight); imagealphablending($newImg, true); $transparent = imagecolorallocatealpha($newImg, 0, 0, 0, 127); imagefill($newImg, 0, 0, $transparent); imagecopyresampled($newImg, $srcImg, 0, 0, 0, 0, $newWidth, $newHeight, $orgWidth, $orgHeight); break; case "FIXED_SLICED_SIZE": $newWidth = $width; $newHeight = $height; $orgWidthHeightRatio = $orgWidth / $orgHeight; $newWidthHeightRatio = $newWidth / $newHeight; if($orgWidthHeightRatio > $newWidthHeightRatio) // Top and bottom cut { $newWidth = ($newHeight / $orgHeight) * $orgWidth; if ($newWidth % 2 != 0) $newWidth++; $destX = round(($newWidth - $width) / 2) * -1; $destY = 0; } elseif($orgWidthHeightRatio <= $newWidthHeightRatio) // Left and right cut { $newHeight = ($newWidth / $orgWidth) * $orgHeight; if ($newHeight % 2 != 0) $newHeight++; $destX = 0; $destY = round(($newHeight - $height) / 2) * -1; } $newImg = imagecreatetruecolor($width, $height); imagealphablending($newImg, true); $transparent = imagecolorallocatealpha($newImg, 0, 0, 0, 127); imagefill($newImg, 0, 0, $transparent); imagecopyresampled ($newImg, $srcImg, $destX, $destY, 0, 0, $newWidth, $newHeight, $orgWidth, $orgHeight); break; case "FIXED_SIZE": $newWidth = $width; $newHeight = $height; $orgWidthHeightRatio = $orgWidth / $orgHeight; $newWidthHeightRatio = $newWidth / $newHeight; if($orgWidthHeightRatio > $newWidthHeightRatio) // Top and bottom have transparency { $newHeight = ($newWidth / $orgWidth) * $orgHeight; if ($newHeight % 2 != 0) $newHeight++; $destX = 0; $destY = round(($newHeight - $height) / 2) * -1; } elseif($orgWidthHeightRatio <= $newWidthHeightRatio) // Left and right have transparency { $newWidth = ($newHeight / $orgHeight) * $orgWidth; if ($newWidth % 2 != 0) $newWidth++; $destX = round(($newWidth - $width) / 2) * -1; $destY = 0; } $newImg = imagecreatetruecolor($width, $height); imagealphablending($newImg, true); $transparent = imagecolorallocatealpha($newImg, 0, 0, 0, 127); imagefill($newImg, 0, 0, $transparent); imagecopyresampled ($newImg, $srcImg, $destX, $destY, 0, 0, $newWidth, $newHeight, $orgWidth, $orgHeight); break; } imagealphablending($newImg, false); imagesavealpha($newImg,true); ob_start(); imagepng($newImg); $new_data = ob_get_contents(); ob_end_clean(); imagedestroy($srcImg); imagedestroy($newImg); return $new_data; } function save_image_from_data($image_data, $destination) { $img = imagecreatefromstring($image_data); imagesavealpha($img, true); imagepng($img, $destination); } ?>