X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fstrings.php;h=4ff54b898bfeb95e145ed5deb259da559bf41aa0;hb=7dc3c1a96de1ee317b6565dad912e672f7627b4b;hp=db5ff7c2e61b480d0f9d4e81e6de945d887d1b7d;hpb=ea5fa593a5217d52bfc69dd0002cf575830c7a80;p=squirrelmail.git diff --git a/functions/strings.php b/functions/strings.php index db5ff7c2..4ff54b89 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -1,31 +1,30 @@ 1) { $bytes /= 1024; $type = 'M'; } - + if ($bytes < 10) { $bytes *= 10; settype($bytes, 'integer'); @@ -353,17 +409,21 @@ function show_readable_size($bytes) { } else { settype($bytes, 'integer'); } - + return $bytes . ' ' . $type . ''; } /** * Generates a random string from the caracter set you pass in * - * Flags: - * 1 = add lowercase a-z to $chars - * 2 = add uppercase A-Z to $chars - * 4 = add numbers 0-9 to $chars + * @param int size the size of the string to generate + * @param string chars a string containing the characters to use + * @param int flags a flag to add a specific set to the characters to use: + * Flags: + * 1 = add lowercase a-z to $chars + * 2 = add uppercase A-Z to $chars + * 4 = add numbers 0-9 to $chars + * @return string the random string */ function GenerateRandomString($size, $chars, $flags = 0) { @@ -376,7 +436,7 @@ function GenerateRandomString($size, $chars, $flags = 0) { if ($flags & 0x4) { $chars .= '0123456789'; } - + if (($size < 1) || (strlen($chars) < 1)) { return ''; } @@ -392,12 +452,18 @@ function GenerateRandomString($size, $chars, $flags = 0) { return $String; } +/** + * Escapes special characters for use in IMAP commands. + * @param string the string to escape + * @return string the escaped string + */ function quoteimap($str) { - return ereg_replace('(["\\])', '\\\\1', $str); + return preg_replace("/([\"\\\\])/", "\\\\$1", $str); } /** - * Trims every element in the array + * Trims every element in the array, ie. remove the first char of each element + * @param array array the array to trim */ function TrimArray(&$array) { foreach ($array as $k => $v) { @@ -409,12 +475,87 @@ function TrimArray(&$array) { } else { $$k = substr($v, 1); } - + /* Re-assign back to array. */ $array[$k] = $$k; } -} +} -$PHP_SELF = php_self(); +/** + * Returns a link to the compose-page, taking in consideration + * the compose_in_new and javascript settings. + * @param string url the URL to the compose page + * @param string text the link text, default "Compose" + * @return string a link to the compose page + */ +function makeComposeLink($url, $text = null, $target='') +{ + global $compose_new_win,$javascript_on; + + if(!$text) { + $text = _("Compose"); + } + + + // if not using "compose in new window", make + // regular link and be done with it + if($compose_new_win != '1') { + return makeInternalLink($url, $text, $target); + } + + // build the compose in new window link... + + + // if javascript is on, use onClick event to handle it + if($javascript_on) { + sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); + return ''. $text.''; + } + + + // otherwise, just open new window using regular HTML + return makeInternalLink($url, $text, '_blank'); + +} + +/** + * sm_print_r($some_variable, [$some_other_variable [, ...]]); + * Debugging function - does the same as print_r, but makes sure special + * characters are converted to htmlentities first. This will allow + * values like to be displayed. + * The output is wrapped in
 and 
tags. + * + * @return void + */ +function sm_print_r() { + ob_start(); // Buffer output + foreach(func_get_args() as $var) { + print_r($var); + echo "\n"; + } + $buffer = ob_get_contents(); // Grab the print_r output + ob_end_clean(); // Silently discard the output & stop buffering + print '
';
+    print htmlentities($buffer);
+    print '
'; +} + +/** + * version of fwrite which checks for failure + */ +function sq_fwrite($fp, $string) { + // write to file + $count = @fwrite($fp,$string); + // the number of bytes written should be the length of the string + if($count != strlen($string)) { + return FALSE; + } + + return $count; +} + + + +$PHP_SELF = php_self(); ?>