User Tools

Site Tools


de:doc:plugins:bbcode:tips

Tipps für das BBCode Plugin

Wie man eigene Tags definiert

Beim Einfügen von neuen bbcode-Tags ist es wichtig, die Änderungen nicht im Core-Plugin zu machen; dieses wird beim nächsten Update höchstwahrscheinlich überschrieben und die Änderungen wären verloren.

Aber man kann ein neues Plugin mit eigenen Tags bauen, indem man an das bestehende Plugin anbaut.

Mehr Infos über die in Flatpress verwendete bbcode-Klasse gibt es in der offiziellen Dokumentation.

Das Nachfolgende Beispiel zeigt, den Code für ein Akronym-Tag baut, welches das Kürzel als Attribut erwartet und die Erklärung als Inhalt des Tags1): [acronym=CSS]Cascading Style Sheet[/acronym] Auf deiner Webseite sieht das dann so aus: CSS.

custombbcode.php
----------------------
<?php
 
// this will tell FlatPress to load the new tags at the very beginning 
 
add_filter('init', 'plugin_custombbcode_tags');
 
// here you define a function. In this case we're creating an acronym tag
 
function plugin_custombbcode_tags() {
       $bbcode = plugin_bbcode_init(); //import the "global" bbcode object into current function
                                         // this way 
                                         // a) parsing is done only once, and by the official plugin
                                         // b) you create only ONE object, and therefore computation is quicker
        $bbcode->addCode (
                    'acronym',  // tag name: this will go between square brackets
                    'callback_replace', // type of action: we'll use a callback function
                    'plugin_custombbcode_acronym', // name of the callback function
                    array('usecontent_param' => array ('default')), // supported parameters: "default" is [acronym=valore]
                    'inline', // type of the tag, inline or block, etc
                    array ('listitem', 'block', 'inline', 'link'), // type of elements in which you can use this tag
                    array ()); // type of elements where this tag CAN'T go (in this case, none, so it can go everywhere)
 
    $bbcode->setCodeFlag ('acronym', 'closetag', BBCODE_CLOSETAG_MUSTEXIST); // a closing tag is mandatory [/tag]
 
}
 
// $content is the text between the two tags, i.e. [tag]CONTAINED TEXT[/tag] $content='CONTAINED TEXT'
// $attributes is an associative array where keys are the tag properties. default is the [tagname=value] property
 
function plugin_custombbcode_acronym($action, $attributes, $content, $params, $node_object) { 
     if ($action == 'validate') {
        // not used for now
        return true;
     }
 
    // [acronym=css]Cascading Style Sheet[/acronym]
    // will become <acronym title="Cascading Style Sheet">css</acronym>
 
    return "<acronym title=\"$content\">{$attributes['default']}</acronym>";
 
 
}
?>
1)
Wenn du dich fragst, ob man so etwas auch in der alternativen Syntax-Schreibweise [acronym=Cascading Style Sheet]CSS[/acronym] realisieren kann: nein, das geht momentan nicht. Mehrere Worte sind als Tag-Attribute nicht erlaubt.
de/doc/plugins/bbcode/tips.txt · Last modified: 2019/01/12 17:53 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki