2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Renapsus [#]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 = sizeof($args);
26 if ($phrasetext = $bugsys->language
["$args[0]"])
30 $phrase = $phrasetext;
34 $args[0] = $phrasetext;
35 if (($phrase = @call_user_func_array('sprintf', $args)) === false
)
37 for ($i = 1; $i < $numargs; $i++
)
39 $phrase = str_replace("%{$i}\$s", $args["$i"], $args[0]);
43 return preg_replace('#%([0-9].*?)\$s#', '<strong>[ARG \\1: UNDEFINED]</strong>', $phrase);
47 return "<strong>[UNDEFINED PHRASE: $args[0]]</strong>";
51 // ########################## Start sanitize #########################
52 function sanitize($toclean)
56 foreach ($toclean AS $varname => $cleaner)
58 $varvalue = $_REQUEST["$varname"];
59 switch (strtoupper($cleaner))
62 $cleaned = trim($varvalue);
66 $cleaned = htmlspecialcharslike(trim($varvalue));
70 $cleaned = intval($varvalue);
74 $cleaned = floatval($varvalue);
79 $vars["$varname"] = $cleaned;
83 // ##################### Start fetch_random_chars ####################
84 function fetch_random_chars($length = 0)
89 $length = rand(20, 65);
92 // Number of ints in our salt
93 $intcount = rand(0, intval($length / 2));
96 $charcount = $length - $intcount;
99 $upperchars = rand(1, intval($charcount / 2));
102 $lowerchars = $charcount - $upperchars;
105 for ($i = 0; $i < $intcount; $i++
)
107 $string[] = rand(0, 9);
110 // Generate upper chars
111 for ($i = 0; $i < $upperchars; $i++
)
113 $string[] = chr(rand(65, 90));
116 // Generate lower chars
117 for ($i = 0; $i < $lowerchars; $i++
)
119 $string[] = chr(rand(97, 122));
122 // Randomly key the chars
123 foreach ($string AS $char)
126 $newstr["$rand"] = $char;
129 // Sort the chars by thier random assignment
134 foreach ($newstr AS $char)
142 // ######################## Start mysetcookie ########################
143 function mysetcookie($name, $value = false
, $sticky = true
)
145 // Expire the cookie if it doesn't have a value
148 setcookie($name, $value, time() - (2 * 900), '/');
152 // Make the cookie one that stays?
155 $expire = time() +
60 * 60 * 24 * 365;
161 setcookie($name, $value, $expire, '/');
165 // ############################ Start iff ############################
166 function iff($condition, $true, $false = null
)
168 return ($condition) ?
($true) : ($false);
171 // ######################## Start exec_swap_bg #######################
172 function exec_swap_bg($class1 = 'alt1', $class2 = 'alt2')
177 $row_class = iff($row_count %
2, $class1, $class2);
181 // ####################### Start addslasheslike ######################
182 // leave this named as such for easy typing
183 function addslasheslike($str)
189 $mqgpc = get_magic_quotes_gpc();
198 return addslashes($str);
202 // #################### Start htmlspecialcharslike ###################
203 function htmlspecialcharslike($str)
205 return str_replace(array('"', '<', '>'), array('"', '<', '>'), $str);
208 // ##################### Start unhtmlspecialchars ####################
209 function unhtmlspecialchars($str)
211 return str_replace(array('"', '<', '>'), array('"', '<', '>'), $str);
214 // ################## Start fetch_user_display_name ##################
215 // preps a dispaly name if one isn't set
216 // should be able to be removed by the final version as registration should set this
217 function fetch_user_display_name(&$userinfo)
219 if (!$userinfo['displayname'])
221 $userinfo['displayname'] = ucwords(trim(str_replace(array('@', '.com', '.net', '.edu', '.org', '.info', '.biz'), ' ', $userinfo['email'])));
225 // ################## Start construct_option_select ##################
226 // creates a <select> menu from an array
227 // key vars are used when you need to get data out of the $label array
228 function construct_option_select($name, $array, $selected = 0, $valuekey = '', $labelkey = '', $includenil = false
)
230 // if we're not working on a boolean false, we use it for the value (allows -1 and 0)
231 if ($includenil !== false
)
233 $opts[] = '<option value="' . $includenil . '"' . iff(!$selected, ' selected="selected"') . '>Not Selected</option>';
235 foreach ($array AS $value => $label)
237 $opts[] = '<option value="' . iff($valuekey, $label["$valuekey"], $value) . '"' . iff($selected == iff($valuekey, $label["$valuekey"], $value), ' selected="selected"') . '>' . iff($labelkey, $label["$labelkey"], $label) . '</option>';
239 return '<select name="' . $name . '">' . implode("\n\t", $opts) . "\r</select>";
242 // ########################## Start datelike #########################
243 function datelike($format, $timestamp)
247 if (!$format OR $format == 'standard')
249 $format = $bugsys->options
['dateformat'];
252 return date($format, ($timestamp +
(60 * $bugsys->userinfo
['timezone'])));
255 // ################### Start construct_user_display ##################
256 // $userinfo needs userid, email, displayname, and showemail
257 function construct_user_display($userinfo, $userid = true
)
259 fetch_user_display_name($userinfo);
260 return "$userinfo[displayname]" . iff($userinfo['showemail'], " <$userinfo[email]>") . iff($userid, " (userid: $userinfo[userid])");
263 // ######################## Start can_perform ########################
264 // short-hand for bitwise &
265 function can_perform($bitmask, $userinfo = null
)
271 return ($bugsys->userinfo
['permissions'] & $_PERMISSION["$bitmask"]);
273 return ($userinfo['permissions'] & $_PERMISSION["bitmask"]);
276 // #################### Start construct_pcv_select ###################
277 // constructs a product/component/version select with one go :-)
278 function construct_pcv_select($type = 'radio', $prefix = ' ')
280 global $bugsys, $DB_sql, $tpl;
288 $row['typeselect'] = $type;
290 $products_fetch = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX
. "product ORDER BY displayorder ASC");
291 while ($product = $DB_sql->fetch_array($products_fetch))
293 if ($product['componentmother'])
295 $components["$product[componentmother]"]["$product[productid]"] = $product;
299 $products["$product[productid]"] = $product;
303 $versions_fetch = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX
. "version ORDER BY displayorder");
304 while ($version = $DB_sql->fetch_array($versions_fetch))
306 $versions["$version[productid]"]["$version[versionid]"] = $version;
309 foreach ($products AS $product)
312 $valuepfx = "p$product[productid]";
313 $row['value'] = "{$valuepfx}c0v0";
314 $row['title'] = "<strong>$product[title]</strong>";
315 $row['description'] = '';
316 eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";');
317 $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $type);
318 if (is_array($versions["$product[productid]"]))
320 foreach ($versions["$product[productid]"] AS $version)
322 $row['prefix'] = $prefix . $prefix;
323 $row['typeselect'] = $type;
324 $row['value'] = "{$valuepfx}c0v$version[versionid]";
325 $row['title'] = $version['version'];
326 eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";');
330 if (is_array($components["$product[productid]"]))
332 foreach ($components["$product[productid]"] AS $component)
334 $row['prefix'] = $prefix;
335 $valuepfx .= "c$component[productid]";
336 $row['value'] = "{$valuepfx}v0";
337 $row['title'] = $component['title'];
338 $row['description'] = '';
339 eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";');
340 $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $type);;
341 if (is_array($versions["$component[productid]"]))
343 foreach ($versions["$component[productid]"] AS $version)
345 $row['prefix'] = $prefix . $prefix;
346 $row['value'] = "$valuepfx$version[versionid]";
347 $row['title'] = $version['version'];
348 $row['description'] = '';
349 eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";');
359 // ############ Start construct_pcv_select_global_version ############
360 function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $type)
363 if (is_array($versions['0']))
365 foreach ($versions['0'] AS $version)
367 $row['prefix'] = $prefix . $prefix;
368 $row['typeselect'] = $type;
369 $row['value'] = "p{$product}c{$component}v$version[versionid]";
370 $row['title'] = $version['version'];
371 $row['description'] = '';
372 eval('$global_versions_html .= "' . $tpl->fetch('pcv_select_row') . '";');
375 return $global_versions_html;
378 /*=====================================================================*\
379 || ###################################################################
382 || ###################################################################
383 \*=====================================================================*/