function get_post_var($name, $default = false) {
if($HTTP_POST_VARS)
return (strlen($HTTP_POST_VARS[$name]) > 0) ? $HTTP_POST_VARS[$name] : $default;
else
return (strlen($_POST[$name]) > 0) ? $_POST[$name] : $default;
}
function get_session_var($name, $default = false) {
if($HTTP_SESSON_VARS)
return (strlen($HTTP_SESSON_VARS[$name]) > 0) ? $HTTP_SESSION_VARS[$name] : $default;
else
return (strlen($_SESSION[$name]) > 0) ? $_SESSION[$name] : $default;
}
function get_get_var($name, $default = false) {
if($HTTP_GET_VARS)
return (strlen($HTTP_GET_VARS[$name]) > 0) ? $HTTP_GET_VARS[$name] : $default;
else
return (strlen($_GET[$name]) > 0) ? $_GET[$name] : $default;
}
function get_cookie_var($name, $default = false) {
if($HTTP_COOKIE_VARS)
return (strlen($HTTP_COOKIE_VARS[$name]) > 0) ? $HTTP_COOKIE_VARS[$name] : $default;
else
return (strlen($_COOKIE[$name]) > 0) ? $_COOKIE[$name] : $default;
}
function get_var($name, $default = null)
{
if(get_post_var($name)) $ret_val = get_post_var($name);
if(get_get_var($name)) $ret_val = get_get_var($name);
if(get_session_var($name)) $ret_val = get_session_var($name);
if(get_cookie_var($name)) $ret_val = get_cookie_var($name);
return stripslashes((strlen($ret_val) > 0) ? $ret_val : $default);
}
function get_file($name)
{
if($HTTP_POST_FILES)
return $HTTP_POST_FILES[$name];
else
return $_FILES[$name];
}
function dump_var( $var, $name='Unknown' )
{
echo "Dumping var: $name
";
echo "
";
print_r($var);
echo "
";
}
function dumpVar($var, $name='Unknown')
{
dump_var( $var, $name );
}
function get_file_extension($filename)
{
$pinfo = pathinfo($filename);
return $pinfo['extension'];
}
function set_if_empty( $val1, $val2 )
{
return empty($val1) ? $val2 : $val1;
}
function get_recursive_filelist( $dir, $filter_extensions = array(), $ignore_list = array(), $return_dirs = false )
{
if( $dir[ strlen($dir) - 1 ] != '/' ) $dir .= "/";
if( !is_dir( $dir ) ) return;
$filter_extensions = array_map("strtolower", $filter_extensions);
$d = dir( $dir );
while($file = $d->read())
{
if ($file != "." && $file != ".." )
{
{
if( is_dir( $dir . "$file/" ) && !in_array($dir . $file, $ignore_list) )
{
if( $return_dirs )
$files[] = $dir . "$file";
$sub_dir_files = get_recursive_filelist( $dir . "$file/", $filter_extensions, $ignore_list );
if( is_array($sub_dir_files) )
{
foreach( $sub_dir_files as $f )
{
if( empty($filter_extensions) || in_array(strtolower(get_file_extension($f)), $filter_extensions) )
$files[] = $f;
}
}
}
else
{
if( empty($filter_extensions) || in_array(strtolower(get_file_extension($file)), $filter_extensions) )
$files[] = $dir . $file;
}
}
}
}
return $files;
}
function remove_dir( $dir )
{
if( $dir[ strlen($dir) - 1 ] != '/' ) $dir .= "/";
if( !is_dir( $dir ) ) return;
$d = dir( $dir );
while($file = $d->read()) {
if ($file!= "." && $file!= "..") {
if( is_dir( $dir . "$file/" ) )
remove_dir( $dir . "$file/" );
else
unlink( $dir . $file );
}
}
$d->close();
rmdir( $dir );
}
function add_slashes_array( $arr )
{
foreach( $arr as $key => $val ) {
if ( is_array($val) ) {
$f_arr[$key] = add_slashes_array( $val );
} else {
$f_arr[$key] = addslashes( $val );
}
}
return $f_arr;
}
function highlighting( $arr = array(), $word, $backcolor = "yellow", $fontcolor = "black" )
{
if(count($arr > 0))
{
foreach( $arr as $key => $val )
{
if ( is_array($val) )
{
$f_arr[$key] = highlighting( $val, $word, $backcolor, $fontcolor );
}
else
{
$f_arr[$key] = str_ireplace( $word, "$word", $val );
}
}
}
else
{
return str_ireplace( $word, "$word", $val );
}
return $f_arr;
}
function human_readable_filesize( $size )
{
$units = array(' B', ' KB', ' MB', ' GB', ' TB');
for ($i = 0; $size > 1024; $i++) { $size /= 1024; }
return round($size, 2).$units[$i];
}
//contributed by Roger
//returns true if it is a valid email address format
//false otherwise
function validate_email($email)
{
$regex =
'^'.
'[_a-z0-9-]+'. /* One or more underscore, alphanumeric,
or hyphen charactures. */
'(\.[_a-z0-9-]+)*'. /* Followed by zero or more sets consisting
of a period and one or more underscore,
alphanumeric, or hyphen charactures. */
'@'. /* Followed by an "at" characture. */
'[a-z0-9-]+'. /* Followed by one or more alphanumeric
or hyphen charactures. */
'(\.[a-z0-9-]{2,})+'. /* Followed by one or more sets consisting
of a period and two or more alphanumeric
or hyphen charactures. */
'$';
if (eregi($regex, $email))
{
return true;
}
else
{
return false;
}
}
?>
First Presbyterian Church -