<?
class strings {

function forURL($str) {
	return htmlspecialchars(rawurlencode(utf8_decode($str)), ENT_QUOTES);
}

function safeJS($str) {
	return addslashes(str_replace("\n","",str_replace("\n","",str_replace("\r","",$str))));
}

function safeSQL($str) {
	//return (!get_magic_quotes_gpc())?addslashes($str):$str;
	return addslashes($str);
}

function HTMLforSafeJS($str) {
	$str = str_replace("'","\'", $str);
	$str = str_replace("\'+","'+", $str);
	$str = str_replace("+\'","+'", $str);
	$str = str_replace("\n","", $str);
	$str = str_replace("\r","", $str);
	return $str;
}

function fromHTML($str, $utf8_decode = true) {
	if (get_magic_quotes_gpc()) {
		$str = stripslashes($str);
	}
	$str = rawurldecode($str);
	if ($utf8_decode) {
		$str = utf8_decode($str);
	}
	return $str;
}

function safeHTML($str) {
	return htmlspecialchars($str, ENT_QUOTES);
}

function okUsername($string) {
$alphanum = array("q","w","e","r","t","y","u","i","o","p","l","k","j","h",
"g","f","d","s","a","z","x","c","v","b","n","m","Q","W",
"E","R","T","Y","U","I","O","P","L","K","J","H","G","F",
"D","S","A","Z","X","C","V","B","N","M","0","1","2","3",
"4","5","6","7","8","9","_","-","@",".");
       for ($i=0;$i<strlen($string);$i++) {
			if (!in_array($string[$i], $alphanum)) {
					return false;
			}
	   }
	   return true;
}

	function shorten($text, $length, $symbol = "[...]") {
	 $length_text = strlen($text);
	 $length_symbol = strlen($symbol);
	 if($length_text <= $length || $length_text <= $length_symbol || $length <= $length_symbol)
	   return($text);
	 else
	   return(substr($text, 0, $length - $length_symbol) . $symbol);
	}
	
	function previewArray($array, $length, $symbol = "[...]") {
		$slice = array_slice($array, 0, $length);
		$str = implode(", ", $slice);
		if (sizeof($array) > $length) {
			$str .= ", ".$symbol;
		}
		return $str;
	}


}


class HTMLForms extends strings {

	function checkThebox($var, $val) {
		if ($var == $val) {
			echo "checked";
		}
	}

}

?>