X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fmassmailer.inc.php;h=95748f6714863a140ad0121c62548562bc774032;hb=6d1747b3dbcf944c995dc2d87e8561c7a66f3aa6;hp=07d9ee6ca295791e6fb29ad9c201ca97b87ab37d;hpb=5f30b30e8b2657ade5c727e98de286386ee002d8;p=platal.git diff --git a/include/massmailer.inc.php b/include/massmailer.inc.php index 07d9ee6..95748f6 100644 --- a/include/massmailer.inc.php +++ b/include/massmailer.inc.php @@ -1,6 +1,6 @@ _title_mail : $this->_title; } - public function head($prenom = null, $nom = null, $sexe = null, $type = 'text') + public function head($user = null, $type = 'text') { - if (is_null($prenom)) { + if (is_null($user)) { return $this->_head; } else { $head = $this->_head; - $head = str_replace('', $sexe ? 'Chère' : 'Cher', $head); - $head = str_replace('', $prenom, $head); - $head = str_replace('', $nom, $head); + $head = str_replace('', $user->isFemale() ? 'Chère' : 'Cher', $head); + $head = str_replace('', $user->displayName(), $head); + $head = str_replace('', '', $head); return format_text($head, $type, 2, 64); } } @@ -129,77 +134,86 @@ abstract class MassMailer } } - public function toText(&$page, $prenom, $nom, $sexe) + public function toText(&$page, $user) { $this->css($page); $page->assign('is_mail', false); $page->assign('mail_part', 'text'); - $page->assign('prenom', $prenom); - $page->assign('nom', $nom); - $page->assign('sexe', $sexe); + $page->assign('user', $user); $this->assignData($page); } - public function toHtml(&$page, $prenom, $nom, $sexe) + public function toHtml(&$page, $user) { $this->css($page); $page->assign('prefix', $this->_prefix . '/' . $this->id()); $page->assign('is_mail', false); $page->assign('mail_part', 'html'); - $page->assign('prenom', $prenom); - $page->assign('nom', $nom); - $page->assign('sexe', $sexe); + $page->assign('user', $user); $this->assignData($page); } - public function sendTo($prenom, $nom, $login, $sexe, $html, $hash = 0) + private function createHash($line, $key = null) { - global $globals; - if (strpos($login, '@') === false) { - $login = "$login@{$globals->mail->domain}"; + $hash = implode(time(), $line) . rand(); + $hash = md5($hash); + return $hash; + } + + public function sendTo($user, $hash = null) + { + if (is_null($hash)) { + $hash = XDB::fetchOneCell("SELECT hash + FROM {$this->_subscriptionTable} + WHERE user_id = {?}", $user->id()); + } + if (is_null($hash)) { + $hash = $this->createHash(array($user->displayName(), $user->fullName(), + $user->isFemale(), $user->isEmailFormatHtml(), + rand(), "X.org rulez")); + XDB::execute("UPDATE {$this->_subscriptionTable} as ni + SET ni.hash = {?} + WHERE ni.user_id != {?}", + $hash, $user->id()); } $mailer = new PlMailer($this->_tpl); $this->assignData($mailer); $mailer->assign('is_mail', true); - $mailer->assign('prenom', $prenom); - $mailer->assign('nom', $nom); - $mailer->assign('sexe', $sexe); + $mailer->assign('user', $user); $mailer->assign('prefix', null); $mailer->assign('hash', $hash); - $mailer->addTo("\"$prenom $nom\" <$login>"); - $mailer->send($html); + $mailer->addTo('"' . $user->fullName() . '" <' . $user->bestEmail() . '>'); + $mailer->send($user->isEmailFormatHtml()); } protected function getAllRecipients() { global $globals; - 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 + return "SELECT a.uid, a.hruid, a.display_name, a.full_name, a.email_format, + 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) - INNER JOIN aliases AS a ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags)) - LEFT JOIN emails AS e ON(e.uid=u.user_id AND e.flags='active') - WHERE ni.last < {?} AND ({$this->subscriptionWhere()}) AND e.email IS NOT NULL - GROUP BY u.user_id"; + INNER JOIN accounts AS a ON (ni.user_id = a.uid) + LEFT JOIN email_options AS eo ON (eo.uid = a.uid) + LEFT JOIN emails AS e ON (e.uid = a.uid AND e.flags='active') + WHERE ni.last < {?} AND ({$this->subscriptionWhere()}) AND + (e.email IS NOT NULL OR FIND_IN_SET('googleapps', eo.storage)) + GROUP BY a.uid"; } public function sendToAll() { $this->setSent(); - $query = $this->getAllRecipients() . " LIMIT {?}"; + $query = XDB::format($this->getAllRecipients(), $this->id()) . ' LIMIT 60'; while (true) { - $res = XDB::iterRow($query, $this->_id, 60); + $res = XDB::iterRow($query); if (!$res->total()) { return; } - $sent = array(); - while (list($uid, $bestalias, $prenom, $nom, $sexe, $fmt, $hash) = $res->next()) { - $sent[] = "(user_id='$uid'" . (!$uid ? " AND email='$bestalias')": ')'); - $this->sendTo($prenom, $nom, $bestalias, $sexe, $fmt=='html', $hash); + while ($infos = $res->next()) { + $user = User::getSilentWithValues(null, $infos); + $sent[] = XDB::format('user_id = {?}', $user->id()); + $this->sendTo($user, $hash); } XDB::execute("UPDATE {$this->_subscriptionTable} SET last = {?}