]>
src.bluestatic.org Git - isso.git/blob - functions.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2003-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2003 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
13 $OBJECT = 'Core Functions';
18 * Globalized function framework
20 * This framework is a set of functions that are commonly used in most
23 * @author Iris Studios, Inc.
24 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
31 * Global environment variables
33 * @var cookiepath The path for cookies
34 * @var cookiedom Cookie domain
35 * @var cookieexp The time in which a cookie will expire
36 * @var bgcolour Current background colour of the alternation system
38 var $cookiepath = '/';
44 * Sets a cookie with a friendly interface
46 * @param str The name of the cookie
47 * @param str Value of the cookie
48 * @param bool Is the cookie going to stay for a while?
50 function cookie($name, $value = '', $sticky = true)
55 setcookie($name, $value, time() - (2 * $this->cookieexp
), $this->cookiepath
, $this->cookiedom
);
62 $expire = time() +
60 * 60 * 24 * 365;
66 $expire = time() +
$this->cookieexp
;
69 setcookie($name, $value, $expire, $this->cookiepath
, $this->cookiedom
);
74 * Alternate between two background colours
76 * @param str First CSS class name
77 * @param str Second CSS class name
79 function exec_swap_bg($class1 = 'alt1', $class2 = 'alt2')
83 $this->bgcolour
= iff($count %
2, $class1, $class2);
88 * Force-download a file by sending application/octetstream
90 * @param str The text of the file to be streamed
91 * @param str File name of the new file
93 function download_file($file, $name)
95 if ($this->is_browser('ie') OR $this->is_browser('opera') OR $this->is_browser('safari'))
97 $mime = 'application/octetstream';
101 $mime = 'application/octet-stream';
104 header("Content-Type: $mime");
105 header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
106 header('Content-Disposition: attachment; filename="' . $name . '"');
107 header('Content-length: ' . strlen($file));
108 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
109 header('Pragma: public');
116 * Verify that an email address is valid via regex
118 * @param str An email address
120 * @return bool Validity of the email address
122 function is_valid_email($email)
124 if (preg_match('#^[a-z0-9\.\-\+_]+?@(.*?\.)*?[a-z0-9\-_]+?\.[a-z]{2,4}$#i', $email))
135 * Check a browser's user agent against a pre-determined list
137 * @param str Browser name
138 * @param str The browser's version
140 * @param mixed False if there is no match, the version if there is
142 function is_browser($check, $version = '')
144 $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
148 // -------------------------------------------------------------------
150 // -------------------------------------------------------------------
151 # Opera/6.05 (Windows 98; U) [en]
152 # Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 6.0 [en]
153 # Mozilla/5.0 (Windows 98; U) Opera 6.0 [en]
154 # Mozilla/4.0 (compatible; MSIE, 6.0; Windows 98) Opera 7.0 [en]
155 if (preg_match('#opera ([0-9\.]+)#', $useragent, $matches) !== false)
157 if (isset($matches[1]))
159 $browser['opera'] = $matches[1];
163 // -------------------------------------------------------------------
165 // -------------------------------------------------------------------
166 if (strpos($useragent, 'mac') !== false)
168 $browser['mac'] = true;
171 // -------------------------------------------------------------------
172 // -- Internet explorer
173 // -------------------------------------------------------------------
174 # Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1; .NET CLR 1.0.2914)
175 # Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
176 if (preg_match('#msie ([0-9\.]+)#', $useragent, $matches) !== false AND !isset($browser['opera']))
178 if (isset($matches[1]))
180 $browser['ie'] = $matches[1];
184 // -------------------------------------------------------------------
186 // -------------------------------------------------------------------
187 # Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9
188 if (preg_match('#safari/([0-9\.]+)#', $useragent, $matches) !== false)
190 if (isset($matches[1]))
192 $browser['safari'] = $matches[1];
196 // -------------------------------------------------------------------
198 // -------------------------------------------------------------------
199 # Mozilla/5.0 (compatible; Konqueror/3)
200 # Mozilla/5.0 (compatible; Konqueror/3.1; i686 Linux; 20020628)
201 if (preg_match('#konqueror/([0-9\.]+)#', $useragent, $matches) !== false)
203 if (isset($matches[1]))
205 $browser['konqueror'] = $matches[1];
209 // -------------------------------------------------------------------
211 // -------------------------------------------------------------------
212 # Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101
213 # Mozilla/5.001 (Macintosh; N; PPC; ja) Gecko/25250101 MegaCorpBrowser/1.0 (MegaCorp, Inc.)
214 if (preg_match('#gecko/([0-9]+)#', $useragent, $matches) !== false AND !isset($browser['safari']))
216 if (isset($matches[1]))
218 $browser['mozilla'] = $matches[1];
221 // -------------------------------------------------------------------
223 // -------------------------------------------------------------------
224 # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040628 Firefox/0.9.1
225 # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4a) Gecko/20030423 Firebird Browser/0.6
226 if (preg_match('#(firebird|firefox)( browser)?/([0-9\.]+)#', $useragent, $matches) !== false)
228 if (isset($matches[3]))
230 $browser['firefox'] = $matches[3];
234 // -------------------------------------------------------------------
236 // -------------------------------------------------------------------
237 # Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:0.9.4.1) Gecko/20020318 Netscape6/6.2.2
238 if (preg_match('#netscape([0-9].*?)?/([0-9\.]+)#', $useragent, $matches) !== false)
240 if (isset($matches[2]))
242 $browser['netscape'] = $matches[2];
246 // -------------------------------------------------------------------
248 // -------------------------------------------------------------------
249 # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040623 Camino/0.8
250 if (preg_match('#camino/([0-9\.]+)#', $useragent, $matches) !== false)
252 if (isset($matches[1]))
254 $browser['camino'] = $matches[1];
259 if (isset($browser["$check"]))
263 if ($browser["$check"] >= $version)
265 return $browser["$check"];
274 return $browser["$check"];
284 /*=====================================================================*\
285 || ###################################################################
288 || ###################################################################
289 \*=====================================================================*/