[SPIP] ~maj v2.1.25-->2.1.26
[velocampus/web/www.git] / www / plugins / auto / couteau_suisse / couteau_suisse / outils / chatons.php
1 <?php
2
3 // Outils CHATONS - 30 janvier 2007
4 // Serieuse refonte et integration au Couteau Suisse : Patrice Vanneufville
5 // Toutes les infos sur : http://www.spip-contrib.net/?article2166
6
7 // cette fonction n'est pas appelee dans les balises html : html|code|cadre|frame|script|acronym|cite
8 function cs_rempl_chatons($texte) {
9 if (strpos($texte, ':')===false) return $texte;
10 $chatons = cs_lire_data_outil('chatons');
11 return count($chatons[2])?preg_replace($chatons[2], $chatons[1], $texte):$texte;
12 // return str_replace($chatons[0], $chatons[1], $texte);
13 }
14
15 function chatons_pre_typo($texte) {
16 if (strpos($texte, ':')===false) return $texte;
17 return cs_echappe_balises('html|code|cadre|frame|script|acronym|cite', 'cs_rempl_chatons', $texte);
18 }
19
20 // cette fonction appelee automatiquement a chaque affichage de la page privee du Couteau Suisse renvoie un tableau
21 function chatons_installe_dist() {
22 $chatons = array(array(), array(), array(), array(), array());
23 $path = find_in_path('img/chatons');
24 $dossier = opendir($path);
25 $bt = defined('_DIR_PLUGIN_PORTE_PLUME');
26 if($path) while ($image = readdir($dossier)) {
27 if (preg_match(',^([a-z][a-z0-9_-]*)\.(png|gif|jpg),', $image, $reg)) {
28 $chatons[0][] = ':'.$reg[1];
29 $chatons[2][] = ',:'.preg_quote($reg[1],',').'\\b,';
30 list(,,,$size) = @getimagesize("$path/$reg[1].$reg[2]");
31 $chatons[1][] = "<img class=\"no_image_filtrer\" alt=\"$reg[1]\" title=\"$reg[1]\" src=\"".url_absolue($path)."/$reg[1].$reg[2]\" $size/>";
32 if($bt) $chatons[4]['chaton_'.$reg[1]] = $reg[1].'.'.$reg[2];
33 }
34 }
35 return array($chatons);
36 }
37
38 // liste des nouveaux raccourcis ajoutes par l'outil
39 // si cette fonction n'existe pas, le plugin cherche alors _T('couteauprive:un_outil:aide');
40 function chatons_raccourcis() {
41 $chatons = cs_lire_data_outil('chatons');
42 return _T('couteauprive:chatons:aide', array('liste' => '<b>'.join('</b>, <b>', $chatons[0]).'</b>'));
43 }
44
45 // cette fonction renvoie une ligne de tableau entre <tr></tr> afin de l'inserer dans la Barre Typo V2, si elle est presente
46 function chatons_BarreTypo($tr) {
47 $chatons = cs_lire_data_outil('chatons');
48 $max = count($chatons[0]);
49 $res = '';
50 for ($i=0; $i<$max; $i++)
51 $res .= "<a href=\"javascript:barre_inserer('{$chatons[0][$i]}',@@champ@@)\">{$chatons[1][$i]}</a>";
52 return $tr.'<tr><td><@@span@@>'._T('couteauprive:chatons:nom')."</span>&nbsp;$res</td></tr>";
53 }
54
55 // les 2 fonctions suivantes inserent les boutons pour le plugin Porte Plume, s'il est present (SPIP>=2.0)
56 function chatons_PP_pre_charger($flux) {
57 $chatons = cs_lire_data_outil('chatons');
58 $max = count($chatons[0]);
59 $r = array();
60 for ($i=0; $i<$max; $i++) {
61 $c = &$chatons[0][$i];
62 $id = 'chaton_'.str_replace(':','',$c);
63 $r[] = array(
64 "id" => $id,
65 "name" => _T('couteau:pp_chatons_inserer', array('chaton'=>$c)),
66 "className" => $id,
67 "replaceWith" => $c,
68 "display" => true);
69 }
70 $r = array(
71 "id" => 'cs_chatons_drop',
72 "name" => _T('couteau:pp_chatons_inserer_drop'),
73 "className" => 'cs_chatons_drop',
74 "replaceWith" => '',
75 "display" => true,
76 "dropMenu" => $r,
77 );
78 foreach(cs_pp_liste_barres('chatons') as $b)
79 $flux[$b]->ajouterApres('grpCaracteres', $r);
80 return $flux;
81 }
82 function chatons_PP_icones($flux) {
83 $chatons = cs_lire_data_outil('chatons');
84 $flux['cs_chatons_drop'] = chatons_creer_icone_barre(find_in_path('img/chatons/lol.png'));
85 $path = find_in_path('img/chatons').'/';
86 foreach($chatons[4] as $i=>$v) $flux[$i] = chatons_creer_icone_barre($path.$v);
87 return $flux;
88 }
89 // creation d'icone pour le plugin porte-plume
90 function chatons_creer_icone_barre($file) {
91 static $icones_barre;
92 rep_icones_barre($icones_barre);
93 define_IMG_GD_MAX_PIXELS();
94 // la config "Methode de fabrication des vignettes" doit etre renseignee pour 'image_reduire'
95 $file = filtrer('image_reduire', $file, 19, 19);
96 $file = filtrer('image_recadre', $file, 16, 16, 'topleft');
97 $nom = basename($src = extraire_attribut($file, 'src'));
98 @copy($src, $icones_barre.$nom);
99 return $nom;
100 }
101 ?>