From 2fa463cdeb5d8e4f2373aa834154ca27ea21c97a Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 16 Sep 2004 18:33:22 +0000 Subject: - more updates, mostly bugfixes to the bbcode parser - changed current_user in sessions (please review) - give more flexibility to style authors in regard to the pagination elements - profile fields updates (included a sample constuct into viewtopic_body.html - have to be documented extensivly) - code optimizations (use of strpos, sizeof, loops not iterating functions on every call, memory savings...) - and last but not least --- hopefully not introduced more bugs than healthy (*cough*) git-svn-id: file:///svn/phpbb/trunk@4984 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/message_parser.php | 95 ++++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 31 deletions(-) (limited to 'phpBB/includes/message_parser.php') diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 88b83e4cd3..6e67e10ac6 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -155,6 +155,19 @@ class bbcode_firstpass extends bbcode // when using the /e modifier, preg_replace slashes double-quotes but does not // seem to slash anything else $in = str_replace("\r\n", "\n", str_replace('\"', '"', $in)); + + // We remove the hardcoded elements from the code block here because it is not used in code blocks + // Having it here saves us one preg_replace per message containing a [code] blocks + $htm_match = array( + '#.*?#', + '#.*?#', + '#.*?#', + '#.*?#', + '#<?php '; + $str_from[] = '<?php '; $str_to[] = ''; - $str_from[] = '<?php '; + $str_from[] = '<?php '; $str_to[] = ''; } @@ -240,10 +254,11 @@ class bbcode_firstpass extends bbcode $out .= '[code:' . $this->bbcode_uid . ']' . str_replace($str_from, $str_to, $code) . '[/code:' . $this->bbcode_uid . ']'; } - if (preg_match('#(.*?)\[code(?:=[a-z]+)?\](.+)#is', $in, $m)) + if (preg_match('#(.*?)\[code(?:=([a-z]+))?\](.+)#is', $in, $m)) { $out .= $m[1]; - $in = $m[2]; + $stx = $m[2]; + $in = $m[3]; } } while ($in); @@ -282,10 +297,10 @@ class bbcode_firstpass extends bbcode { // if $tok is ']' the buffer holds a tag - if ($buffer == '/list' && count($list_end_tags)) + if ($buffer == '/list' && sizeof($list_end_tags)) { // valid [/list] tag - if (count($item_end_tags)) + if (sizeof($item_end_tags)) { // current li tag has not been closed $out = preg_replace('/(\n)?\[$/', '[', $out) . array_pop($item_end_tags) . ']['; @@ -310,10 +325,10 @@ class bbcode_firstpass extends bbcode } else { - if ($buffer == '*' && count($list_end_tags)) + if ($buffer == '*' && sizeof($list_end_tags)) { // the buffer holds a bullet tag and we have a [list] tag open - if (count($item_end_tags) >= count($list_end_tags)) + if (sizeof($item_end_tags) >= sizeof($list_end_tags)) { // current li tag has not been closed if (preg_match('/\n\[$/', $out, $m)) @@ -354,11 +369,11 @@ class bbcode_firstpass extends bbcode while ($in); // do we have some tags open? close them now - if (count($item_end_tags)) + if (sizeof($item_end_tags)) { $out .= '[' . implode('][', $item_end_tags) . ']'; } - if (count($list_end_tags)) + if (sizeof($list_end_tags)) { $out .= '[' . implode('][', $list_end_tags) . ']'; } @@ -374,6 +389,9 @@ class bbcode_firstpass extends bbcode $tok = ']'; $out = '['; + // Add newline at the end of each quote block to prevent parsing errors (urls, smilies, etc.) + $in = preg_replace('#([^\n])\[\/quote\]#is', "\\1\n[/quote]", $in); + $in = substr(str_replace('\"', '"', $in), 1); $close_tags = $error_ary = array(); $buffer = ''; @@ -396,7 +414,7 @@ class bbcode_firstpass extends bbcode if ($tok == ']') { - if ($buffer == '/quote' && count($close_tags)) + if ($buffer == '/quote' && sizeof($close_tags)) { // we have found a closing tag @@ -407,7 +425,7 @@ class bbcode_firstpass extends bbcode elseif (preg_match('#^quote(?:="(.*?)")?$#is', $buffer, $m)) { // the buffer holds a valid opening tag - if ($config['max_quote_depth'] && count($close_tags) >= $config['max_quote_depth']) + if ($config['max_quote_depth'] && sizeof($close_tags) >= $config['max_quote_depth']) { // there are too many nested quotes $error_ary['quote_depth'] = sprintf($user->lang['QUOTE_DEPTH_EXCEEDED'], $config['max_quote_depth']); @@ -483,7 +501,7 @@ class bbcode_firstpass extends bbcode } while ($in); - if (count($close_tags)) + if (sizeof($close_tags)) { $out .= '[' . implode('][', $close_tags) . ']'; } @@ -626,6 +644,18 @@ class parse_message extends bbcode_firstpass $this->html($config['allow_html_tags']); } + // Parse Emoticons + if ($allow_smilies) + { + $this->emoticons($config['max_post_smilies']); + } + + // Parse URL's + if ($allow_magic_url) + { + $this->magic_url((($config['cookie_secure']) ? 'https://' : 'http://'), $config['server_name'], $config['server_port'], $config['script_path']); + } + // Parse BBCode if ($allow_bbcode && strpos($this->message, '[') !== false) { @@ -641,18 +671,6 @@ class parse_message extends bbcode_firstpass $this->parse_bbcode(); } - // Parse Emoticons - if ($allow_smilies) - { - $this->emoticons($config['max_post_smilies']); - } - - // Parse URL's - if ($allow_magic_url) - { - $this->magic_url((($config['cookie_secure']) ? 'https://' : 'http://'), $config['server_name'], $config['server_port'], $config['script_path']); - } - if (!$update_this_message) { unset($this->message); @@ -737,7 +755,7 @@ class parse_message extends bbcode_firstpass if (sizeof($allowed_tags)) { - $this->message = preg_replace('#<(\/?)(' . str_replace('*', '.*?', implode('|', $allowed_tags)) . ')>#is', '<$1$2>', $this->message); + $this->message = preg_replace('#<(\/?)(' . str_replace('*', '.*?', implode('|', $allowed_tags)) . ')>#is', '<$1$2>', $this->message); } } @@ -786,9 +804,24 @@ class parse_message extends bbcode_firstpass global $db, $user, $phpbb_root_path; // NOTE: obtain_* function? chaching the table contents? + // For now setting the ttl to 10 minutes - $sql = 'SELECT * - FROM ' . SMILIES_TABLE; + switch (SQL_LAYER) + { + case 'mssql': + case 'mssql-odbc': + $sql = 'SELECT * + FROM ' . SMILIES_TABLE . ' + ORDER BY LEN(code) DESC'; + break; + + // LENGTH supported by MySQL, IBM DB2, Oracle and Access for sure... + default: + $sql = 'SELECT * + FROM ' . SMILIES_TABLE . ' + ORDER BY LENGTH(code) DESC'; + break; + } $result = $db->sql_query($sql, 600); if ($row = $db->sql_fetchrow($result)) @@ -884,7 +917,7 @@ class parse_message extends bbcode_firstpass } } - if ($preview || $refresh || count($error)) + if ($preview || $refresh || sizeof($error)) { // Perform actions on temporary attachments if ($delete_file) @@ -932,7 +965,7 @@ class parse_message extends bbcode_firstpass $error = array_merge($error, $filedata['error']); - if (!count($error)) + if (!sizeof($error)) { $new_entry = array( 'physical_filename' => $filedata['destination_filename'], -- cgit v1.2.1