"; var_dump($data); echo ""; } public static function setUrlParam($url, $name, $value) { //does it already have any stuff? if ($pos = strpos($url, '?')) { $vars = substr($url, $pos+1); $url = substr($url, 0, $pos); } //get our params... $getAr = array(); $paramAr = explode('&', $vars); foreach ($paramAr AS $param) { if ($param) { $vars = explode('=', $param); $getAr[$vars[0]] = $vars[1]; } } //set our new one... $getAr[$name] = urlencode($value); //now format that url.... $count = 0; $url .= "?"; foreach ($getAr AS $key => $val) { if ($count) $url .= '&'; $url .= "$key=$val"; $count++; } return $url; } /** * Checks is the provided email address is formally valid * @param string $email email address to be checked * @return true if the email is valid, false otherwise */ public static function isValidEmail($email) { $regexp = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i"; return preg_match($regexp, $email); } /** * draws a clearing div... fuck ie. */ public static function ieDrawClear() { echo "\t
\n"; } /** * This function calls a script and then moves on. The called script *must* call ignore_user_abort() otherwise it will die. * This is used for things that may take a while... like resizing images. */ public static function spawnHttpAsync($page) { $cbSock = fsockopen(SITE_HOSTNAME, 80, $errno, $errstr, 5); if ($cbSock) { $cmd = "GET {$page} HTTP/1.0\r\n"; $cmd .= "Host: " . SITE_HOSTNAME . "\r\n\r\n"; fwrite($cbSock, $cmd); } } /** * This function opens a url and gets its contents... can be tricky in php w/ weird configs */ public static function getUrlContents($link) { $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $link); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); return $file_contents; } /** * This function gets a blurb of text froma larger chunk of text. It strips it of tags and calls nl2br to give it basic formatting. * * @param $text the text to take the blurb from. * @param $length how long of a blurb. default = 255 characters * @param $truncated is a boolean of whether the string was truncated. the variable you pass in @b will be changed! * * @return the possibly truncated string. */ public static function getBlurb($text, $length = 255, &$truncated = null) { //clean it up. $text = strip_tags(trim($text)); //if its shorter or exactly ourlength... use it. if (strlen($text) <= $length) { $blurb = $text; $truncated = false; } //nope, we might truncate else { //search for first space. $pos = strpos($text, " ", $length); //if it didnt get found... it is the thing. if ($pos === false) { $blurb = $text; $truncated = false; } else { $blurb = substr($text, 0, $pos); $truncated = true; } } //send it back formatted. return Linkify::bbcode($blurb); } /** * This function adds a suffix (st, nd, rd, th) to a supplied number. very cool!! * * @param a number to add suffix to. * * @return the number with suffix added. */ public static function getNumberSuffix($n) { $l = substr($n, -1); $m = substr($n, -2); if ($m == '11') return $n . "th"; if ($m == '12') return $n . "th"; if ($m == '13') return $n . "th"; if ($l == 1) return $n . "st"; if ($l == 2) return $n . "nd"; if ($l == 3) return $n . "rd"; else return $n . "th"; } public static function formatPhoneNumber($number) { //remove non number characters $number = preg_replace("/[^0-9]/", "", $number); if (preg_match("/([0-9]{3})([0-9]{3})([0-9]{4})/", $number, $matches)) return "$matches[1].$matches[2].$matches[3]"; return $number; } public static function shellExec($call) { return system($call); } /** * Prevents the current page from being cached in the client's browser. */ public static function noCache() { // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Always modified header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // HTTP/1.1 header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: pre-check=0, post-check=0", false); // HTTP/1.0 header("Pragma: no-cache"); } /** * Pluralizes the given string. If @c $amount is not @c null, it is a numeric * quantity that determines whether the string is pluralized or not. If @c * $num is not @c false, then the number is prepended to the string. If @c * $num is @c -1, then HTML entities are used to represent fractional numbers. * * @param $str the string to pluralize * @param $amount the numeric quantity (default: @c null) * @param $num @c true if @c $amount should be prepended to the result, and @c * -1 if @c $amount should use HTML entities * @return the pluralized string, optionally included numbers */ public static function pluralize($str, $amount = null, $num = false) { if ($num) { if ($amount) { if ($num === -1) { $whole = (int)$amount; $prefix = $whole ? $whole . " " : ""; $frac = $amount - $whole; if ($frac) { if ($frac == 0.25) $prefix .= "¼ "; else if ($frac == 0.50) $prefix .= "½ "; else if ($frac == 0.75) $prefix .= "¾ "; else $prefix = "$amount "; } } else $prefix = "$amount "; } else $prefix = "0 "; } else $prefix = ""; if ($amount !== null && abs($amount) == 1) return $prefix . $str; // Simple pluralization rules. Add more rules or exceptions as needed. if (substr($str, -1) == "s") return $prefix . $str . "es"; if (substr($str, -1) == "y" && $str != 'day') return $prefix . substr($str, 0, -1) . "ies"; if (substr($str, -1) == "f") return $prefix . substr($str, 0, -1) . "ves"; return $prefix . $str . "s"; } } ?>