/functions/strings.php

Description

strings.php

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

Functions
GenerateRandomString (line 746)

Generates a random string from the character set you pass in

  • return: the random string
  • since: 1.0
string GenerateRandomString (int $size, string $chars, [int $flags = 0])
  • int $size: the length of the string to generate
  • string $chars: a string containing the characters to use
  • 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
get_location (line 471)

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
  • since: 1.0
string get_location ()
makeComposeLink (line 794)

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
  • since: 1.4.2
string makeComposeLink (string $url, [string $text = null], [string $target = ''])
  • string $url: the URL to the compose page
  • string $text: the link text, default "Compose"
  • string $target: (since 1.4.3) url target
OneTimePadCreate (line 695)

Creates encryption key

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

Pad must be longer or equal to encoded string length in 1.4.4/1.5.0 and older.

  • return: the encryption key
  • since: 1.0
string OneTimePadCreate ([int $length = 100])
  • int $length: optional, length of the string to generate
OneTimePadDecrypt (line 586)

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
  • since: 1.0
string OneTimePadDecrypt (string $string, string $epad)
  • string $string: the string to decrypt
  • string $epad: the encryption key from the session
OneTimePadEncrypt (line 555)

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
  • since: 1.0
string OneTimePadEncrypt (string $string, string $epad)
  • string $string: the (password)string to encrypt
  • string $epad: the encryption key
quoteimap (line 779)

Escapes special characters for use in IMAP commands.

  • return: the escaped string
  • since: 1.0.3
string quoteimap (string $str)
  • string $str: the string to escape
readShortMailboxName (line 443)

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
  • since: 1.0
string readShortMailboxName (mixed $haystack, mixed $needle)
show_readable_size (line 713)

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

  • return: the filesize in human readable format
  • since: 1.0
string show_readable_size (int $bytes)
  • int $bytes: the filesize in bytes
sm_ctype_space (line 76)

Checks for spaces in strings - only used if PHP doesn't have native ctype support

You might be able to rewrite the function by adding short evaluation form.

possible problems:

  • iso-2022-xx charsets - hex 20 might be part of other symbol. I might
be wrong. 0x20 is not used in iso-2022-jp. I haven't checked iso-2022-kr and iso-2022-cn mappings.

  • no-break space ( ) - it is 8bit symbol, that depends on charset.
there are at least three different charset groups that have nbsp in different places.

I don't see any charset/nbsp options in php ctype either.

  • return: true when only whitespace symbols are present in test string
  • since: 1.5.1
bool sm_ctype_space (string $string)
  • string $string: tested string
sqBodyWrap (line 96)

Wraps text at $wrap characters. While sqWordWrap takes a single line of text and wraps it, this function works on the entire corpus at once, this allows it to be a little bit smarter and when and how to wrap.

  • return: the wrapped text
  • since: 1.5.1
  • author: Justus Pendleton
string &sqBodyWrap ( &$body, int $wrap, string $body)
  • string $body: the entire body of text
  • int $wrap: the maximum line length
  • &$body
sqMakeCite (line 25)

Appends citation markers to the string.

Also appends a trailing space.

  • since: 1.5.1
  • author: Justus Pendleton
null sqMakeCite ( &$str, int $citeLevel, string $str)
  • string $str: The string to append to
  • int $citeLevel: the number of markers to append
  • &$str
sqMakeNewLine (line 45)

Create a newline in the string, adding citation markers to the newline as necessary.

  • since: 1.5.1
  • author: Justus Pendleton
null sqMakeNewLine ( &$str, int $citeLevel,  &$column, string $str, int $column)
  • string $str: the string to make a newline in
  • int $citeLevel: the citation level the newline is at
  • int $column: starting column of the newline
  • &$str
  • &$column
sqUnWordWrap (line 399)

Does the opposite of sqWordWrap()

  • since: 1.0
void sqUnWordWrap ( &$body, string $body)
  • string $body: the text to un-wordwrap
  • &$body
