]>
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 * Simple way to protect against HTML attacks with Unicode support
76 * @param str Unsanitzed text
78 * @return str Properly protected text that only encodes potential threats
80 function sanitize($text)
82 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
86 * Takes text that has been processed for HTML and unsanitizes it
88 * @param str Text that needs to be turned back into HTML
90 * @return str Unsanitized text
92 function unsanitize($text)
94 return str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
98 * Alternate between two background colours
100 * @param str First CSS class name
101 * @param str Second CSS class name
103 function exec_swap_bg($class1 = 'alt1', $class2 = 'alt2')
107 $this->bgcolour
= iff($count %
2, $class1, $class2);
112 * Force-download a file by sending application/octetstream
114 * @param str The text of the file to be streamed
115 * @param str File name of the new file
117 function download_file($file, $name)
119 if ($this->is_browser('ie') OR $this->is_browser('opera') OR $this->is_browser('safari'))
121 $mime = 'application/octetstream';
125 $mime = 'application/octet-stream';
128 header("Content-Type: $mime");
129 header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
130 header('Content-Disposition: attachment; filename="' . $name . '"');
131 header('Content-length: ' . strlen($file));
132 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
133 header('Pragma: public');
140 * Verify that an email address is valid via regex
142 * @param str An email address
144 * @return bool Validity of the email address
146 function is_valid_email($email)
148 if (preg_match('#^[a-z0-9\.\-\+_]+?@(.*?\.)*?[a-z0-9\-_]+?\.[a-z]{2,4}$#i', $email))
159 * Check a browser's user agent against a pre-determined list
161 * @param str Browser name
162 * @param str The browser's version
164 * @param mixed False if there is no match, the version if there is
166 function is_browser($check, $version = '')
168 $useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
172 // -------------------------------------------------------------------
174 // -------------------------------------------------------------------
175 # Opera/6.05 (Windows 98; U) [en]
176 # Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 6.0 [en]
177 # Mozilla/5.0 (Windows 98; U) Opera 6.0 [en]
178 # Mozilla/4.0 (compatible; MSIE, 6.0; Windows 98) Opera 7.0 [en]
179 if (preg_match('#opera ([0-9\.]+)#', $useragent, $matches) !== false)
181 if (isset($matches[1]))
183 $browser['opera'] = $matches[1];
187 // -------------------------------------------------------------------
189 // -------------------------------------------------------------------
190 if (strpos($useragent, 'mac') !== false)
192 $browser['mac'] = true;
195 // -------------------------------------------------------------------
196 // -- Internet explorer
197 // -------------------------------------------------------------------
198 # Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1; .NET CLR 1.0.2914)
199 # Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
200 if (preg_match('#msie ([0-9\.]+)#', $useragent, $matches) !== false AND !isset($browser['opera']))
202 if (isset($matches[1]))
204 $browser['ie'] = $matches[1];
208 // -------------------------------------------------------------------
210 // -------------------------------------------------------------------
211 # Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9
212 if (preg_match('#safari/([0-9\.]+)#', $useragent, $matches) !== false)
214 if (isset($matches[1]))
216 $browser['safari'] = $matches[1];
220 // -------------------------------------------------------------------
222 // -------------------------------------------------------------------
223 # Mozilla/5.0 (compatible; Konqueror/3)
224 # Mozilla/5.0 (compatible; Konqueror/3.1; i686 Linux; 20020628)
225 if (preg_match('#konqueror/([0-9\.]+)#', $useragent, $matches) !== false)
227 if (isset($matches[1]))
229 $browser['konqueror'] = $matches[1];
233 // -------------------------------------------------------------------
235 // -------------------------------------------------------------------
236 # Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101
237 # Mozilla/5.001 (Macintosh; N; PPC; ja) Gecko/25250101 MegaCorpBrowser/1.0 (MegaCorp, Inc.)
238 if (preg_match('#gecko/([0-9]+)#', $useragent, $matches) !== false AND !isset($browser['safari']))
240 if (isset($matches[1]))
242 $browser['mozilla'] = $matches[1];
245 // -------------------------------------------------------------------
247 // -------------------------------------------------------------------
248 # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040628 Firefox/0.9.1
249 # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4a) Gecko/20030423 Firebird Browser/0.6
250 if (preg_match('#(firebird|firefox)( browser)?/([0-9\.]+)#', $useragent, $matches) !== false)
252 if (isset($matches[3]))
254 $browser['firefox'] = $matches[3];
258 // -------------------------------------------------------------------
260 // -------------------------------------------------------------------
261 # Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:0.9.4.1) Gecko/20020318 Netscape6/6.2.2
262 if (preg_match('#netscape([0-9].*?)?/([0-9\.]+)#', $useragent, $matches) !== false)
264 if (isset($matches[2]))
266 $browser['netscape'] = $matches[2];
270 // -------------------------------------------------------------------
272 // -------------------------------------------------------------------
273 # Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040623 Camino/0.8
274 if (preg_match('#camino/([0-9\.]+)#', $useragent, $matches) !== false)
276 if (isset($matches[1]))
278 $browser['camino'] = $matches[1];
283 if (isset($browser["$check"]))
287 if ($browser["$check"] >= $version)
289 return $browser["$check"];
298 return $browser["$check"];
308 /*=====================================================================*\
309 || ###################################################################
312 || ###################################################################
313 \*=====================================================================*/