cookieexp), $this->cookiepath, $this->cookiedom); } // set the cookie else { if ($sticky) { $expire = time() + 60 * 60 * 24 * 365; } else { $expire = time() + $this->cookieexp; } setcookie($name, $value, $expire, $this->cookiepath, $this->cookiedom); } } /** * Alternate between two background colours * * @param str First CSS class name * @param str Second CSS class name */ function exec_swap_bg($class1 = 'alt1', $class2 = 'alt2') { static $count; $this->bgcolour = iff($count % 2, $class1, $class2); $count++; } /** * Force-download a file by sending application/octetstream * * @param str The text of the file to be streamed * @param str File name of the new file */ function download_file($file, $name) { if ($this->is_browser('ie') OR $this->is_browser('opera') OR $this->is_browser('safari')) { $mime = 'application/octetstream'; } else { $mime = 'application/octet-stream'; } header("Content-Type: $mime"); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: attachment; filename="' . $name . '"'); header('Content-length: ' . strlen($file)); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); print($file); exit; } /** * Verify that an email address is valid via regex * * @param str An email address * * @return bool Validity of the email address */ function is_valid_email($email) { if (preg_match('#^[a-z0-9\.\-\+_]+?@(.*?\.)*?[a-z0-9\-_]+?\.[a-z]{2,4}$#i', $email)) { return true; } else { return false; } } /** * Check a browser's user agent against a pre-determined list * * @param str Browser name * @param str The browser's version * * @param mixed False if there is no match, the version if there is */ function is_browser($check, $version = '') { $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); $browser = array(); $matches = array(); // ------------------------------------------------------------------- // -- Opera // ------------------------------------------------------------------- # Opera/6.05 (Windows 98; U) [en] # Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 6.0 [en] # Mozilla/5.0 (Windows 98; U) Opera 6.0 [en] # Mozilla/4.0 (compatible; MSIE, 6.0; Windows 98) Opera 7.0 [en] if (preg_match('#opera ([0-9\.]+)#', $useragent, $matches) !== false) { if (isset($matches[1])) { $browser['opera'] = $matches[1]; } } // ------------------------------------------------------------------- // -- Mac browser // ------------------------------------------------------------------- if (strpos($useragent, 'mac') !== false) { $browser['mac'] = true; } // ------------------------------------------------------------------- // -- Internet explorer // ------------------------------------------------------------------- # Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1; .NET CLR 1.0.2914) # Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) if (preg_match('#msie ([0-9\.]+)#', $useragent, $matches) !== false AND !isset($browser['opera'])) { if (isset($matches[1])) { $browser['ie'] = $matches[1]; } } // ------------------------------------------------------------------- // -- Safari // ------------------------------------------------------------------- # Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9 if (preg_match('#safari/([0-9\.]+)#', $useragent, $matches) !== false) { if (isset($matches[1])) { $browser['safari'] = $matches[1]; } } // ------------------------------------------------------------------- // -- Konqueror // ------------------------------------------------------------------- # Mozilla/5.0 (compatible; Konqueror/3) # Mozilla/5.0 (compatible; Konqueror/3.1; i686 Linux; 20020628) if (preg_match('#konqueror/([0-9\.]+)#', $useragent, $matches) !== false) { if (isset($matches[1])) { $browser['konqueror'] = $matches[1]; } } // ------------------------------------------------------------------- // -- Mozilla // ------------------------------------------------------------------- # Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101 # Mozilla/5.001 (Macintosh; N; PPC; ja) Gecko/25250101 MegaCorpBrowser/1.0 (MegaCorp, Inc.) if (preg_match('#gecko/([0-9]+)#', $useragent, $matches) !== false AND !isset($browser['safari'])) { if (isset($matches[1])) { $browser['mozilla'] = $matches[1]; } // ------------------------------------------------------------------- // -- Firefox // ------------------------------------------------------------------- # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040628 Firefox/0.9.1 # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4a) Gecko/20030423 Firebird Browser/0.6 if (preg_match('#(firebird|firefox)( browser)?/([0-9\.]+)#', $useragent, $matches) !== false) { if (isset($matches[3])) { $browser['firefox'] = $matches[3]; } } // ------------------------------------------------------------------- // -- Netscape // ------------------------------------------------------------------- # Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:0.9.4.1) Gecko/20020318 Netscape6/6.2.2 if (preg_match('#netscape([0-9].*?)?/([0-9\.]+)#', $useragent, $matches) !== false) { if (isset($matches[2])) { $browser['netscape'] = $matches[2]; } } // ------------------------------------------------------------------- // -- Camino // ------------------------------------------------------------------- # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040623 Camino/0.8 if (preg_match('#camino/([0-9\.]+)#', $useragent, $matches) !== false) { if (isset($matches[1])) { $browser['camino'] = $matches[1]; } } } if (isset($browser["$check"])) { if ($version) { if ($browser["$check"] >= $version) { return $browser["$check"]; } else { return false; } } else { return $browser["$check"]; } } else { return false; } } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>