language["$args[0]"]) { if ($numargs < 2) { $phrase = $phrasetext; } else { $args[0] = $phrasetext; if (($phrase = @call_user_func_array('sprintf', $args)) === false) { for ($i = 1; $i < $numargs; $i++) { $phrase = str_replace("%{$i}\$s", $args["$i"], $args[0]); } } } return preg_replace('#%([0-9].*?)\$s#', '[ARG \\1: UNDEFINED]', $phrase); } else { return "[UNDEFINED PHRASE: $args[0]]"; } } // ########################## Start sanitize ######################### function sanitize($toclean) { global $vars; foreach ($toclean AS $varname => $cleaner) { $varvalue = $_REQUEST["$varname"]; switch (strtoupper($cleaner)) { case 'STR': $cleaned = trim($varvalue); break; case 'STR_NOHTML': $cleaned = htmlspecialcharslike(trim($varvalue)); break; case 'INT': $cleaned = intval($varvalue); break; case 'FLOAT': $cleaned = floatval($varvalue); break; default: break; } $vars["$varname"] = $cleaned; } } // ##################### Start fetch_random_chars #################### function fetch_random_chars($length = 0) { // Gimme a length! if (!$length) { $length = rand(20, 65); } // Number of ints in our salt $intcount = rand(0, intval($length / 2)); // Number of chars $charcount = $length - $intcount; // Upper-case chars $upperchars = rand(1, intval($charcount / 2)); // Lower-case chars $lowerchars = $charcount - $upperchars; // Generate ints for ($i = 0; $i < $intcount; $i++) { $string[] = rand(0, 9); } // Generate upper chars for ($i = 0; $i < $upperchars; $i++) { $string[] = chr(rand(65, 90)); } // Generate lower chars for ($i = 0; $i < $lowerchars; $i++) { $string[] = chr(rand(97, 122)); } // Randomly key the chars foreach ($string AS $char) { $rand = mt_rand(); $newstr["$rand"] = $char; } // Sort the chars by thier random assignment ksort($newstr); // Flatten the array $string = ''; foreach ($newstr AS $char) { $string .= $char; } return $string; } // ######################## Start mysetcookie ######################## function mysetcookie($name, $value = false, $sticky = true) { // Expire the cookie if it doesn't have a value if (!$value) { setcookie($name, $value, time() - (2 * 900), '/'); } else { // Make the cookie one that stays? if ($sticky) { $expire = time() + 60 * 60 * 24 * 365; } else { $expire = 0; } setcookie($name, $value, $expire, '/'); } } // ############################ Start iff ############################ function iff($condition, $true, $false = null) { return ($condition) ? ($true) : ($false); } // ######################## Start exec_swap_bg ####################### function exec_swap_bg($class1 = 'alt1', $class2 = 'alt2') { global $row_class; static $row_count; $row_class = iff($row_count % 2, $class1, $class2); $row_count++; } // ####################### Start addslasheslike ###################### // leave this named as such for easy typing function addslasheslike($str) { static $mqgpc; if (!isset($mqgpc)) { $mqgpc = get_magic_quotes_gpc(); } if ($mqgpc) { return $str; } else { return addslashes($str); } } // #################### Start htmlspecialcharslike ################### function htmlspecialcharslike($str) { return str_replace(array('"', '<', '>'), array('"', '<', '>'), $str); } // ##################### Start unhtmlspecialchars #################### function unhtmlspecialchars($str) { return str_replace(array('"', '<', '>'), array('"', '<', '>'), $str); } // ################## Start fetch_user_display_name ################## // preps a dispaly name if one isn't set // should be able to be removed by the final version as registration should set this function fetch_user_display_name(&$userinfo) { if (!$userinfo['displayname']) { $userinfo['displayname'] = ucwords(trim(str_replace(array('@', '.com', '.net', '.edu', '.org', '.info', '.biz'), ' ', $userinfo['email']))); } } // ################## Start construct_option_select ################## // creates a ' . implode("\n\t", $opts) . "\r"; } // ########################## Start datelike ######################### function datelike($format, $timestamp) { global $bugsys; if (!$format OR $format == 'standard') { $format = $bugsys->options['dateformat']; } return date($format, ($timestamp + (60 * $bugsys->userinfo['timezone']))); } // ################### Start construct_user_display ################## // $userinfo needs userid, email, displayname, and showemail function construct_user_display($userinfo, $userid = true) { fetch_user_display_name($userinfo); return "$userinfo[displayname]" . iff($userinfo['showemail'], " <$userinfo[email]>") . iff($userid, " (userid: $userinfo[userid])"); } // ######################## Start can_perform ######################## // short-hand for bitwise & function can_perform($bitmask, $userinfo = null) { global $_PERMISSION; if (!$userinfo) { global $bugsys; return ($bugsys->userinfo['permissions'] & $_PERMISSION["$bitmask"]); } return ($userinfo['permissions'] & $_PERMISSION["bitmask"]); } // #################### Start construct_pcv_select ################### // constructs a product/component/version select with one go :-) function construct_pcv_select($type = 'radio', $prefix = '     ') { global $bugsys, $DB_sql, $tpl; static $HTML; if ($HTML) { return $HTML; } $row['typeselect'] = $type; $products_fetch = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC"); while ($product = $DB_sql->fetch_array($products_fetch)) { if ($product['componentmother']) { $components["$product[componentmother]"]["$product[productid]"] = $product; } else { $products["$product[productid]"] = $product; } } $versions_fetch = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder"); while ($version = $DB_sql->fetch_array($versions_fetch)) { $versions["$version[productid]"]["$version[versionid]"] = $version; } foreach ($products AS $product) { $row['prefix'] = ''; $valuepfx = "p$product[productid]"; $row['value'] = "{$valuepfx}c0v0"; $row['title'] = "$product[title]"; $row['description'] = ''; eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";'); $HTML .= construct_pcv_select_global_version($product['productid'], 0, $versions, $prefix, $type); if (is_array($versions["$product[productid]"])) { foreach ($versions["$product[productid]"] AS $version) { $row['prefix'] = $prefix . $prefix; $row['typeselect'] = $type; $row['value'] = "{$valuepfx}c0v$version[versionid]"; $row['title'] = $version['version']; eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";'); } } if (is_array($components["$product[productid]"])) { foreach ($components["$product[productid]"] AS $component) { $row['prefix'] = $prefix; $valuepfx .= "c$component[productid]"; $row['value'] = "{$valuepfx}v0"; $row['title'] = $component['title']; $row['description'] = ''; eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";'); $HTML .= construct_pcv_select_global_version($component['componentmother'], $component['productid'], $versions, $prefix, $type);; if (is_array($versions["$component[productid]"])) { foreach ($versions["$component[productid]"] AS $version) { $row['prefix'] = $prefix . $prefix; $row['value'] = "$valuepfx$version[versionid]"; $row['title'] = $version['version']; $row['description'] = ''; eval('$HTML .= "' . $tpl->fetch('pcv_select_row') . '";'); } } } } } return $HTML; } // ############ Start construct_pcv_select_global_version ############ function construct_pcv_select_global_version($product = 0, $component = 0, $versions = array(), $prefix = '', $type) { global $tpl; if (is_array($versions['0'])) { foreach ($versions['0'] AS $version) { $row['prefix'] = $prefix . $prefix; $row['typeselect'] = $type; $row['value'] = "p{$product}c{$component}v$version[versionid]"; $row['title'] = $version['version']; $row['description'] = ''; eval('$global_versions_html .= "' . $tpl->fetch('pcv_select_row') . '";'); } } return $global_versions_html; } // ###################### Start parse_pcv_select ##################### function parse_pcv_select($input) { $input = trim($input); ///////// PREG_MATCH IS A PIECE OF SHIT!1!!!!11! // (yes I just swore in the code because the bastard of a RegEx didn't match // my string for any good reason) //var_dump( preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) ); /*if (ereg('p[:digit:].+?c[:digit:].+?v[:digit:].+?', $input) === false) { return false; }*/ /////////// CANT'T EXPLODE EMPTY //$moo = explode('', $input); //print_r($moo); /////////// TOKENIZING TAKES WAAAAAAAAAAY TOO MUCH WORK /*$tokens = array('p', 'c', 'v'); $token = current($tokens);*/ /*for ($i = 0; $i <= strlen($input); $i++) { $char = $input[$i]; echo $token . "-$i>$char "; if (is_numeric($char)) { $trio["$token"] .= $char; } else { array_shift($tokens); $token = current($tokens); if ($char != $token AND $char != current($tokens)) { // return false; } } }*/ ///////// TOKENIZING 2 -- NO WORKEY /*foreach ($tokens AS $token) { for ($i = 0; $i <= strlen($input); $i++) { $char = $input["$i"]; if ($char != current($tokens)) { } } }*/ //////// SO WE DO IT THE MORONIC WAY AND IT WORKS!!!! $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); print_r($trio); if (count($trio) != 6 OR $trio[0] != 'p' OR $trio[2] != 'c' OR $trio[4] != 'v') { return false; } return array('product' => intval($trio[1]), 'component' => intval($trio[3]), 'version' => intval($trio[5])); } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>