4 * (c) 2007-2009 Cedric Morin
5 * Distribue sous licence GPL
9 if (!defined("_ECRIRE_INC_VERSION")) return;
11 include_spip('compositions_fonctions');
14 * Separer le type et le nom de la composition dans un nom de fichier
19 function compositions_decomposer_nom($nom){
20 $reg = ",^([a-z][^-.]*)("._COMPOSITIONS_MATCH
.")?$,i";
22 // recuperer le type et la composition
23 preg_match($reg,$nom,$matches)
24 // il y a bien un type
27 $composition = isset($matches[3])?
$matches[3]:'';
28 return array($type,$composition);
30 return array($nom,"");
34 * Charger les informations contenues dans le xml d'une composition
38 * @return array|string
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 (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 $composition['icon'] = isset($xml['icon'])?
find_in_path(reset($xml['icon'])):'';
51 $composition['class'] = isset($xml['class'])?
trim(reset($xml['class'])):'';
52 $composition['configuration'] = isset($xml['configuration'])?
spip_xml_aplatit($xml['configuration']):'';
53 $composition['branche'] = array();
54 if (spip_xml_match_nodes(',^branche,', $xml, $branches)){
55 foreach (array_keys($branches) as $branche){
56 list($balise, $attributs) = spip_xml_decompose_tag($branche);
57 $composition['branche'][$attributs['type']] = $attributs['composition'];
65 return isset($composition[$info])?
$composition[$info]:"";
70 * Ecrire dans une meta la liste des objets qui sont sous le regime des
72 * La fonction est appelee
73 * - lors de la stylisation si la meta n'est pas encore definie
74 * - a chaque fois qu'on selectionne un composition dans l'espace prive
75 * - si var_mode=recalcul
76 * On est sur ainsi que toute nouvelle composition selectionnee est dedans
77 * Si une composition est retiree du file system sans etre deselectionnee
78 * l'erreur sera evitee par la verification d'existence au moment de styliser
82 function compositions_cacher($liste=null){
83 if (!is_array($liste)){
84 include_spip('compositions_fonctions');
85 $liste = compositions_lister_disponibles('',false);
87 include_spip('inc/meta');
88 ecrire_meta('compositions_types',implode(',',array_keys($liste)));
89 spip_log('compositions: maj des compositions_types ['.$GLOBALS['meta']['compositions_types'].']');