= $version) { return $browser["$check"]; } else { return false; } } else { return $browser["$check"]; } } else { return false; } } // ################################################################### /** * Generates a random string of random length (unless otherwise * specified) * * @param integer Optional length * * @return string A random string */ public static function Random($length = 0) { // custom high and lows if (is_array($length)) { $length = rand($length[0], $length[1]); } else if (!$length) { // Gimme a length! $length = rand(20, 65); } // Number of ints in our salt $intcount = rand(1, intval($length / 2)); // Number of chars $charcount = $length - $intcount; // Upper-case chars $upperchars = rand(1, intval($charcount / 2)); // Lower-case chars $lowerchars = $charcount - $upperchars; // Generate ints for ($i = 0; $i < $intcount; $i++) { $string[ mt_rand() ] = rand(0, 9); } // Generate upper chars for ($i = 0; $i < $upperchars; $i++) { $string[ mt_rand() ] = chr(rand(65, 90)); } // Generate lower chars for ($i = 0; $i < $lowerchars; $i++) { $string[ mt_rand() ] = chr(rand(97, 122)); } if ($length != sizeof($string)) { return $this->rand($length); } // Sort the chars by thier random assignment ksort($string); // Flatten the array $return = ''; foreach ($string AS $char) { $return .= $char; } return $return; } // ################################################################### /** * Sets the current array position to be the specified key. This * function should be avoided on large arrays. * * @param array The array whose counter is to be updated * @param mixed The key of the element of the array that the counter is to be set to * * @return mixed Return the elelment of the array that we just put the counter to */ public static function ArraySetCurrent(&$array, $key) { reset($array); while (current($array) !== false) { if (key($array) == $key) { break; } next($array); } return current($array); } // ################################################################### /** * Calculates the microtime difference by taking a given microtime and * subtracting it from the current one * * @param string The start microtime * * @return float Microtime difference */ public static function FetchMicrotimeDiff($mtstart) { $mtend = microtime(); list ($starttime['micro'], $starttime['sec']) = explode(' ', $mtstart); list ($endtime['micro'], $endtime['sec']) = explode(' ', $mtend); return ($endtime['micro'] + $endtime['sec']) - ($starttime['micro'] + $starttime['sec']); } // ################################################################### /** * Fetches the extension of a file by extracting everything after the * last period * * @param string Filename * * @return string The extension for the specifid file name */ public static function FetchExtension($filename) { return strval(end(explode('.', $filename))); } // ################################################################### /** * Gets the maximum file size for attachment uploading, as specified by * PHP. If no value is present, 10 MB (represented in bytes) is * returned. * * @return integer The maximum file upload size in bytes */ public static function FetchMaxPhpFileSize() { if ($size = @ini_get('upload_max_filesize')) { if (preg_match('#[^0-9].#', $size)) { return $size; } else { return intval($size) * 1048576; } } else { return 10 * 1048576; } } // ################################################################### /** * Scans a specified directory path and returns an array of all the * items in that directory. Directories found by this are end in a "/" * * @param string Path to scan * @param bool Whether or not to recursively scan the directories encountered * @param bool Ignore files beginning with a dot * @param bool Ignore 'CVS' dirctories * * @return array A list of all the files in the specified path */ public static function ScanDirectory($path, $recurse = true, $ignoredot = true, $ignorecvs = true, $basepath = '', $unset = 1) { static $filelist; if ($unset) { $filelist = array(); } if (substr($path, (strlen($path) - 1), 1) != '/') { $path .= '/'; } if ($handle = opendir($path)) { while (($file = readdir($handle)) !== false) { $isdot = ((substr($file, 0, 1) == '.') ? true : false); $isdot = (($ignoredot) ? $isdot : true); $iscvs = (($file == 'CVS') ? true : false); $iscvs = (($ignorecvs) ? $iscvs : true); if (!$isdot AND !$iscvs) { if (is_dir($path . $file)) { $filelist["$basepath"][] = "$file/"; if ($recurse) { self::ScanDirectory("$path$file", true, $ignoredot, $ignorecvs, "$basepath$file/", 0); } } else { $filelist["$basepath"][] = $file; } } } closedir($handle); } return $filelist; } // ################################################################### /** * Changes line breaks into one format * * @param string Text * @param string New line break (default is UNIX \n format) * * @return string Text with one type of line break */ public static function ConvertLineBreaks($text, $convert_to = "\n") { $text = trim($text); $text = str_replace(array("\r\n", "\r", "\n"), "\n", $text); $text = str_replace("\n", $convert_to, $text); return $text; } // ################################################################### /** * Removes all empty() [by PHP's standards] elements in an array. This * can be used in place of using PREG_SPLIT_NO_EMPTY. * * @param array An array to strip empties from * * @return array Full-valued array */ public static function ArrayStripEmpty($array) { foreach ($array AS $key => $value) { if (is_array($array["$key"])) { $array["$key"] = self::ArrayStripEmpty($array["$key"]); } else if (empty($value) OR is_null($value)) { unset($array["$key"]); } } return $array; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>