From 70e5dbf50f94d41561fbbd27e09008c1de5dfc7e Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Tue, 15 Mar 2016 15:30:17 +0000 Subject: [PATCH] further refinement on activate_links --- api/src/Html.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/api/src/Html.php b/api/src/Html.php index b72a136f5f..fc5e79b21e 100644 --- a/api/src/Html.php +++ b/api/src/Html.php @@ -79,13 +79,26 @@ class Html $NotHTTP = '(?)'; // avoid running again on http://www links already handled above $Domain2 = 'www(\.[\w-.]+)'; $Subdir2 = '([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?'; - $optBracket = '(>|>)?'; + $optBracket = '(>|>|>|;)?'; $Expr = '/' .$optBracket0. $NotAnchor . $NotHTTP . $Domain2 . $Subdir2 .$optBracket. '/i'; //$Expr = '/' . $NotAnchor . $NotHTTP . $Domain . $Subdir . $optBracket . '/i'; + // use preg_replace_callback as we experienced problems with links such as + $result4 = preg_replace_callback( $Expr, function ($match) { + //error_log(__METHOD__.__LINE__.array2string($match)); + if ($match[4]==';' && (strlen($match[3])-4) >=0 && strpos($match[3],'>',strlen($match[3])-4)!==false) + { + $match[3] = substr($match[3],0,strpos($match[3],'>',strlen($match[3])-4)); + $match[4] = ">"; + } + if ($match[4]==';'&&$match[3]==">") + { + $match[3] =''; + $match[4] = ">"; + } + //error_log(__METHOD__.__LINE__.array2string($match)); + return $match[1].""."www".$match[2].$match[3]."".$match[4]; + }, $result3 ); } - $result4 = preg_replace( $Expr, "$1www$2$3$4$5$6", $result3 ); - - //return preg_replace( $Expr, "www$1$2$3 ", $result ); return $result4; }