From 49dad5f669965ca6149c2d759ede2a91fa571149 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 27 May 2014 11:39:31 +0200 Subject: Fix broken normalize_string(), add support for ISO-8859-2 --- program/lib/Roundcube/rcube_utils.php | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'program/lib/Roundcube/rcube_utils.php') diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index c2009cee0..00999ba50 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -928,7 +928,7 @@ class rcube_utils /** * Normalize the given string for fulltext search. - * Currently only optimized for Latin-1 characters; to be extended + * Currently only optimized for ISO-8859-1 and ISO-8859-2 characters; to be extended * * @param string Input string (UTF-8) * @param boolean True to return list of words as array @@ -949,15 +949,32 @@ class rcube_utils // split by words $arr = self::tokenize_string($str); + // detect character set + if (utf8_encode(utf8_decode($str)) == $str) { + // ISO-8859-1 (or ASCII) + preg_match_all('/./u', 'äâàåáãæçéêëèïîìíñöôòøõóüûùúýÿ', $keys); + preg_match_all('/./', 'aaaaaaaceeeeiiiinoooooouuuuyy', $values); + + $mapping = array_combine($keys[0], $values[0]); + $mapping = array_merge($mapping, array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')); + } + else if (rcube_charset::convert(rcube_charset::convert($str, 'UTF-8', 'ISO-8859-2'), 'ISO-8859-2', 'UTF-8') == $str) { + // ISO-8859-2 + preg_match_all('/./u', 'ąáâäćçčéęëěíîłľĺńňóôöŕřśšşťţůúűüźžżý', $keys); + preg_match_all('/./', 'aaaaccceeeeiilllnnooorrsssttuuuuzzzy', $values); + + $mapping = array_combine($keys[0], $values[0]); + $mapping = array_merge($mapping, array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')); + } + foreach ($arr as $i => $part) { - if (utf8_encode(utf8_decode($part)) == $part) { // is latin-1 ? - $arr[$i] = utf8_encode(strtr(strtolower(strtr(utf8_decode($part), - 'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ', - 'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')), - array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u'))); + $part = mb_strtolower($part); + + if (!empty($mapping)) { + $part = strtr($part, $mapping); } - else - $arr[$i] = mb_strtolower($part); + + $arr[$i] = $part; } return $as_array ? $arr : join(" ", $arr); @@ -1039,7 +1056,6 @@ class rcube_utils } } - /** * Find out if the string content means true or false * -- cgit v1.2.3 From cc850263d40ac080890f2b9f7bb797f83e7a30ff Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 31 Jul 2014 14:29:08 +0200 Subject: Add optional timezone argument for date conversion --- program/lib/Roundcube/rcube_utils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'program/lib/Roundcube/rcube_utils.php') diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 00999ba50..39e27fc7f 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -795,7 +795,7 @@ class rcube_utils * * @return object DateTime instance or false on failure */ - public static function anytodatetime($date) + public static function anytodatetime($date, $timezone = null) { if (is_object($date) && is_a($date, 'DateTime')) { return $date; @@ -807,7 +807,7 @@ class rcube_utils // try to parse string with DateTime first if (!empty($date)) { try { - $dt = new DateTime($date); + $dt = new DateTime($date, $timezone); } catch (Exception $e) { // ignore -- cgit v1.2.3 From 75bbada03b0e616248ec3458d1a6ee98bfc03659 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 24 Aug 2014 11:23:33 +0200 Subject: Remove code for PHP<5.3, use PHP_VERSION_ID instead of version_compare() for version checks --- program/include/rcmail.php | 2 +- program/lib/Roundcube/rcube_utils.php | 11 ----------- program/lib/Roundcube/rcube_washtml.php | 2 +- 3 files changed, 2 insertions(+), 13 deletions(-) (limited to 'program/lib/Roundcube/rcube_utils.php') diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 0c41c1598..52b53e9d9 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -173,7 +173,7 @@ class rcmail extends rcube setlocale(LC_ALL, $lang . '.utf8', $lang . '.UTF-8', 'en_US.utf8', 'en_US.UTF-8'); // workaround for http://bugs.php.net/bug.php?id=18556 - if (version_compare(PHP_VERSION, '5.5.0', '<') && in_array($lang, array('tr_TR', 'ku', 'az_AZ'))) { + if (PHP_VERSION_ID < 50500 && in_array($lang, array('tr_TR', 'ku', 'az_AZ'))) { setlocale(LC_CTYPE, 'en_US.utf8', 'en_US.UTF-8'); } } diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 39e27fc7f..86d9eb2cc 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -119,17 +119,6 @@ class rcube_utils return true; } - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && version_compare(PHP_VERSION, '5.3.0', '<')) { - $lookup = array(); - @exec("nslookup -type=MX " . escapeshellarg($domain_part) . " 2>&1", $lookup); - foreach ($lookup as $line) { - if (strpos($line, 'MX preference')) { - return true; - } - } - return false; - } - // find MX record(s) if (!function_exists('getmxrr') || getmxrr($domain_part, $mx_records)) { return true; diff --git a/program/lib/Roundcube/rcube_washtml.php b/program/lib/Roundcube/rcube_washtml.php index b93d3b117..97ab56cdf 100644 --- a/program/lib/Roundcube/rcube_washtml.php +++ b/program/lib/Roundcube/rcube_washtml.php @@ -378,7 +378,7 @@ class rcube_washtml $this->max_nesting_level = (int) @ini_get('xdebug.max_nesting_level'); // Use optimizations if supported - if (version_compare(PHP_VERSION, '5.4.0', '>=')) { + if (PHP_VERSION_ID >= 50400) { @$node->loadHTML($html, LIBXML_PARSEHUGE | LIBXML_COMPACT); } else { -- cgit v1.2.3 From 5f58127eae9ed8c54c190506e11af13e8ba57170 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 24 Aug 2014 11:43:12 +0200 Subject: Added rcube_utils::resolve_url() --- program/include/rcmail.php | 21 ++++++--------------- program/lib/Roundcube/rcube_utils.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 15 deletions(-) (limited to 'program/lib/Roundcube/rcube_utils.php') diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 52b53e9d9..ece0606ae 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -827,26 +827,17 @@ class rcmail extends rcube } if ($absolute || $full) { - $prefix = ''; + // add base path to this Roundcube installation + $base_path = preg_replace('![^/]+$!', '', strval($_SERVER['SCRIPT_NAME'])); + if ($base_path == '') $base_path = '/'; + $prefix = $base_path; // prepend protocol://hostname:port if ($full) { - $schema = 'http'; - $default_port = 80; - if (rcube_utils::https_check()) { - $schema = 'https'; - $default_port = 443; - } - $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']); - if ($_SERVER['SERVER_PORT'] != $default_port) { - $prefix .= ':' . $_SERVER['SERVER_PORT']; - } + $prefix = rcube_utils::resolve_url($prefix); } - // add base path to this Roundcube installation - $base_path = preg_replace('![^/]+$!', '', strval($_SERVER['SCRIPT_NAME'])); - if ($base_path == '') $base_path = '/'; - $prefix .= $base_path; + $prefix = rtrim($prefix, '/') . '/'; } else { $prefix = './'; diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 86d9eb2cc..ef303f8c1 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -1071,4 +1071,34 @@ class rcube_utils return $path[0] == DIRECTORY_SEPARATOR; } } + + /** + * Resolve relative URL + * + * @param string $url Relative URL + * + * @return string Absolute URL + */ + public static function resolve_url($url) + { + // prepend protocol://hostname:port + if (!preg_match('|^https?://|', $url)) { + $schema = 'http'; + $default_port = 80; + + if (self::https_check()) { + $schema = 'https'; + $default_port = 443; + } + + $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']); + if ($_SERVER['SERVER_PORT'] != $default_port) { + $prefix .= ':' . $_SERVER['SERVER_PORT']; + } + + $url = $prefix . ($url[0] == '/' ? '' : '/') . $url; + } + + return $url; + } } -- cgit v1.2.3 From 29c24e647cb4c4a0928382a9ab2964980898562b Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 28 Aug 2014 19:24:03 +0200 Subject: Get rid of DIRECTORY_SEPARATOR for consistency --- bin/update.sh | 2 +- bin/updatedb.sh | 4 ++-- program/lib/Roundcube/bootstrap.php | 2 +- program/lib/Roundcube/rcube_plugin_api.php | 5 ++--- program/lib/Roundcube/rcube_utils.php | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) (limited to 'program/lib/Roundcube/rcube_utils.php') diff --git a/bin/update.sh b/bin/update.sh index 91af6413d..f0c6d2f6c 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -157,7 +157,7 @@ if ($RCI->configured) { if ($RCI->config['db_dsnw']) { echo "Executing database schema update.\n"; system("php " . INSTALL_PATH . "bin/updatedb.sh --package=roundcube --version=" . $opts['version'] - . " --dir=" . INSTALL_PATH . DIRECTORY_SEPARATOR . "SQL", $res); + . " --dir=" . INSTALL_PATH . "SQL", $res); $success = !$res; } diff --git a/bin/updatedb.sh b/bin/updatedb.sh index daee6e835..964bc184c 100755 --- a/bin/updatedb.sh +++ b/bin/updatedb.sh @@ -116,7 +116,7 @@ if (empty($version)) { $version = 2012080700; } -$dir = $opts['dir'] . DIRECTORY_SEPARATOR . $DB->db_provider; +$dir = $opts['dir'] . '/' . $DB->db_provider; if (!file_exists($dir)) { rcube::raise_error("DDL Upgrade files for " . $DB->db_provider . " driver not found.", false, true); } @@ -133,7 +133,7 @@ sort($result, SORT_NUMERIC); foreach ($result as $v) { echo "Updating database schema ($v)... "; - $error = update_db_schema($opts['package'], $v, $dir . DIRECTORY_SEPARATOR . "$v.sql"); + $error = update_db_schema($opts['package'], $v, "$dir/$v.sql"); if ($error) { echo "[FAILED]\n"; diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php index 0aa5cb1de..98bbce5d4 100644 --- a/program/lib/Roundcube/bootstrap.php +++ b/program/lib/Roundcube/bootstrap.php @@ -58,7 +58,7 @@ define('RCUBE_VERSION', '1.1-git'); define('RCUBE_CHARSET', 'UTF-8'); if (!defined('RCUBE_LIB_DIR')) { - define('RCUBE_LIB_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); + define('RCUBE_LIB_DIR', dirname(__FILE__) . '/'); } if (!defined('RCUBE_INSTALL_PATH')) { diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php index defccc94f..e0b8aea38 100644 --- a/program/lib/Roundcube/rcube_plugin_api.php +++ b/program/lib/Roundcube/rcube_plugin_api.php @@ -188,8 +188,7 @@ class rcube_plugin_api return true; } - $fn = $plugins_dir . DIRECTORY_SEPARATOR . $plugin_name - . DIRECTORY_SEPARATOR . $plugin_name . '.php'; + $fn = "$plugins_dir/$plugin_name/$plugin_name.php"; if (is_readable($fn)) { if (!class_exists($plugin_name, false)) { @@ -279,7 +278,7 @@ class rcube_plugin_api ); $dir = dir($this->dir); - $fn = unslashify($dir->path) . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . $plugin_name . '.php'; + $fn = unslashify($dir->path) . "/$plugin_name/$plugin_name.php"; $info = false; if (!class_exists($plugin_name, false)) { diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index ef303f8c1..330322f10 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -1068,7 +1068,7 @@ class rcube_utils return (bool) preg_match('!^[a-z]:[\\\\/]!i', $path); } else { - return $path[0] == DIRECTORY_SEPARATOR; + return $path[0] == '/'; } } -- cgit v1.2.3