4 * (c) 2007-2009 Cedric Morin
5 * Distribue sous licence GPL
9 if (!defined("_ECRIRE_INC_VERSION")) return;
12 * Declaration des champs sur les objets
14 * @param array $tables
17 function compositions_declarer_tables_objets_sql($tables){
19 // champs composition et composition_lock sur tous les objets
21 $tables[]['field']['composition'] = "varchar(255) DEFAULT '' NOT NULL";
22 $tables[]['field']['composition_lock'] = "tinyint(1) DEFAULT 0 NOT NULL";
23 $tables['spip_rubriques']['field']['composition_branche_lock'] = "tinyint(1) DEFAULT 0 NOT NULL";
30 * Fonction vide pour le pipeline homonyme
32 function compositions_autoriser(){}
35 * Autorisation de modifier la composition
37 * @param string $faire
44 function autoriser_styliser_dist($faire, $type='', $id=0, $qui = NULL, $opt = NULL){
45 include_spip('compositions_fonctions');
46 if (!autoriser('modifier',$type,$id,$qui,$opt))
48 if (compositions_verrouiller($type, $id) AND !autoriser('webmestre'))
55 * Pipeline styliser pour definir le fond d'un objet en fonction de sa composition
60 function compositions_styliser($flux){
61 include_spip('compositions_fonctions');
62 // en contexte Z, c'est Z ou Z-core qui stylise (on ne n'en occupe donc pas ici)
63 if (compositions_styliser_auto() AND !defined('_DIR_PLUGIN_Z') AND !defined('_DIR_PLUGIN_ZCORE')){
64 $type = $flux['args']['fond']; // on fait l'approximation fond=type
65 // si le type n'est pas l'objet d'une composition, ne rien faire
66 if (in_array($type,compositions_types())){
67 $contexte = isset($flux['args']['contexte'])?
$flux['args']['contexte']:$GLOBALS['contexte'];
68 $serveur = $flux['args']['connect'];
70 $ext = $flux['args']['ext'];
71 $_id_table = id_table_objet($type);
73 if ($id = $contexte[$_id_table] AND $composition = compositions_determiner($type,$id,$serveur)){
74 if ($fond = compositions_selectionner($composition, $type, '', $ext, true, "")){
75 $flux['data'] = substr($fond, 0, - strlen(".$ext"));
84 * Affichage du formulaire de selection de la composition
89 function compositions_affiche_milieu($flux){
90 $e = trouver_objet_exec($flux['args']['exec']);
91 $objets = compositions_objets_actives();
92 if (in_array($e['type'],$objets)
93 AND $e['edition']===false){
95 if ($id = $flux['args'][$e['id_table_objet']]) {
96 $config = unserialize($GLOBALS['meta']['compositions']);
97 $aut = autoriser('styliser',$type,$id);
98 if ((!isset($config['masquer_formulaire']) OR $config['masquer_formulaire'] != 'oui' OR $aut)
100 ($c=compositions_lister_disponibles($type) AND is_array(reset($c)))
101 OR ($type == 'rubrique' AND (!isset($config['tout_verrouiller']) OR $config['tout_verrouiller'] != 'oui'))
104 $ids = 'formulaire_editer_composition_objet-' . "$type-$id";
105 $texte = recuperer_fond(
106 'prive/editer/compositions',
113 if (($p = strpos($flux['data'],'<!--affiche_milieu-->'))!==false)
114 $flux['data'] = substr_replace($flux['data'],$texte,$p,0);
116 $flux['data'] .= $texte;
125 * Le pipeline compositions_declarer_heritage permet de declarer les heritages
127 * $heritages['objet'] = 'parent';
128 * ce qui permet ensuite de faire dans le fichier parent-ma_compo.xml
129 * <branche type="objet" composition="une_compo" />
131 * A partir de compositions 3.3.0 cette declaration est obligatoire.
132 * Les objets "standards" de SPIP sont declares ici. (a deplacer dans leurs plugins respectifs ?)
134 function compositions_compositions_declarer_heritage($heritages){
135 $heritages['mot'] = 'groupe_mots';
136 $heritages['rubrique'] = 'rubrique';
137 $heritages['article'] = 'rubrique';
138 $heritages['breve'] = 'rubrique';
139 $heritages['site'] = 'rubrique';