X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=functions%2Fglobal.php;h=b2f7d16ade974f289a5f936d5af63a974d1a5486;hb=3047e291f2982efe9501ec790faafd3da843d22d;hp=5221b44ec909ea1bee7f608472e917b200a94474;hpb=f31687f676e7f2e695593f04730902cef5335a9d;p=squirrelmail.git diff --git a/functions/global.php b/functions/global.php index 5221b44e..3b42e750 100644 --- a/functions/global.php +++ b/functions/global.php @@ -1,70 +1,79 @@ = ($a.$b.$c); + global $SQM_INTERNAL_VERSION; + if ( !isset($SQM_INTERNAL_VERSION) || + $SQM_INTERNAL_VERSION[0] < $a || + ( $SQM_INTERNAL_VERSION[0] == $a && + $SQM_INTERNAL_VERSION[1] < $b) || + ( $SQM_INTERNAL_VERSION[0] == $a && + $SQM_INTERNAL_VERSION[1] == $b && + $SQM_INTERNAL_VERSION[2] < $c ) ) { + return FALSE; + } + return TRUE; } -/* recursively strip slashes from the values of an array */ + +/** + * Recursively strip slashes from the values of an array. + * @param array array the array to strip, passed by reference + * @return void + */ function sqstripslashes(&$array) { if(count($array) > 0) { foreach ($array as $index=>$value) { @@ -78,72 +87,394 @@ function sqstripslashes(&$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. + * + * 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_call_function_suppress_errors($function, $args=array()) { + global $sm_debug_mode; + + $display_errors = ini_get('display_errors'); + ini_set('display_errors', '0'); + + // 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 (!($sm_debug_mode & SM_DEBUG_MODE_ADVANCED)) + error_reporting($error_reporting); + + ini_set('display_errors', $display_errors); + return $ret; +} + +/** + * Add a variable to the session. + * @param mixed $var the variable to register + * @param string $name the name to refer to this variable + * @return void + */ function sqsession_register ($var, $name) { sqsession_is_active(); - if ( !check_php_version(4,1) ) { - global $HTTP_SESSION_VARS; - $HTTP_SESSION_VARS[$name] = $var; - } - else { - $_SESSION["$name"] = $var; - } - session_register("$name"); + $_SESSION[$name] = $var; } +/** + * Delete a variable from the session. + * @param string $name the name of the var to delete + * @return void + */ function sqsession_unregister ($name) { sqsession_is_active(); - if ( !check_php_version(4,1) ) { - global $HTTP_SESSION_VARS; - unset($HTTP_SESSION_VARS[$name]); - } - else { - unset($_SESSION[$name]); - } - session_unregister("$name"); + unset($_SESSION[$name]); + + // starts throwing warnings in PHP 5.3.0 and is + // removed in PHP 6 and is redundant anyway + //session_unregister("$name"); } +/** + * Checks to see if a variable has already been registered + * in the session. + * @param string $name the name of the var to check + * @return bool whether the var has been registered + */ function sqsession_is_registered ($name) { $test_name = &$name; $result = false; - if ( !check_php_version(4,1) ) { - global $HTTP_SESSION_VARS; - if (isset($HTTP_SESSION_VARS[$test_name])) { - $result = true; - } + + if (isset($_SESSION[$test_name])) { + $result = true; } - else { - if (isset($_SESSION[$test_name])) { - $result = true; + + return $result; +} + + +/** + * 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 + *