- }
- }
-
- // Apache-specific
- sq_mt_seed(md5($UNIQUE_ID));
-
- $randomized = 1;
- }
-
- function OneTimePadCreate ($length=100) {
- sq_mt_randomize();
-
- $pad = '';
- for ($i = 0; $i < $length; $i++) {
- $pad .= chr(mt_rand(0,255));
- }
-
- return base64_encode($pad);
- }
-
- // Check if we have a required PHP-version. Return TRUE if we do,
- // or FALSE if we don't.
- // To check for 4.0.1, use sqCheckPHPVersion(4,0,1)
- // To check for 4.0b3, use sqCheckPHPVersion(4,0,-3)
- // Does not handle betas like 4.0.1b1 or development versions
- function sqCheckPHPVersion($major, $minor, $release) {
-
- $ver = phpversion();
- eregi('^([0-9]+)\\.([0-9]+)(.*)', $ver, $regs);
-
- // Parse the version string
- $vmajor = strval($regs[1]);
- $vminor = strval($regs[2]);
- $vrel = $regs[3];
- if($vrel[0] == ".")
- $vrel = strval(substr($vrel, 1));
- if($vrel[0] == 'b' || $vrel[0] == 'B')
- $vrel = - strval(substr($vrel, 1));
- if($vrel[0] == 'r' || $vrel[0] == 'R')
- $vrel = - strval(substr($vrel, 2))/10;
-
- // Compare major version
- if($vmajor < $major) return false;
- if($vmajor > $major) return true;
-
- // Major is the same. Compare minor
- if($vminor < $minor) return false;
- if($vminor > $minor) return true;
-
- // Major and minor is the same as the required one.
- // Compare release
- if($vrel >= 0 && $release >= 0) { // Neither are beta
- if($vrel < $release) return false;
- } else if($vrel >= 0 && $release < 0){ // This is not beta, required is beta
- return true;
- } else if($vrel < 0 && $release >= 0){ // This is beta, require not beta
- return false;
- } else { // Both are beta
- if($vrel > $release) return false;
- }
-
- return true;
- }
-
- /* Returns a string showing the size of the message/attachment */
- function show_readable_size($bytes)
- {
- $bytes /= 1024;
- $type = 'k';
-
- if ($bytes / 1024 > 1)
- {
- $bytes /= 1024;
- $type = 'm';
- }
-
- if ($bytes < 10)
- {
- $bytes *= 10;
- settype($bytes, 'integer');
- $bytes /= 10;
- }
- else
- settype($bytes, 'integer');
-
- return $bytes . '<small> ' . $type . '</small>';
- }
-
- /* 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
- */
-
- function GenerateRandomString($size, $chars, $flags = 0)
- {
- if ($flags & 0x1)
- $chars .= 'abcdefghijklmnopqrstuvwxyz';
- if ($flags & 0x2)
- $chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- if ($flags & 0x4)
- $chars .= '0123456789';
-
- if ($size < 1 || strlen($chars) < 1)
- return '';
-
- sq_mt_randomize(); // Initialize the random number generator
-
- $String = "";
- while (strlen($String) < $size) {
- $String .= $chars[mt_rand(0, strlen($chars))];
- }
-
- return $String;
- }
-
- function quoteIMAP($str)
- {
- return ereg_replace('(["\\])', '\\\\1', $str);
- }
-
-?>
\ No newline at end of file
+ }
+ }
+
+ if(sqgetGlobalVar('UNIQUE_ID', $unique_id, SQ_SERVER)) {
+ sq_mt_seed(md5($unique_id));
+ }
+
+ $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();
+
+ $pad = '';
+ for ($i = 0; $i < $length; $i++) {
+ $pad .= chr(mt_rand(0,255));
+ }
+
+ return base64_encode($pad);
+}
+
+/**
+ * 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;
+ $type = 'k';
+
+ if ($bytes / 1024 > 1) {
+ $bytes /= 1024;
+ $type = 'M';
+ }
+
+ if ($bytes < 10) {
+ $bytes *= 10;
+ settype($bytes, 'integer');
+ $bytes /= 10;
+ } else {
+ settype($bytes, 'integer');
+ }
+
+ return $bytes . '<small> ' . $type . '</small>';
+}
+
+/**
+ * Generates a random string from the caracter set you pass in
+ *
+ * @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) {
+ if ($flags & 0x1) {
+ $chars .= 'abcdefghijklmnopqrstuvwxyz';
+ }
+ if ($flags & 0x2) {
+ $chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ }
+ if ($flags & 0x4) {
+ $chars .= '0123456789';
+ }
+
+ if (($size < 1) || (strlen($chars) < 1)) {
+ return '';
+ }
+
+ sq_mt_randomize(); /* Initialize the random number generator */
+
+ $String = '';
+ $j = strlen( $chars ) - 1;
+ while (strlen($String) < $size) {
+ $String .= $chars{mt_rand(0, $j)};
+ }
+
+ 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, ie. remove the first char of each element
+ * @param array array the array to trim
+ */
+function TrimArray(&$array) {
+ foreach ($array as $k => $v) {
+ global $$k;
+ if (is_array($$k)) {
+ foreach ($$k as $k2 => $v2) {
+ $$k[$k2] = substr($v2, 1);
+ }
+ } else {
+ $$k = substr($v, 1);
+ }
+
+ /* Re-assign back to array. */
+ $array[$k] = $$k;
+ }
+}
+
+/**
+ * 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)
+{
+ 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, 'right');
+ }
+
+
+ // 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 '<a href="javascript:void(0)" onclick="comp_in_new(\''.$base_uri.$url.'\')">'. $text.'</a>';
+ }
+
+
+ // 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 <some@email.address> to be displayed.
+ * The output is wrapped in <pre> and </pre> 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 '<pre>';
+ print htmlentities($buffer);
+ print '</pre>';
+}
+
+$PHP_SELF = php_self();
+?>