| | |
| | | foreach ($var as $key => $value) |
| | | { |
| | | // enclose key with quotes if it is not variable-name conform |
| | | if (!ereg("^[_a-zA-Z]{1}[_a-zA-Z0-9]*$", $key) || is_js_reserved_word($key)) |
| | | 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 $path; |
| | | |
| | | // cut base_url to the last directory |
| | | if (strpos($base_url, '/')>7) |
| | | if (strrpos($base_url, '/')>7) |
| | | { |
| | | $host_url = substr($base_url, 0, strpos($base_url, '/')); |
| | | $base_url = substr($base_url, 0, strrpos($base_url, '/')); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Wrapper function for strtoupper |
| | | */ |
| | | function rc_strtoupper($str) |
| | | { |
| | | if (function_exists('mb_strtoupper')) |
| | | return mb_strtoupper($str); |
| | | else |
| | | return strtoupper($str); |
| | | } |
| | | |
| | | /** |
| | | * Wrapper function for substr |
| | | */ |
| | | function rc_substr($str, $start, $len=null) |
| | |
| | | return strrpos($haystack, $needle, $offset); |
| | | } |
| | | |
| | | /** |
| | | * Wrapper function for wordwrap |
| | | */ |
| | | function rc_wordwrap($string, $width=75, $break="\n", $cut=false) |
| | | { |
| | | if (!function_exists('mb_substr') || !function_exists('mb_strlen')) |
| | | return wordwrap($string, $width, $break, $cut); |
| | | |
| | | $para = explode($break, $string); |
| | | $string = ''; |
| | | while (count($para)) { |
| | | $list = explode(' ', array_shift($para)); |
| | | $len = 0; |
| | | while (count($list)) { |
| | | $line = array_shift($list); |
| | | $l = mb_strlen($line); |
| | | $newlen = $len + $l + ($len ? 1 : 0); |
| | | |
| | | if ($newlen <= $width) { |
| | | $string .= ($len ? ' ' : '').$line; |
| | | $len += ($len ? 1 : 0) + $l; |
| | | } else { |
| | | if ($l > $width) { |
| | | if ($cut) { |
| | | $start = 0; |
| | | while ($l) { |
| | | $str = mb_substr($line, $start, $width); |
| | | $strlen = mb_strlen($str); |
| | | $string .= ($len ? $break : '').$str; |
| | | $start += $strlen; |
| | | $l -= $strlen; |
| | | $len = $strlen; |
| | | } |
| | | } else { |
| | | $string .= ($len ? $break : '').$line; |
| | | if (count($list)) $string .= $break; |
| | | $len = 0; |
| | | } |
| | | } else { |
| | | $string .= $break.$line; |
| | | $len = $l; |
| | | } |
| | | } |
| | | } |
| | | if (count($para)) $string .= $break; |
| | | } |
| | | return $string; |
| | | } |
| | | |
| | | /** |
| | | * Read a specific HTTP request header |
| | |
| | | * A method to guess the mime_type of an attachment. |
| | | * |
| | | * @param string $path Path to the file. |
| | | * @param string $name File name (with suffix) |
| | | * @param string $failover Mime type supplied for failover. |
| | | * |
| | | * @return string |
| | |
| | | * @see http://de2.php.net/manual/en/ref.fileinfo.php |
| | | * @see http://de2.php.net/mime_content_type |
| | | */ |
| | | function rc_mime_content_type($path, $failover = 'application/octet-stream') |
| | | function rc_mime_content_type($path, $name, $failover = 'application/octet-stream') |
| | | { |
| | | $mime_type = null; |
| | | $mime_magic = rcmail::get_instance()->config->get('mime_magic'); |
| | | $mime_ext = @include(RCMAIL_CONFIG_DIR . '/mimetypes.php'); |
| | | $suffix = $name ? substr($name, strrpos($name, '.')+1) : '*'; |
| | | |
| | | if (!extension_loaded('fileinfo')) { |
| | | @dl('fileinfo.' . PHP_SHLIB_SUFFIX); |
| | | // use file name suffix with hard-coded mime-type map |
| | | if (is_array($mime_ext)) { |
| | | $mime_type = $mime_ext[$suffix]; |
| | | } |
| | | |
| | | if (function_exists('finfo_open')) { |
| | | if ($finfo = finfo_open(FILEINFO_MIME, $mime_magic)) { |
| | | $mime_type = finfo_file($finfo, $path); |
| | | finfo_close($finfo); |
| | | // try fileinfo extension if available |
| | | if (!$mime_type) { |
| | | if (!extension_loaded('fileinfo')) { |
| | | @dl('fileinfo.' . PHP_SHLIB_SUFFIX); |
| | | } |
| | | if (function_exists('finfo_open')) { |
| | | if ($finfo = finfo_open(FILEINFO_MIME, $mime_magic)) { |
| | | $mime_type = finfo_file($finfo, $path); |
| | | finfo_close($finfo); |
| | | } |
| | | } |
| | | } |
| | | // try PHP's mime_content_type |
| | | if (!$mime_type && function_exists('mime_content_type')) { |
| | | $mime_type = mime_content_type($path); |
| | | } |
| | | |
| | | // fall back to user-submitted string |
| | | if (!$mime_type) { |
| | | $mime_type = $failover; |
| | | } |
| | |
| | | return $result ? $result : $failover; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Explode quoted string |
| | | * |
| | | * @param string Delimiter expression string for preg_match() |
| | | * @param string Input string |
| | | */ |
| | | function rcube_explode_quoted_string($delimiter, $string) |
| | | { |
| | | $result = array(); |
| | | $strlen = strlen($string); |
| | | |
| | | for ($q=$p=$i=0; $i < $strlen; $i++) { |
| | | if ($string[$i] == "\"" && $string[$i-1] != "\\") { |
| | | $q = $q ? false : true; |
| | | } |
| | | else if (!$q && preg_match("/$delimiter/", $string[$i])) { |
| | | $result[] = substr($string, $p, $i - $p); |
| | | $p = $i + 1; |
| | | } |
| | | } |
| | | |
| | | $result[] = substr($string, $p); |
| | | return $result; |
| | | } |
| | | |
| | | ?> |