1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Insertion dans le formulaire DIOGENE_AJOUTER_MEDIA |
---|
5 | * |
---|
6 | * @param array $flux Le contexte du pipeline |
---|
7 | * @return array $flux le contexte modifié passé aux suivants |
---|
8 | */ |
---|
9 | function diogene_mots_diogene_ajouter_media($flux){ |
---|
10 | $id_article = $flux['args']['contexte']['id_article']; |
---|
11 | if (is_array(unserialize($flux['args']['champs_ajoutes'])) && in_array('mots',unserialize($flux['args']['champs_ajoutes']))) { |
---|
12 | if ($id_article) { |
---|
13 | if (intval($id_article)) { |
---|
14 | if (!is_array($flux['args']['options_complements']['mots_obligatoires'])) { |
---|
15 | $mots_obligatoires = array(); |
---|
16 | } else { |
---|
17 | $mots_obligatoires = $flux['args']['options_complements']['mots_obligatoires']; |
---|
18 | } |
---|
19 | if(!is_array($flux['args']['options_complements']['mots_facultatifs'])) { |
---|
20 | $mots_facultatifs = array(); |
---|
21 | } else { |
---|
22 | $mots_facultatifs = $flux['args']['options_complements']['mots_facultatifs']; |
---|
23 | } |
---|
24 | $valeurs_mots['id_groupes'] = $groupes_possibles = array_merge($mots_obligatoires,$mots_facultatifs); |
---|
25 | //On récupÚre les mots qui sont peut être associés |
---|
26 | foreach($groupes_possibles as $groupe){ |
---|
27 | $valeurs_mots['groupe_'.$groupe] = sql_fetsel('mot.id_mot','spip_mots as mot left join spip_mots_articles as mots_articles ON (mot.id_mot=mots_articles.id_mot)','mots_articles.id_article='.intval($id_article).' AND mot.id_groupe='.intval($groupe)); |
---|
28 | } |
---|
29 | if (is_array($valeurs_mots)) { |
---|
30 | $flux['args']['contexte'] = array_merge($flux['args']['contexte'],$valeurs_mots); |
---|
31 | } |
---|
32 | } |
---|
33 | $flux['data'] .= recuperer_fond('formulaires/diogene_ajouter_medias_mots',$flux['args']['contexte']); |
---|
34 | } |
---|
35 | } |
---|
36 | return $flux; |
---|
37 | } |
---|
38 | |
---|
39 | function diogene_mots_diogene_ajout_media_post_verifier($flux){ |
---|
40 | spip_log("DIOGENE_MOTS : Verification des mots cles"); |
---|
41 | |
---|
42 | $id_diogene = _request('id_diogene'); |
---|
43 | $diogene = sql_fetsel("*","spip_diogenes","id_diogene=$id_diogene"); |
---|
44 | $options_complements = unserialize($diogene['options_complements']); |
---|
45 | $erreurs = &$flux['args']['erreurs']; |
---|
46 | // On teste si les groupes obligatoires sont ok |
---|
47 | if (is_array($options_complements['mots_obligatoires'])) { |
---|
48 | foreach($options_complements['mots_obligatoires'] as $groupe_obligatoire){ |
---|
49 | $mots_groupe = _request('groupe_'.$groupe_obligatoire); |
---|
50 | spip_log($mots_groupe,"bb"); |
---|
51 | if(empty($mots_groupe)){ |
---|
52 | $erreurs['groupe_'.$groupe_obligatoire] = _T('info_obligatoire'); |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | return $flux; |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * Fonction s'exécutant au traitement du formulaire DIOGENE_AJOUTER_MEDIA |
---|
61 | * |
---|
62 | * @param array $flux Le contexte du pipeline |
---|
63 | * @return array $flux le contexte modifié passé aux suivants |
---|
64 | */ |
---|
65 | function diogene_mots_diogene_ajout_media_post_traiter($flux){ |
---|
66 | spip_log("DIOGENE_MOTS : Traitement des mots cles"); |
---|
67 | |
---|
68 | if ($flux['args']['type'] == 'article') { |
---|
69 | $id_article = $flux['args']['id_objet']; |
---|
70 | |
---|
71 | $id_diogene = _request('id_diogene'); |
---|
72 | $diogene = sql_fetsel("*","spip_diogenes","id_diogene=$id_diogene"); |
---|
73 | $options_complements = unserialize($diogene['options_complements']); |
---|
74 | |
---|
75 | $mots_obligatoires = is_array($options_complements['mots_obligatoires']) |
---|
76 | ? $options_complements['mots_obligatoires'] |
---|
77 | : array(); |
---|
78 | |
---|
79 | $mots_facultatifs = is_array($options_complements['mots_facultatifs']) |
---|
80 | ? $options_complements['mots_facultatifs'] |
---|
81 | : array(); |
---|
82 | |
---|
83 | //On traite les mots clés obligatoires ou pas |
---|
84 | include_spip('inc/editer_mots'); |
---|
85 | $groupes_possibles = array_merge($mots_obligatoires,$mots_facultatifs); |
---|
86 | |
---|
87 | /* |
---|
88 | * On traite chaque groupe séparément |
---|
89 | * Si c'est une modification d'article il se peut qu'il faille supprimer les anciens mots |
---|
90 | * On fait une vérifications sur chaque groupe |
---|
91 | */ |
---|
92 | foreach($groupes_possibles as $groupe){ |
---|
93 | $mots = sql_fetsel('mot.id_mot','spip_mots as mot left join spip_mots_articles as articles ON mot.id_mot=articles.id_mot','id_groupe='.intval($groupe).' AND id_article='.intval($id_article)); |
---|
94 | /* |
---|
95 | * Si le select est multiple |
---|
96 | */ |
---|
97 | if(is_array(_request('groupe_'.$groupe))){ |
---|
98 | foreach(_request('groupe_'.$groupe) as $cle => $mot){ |
---|
99 | /* |
---|
100 | * Si le mot est déja dans les mots, on le supprime juste |
---|
101 | * de l'array des mots originaux |
---|
102 | */ |
---|
103 | if(in_array($mot, $mots)){ |
---|
104 | unset($mots[$cle]); |
---|
105 | } |
---|
106 | else{ |
---|
107 | sql_insertq('spip_mots_articles', array('id_mot' =>$mot, 'id_article' => $id_article)); |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | /* |
---|
112 | * Si le select est simple |
---|
113 | */ |
---|
114 | else{ |
---|
115 | if(!is_array($mots)){ |
---|
116 | $mots_tmp[] = $mots; |
---|
117 | $mots = $mots_tmp; |
---|
118 | } |
---|
119 | if(in_array(_request('groupe_'.$groupe), $mots)){ |
---|
120 | unset($mots); |
---|
121 | } |
---|
122 | else{ |
---|
123 | sql_insertq('spip_mots_articles', array('id_mot' =>_request('groupe_'.$groupe), 'id_article' => $id_article)); |
---|
124 | } |
---|
125 | } |
---|
126 | /* |
---|
127 | * S'il reste quelque chose dans les mots d'origine, on les délie d l'article |
---|
128 | */ |
---|
129 | if(count($mots)>0){ |
---|
130 | spip_log('on supprime des mots','emballe_media'); |
---|
131 | spip_log($mots); |
---|
132 | sql_delete('spip_mots_articles','id_article='.intval($id_article).' AND id_mot IN ('.implode(',',$mots).')'); |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | return $flux; |
---|
137 | } |
---|
138 | |
---|
139 | function diogene_mots_diogene_champs_sup($flux){ |
---|
140 | $flux['article']['mots'] = _T('diogene_mots:form_legend'); |
---|
141 | $flux['emballe_media']['mots'] = _T('diogene_mots:form_legend'); |
---|
142 | return $flux; |
---|
143 | } |
---|
144 | |
---|
145 | function diogene_mots_diogene_champs_texte($flux){ |
---|
146 | if(is_array(unserialize($flux['args']['champs_ajoutes'])) && in_array('mots',unserialize($flux['args']['champs_ajoutes']))){ |
---|
147 | $flux['data'] .= recuperer_fond('prive/diogene_mots_champs_texte', $flux['args']); |
---|
148 | return $flux; |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | function diogene_mots_pre_edition($flux){ |
---|
153 | if(($flux['args']['table'] == 'spip_diogenes') && ($flux['args']['action'] == 'instituer')){ |
---|
154 | $options_complements = unserialize($flux['data']['options_complements']); |
---|
155 | foreach(array( |
---|
156 | 'mots_obligatoires','mots_facultatifs' |
---|
157 | ) as $champ){ |
---|
158 | $val = _request($champ); |
---|
159 | if(is_array($val)){ |
---|
160 | $options_complements[$champ] = $val; |
---|
161 | } |
---|
162 | } |
---|
163 | $flux['data']['options_complements'] = serialize($options_complements); |
---|
164 | } |
---|
165 | return $flux; |
---|
166 | } |
---|
167 | |
---|
168 | ?> |
---|