64) { // local part length exceeded $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { // domain not found in DNS $isValid = false; } } return $isValid; } // password conditions function validPassword($password) { if( //ctype_alnum($password) &&// numbers & digits only strlen($password)>7 // at least 8 chars && strlen($password)<21 // at most 20 chars //&& preg_match('`[A-Z]`',$password) // at least one upper case //&& preg_match('`[a-z]`',$password) // at least one lower case //&& preg_match('`[0-9]`',$password) // at least one digit ){ return true; } else return false; } // encrypt cookie data saved on client side function encryptCookie($value) { if(!$value){return false;} $key = 'MZEmB1tO391YL537'; $text = $value; $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv); return trim(strtr(base64_encode($crypttext),'+/=', '-_,')); //encode for cookie } // decrypt data from above function function decryptCookie($value) { if(!$value){return false;} $key = 'MZEmB1tO391YL537'; $crypttext = base64_decode(strtr($value, '-_,', '+/=')); //decode cookie $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv); return trim($decrypttext); } function sanitizeInputs(&$item1, $key) { if(is_string($item1)){ $item1 = strip_tags(trim($item1)); } } function cleanInputs(&$item1, $key) { if(is_string($item1)){ $item1 = stripslashes(nl2br($item1)); } } function url_exists($url) { /*$handle = @fopen($url, "r"); if ($handle === false) return false; fclose($handle); return true;*/ if (is_array(@get_headers($url))) return true; else return false; } function topiaExtractor($text) { $cmd = "cd ".ROOT_PATH."/library/topic; ./extract2.py \"".$text."\""; $exec_out = `$cmd`; $tags = json_decode($exec_out,true); return $tags; } function listDirImages($dir) { //$dir is the name of the directory you want to list the images. $files = scandir($dir); //scans the directory's files $preg = "/.(jpg)/i"; //match the following files, can be changed to limit or extend range, ie: png,jpeg,etc. $images = array(); foreach($files as $img) { //loop through directory files if(substr($img, 0, 1) != '.') { //ignore anything starting with a period $images[]= $img; } } return $images; } ?>