sqWordWrap (line 340)

Wraps text at $wrap characters

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

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

  • since: 1.0
void sqWordWrap ( &$line, int $wrap, [string $charset = ''], string $line)
  • string $line: the line of text to wrap, by ref
  • int $wrap: the maximum line lenth
  • string $charset: name of charset used in $line string. Available since v.1.5.1.
  • &$line
sq_count8bit (line 1272)

Counts 8bit bytes in string

  • return: number of 8bit bytes
integer sq_count8bit (string $string)
  • string $string: tested string
sq_fwrite (line 828)

version of fwrite which checks for failure

  • return: of written bytes. false on failure
  • since: 1.4.3
number sq_fwrite (resource $fp, string $string)
  • resource $fp
  • string $string
sq_get_html_translation_table (line 859)

sq_get_html_translation_table

Returns the translation table used by sq_htmlentities()

  • return: html translation array
  • since: 1.5.1
array sq_get_html_translation_table (integer $table, [integer $quote_style = ENT_COMPAT], [string $charset = 'us-ascii'])
  • integer $table: html translation table. Possible values (without quotes):
    • HTML_ENTITIES - full html entities table defined by charset
    • HTML_SPECIALCHARS - html special characters table
  • integer $quote_style: quote encoding style. Possible values (without quotes):
    • ENT_COMPAT - (default) encode double quotes
    • ENT_NOQUOTES - don't encode double or single quotes
    • ENT_QUOTES - encode double and single quotes
  • string $charset: charset used for encoding. default to us-ascii, 'auto' uses $default_charset global value.
sq_htmlentities (line 923)

sq_htmlentities

Convert all applicable characters to HTML entities. Minimal php requirement - v.4.0.5.

Function is designed for people that want to use full power of htmlentities() in i18n environment.

  • return: sanitized string
  • since: 1.5.1
string sq_htmlentities (string $string, [integer $quote_style = ENT_COMPAT], [string $charset = 'us-ascii'])
  • string $string: string that has to be sanitized
  • integer $quote_style: quote encoding style. Possible values (without quotes):
    • ENT_COMPAT - (default) encode double quotes
    • ENT_NOQUOTES - don't encode double or single quotes
    • ENT_QUOTES - encode double and single quotes
  • string $charset: charset used for encoding. defaults to 'us-ascii', 'auto' uses $default_charset global value.
sq_is8bit (line 941)

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 1046)

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 976)

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 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 650)

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.

  • since: 1.0
void sq_mt_randomize ()
sq_mt_seed (line 619)

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.

  • since: 1.0
void sq_mt_seed ( $Val, mixed $val)
  • mixed $val: a value to seed the random number generator. mixed = integer or string.
  • $Val
sq_strlen (line 1063)

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_strpos (line 1185)

Wrapper that is used to switch between vanilla and multibyte strpos functions.

string sq_strpos (string $haystack, mixed $needle, integer $offset, [string $charset = 'auto'])
  • string $haystack
  • mixed $needle
  • integer $offset
  • string $charset
sq_strtoupper (line 1230)

Wrapper that is used to switch between vanilla and multibyte strtoupper functions.

string sq_strtoupper (string $string, [string $charset = 'auto'])
  • string $string
  • string $charset
sq_str_pad (line 1104)

string padding with multibyte support

string sq_str_pad (string $string, integer $width, string $pad, integer $padtype, [string $charset = ''])
  • string $string: original string
  • integer $width: padded string width
  • string $pad: padding symbols
  • integer $padtype: padding type (internal php defines, see str_pad() description)
  • string $charset: charset used in original string
sq_substr (line 1137)

Wrapper that is used to switch between vanilla and multibyte substr functions.

string sq_substr (string $string, integer $start, integer $length, [string $charset = 'auto'])
  • string $string
  • integer $start
  • integer $length
  • string $charset
sq_trim_value (line 1285)

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

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