From 4391a7809edae1b552f0720a43924212519900a9 Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Fri, 13 Jan 2012 06:21:45 -0500 Subject: [PATCH] - Make mime type detection based on filename extension to be case-insensitive --- program/include/main.inc | 136 ++++++++++++++++++++++++++++++++++---------- 1 files changed, 104 insertions(+), 32 deletions(-) diff --git a/program/include/main.inc b/program/include/main.inc index 012ee8d..9f154e4 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -839,11 +839,11 @@ function rcmail_get_edit_field($col, $value, $attrib, $type='text') { static $colcounts = array(); - + $fname = '_'.$col; $attrib['name'] = $fname . ($attrib['array'] ? '[]' : ''); $attrib['class'] = trim($attrib['class'] . ' ff_' . $col); - + if ($type == 'checkbox') { $attrib['value'] = '1'; $input = new html_checkbox($attrib); @@ -856,6 +856,9 @@ $input = new html_select($attrib); $input->add('---', ''); $input->add(array_values($attrib['options']), array_keys($attrib['options'])); + } + else if ($attrib['type'] == 'password') { + $input = new html_passwordfield($attrib); } else { if ($attrib['type'] != 'text' && $attrib['type'] != 'hidden') @@ -1059,20 +1062,23 @@ if (empty($ts)) return ''; - if ($convert) { - // get user's timezone offset - $tz = $RCMAIL->config->get_timezone(); - - // convert time to user's timezone - $timestamp = $ts - date('Z', $ts) + ($tz * 3600); - - // get current timestamp in user's timezone - $now = time(); // local time - $now -= (int)date('Z'); // make GMT time - $now += ($tz * 3600); // user's time + try { + $date = new DateTime("@".$ts); } - else { - $now = time(); + catch (Exception $e) { + return ''; + } + + try { + // convert to the right timezone + $stz = date_default_timezone_get(); + $tz = new DateTimeZone($convert ? $RCMAIL->config->get('timezone') : 'GMT'); + $date->setTimezone($tz); + date_default_timezone_set($tz->getName()); + + $timestamp = $date->format('U'); + } + catch (Exception $e) { $timestamp = $ts; } @@ -1095,6 +1101,7 @@ // strftime() format if (preg_match('/%[a-z]+/i', $format)) { $format = strftime($format, $timestamp); + date_default_timezone_set($stz); return $today ? (rcube_label('today') . ' ' . $format) : $format; } @@ -1110,20 +1117,20 @@ $out .= $format[$i]; // weekday (short) else if ($format[$i]=='D') - $out .= rcube_label(strtolower(date('D', $timestamp))); + $out .= rcube_label(strtolower($date->format('D'))); // weekday long else if ($format[$i]=='l') - $out .= rcube_label(strtolower(date('l', $timestamp))); + $out .= rcube_label(strtolower($date->format('l'))); // month name (short) else if ($format[$i]=='M') - $out .= rcube_label(strtolower(date('M', $timestamp))); + $out .= rcube_label(strtolower($date->format('M'))); // month name (long) else if ($format[$i]=='F') - $out .= rcube_label('long'.strtolower(date('M', $timestamp))); + $out .= rcube_label('long'.strtolower($date->format('M'))); else if ($format[$i]=='x') $out .= strftime('%x %X', $timestamp); else - $out .= date($format[$i], $timestamp); + $out .= $date->format($format[$i]); } if ($today) { @@ -1137,6 +1144,7 @@ } } + date_default_timezone_set($stz); return $out; } @@ -1619,12 +1627,14 @@ list($primary, $secondary) = explode('/', $mimetype); $classes = array($primary ? $primary : 'unknown'); - if ($secondary) + if ($secondary) { $classes[] = $secondary; - if (preg_match('/\.([a-z0-9]+)$/', $filename, $m)) + } + if (preg_match('/\.([a-z0-9]+)$/i', $filename, $m)) { $classes[] = $m[1]; + } - return join(" ", $classes); + return strtolower(join(" ", $classes)); } /** @@ -1875,17 +1885,18 @@ // Returns RFC2822 formatted current date in user's timezone function rcmail_user_date() { - global $RCMAIL, $CONFIG; + global $RCMAIL; // get user's timezone - $tz = $RCMAIL->config->get_timezone(); + try { + $tz = new DateTimeZone($RCMAIL->config->get('timezone')); + $date = new DateTime('now', $tz); + } + catch (Exception $e) { + $date = new DateTime(); + } - $date = time() + $tz * 60 * 60; - $date = gmdate('r', $date); - $tz = sprintf('%+05d', intval($tz) * 100 + ($tz - intval($tz)) * 60); - $date = preg_replace('/[+-][0-9]{4}$/', $tz, $date); - - return $date; + return $date->format('r'); } @@ -2098,7 +2109,68 @@ public function callback($matches) { - return $matches[1] . '="' . make_absolute_url($matches[3], $this->base_url) . '"'; + return $matches[1] . '="' . self::absolute_url($matches[3], $this->base_url) . '"'; + } + + public function replace($body) + { + return preg_replace_callback(array( + '/(src|background|href)=(["\']?)([^"\'\s]+)(\2|\s|>)/Ui', + '/(url\s*\()(["\']?)([^"\'\)\s]+)(\2)\)/Ui', + ), + array($this, 'callback'), $body); + } + + /** + * Convert paths like ../xxx to an absolute path using a base url + * + * @param string $path Relative path + * @param string $base_url Base URL + * + * @return string Absolute URL + */ + public static function absolute_url($path, $base_url) + { + $host_url = $base_url; + $abs_path = $path; + + // check if path is an absolute URL + if (preg_match('/^[fhtps]+:\/\//', $path)) { + return $path; + } + + // check if path is a content-id scheme + if (strpos($path, 'cid:') === 0) { + return $path; + } + + // cut base_url to the last directory + if (strrpos($base_url, '/') > 7) { + $host_url = substr($base_url, 0, strpos($base_url, '/', 7)); + $base_url = substr($base_url, 0, strrpos($base_url, '/')); + } + + // $path is absolute + if ($path[0] == '/') { + $abs_path = $host_url.$path; + } + else { + // strip './' because its the same as '' + $path = preg_replace('/^\.\//', '', $path); + + if (preg_match_all('/\.\.\//', $path, $matches, PREG_SET_ORDER)) { + foreach ($matches as $a_match) { + if (strrpos($base_url, '/')) { + $base_url = substr($base_url, 0, strrpos($base_url, '/')); + } + $path = substr($path, 3); + } + } + + $abs_path = $base_url.'/'.$path; + } + + return $abs_path; } } -- Gitblit v1.9.1