[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins / compositions_v3 / inc / compositions.php
1 <?php
2 /*
3 * Plugin Compositions
4 * (c) 2007-2009 Cedric Morin
5 * Distribue sous licence GPL
6 *
7 */
8
9 if (!defined("_ECRIRE_INC_VERSION")) return;
10
11 include_spip('compositions_fonctions');
12
13 /**
14 * Separer le type et le nom de la composition dans un nom de fichier
15 *
16 * @param string $nom
17 * @return array
18 */
19 function compositions_decomposer_nom($nom){
20 $reg = ",^([a-z][^-.]*)("._COMPOSITIONS_MATCH.")?$,i";
21 if (
22 /* recuperer le type et la composition */
23 preg_match($reg,$nom,$matches)
24 /* il y a bien un type */
25 AND $type=$matches[1]
26 ){
27 $composition = isset($matches[3])?$matches[3]:'';
28 return array($type,$composition);
29 }
30 return array($nom,"");
31 }
32
33 /**
34 * Charger les informations contenues dans le xml d'une composition
35 *
36 * @param string $nom
37 * @param string $info
38 * @return array|string
39 */
40 function compositions_charger_infos($nom,$info=""){
41 /* on peut appeller avec le nom du squelette */
42 $nom = preg_replace(',[.]html$,i','',$nom).".xml";
43 include_spip('inc/xml');
44 $composition = array();
45 if ($xml = spip_xml_load($nom,false)){
46 if (isset($xml['composition']) and count($xml['composition'])){
47 $xml = reset($xml['composition']);
48 $composition['nom'] = _T_ou_typo(spip_xml_aplatit($xml['nom']));
49 $composition['description'] = isset($xml['description'])?_T_ou_typo(spip_xml_aplatit($xml['description'])):'';
50 if (isset($xml['icon'])) {
51 $icon = chemin_image(reset($xml['icon']));
52 if (!$icon) {
53 $icon = find_in_path(reset($xml['icon']));
54 }
55 } else {
56 $icon = '';
57 }
58 $composition['image_exemple'] = isset($xml['image_exemple']) ? find_in_path(reset($xml['image_exemple'])) : '';
59 $composition['icon'] = $icon;
60 $composition['class'] = isset($xml['class']) ? trim(reset($xml['class'])) : '';
61 $composition['configuration'] = isset($xml['configuration']) ? spip_xml_aplatit($xml['configuration']) : '';
62 $composition['branche'] = array();
63 if (spip_xml_match_nodes(',^branche,', $xml, $branches)){
64 foreach (array_keys($branches) as $branche){
65 list($balise, $attributs) = spip_xml_decompose_tag($branche);
66 $composition['branche'][$attributs['type']] = $attributs['composition'];
67 }
68 }
69 }
70 }
71 if (!$info)
72 return $composition;
73 else
74 return isset($composition[$info])?$composition[$info]:"";
75 }
76
77
78 /**
79 * Ecrire dans une meta la liste des objets qui sont sous le regime des
80 * compositions
81 * La fonction est appelee
82 * - lors de la stylisation si la meta n'est pas encore definie
83 * - a chaque fois qu'on selectionne un composition dans l'espace prive
84 * - si var_mode=recalcul
85 * On est sur ainsi que toute nouvelle composition selectionnee est dedans
86 * Si une composition est retiree du file system sans etre deselectionnee
87 * l'erreur sera evitee par la verification d'existence au moment de styliser
88 *
89 * @param array $liste
90 */
91 function compositions_cacher($liste=null){
92 /* lister les compositions vraiment utilisees */
93 if (!is_array($liste)){
94 include_spip('compositions_fonctions');
95 $liste = compositions_lister_disponibles('',false);
96 }
97 /* lister les objets dont on a active la composition dans la configuration */
98 $config = compositions_objets_actives();
99
100 $liste = array_intersect($config,array_keys($liste));
101 ecrire_meta('compositions_types',implode(',',$liste));
102 spip_log('compositions: maj des compositions_types ['.$GLOBALS['meta']['compositions_types'].']');
103 }
104
105 ?>