From: <be...@us...> - 2013-08-17 00:10:27
|
Revision: 11934 http://sourceforge.net/p/xoops/svn/11934 Author: beckmi Date: 2013-08-17 00:10:20 +0000 (Sat, 17 Aug 2013) Log Message: ----------- Fixing preg_replace /e in textsanitizer for PHP 5.5.x Modified Paths: -------------- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/module.textsanitizer.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/flash/flash.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/mp3/mp3.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/wiki/wiki.php XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/youtube/youtube.php Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/module.textsanitizer.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/module.textsanitizer.php 2013-08-16 23:03:01 UTC (rev 11933) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/module.textsanitizer.php 2013-08-17 00:10:20 UTC (rev 11934) @@ -136,7 +136,7 @@ * @param string $height * @return string */ - public function decode($url, $width, $height) + public static function decode($url, $width, $height) { return ''; } @@ -181,6 +181,11 @@ */ public $replacements = array(); +//mb------------------------------ + public $callbackPatterns = array(); + public $callbacks = array(); +//mb------------------------------ + /** * @var string */ @@ -280,6 +285,29 @@ return $message; } + + + function makeClickableCallback01($match) + { + return $match[1]."<a href=\"$match[2]://$match[3]\" title=\"$match[2]://$match[3]\" rel=\"external\">$match[2]://".$this->truncate( $match[3] ).'</a>'; + } + + function makeClickableCallback02($match) + { + return $match[1] ."<a href=\"http://www.$match[2]$match[6]\" title=\"www.$match[2]$match[6]\" rel=\"external\">" .$this->truncate('www.'.$match[2].$match[6]) .'</a>'; + } + + function makeClickableCallback03($match) + { + return $match[1]."<a href=\"ftp://ftp.$match[2].$match[3]\" title=\"ftp.$match[2].$match[3]\" rel=\"external\">" . $this->truncate('ftp.'.$match[2].$match[3]) .'</a>'; + } + + function makeClickableCallback04($match) + { + return $match[1]. "<a href=\"mailto:$match[2]@$match[3]\" title=\"$match[2]@$match[3]\">" .$this->truncate($match[2]."@".$match[3]) .'</a>'; + } + + /** * Make links in the text clickable * @@ -290,22 +318,40 @@ $valid_chars = "a-z0-9\/\-_+=.~!%@?#&;:$\|"; $end_chars = "a-z0-9\/\-_+=~!%@?#&;:$\|"; - $patterns = array(); - $replacements = array(); +// $patterns = array(); +// $replacements = array(); +// +// $patterns[] = "/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([{$valid_chars}]+[{$end_chars}])/ei"; +// $replacements[] = "'\\1<a href=\"\\2://\\3\" title=\"\\2://\\3\" rel=\"external\">\\2://'.MyTextSanitizer::truncate( '\\3' ).'</a>'"; +// +// +// $patterns[] = "/(^|[^]_a-z0-9-=\"'\/:\.])www\.((([a-zA-Z0-9\-]*\.){1,}){1}([a-zA-Z]{2,6}){1})((\/([a-zA-Z0-9\-\._\?\,\'\/\\+&%\$#\=~])*)*)/ei"; +// $replacements[] = "'\\1<a href=\"http://www.\\2\\6\" title=\"www.\\2\\6\" rel=\"external\">'.MyTextSanitizer::truncate( 'www.\\2\\6' ).'</a>'"; +// +// $patterns[] = "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([{$valid_chars}]+[{$end_chars}])/ei"; +// $replacements[] = "'\\1<a href=\"ftp://ftp.\\2.\\3\" title=\"ftp.\\2.\\3\" rel=\"external\">'.MyTextSanitizer::truncate( 'ftp.\\2.\\3' ).'</a>'"; +// +// $patterns[] = "/(^|[^]_a-z0-9-=\"'\/:\.])([-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+)@((?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?)/ei"; +// $replacements[] = "'\\1<a href=\"mailto:\\2@\\3\" title=\"\\2@\\3\">'.MyTextSanitizer::truncate( '\\2@\\3' ).'</a>'"; +// +// $text = preg_replace($patterns, $replacements, $text); +// +//---------------------------------------------------------------------------------- - $patterns[] = "/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([{$valid_chars}]+[{$end_chars}])/ei"; - $replacements[] = "'\\1<a href=\"\\2://\\3\" title=\"\\2://\\3\" rel=\"external\">\\2://'.MyTextSanitizer::truncate( '\\3' ).'</a>'"; - $patterns[] = "/(^|[^]_a-z0-9-=\"'\/:\.])www\.((([a-zA-Z0-9\-]*\.){1,}){1}([a-zA-Z]{2,6}){1})((\/([a-zA-Z0-9\-\._\?\,\'\/\\+&%\$#\=~])*)*)/ei"; - $replacements[] = "'\\1<a href=\"http://www.\\2\\6\" title=\"www.\\2\\6\" rel=\"external\">'.MyTextSanitizer::truncate( 'www.\\2\\6' ).'</a>'"; + $pattern = "/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([{$valid_chars}]+[{$end_chars}])/i"; + $text = preg_replace_callback($pattern, 'self::makeClickableCallback01', $text); - $patterns[] = "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([{$valid_chars}]+[{$end_chars}])/ei"; - $replacements[] = "'\\1<a href=\"ftp://ftp.\\2.\\3\" title=\"ftp.\\2.\\3\" rel=\"external\">'.MyTextSanitizer::truncate( 'ftp.\\2.\\3' ).'</a>'"; + $pattern = "/(^|[^]_a-z0-9-=\"'\/:\.])www\.((([a-zA-Z0-9\-]*\.){1,}){1}([a-zA-Z]{2,6}){1})((\/([a-zA-Z0-9\-\._\?\,\'\/\\+&%\$#\=~])*)*)/i"; + $text = preg_replace_callback($pattern, 'self::makeClickableCallback02', $text); - $patterns[] = "/(^|[^]_a-z0-9-=\"'\/:\.])([-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+)@((?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?)/ei"; - $replacements[] = "'\\1<a href=\"mailto:\\2@\\3\" title=\"\\2@\\3\">'.MyTextSanitizer::truncate( '\\2@\\3' ).'</a>'"; - $text = preg_replace($patterns, $replacements, $text); + $pattern = "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([{$valid_chars}]+[{$end_chars}])/i"; + $text = preg_replace_callback($pattern, 'self::makeClickableCallback03', $text); + + $pattern = "/(^|[^]_a-z0-9-=\"'\/:\.])([-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+)@((?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?)/i"; + $text = preg_replace_callback($pattern, 'self::makeClickableCallback04', $text); + return $text; } @@ -378,6 +424,13 @@ $this->executeExtensions(); $text = preg_replace($this->patterns, $this->replacements, $this->text); +//------------------------------------------------------------------------------- + $count = sizeof($this->callbackPatterns); + + for ($i = 0; $i < $count; $i++) { + $text = preg_replace_callback($this->callbackPatterns[$i], $this->callbacks[$i] , $text); + } +//------------------------------------------------------------------------------ $text = $this->quoteConv($text); return $text; } @@ -582,13 +635,21 @@ public function codePreConv($text, $xcode = 1) { if ($xcode != 0) { - $patterns = "/\[code([^\]]*?)\](.*)\[\/code\]/esU"; - $replacements = "'[code\\1]'.base64_encode('\\2').'[/code]'"; - $text = preg_replace($patterns, $replacements, $text); +// $patterns = "/\[code([^\]]*?)\](.*)\[\/code\]/esU"; +// $replacements = "'[code\\1]'.base64_encode('\\2').'[/code]'"; + $patterns = "/\[code([^\]]*?)\](.*)\[\/code\]/sU"; + $text = preg_replace_callback($patterns, create_function('$matches',"return '[code'.\$matches[1].']' . base64_encode(\$matches[2]). '[/code]';"),$text); } return $text; } + +function codeConvCallback($match) + { + return '<div class=\"xoopsCode\">'. $this->executeExtension('syntaxhighlight', str_replace('\\\"', '\"', base64_decode($match[2])), $match[1]).'</div>'; + } + + /** * MyTextSanitizer::codeConv() * @@ -601,9 +662,10 @@ if (empty($xcode)) { return $text; } - $patterns = "/\[code([^\]]*?)\](.*)\[\/code\]/esU"; - $replacements = "'<div class=\"xoopsCode\">'.\$this->executeExtension('syntaxhighlight', str_replace('\\\"', '\"', base64_decode('$2')), '$1').'</div>'"; - $text = preg_replace($patterns, $replacements, $text); + $patterns = "/\[code([^\]]*?)\](.*)\[\/code\]/sU"; +// $replacements = "'<div class=\"xoopsCode\">'.\$this->executeExtension('syntaxhighlight', str_replace('\\\"', '\"', base64_decode('$2')), '$1').'</div>'"; + $text = preg_replace_callback($patterns, array($this,'codeConvCallback'), $text); + return $text; } Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/flash/flash.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/flash/flash.php 2013-08-16 23:03:01 UTC (rev 11933) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/flash/flash.php 2013-08-17 00:10:20 UTC (rev 11934) @@ -57,6 +57,9 @@ $code, $javascript ); } + static function myCallback($match) { + return self::decode( $match[5], $match[3], $match[4] ); + } /** * @param MyTextSanitizer $ts @@ -64,9 +67,14 @@ */ public function load(MyTextSanitizer &$ts) { - $ts->patterns[] = "/\[(swf|flash)=(['\"]?)([^\"']*),([^\"']*)\\2]([^\"]*)\[\/\\1\]/esU"; - $ts->replacements[] = __CLASS__ . "::decode( '\\5', '\\3', '\\4' )"; +// $ts->patterns[] = "/\[(swf|flash)=(['\"]?)([^\"']*),([^\"']*)\\2]([^\"]*)\[\/\\1\]/esU"; +// $ts->replacements[] = __CLASS__ . "::decode( '\\5', '\\3', '\\4' )"; +//mb------------------------------ + $ts->callbackPatterns[] = "/\[(swf|flash)=(['\"]?)([^\"']*),([^\"']*)\\2]([^\"]*)\[\/\\1\]/sU"; + $ts->callbacks[] = __CLASS__ . "::myCallback"; +//mb------------------------------ + return true; } @@ -76,7 +84,7 @@ * @param int $height * @return string */ - public function decode($url, $width, $height) + public static function decode($url, $width, $height) { $config = parent::loadConfig(dirname(__FILE__)); if ((empty($width) || empty($height)) && !empty($config['detect_dimension'])) { Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/mp3/mp3.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/mp3/mp3.php 2013-08-16 23:03:01 UTC (rev 11933) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/mp3/mp3.php 2013-08-17 00:10:20 UTC (rev 11934) @@ -55,10 +55,18 @@ ); } + static function myCallback($match) { + return self::decode($match[1]); + } + public function load(MyTextSanitizer &$ts) { - $ts->patterns[] = "/\[mp3\](.*?)\[\/mp3\]/es"; - $ts->replacements[] = __CLASS__ . "::decode( '\\1' )"; +// $ts->patterns[] = "/\[mp3\](.*?)\[\/mp3\]/es"; +// $ts->replacements[] = __CLASS__ . "::decode( '\\1' )"; +//mb------------------------------ + $ts->callbackPatterns[] = "/\[mp3\](.*?)\[\/mp3\]/s"; + $ts->callbacks[] = __CLASS__ . "::myCallback"; +//mb------------------------------ return true; } @@ -67,7 +75,7 @@ * @param string $url * @return string */ - public function decode($url) + public static function decode ($url) { $rp = "<embed flashvars=\"playerID=1&bg=0xf8f8f8&leftbg=0x3786b3&lefticon=0x78bee3&rightbg=0x3786b3&rightbghover=0x78bee3&righticon=0x78bee3&righticonhover=0x3786b3&text=0x666666&slider=0x3786b3&track=0xcccccc&border=0x666666&loader=0x78bee3&loop=no&soundFile={$url}\" quality='high' menu='false' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' src='" . XOOPS_URL . "/images/form/player.swf' width=290 height=24 type='application/x-shockwave-flash'></embed>"; return $rp; Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/wiki/wiki.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/wiki/wiki.php 2013-08-16 23:03:01 UTC (rev 11933) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/wiki/wiki.php 2013-08-17 00:10:20 UTC (rev 11934) @@ -56,21 +56,28 @@ ); } + static function myCallback($match) { + return self::decode( $match[1] ); + } /** * @param MyTextSanitizer $ts * @return void */ public function load(MyTextSanitizer &$ts) { - $ts->patterns[] = "/\[\[([^\]]*)\]\]/esU"; - $ts->replacements[] = __CLASS__ . "::decode( '\\1' )"; +// $ts->patterns[] = "/\[\[([^\]]*)\]\]/esU"; +// $ts->replacements[] = __CLASS__ . "::decode( '\\1' )"; +//mb------------------------------ + $ts->callbackPatterns[] = "/\[\[([^\]]*)\]\]/sU"; + $ts->callbacks[] = __CLASS__ . "::myCallback"; +//mb------------------------------ } /** * @param string $text * @return string */ - public function decode($text) + public static function decode($text) { $config = parent::loadConfig(dirname(__FILE__)); if (empty($text) || empty($config['link'])) { Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/youtube/youtube.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/youtube/youtube.php 2013-08-16 23:03:01 UTC (rev 11933) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/textsanitizer/youtube/youtube.php 2013-08-17 00:10:20 UTC (rev 11934) @@ -55,14 +55,24 @@ return array($code, $javascript); } +static function myCallback($match) { + return self::decode( $match[4], $match[2], $match[3] ); +} + /** * @param MyTextSanitizer $ts * @return void */ public function load(MyTextSanitizer &$ts) { - $ts->patterns[] = "/\[youtube=(['\"]?)([^\"']*),([^\"']*)\\1]([^\"]*)\[\/youtube\]/esU"; - $ts->replacements[] = __CLASS__ . "::decode( '\\4', '\\2', '\\3' )"; +// $ts->patterns[] = "/\[youtube=(['\"]?)([^\"']*),([^\"']*)\\1]([^\"]*)\[\/youtube\]/esU"; +// $ts->replacements[] = __CLASS__ . "::decode( '\\4', '\\2', '\\3' )"; + +//mb------------------------------ + $ts->callbackPatterns[] = "/\[youtube=(['\"]?)([^\"']*),([^\"']*)\\1]([^\"]*)\[\/youtube\]/sU"; + $ts->callbacks[] = __CLASS__ . "::myCallback"; +//mb------------------------------ + } /** @@ -71,7 +81,7 @@ * @param string $height * @return string */ - public function decode($url, $width, $height) + public static function decode($url, $width, $height) { if (!preg_match("/^http:\/\/(www\.)?youtube\.com\/watch\?v=(.*)/i", $url, $matches)) { trigger_error("Not matched: {$url} {$width} {$height}", E_USER_WARNING); |