X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fstrings.php;h=01454742ee109a5458f277fae3ba9b3e0fb07227;hb=3bc714d503d53465083aaf325a649c6bd1bfc650;hp=9e137cab90a1ae271d4803faeb8dfe04cb127a3b;hpb=f72f61d8e1443294a3e103ff6f8e2f99459ae7f4;p=squirrelmail.git diff --git a/functions/strings.php b/functions/strings.php index 9e137cab..01454742 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -3,27 +3,28 @@ /** * strings.php * - * Copyright (c) 1999-2003 The SquirrelMail Project Team + * Copyright (c) 1999-2004 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * This code provides various string manipulation functions that are * used by the rest of the Squirrelmail code. * * $Id$ + * @package squirrelmail */ /** * SquirrelMail version number -- DO NOT CHANGE */ global $version; -$version = '1.5.0 [CVS]'; +$version = '1.5.1 [CVS]'; /** * SquirrelMail internal version number -- DO NOT CHANGE * $sm_internal_version = array (release, major, minor) */ global $SQM_INTERNAL_VERSION; -$SQM_INTERNAL_VERSION = array(1,5,0); +$SQM_INTERNAL_VERSION = array(1,5,1); /** * There can be a circular issue with includes, where the $version string is @@ -40,6 +41,10 @@ require_once(SM_PATH . 'functions/global.php'); * * Specifically, ' comes up as 5 characters instead of 1. * This should not add newlines to the end of lines. + * + * @param string line the line of text to wrap, by ref + * @param int wrap the maximum line lenth + * @return void */ function sqWordWrap(&$line, $wrap) { global $languages, $squirrelmail_language; @@ -95,6 +100,8 @@ function sqWordWrap(&$line, $wrap) { /** * Does the opposite of sqWordWrap() + * @param string body the text to un-wordwrap + * @return void */ function sqUnWordWrap(&$body) { global $squirrelmail_language; @@ -134,6 +141,10 @@ function sqUnWordWrap(&$body) { /** * If $haystack is a full mailbox name and $needle is the mailbox * separator character, returns the last part of the mailbox name. + * + * @param string haystack full mailbox name to search + * @param string needle the mailbox separator character + * @return string the last part of the mailbox name */ function readShortMailboxName($haystack, $needle) { @@ -149,6 +160,12 @@ function readShortMailboxName($haystack, $needle) { return( $elem ); } +/** + * Creates an URL for the page calling this function, using either the PHP global + * REQUEST_URI, or the PHP global PHP_SELF with QUERY_STRING added. + * + * @return string the complete url for this page + */ function php_self () { if ( sqgetGlobalVar('REQUEST_URI', $req_uri, SQ_SERVER) && !empty($req_uri) ) { return $req_uri; @@ -170,13 +187,15 @@ function php_self () { /** - * This determines the location to forward to relative to your server. + * Determines the location to forward to, relative to your server. + * This is used in HTTP Location: redirects. * If this doesnt work correctly for you (although it should), you can - * remove all this code except the last two lines, and change the header() - * function to look something like this, customized to the location of - * SquirrelMail on your server: + * remove all this code except the last two lines, and have it return + * the right URL for your site, something like: + * + * http://www.example.com/squirrelmail/ * - * http://www.myhost.com/squirrelmail/src/login.php + * @return string the base url for this SquirrelMail installation */ function get_location () { @@ -242,8 +261,13 @@ function get_location () { /** - * These functions are used to encrypt the passowrd before it is - * stored in a cookie. + * These functions are used to encrypt the password before it is + * stored in a cookie. The encryption key is generated by + * OneTimePadCreate(); + * + * @param string string the (password)string to encrypt + * @param string epad the encryption key + * @return string the base64-encoded encrypted password */ function OneTimePadEncrypt ($string, $epad) { $pad = base64_decode($epad); @@ -255,6 +279,14 @@ function OneTimePadEncrypt ($string, $epad) { return base64_encode($encrypted); } +/** + * Decrypt a password from the cookie, encrypted by OneTimePadEncrypt. + * This uses the encryption key that is stored in the session. + * + * @param string string the string to decrypt + * @param string epad the encryption key from the session + * @return string the decrypted password + */ function OneTimePadDecrypt ($string, $epad) { $pad = base64_decode($epad); $encrypted = base64_decode ($string); @@ -271,6 +303,9 @@ function OneTimePadDecrypt ($string, $epad) { * Randomize the mt_rand() function. Toss this in strings or integers * and it will seed the generator appropriately. With strings, it is * better to get them long. Use md5() to lengthen smaller strings. + * + * @param mixed val a value to seed the random number generator + * @return void */ function sq_mt_seed($Val) { /* if mt_getrandmax() does not return a 2^n - 1 number, @@ -297,6 +332,8 @@ function sq_mt_seed($Val) { * This function initializes the random number generator fairly well. * It also only initializes it once, so you don't accidentally get * the same 'random' numbers twice in one session. + * + * @return void */ function sq_mt_randomize() { static $randomized; @@ -332,6 +369,13 @@ function sq_mt_randomize() { $randomized = 1; } +/** + * Creates an encryption key for encrypting the password stored in the cookie. + * The encryption key itself is stored in the session. + * + * @param int length optional, length of the string to generate + * @return string the encryption key + */ function OneTimePadCreate ($length=100) { sq_mt_randomize(); @@ -344,7 +388,10 @@ function OneTimePadCreate ($length=100) { } /** - * Returns a string showing the size of the message/attachment. + * Returns a string showing the size of the message/attachment. + * + * @param int bytes the filesize in bytes + * @return string the filesize in human readable format */ function show_readable_size($bytes) { $bytes /= 1024; @@ -369,10 +416,14 @@ function show_readable_size($bytes) { /** * 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) { @@ -401,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); } /** - * 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) { @@ -424,11 +481,14 @@ function TrimArray(&$array) { } } -// Returns a link to the compose-page, taking in -// consideration the compose_in_new and javascript -// settings. -// -function makeComposeLink($url, $text = null) +/** + * 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; @@ -439,19 +499,15 @@ function makeComposeLink($url, $text = null) // if not using "compose in new window", make // regular link and be done with it - // if($compose_new_win != '1') { - return makeInternalLink($url, $text, 'right'); + 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.''; @@ -459,18 +515,19 @@ function makeComposeLink($url, $text = null) // 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. -*/ + * 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) {