Add a generic hash capability to the newsletter.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 25 May 2008 09:41:53 +0000 (11:41 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 25 May 2008 09:41:53 +0000 (11:41 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
include/massmailer.inc.php
modules/newsletter.php
upgrade/0.9.16/pr11_nl.sql [new file with mode: 0644]

index 0279948..93f661d 100644 (file)
@@ -152,12 +152,30 @@ abstract class MassMailer
         $this->assignData($page);
     }
 
+    private function createHash($line, $key = null)
+    {
+        $hash = implode(time(), $line) . rand();
+        $hash = md5($hash);
+        return $hash;
+    }
+
     public function sendTo($prenom, $nom, $login, $sexe, $html, $hash = 0)
     {
         global $globals;
+        $alias = $login;
         if (strpos($login, '@') === false) {
+            $alias = $login;
             $login = "$login@{$globals->mail->domain}";
         }
+        if (strpos($alias, '@') === false && (is_null($hash) || $hash == 0)) {
+
+            $hash = $this->createHash(array($prenom, $nom, $login, $sexe, $html, rand(), "X.org rulez"));
+            XDB::query("UPDATE  {$this->_subscriptionTable} as ni
+                    INNER JOIN  aliases AS a ON (ni.user_id = a.id)
+                           SET  ni.hash = {?}
+                         WHERE  ni.user_id != 0 AND a.alias = {?}",
+                       $hash, $alias);
+        }
 
         $mailer = new PlMailer($this->_tpl);
         $this->assignData($mailer);
@@ -177,7 +195,7 @@ abstract class MassMailer
         return  "SELECT  u.user_id, CONCAT(a.alias, '@{$globals->mail->domain}'),
                          u.prenom, IF(u.nom_usage='', u.nom, u.nom_usage),
                          FIND_IN_SET('femme', u.flags),
-                         q.core_mail_fmt AS pref, 0 AS hash
+                         q.core_mail_fmt AS pref, ni.hash AS hash
                    FROM  {$this->_subscriptionTable}  AS ni
              INNER JOIN  auth_user_md5   AS u  USING(user_id)
              INNER JOIN  auth_user_quick AS q  ON(q.user_id = u.user_id)
index 4a3c75c..37cb46a 100644 (file)
@@ -63,9 +63,11 @@ class NewsletterModule extends PLModule
             $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme'));
         }
         if (Post::has('send')) {
+            $res = XDB::query("SELECT hash FROM newsletter_ins WHERE user_id = {?}", S::i('uid'));
             $nl->sendTo(S::v('prenom'), S::v('nom'),
                         S::v('bestalias'), S::v('femme'),
-                        S::v('mail_fmt') != 'texte');
+                        S::v('mail_fmt') != 'texte',
+                        $res->fetchOneCell());
         }
     }
 
diff --git a/upgrade/0.9.16/pr11_nl.sql b/upgrade/0.9.16/pr11_nl.sql
new file mode 100644 (file)
index 0000000..2b7aaa7
--- /dev/null
@@ -0,0 +1,3 @@
+alter table newsletter_ins add column hash varchar(16) default null;
+
+# vim:set syntax=mysql: