Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | ||
3 | /* | |
4 | * forms | |
5 | * version plug-in de spip_form | |
6 | * | |
7 | * Auteur : | |
8 | * Antoine Pitrou | |
9 | * adaptation en 182e puis plugin par cedric.morin@yterium.com | |
10 | * © 2005,2006 - Distribue sous licence GNU/GPL | |
11 | * | |
12 | */ | |
13 | if (!defined('_DIR_PLUGIN_FORMS')){ | |
14 | $p=explode(basename(_DIR_PLUGINS)."/",str_replace('\\','/',realpath(dirname(__FILE__)))); | |
15 | define('_DIR_PLUGIN_FORMS',(_DIR_PLUGINS.end($p))); | |
16 | } | |
17 | include_spip('base/forms'); | |
18 | ||
19 | // Code a rapatrier dans inc-public et inc_forms | |
20 | // (NB : le reglage du cookie doit se faire avant l'envoi de tout HTML au client) | |
21 | function Forms_poser_cookie_sondage() { | |
22 | if ($id_form = intval($_POST['id_form'])) { | |
23 | $nom_cookie = $GLOBALS['cookie_prefix'].'cookie_form_'.$id_form; | |
24 | // Ne generer un nouveau cookie que s'il n'existe pas deja | |
25 | if (!$cookie = $_COOKIE[$nom_cookie]) { | |
26 | include_spip("inc/acces"); | |
27 | $cookie = creer_uniqid(); | |
28 | } | |
29 | $GLOBALS['cookie_form'] = $cookie; // pour utilisation dans inc_forms... | |
30 | // Expiration dans 30 jours | |
31 | setcookie($nom_cookie, $cookie, time() + 30 * 24 * 3600); | |
32 | } | |
33 | } | |
34 | ||
35 | function Forms_generer_url_sondage($id_form) { | |
36 | return generer_url_public("sondage","id_form=$id_form",true); | |
37 | } | |
38 | ||
39 | if (isset($GLOBALS['ajout_reponse']) && $GLOBALS['ajout_reponse'] == 'oui' && | |
40 | isset($GLOBALS['ajout_cookie_form']) && $GLOBALS['ajout_cookie_form'] == 'oui') | |
41 | Forms_poser_cookie_sondage(); | |
42 | ||
43 | // test si un cookie sondage a ete pose | |
44 | foreach($_COOKIE as $cookie=>$value){ | |
45 | if (preg_match(",".$GLOBALS['cookie_prefix']."cookie_form_([0-9]+),",$cookie)){ | |
46 | $idf = preg_replace(",".$GLOBALS['cookie_prefix']."cookie_form_([0-9]+),","\\1",$cookie); | |
47 | $res = spip_query("SELECT id_article FROM spip_forms_articles WHERE id_form=$idf"); | |
48 | while($row=spip_fetch_array($res)){ | |
49 | $ida = $row['id_article']; | |
50 | if ( | |
51 | (isset($GLOBALS['article'])&&($GLOBALS['article']==$ida)) | |
52 | ||(isset($GLOBALS['id_article'])&&($GLOBALS['id_article']==$ida)) | |
53 | ||(isset($GLOBALS['contexte_inclus']['id_article'])&&($GLOBALS['contexte_inclus']['id_article']==$ida)) ){ | |
54 | // un article qui utilise le form va etre rendu | |
55 | // il faut utiliser le marquer cache pour ne pas polluer la page commune | |
56 | $GLOBALS['marqueur'].=":sondage $idf"; | |
57 | break; | |
58 | } | |
59 | } | |
60 | } | |
61 | } | |
62 | ||
63 | function forms_creer_tables_temporaires_boucles(){ | |
64 | include_spip('base/forms_temporaire'); | |
65 | forms_creer_tables_temporaires(); | |
66 | } | |
67 | ||
68 | ?> |