From: Florent Bruneau Date: Sun, 25 May 2008 09:41:53 +0000 (+0200) Subject: Add a generic hash capability to the newsletter. X-Git-Tag: xorg/0.9.16~10 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=39337e2d8e5357597a6e14a5e0ba91521f1e2c21;p=platal.git Add a generic hash capability to the newsletter. Signed-off-by: Florent Bruneau --- diff --git a/include/massmailer.inc.php b/include/massmailer.inc.php index 0279948..93f661d 100644 --- a/include/massmailer.inc.php +++ b/include/massmailer.inc.php @@ -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) diff --git a/modules/newsletter.php b/modules/newsletter.php index 4a3c75c..37cb46a 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -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 index 0000000..2b7aaa7 --- /dev/null +++ b/upgrade/0.9.16/pr11_nl.sql @@ -0,0 +1,3 @@ +alter table newsletter_ins add column hash varchar(16) default null; + +# vim:set syntax=mysql: