Advertisement:
2by2host

Author Topic: BBCode parameters... how to?  (Read 457 times)

Offline Yoshi

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,164
  • Gender: Male
BBCode parameters... how to?
« on: April 01, 2012, 09:17:59 AM »
Hi!

I've been fighting with the BBCode parameters of SMF for a while now and can't seem to figure them out.

I have this code:

Code: [Select]
        $codes[] = array(
                        'tag' => 'button',
                        'type' => 'parsed_equals',
                        'before' => '<li><a href="$2" class="firstlevel"><span class="firstlevel">',
                        'after' => '</span></a></li>',
                        'trim' => 'outside',
                        'require_parents' => array('menu'),
                );

And I'd like to add two parameters to it:
'active', which can either be true or false.
It should validate something like this:
Code: [Select]
if (strtolower($value) == 'true')
$value = 'active ';
else
$value = '';
It's an optional parameter meguesses.

'url', which should be used and validated as an URL.

In the end I guess the code would look something like this:
Code: [Select]
        $codes[] = array(
                        'tag' => 'button',
// Parameters somewhere here?
                        'type' => 'parsed_equals',
                        'before' => '<li><a href="{url}" class="{active}firstlevel"><span class="firstlevel">',
                        'after' => '</span></a></li>',
                        'trim' => 'outside',
                        'require_parents' => array('menu'),
                );

But I can't seem to figure out how to add it. I've read the text that explains it but I just can't bake any cake with it :(

Anybody caring to explain it to me? :)
SMF version: 2.0.2
My Mods / [WIP] Mod Builder / GitHub profile / "A programmer is just a tool which converts caffeine into code."
Quote
<FLAMER> Marketing is about to get into drug activities maybe... but we will see about that later on :P
<Yoshi2889> We're getting free drugs?
<CoreISP> He's talking about caffeine man, damn pen lifter.

Offline Yoshi

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,164
  • Gender: Male
Re: BBCode parameters... how to?
« Reply #1 on: April 01, 2012, 10:30:53 AM »
Seems like this worked:

Code: [Select]
        $codes[] = array(
                        'tag' => 'button',
                        'parameters' => array(
                                'active' => array('validate' => create_function('&$code', '
                                        if (strtolower($code) == \'true\')
                                                $code = \'active \';
                                        else
                                                $code = \'\';
                                               
                                        return $code;'), 'optional' => true),
                                'url' => array('validate' => create_function('&$code', '
                                        $code = strtr($code, array(\'<br />\' => \'\'));
                                        if (strpos($code, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
                                                $code = \'http://\' . $code;
                                               
                                        return $code;
                                ')),
                        ),
                        'before' => '<li><a href="{url}" class="{active}firstlevel"><span class="firstlevel">',
                        'after' => '</span></a></li>',
                        'trim' => 'outside',
                        'require_parents' => array('menu'),
                );

Thanks to Ricky and emanuele.

Dunno if that's 100% right, though.
My Mods / [WIP] Mod Builder / GitHub profile / "A programmer is just a tool which converts caffeine into code."
Quote
<FLAMER> Marketing is about to get into drug activities maybe... but we will see about that later on :P
<Yoshi2889> We're getting free drugs?
<CoreISP> He's talking about caffeine man, damn pen lifter.