From 2aa2b332f6e216ceeabc36ef6b942c40d91bda5a Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 08 Sep 2010 05:40:39 -0400
Subject: [PATCH] - Small performance improvements

---
 program/include/main.inc               |    2 +-
 program/include/rcube_imap.php         |    4 ++--
 program/include/rcmail.php             |    6 +++---
 program/include/rcube_browser.php      |   32 ++++++++++++++++----------------
 program/include/rcube_template.php     |    5 ++++-
 program/include/rcube_imap_generic.php |    4 ++--
 6 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/program/include/main.inc b/program/include/main.inc
index fa5534f..04992fd 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -700,7 +700,7 @@
  */
 function strip_quotes($str)
 {
-  return preg_replace('/[\'"]/', '', $str);
+  return str_replace(array("'", '"'), '', $str);
 }
 
 
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 808f0db..0a7c15d 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -810,9 +810,9 @@
     if (($attrib['uppercase'] && strtolower($attrib['uppercase']=='first')) || $attrib['ucfirst'])
       return ucfirst($text);
     else if ($attrib['uppercase'])
-      return strtoupper($text);
+      return mb_strtoupper($text);
     else if ($attrib['lowercase'])
-      return strtolower($text);
+      return mb_strtolower($text);
 
     return $text;
   }
@@ -874,7 +874,7 @@
 
       if ($dh = @opendir(INSTALL_PATH . 'program/localization')) {
         while (($name = readdir($dh)) !== false) {
-          if ($name{0}=='.' || !is_dir(INSTALL_PATH . 'program/localization/' . $name))
+          if ($name[0] == '.' || !is_dir(INSTALL_PATH . 'program/localization/' . $name))
             continue;
 
           if ($label = $rcube_languages[$name])
diff --git a/program/include/rcube_browser.php b/program/include/rcube_browser.php
index 23ef615..361ffb6 100644
--- a/program/include/rcube_browser.php
+++ b/program/include/rcube_browser.php
@@ -30,25 +30,25 @@
 {
     function __construct()
     {
-        $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
+        $HTTP_USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
 
         $this->ver = 0;
-        $this->win = stristr($HTTP_USER_AGENT, 'win');
-        $this->mac = stristr($HTTP_USER_AGENT, 'mac');
-        $this->linux = stristr($HTTP_USER_AGENT, 'linux');
-        $this->unix  = stristr($HTTP_USER_AGENT, 'unix');
+        $this->win = strstr($HTTP_USER_AGENT, 'win');
+        $this->mac = strstr($HTTP_USER_AGENT, 'mac');
+        $this->linux = strstr($HTTP_USER_AGENT, 'linux');
+        $this->unix  = strstr($HTTP_USER_AGENT, 'unix');
 
-        $this->opera = stristr($HTTP_USER_AGENT, 'opera');
-        $this->ns4 = stristr($HTTP_USER_AGENT, 'mozilla/4') && !stristr($HTTP_USER_AGENT, 'msie');
-        $this->ns  = ($this->ns4 || stristr($HTTP_USER_AGENT, 'netscape'));
-        $this->ie  = stristr($HTTP_USER_AGENT, 'compatible; msie') && !$this->opera;
-        $this->mz  = stristr($HTTP_USER_AGENT, 'mozilla/5');
-        $this->chrome = stristr($HTTP_USER_AGENT, 'chrome');
-        $this->khtml = stristr($HTTP_USER_AGENT, 'khtml');
-        $this->safari = !$this->chrome && ($this->khtml || stristr($HTTP_USER_AGENT, 'safari'));
+        $this->opera = strstr($HTTP_USER_AGENT, 'opera');
+        $this->ns4 = strstr($HTTP_USER_AGENT, 'mozilla/4') && !strstr($HTTP_USER_AGENT, 'msie');
+        $this->ns  = ($this->ns4 || strstr($HTTP_USER_AGENT, 'netscape'));
+        $this->ie  = !$this->opera && strstr($HTTP_USER_AGENT, 'compatible; msie');
+        $this->mz  = strstr($HTTP_USER_AGENT, 'mozilla/5');
+        $this->chrome = strstr($HTTP_USER_AGENT, 'chrome');
+        $this->khtml = strstr($HTTP_USER_AGENT, 'khtml');
+        $this->safari = !$this->chrome && ($this->khtml || strstr($HTTP_USER_AGENT, 'safari'));
 
         if ($this->ns || $this->chrome) {
-            $test = preg_match('/(mozilla|chrome)\/([0-9.]+)/i', $HTTP_USER_AGENT, $regs);
+            $test = preg_match('/(mozilla|chrome)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs);
             $this->ver = $test ? (float)$regs[2] : 0;
         }
         else if ($this->mz) {
@@ -56,11 +56,11 @@
             $this->ver = $test ? (float)$regs[1] : 0;
         }
         else if ($this->ie || $this->opera) {
-            $test = preg_match('/(msie|opera) ([0-9.]+)/i', $HTTP_USER_AGENT, $regs);
+            $test = preg_match('/(msie|opera) ([0-9.]+)/', $HTTP_USER_AGENT, $regs);
             $this->ver = $test ? (float)$regs[2] : 0;
         }
 
-        if (preg_match('/ ([a-z]{2})-([a-z]{2})/i', $HTTP_USER_AGENT, $regs))
+        if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $HTTP_USER_AGENT, $regs))
             $this->lang =  $regs[1];
         else
             $this->lang =  'en';
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index c5b10e6..043d902 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -3426,7 +3426,7 @@
             $name = trim($val['name']);
 
             if (preg_match('/^[\'"]/', $name) && preg_match('/[\'"]$/', $name))
-                $name = preg_replace(array('/^[\'"]/', '/[\'"]$/'), '', $name);
+                $name = trim($name, '\'"');
 
             if ($name && $address && $name != $address)
                 $string = sprintf('%s <%s>', preg_match("/$special_chars/", $name) ? '"'.addcslashes($name, '"').'"' : $name, $address);
@@ -3458,7 +3458,7 @@
     function decode_header($input, $remove_quotes=false)
     {
         $str = rcube_imap::decode_mime_string((string)$input, $this->default_charset);
-        if ($str{0}=='"' && $remove_quotes)
+        if ($str[0] == '"' && $remove_quotes)
             $str = str_replace('"', '', $str);
 
         return $str;
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 6cf86fc..0c69c23 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -1258,7 +1258,7 @@
 					    	}
         					break;
 					    case 'in-reply-to':
-			    			$result[$id]->in_reply_to = preg_replace('/[\n<>]/', '', $string);
+			    			$result[$id]->in_reply_to = str_replace(array("\n", '<', '>'), '', $string);
 				    		break;
     					case 'references':
 	    					$result[$id]->references = $string;
@@ -2115,7 +2115,7 @@
 	    // return false if not found, parse if found
 	    $min_free = PHP_INT_MAX;
 	    foreach ($quota_lines as $key => $quota_line) {
-		    $quota_line   = preg_replace('/[()]/', '', $quota_line);
+		    $quota_line   = str_replace(array('(', ')'), '', $quota_line);
 		    $parts        = explode(' ', $quota_line);
 		    $storage_part = array_search('STORAGE', $parts);
 
diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php
index 2c9e951..f301b36 100755
--- a/program/include/rcube_template.php
+++ b/program/include/rcube_template.php
@@ -444,7 +444,10 @@
      */
     public function abs_url($str)
     {
-        return preg_replace('/^\//', $this->config['skin_path'].'/', $str);
+        if ($str[0] == '/')
+            return $this->config['skin_path'] . $str;
+        else
+            return $str;
     }
 
 

--
Gitblit v1.9.1