Total Users Online: 0 üye, 142 guest | Tarih/Saat: 2025-04-29 07:28
AUTO-CLOSING BBCODES
Prevent your layout from being spoiled by auto-closing all bbcodes
By default, Seditio does not close BB codes which have been left unclosed by page author. For some tags it turns BB into HTML only if there is a complete open/close match, but for some BB codes it converts open/close tags separately. Say, if someone leaves "b" bbcode unclosed, all the text below will stay bold. Or if you provide bbcodes for tables in the same manner as described here, a simple forum post can spoil all the layout if someone uses unclosed BBcodes.

There are several ways to protect your layout.

The first is searching for unclosed tags on any page/post/pm add/update and warning if there are unclosed bbcodes. It is probably the most right one, because it's reliable enough and not so resource-consuming since checks are made on add/edit only. But it has an important drawback: lots of scripts and plugins to modify.

The second way is adding autoclosing functionality to the Textboxer. This way it wouldn't be so annoying for a user, because everything is done by JavaScript on page submit. But if someone disables JavaScript, he can easily pass malformed input.

The third way is autoclosing BBcodes on each page parse. It is both reliable and easy to apply, but affects the rendering time slightly (usually, nothing to worry about, it's quite fast). In order to apply this hack, open your system/functions.php, sed_parse(). Then find this code:
Kod:
if ($parse_bbcodes)
{ $text = parse_bbcode($text); }

and replace it with this code:
:
hp]// BB auto-close

if ($parse_bbcodes)

    {

        // List of valid bbcodes

        $valid_bb = array('b', 'i', 's', 'u', 'p', 'size', 'quote', 'img', 't', 'thumb',

            'list', 'ol', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'del',

            'red', 'white', 'green', 'blue', 'orange', 'yellow', 'purple', 'black', 'grey', 'pink', 'sky', 'sea',

            'url', 'email', 'pfs', 'user', 'group', 'topic', 'page', 'pm', 'f', 'ac', 'youtube', 'googlevideo', 'metacafe',

            'spoiler', 'left', 'right', 'colleft', 'colright',

            'table', 'tr', 'th', 'td', 'hide');

        // These bbcodes don't need closing ones

        $ignore_bb = array('br', 'hr', '_', '__', 'more', 'c1', 'c2', 'c3');

        // Count all bbcodes

        if(preg_match_all('#\[(/)ş(\w+)(=[^\]]*)ş\]#', $text, $mt, PREG_SET_ORDER))

        {

            // Count all unclosed bbcode entries

            for($i = 0; $i < count($mt); $i++)

            {

                if(in_array($mt[$i][2], $valid_bb))

                {

                    if($mt[$i][1] == '/')

                    {

                        $bb = $mt[$i][2];

                        // Protect from "[/foo] [/bar][foo][bar]" trick

                        if($bbc[$bb] > 0) $bbc[$bb]--;

                        // else echo 'ERROR: invalid closing bbcode detected';

                    }

                    else

                    $bbc[$mt[$i][2]]++;

                }

            }

            // Close all unclosed tags. Produces non XHTML-comliant output (doesn't take tag order into account) but fixes the layout

            if(count($bbc) > 0) foreach($bbc as $bb => $c)

                $text .= str_repeat("[/$bb]", $c);

        }

        // Done, ready to parse bbcodes

        $text = sed_bbcode($text);

    }

(you can download the correct code from the link below)

It has 2 drawbacks: 1) it produces non XHTML-compliant output (because detecting the right tag order would result into much more difficult algorithm); 2) it doesn't autoclose HTML (when using HTML parsing mode). Though, XHTML-compliance is not so important as protecting the layout from being spoiled. And enabling HTML for users or noob admins is a bad practice.

If someone is interested, I may suggest implementations for the first and the second way later in this article.

Updated 2007/10/19: now closing valid BBcodes only.

Henüz yorum yapılmamıştır.
AUTO-CLOSING BBCODES
Author: Kaan
Date: 2011-11-27 12:21
Comments: (0)
File: 4224731-15-sed-usersprofile.rar
Filesize: 5 KB
Downloads: 473 times
Download AUTO-CLOSING BBCODES
Benzer SayfalarYorum
Installation with the auto-installer0
ACCURATE AVATAR/PHOTO/SIGNATURE AUTO-RESIZE WIT...0
PhpBB3 BBCodes Smilies0
Forum Auto Lavel2
Page Auto Refresh0
 
Powered by Seditio © 2009-2012 All Rights Reserved