[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins-dist / mediabox / formulaires / configurer_mediabox.php
1 <?php
2 /*
3 * Plugin xxx
4 * (c) 2009 xxx
5 * Distribue sous licence GPL
6 *
7 */
8
9 if (!defined('_ECRIRE_INC_VERSION')) {
10 return;
11 }
12
13 include_spip('mediabox_pipelines');
14
15 function box_lister_skins() {
16 $skins = array('none' => array('nom' => _T('mediabox:label_aucun_style')));
17
18 $maxfiles = 1000;
19 $liste_fichiers = array();
20 $recurs = array();
21 foreach (creer_chemin() as $d) {
22 $f = $d . 'colorbox/';
23 if (@is_dir($f)) {
24 $liste = preg_files($f, 'colorbox[.]css$', $maxfiles - count($liste_fichiers), $recurs);
25 foreach ($liste as $chemin) {
26 $nom = substr(dirname($chemin), strlen($f));
27 // ne prendre que les fichiers pas deja trouves
28 // car find_in_path prend le premier qu'il trouve,
29 // les autres sont donc masques
30 if (!isset($liste_fichiers[$nom])) {
31 $liste_fichiers[$nom] = $chemin;
32 }
33 }
34 }
35 }
36 foreach ($liste_fichiers as $short => $fullpath) {
37 $skins[$short] = array('nom' => basename($short));
38 if (file_exists($f = dirname($fullpath) . '/vignette.jpg')) {
39 $skins[$short]['img'] = $f;
40 }
41 }
42
43 return $skins;
44 }
45
46 function box_choisir_skin($skins, $selected, $name = 'skin') {
47 $out = '';
48 if (!is_array($skins) or !count($skins)) {
49 return $out;
50 }
51 foreach ($skins as $k => $skin) {
52 $id = "${name}_" . preg_replace(',[^a-z0-9_],i', '_', $k);
53 $sel = ($selected == "$k" ? " checked='checked'" : '');
54 $balise_img = chercher_filtre('balise_img');
55 $label = isset($skin['img']) ?
56 '<a href="' . $skin['img'] . '" class="mediabox" rel="habillage">' . $balise_img($skin['img'],
57 $skin['nom']) . '</a>'
58 : $skin['nom'];
59
60 $out .= "<div class='choix'>";
61 $out .= "<input type='radio' name='$name' id='$id' value='$k'$sel />";
62 $out .= "<label for='$id'>$label</label>";
63 $out .= "</div>\n";
64 }
65
66 return $out;
67 }
68
69
70 function formulaires_configurer_mediabox_charger_dist() {
71 $valeurs = mediabox_config(true);
72 $valeurs['_skins'] = box_lister_skins();
73
74 return $valeurs;
75 }
76
77 function formulaires_configurer_mediabox_traiter_dist() {
78 $config = mediabox_config(true);
79
80 include_spip('inc/meta');
81 if (_request('reinit')) {
82 foreach ($config as $k => $v) {
83 set_request($k);
84 }
85 effacer_meta('mediabox');
86 } else {
87 // cas particulier de la checkbox :
88 if (!_request('active')) {
89 set_request('active', 'non');
90 }
91 foreach ($config as $k => $v) {
92 if (!is_null(_request($k))) {
93 $config[$k] = _request($k);
94 }
95 }
96 ecrire_meta('mediabox', serialize($config));
97 }
98
99 return array('message_ok' => _T('config_info_enregistree'), 'editable' => true);
100 }