Re-enabling Quotes in phpBB Color Code

2019-09-15 02:42发布

问题:

In one of their updates, phpBB removed the option for the [color=value]...[/color] BBCode to include quotes around the color value. My implementation of phpBB depends heavily on this functionality working, since industry software has been designed to output with quotes around the value.

How can I re-enable this format?

I have tried modifying the regular expressions in includes/message_parser.php to include the possibility of quotes (as shown below). This works for most symbols, but it seems that there is something specific somewhere else in the code which disables quotes from working.

Here are the changes I tried in includes/message_parser.php. I changed:

function bbcode_init()
    {
        static $rowset;

        // This array holds all bbcode data. BBCodes will be processed in this
        // order, so it is important to keep [code] in first position and
        // [quote] in second position.
        $this->bbcodes = array(
            'code'          => array('bbcode_id' => 8,  'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#ise' => "\$this->bbcode_code('\$1', '\$2')")),
            'quote'         => array('bbcode_id' => 0,  'regexp' => array('#\[quote(?:="(.*?)")?\](.+)\[/quote\]#ise' => "\$this->bbcode_quote('\$0')")),
            'attachment'    => array('bbcode_id' => 12, 'regexp' => array('#\[attachment=([0-9]+)\](.*?)\[/attachment\]#ise' => "\$this->bbcode_attachment('\$1', '\$2')")),
            'b'             => array('bbcode_id' => 1,  'regexp' => array('#\[b\](.*?)\[/b\]#ise' => "\$this->bbcode_strong('\$1')")),
            'i'             => array('bbcode_id' => 2,  'regexp' => array('#\[i\](.*?)\[/i\]#ise' => "\$this->bbcode_italic('\$1')")),
            'url'           => array('bbcode_id' => 3,  'regexp' => array('#\[url(=(.*))?\](.*)\[/url\]#iUe' => "\$this->validate_url('\$2', '\$3')")),
            'img'           => array('bbcode_id' => 4,  'regexp' => array('#\[img\](.*)\[/img\]#iUe' => "\$this->bbcode_img('\$1')")),
            'size'          => array('bbcode_id' => 5,  'regexp' => array('#\[size=([\-\+]?\d+)\](.*?)\[/size\]#ise' => "\$this->bbcode_size('\$1', '\$2')")),
            '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')")),
            'u'             => array('bbcode_id' => 7,  'regexp' => array('#\[u\](.*?)\[/u\]#ise' => "\$this->bbcode_underline('\$1')")),
            'list'          => array('bbcode_id' => 9,  'regexp' => array('#\[list(?:=(?:[a-z0-9]|disc|circle|square))?].*\[/list]#ise' => "\$this->bbcode_parse_list('\$0')")),
            'email'         => array('bbcode_id' => 10, 'regexp' => array('#\[email=?(.*?)?\](.*?)\[/email\]#ise' => "\$this->validate_email('\$1', '\$2')")),
            'flash'         => array('bbcode_id' => 11, 'regexp' => array('#\[flash=([0-9]+),([0-9]+)\](.*?)\[/flash\]#ie' => "\$this->bbcode_flash('\$1', '\$2', '\$3')"))
        );
...

To use the following for the 'color' match:

'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')"))

What else can I try to re-add this functionality to phpBB?

回答1:

I believe that phpBB escapes special HTML characters before processing, which means your regexp should be something like this:

'!\[color=(?:")?(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)(?:")?\](.*?)\[/color\]!ise'