[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / spip-bonux / inc / core21_filtres.php
1 <?php
2 /**
3 * Plugin Spip-Bonux
4 * Le plugin qui lave plus SPIP que SPIP
5 * (c) 2008 Mathieu Marcillaud, Cedric Morin, Romy Tetue
6 * Licence GPL
7 *
8 * Fonctions integrees au core en branche 2.1 que l'on rend disponible en branche 2.0.x
9 *
10 */
11
12 if (!defined("_ECRIRE_INC_VERSION")) return;
13
14 // s'assurer que les filtres du core sont deja charges
15 // pour eviter tout risque de conflit
16 include_spip('inc/filtres');
17
18 if (!function_exists('lien_ou_expose')){
19 /**
20 * une fonction pour generer des menus avec liens
21 * ou un <strong class='on'> non clicable lorsque l'item est selectionne
22 *
23 * @param string $url
24 * @param string $libelle
25 * @param bool $on
26 * @param string $class
27 * @param string $title
28 * @return string
29 */
30 function lien_ou_expose($url,$libelle,$on=false,$class="",$title="",$rel=""){
31 return
32 ($on ?"<strong class='on'>":
33 "<a href='$url'"
34 .($title?" title='".attribut_html($title)."'":'')
35 .($class?" class='".attribut_html($class)."'":'')
36 .($rel?" rel='".attribut_html($rel)."'":'')
37 .">"
38 )
39 . $libelle
40 . ($on ? "</strong>":"</a>");
41 }
42 }
43
44 if (!function_exists('filtre_balise_img_dist')){
45 /**
46 * une fonction pour generer une balise img a partir d'un nom de fichier
47 *
48 * @param string $img
49 * @param string $alt
50 * @param string $class
51 * @return string
52 */
53 function filtre_balise_img_dist($img,$alt="",$class=""){
54 $taille = taille_image($img);
55 list($hauteur,$largeur) = $taille;
56 if (!$hauteur OR !$largeur)
57 return "";
58 return
59 "<img src='$img' width='$largeur' height='$hauteur'"
60 ." alt='".attribut_html($alt)."'"
61 .($class?" class='".attribut_html($class)."'":'')
62 .' />';
63 }
64 }
65
66 if (!function_exists('singulier_ou_pluriel')){
67 /**
68 * Afficher un message "un truc"/"N trucs"
69 *
70 * @param int $nb
71 * @return string
72 */
73 function singulier_ou_pluriel($nb,$chaine_un,$chaine_plusieurs,$var='nb'){
74 if (!$nb=intval($nb)) return "";
75 if ($nb>1) return _T($chaine_plusieurs, array($var => $nb));
76 else return _T($chaine_un);
77 }
78 }
79
80 if (!function_exists('filtre_icone_dist')){
81 /**
82 * un filtre icone mappe sur icone_inline, qui cree une icone a gauche par defaut
83 * le code de icone_inline est grandement reproduit ici car les liens ajax portent simplement une class ajax
84 * lorsque les interfaces sont en squelette, alors que l'implementation d'ajax de des scripts php
85 * est plus complexe
86 *
87 * @param string $lien
88 * @param string $texte
89 * @param string $fond
90 * @param string $align
91 * @param string $fonction
92 * @return string
93 */
94 function filtre_icone_dist($lien, $texte, $fond, $align="", $fonction="", $class="",$javascript=""){
95 $align = $align?$align:$GLOBALS['spip_lang_left'];
96 global $spip_display;
97
98 if ($fonction == "supprimer.gif") {
99 $style = 'icone36 danger';
100 } else {
101 $style = 'icone36';
102 if (strlen($fonction) < 3) $fonction = "rien.gif";
103 }
104 $style .= " " . substr(basename($fond),0,-4);
105
106 if ($spip_display == 1){
107 $hauteur = 20;
108 $largeur = 100;
109 $title = $alt = "";
110 }
111 else if ($spip_display == 3){
112 $hauteur = 30;
113 $largeur = 30;
114 $title = "\ntitle=\"$texte\"";
115 $alt = $texte;
116 }
117 else {
118 $hauteur = 70;
119 $largeur = 100;
120 $title = '';
121 $alt = $texte;
122 }
123
124 $size = 24;
125 if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
126 $size = $match[1];
127 if ($spip_display != 1 AND $spip_display != 4){
128 if ($fonction != "rien.gif"){
129 $icone = http_img_pack($fonction, $alt, "$title width='$size' height='$size'\n" .
130 http_style_background($fond, "no-repeat center center"));
131 }
132 else {
133 $icone = http_img_pack($fond, $alt, "$title width='$size' height='$size'");
134 }
135 } else $icone = '';
136
137 // cas d'ajax_action_auteur: faut defaire le boulot
138 // (il faudrait fusionner avec le cas $javascript)
139 if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i",$lien,$r))
140 list($x,$lien,$atts,$texte)= $r;
141 else $atts = '';
142
143 if ($align && $align!='center') $align = "float: $align; ";
144
145 $icone = "<a style='$align' class='$style $class'"
146 . $atts
147 . $javascript
148 . "\nhref='"
149 . $lien
150 . "'>"
151 . $icone
152 . (($spip_display == 3) ? '' : "<span>$texte</span>")
153 . "</a>\n";
154
155 if ($align <> 'center') return $icone;
156 $style = " style='text-align:center;'";
157 return "<div$style>$icone</div>";
158 }
159 }
160
161
162 if (!function_exists('filtre_explode_dist')){
163 /**
164 * filtre explode pour les squelettes permettant d'ecrire
165 * #GET{truc}|explode{-}
166 *
167 * @param strong $a
168 * @param string $b
169 * @return array
170 */
171 function filtre_explode_dist($a,$b){return explode($b,$a);}
172 }
173
174 if (!function_exists('filtre_implode_dist')){
175 /**
176 * filtre implode pour les squelettes permettant d'ecrire
177 * #GET{truc}|implode{-}
178 *
179 * @param array $a
180 * @param string $b
181 * @return string
182 */
183 function filtre_implode_dist($a,$b){return implode($b,$a);}
184 }
185
186 if (!function_exists('bando_images_background') AND !defined('_DIR_PLUGIN_BANDO')){
187 function bando_images_background(){
188 return '';
189 }
190 }
191
192 if (!function_exists('bando_style_prive_theme') AND !defined('_DIR_PLUGIN_BANDO')){
193 function bando_style_prive_theme() {
194 return '';
195 }
196 }
197
198 ?>