X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Finclude%2Frcube_string_replacer.php;fp=program%2Finclude%2Frcube_string_replacer.php;h=2625fdfb9a8b34b7bff594c3975c99e6f85bb000;hb=b68022ca3782d5eb5a1a7ef6f8cf7abe1dc15bd6;hp=fe082a583c98b1e57a0f1658058dafab72dd917d;hpb=162c8d010934c01433e8125382fb493712575198;p=roundcube.git diff --git a/program/include/rcube_string_replacer.php b/program/include/rcube_string_replacer.php index fe082a5..2625fdf 100644 --- a/program/include/rcube_string_replacer.php +++ b/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,16 +74,17 @@ 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 (preg_match('!^(http|ftp|file)s?://!', $scheme)) { + $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) : ''; + // Return valid link for recognized schemes, otherwise, return the unmodified string for unrecognized schemes. + return $i >= 0 ? $this->get_replacement($i) : $matches[0]; } /**