]>
src.bluestatic.org Git - bugdar.git/blob - functions.php
d090ad492061ebfbf9c6bc0d842a2d4504f0b195
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # [#]app[#] [#]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 // ########################### Start phrase ##########################
18 $args = func_get_args();
19 $numargs = count($args);
26 if ($phrasetext = $bugsys->language
["$args[0]"])
30 $phrase = $phrasetext;
34 if (!($phrase = @call_user_func_array('sprintf', $args)))
36 for ($i = 1; $i < $numargs; $i++
)
38 $phrase = str_replace("%{$i}\$s", $args["$i"], $phrase);
42 return preg_replace('#%([0-9].*?)\$s#', '<strong>[ARG \1: UNDEFINED]</strong>', $phrase);
46 return "<strong
>[UNDEFINED PHRASE
: $args[0]]</strong
>";
50 // ########################## Start sanitize #########################
51 function sanitize($toclean)
55 foreach ($toclean AS $varname => $cleaner)
57 $varvalue = $_REQUEST["$varname"];
58 switch (strtoupper($cleaner))
61 $cleaned = trim($varvalue);
65 $cleaned = htmlspecialcharslike(trim($varvalue));
69 $cleaned = intval($varvalue);
73 $cleaned = floatval($varvalue);
78 $vars["$varname"] = $cleaned;
82 // ##################### Start fetch_random_chars ####################
83 function fetch_random_chars($length = 0)
88 $length = rand(20, 65);
91 // Number of ints in our salt
92 $intcount = rand(0, intval($length / 2));
95 $charcount = $length - $intcount;
98 $upperchars = rand(1, intval($charcount / 2));
101 $lowerchars = $charcount - $upperchars;
104 for ($i = 0; $i < $intcount; $i++)
106 $string[] = rand(0, 9);
109 // Generate upper chars
110 for ($i = 0; $i < $upperchars; $i++)
112 $string[] = chr(rand(65, 90));
115 // Generate lower chars
116 for ($i = 0; $i < $lowerchars; $i++)
118 $string[] = chr(rand(97, 122));
121 // Randomly key the chars
122 foreach ($string AS $char)
125 $newstr["$rand"] = $char;
128 // Sort the chars by thier random assignment
133 foreach ($newstr AS $char)
141 // ######################## Start mysetcookie ########################
142 function mysetcookie($name, $value = false, $sticky = true)
144 // Expire the cookie if it doesn't have a value
147 setcookie($name, $value, time() - (2 * 900), '/');
151 // Make the cookie one that stays?
154 $expire = time() +
60 * 60 * 24 * 365;
160 setcookie($name, $value, $expire, '/');
164 // ############################ Start iff ############################
165 function iff($condition, $true, $false = null)
167 return ($condition) ? ($true) : ($false);
170 // ######################## Start exec_swap_bg #######################
171 function exec_swap_bg($class1 = 'alt1', $class2 = 'alt2')
176 $row_class = iff($row_count %
2, $class1, $class2);
180 // ####################### Start addslasheslike ######################
181 // leave this named as such for easy typing
182 function addslasheslike($str)
188 $mqgpc = get_magic_quotes_gpc();
197 return addslashes($str);
201 // #################### Start htmlspecialcharslike ###################
202 function htmlspecialcharslike($str)
204 return str_replace(array('"', '<', '>'), array('"', '<', '>'), $str);
207 // ##################### Start unhtmlspecialchars ####################
208 function unhtmlspecialchars($str)
210 return str_replace(array('"', '<', '>'), array('"', '<', '>'), $str);
213 // ################## Start fetch_user_display_name ##################
214 // preps a dispaly name if one isn't set
215 // should be able to be removed by the final version as registration should set this
216 function fetch_user_display_name(&$userinfo)
218 if (!$userinfo['displayname'])
220 $userinfo['displayname'] = ucwords(trim(str_replace(array('@', '.com', '.net', '.edu', '.org', '.info', '.biz'), ' ', $userinfo['email'])));
224 // ################## Start construct_option_select ##################
225 // creates a <select> menu from an array
226 // key vars are used when you need to get data out of the $label array
227 function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false)
229 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
230 if ($includenil !== false)
232 $opts[] = '<option value="' . $includenil . '"' . iff(!$selected, ' selected="selected"') . '>Not Selected</option>';
234 foreach ($array AS $value => $label)
236 $opts[] = '<option value="' . iff($valuekey, $label["$valuekey"], $value) . '"' . iff($selected == iff($valuekey, $label["$valuekey"], $value), ' selected
="selected"') . '>' . iff($labelkey, $label["$labelkey"], $label) . '</option
>';
238 return '<select name
="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
241 // ########################## Start datelike #########################
242 function datelike($format, $timestamp)
246 if (!$format OR $format == 'standard
')
248 $format = $bugsys->options['dateformat
'];
251 return date($format, ($timestamp + (60 * $bugsys->userinfo['timezone
'])));
254 // ################### Start construct_user_display ##################
255 // $userinfo needs userid, email, displayname, and showemail
256 function construct_user_display($userinfo, $userid = true)
258 fetch_user_display_name($userinfo);
259 return "$userinfo[displayname]" . iff($userinfo['showemail
'], " <$userinfo[email]>") . iff($userid, " (userid: $userinfo[userid])");
262 // ######################## Start can_perform ########################
263 // short-hand for bitwise &
264 function can_perform($bitmask, $userinfo = null)
270 return ($bugsys->userinfo['permissions
'] & $_PERMISSION["$bitmask"]);
272 return ($userinfo['permissions
'] & $_PERMISSION["bitmask"]);
275 /*=====================================================================*\
276 || ###################################################################
279 || ###################################################################
280 \*=====================================================================*/