/functions/strings.php

Description

strings.php

This code provides various string manipulation functions that are used by the rest of the SquirrelMail code.

Includes
require_once (SM_PATH.'functions/global.php') (line 33)

There can be a circular issue with includes, where the $version string is referenced by the include of global.php, etc. before it's defined.

For that reason, bring in global.php AFTER we define the version strings.

Functions
GenerateRandomString (line 536)

Generates a random string from the caracter set you pass in

  • return: the random string
string GenerateRandomString (mixed $size, mixed $chars, [mixed $flags = 0])
get_location (line 267)

get_location

Determines the location to forward to, relative to your server. This is used in HTTP Location: redirects. If set, it uses $config_location_base as the first part of the URL, specifically, the protocol, hostname and port parts. The path is always autodetected.

  • return: the base url for this SquirrelMail installation
string get_location ()
makeComposeLink (line 625)

Create compose link

Returns a link to the compose-page, taking in consideration the compose_in_new and javascript settings.

  • return: a link to the compose page
string makeComposeLink (mixed $url, [mixed $text = null], [ $target = ''])
  • $target
OneTimePadCreate (line 487)

Creates encryption key

Creates an encryption key for encrypting the password stored in the cookie. The encryption key itself is stored in the session.

  • return: the encryption key
string OneTimePadCreate ([mixed $length = 100])
OneTimePadDecrypt (line 382)

Decrypts a password from the cookie

Decrypts a password from the cookie, encrypted by OneTimePadEncrypt. This uses the encryption key that is stored in the session.

  • return: the decrypted password
string OneTimePadDecrypt (mixed $string, mixed $epad)
OneTimePadEncrypt (line 352)

Encrypts password

These functions are used to encrypt the password before it is stored in a cookie. The encryption key is generated by OneTimePadCreate();

  • return: the base64-encoded encrypted password
string OneTimePadEncrypt (mixed $string, mixed $epad)
php_self (line 214)

php_self

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: the complete url for this page
string php_self ()
quoteimap (line 568)

Escapes special characters for use in IMAP commands.

  • return: the escaped string
string quoteimap (mixed $str)
readShortMailboxName (line 192)

If $haystack is a full mailbox name and $needle is the mailbox separator character, returns the last part of the mailbox name.

  • return: the last part of the mailbox name
string readShortMailboxName (mixed $haystack, mixed $needle)
RemoveSlashes (line 599)

Removes slashes from every element in the array

void RemoveSlashes ( &$array)
  • &$array
show_readable_size (line 504)

Returns a string showing the size of the message/attachment.

  • return: the filesize in human readable format
string show_readable_size (mixed $bytes)
sm_print_r (line 668)

Print variable

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 <[email protected]> to be displayed. The output is wrapped in <pre> and </pre> tags.

void sm_print_r ()
sqm_baseuri (line 242)

Find out where squirrelmail lives and try to be smart about it.

The only problem would be when squirrelmail lives in directories called "src", "functions", or "plugins", but people who do that need to be beaten with a steel pipe anyway.

  • return: the base uri of squirrelmail installation.
string sqm_baseuri ()
sqUnWordWrap (line 101)

Does the opposite of sqWordWrap()

void sqUnWordWrap (mixed &$body)
sqWordWrap (line 44)

Wraps text at $wrap characters

Has a problem with special HTML characters, so call this before you do character translation.

Specifically, &#039 comes up as 5 characters instead of 1. This should not add newlines to the end of lines.

void sqWordWrap ( &$line,  $wrap, [ $charset = null])
  • &$line
  • $wrap
  • $charset
sq_fwrite (line 684)

version of fwrite which checks for failure

void sq_fwrite ( $fp,  $string)
  • $fp
  • $string
sq_is8bit (line 705)

Tests if string contains 8bit symbols.

If charset is not set, function defaults to default_charset. $default_charset global must be set correctly if $charset is not used.

  • return: true if 8bit symbols are detected
  • since: 1.5.1 and 1.4.4
bool sq_is8bit (string $string, [string $charset = ''])
  • string $string: tested string
  • string $charset: charset used in a string
sq_lowercase_array_vals (line 855)

Callback function used to lowercase array values.

  • since: 1.5.1 and 1.4.6
void sq_lowercase_array_vals ( &$val, mixed $key, string $val)
  • string $val: array value
  • mixed $key: array key
  • &$val
sq_mb_list_encodings (line 784)

Replacement of mb_list_encodings function

This function provides replacement for function that is available only in php 5.x. Function does not test all mbstring encodings. Only the ones that might be used in SM translations.

Supported strings are stored in session in order to reduce number of mb_internal_encoding function calls.

If mb_list_encodings() function is present, code uses it. Main difference from original function behaviour - array values are lowercased in order to simplify use of returned array in in_array() checks.

If you want to test all mbstring encodings - fill $list_of_encodings array.

  • return: list of encodings supported by php mbstring extension
  • since: 1.5.1 and 1.4.6
array sq_mb_list_encodings ()
sq_mt_randomize (line 444)

Init random number generator

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.

void sq_mt_randomize ()
sq_mt_seed (line 414)

Randomizes 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.

void sq_mt_seed (mixed $Val)
sq_strlen (line 737)

Function returns number of characters in string.

Returned number might be different from number of bytes in string, if $charset is multibyte charset. Detection depends on mbstring functions. If mbstring does not support tested multibyte charset, vanilla string length function is used.

  • return: number of characters in string
  • since: 1.5.1 and 1.4.6
integer sq_strlen (string $str, [string $charset = null])
  • string $str: string
  • string $charset: charset
sq_trim_value (line 864)

Callback function to trim whitespace from a value, to be used in array_walk

  • since: 1.5.2 and 1.4.7
void sq_trim_value ( &$value, string $value)
  • string $value: value to trim
  • &$value
TrimArray (line 580)

Trims array

Trims every element in the array, ie. remove the first char of each element Obsolete: will probably removed soon

void TrimArray (mixed &$array)
truncateWithEntities (line 143)

Truncates a string and take care of html encoded characters

  • return: Trimmed string
string truncateWithEntities (string $s, int $iTrimAt)
  • string $s: string to truncate
  • int $iTrimAt: Trim at nn characters

Documentation generated on Sat, 07 Oct 2006 16:33:51 +0300 by phpDocumentor 1.3.0RC6