[PLUGINS] +set de base
[lhc/web/www.git] / www / plugins / compositions_v3 / compositions_pipeline.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 /**
12 * Declaration des champs sur les objets
13 *
14 * @param array $tables
15 * @return array
16 */
17 function compositions_declarer_tables_objets_sql($tables){
18
19 // champs composition et composition_lock sur tous les objets
20 // c'est easy
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";
24
25 return $tables;
26 }
27
28
29 /**
30 * Fonction vide pour le pipeline homonyme
31 */
32 function compositions_autoriser(){}
33
34 /**
35 * Autorisation de modifier la composition
36 *
37 * @param string $faire
38 * @param string $type
39 * @param int $id
40 * @param array $qui
41 * @param array $opt
42 * @return bool
43 */
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))
47 return false;
48 if (compositions_verrouiller($type, $id) AND !autoriser('webmestre'))
49 return false;
50 return true;
51 }
52
53
54 /**
55 * Pipeline styliser pour definir le fond d'un objet en fonction de sa composition
56 *
57 * @param array $flux
58 * @return array
59 */
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'];
69
70 $ext = $flux['args']['ext'];
71 $_id_table = id_table_objet($type);
72
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"));
76 }
77 }
78 }
79 }
80 return $flux;
81 }
82
83 /**
84 * Affichage du formulaire de selection de la composition
85 *
86 * @param array $flux
87 * @return array
88 */
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){
94 $type = $e['type'];
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)
99 AND (
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'))
102 )
103 ) {
104 $ids = 'formulaire_editer_composition_objet-' . "$type-$id";
105 $texte = recuperer_fond(
106 'prive/editer/compositions',
107 array(
108 'type'=>$type,
109 'id'=>$id,
110 )
111 );
112
113 if (($p = strpos($flux['data'],'<!--affiche_milieu-->'))!==false)
114 $flux['data'] = substr_replace($flux['data'],$texte,$p,0);
115 else
116 $flux['data'] .= $texte;
117 }
118 }
119 }
120
121 return $flux;
122 }
123
124 /**
125 * Le pipeline compositions_declarer_heritage permet de declarer les heritages
126 * sous la forme :
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" />
130 *
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 ?)
133 */
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';
140 return $heritages;
141 }
142
143
144 ?>