window.location.href='{$url}'"; } else { header("Location: $url"); exit(); } } // Fixes MAGIC_QUOTES function fix_slashes($arr = '') { if(is_null($arr) || $arr == '') return null; if(!get_magic_quotes_gpc()) return $arr; return is_array($arr) ? array_map('fix_slashes', $arr) : stripslashes($arr); } // Simple wrapper for htmlentities function function e($arr = '', $quote_style = "ENT_COMPAT") { if(is_null($arr) || $arr == '') return null; return is_array($arr) ? array_map('e', $arr) : htmlentities($arr); } // Convert from html entities back to regular keyboard-typed characters function html_decode($arr, $quote_style = "ENT_COMPAT") { if(is_null($arr) || $arr == '') return null; /*$trans_table = get_html_translation_table(HTML_ENTITIES, $quote_style); if($trans_table["'"] != ''') $trans_table["'"] = ''';*/ return is_array($arr) ? array_map('html_decode', $arr) : html_entity_decode($arr); } // Prepares $_POST for insertion into database. (de-slashes, converts html entities - while ignoring existing ones...) function prepare_post($allow_html = false) { if(!empty($_POST)) { if($allow_html) { foreach($_POST as $x => $y) { $_POST[$x] = trim(fix_slashes($y)); } } else { foreach($_POST as $x => $y) { $_POST[$x] = trim(e(html_decode(fix_slashes($y)))); } } } } // Tests for a valid email address and optionally tests for valid MX records, too. function valid_email($email, $test_mx = false) { if(eregi("^([_a-z0-9+-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) { if($test_mx) { list( , $domain) = split("@", $email); return getmxrr($domain, $mxrecords); } else return true; } else return false; } function contact_form_spam() { global $phone_number, $organization; $blacklisted_terms = array('seo', 'seo company', 'marketing', 'marketing company', 'internet marketing company'); if((ereg_replace("[^0-9]", "", $phone_number) < 1) || (ereg_replace("[^0-9]", "", $phone_number) == '4234020035')) return true; foreach($blacklisted_terms AS $term) { if(preg_match("/$term/i", $organization)) return true; else $foo = 'foo'; // do nothing. } return false; } // Grabs the contents of a remote URL. Can perform basic authentication if un/pw are provided. function geturl($url, $username = null, $password = null) { if(function_exists('curl_init')) { $ch = curl_init(); if(!is_null($username) && !is_null($password)) curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . base64_encode("$username:$password"))); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729; .NET4.0E)'); $html = curl_exec($ch); curl_close($ch); return $html; } elseif(ini_get('allow_url_fopen') == true) { if(!is_null($username) && !is_null($password)) $url = str_replace("://", "://$username:$password@", $url); $html = file_get_contents($url); return $html; } else { // Cannot open url. Either install curl-php or set allow_url_fopen = true in php.ini return false; } } // Class Autoloader function __autoload($class_name) { require_once DOC_ROOT . '/_includes/class.' . strtolower($class_name) . '.php'; } function match_any($needle, $haystack) { $needle_in_haystack = false; if(is_array($needle)) { foreach($needle AS $need) { if(preg_match("/$need/i", $haystack)) $needle_in_haystack = true; } } else { if(preg_match("/$needle/i", $haystack)) $needle_in_haystack = true; } return ($needle_in_haystack) ? true : false; } ?>