[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / compositions_v2 / 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 // lister les exec ou apparait l'interface de composition et le type correspondant
12 // peut etre etendu par des plugins
13 $GLOBALS['compositions_exec']['naviguer'] = 'rubrique';
14 $GLOBALS['compositions_exec']['articles'] = 'article';
15 $GLOBALS['compositions_exec']['mots_edit'] = 'mot';
16 $GLOBALS['compositions_exec']['sites'] = 'site';
17 $GLOBALS['compositions_exec']['breves_voir'] = 'breve';
18 $GLOBALS['compositions_exec']['auteur_infos'] = 'auteur';
19
20 /**
21 * Fonction vide pour le pipeline homonyme
22 */
23 function compositions_autoriser(){}
24
25 /**
26 * Autorisation de modifier la composition
27 *
28 * @param <type> $faire
29 * @param <type> $type
30 * @param <type> $id
31 * @param <type> $qui
32 * @param <type> $opt
33 * @return <type>
34 */
35 function autoriser_styliser_dist($faire, $type='', $id=0, $qui = NULL, $opt = NULL){
36 include_spip('compositions_fonctions');
37 if (!autoriser('modifier',$type,$id,$qui,$opt))
38 return false;
39 if (compositions_verrouiller($type, $id) AND !autoriser('webmestre'))
40 return false;
41 return true;
42 }
43
44
45 /**
46 * Pipeline styliser pour definir le fond d'un objet en fonction de sa composition
47 *
48 * @param array $flux
49 * @return array
50 */
51 function compositions_styliser($flux){
52 include_spip('compositions_fonctions');
53 if (compositions_styliser_auto()){
54 if (!defined('_DIR_PLUGIN_Z')){
55 $type = $flux['args']['fond']; // on fait l'approximation fond=type
56 // si le type n'est pas l'objet d'une composition, ne rien faire
57 if (in_array($type,compositions_types())){
58 $contexte = isset($flux['args']['contexte'])?$flux['args']['contexte']:$GLOBALS['contexte'];
59 $serveur = $flux['args']['connect'];
60
61 $ext = $flux['args']['ext'];
62 $_id_table = id_table_objet($type);
63
64 if ($id = $contexte[$_id_table] AND $composition = compositions_determiner($type,$id,$serveur)){
65 if ($fond = compositions_selectionner($composition, $type, '', $ext, true, "")){
66 $flux['data'] = substr($fond, 0, - strlen(".$ext"));
67 }
68 }
69 }
70 }
71 else {
72 $contexte = isset($flux['args']['contexte'])?$flux['args']['contexte']:$GLOBALS['contexte'];
73 if (!test_espace_prive()
74 AND preg_match(',(^|/)contenu/([^/]*)$,i',$flux['args']['fond'],$regs)
75 AND $type = $regs[2]
76 AND in_array($type,compositions_types())){
77 $serveur = $flux['args']['connect'];
78
79 $ext = $flux['args']['ext'];
80 $_id_table = id_table_objet($type);
81
82 if ($id = $contexte[$_id_table] AND $composition = compositions_determiner($type,$id,$serveur)){
83 if ($fond = compositions_selectionner($composition, $type, '', $ext, true, "")){
84 $flux['data'] = substr($fond, 0, - strlen(".$ext"));
85 }
86 }
87 }
88 }
89 }
90 return $flux;
91 }
92
93 /**
94 * Affichage du formulaire de selection de la composition
95 *
96 * @param array $flux
97 * @return array
98 */
99 function compositions_affiche_milieu($flux){
100 $exec = $flux['args']['exec'];
101 if (isset($GLOBALS['compositions_exec'][$exec])){
102 $type = $GLOBALS['compositions_exec'][$exec];
103 $_id = id_table_objet($type);
104 if ($id = $flux['args'][$_id]) {
105 $config = unserialize($GLOBALS['meta']['compositions']);
106 $aut = autoriser('styliser',$type,$id);
107 include_spip('compositions_fonctions');
108 if (($config['masquer_formulaire'] != 'oui' OR $aut)
109 AND (is_array(reset(compositions_lister_disponibles($type))) OR ($type == 'rubrique' AND $config['tout_verrouiller'] != 'oui'))
110 ) {
111 $deplie = $aut ? false : -1;
112 $ids = 'formulaire_editer_composition_objet-' . "$type-$id";
113 $bouton = bouton_block_depliable(strtoupper(_T('compositions:composition')), $deplie, $ids);
114 $flux['data'] .= debut_cadre('e', chemin('compositions-24.png','images/'),'',$bouton, '', '', true);
115 $flux['data'] .= recuperer_fond('prive/editer/compositions', array_merge($_GET, array('type'=>$type,'id'=>$id)));
116 $flux['data'] .= fin_cadre();
117 }
118 }
119 }
120
121 return $flux;
122 }
123
124 function compositions_compositions_lister_disponibles($flux){return $flux;}
125
126 ?>