Defining buttons

To add buttons into the private zone, all that is needed is to provide a bouton element in the plugin.xml files as follows:

<bouton id="identifier" parent="name of parent identifier">
    <icone>icon path</icone>
    <titre>title language string code</titre>  
    <url>name of the exec</url>
    <args>arguments passed</args>  
</bouton>

Description:

  • id holds the unique identifier of the button, which is used (amongst other things) by sub-menus to indicate the name of their parent button. Quite often the name of the exec file (used to display the page) is the same as the identifier name,
  • parent: optional, used to specify that the button is a sub-element of a parent button. It therefore stores the identifier of the parent button. Absent any value, it will be a top level element that will be created (alongside the "Launch pad" and "Site edit" buttons),
  • icone: also optional, used to specify the icon path,
  • titre: button text, may also be a text placeholder code "plugin:placeholdername",
  • url specifies the exec file name that is loaded when you click on the button. If not indicated, it will be the identifier name that is used.
  • args, optional, used to pass arguments to the URL (example: <args>criteria=start</args>).

Authorisations

The buttons are displayed by default for all persons connecting to the private zone. To change this setting, specific authorisations must be created for the buttons (and then use the authorisation pipeline to load the new plugin authorisations):

function autoriser_identifiant_bouton_dist($faire, $type, $id, $qui, $opt) {
    return true; // or false
}

Example

Statistics for SPIP 2.3 – currently under development – will be in a separate plugin. At present, it reproduces the buttons as below:

    
<pipeline>
    <nom>autoriser</nom>
    <inclure>stats_autoriser.php</inclure>
</pipeline>
<bouton id="statistiques_visites">
    <icone>images/statistiques-48.png</icone>
    <titre>icone_statistiques_visites</titre>      
</bouton>
<bouton id='statistiques_repartition' parent='statistiques_visites'>
    <icone>images/rubrique-24.gif</icone>
    <titre>icone_repartition_visites</titre>
</bouton>
<bouton id='statistiques_lang' parent='statistiques_visites'>
    <icone>images/langues-24.gif</icone>
    <titre>onglet_repartition_lang</titre>
</bouton>  
<bouton id='statistiques_referers' parent='statistiques_visites'>
    <icone>images/referers-24.gif</icone>
    <titre>titre_liens_entrants</titre>
</bouton>

The authorisations are defined in a specific file:

<?php
function stats_autoriser(){}

// View the stats ? = all admins
function autoriser_voirstats_dist($faire, $type, $id, $qui, $opt) {
    return (($GLOBALS['meta']["activer_statistiques"] != 'non')
            AND ($qui['statut'] == '0minirezo'));
}

// Button authorisation
function autoriser_statistiques_visites_bouton_dist($faire, $type, $id, $qui, $opt) {
    return autoriser('voirstats', $type, $id, $qui, $opt);
}

function autoriser_statistiques_repartition_bouton_dist($faire, $type, $id, $qui, $opt) {
    return autoriser('voirstats', $type, $id, $qui, $opt);
}

function autoriser_statistiques_lang_bouton_dist($faire, $type, $id, $qui, $opt) {
    return ($GLOBALS['meta']['multi_articles'] == 'oui'
            OR $GLOBALS['meta']['multi_rubriques'] == 'oui')
        AND autoriser('voirstats', $type, $id, $qui, $opt);
}

function autoriser_statistiques_referers_bouton_dist($faire, $type, $id, $qui, $opt) {
    return autoriser('voirstats', $type, $id, $qui, $opt);
}

?>

Author Mark Baber Published : Updated : 13/10/10

Translations : English, français