X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fglobal.php;h=f07d313da43b284a6482fe7c21f70c9d3c19c6eb;hp=2ee2b837d3c03f681d7c8ce3697cdd706c805e68;hb=8ed1923822b383ddb338e9eef75bb7f110cc47b4;hpb=54b1fdfcf38f82c7987554920cf7dcbe0f825009 diff --git a/functions/global.php b/functions/global.php index 2ee2b837..f07d313d 100644 --- a/functions/global.php +++ b/functions/global.php @@ -7,13 +7,17 @@ * It also has some session register functions that work across various * php versions. * - * @copyright © 1999-2006 The SquirrelMail Project Team + * @copyright 1999-2019 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail */ /** + * These constants are used in the function sqgetGlobalVar(). See + * sqgetGlobalVar() for a description of what they mean. + * + * @since 1.4.0 */ define('SQ_INORDER',0); define('SQ_GET',1); @@ -84,61 +88,51 @@ function sqstripslashes(&$array) { } /** - * Merges two variables into a single array - * - * Similar to PHP array_merge function, but provides same - * functionality as array_merge without losing array values - * with same key names. If the values under identical array - * keys are both strings and $concat_strings is TRUE, those - * values are concatenated together, otherwise they are placed - * in a sub-array and are merged (recursively) in the same manner. - * - * If either of the elements being merged is not an array, - * it will simply be added to the returned array. - * - * If both values are strings and $concat_strings is TRUE, - * a concatenated string is returned instead of an array. - * - * @param mixed $a First element to be merged - * @param mixed $b Second element to be merged - * @param boolean $concat_strings Whether or not string values - * should be concatenated instead - * of added to different array - * keys (default TRUE) - * - * @return array The merged $a and $b in one array + * Squelch error output to screen (only) for the given function. + * If the SquirrelMail debug mode SM_DEBUG_MODE_ADVANCED is not + * enabled, error output will not go to the log, either. * - * @since 1.5.2 + * This provides an alternative to the @ error-suppression + * operator where errors will not be shown in the interface + * but will show up in the server log file (assuming the + * administrator has configured PHP logging). + * + * @since 1.4.12 and 1.5.2 + * + * @param string $function The function to be executed + * @param array $args The arguments to be passed to the function + * (OPTIONAL; default no arguments) + * NOTE: The caller must take extra action if + * the function being called is supposed + * to use any of the parameters by + * reference. In the following example, + * $x is passed by reference and $y is + * passed by value to the "my_func" + * function. + * sq_call_function_suppress_errors('my_func', array(&$x, $y)); + * + * @return mixed The return value, if any, of the function being + * executed will be returned. * */ -function sq_array_merge($a, $b, $concat_strings=true) { +function sq_call_function_suppress_errors($function, $args=array()) { + global $sm_debug_mode; - $ret = array(); + $display_errors = ini_get('display_errors'); + ini_set('display_errors', '0'); - if (is_array($a)) { - $ret = $a; - } else { - if (is_string($a) && is_string($b) && $concat_strings) { - return $a . $b; - } - $ret[] = $a; - } + // if advanced debug mode isn't enabled, don't log the error, either + // + if (!($sm_debug_mode & SM_DEBUG_MODE_ADVANCED)) + $error_reporting = error_reporting(0); + $ret = call_user_func_array($function, $args); - if (is_array($b)) { - foreach ($b as $key => $value) { - if (isset($ret[$key])) { - $ret[$key] = sq_array_merge($ret[$key], $value, $concat_strings); - } else { - $ret[$key] = $value; - } - } - } else { - $ret[] = $b; - } - - return $ret; + if (!($sm_debug_mode & SM_DEBUG_MODE_ADVANCED)) + error_reporting($error_reporting); + ini_set('display_errors', $display_errors); + return $ret; } /** @@ -151,9 +145,7 @@ function sqsession_register ($var, $name) { sqsession_is_active(); - $_SESSION["$name"] = $var; - - session_register("$name"); + $_SESSION[$name] = $var; } /** @@ -167,7 +159,9 @@ function sqsession_unregister ($name) { unset($_SESSION[$name]); - session_unregister("$name"); + // starts throwing warnings in PHP 5.3.0 and is + // removed in PHP 6 and is redundant anyway + //session_unregister("$name"); } /** @@ -187,101 +181,298 @@ function sqsession_is_registered ($name) { return $result; } + /** - * Search for the var $name in $_SESSION, $_POST, $_GET, $_COOKIE, or $_SERVER - * and set it in provided var. + * Retrieves a form variable, from a set of possible similarly named + * form variables, based on finding a different, single field. This + * is intended to allow more than one same-named inputs in a single + *