Changeset 702 for trunk/forum/includes/message_parser.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/message_parser.php
r400 r702 3 3 * 4 4 * @package phpBB3 5 * @version $Id : message_parser.php 9034 2008-10-24 00:49:30Z toonarmy$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 119 119 'img' => array('bbcode_id' => 4, 'regexp' => array('#\[img\](.*)\[/img\]#iUe' => "\$this->bbcode_img('\$1')")), 120 120 'size' => array('bbcode_id' => 5, 'regexp' => array('#\[size=([\-\+]?\d+)\](.*?)\[/size\]#ise' => "\$this->bbcode_size('\$1', '\$2')")), 121 'color' => array('bbcode_id' => 6, 'regexp' => array('!\[color=(#[0-9a-f]{ 6}|[a-z\-]+)\](.*?)\[/color\]!ise' => "\$this->bbcode_color('\$1', '\$2')")),121 'color' => array('bbcode_id' => 6, 'regexp' => array('!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)\](.*?)\[/color\]!ise' => "\$this->bbcode_color('\$1', '\$2')")), 122 122 'u' => array('bbcode_id' => 7, 'regexp' => array('#\[u\](.*?)\[/u\]#ise' => "\$this->bbcode_underline('\$1')")), 123 123 'list' => array('bbcode_id' => 9, 'regexp' => array('#\[list(?:=(?:[a-z0-9]|disc|circle|square))?].*\[/list]#ise' => "\$this->bbcode_parse_list('\$0')")), … … 696 696 * [quote="[quote]test[/quote]"]test[/quote] (correct: parsed - Username displayed as [quote]test[/quote]) 697 697 * #20735 - [quote]test[/[/b]quote] test [/quote][/quote] test - (correct: quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted) 698 * #40565 - [quote="a"]a[/quote][quote="a]a[/quote] (correct: first quote tag parsed, second quote tag unparsed) 698 699 */ 699 700 … … 706 707 707 708 // To let the parser not catch tokens within quote_username quotes we encode them before we start this... 708 $in = preg_replace('#quote="(.*?)"\]#ie', "'quote="' . str_replace(array('[', ']' ), array('[', ']'), '\$1') . '"]'", $in);709 $in = preg_replace('#quote="(.*?)"\]#ie', "'quote="' . str_replace(array('[', ']', '\\\"'), array('[', ']', '\"'), '\$1') . '"]'", $in); 709 710 710 711 $tok = ']'; … … 859 860 while ($in); 860 861 862 $out .= $buffer; 863 861 864 if (sizeof($close_tags)) 862 865 { … … 1050 1053 // Init BBCode UID 1051 1054 $this->bbcode_uid = substr(base_convert(unique_id(), 16, 36), 0, BBCODE_UID_LEN); 1052 1053 if ($message) 1054 { 1055 $this->message = $message; 1056 } 1055 $this->message = $message; 1057 1056 } 1058 1057 … … 1064 1063 global $config, $db, $user; 1065 1064 1066 $mode = ($mode != 'post') ? 'sig' : 'post';1067 1068 1065 $this->mode = $mode; 1066 1067 foreach (array('chars', 'smilies', 'urls', 'font_size', 'img_height', 'img_width') as $key) 1068 { 1069 if (!isset($config['max_' . $mode . '_' . $key])) 1070 { 1071 $config['max_' . $mode . '_' . $key] = 0; 1072 } 1073 } 1069 1074 1070 1075 $this->allow_img_bbcode = $allow_img_bbcode; … … 1091 1096 $this->message = preg_replace($match, $replace, trim($this->message)); 1092 1097 1093 // Message length check. 0 disables this check completely. 1094 if ($config['max_' . $mode . '_chars'] > 0) 1095 { 1096 $msg_len = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message)); 1097 1098 if ((!$msg_len && $mode !== 'sig') || $config['max_' . $mode . '_chars'] && $msg_len > $config['max_' . $mode . '_chars']) 1099 { 1100 $this->warn_msg[] = (!$msg_len) ? $user->lang['TOO_FEW_CHARS'] : sprintf($user->lang['TOO_MANY_CHARS_' . strtoupper($mode)], $msg_len, $config['max_' . $mode . '_chars']); 1098 // Store message length... 1099 $message_length = ($mode == 'post') ? utf8_strlen($this->message) : utf8_strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#ius', ' ', $this->message)); 1100 1101 // Maximum message length check. 0 disables this check completely. 1102 if ((int) $config['max_' . $mode . '_chars'] > 0 && $message_length > (int) $config['max_' . $mode . '_chars']) 1103 { 1104 $this->warn_msg[] = sprintf($user->lang['TOO_MANY_CHARS_' . strtoupper($mode)], $message_length, (int) $config['max_' . $mode . '_chars']); 1105 return (!$update_this_message) ? $return_message : $this->warn_msg; 1106 } 1107 1108 // Minimum message length check for post only 1109 if ($mode === 'post') 1110 { 1111 if (!$message_length || $message_length < (int) $config['min_post_chars']) 1112 { 1113 $this->warn_msg[] = (!$message_length) ? $user->lang['TOO_FEW_CHARS'] : sprintf($user->lang['TOO_FEW_CHARS_LIMIT'], $message_length, (int) $config['min_post_chars']); 1101 1114 return (!$update_this_message) ? $return_message : $this->warn_msg; 1102 1115 } 1103 }1104 1105 // Check for "empty" message1106 if ($mode !== 'sig' && utf8_clean_string($this->message) === '')1107 {1108 $this->warn_msg[] = $user->lang['TOO_FEW_CHARS'];1109 return (!$update_this_message) ? $return_message : $this->warn_msg;1110 1116 } 1111 1117 … … 1150 1156 $num_urls += preg_match_all('#\<!-- ([lmwe]) --\>.*?\<!-- \1 --\>#', $this->message, $matches); 1151 1157 } 1158 } 1159 1160 // Check for "empty" message. We do not check here for maximum length, because bbcode, smilies, etc. can add to the length. 1161 // The maximum length check happened before any parsings. 1162 if ($mode === 'post' && utf8_clean_string($this->message) === '') 1163 { 1164 $this->warn_msg[] = $user->lang['TOO_FEW_CHARS']; 1165 return (!$update_this_message) ? $return_message : $this->warn_msg; 1152 1166 } 1153 1167 … … 1299 1313 1300 1314 // (assertion) 1301 $match[] = '(?<=^|[\n .])' . preg_quote($row['code'], '#') . '(?![^<>]*>)';1315 $match[] = preg_quote($row['code'], '#'); 1302 1316 $replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILIES_PATH}/' . $row['smiley_url'] . '" alt="' . $row['code'] . '" title="' . $row['emotion'] . '" /><!-- s' . $row['code'] . ' -->'; 1303 1317 } … … 1309 1323 if ($max_smilies) 1310 1324 { 1311 $num_matches = preg_match_all('# ' . implode('|', $match) . '#', $this->message, $matches);1325 $num_matches = preg_match_all('#(?<=^|[\n .])(?:' . implode('|', $match) . ')(?![^<>]*>)#', $this->message, $matches); 1312 1326 unset($matches); 1313 1327 … … 1320 1334 1321 1335 // Make sure the delimiter # is added in front and at the end of every element within $match 1322 $this->message = trim(preg_replace(explode(chr(0), '# ' . implode('#' . chr(0) . '#', $match) . '#'), $replace, $this->message));1336 $this->message = trim(preg_replace(explode(chr(0), '#(?<=^|[\n .])' . implode('(?![^<>]*>)#' . chr(0) . '#(?<=^|[\n .])', $match) . '(?![^<>]*>)#'), $replace, $this->message)); 1323 1337 } 1324 1338 } … … 1613 1627 $bbcode_bitfield = $this->bbcode_bitfield; 1614 1628 1615 $poll['poll_option_text'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false );1629 $poll['poll_option_text'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false, 'poll'); 1616 1630 1617 1631 $bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield)); … … 1636 1650 $this->warn_msg[] = $user->lang['POLL_TITLE_TOO_LONG']; 1637 1651 } 1638 $poll['poll_title'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false );1652 $poll['poll_title'] = $this->parse($poll['enable_bbcode'], ($config['allow_post_links']) ? $poll['enable_urls'] : false, $poll['enable_smilies'], $poll['img_status'], false, false, $config['allow_post_links'], false, 'poll'); 1639 1653 if (strlen($poll['poll_title']) > 255) 1640 1654 {
Note:
See TracChangeset
for help on using the changeset viewer.