User Tools

Site Tools


it:doc:plugins:bbcode:tips
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


Next revision
it:doc:plugins:bbcode:tips [2019/01/12 17:53] – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== BBCode Plugin trucchetti ======
  
 +Traduzione italiana (a tratti libera) del documento [[doc:plugins:bbcode:tips|Adding custom BBCode]].
 +
 +//[[drudo3@gmail.com|Luciano P.]] 2007/07/05//
 +
 +===== Come aggiungere un tag personale =====
 +
 +Se si ha la necessità di aggiungere un nuovo tag BBCode, non è consigliabile modificare il plugin esistente, poichè all' eventuale successivo rilascio di FlatPress si è costretti a rifare da capo la modifica!
 +
 +Si consiglia di creare un **nuovo** plugin in modo da poterlo usare anche nelle successive release.
 +
 +Per altre informazioni sul BBCode di FP leggere questo documento: [[http://www.christian-seiler.de/projekte/php/bbcode/doc/en/chapter1.php|official documentation]].
 +
 +In questo esempio si vedrà come implementare l' elemento //acronym// grazie ad un tag del tipo [acronym=CSS]Cascading Style Sheet[/acronym] ((se vi state chiedendo se è possibile creare un tag alternativo come ad esempio [acronym=Cascading Style Sheet]CSS[/acronym], sappiate che per ora non è possibile! Non sono infatte ammesse più parole nell' attributo del tag)) che genererà una cosa di questo tipo: CSS
 +
 +<code php>
 +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>";
 +
 +
 +}
 +?>
 +
 +</code>
it/doc/plugins/bbcode/tips.txt · Last modified: 2024/03/02 20:08 by eagleman

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki