alecpl
2008-04-29 257782150db70dbe852d1c71fe6fd8abda0229f0
program/include/rcube_shared.inc
@@ -91,8 +91,9 @@
 */
function rcube_label($attrib)
{
  global $sess_user_lang, $INSTALL_PATH, $OUTPUT;
  static $sa_text_data, $s_language, $utf8_decode;
  global $sess_user_lang, $OUTPUT;
  static $sa_text_data = false;
  static $s_language, $utf8_decode;
  // extract attributes
  if (is_string($attrib))
@@ -106,13 +107,13 @@
  // load localized texts
  if (!$sa_text_data || $s_language != $sess_user_lang)
  if ($sa_text_data===false || $s_language != $sess_user_lang)
    {
    $sa_text_data = array();
    
    // get english labels (these should be complete)
    @include($INSTALL_PATH.'program/localization/en_US/labels.inc');
    @include($INSTALL_PATH.'program/localization/en_US/messages.inc');
    @include(INSTALL_PATH.'program/localization/en_US/labels.inc');
    @include(INSTALL_PATH.'program/localization/en_US/messages.inc');
    if (is_array($labels))
      $sa_text_data = $labels;
@@ -120,10 +121,10 @@
      $sa_text_data = array_merge($sa_text_data, $messages);
    
    // include user language files
    if ($sess_user_lang!='en' && is_dir($INSTALL_PATH.'program/localization/'.$sess_user_lang))
    if ($sess_user_lang!='en' && is_dir(INSTALL_PATH.'program/localization/'.$sess_user_lang))
    {
      include_once($INSTALL_PATH.'program/localization/'.$sess_user_lang.'/labels.inc');
      include_once($INSTALL_PATH.'program/localization/'.$sess_user_lang.'/messages.inc');
      include_once(INSTALL_PATH.'program/localization/'.$sess_user_lang.'/labels.inc');
      include_once(INSTALL_PATH.'program/localization/'.$sess_user_lang.'/messages.inc');
      if (is_array($labels))
        $sa_text_data = array_merge($sa_text_data, $labels);
@@ -236,18 +237,22 @@
 * @param int Modified date as unix timestamp
 * @param string Etag value for caching
 */
function send_modified_header($mdate, $etag=null)
function send_modified_header($mdate, $etag=null, $skip_check=false)
{
  if (headers_sent())
    return;
    
  $iscached = false;
  if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $mdate)
    $iscached = true;
  $etag = $etag ? "\"$etag\"" : null;
  if ($etag && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
    $iscached = true;
  if (!$skip_check)
  {
    if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $mdate)
      $iscached = true;
    if ($etag)
      $iscached = ($_SERVER['HTTP_IF_NONE_MATCH'] == $etag);
  }
  
  if ($iscached)
    header("HTTP/1.x 304 Not Modified");
@@ -262,7 +267,10 @@
    header("Etag: $etag");
  
  if ($iscached)
    {
    ob_end_clean();
    exit;
    }
}
@@ -434,6 +442,10 @@
{
  $host_url = $base_url;
  $abs_path = $path;
  // check if path is an absolute URL
  if (preg_match('/^[fhtps]+:\/\//', $path))
    return $path;
  // cut base_url to the last directory
  if (strpos($base_url, '/')>7)
@@ -525,22 +537,25 @@
/**
 * Read a specific HTTP request header
 *
 * @param string Header name
 * @return string Header value or null if not available
 * @access static
 * @param  string $name Header name
 * @return mixed  Header value or null if not available
 */
function rc_request_header($name)
{
  if (function_exists('getallheaders'))
  {
    $hdrs = getallheaders();
    return $hdrs[$name];
    $hdrs = array_change_key_case(getallheaders(), CASE_UPPER);
    $key  = strtoupper($name);
  }
  else
  {
    $key = "HTTP_" . strtoupper(strtr($name, "-", "_"));
    return $_SERVER[$key];
    $key  = 'HTTP_' . strtoupper(strtr($name, '-', '_'));
    $hdrs = array_change_key_case($_SERVER, CASE_UPPER);
  }
}
  return $hdrs[$key];
  }
/**
@@ -550,9 +565,9 @@
 * @param string Input string
 * @param int    Max. length
 * @param string Replace removed chars with this
 * @return string Abbrevated string
 * @return string Abbreviated string
 */
function abbrevate_string($str, $maxlength, $place_holder='...')
function abbreviate_string($str, $maxlength, $place_holder='...')
{
  $length = rc_strlen($str);
  $first_part_length = floor($maxlength/2) - rc_strlen($place_holder);
@@ -645,27 +660,41 @@
/**
 * Return the last occurence of a string in another string
 * A method to guess the mime_type of an attachment.
 *
 * @param haystack string string in which to search
 * @param needle string string for which to search
 * @return index of needle within haystack, or false if not found
 * @param string $path     Path to the file.
 * @param string $failover Mime type supplied for failover.
 *
 * @return string
 * @author Till Klampaeckel <till@php.net>
 * @see    http://de2.php.net/manual/en/ref.fileinfo.php
 * @see    http://de2.php.net/mime_content_type
 */
function strrstr($haystack, $needle)
function rc_mime_content_type($path, $failover = 'unknown/unknown')
{
  $pver = phpversion();
  if ($pver[0] >= 5)
      return strrpos($haystack, $needle);
  else
  {
    $index = strpos(strrev($haystack), strrev($needle));
    if($index === false)
        return false;
    $index = strlen($haystack) - strlen($needle) - $index;
    return $index;
  }
    global $CONFIG;
    $mime_magic = $CONFIG['mime_magic'];
    if (function_exists('mime_content_type')) {
        return mime_content_type($path);
    }
    if (!extension_loaded('fileinfo')) {
        if (!dl('fileinfo.' . PHP_SHLIB_SUFFIX)) {
            return $failover;
        }
    }
    $finfo = finfo_open(FILEINFO_MIME, $mime_magic);
    if (!$finfo) {
        return $failover;
    }
    $mime_type = finfo_file($finfo,$path);
    if (!$mime_type) {
        return $failover;
    }
    finfo_close($finfo);
    return $mime_type;
}
?>
?>