| | |
| | | header("Pragma: no-cache"); |
| | | |
| | | // We need to set the following headers to make downloads work using IE in HTTPS mode. |
| | | if (isset($_SERVER['HTTPS']) || rcmail::get_instance()->config->get('use_https')) { |
| | | if (rcube_https_check()) { |
| | | header('Pragma: '); |
| | | header('Cache-Control: '); |
| | | } |
| | |
| | | else |
| | | header("Last-Modified: ".gmdate("D, d M Y H:i:s", $mdate)." GMT"); |
| | | |
| | | header("Cache-Control: max-age=0"); |
| | | header("Cache-Control: private, must-revalidate, max-age=0"); |
| | | header("Expires: "); |
| | | header("Pragma: "); |
| | | |
| | |
| | | ob_end_clean(); |
| | | exit; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns whether an $str is a reserved word for any of the version of Javascript or ECMAScript |
| | | * @param str String to check |
| | | * @return boolean True if $str is a reserver word, False if not |
| | | */ |
| | | function is_js_reserved_word($str) |
| | | { |
| | | return in_array($str, array( |
| | | // ECMASript ver 4 reserved words |
| | | 'as','break','case','catch','class','const','continue', |
| | | 'default','delete','do','else','export','extends','false','finally','for','function', |
| | | 'if','import','in','instanceof','is','namespace','new','null','package','private', |
| | | 'public','return','super','switch','this','throw','true','try','typeof','use','var', |
| | | 'void','while','with', |
| | | // ECMAScript ver 4 future reserved words |
| | | 'abstract','debugger','enum','goto','implements','interface','native','protected', |
| | | 'synchronized','throws','transient','volatile', |
| | | // special meaning in some contexts |
| | | 'get','set', |
| | | // were reserved in ECMAScript ver 3 |
| | | 'boolean','byte','char','double','final','float','int','long','short','static' |
| | | )); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Convert a variable into a javascript object notation |
| | | * |
| | | * @param mixed Input value |
| | | * @return string Serialized JSON string |
| | | */ |
| | | function json_serialize($var) |
| | | { |
| | | if (is_object($var)) |
| | | $var = get_object_vars($var); |
| | | |
| | | if (is_array($var)) |
| | | { |
| | | // empty array |
| | | if (!sizeof($var)) |
| | | return '[]'; |
| | | else |
| | | { |
| | | $keys_arr = array_keys($var); |
| | | $is_assoc = $have_numeric = 0; |
| | | |
| | | for ($i=0; $i<sizeof($keys_arr); ++$i) |
| | | { |
| | | if (is_numeric($keys_arr[$i])) |
| | | $have_numeric = 1; |
| | | if (!is_numeric($keys_arr[$i]) || $keys_arr[$i] != $i) |
| | | $is_assoc = 1; |
| | | if ($is_assoc && $have_numeric) |
| | | break; |
| | | } |
| | | |
| | | $brackets = $is_assoc ? '{}' : '[]'; |
| | | $pairs = array(); |
| | | |
| | | foreach ($var as $key => $value) |
| | | { |
| | | // enclose key with quotes if it is not variable-name conform |
| | | if (!preg_match('/^[_a-zA-Z]{1}[_a-zA-Z0-9]*$/', $key) || is_js_reserved_word($key)) |
| | | $key = "'$key'"; |
| | | |
| | | $pairs[] = sprintf("%s%s", $is_assoc ? "$key:" : '', json_serialize($value)); |
| | | } |
| | | |
| | | return $brackets{0} . implode(',', $pairs) . $brackets{1}; |
| | | } |
| | | } |
| | | else if (!is_string($var) && strval(intval($var)) === strval($var)) |
| | | return $var; |
| | | else if (is_bool($var)) |
| | | return $var ? '1' : '0'; |
| | | else |
| | | return "'".JQ($var)."'"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Function to convert an array to a javascript array |
| | | * Actually an alias function for json_serialize() |
| | | * @deprecated |
| | | */ |
| | | function array2js($arr, $type='') |
| | | { |
| | | return json_serialize($arr); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if (is_numeric($str)) |
| | | return floatval($str); |
| | | |
| | | if (preg_match('/([0-9]+)([a-z])/i', $str, $regs)) |
| | | |
| | | if (preg_match('/([0-9\.]+)\s*([a-z]*)/i', $str, $regs)) |
| | | { |
| | | $bytes = floatval($regs[1]); |
| | | switch (strtolower($regs[2])) |
| | | { |
| | | case 'g': |
| | | case 'gb': |
| | | $bytes *= 1073741824; |
| | | break; |
| | | case 'm': |
| | | case 'mb': |
| | | $bytes *= 1048576; |
| | | break; |
| | | case 'k': |
| | | case 'kb': |
| | | $bytes *= 1024; |
| | | break; |
| | | } |
| | |
| | | return $input; |
| | | } |
| | | |
| | | if (!is_string($input)) |
| | | if (!is_string($input) || $input == '') |
| | | return $input; |
| | | |
| | | // iconv is 10x faster |
| | | if (function_exists('iconv')) |
| | | return iconv('UTF8', 'UTF8//IGNORE', $input); |
| | | |
| | | // iconv/mbstring are much faster (especially with long strings) |
| | | if (function_exists('mb_convert_encoding') && ($res = mb_convert_encoding($input, 'UTF-8', 'UTF-8')) !== false) |
| | | return $res; |
| | | |
| | | if (function_exists('iconv') && ($res = @iconv('UTF-8', 'UTF-8//IGNORE', $input)) !== false) |
| | | return $res; |
| | | |
| | | $regexp = '/^('. |
| | | // '[\x00-\x7F]'. // UTF8-1 |
| | |
| | | $seq = ''; |
| | | $out = ''; |
| | | |
| | | for ($i = 0, $len = strlen($input)-1; $i < $len; $i++) { |
| | | for ($i = 0, $len = strlen($input); $i < $len; $i++) { |
| | | $chr = $input[$i]; |
| | | $ord = ord($chr); |
| | | // 1-byte character |
| | |
| | | return $out; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Convert a variable into a javascript object notation |
| | | * |
| | | * @param mixed Input value |
| | | * @return string Serialized JSON string |
| | | */ |
| | | function json_serialize($input) |
| | | { |
| | | $input = rc_utf8_clean($input); |
| | | |
| | | return json_encode($input); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Explode quoted string |
| | | * |