From f5e00e4bad20885f87016a595ef20966e80f8a3b Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Thu, 29 Aug 2013 10:39:08 +0000 Subject: [PATCH] add (and use) preg replace callback for mailto link to text transformation --- phpgwapi/inc/class.translation.inc.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/phpgwapi/inc/class.translation.inc.php b/phpgwapi/inc/class.translation.inc.php index f5bff2db2e..1197c33195 100644 --- a/phpgwapi/inc/class.translation.inc.php +++ b/phpgwapi/inc/class.translation.inc.php @@ -963,7 +963,9 @@ class translation $text = str_replace("\r\n",'<#cr-lf#>',$text); // replace emailaddresses eclosed in <> (eg.: ) with the emailaddress only (e.g: me@you.de) $text = preg_replace("/(<|<a href=\")*(mailto:([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))(>|>)*/ie","'$2 '", $text); - $text = preg_replace('~]+href=\"(mailto:)+([^"]+)\"[^>]*>~si','$2 ',$text); + //$text = preg_replace_callback("/(<|<a href=\")*(mailto:([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))(>|>)*/i",'self::transform_mailto2text',$text); + //$text = preg_replace('~]+href=\"(mailto:)+([^"]+)\"[^>]*>~si','$2 ',$text); + $text = preg_replace_callback('~]+href=\"(mailto:)+([^"]+)\"[^>]*>([ @\w\.,-.,_.,0-9.]+)<\/a>~si','self::transform_mailto2text',$text); $text = preg_replace("/(([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))( |\s)*(<\/a>)*( |\s)*(>|>)*/ie","'$1 '", $text); $text = preg_replace("/(<|<)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|>)*/ie","'$2 '", $text); $text = str_replace('<#cr-lf#>',"\r\n",$text); @@ -1020,6 +1022,18 @@ class translation } } + static function transform_mailto2text($matches) + { + //error_log(__METHOD__.__LINE__.array2string($matches)); + $linkTextislink = false; + // this is the actual url + $matches[2] = trim(strip_tags($matches[2])); + $matches[3] = trim(strip_tags($matches[3])); + $matches[2] = str_replace(array('%40','%20'),array('@',' '),$matches[2]); + $matches[3] = str_replace(array('%40','%20'),array('@',' '),$matches[3]); + return $matches[1].$matches[2].($matches[2]==$matches[3]?' ':' -> '.$matches[3].' '); + } + static function transform_url2text($matches) { //error_log(__METHOD__.__LINE__.array2string($matches));