Exemplo n.º 1
0
 public function resendEmailInvitationEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $invitationId = $pl->getParameterValue("invitationId");
     $message2 = trim($pl->getParameterValue("message"));
     $c = new Criteria();
     $c->add("invitation_id", $invitationId);
     $c->add("site_id", $site->getSiteId());
     $inv = DB_EmailInvitationPeer::instance()->selectOne($c);
     if (!$inv) {
         throw new ProcessException(_("Invitation could not be found."), "no_invitation");
     }
     if ($inv->getAttempts() >= 3) {
         throw new ProcessException(_("You can not send more than 3 copies of the invitation."));
     }
     if ($message2 == "") {
         throw new ProcessException(_('Message should not be empty'));
     }
     if (preg_match(';://;', $message2) || preg_match(';\\.www;i', $message2)) {
         throw new ProcessException(_('The message should not contain any links to websites.'), "bad_message");
     }
     if ($message2 != "" && strlen($message2) > 1000) {
         throw new ProcessException(_('The message seems to be too long. Max 1000 characters are allowed.'), "bad_message");
     }
     $db = Database::connection();
     $db->begin();
     // prepare and send email
     $user = $runData->getUser();
     $profile = $user->getProfile();
     $oe = new OzoneEmail();
     $oe->addAddress($inv->getEmail());
     $oe->setSubject(sprintf(_("[%s] %s invites you to join! (reminder)"), GlobalProperties::$SERVICE_NAME, $user->getNickName()));
     $oe->contextAdd('user', $user);
     $oe->contextAdd('profile', $profile);
     $oe->contextAdd('hash', $inv->getHash());
     $oe->contextAdd("site", $site);
     $oe->contextAdd("message", $inv->getMessage());
     $oe->contextAdd("message2", $message2);
     $oe->contextAdd('name', $inv->getName());
     $oe->setBodyTemplate('MembershipEmailInvitation');
     $res = $oe->send();
     if (!$res) {
         throw new ProcessException("Email to this recipient could not be sent for some reason.");
     }
     $inv->setAttempts($inv->getAttempts() + 1);
     $inv->save();
     $db->commit();
 }
Exemplo n.º 2
0
 public function handleUser($user)
 {
     $db = Database::connection();
     $db->begin();
     $c = new Criteria();
     $c->add("user_id", $user->getUserId());
     $c->add("notify_email", true);
     $c->addOrderAscending("notification_id");
     $nots = DB_NotificationPeer::instance()->select($c);
     if (count($nots) == 0) {
         $db->commit();
         return;
     }
     if (count($nots) > 0) {
         $q = "UPDATE notification SET notify_email=FALSE " . "WHERE user_id='" . $user->getUserId() . "' AND " . "notify_email = TRUE";
         $db->query($q);
     }
     // set language
     $lang = $user->getLanguage();
     OZONE::getRunData()->setLanguage($lang);
     $GLOBALS['lang'] = $lang;
     // and for gettext too:
     switch ($lang) {
         case 'pl':
             $glang = "pl_PL";
             break;
         case 'en':
             $glang = "en_US";
             break;
     }
     putenv("LANG={$glang}");
     putenv("LANGUAGE={$glang}");
     setlocale(LC_ALL, $glang . '.UTF-8');
     $nots2 = array();
     foreach ($nots as &$not) {
         if ($not->getType() == "new_private_message") {
             // check if the message is read or still new
             $extra = $not->getExtra();
             $pm = DB_PrivateMessagePeer::instance()->selectByPrimaryKey($extra['message_id']);
             if ($pm && $pm->getFlagNew()) {
                 $body = $not->getBody();
                 $body = preg_replace('/<br\\/>Preview.*$/sm', '', $body);
                 $body = preg_replace(';You have.*?<br/>;sm', '', $body);
                 $not->setBody($body);
                 $nots2[] = $not;
             }
         } else {
             $nots2[] = $not;
         }
     }
     $count = count($nots2);
     // now send an email
     $oe = new OzoneEmail();
     $oe->addAddress($user->getName());
     $oe->setSubject(sprintf(_("%s Account Notifications"), GlobalProperties::$SERVICE_NAME));
     $oe->contextAdd('user', $user);
     $oe->contextAdd('notifications', $nots2);
     $oe->contextAdd('count', $count);
     $oe->setBodyTemplate('DigestEmail');
     if (!$oe->send()) {
         throw new ProcessException("The email can not be sent to address " . $user->getName(), "email_failed");
     }
     $db->commit();
 }