Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/message_parser.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: message_parser.php 9034 2008-10-24 00:49:30Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    119119                        'img'                   => array('bbcode_id' => 4,      'regexp' => array('#\[img\](.*)\[/img\]#iUe' => "\$this->bbcode_img('\$1')")),
    120120                        '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')")),
    122122                        'u'                             => array('bbcode_id' => 7,      'regexp' => array('#\[u\](.*?)\[/u\]#ise' => "\$this->bbcode_underline('\$1')")),
    123123                        'list'                  => array('bbcode_id' => 9,      'regexp' => array('#\[list(?:=(?:[a-z0-9]|disc|circle|square))?].*\[/list]#ise' => "\$this->bbcode_parse_list('\$0')")),
     
    696696                * [quote="[quote]test[/quote]"]test[/quote] (correct: parsed - Username displayed as [quote]test[/quote])
    697697                * #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)
    698699                */
    699700
     
    706707
    707708                // 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);
    709710
    710711                $tok = ']';
     
    859860                while ($in);
    860861
     862                $out .= $buffer;
     863
    861864                if (sizeof($close_tags))
    862865                {
     
    10501053                // Init BBCode UID
    10511054                $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;
    10571056        }
    10581057
     
    10641063                global $config, $db, $user;
    10651064
    1066                 $mode = ($mode != 'post') ? 'sig' : 'post';
    1067 
    10681065                $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                }
    10691074
    10701075                $this->allow_img_bbcode = $allow_img_bbcode;
     
    10911096                $this->message = preg_replace($match, $replace, trim($this->message));
    10921097
    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']);
    11011114                                return (!$update_this_message) ? $return_message : $this->warn_msg;
    11021115                        }
    1103                 }
    1104 
    1105                 // Check for "empty" message
    1106                 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;
    11101116                }
    11111117
     
    11501156                                $num_urls += preg_match_all('#\<!-- ([lmwe]) --\>.*?\<!-- \1 --\>#', $this->message, $matches);
    11511157                        }
     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;
    11521166                }
    11531167
     
    12991313
    13001314                                // (assertion)
    1301                                 $match[] = '(?<=^|[\n .])' . preg_quote($row['code'], '#') . '(?![^<>]*>)';
     1315                                $match[] = preg_quote($row['code'], '#');
    13021316                                $replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILIES_PATH}/' . $row['smiley_url'] . '" alt="' . $row['code'] . '" title="' . $row['emotion'] . '" /><!-- s' . $row['code'] . ' -->';
    13031317                        }
     
    13091323                        if ($max_smilies)
    13101324                        {
    1311                                 $num_matches = preg_match_all('#' . implode('|', $match) . '#', $this->message, $matches);
     1325                                $num_matches = preg_match_all('#(?<=^|[\n .])(?:' . implode('|', $match) . ')(?![^<>]*>)#', $this->message, $matches);
    13121326                                unset($matches);
    13131327
     
    13201334
    13211335                        // 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));
    13231337                }
    13241338        }
     
    16131627                $bbcode_bitfield = $this->bbcode_bitfield;
    16141628
    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');
    16161630
    16171631                $bbcode_bitfield = base64_encode(base64_decode($bbcode_bitfield) | base64_decode($this->bbcode_bitfield));
     
    16361650                                $this->warn_msg[] = $user->lang['POLL_TITLE_TOO_LONG'];
    16371651                        }
    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');
    16391653                        if (strlen($poll['poll_title']) > 255)
    16401654                        {
Note: See TracChangeset for help on using the changeset viewer.