diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2009-06-04 10:27:19 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2009-06-04 10:27:19 +0000 |
| commit | 268292802dbfb6c6550820011f5a3e195be17c75 (patch) | |
| tree | a505880b23ab3865a02d37880f13fd9d277c888f /roundcubemail/program/include/rcube_string_replacer.php | |
| parent | 696f90118cd93f69b54099e571d243b0153bbb2b (diff) | |
- speed up plain text messages parsing (up to 60%)
git-svn-id: https://svn.roundcube.net/trunk@2606 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include/rcube_string_replacer.php')
| -rw-r--r-- | roundcubemail/program/include/rcube_string_replacer.php | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/roundcubemail/program/include/rcube_string_replacer.php b/roundcubemail/program/include/rcube_string_replacer.php index fe082a583..064a723a2 100644 --- a/roundcubemail/program/include/rcube_string_replacer.php +++ b/roundcubemail/program/include/rcube_string_replacer.php @@ -28,10 +28,20 @@ class rcube_string_replacer { public static $pattern = '/##str_replacement\[([0-9]+)\]##/'; - + public $mailto_pattern; + public $link_pattern; private $values = array(); + function __construct() + { + $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;'; + $url_chars_within = '\?\.~,!'; + + $this->link_pattern = "/([\w]+:\/\/|\Wwww\.)([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/i"; + $this->mailto_pattern = "/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i"; + } + /** * Add a string to the internal list * @@ -64,13 +74,13 @@ class rcube_string_replacer $i = -1; $scheme = strtolower($matches[1]); - if ($scheme == 'http' || $scheme == 'https' || $scheme == 'ftp') { - $url = $matches[1] . '://' . $matches[2]; - $i = $this->add(html::a(array('href' => $url, 'target' => "_blank"), Q($url))); + if ($scheme == 'http://' || $scheme == 'https://' || $scheme == 'ftp://') { + $url = $matches[1] . $matches[2]; + $i = $this->add(html::a(array('href' => $url, 'target' => '_blank'), Q($url))); } - else if ($matches[2] == 'www.') { - $url = $matches[2] . $matches[3]; - $i = $this->add($matches[1] . html::a(array('href' => 'http://' . $url, 'target' => "_blank"), Q($url))); + else if (preg_match('/^(\W)www\.$/', $matches[1], $m)) { + $url = 'www.' . $matches[2]; + $i = $this->add($m[1] . html::a(array('href' => 'http://' . $url, 'target' => '_blank'), Q($url))); } return $i >= 0 ? $this->get_replacement($i) : ''; |
