diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2006-02-21 10:32:19 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2006-02-21 10:32:19 +0000 |
commit | cddf792dea0195783c20094023272c5713faf2b3 (patch) | |
tree | 2d3dbb503514b53e8c9c8b842c79681c5e7136a3 /phpBB/includes/message_parser.php | |
parent | 22b9a9d886431af57985d11a23f9f2ee60a6bc5a (diff) | |
download | forums-cddf792dea0195783c20094023272c5713faf2b3.tar forums-cddf792dea0195783c20094023272c5713faf2b3.tar.gz forums-cddf792dea0195783c20094023272c5713faf2b3.tar.bz2 forums-cddf792dea0195783c20094023272c5713faf2b3.tar.xz forums-cddf792dea0195783c20094023272c5713faf2b3.zip |
- implementing David's proposed expression changes (some of them already noted within the events CCP)
git-svn-id: file:///svn/phpbb/trunk@5566 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/message_parser.php')
-rw-r--r-- | phpBB/includes/message_parser.php | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index e8d2a93444..feeeafc4c0 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -886,41 +886,32 @@ class parse_message extends bbcode_firstpass { static $match; static $replace; - + $server_port = ($server_port <> 80 ) ? ':' . trim($server_port) . '/' : '/'; if (!is_array($match)) { $match = $replace = array(); // Be sure to not let the matches cross over. ;) - + // relative urls for this board - $match[] = '#(^|[\n ]|\()(' . preg_quote($server_protocol . trim($server_name) . $server_port . preg_replace('/^\/?(.*?)(\/)?$/', '$1', trim($script_path)), '#') . ')/(.*?([^ \t\n\r<"\'\)]*)?)#i'; + $match[] = '#(^|[\n ]|\()(' . preg_quote($server_protocol . trim($server_name) . $server_port . preg_replace('/^\/?(.*?)(\/)?$/', '$1', trim($script_path)), '#') . ')/([^ \t\n\r<"\'\)&]+|&(?!lt;))*)#i'; $replace[] = '$1<!-- l --><a href="$2/$3">$3</a><!-- l -->'; - + // matches a xxxx://aaaaa.bbb.cccc. ... - $match[] = '#(^|[\n ]|\()([\w]+?://.*?([^ \t\n\r<"\'\)]*)?)#ie'; + $match[] = '#(^|[\n ]|\()([\w]+:/{2}.*?([^ \t\n\r<"\'\)&]+|&(?!lt;))*)#ie'; $replace[] = "'\$1<!-- m --><a href=\"\$2\" target=\"_blank\">' . ((strlen('\$2') > 55) ? substr(str_replace('&', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&', '&', '\$2'), -10) : '\$2') . '</a><!-- m -->'"; - + // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing - $match[] = '#(^|[\n ]|\()(www\.[\w\-]+\.[\w\-.\~]+(?:/[^ \t\n\r<"\'\)]*)?)#ie'; + $match[] = '#(^|[\n ]|\()(w{3}\.[\w\-]+\.[\w\-.\~]+(?:[^ \t\n\r<"\'\)&]+|&(?!lt;))*)#ie'; $replace[] = "'\$1<!-- w --><a href=\"http://\$2\" target=\"_blank\">' . ((strlen('\$2') > 55) ? substr(str_replace('&', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&', '&', '\$2'), -10) : '\$2') . '</a><!-- w -->'"; - + // matches an email@domain type address at the start of a line, or after a space. - $match[] = '#(^|[\n ]|\()([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)#ie'; + $match[] = '#(^|[\n ]|\()([a-z0-9&\-_.]+?@[\w\-]+\.(?:[\w\-\.]+\.)?[\w]+)#ie'; $replace[] = "'\$1<!-- e --><a href=\"mailto:\$2\">' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- e -->'"; } - - /* IMPORTANT NOTE (Developer inability to do advanced regular expressions) - Acyd Burn: - Transforming < (<) to <&lt; in order to bypass the inability of preg_replace - supporting multi-character sequences (POSIX - [..]). Since all message text is specialchared by - default a match against < will always fail, since it is a < sequence within the text. - Replacing with <&lt; and switching back thereafter produces no problems, because < will never show up with &lt; in - the same text (due to this specialcharing). The < is put in front of &lt; to let the url break gracefully. - I hope someone can lend me a hand here, telling me how to achive the wanted result without switching to ereg_replace. - */ - $this->message = preg_replace($match, $replace, str_replace('<', '<&lt;', $this->message)); - $this->message = str_replace('<&lt;', '<', $this->message); + + $this->message = preg_replace($match, $replace, $this->message); } // Parse Smilies @@ -954,7 +945,7 @@ class parse_message extends bbcode_firstpass break; } $result = $db->sql_query($sql, 600); - + if ($row = $db->sql_fetchrow($result)) { $match = $replace = array(); @@ -973,7 +964,7 @@ class parse_message extends bbcode_firstpass } $db->sql_freeresult($result); } - + if (sizeof($match)) { if ($max_smilies) |