Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | ||
3 | /***************************************************************************\ | |
4 | * SPIP, Systeme de publication pour l'internet * | |
5 | * * | |
6 | * Copyright (c) 2001-2007 * | |
7 | * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * | |
8 | * * | |
9 | * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * | |
10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * | |
11 | \***************************************************************************/ | |
12 | ||
13 | if (!defined("_ECRIRE_INC_VERSION")) return; #securite | |
14 | ||
15 | // | |
16 | // Formulaire de signature d'une petition | |
17 | // | |
18 | ||
19 | include_spip('base/abstract_sql'); | |
20 | spip_connect(); | |
21 | ||
22 | // Contexte necessaire lors de la compilation | |
23 | ||
24 | // Il *faut* demander petition, meme si on ne s'en sert pas dans l'affichage, | |
25 | // car on doit obtenir la jointure avec sql_petitions pour verifier si | |
26 | // une petition est attachee a l'article | |
27 | ||
28 | // http://doc.spip.org/@balise_FORMULAIRE_SIGNATURE | |
29 | function balise_FORMULAIRE_SIGNATURE ($p) { | |
30 | return calculer_balise_dynamique($p,'FORMULAIRE_SIGNATURE', array('id_article', 'petition')); | |
31 | } | |
32 | ||
33 | // Verification des arguments (contexte + filtres) | |
34 | // http://doc.spip.org/@balise_FORMULAIRE_SIGNATURE_stat | |
35 | function balise_FORMULAIRE_SIGNATURE_stat($args, $filtres) { | |
36 | ||
37 | // pas d'id_article => erreur de squelette | |
38 | if (!$args[0]) | |
39 | return erreur_squelette( | |
40 | _T('zbug_champ_hors_motif', | |
41 | array ('champ' => '#FORMULAIRE_SIGNATURE', | |
42 | 'motif' => 'ARTICLES')), ''); | |
43 | ||
44 | // article sans petition => pas de balise | |
45 | else if (!$args[1]) | |
46 | return ''; | |
47 | ||
48 | else { | |
49 | // aller chercher dans la base la petition associee | |
50 | if ($r = spip_abstract_fetsel("texte, site_obli, message", 'spip_petitions', "id_article = ".intval($args[0]))) { | |
51 | $args[2] = $r['texte']; | |
52 | // le signataire doit-il donner un site ? | |
53 | $args[3] = ($r['site_obli'] == 'oui') ? '':' '; | |
54 | // le signataire peut-il proposer un commentaire | |
55 | $args[4] = ($r['message'] == 'oui') ? ' ':''; | |
56 | } | |
57 | return $args; | |
58 | } | |
59 | } | |
60 | ||
61 | // Executer la balise | |
62 | // http://doc.spip.org/@balise_FORMULAIRE_SIGNATURE_dyn | |
63 | function balise_FORMULAIRE_SIGNATURE_dyn($id_article, $petition, $texte, $site_obli, $message) { | |
64 | ||
65 | if (_request('var_confirm')) # _GET | |
66 | $reponse = reponse_confirmation(); # calculee plus tot: assembler.php | |
67 | ||
68 | else if (_request('nom_email') AND _request('adresse_email')){ # _POST | |
69 | if (!spip_connect()) | |
70 | $reponse = _T('form_pet_probleme_technique'); | |
71 | else { | |
72 | // Eviter les doublons | |
73 | $lock = "petition $id_article $adresse_email"; | |
74 | if (!spip_get_lock($lock, 5)) | |
75 | $reponse = _T('form_pet_probleme_technique'); | |
76 | else { | |
77 | $controler_signature = charger_fonction('controler_signature', 'inc'); | |
78 | $reponse = $controler_signature($id_article, | |
79 | _request('nom_email'), _request('adresse_email'), | |
80 | _request('message'), _request('signature_nom_site'), | |
81 | _request('signature_url_site'), _request('url_page')); | |
82 | spip_release_lock($lock); | |
83 | } | |
84 | } | |
85 | } | |
86 | ||
87 | return array('formulaires/signature', $GLOBALS['delais'], | |
88 | array( | |
89 | 'id_article' => $id_article, | |
90 | 'petition' => $petition, | |
91 | 'texte' => $texte, | |
92 | 'site_obli' => $site_obli, | |
93 | 'message' => $message, | |
94 | 'self' => $reponse ?'':parametre_url(self(),'debut_signatures','', '&'), | |
95 | 'reponse' => $reponse | |
96 | )); | |
97 | } | |
98 | ||
99 | ||
100 | // Retour a l'ecran du lien de confirmation d'une signature de petition. | |
101 | // Si var_confirm est non vide, c'est l'appel dans public/assembler.php | |
102 | // pour vider le cache au demarrage afin que la nouvelle signature apparaisse. | |
103 | // Sinon, c'est l'execution du formulaire et on retourne le message | |
104 | // de confirmation ou d'erreur construit lors de l'appel par assembler.php | |
105 | ||
106 | // http://doc.spip.org/@reponse_confirmation | |
107 | function reponse_confirmation($var_confirm = '') { | |
108 | ||
109 | static $confirm = ''; | |
110 | if (!$var_confirm) return $confirm; | |
111 | ||
112 | if ($var_confirm == 'publie' OR $var_confirm == 'poubelle') | |
113 | return ''; | |
114 | ||
115 | if (spip_connect()) { | |
116 | include_spip('inc/texte'); | |
117 | include_spip('inc/filtres'); | |
118 | ||
119 | // Eviter les doublons | |
120 | $lock = "petition $var_confirm"; | |
121 | if (!spip_get_lock($lock, 5)) { | |
122 | $confirm= _T('form_pet_probleme_technique'); | |
123 | } | |
124 | else { | |
125 | ||
126 | // Suppression d'une signature par un moderateur ? | |
127 | // Cf. plugin notifications | |
128 | if (isset($_GET['refus'])) { | |
129 | // verifier validite de la cle de suppression | |
130 | // l'id_signature est dans var_confirm | |
131 | include_spip('inc/securiser_action'); | |
132 | if ($id_signature = intval($var_confirm) | |
133 | AND ( | |
134 | $_GET['refus'] == _action_auteur("supprimer signature $id_signature", '', '', 'alea_ephemere') | |
135 | OR | |
136 | $_GET['refus'] == _action_auteur("supprimer signature $id_signature", '', '', 'alea_ephemere_ancien') | |
137 | )) { | |
138 | spip_query("UPDATE spip_signatures SET statut='poubelle' WHERE id_signature=$id_signature"); | |
139 | $confirm= _T('info_message_supprime'); # _L('Signature supprimee'); | |
140 | } else { | |
141 | $confirm = _T('forum_titre_erreur'); # _L('Erreur: ce code de suppression ne correspond a aucune signature'); | |
142 | } | |
143 | return ''; | |
144 | } | |
145 | ||
146 | ||
147 | $result_sign = spip_abstract_select('*', 'spip_signatures', "statut=" . _q($var_confirm)); | |
148 | ||
149 | if (spip_num_rows($result_sign) > 0) { | |
150 | while($row = spip_fetch_array($result_sign)) { | |
151 | $id_signature = $row['id_signature']; | |
152 | $id_article = $row['id_article']; | |
153 | $date_time = $row['date_time']; | |
154 | $nom_email = $row['nom_email']; | |
155 | $adresse_email = $row['ad_email']; | |
156 | $nom_site = $row['nom_site']; | |
157 | $url_site = $row['url_site']; | |
158 | $message = $row['message']; | |
159 | $statut = $row['statut']; | |
160 | } | |
161 | $result_petition = spip_abstract_select('*', 'spip_petitions', "id_article=$id_article"); | |
162 | ||
163 | while ($row = spip_fetch_array($result_petition)) { | |
164 | $id_article = $row['id_article']; | |
165 | $email_unique = $row['email_unique']; | |
166 | $site_obli = $row['site_obli']; | |
167 | $site_unique = $row['site_unique']; | |
168 | $message_petition = $row['message']; | |
169 | $texte_petition = $row['texte']; | |
170 | } | |
171 | ||
172 | if ($email_unique == "oui") { | |
173 | $result = spip_abstract_select('ad_email', 'spip_signatures', "id_article=$id_article AND ad_email=" . _q($adresse_email) . " AND statut='publie'"); | |
174 | if (spip_num_rows($result) > 0) { | |
175 | $confirm= _T('form_pet_deja_signe'); | |
176 | $refus = "oui"; | |
177 | } | |
178 | } | |
179 | ||
180 | if ($site_unique == "oui") { | |
181 | $result = spip_abstract_select('statut', 'spip_signatures', "id_article=$id_article AND url_site=" . _q($url_site) . " AND statut='publie'"); | |
182 | if (spip_num_rows($result) > 0) { | |
183 | $confirm= _T('form_pet_deja_enregistre'); | |
184 | $refus = "oui"; | |
185 | } | |
186 | } | |
187 | ||
188 | if ($refus == "oui") { | |
189 | $confirm= _T('form_deja_inscrit'); | |
190 | } | |
191 | else { | |
192 | $statut = 'publie'; | |
193 | $confirm= _T('form_pet_signature_validee'); | |
194 | ||
195 | spip_query("UPDATE spip_signatures SET statut="._q($statut).", date_time=NOW() WHERE id_signature="._q($id_signature)); | |
196 | ||
197 | // invalider les pages ayant des boucles signatures | |
198 | include_spip('inc/invalideur'); | |
199 | include_spip('inc/meta'); | |
200 | suivre_invalideur("id='varia/pet$id_article'"); | |
201 | ||
202 | } | |
203 | } | |
204 | else { | |
205 | $confirm= _T('form_pet_aucune_signature'); | |
206 | } | |
207 | spip_release_lock($lock); | |
208 | } | |
209 | } | |
210 | else { | |
211 | $confirm= _T('form_pet_probleme_technique'); | |
212 | } | |
213 | } | |
214 | ||
215 | // | |
216 | // Recevabilite de la signature d'une petition | |
217 | // | |
218 | ||
219 | // http://doc.spip.org/@inc_controler_signature_dist | |
220 | function inc_controler_signature_dist($id_article, $nom_email, $adresse_email, $message, $nom_site, $url_site, $url_page) { | |
221 | ||
222 | include_spip('inc/texte'); | |
223 | include_spip('inc/filtres'); | |
224 | include_spip('inc/mail'); | |
225 | ||
226 | $result_petition = spip_abstract_select('*', 'spip_petitions', "id_article=$id_article"); | |
227 | ||
228 | if ($row = spip_fetch_array($result_petition)) { | |
229 | $email_unique = $row['email_unique']; | |
230 | $site_obli = $row['site_obli']; | |
231 | $site_unique = $row['site_unique']; | |
232 | } | |
233 | ||
234 | $texte = ''; | |
235 | if (strlen($nom_email) < 2) | |
236 | $texte = _T('form_indiquer_nom'); | |
237 | elseif ($adresse_email == _T('info_mail_fournisseur')) | |
238 | $texte = _T('form_indiquer_email'); | |
239 | elseif (!email_valide($adresse_email)) | |
240 | $texte = _T('form_email_non_valide'); | |
241 | elseif (strlen(_request('nobot')) | |
242 | OR substr_count($message,'http://')>2) { | |
243 | $texte = _T('form_pet_probleme_technique'); # _L("Vilain !") | |
244 | #envoyer_mail('email_moderateur@example.tld', 'spam intercepte', var_export($_POST,1)); | |
245 | } else { | |
246 | if ($email_unique == "oui") { | |
247 | $result = spip_abstract_select('statut', 'spip_signatures', "id_article=$id_article AND ad_email=" . _q($adresse_email) . " AND statut='publie'"); | |
248 | if (spip_num_rows($result) > 0) | |
249 | $texte = _T('form_pet_deja_signe'); | |
250 | } | |
251 | if (!$texte AND $site_obli == "oui") { | |
252 | if (!strlen($nom_site) | |
253 | OR !vider_url($url_site)) { | |
254 | $texte = _T('form_indiquer_nom_site'); | |
255 | } | |
256 | include_spip('inc/sites'); | |
257 | if (!$texte | |
258 | AND !recuperer_page($url_site, false, true, 0)) | |
259 | $texte = _T('form_pet_url_invalide'); | |
260 | } | |
261 | if (!$texte AND $site_unique == "oui") { | |
262 | $result = spip_abstract_select('statut', 'spip_signatures', "id_article=$id_article AND url_site=" . _q($url_site) . " AND (statut='publie' OR statut='poubelle')"); | |
263 | if (spip_num_rows($result) > 0) { | |
264 | $texte = _T('form_pet_site_deja_enregistre'); | |
265 | } | |
266 | } | |
267 | if ($texte) return $texte; | |
268 | ||
269 | $passw = test_pass(); | |
270 | ||
271 | $row = spip_fetch_array(spip_abstract_select('titre,lang', 'spip_articles', "id_article=$id_article")); | |
272 | lang_select($row['lang']); | |
273 | $titre = textebrut(typo($row['titre'])); | |
274 | lang_dselect(); | |
275 | ||
276 | // preparer l'url de confirmation | |
277 | $url = parametre_url($url_page, 'var_confirm',$passw,'&'); | |
278 | if ($row['lang'] != $GLOBALS['meta']['langue_site']) | |
279 | $url = parametre_url($url, "lang", $row['lang'],'&'); | |
280 | $url .= "#sp$id_article"; | |
281 | ||
282 | $messagex = _T('form_pet_mail_confirmation', array('titre' => $titre, 'nom_email' => $nom_email, 'nom_site' => $nom_site, 'url_site' => $url_site, 'url' => $url, 'message' => $message)); | |
283 | ||
284 | if (envoyer_mail($adresse_email, _T('form_pet_confirmation')." ".$titre, $messagex)) { | |
285 | $id_signature = spip_abstract_insert('spip_signatures', "(id_article, date_time, statut)", "($id_article, NOW(), '$passw')"); | |
286 | include_spip('inc/modifier'); | |
287 | revision_signature($id_signature, array( | |
288 | 'nom_email' => $nom_email, | |
289 | 'ad_email' => $adresse_email, | |
290 | 'message' => $message, | |
291 | 'nom_site' => $nom_site, | |
292 | 'url_site' => $url_site | |
293 | )); | |
294 | $texte = _T('form_pet_envoi_mail_confirmation'); | |
295 | } | |
296 | else { | |
297 | $texte = _T('form_pet_probleme_technique'); | |
298 | } | |
299 | } | |
300 | return $texte; | |
301 | } | |
302 | ||
303 | ||
304 | // http://doc.spip.org/@test_pass | |
305 | function test_pass() { | |
306 | include_spip('inc/acces'); | |
307 | for (;;) { | |
308 | $passw = creer_pass_aleatoire(); | |
309 | if (!spip_num_rows(spip_abstract_select('statut', 'spip_signatures', "statut='$passw'"))) | |
310 | return $passw; | |
311 | } | |
312 | ||
313 | } | |
314 | ?> |