thomascube
2010-04-01 1d773d71414316e0b9836a15c35576593427ee21
program/include/rcube_shared.inc
@@ -39,6 +39,8 @@
  header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
  header("Cache-Control: private, must-revalidate, post-check=0, pre-check=0");
  header("Pragma: no-cache");
  // Request browser to disable DNS prefetching (CVE-2010-0464)
  header("X-DNS-Prefetch-Control: off");
  
  // We need to set the following headers to make downloads work using IE in HTTPS mode.
  if (rcube_https_check()) {
@@ -408,12 +410,13 @@
function abbreviate_string($str, $maxlength, $place_holder='...')
{
  $length = mb_strlen($str);
  $first_part_length = floor($maxlength/2) - mb_strlen($place_holder);
  
  if ($length > $maxlength)
  {
    $second_starting_location = $length - $maxlength + $first_part_length + 1;
    $str = mb_substr($str, 0, $first_part_length) . $place_holder . mb_substr($str, $second_starting_location, $length);
    $place_holder_length = mb_strlen($place_holder);
    $first_part_length = floor(($maxlength - $place_holder_length)/2);
    $second_starting_location = $length - $maxlength + $first_part_length + $place_holder_length;
    $str = mb_substr($str, 0, $first_part_length) . $place_holder . mb_substr($str, $second_starting_location);
  }
  return $str;
@@ -443,20 +446,15 @@
        $mime_type = $mime_ext[$suffix];
    }
    // 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);
            }
    if (!$mime_type && 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);
      $mime_type = mime_content_type($path);
    }
    // fall back to user-submitted string
    if (!$mime_type) {
@@ -515,10 +513,10 @@
    return $input;
  // iconv/mbstring are much faster (especially with long strings)
  if (function_exists('mb_convert_encoding') && ($res = mb_convert_encoding($input, 'UTF8', 'UTF8')) !== false)
  if (function_exists('mb_convert_encoding') && ($res = mb_convert_encoding($input, 'UTF-8', 'UTF-8')) !== false)
    return $res;
  if (function_exists('iconv') && ($res = iconv('UTF8', 'UTF8//IGNORE', $input)) !== false)
  if (function_exists('iconv') && ($res = @iconv('UTF-8', 'UTF-8//IGNORE', $input)) !== false)
    return $res;
  $regexp = '/^('.
@@ -536,7 +534,7 @@
  $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
@@ -577,7 +575,9 @@
{
  $input = rc_utf8_clean($input);
  return json_encode($input);
  // sometimes even using rc_utf8_clean() the input contains invalid UTF-8 sequences
  // that's why we have @ here
  return @json_encode($input);
}
@@ -608,6 +608,26 @@
/**
 * Get all keys from array (recursive)
 *
 * @param array Input array
 * @return array
 */
function array_keys_recursive($array)
{
  $keys = array();
  if (!empty($array))
    foreach ($array as $key => $child) {
      $keys[] = $key;
      if ($children = array_keys_recursive($child))
        $keys = array_merge($keys, $children);
    }
  return $keys;
}
/**
 * mbstring replacement functions
 */