VI. Appendices
[ Previous: D. Template Flags | Next: F. CSS Examples ]
E. Common Rule Examples
Common Rule Types
$bbcode->AddRule('mono', array(
    'simple_start' => '',
    'simple_end' => '',
    'class' => 'inline',
    'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
));
$bbcode->AddRule('border',  Array(
    'mode' => BBCODE_MODE_ENHANCED,
    'template' => '{$_content}
',
    'allow' => Array(
        'color' => '/^#[0-9a-fA-F]+|[a-zA-Z]+$/',
        'size' => '/^[1-9][0-9]*$/',
    ),
    'default' => Array(
        'color' => 'blue',
        'size' => '1',
    ),
    'class' => 'block',
    'allow_in' => Array('listitem', 'block', 'columns'),
));
$bbcode->AddRule('border',  Array(
    'mode' => BBCODE_MODE_CALLBACK,
    'method' => 'MyBorderFunction',
    'class' => 'block',
    'allow_in' => Array('listitem', 'block', 'columns'),
));
function MyBorderFunction($bbcode, $action, $name,
    $default, $params, $content) {
    ....
}
class MyObject {
    function BlargFunction($bbcode, $action, $name,
        $default, $params, $content) {
        ....
    }
}
$object = new MyObject;
$bbcode->AddRule('blarg',  Array(
    'mode' => BBCODE_MODE_CALLBACK,
    'method' => array($object, 'BlargFunction'),
    'class' => 'block',
    'allow_in' => Array('listitem', 'block', 'columns'),
));
Common Class Types
If your tag is a new replaced item tag (like [img], for example), you'll probably want to use these classes:
array(
    ...
    'class' => 'image',
    'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
    ...
)
If your tag is a new inline style tag (like [b] or [font], for example), you'll probably want to use these classes:
array(
    ...
    'class' => 'inline',
    'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
    ...
)
If your tag is a new link tag (like [url] or [email], for example), you'll probably want to use these classes:
array(
    ...
    'class' => 'link',
    'allow_in' => Array('listitem', 'block', 'columns', 'inline'),
    ...
)
If your tag is a new block tag (like [quote] or [center], for example), you'll probably want to use these classes:
array(
    ...
    'class' => 'block',
    'allow_in' => Array('listitem', 'block', 'columns'),
    ...
)
Regardless of which classes you use, it is still important to check to make sure that your new
tag can only go inside other tags where it's legal:  For example, if your tag outputs a <span>,
it's legal inside another tag that outputs a <div>, but not the other way around.  The rules
above are good rules of thumb, but it's still important to check.  (For example, you should not allow the
user to place a Flash animation inside an <a href="...">...</a> element, which
means that if you add a [flash] tag, it's of class "image" but is not allowed
inside class "link" like [img] is.  Always carefully check to see how your new tags
affect the class hierarchy and the resulting HTML.)
[ Previous: D. Template Flags | Next: F. CSS Examples ]
Copyright © 2010, the Phantom Inker.  All rights reserved.