(.*?)^si', '\1', $text); $text = str_replace(" [", "[", $text); $text = str_replace("] ", "]", $text); } return $text; } function callbackPreCode($matches) { return '[code]'.bbcode_off($matches[1], 1).'[/code]'; } function callbackPostCode($matches) { return '[code]'.bbcode_off($matches[1], 2).'[/code]'; } function callbackPreGeshi($matches) { return '[geshi='.$matches[1].']'.bbcode_off($matches[2], '1').'[/geshi]'; } function callbackPostGeshi($matches) { return '[geshi='.$matches[1].']'.bbcode_off($matches[2], 2).'[/geshi]'; } function callbackPrePHP($matches) { return '[php]'.bbcode_off($matches[1], 1).'[/php]'; } function callbackPostPHP($matches) { return '[php]'.bbcode_off($matches[1], 2).'[/php]'; } function callbackURLWithProtocol($matches) { $len = strlen($matches[2]); return $matches[1].'' .trimlink($matches[2], 20) .($len > 30 ? substr($matches[2], $len - 10, $len) : '').''; } function callbackURLWithoutProtocol($matches) { $len = strlen($matches[2]); return $matches[1].'' .trimlink($matches[2], 20) .(strlen($matches[1]) > 30 ? substr($matches[2], $len - 10, $len) : '').''; } function callbackMail($matches) { return hide_email($matches[0]); } function run($text) { $containsCode = strpos($text, '[code]') !== FALSE; $containsGeshi = strpos($text, '[geshi]') !== FALSE; $containsPHP = strpos($text, '[php]') !== FALSE; if ($containsCode) { $text = preg_replace_callback('#\[code\](.*?)\[/code\]#si', __NAMESPACE__.'\callbackPreCode', $text); } if ($containsGeshi) { $text = preg_replace_callback('#\[geshi=(.*?)\](.*?)\[/geshi\]#si', __NAMESPACE__.'\callbackPreGeshi', $text); } if ($containsPHP) { $text = preg_replace_callback('#\[php\](.*?)\[/php\]#si', __NAMESPACE__.'\callbackPrePHP', $text); } $text = str_replace(["]", ">", "[", "<"], ["] ", "> ", "  [", " <"], $text); $text = preg_replace_callback('#(^|[\n ])((http|https|ftp|ftps)://[\w\#$%&~/.\-;:=,?@\[\]\(\)+]*)#si', __NAMESPACE__.'\callbackURLWithProtocol', $text); $text = preg_replace_callback('#(^|\s)((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]\(\)+]*)#si', __NAMESPACE__.'\callbackURLWithoutProtocol', $text); $text = preg_replace_callback('#[a-z0-9_.-]+?@[\w\-]+\.([\w\-\.]+\.)*[\w]+#si', __NAMESPACE__.'\callbackMail', $text); if ($containsCode) { $text = preg_replace_callback('#\[code\](.*?)\[/code\]#si', __NAMESPACE__.'\callbackPostCode', $text); } if ($containsGeshi) { $text = preg_replace_callback('#\[geshi=(.*?)\](.*?)\[/geshi\]#si', __NAMESPACE__.'\callbackPostGeshi', $text); } if ($containsPHP) { $text = preg_replace_callback('#\[php\](.*?)\[/php\]#si', __NAMESPACE__.'\callbackPostPHP', $text); } return str_replace(["] ", "> ", "  [", " <"], ["]", ">", "[", "<"], $text); } } $text = run($text);