/**
* 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
* 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
}
/**
+ * 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.
*
/**
+ * get_location
+ *
* 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
/**
+ * Encrypts password
+ *
* These functions are used to encrypt the password before it is
* stored in a cookie. The encryption key is generated by
* OneTimePadCreate();
}
/**
- * Decrypt a password from the cookie, encrypted by OneTimePadEncrypt.
+ * 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.
*
* @param string string the string to decrypt
/**
- * 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.
+ * 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.
*
* @param mixed val a value to seed the random number generator
* @return void
/**
+ * 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.
}
/**
+ * Creates encryption key
+ *
* Creates an encryption key for encrypting the password stored in the cookie.
* The encryption key itself is stored in the session.
*
* 4 = add numbers 0-9 to $chars
* @return string the random string
*/
-
function GenerateRandomString($size, $chars, $flags = 0) {
if ($flags & 0x1) {
$chars .= 'abcdefghijklmnopqrstuvwxyz';
/**
* 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 array
+ *
* Trims every element in the array, ie. remove the first char of each element
* @param array array the array to trim
*/
}
/**
+ * Create compose link
+ *
* 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
}
/**
+ * 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 <some@email.address> to be displayed.
- * The output is wrapped in <pre> and </pre> tags.
+ * The output is wrapped in <<pre>> and <</pre>> tags.
*
* @return void
*/
print '</pre>';
}
+/**
+ * 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;
+}
+
+/**
+ * sq_get_html_translation_table
+ *
+ * Returns the translation table used by sq_htmlentities()
+ *
+ * @param integer $table html translation table. Possible values (without quotes):
+ * <ul>
+ * <li>HTML_ENTITIES - full html entities table defined by charset</li>
+ * <li>HTML_SPECIALCHARS - html special characters table</li>
+ * </ul>
+ * @param integer $quote_style quote encoding style. Possible values (without quotes):
+ * <ul>
+ * <li>ENT_COMPAT - (default) encode double quotes</li>
+ * <li>ENT_NOQUOTES - don't encode double or single quotes</li>
+ * <li>ENT_QUOTES - encode double and single quotes</li>
+ * </ul>
+ * @param string $charset charset used for encoding. default to us-ascii, 'auto' uses $default_charset global value.
+ * @return array html translation array
+ */
+function sq_get_html_translation_table($table,$quote_style=ENT_COMPAT,$charset='us-ascii') {
+ global $default_charset;
+
+ if ($table == HTML_SPECIALCHARS) $charset='us-ascii';
+
+ // Start array with ampersand
+ $sq_html_ent_table = array( "&" => '&' );
+
+ // < and >
+ $sq_html_ent_table = array_merge($sq_html_ent_table,
+ array("<" => '<',
+ ">" => '>')
+ );
+ // double quotes
+ if ($quote_style == ENT_COMPAT)
+ $sq_html_ent_table = array_merge($sq_html_ent_table,
+ array("\"" => '"')
+ );
+
+ // double and single quotes
+ if ($quote_style == ENT_QUOTES)
+ $sq_html_ent_table = array_merge($sq_html_ent_table,
+ array("\"" => '"',
+ "'" => ''')
+ );
+
+ if ($charset=='auto') $charset=$default_charset;
+
+ // add entities that depend on charset
+ switch($charset){
+ case 'iso-8859-1':
+ include_once(SM_PATH . 'functions/htmlentities/iso-8859-1.php');
+ break;
+ case 'utf-8':
+ include_once(SM_PATH . 'functions/htmlentities/utf-8.php');
+ break;
+ case 'us-ascii':
+ default:
+ break;
+ }
+ // return table
+ return $sq_html_ent_table;
+}
+
+/**
+ * sq_htmlentities
+ *
+ * Convert all applicable characters to HTML entities.
+ * Minimal php requirement - v.4.0.5
+ *
+ * @param string $string string that has to be sanitized
+ * @param integer $quote_style quote encoding style. Possible values (without quotes):
+ * <ul>
+ * <li>ENT_COMPAT - (default) encode double quotes</li>
+ * <li>ENT_NOQUOTES - don't encode double or single quotes</li>
+ * <li>ENT_QUOTES - encode double and single quotes</li>
+ * </ul>
+ * @param string $charset charset used for encoding. defaults to 'us-ascii', 'auto' uses $default_charset global value.
+ * @return string sanitized string
+ */
+function sq_htmlentities($string,$quote_style=ENT_COMPAT,$charset='us-ascii') {
+ // get translation table
+ $sq_html_ent_table=sq_get_html_translation_table(HTML_ENTITIES,$quote_style,$charset);
+ // convert characters
+ return str_replace(array_keys($sq_html_ent_table),array_values($sq_html_ent_table),$string);
+}
+
$PHP_SELF = php_self();
-?>
+?>
\ No newline at end of file