SPIP - Contrib -
1 days and 4 hours ago
img src=http://www.spip-contrib.net/IMG/arton2900.png alt= align=right width=128 height=128
class=spip_logos / div class='rss_chapo'pUn outil du Couteau Suisse : une balise (ou plusieurs !)
pour afficher le titre du parent d'un objet (article, rubrique, brève, mot-clé, ...),
ou simplement le titre d'un objet SPIP. Sans boucle supplémentaire !/p/div div
class='rss_texte'h3 class=spipPrésentation/h3 pCet outil est une fonctionnalité du
plugin « stronga href='http://www.spip-contrib.net/Le-Couteau-Suisse' class='spip_in'Le
Couteau Suisse/a/strong ». Pour avoir accès au paramétrage de la balise
#TITRE_PARENT, il vous faut donc avoir préalablement installé ce plugin, puis
activé l'outil « strongBalise #TITRE_PARENT/strong » sur la page
d'administration du plugin en espace privé./p pCet article est une version approfondie et
adaptée au Couteau Suisse de : a href='http://www.spip-contrib.net/balise-TITRE_PARENT'
class='spip_in'balise #TITRE_PARENT/a (par a href='http://www.spip-contrib.net/James,178'
class='spip_in'James/a)/p pVoici donc une simple balise qui évite d'ajouter une boucle dans
un squelette pour afficher le titre du parent d'un objet./p h3 class=spipUn peu d'histoire.../h3
p[a href='http://www.spip-contrib.net/romy-tetue-net' class='spip_in'romy.tetue.net/a] nous disait
:/p blockquote class=spip pCe n'est pas grand-chose, mais c'est un besoin que j'ai de façon
répétitive depuis que je connais SPIP : dans un squelette article, afficher
rapidement le titre de sa rubrique parente, pour faire un lien de retour (par exemple)./p pDans une
boucle article, on peut utiliser #URL_RUBRIQUE et #ID_RUBRIQUE... mais pas #TITRE pour afficher le
titre de la rubrique en question, pour lequel on devra alors sortir l'artillerie d'une boucle, si
bien qu'on peut se retrouver avec quelque chose d'un peu grotesque :/p div style='text-align:
left;' class='spip_code' dir='ltr'codea href=#URL_RUBRIQUEbr /
BOUCLE_rub(RUBRIQUES){id_rubrique}#TITRE/BOUCLE_rubbr / /a/code/div p ;-)/p /blockquote
pD'après Grégoire :/p blockquote class=spip pSi tu es dans une boucle incluse dans
une autre, c'est encore plus simple./p div style='text-align: left;' class='spip_code'
dir='ltr'codeBOUCLE_lstRub(RUBRIQUES)br / BOUCLE_art(ARTICLES){id_rubrique}br / br / Art :
#ID_ARTICLE - #TITREbr / [(#REM) titre de la rubrique maintenant]br / br /#_lstRub:TITREbr / [(REM)
ça marche avec les URL aussi]br / /BOUCLE_artbr / /BOUCLE_lstRub/code/div /blockquote pMais
une balise strong#TITRE_PARENT/strong simplifierait drôlement la vie :/p pcode
class='spip_code' dir='ltr'a href=#URL_RUBRIQUE#TITRE_PARENT/a/code/p pElle permettrait d'afficher
facilement le titre de la rubrique parente dans les boucles articles, brèves, rubriques.../p
pLa chose est faite. Cet outil ajoute à l'arsenal des balises utilisables sur votre site la
fameuse balise, sans boucle supplémentaire./p h3 class=spipUn peu de technique.../h3 pLe
fichier code class='spip_code' dir='ltr'outils/titre_parent_fonctions.php/code est le seul fichier
réellement essentiel à SPIP pour fournir la fonctionnalité. En effet, le
plugin n'a pour rôle que de proposer ce fichier comme extension au compilateur de SPIP./p pIl
se décompose en trois concepts : le filtre SPIP, la balise SPIP et le traitement SPIP des
balises./p h3 class=spipLES FILTRES/h3 pLa fonction « cs_titre_id() » est le filtre
« |cs_titre_id » qui permet de récupérer l'information voulue, c'est
à dire le titre de la table parent d'un objet $id. Il faut donc absolument appliquer ce
filtre à un #ID dont on est sûr qu'il est le parent de l'objet en cours dans la
boucle, et par défaut, une rubrique. Quatre exemples pour éclaircir cette idée
:/p pimg src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8'
height='11' alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_a(ARTICLES)[(#ID_RUBRIQUE|cs_titre_id)]/BOUCLE_a/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_b(BREVES)[(#ID_BREVE|cs_titre_id)]/BOUCLE_b/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_r(RUBRIQUES)[(#ID_PARENT|cs_titre_id)]/BOUCLE_r/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_m(MOTS)[(#ID_GROUPE|cs_titre_id{groupes_mots,id_groupe})]/BOUCLE_m/code/p pJe le
reconnais, pour utiliser « |cs_titre_id », il faut avoir une bonne connaissance de la
structure des tables SPIP et reconnaître les liaisons entre les objets enfants et leurs
parents. Ce filtre explore par défaut la table des rubriques, mais il est possible de
spécifier d'autres tables en utilisant les deux arguments prévus à cette effet
: itable, champ id/i. Le 3e exemple ci-dessus explore la table des groupes de mots-clés
(groupes_mots) et récupère le titre du groupe dont le champ id_groupe est bien
égal à #ID_GROUPE, le groupe parent du mot-clé traité par la boucle./p
pVoici le code du filtre « |cs_titre_id » :/p div class=coloration_codediv
class=spip_php codespan style=color: #666666; font-style: italic;// Renvoie le titre trouve dans la
$table_parent, là où $champ = $id/spanbr / span style=color: #000000; font-weight:
bold;function/span cs_titre_idspan style=color: #009900;#40;/spanspan style=color:
#000088;$id/spanspan style=color: #339933;,/span span style=color: #000088;$table_parent/spanspan
style=color: #339933;=/spanspan style='rubriques'/spanspan style=color: #339933;,/span span
style=color: #000088;$champ/spanspan style=color: #339933;=/spanspan style='id_rubrique'/spanspan
style=color: #009900;#41;/span span style=color: #009900;{/spanbr / span style=color: #666666;
font-style: italic;// retour nul si pas de parent a priori/spanbr / span style=color:
#b1b100;if/spanspan style=color: #009900;#40;/spanspan style=color: #339933;!/spanspan style=color:
#000088;$id/spanspan style=color: #009900;#41;/span span style=color: #b1b100;return/span span
style=''/span;br / span style=color: #666666; font-style: italic;// Utiliser la bonne requete en
fonction de la version de SPIP/spanbr / span style=color: #b1b100;if/spanspan style=color:
#009900;#40;/spana href=http://www.php.net/function_existsspan style=color:
#990000;function_exists/span/aspan style=color: #009900;#40;/spanspan
style='sql_getfetsel'/spanspan style=color: #009900;#41;/spanspan style=color: #009900;#41;/span
span style=color: #009900;{/spanbr / span style=color: #666666; font-style: italic;// SPIP
2.0/spanbr / span style=color: #b1b100;if/spanspan style=color: #009900;#40;/spanspan style=color:
#000088;$titre/span span style=color: #339933;=/span sql_getfetselspan style=color:
#009900;#40;/spanspan style='titre'/spanspan style=color: #339933;,/span span style=color:
#0000ff;spip_$table_parent/spanspan style=color: #339933;,/span span style=color: #0000ff;
$champ=$id/spanspan style=color: #009900;#41;/spanspan style=color: #009900;#41;/spanbr / span
style=color: #b1b100;return/span span style=color: #000088;$titre/span;br / span style=color:
#009900;}/span span style=color: #b1b100;else/span span style=color: #009900;{/spanbr / span
style=color: #b1b100;if/spanspan style=color: #009900;#40;/spanspan style=color: #000088;$r/span
span style=color: #339933;=/span spip_queryspan style=color: #009900;#40;/spanspan style=color:
#0000ff;SELECT titre FROM spip_$table_parent WHERE $champ=$id/spanspan style=color:
#009900;#41;/spanspan style=color: #009900;#41;/spanbr / span style=color: #666666; font-style:
italic;// s'il existe un champ, on le retourne/spanbr / span style=color: #b1b100;if/spanspan
style=color: #009900;#40;/spanspan style=color: #000088;$row/span span style=color: #339933;=/span
spip_fetch_arrayspan style=color: #009900;#40;/spanspan style=color: #000088;$r/spanspan
style=color: #009900;#41;/spanspan style=color: #009900;#41;/span span style=color:
#b1b100;return/span span style=color: #000088;$row/spanspan style=color: #009900;#91;/spanspan
style='titre'/spanspan style=color: #009900;#93;/span;br / span style=color: #009900;}/spanbr /
span style=color: #666666; font-style: italic;// sinon, rien !/spanbr / span style=color:
#b1b100;return/span span style=''/span;br / span style=color: #009900;}/span/divdiv
class='code_download' style='text-align: right;' a
href='http://www.spip-contrib.net/local/cache-code/40188ab05bb1d0c8d6b9ac3c49e607c5.txt'
style='font-family: verdana, arial, sans; font-weight: bold; font-style:
normal;'Télécharger/a/div/div pHistoire de simplifier un peu, voici deux autres
filtres bien plus pratiques : strong|titre_rubrique/strong et strong|titre_groupe/strong. En fait
ils sont tous les deux basés sur le précédent : br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / Le premier, appliqué à un #ID_RUBRIQUE (de
tout objet sauf les rubriques elles-mêmes) donne le titre de la rubrique parente.
Appliqué à #ID_PARENT (champ disponible dans la table des rubriques), ce filtre
renverra la rubrique mère de la rubrique en cours. br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / Le second, appliqué à #ID_GROUPE, balise
disponible uniquement si l'objet est un mot-clé, donne le titre du groupe parent./p pVoici
comment nos quatres exemples précédents peuvent maintenant s'écrire : br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_a(ARTICLES)[(#ID_RUBRIQUE|titre_rubrique)]/BOUCLE_a/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_b(BREVES)[(#ID_BREVE|titre_rubrique)]/BOUCLE_b/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_r(RUBRIQUES)[(#ID_PARENT|titre_rubrique)]/BOUCLE_r/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_m(MOTS)[(#ID_GROUPE|titre_groupe)]/BOUCLE_m/code/p pVoici le code de ces deux
filtres :/p div class=coloration_codediv class=spip_php codespan style=color: #666666; font-style:
italic;// filtre 'titre_rubrique' a utiliser sur #ID_RUBRIQUE d'un objet ou #ID_PARENT d'une
rubrique/spanbr / span style=color: #666666; font-style: italic;// Ex : :
BOUCLE_a(ARTICLES)[(#ID_RUBRIQUE|titre_rubrique)]/BOUCLE_a/spanbr / span style=color: #666666;
font-style: italic;// Ex : : BOUCLE_b(BREVES)[(#ID_RUBRIQUE|titre_rubrique)]/BOUCLE_b/spanbr / span
style=color: #666666; font-style: italic;// Ex : :
BOUCLE_r(RUBRIQUES)[(#ID_PARENT|titre_rubrique)]/BOUCLE_r/spanbr / span style=color: #000000;
font-weight: bold;function/span titre_rubriquespan style=color: #009900;#40;/spanspan style=color:
#000088;$id_rubrique/spanspan style=color: #339933;,/span span style=color: #000088;$table/spanspan
style=color: #339933;=/spanspan style='rubriques'/spanspan style=color: #339933;,/span span
style=color: #000088;$id/spanspan style=color: #339933;=/spanspan style='id_rubrique'/spanspan
style=color: #009900;#41;/span span style=color: #009900;{/spanbr / span style=color:
#b1b100;return/span cs_titre_idspan style=color: #009900;#40;/spanspan style=color:
#000088;$id_rubrique/spanspan style=color: #339933;,/span span style=color: #000088;$table/spanspan
style=color: #339933;,/span span style=color: #000088;$id/spanspan style=color:
#009900;#41;/span;br / span style=color: #009900;}/spanbr / span style=color: #666666; font-style:
italic;// filtre 'titre_groupe' a utiliser sur #ID_GROUPE d'un mot-clef/spanbr / span style=color:
#666666; font-style: italic;// Ex : : BOUCLE_m(MOTS)[(#ID_GROUPE|titre_groupe)]/BOUCLE_m/spanbr /
span style=color: #000000; font-weight: bold;function/span titre_groupespan style=color:
#009900;#40;/spanspan style=color: #000088;$id_mot/spanspan style=color: #339933;,/span span
style=color: #000088;$table/spanspan style=color: #339933;=/spanspan style='groupes_mots'/spanspan
style=color: #339933;,/span span style=color: #000088;$id/spanspan style=color: #339933;=/spanspan
style='id_groupe'/spanspan style=color: #009900;#41;/span span style=color: #009900;{/spanbr / span
style=color: #b1b100;return/span cs_titre_idspan style=color: #009900;#40;/spanspan style=color:
#000088;$id_mot/spanspan style=color: #339933;,/span span style=color: #000088;$table/spanspan
style=color: #339933;,/span span style=color: #000088;$id/spanspan style=color:
#009900;#41;/span;br / span style=color: #009900;}/span/divdiv class='code_download'
style='text-align: right;' a
href='http://www.spip-contrib.net/local/cache-code/74f50bc612c98ce7df7e9ded0b55e215.txt'
style='font-family: verdana, arial, sans; font-weight: bold; font-style:
normal;'Télécharger/a/div/div pDans l'absolu, ces filtres suffisent
déjà à simplifier l'écriture de vos squelettes, mais.../p pcode
class='spip_code' dir='ltr'BOUCLE_a(ARTICLES)[(#ID_RUBRIQUE|titre_rubrique)]/BOUCLE_a/code/p h3
class=spipLES BALISES/h3 pstrongMais allez, oubliez tout ce qu'on vient de dire, il y a encore plus
simple ! Laissons tomber les filtres et créons des balises !/strong/p pLa balise
strong#TITRE_PARENT/strong ne sert qu'à une chose, faire croire au compilateur SPIP qu'il
existe un champ 'titre_parent' dans la base de données. Le code va subtilement lui faire
chercher autre chose, un « vrai » champ de la base de données et on profit de
l'aubaine pour appliquer directement le filtre qu'on vient d'imaginer. Voici comment sont devenus
nos exemples proposés ci-dessus :/p pimg
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_a(ARTICLES)#TITRE_PARENT/BOUCLE_a/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_b(BREVES)#TITRE_PARENT/BOUCLE_b/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_r(RUBRIQUES)#TITRE_PARENT/BOUCLE_r/code br /img
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / code class='spip_code'
dir='ltr'BOUCLE_m(MOTS)#TITRE_PARENT/BOUCLE_m/code/p pJoli n'est-ce pas ?/p pLa fonction «
balise_TITRE_PARENT_dist() » définit donc la balise #TITRE_PARENT. Cette fonction est
appelée par le compilateur au strongre/strongcalcul de la page, pour remplacer le symbole
« #TITRE_PARENT » par l'appel du code PHP, voilà comment./p pLe fichier HTML
dans lequel on va placer #TITRE_PARENT, qu'on appelle squelette, est décortiqué par
le compilateur pour y découvrir des symboles qu'il va transformer en une portion de code
plus complexe./p pCes portions de code vont être empilées dans une mémoire
à laquelle on accédera plus tard pour recomposer un nouveau fichier, écrit en
PHP./p pLa définition d'une balise SPIP sert donc à préciser par quelle
portion de code sera remplacé le symbole auquel il fait référence, le tout
étant stocké au bon endroit dans la pile. Cet endroit est un objet technique
appelé Champ (parce qu'il fait référence au champ dans une table de base de
données). Celui-ci est capable d'explorer la pile de code qu'on a mémorisé et
pour faciliter l'exploration de cette pile mémoire, ainsi que la composition du code, on
peut utiliser les fonctions du compilateur. C'est le fameux paramètre code class='spip_code'
dir='ltr'$p/code. Voici le code de cette balise :/p div class=coloration_codediv class=spip_php
codespan style=color: #666666; font-style: italic;// Rubrique parente de tout objet
possédant un 'id_rubrique' ou groupe de mot-clef/spanbr / span style=color: #000000;
font-weight: bold;function/span balise_TITRE_PARENT_distspan style=color: #009900;#40;/spanspan
style=color: #000088;$p/spanspan style=color: #009900;#41;/span span style=color: #009900;{/spanbr
/ span style=color: #666666; font-style: italic;// examen du contexte/spanbr / span style=color:
#b1b100;switch/span span style=color: #009900;#40;/spanspan style=color: #000088;$p/spanspan
style=color: #339933;-/spanspan style=color: #004000;type_requete/spanspan style=color:
#009900;#41;/span span style=color: #009900;{/spanbr / span style=color: #b1b100;case/span span
style='rubriques'/spanspan style=color: #339933;:/spanbr / span style=color:
#000088;$table_parent/span span style=color: #339933;=/span span style='rubriques'/span;br / span
style=color: #000088;$champ_parent/span span style=color: #339933;=/span span
style='id_rubrique'/span;br / span style=color: #000088;$id/span span style=color: #339933;=/span
span style='id_parent'/span;br / span style=color: #b1b100;break/span;br / span style=color:
#b1b100;case/span span style='mots'/spanspan style=color: #339933;:/spanbr / span style=color:
#000088;$table_parent/span span style=color: #339933;=/span span style='groupes_mots'/span;br /
span style=color: #000088;$id/span span style=color: #339933;=/span span style=color:
#000088;$champ_parent/span span style=color: #339933;=/span span style='id_groupe'/span;br / span
style=color: #b1b100;break/span;br / span style=color: #000000; font-weight: bold;default/spanspan
style=color: #339933;:/spanbr / span style=color: #000088;$table_parent/span span style=color:
#339933;=/span span style='rubriques'/span;br / span style=color: #000088;$id/span span
style=color: #339933;=/span span style=color: #000088;$champ_parent/span span style=color:
#339933;=/span span style='id_rubrique'/span;br / span style=color: #b1b100;break/span;br / span
style=color: #009900;}/spanbr / span style=color: #666666; font-style: italic;// id de l'objet a
trouver pour retourner son titre/spanbr / span style=color: #000088;$id/span span style=color:
#339933;=/span champ_sqlspan style=color: #009900;#40;/spanspan style=color: #000088;$id/spanspan
style=color: #339933;,/span span style=color: #000088;$p/spanspan style=color: #009900;#41;/span;br
/ span style=color: #666666; font-style: italic;// le code php a executer/spanbr / span
style=color: #000088;$p/spanspan style=color: #339933;-/spanspan style=color: #004000;code/span
span style=color: #339933;=/span span style=color: #0000ff;cs_titre_id(intval($id),
'$table_parent', '$champ_parent')/span;br / span style=color: #b1b100;return/span span style=color:
#000088;$p/span;br / span style=color: #009900;}/span/divdiv class='code_download'
style='text-align: right;' a
href='http://www.spip-contrib.net/local/cache-code/5ed2d6b6450e15afe870a3495158e052.txt'
style='font-family: verdana, arial, sans; font-weight: bold; font-style:
normal;'Télécharger/a/div/div pOn enregistre donc dans ce champ le code PHP qu'on
souhaite. Ici, un appel au filtre 'cs_titre_id' détaillé plus haut, avec en
paramètre, la référence à de « vrais » champs de la la
table de base de données : le numéro du père connu du fils. D'où
l'utilisation de la fonction champ_sql, qui explore la pile pour atteindre le « vrai »
champ SQL qui nous intéresse ici./p pEncore un petit plaisir ? Voici une deuxième
balise qui permet d'obtenir facilement le titre du groupe auquel appartient un mot-clé. Bien
sûr, ceci est très pédagogique, mais que ne donnerait-on pour simplifier la
lecture de nos squelettes ! Voici le code de la balise strong#TITRE_GROUPE/strong :/p div
class=coloration_codediv class=spip_php codespan style=color: #666666; font-style: italic;// juste
le groupe d'un mot-clef/spanbr / span style=color: #000000; font-weight: bold;function/span
balise_TITRE_GROUPE_distspan style=color: #009900;#40;/spanspan style=color: #000088;$p/spanspan
style=color: #009900;#41;/span span style=color: #009900;{/spanbr / span style=color:
#000088;$p/spanspan style=color: #339933;-/spanspan style=color: #004000;code/span span
style=color: #339933;=/span span style=color: #0000ff;''/span;br / span style=color:
#b1b100;return/span span style=color: #000088;$p/spanspan style=color: #339933;-/spanspan
style=color: #004000;type_requete/spanspan style=color: #339933;==/spanspan
style='mots'/span?balise_TITRE_PARENT_distspan style=color: #009900;#40;/spanspan style=color:
#000088;$p/spanspan style=color: #009900;#41;/spanspan style=color: #339933;:/spanspan style=color:
#000088;$p/span;br / span style=color: #009900;}/span/divdiv class='code_download'
style='text-align: right;' a
href='http://www.spip-contrib.net/local/cache-code/6e3a641a8dd7322582ef53717bb77fff.txt'
style='font-family: verdana, arial, sans; font-weight: bold; font-style:
normal;'Télécharger/a/div/div pPour les connaisseurs, il existe en fait un champ
'type' dans la table des mots-clés, qui reproduit exactement ce que l'on veut ici. La balise
#TITRE_GROUPE renvoie donc le même résultat que #TYPE ; seuls les traitements peuvent
être différents (cf. paragraphe suivant)./p h3 class=spipLA SPÉCIFICATION DES
TRAITEMENTS/h3 pUne fois que le compilateur à entièrement exploré le fichier
HTML et constitué cette fameuse pile mémoire, il va fabriquer un fichier en PHP qui
aura donc remplacé tous les symboles par du « vrai » code. Ce résultat
est visible quand on affiche le débusqueur (code class='spip_code'
dir='ltr'var_mode=debug/code)./p pMais avant d'imprimer le code qu'on a demandé dans le
fichier, SPIP va ajouter d'autres traitements, autrement dit, il va appliquer d'autres filtres. Par
exemple, la typographie, la fonction propre() qui transformera les raccourcis SPIP en HTML ou
autre. Tout ces traitements sont regroupés dans une variable code class='spip_code'
dir='ltr'$table_des_traitements/code./p pUn SPIP installé connaît les traitements
qu'il doit appliquer au champ qui lui sont connu. Mais #TITRE_PARENT, il ne le connaît pas
encore. Or, c'est le titre d'une rubrique, il faut appliquer la typographie des #TITREs
traditionnels. On explique donc au compilateur que #TITRE_PARENT est à traiter comme un
#TITRE normal et par conséquent, la typographie standard lui sera appliquée avant son
affichage./p div class=coloration_codediv class=spip_php codespan style=color: #666666; font-style:
italic;/// invoquer la table des traitements/spanbr / include_spipspan style=color:
#009900;#40;/spanspan style='public/interfaces'/spanspan style=color: #009900;#41;/span;br / a
href=http://www.php.net/globalspan style=color: #990000;global/span/a span style=color:
#000088;$table_des_traitements/span;br / span style=color: #666666; font-style: italic;//
TITRE_PARENT et TITRE_GROUPE sont des TITREs !/spanbr / span style=color: #b1b100;if/span span
style=color: #009900;#40;/spanspan style=color: #339933;!/spana href=http://www.php.net/issetspan
style=color: #990000;isset/span/aspan style=color: #009900;#40;/spanspan style=color:
#000088;$table_des_traitements/spanspan style=color: #009900;#91;/spanspan
style='TITRE_PARENT'/spanspan style=color: #009900;#93;/spanspan style=color: #009900;#41;/spanspan
style=color: #009900;#41;/spanbr / span style=color: #000088;$table_des_traitements/spanspan
style=color: #009900;#91;/spanspan style='TITRE_PARENT'/spanspan style=color: #009900;#93;/span
span style=color: #339933;=/span span style=color: #000088;$table_des_traitements/spanspan
style=color: #009900;#91;/spanspan style='TITRE'/spanspan style=color: #009900;#93;/span;br / span
style=color: #b1b100;if/span span style=color: #009900;#40;/spanspan style=color: #339933;!/spana
href=http://www.php.net/issetspan style=color: #990000;isset/span/aspan style=color:
#009900;#40;/spanspan style=color: #000088;$table_des_traitements/spanspan style=color:
#009900;#91;/spanspan style='TITRE_GROUPE'/spanspan style=color: #009900;#93;/spanspan style=color:
#009900;#41;/spanspan style=color: #009900;#41;/spanbr / span style=color:
#000088;$table_des_traitements/spanspan style=color: #009900;#91;/spanspan
style='TITRE_GROUPE'/spanspan style=color: #009900;#93;/span span style=color: #339933;=/span span
style=color: #000088;$table_des_traitements/spanspan style=color: #009900;#91;/spanspan
style='TITRE'/spanspan style=color: #009900;#93;/span;br / span style=color: #009900;}/span/divdiv
class='code_download' style='text-align: right;' a
href='http://www.spip-contrib.net/local/cache-code/60f40fc4345dd56421d075ac3c94dd6e.txt'
style='font-family: verdana, arial, sans; font-weight: bold; font-style:
normal;'Télécharger/a/div/div pPetite finesse ici : Les experts pourront toute de
même personnaliser le traitement qu'ils tiennent à réserver à ces
nouvelles balises. Aussi, si un traitement spécifique leur est affecté dans le
fichier code class='spip_code' dir='ltr'config/mes_options.php/code, on ne l'écrase pas./p
h3 class=spipLa suite : la syntaxe étendue.../h3 pPourquoi ne pas étendre cette
idée #TITRE_OBJET à tous les objets de SPIP ? L'idée serait de programmer une
balise « ouverte » (#TITRE_QQCHOSE) qui donnerait le titre de n'importe quel objet
référencé dans n'importe quelle table, grâce à son simple «
id_qqchose »./p pSaviez-vous que la table 'spip_forum' par exemple possède tous ces
champs : iid_forum, id_parent, id_thread, id_rubrique, id_article, id_breve, id_auteur, id_message,
id_syndic/i ? Et donc, autant de liaisons avec tous ces objets.../p pM'enfin, avec nos filtres
décrits en tout début d'article, on peut, même sans balise
dédiée, accéder à tous les titres sans boucle supplémentaire. Il
suffit juste d'avoir un peu les idées claires :/p div style='text-align: left;'
class='spip_code' dir='ltr'codeBOUCLE_f1(FORUMS){tout}br / bull; Message #ID_FORUM, enfant du
message : br / [(#ID_PARENT|cs_titre_id{forum,id_forum})]br / br /br / /BOUCLE_f1br / br /
BOUCLE_f2(FORUMS){tout}br / bull; Message #ID_FORUM, attaché à l'article : br /
[(#ID_ARTICLE|cs_titre_id{articles,id_article})]br / br /br / /BOUCLE_f2/code/div pAprès
activation de la fonctionnalité au niveau de la configuration de l'outil « balise
#TITRE_PARENT », le Couteau Suisse donne accès à ces nouvelles balises
raccourcis (uniquement vous utilisez SPIP v2.0 minimum). Il s'agit donc d'un ensemble de balises
#TITRE_XXX qui pourront vous donner le titre de l'objet 'xxx', à condition que le champ
'id_xxx' soit présent dans la table en cours (#ID_XXX utilisable dans la boucle en cours)./p
pPar exemple, dans une boucle sur (ARTICLES), #TITRE_SECTEUR donnera le titre du secteur dans
lequel est placé l'article en cours, puisque l'identifiant #ID_SECTEUR (ou le champ
'id_secteur') est disponible dans ce cas./p pCes « balises ouvertes » existent
déjà dans SPIP : #LOGO_QQCHOSE, #URL_QQCHOSE, #FORMULAIRE_QQCHOSE, etc./p pDans le
cas de notre table 'spip_forum', les nouvelles balises #TITRE_THREAD, #TITRE_RUBRIQUE,
#TITRE_ARTICLE, #TITRE_BREVE, #TITRE_AUTEUR, #TITRE_MESSAGE renverrons les titres contenus dans la
table, si les identifiants respectifs (#ID_THREAD, #ID_RUBRIQUE, etc.) ont été
renseignés par SPIP au moment de la création de l'objet 'forum'./p pUne exception
à connaitre : équivalente à la balise #NOM placée dans une boucle sur
(AUTEURS), la balise #TITRE_AUTEUR renvoie le 'nom' de l'auteur et non le 'titre'./p h3
class=spipMise en garde !!/h3 pL'un des intérêts de cette contribution est la
pédagogie. Dans vos squelettes, n'abusez pas des balises décrites ici, car chacune
crée un appel à la base de données. Hors, il faut tout faire pour
éviter les appels trop fréquents, histoire de ne pas surcharger le serveur, surtout
s'il est mutualisé. Certains hébergeurs limitent parfois le nombre d'accès
afin d'éviter les abus./p pimg
src=http://www.spip-contrib.net/local/cache-vignettes/L8xH11/puce-5996f.gif width='8' height='11'
alt=- style='height:11px;width:8px;' / La règle est donc : strongune seule balise
#TITRE_QQCHOSE par(...)

|