From 0969aa7f98456138027530934e41748f5f11f808 Mon Sep 17 00:00:00 2001 From: www-data Date: Thu, 8 Aug 2013 17:19:55 +0200 Subject: [PATCH] replace preg_replace by preg_replace_callback --- system/Utils.php | 55 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/system/Utils.php b/system/Utils.php index 01f5ff4b8..44931438e 100644 --- a/system/Utils.php +++ b/system/Utils.php @@ -1,5 +1,5 @@ /i','', $string); - $string = preg_replace( + /* + * OLD VERSION preg_replace with EVAL ( :o ! ) + * + $string = preg_replace( array( '/(^|\s|>)(www.[^<> \n\r]+)/iex', '/(^|\s|>)([_A-Za-z0-9-]+(\\.[A-Za-z]{2,3})?\\.[A-Za-z]{2,4}\\/[^<> \n\r]+)/iex', @@ -101,8 +103,52 @@ function prepareString($string) { '' ), ' '.$string - ); + );*/ + //replace begin by www + $string = preg_replace_callback( + '/(^|\s|>)(www.[^<> \n\r]+)/ix', function ($match) { + //print '
preg[1]';\system\Debug::dump($match); + if (strlen($match[2])>0) { + return stripslashes($match[1].''.$match[2].''); + } else { + return $match[2]; + } + }, ' ' . $string + ); + + //replace begin by http - https (before www) + $string = preg_replace_callback( + '/(?(?=]*>.+<\/a>)(?:]*>.+<\/a>)|([^="\'])((?:https?):\/\/([^<> \n\r]+)))/ix', function ($match) { + //print '
preg[2]';\system\Debug::dump($match); + if (isset($match[2]) && strlen($match[2])>0) { + return stripslashes($match[1].''.$match[3].''); + } else { + return $match[0]; + } + }, ' ' . $string + ); + + //what the fuck it is ???!!! + $string = preg_replace_callback( + '/(^|\s|>)([_A-Za-z0-9-]+(\\.[A-Za-z]{2,3})?\\.[A-Za-z]{2,4}\\/[^<> \n\r]+)/ix', function ($match) { + //print '
preg[3]';\system\Debug::dump($match); + if (isset($match[2]) && strlen($match[2])>0) { + return stripslashes($match[1].''.$match[2].''); + } else { + return $match[2]; + } + }, ' ' . $string + ); + + //remove all scripts + $string = preg_replace_callback( + '#<[^>]*script[^>]*>#is', function ($match) { + return ''; + }, ' ' . $string + ); + + // We add some smileys... $conf = new Conf(); $theme = $conf->getServerConfElement('theme'); @@ -114,7 +160,6 @@ function prepareString($string) { $string = preg_replace('/(^|[ ])('.$key.')/', $replace, $string); } - //return ''; return trim($string); }