]*?>.*?@si', // Strip out javascript '@]*?>.*?@siU', // Strip style tags properly '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@@' // Strip multi-line comments including CDATA ); if(is_array($_string)){ foreach($_string as $key => $value){ $value = (is_array($value) || is_object($value)) ? self::html2txt($value) : $value; $text = preg_replace($search, '', $value); $text = str_replace("'",' ',$text); $string[$key] = trim(self::addSlashesGPC($text)); } }else{ $string = preg_replace($search, '', trim($_string)); $string = str_replace("'",' ',self::addSlashesGPC($string)); } return $string; } /******************************************************** * add Slashes to magic quotes *********************************************************/ public static function addSlashesGPC($_var) { if(!get_magic_quotes_gpc()){ return addSlashes($_var); } else{ return $_var; } } public static function checkEmail ($_email) { $email = new Validate(); if (false===$email->email($_email, true)){ return false; }else{ return true; } } public static function relocateOnError($_url){ if(ConfigLoader::getInstance()->getPHPSettings("display_errors") == 'off'){ header('Location: http://'.$_SERVER['HTTP_HOST'].'/'.$_url.'.php'); die; } } /******************************************************** * encodes the given String *********************************************************/ public static function encode($code){ return sha1($code); } /***************************************************************** * generates a password with a length of 8 characters * min one lower case letter * min one special characters (numbers are special characters too) * min one upper case letter ****************************************************************/ public static function generatePwd() { $all = array( range(0, 9), range('a', 'z'), range('A', 'Z'), array("!", "$", "%", "&", "/", "?", "*", "#", "+", "-", "@") ); foreach ($all as $key => $value) $pwd[] = $value[array_rand($value)]; while(count($pwd) < 7) { $value = $all[array_rand($all)]; $pwd[] = $value[array_rand($value)]; } shuffle($pwd); $pwd = implode($pwd); return $pwd; } public static function vardump ($this) { if($this)echo '
'.htmlentities(print_r($this, true)).'
'; else var_dump($this); } public static function getSelectedId ($_btnName, $_post) { $selectedResID = ''; foreach($_post as $id => $values){ if($id == $_btnName){ foreach($values as $ids => $value) { $selectedResID = $ids; break; } } } return $selectedResID; } /********************************************************************************************** * upload image to destination, creates dir if not exists and sets global CHMOD * @param $_sourceFilename source fileName * @param $_destDir destination dir * @param $_destFilename upload destination location * @param $_doOverwrite flag to overwrite file if exists y/n **********************************************************************************************/ public static function uploadFile($_sourceFilename, $_destDir, $_destFilename, $_doOverwrite) { $dirRewind = ""; // navigate to destiantiondir, if file not exists, create $dirArr = explode("/", $_destDir); foreach ($dirArr as $dir) { if (!file_exists($dir) && !empty ($dir)) { mkdir($dir, 0777); chmod($dir, 0777); chdir($dir); $dirRewind .= "../"; } elseif (file_exists($dir)) { chdir($dir); $dirRewind .= "../"; } } // if file exists choose to overwrite or not if (file_exists($_destFilename)) { if ($_doOverwrite) { unlink($_destFilename); if (copy($_sourceFilename, $_destFilename)) { chmod($_destFilename, 0755); chdir($dirRewind); return 1; } } } else { if (copy($_sourceFilename, $_destFilename)) { chmod($_destFilename, 0755); chdir($dirRewind); return 1; } } chdir($dirRewind); return 0; } public static function makeDir($_dir){ if (!file_exists($_dir) && !empty ($_dir)) { mkdir($_dir, 0777); chmod($_dir, 0777); } } /********************************************************************************************** * returns name of folder in delieverd directory * @param $pfad path of the directory **********************************************************************************************/ public static function readDirectory($pfad,$_numberOfFiles = false){ $filesArr = array(); $dh = opendir($pfad); $i = 0; if($ordner = dir($pfad)){ while(false !== ($datei = $ordner->read())){ if($datei !== "" && $datei !== "." && $datei !== ".." && $datei !== ".htaccess" && !is_dir($pfad.$datei)) { array_push($filesArr,$datei); } if(is_numeric($_numberOfFiles) && $_numberOfFiles < $i) break; $i++; } } closedir($dh); return $filesArr; } //returns current userIp public static function getIP(){ if(getenv("HTTP_X_FORWARDED_FOR")){ $guest_ip = getenv("HTTP_X_FORWARDED_FOR"); }else { $guest_ip =getenv("REMOTE_ADDR"); } return $guest_ip; } //checks if function exist in delievered class public static function existFunction ($_class, $_event) { if (!class_exists($_class)) { $_SESSION['messages'][] = "unknown class: $_class"; // class not available return false; } // initialize Processing $object = new $_class (); $methods = get_class_methods($_class); // method in object available and public? if (!in_array($_event, $methods)) { // function not available or not public $_SESSION['messages'][] = "unknown event: ".$_event." in class ".$_class.""; return false; } // call the function call_user_func(array ($object, $_event)); return true; } //returns the date of the next tuesday public static function getDateOfNextTuesday(){ $today = time(); for($i=0; $i<=6; $i++){ $day = date('l - d.m.Y',mktime(0,0,0, date('m',$today), date('d',$today)+$i, date('Y',$today))); $hit = date('d.m.Y',mktime(0,0,0, date('m',$today), date('d',$today)+$i, date('Y',$today))); if(preg_match("/(Tuesday)( -)/",$day)){ return $hit; } } } /** * **************************************************************** * sets cookie * set_cookie("TestCookie", $value, 3600); expire in 1 hour * set_cookie("TestCookie", $value, 3600, "/~rasmus/", ".example.com", 1); * ***************************************************************/ public static function set_cookie($Name, $Value = '', $MaxAge = 0, $Path = '', $Domain = '', $Secure = false, $HTTPOnly = false) { header('Set-Cookie: ' . rawurlencode($Name) . '=' . rawurlencode($Value) . (empty($MaxAge) ? '' : '; Max-Age=' . $MaxAge) . (empty($Path) ? '' : '; path=' . $Path) . (empty($Domain) ? '' : '; domain=' . $Domain) . (!$Secure ? '' : '; secure') . (!$HTTPOnly ? '' : '; HttpOnly'), false); } /***************************************************************** * converts the delivered date or datetime to timestamp for the db * delivered dateformat d.M.y h:i:s *****************************************************************/ public static function convertToDBDate($_date) { if(empty($_date)) return null; if(strlen($_date) > 10) { $dtTmp = explode(" ", $_date); $date = explode(".", $dtTmp[0]); $time = explode(":", $dtTmp[1]); } else { $date = explode(".", $_date); $time = array("00","00","00"); } //stunde, minute ,seconds ,month ,day ,year if(strlen($_date) > 10) return $date[2]."-".$date[1]."-".$date[0]." ".$time[0].":".$time[1].":".$time[2]; else return $date[2]."-".$date[1]."-".$date[0]; } public static function decodeUtf8($_post){ if(is_array($_post)){ foreach($_post as $key => $value){ $value = (is_array($value) || is_object($value)) ? self::decodeUtf8($value) : $value; $_post[$key] = (!is_array($value) && !is_object($value))? utf8_decode($value) : $value; } return $_post; } elseif(is_string($_post)){ return utf8_decode($_post); }elseif(is_object($_post)){ $_arr = get_object_vars($_post); foreach ($_arr as $key => $val) { $val = (is_array($val) || is_object($val)) ? self::decodeUtf8($val) : $val; $_post->$key = (!is_array($val) && !is_object($val))? utf8_decode($val) : $val; } return $_post; } } public static function encodeUtf8($_post){ if(is_array($_post)){ foreach($_post as $key => $value){ $value = (is_array($value) || is_object($value)) ? self::encodeUtf8($value) : $value; $_post[$key] = (!is_array($value) && !is_object($value))? utf8_encode($value) : $value; } return $_post; } elseif(is_string($_post)){ return utf8_encode($_post); }elseif(is_object($_post)){ $_arr = get_object_vars($_post); foreach ($_arr as $key => $val) { $val = (is_array($val) || is_object($val)) ? self::encodeUtf8($val) : $val; $_post->$key = (!is_array($val) && !is_object($val))? utf8_encode($val) : $val; } return $_post; } } } ?>