Inheritance: extends Swift_Message
コード例 #1
0
 /**
  * On NotImplementedUnsubscribedEvent
  *
  * @param NotImplementedUnsubscribedEvent $event
  */
 public function onNotImplementedUnsubscribedEvent(NotImplementedUnsubscribedEvent $event)
 {
     // define title
     $title = sprintf(Language::lbl('MailTitleUnsubscribeSubscriber'), $event->getUnsubscription()->email, strtoupper($event->getUnsubscription()->language));
     // define sender/receiver(s)
     $to = $this->modulesSettings->get('Core', 'mailer_to');
     $from = $this->modulesSettings->get('Core', 'mailer_from');
     $replyTo = $this->modulesSettings->get('Core', 'mailer_reply_to');
     // define message
     $message = Message::newInstance($title)->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.html.twig', array('message' => $title), true);
     // send mail
     $this->mailer->send($message);
 }
コード例 #2
0
 /**
  * @param FormBuilderSubmittedEvent $event
  */
 public function onFormSubmitted(FormBuilderSubmittedEvent $event)
 {
     $form = $event->getForm();
     // need to send mail
     if ($form['method'] == 'database_email') {
         // build our message
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $fieldData = $this->getEmailFields($event->getData());
         $message = \Common\Mailer\Message::newInstance(sprintf(FL::getMessage('FormBuilderSubject'), $form['name']))->parseHtml(FRONTEND_MODULES_PATH . '/FormBuilder/Layout/Templates/Mails/Form.tpl', array('sentOn' => time(), 'name' => $form['name'], 'fields' => $fieldData), true)->setTo($form['email'])->setFrom(array($from['email'] => $from['name']));
         // check if we have a replyTo email set
         foreach ($form['fields'] as $field) {
             if (array_key_exists('reply_to', $field['settings']) && $field['settings']['reply_to'] === true) {
                 $email = $fieldData[$field['id']]['value'];
                 $message->setReplyTo(array($email => $email));
             }
         }
         if ($message->getReplyTo() === null) {
             $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
             $message->setReplyTo(array($replyTo['email'] => $replyTo['name']));
         }
         $this->mailer->send($message);
     }
 }
コード例 #3
0
ファイル: Index.php プロジェクト: bwgraves/forkcms
 /**
  * Validate the forms
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $txtEmail = $this->frm->getField('backend_email');
         $txtPassword = $this->frm->getField('backend_password');
         // required fields
         if (!$txtEmail->isFilled() || !$txtPassword->isFilled()) {
             // add error
             $this->frm->addError('fields required');
             // show error
             $this->tpl->assign('hasError', true);
         }
         $this->getContainer()->get('logger')->info("Trying to authenticate user '{$txtEmail->getValue()}'.");
         // invalid form-token?
         if ($this->frm->getToken() != $this->frm->getField('form_token')->getValue()) {
             // set a correct header, so bots understand they can't mess with us.
             if (!headers_sent()) {
                 header('400 Bad Request', true, 400);
             }
         }
         // get the user's id
         $userId = BackendUsersModel::getIdByEmail($txtEmail->getValue());
         // all fields are ok?
         if ($txtEmail->isFilled() && $txtPassword->isFilled() && $this->frm->getToken() == $this->frm->getField('form_token')->getValue()) {
             // try to login the user
             if (!BackendAuthentication::loginUser($txtEmail->getValue(), $txtPassword->getValue())) {
                 $this->getContainer()->get('logger')->info("Failed authenticating user '{$txtEmail->getValue()}'.");
                 // add error
                 $this->frm->addError('invalid login');
                 // store attempt in session
                 $current = \SpoonSession::exists('backend_login_attempts') ? (int) \SpoonSession::get('backend_login_attempts') : 0;
                 // increment and store
                 \SpoonSession::set('backend_login_attempts', ++$current);
                 // save the failed login attempt in the user's settings
                 if ($userId !== false) {
                     BackendUsersModel::setSetting($userId, 'last_failed_login_attempt', time());
                 }
                 // show error
                 $this->tpl->assign('hasError', true);
             }
         }
         // check sessions
         if (\SpoonSession::exists('backend_login_attempts') && (int) \SpoonSession::get('backend_login_attempts') >= 5) {
             // get previous attempt
             $previousAttempt = \SpoonSession::exists('backend_last_attempt') ? \SpoonSession::get('backend_last_attempt') : time();
             // calculate timeout
             $timeout = 5 * (\SpoonSession::get('backend_login_attempts') - 4);
             // too soon!
             if (time() < $previousAttempt + $timeout) {
                 // sleep until the user can login again
                 sleep($timeout);
                 // set a correct header, so bots understand they can't mess with us.
                 if (!headers_sent()) {
                     header('503 Service Unavailable', true, 503);
                 }
             } else {
                 // increment and store
                 \SpoonSession::set('backend_last_attempt', time());
             }
             // too many attempts
             $this->frm->addEditor('too many attempts');
             $this->getContainer()->get('logger')->info("Too many login attempts for user '{$txtEmail->getValue()}'.");
             // show error
             $this->tpl->assign('hasTooManyAttemps', true);
             $this->tpl->assign('hasError', false);
         }
         // no errors in the form?
         if ($this->frm->isCorrect()) {
             // cleanup sessions
             \SpoonSession::delete('backend_login_attempts');
             \SpoonSession::delete('backend_last_attempt');
             // save the login timestamp in the user's settings
             $lastLogin = BackendUsersModel::getSetting($userId, 'current_login');
             BackendUsersModel::setSetting($userId, 'current_login', time());
             if ($lastLogin) {
                 BackendUsersModel::setSetting($userId, 'last_login', $lastLogin);
             }
             $this->getContainer()->get('logger')->info("Successfully authenticated user '{$txtEmail->getValue()}'.");
             // redirect to the correct URL (URL the user was looking for or fallback)
             $this->redirectToAllowedModuleAndAction();
         }
     }
     // is the form submitted
     if ($this->frmForgotPassword->isSubmitted()) {
         // backend email
         $email = $this->frmForgotPassword->getField('backend_email_forgot')->getValue();
         // required fields
         if ($this->frmForgotPassword->getField('backend_email_forgot')->isEmail(BL::err('EmailIsInvalid'))) {
             // check if there is a user with the given emailaddress
             if (!BackendUsersModel::existsEmail($email)) {
                 $this->frmForgotPassword->getField('backend_email_forgot')->addError(BL::err('EmailIsUnknown'));
             }
         }
         // no errors in the form?
         if ($this->frmForgotPassword->isCorrect()) {
             // generate the key for the reset link and fetch the user ID for this email
             $key = BackendAuthentication::getEncryptedString($email, uniqid());
             // insert the key and the timestamp into the user settings
             $userId = BackendUsersModel::getIdByEmail($email);
             $user = new User($userId);
             $user->setSetting('reset_password_key', $key);
             $user->setSetting('reset_password_timestamp', time());
             // variables to parse in the e-mail
             $variables['resetLink'] = SITE_URL . BackendModel::createURLForAction('ResetPassword') . '&email=' . $email . '&key=' . $key;
             // send e-mail to user
             $from = $this->get('fork.settings')->get('Core', 'mailer_from');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = \Common\Mailer\Message::newInstance(\SpoonFilter::ucfirst(BL::msg('ResetYourPasswordMailSubject')))->setFrom(array($from['email'] => $from['name']))->setTo(array($email))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(BACKEND_MODULES_PATH . '/Authentication/Layout/Templates/Mails/ResetPassword.tpl', $variables);
             $this->get('mailer')->send($message);
             // clear post-values
             $_POST['backend_email_forgot'] = '';
             // show success message
             $this->tpl->assign('isForgotPasswordSuccess', true);
             // show form
             $this->tpl->assign('showForm', true);
         } else {
             // errors?
             $this->tpl->assign('showForm', true);
         }
     }
 }
コード例 #4
0
ファイル: Register.php プロジェクト: newaltcoin/forkcms
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtDisplayName = $this->frm->getField('display_name');
         $txtEmail = $this->frm->getField('email');
         $txtPassword = $this->frm->getField('password');
         // check email
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email already exists?
                 if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     // set error
                     $txtEmail->setError(FL::getError('EmailExists'));
                 }
             }
         }
         // check password
         $txtPassword->isFilled(FL::getError('PasswordIsRequired'));
         // no errors
         if ($this->frm->isCorrect()) {
             // init values
             $settings = array();
             $values = array();
             // generate salt
             $settings['salt'] = FrontendProfilesModel::getRandomString();
             $settings['language'] = FRONTEND_LANGUAGE;
             // values
             $values['email'] = $txtEmail->getValue();
             $values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $settings['salt']);
             $values['status'] = 'inactive';
             $values['display_name'] = $txtDisplayName->getValue();
             $values['registered_on'] = FrontendModel::getUTCDate();
             $values['last_login'] = FrontendModel::getUTCDate(null, 0);
             /*
              * Add a profile.
              * We use a try-catch statement to catch errors when more users sign up simultaneously.
              */
             try {
                 // insert profile
                 $profileId = FrontendProfilesModel::insert($values);
                 // use the profile id as url until we have an actual url
                 FrontendProfilesModel::update($profileId, array('url' => FrontendProfilesModel::getUrl($values['display_name'])));
                 // trigger event
                 FrontendModel::triggerEvent('Profiles', 'after_register', array('id' => $profileId));
                 // generate activation key
                 $settings['activation_key'] = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $settings['salt']);
                 // set settings
                 FrontendProfilesModel::setSettings($profileId, $settings);
                 // login
                 FrontendProfilesAuthentication::login($profileId);
                 // activation URL
                 $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Activate') . '/' . $settings['activation_key'];
                 // send email
                 $from = $this->get('fork.settings')->get('Core', 'mailer_from');
                 $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
                 $message = \Common\Mailer\Message::newInstance(FL::getMessage('RegisterSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Profiles/Layout/Templates/Mails/Register.tpl', $mailValues, true);
                 $this->get('mailer')->send($message);
                 // redirect
                 $this->redirect(SITE_URL . '/' . $this->URL->getQueryString() . '?sent=true');
             } catch (\Exception $e) {
                 // when debugging we need to see the exceptions
                 if ($this->getContainer()->getParameter('kernel.debug')) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('registerHasFormError', true);
             }
         } else {
             $this->tpl->assign('registerHasFormError', true);
         }
     }
 }
コード例 #5
0
ファイル: Model.php プロジェクト: bwgraves/forkcms
 /**
  * Notify the admin
  *
  * @param array $comment The comment that was submitted.
  */
 public static function notifyAdmin(array $comment)
 {
     // don't notify admin in case of spam
     if ($comment['status'] == 'spam') {
         return;
     }
     // build data for push notification
     if ($comment['status'] == 'moderation') {
         $key = 'BLOG_COMMENT_MOD';
     } else {
         $key = 'BLOG_COMMENT';
     }
     $author = $comment['author'];
     if (mb_strlen($author) > 20) {
         $author = mb_substr($author, 0, 19) . '…';
     }
     $text = $comment['text'];
     if (mb_strlen($text) > 50) {
         $text = mb_substr($text, 0, 49) . '…';
     }
     $alert = array('loc-key' => $key, 'loc-args' => array($author, $text));
     // build data
     $data = array('api' => SITE_URL . '/api/1.0', 'id' => $comment['id']);
     // push it
     FrontendModel::pushToAppleApp($alert, null, 'default', $data);
     // get settings
     $notifyByMailOnComment = FrontendModel::get('fork.settings')->get('Blog', 'notify_by_email_on_new_comment', false);
     $notifyByMailOnCommentToModerate = FrontendModel::get('fork.settings')->get('Blog', 'notify_by_email_on_new_comment_to_moderate', false);
     // create URLs
     $URL = SITE_URL . FrontendNavigation::getURLForBlock('Blog', 'Detail') . '/' . $comment['post_url'] . '#comment-' . $comment['id'];
     $backendURL = SITE_URL . FrontendNavigation::getBackendURLForBlock('comments', 'Blog') . '#tabModeration';
     // notify on all comments
     if ($notifyByMailOnComment) {
         // init var
         $variables = null;
         // comment to moderate
         if ($comment['status'] == 'moderation') {
             $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $URL, $comment['post_title'], $backendURL));
         } elseif ($comment['status'] == 'published') {
             // comment was published
             $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewComment'), array($comment['author'], $URL, $comment['post_title']));
         }
         $to = FrontendModel::get('fork.settings')->get('Core', 'mailer_to');
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
         $message = \Common\Mailer\Message::newInstance(FL::msg('NotificationSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl', $variables, true);
         FrontendModel::get('mailer')->send($message);
     } elseif ($notifyByMailOnCommentToModerate && $comment['status'] == 'moderation') {
         // only notify on new comments to moderate and if the comment is one to moderate
         // set variables
         $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $URL, $comment['post_title'], $backendURL));
         $to = FrontendModel::get('fork.settings')->get('Core', 'mailer_to');
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
         $message = \Common\Mailer\Message::newInstance(FL::msg('NotificationSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl', $variables, true);
         FrontendModel::get('mailer')->send($message);
     }
 }
コード例 #6
0
ファイル: Model.php プロジェクト: forkcms/forkcms
 /**
  * Notify the admin
  *
  * @param array $comment The comment that was submitted.
  */
 public static function notifyAdmin(array $comment)
 {
     // don't notify admin in case of spam
     if ($comment['status'] == 'spam') {
         return;
     }
     // get settings
     $notifyByMailOnComment = FrontendModel::get('fork.settings')->get('Blog', 'notify_by_email_on_new_comment', false);
     $notifyByMailOnCommentToModerate = FrontendModel::get('fork.settings')->get('Blog', 'notify_by_email_on_new_comment_to_moderate', false);
     // create URLs
     $url = SITE_URL . FrontendNavigation::getURLForBlock('Blog', 'Detail') . '/' . $comment['post_url'] . '#comment-' . $comment['id'];
     $backendURL = SITE_URL . FrontendNavigation::getBackendURLForBlock('comments', 'Blog') . '#tabModeration';
     // notify on all comments
     if ($notifyByMailOnComment) {
         // init var
         $variables = null;
         // comment to moderate
         if ($comment['status'] == 'moderation') {
             $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $url, $comment['post_title'], $backendURL));
         } elseif ($comment['status'] == 'published') {
             // comment was published
             $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewComment'), array($comment['author'], $url, $comment['post_title']));
         }
         $to = FrontendModel::get('fork.settings')->get('Core', 'mailer_to');
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
         $message = Message::newInstance(FL::msg('NotificationSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Core/Layout/Templates/Mails/Notification.html.twig', $variables, true);
         FrontendModel::get('mailer')->send($message);
     } elseif ($notifyByMailOnCommentToModerate && $comment['status'] == 'moderation') {
         // only notify on new comments to moderate and if the comment is one to moderate
         // set variables
         $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $url, $comment['post_title'], $backendURL));
         $to = FrontendModel::get('fork.settings')->get('Core', 'mailer_to');
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $replyTo = FrontendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
         $message = Message::newInstance(FL::msg('NotificationSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Core/Layout/Templates/Mails/Notification.html.twig', $variables, true);
         FrontendModel::get('mailer')->send($message);
     }
 }
コード例 #7
0
ファイル: Model.php プロジェクト: Comsa-Veurne/modules
 public static function sendMail($subject, $text, $email_receipient, $name_receipient, $mail)
 {
     $message = \Common\Mailer\Message::newInstance($subject);
     $message->setTo(array($email_receipient => \SpoonFilter::isEmail($name_receipient) ? null : $name_receipient));
     $message->setFrom(array($mail['from_email'] => $mail['from_name']));
     $message->setReplyTo(array($mail['reply_email'] => $mail['reply_name']));
     $message->setBody($text, 'text/html');
     $message->addPart(strip_tags($text));
     $message->setCharset(SPOON_CHARSET);
     BackendModel::get('mailer')->send($message);
     // mailer type
     //		$mailerType = BackendModel::getModuleSetting('Core', 'mailer_type', 'mail');
     //
     //		// create new SpoonEmail-instance
     //		$email = new \SpoonEmail();
     //		$email->setTemplateCompileDirectory(BACKEND_CACHE_PATH . '/compiled_templates');
     //
     //		// send via SMTP
     //		if($mailerType == 'smtp')
     //		{
     //
     //
     //			// get settings
     //			$SMTPServer = BackendModel::getModuleSetting('Core', 'smtp_server');
     //			$SMTPPort = BackendModel::getModuleSetting('Core', 'smtp_port', 25);
     //			$SMTPUsername = BackendModel::getModuleSetting('Core', 'smtp_username');
     //			$SMTPPassword = BackendModel::getModuleSetting('Core', 'smtp_password');
     //
     //			// set server and connect with SMTP
     //			$email->setSMTPConnection($SMTPServer, $SMTPPort, 10);
     //
     //			// set authentication if needed
     //			if($SMTPUsername !== null && $SMTPPassword !== null) $email->setSMTPAuth($SMTPUsername, $SMTPPassword);
     //		}
     //
     //		// set some properties
     //		$email->setFrom($mail['from_email'], $mail['from_name']);
     //
     //		//--If the receipient name is an email, set name to null
     //		if(\SpoonFilter::isEmail($name_receipient))
     //		{
     //			$name_receipient = null;
     //		}
     //
     //		$email->addRecipient($email_receipient, $name_receipient);
     //		$email->setReplyTo($mail['reply_email'], $mail['reply_name']);
     //		$email->setSubject($subject);
     //		$email->setHTMLContent($text);
     //		$email->setCharset(SPOON_CHARSET);
     //		$email->setContentTransferEncoding('base64');
     //		$email->setPlainContent();
     // send the email
     //		return $email->send();
 }
コード例 #8
0
ファイル: AskOwnQuestion.php プロジェクト: bwgraves/forkcms
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate required fields
         $this->frm->getField('name')->isFilled(FL::err('NameIsRequired'));
         $this->frm->getField('email')->isEmail(FL::err('EmailIsInvalid'));
         $this->frm->getField('message')->isFilled(FL::err('QuestionIsRequired'));
         if ($this->frm->isCorrect()) {
             $spamFilterEnabled = $this->get('fork.settings')->get('Faq', 'spamfilter');
             $variables['sentOn'] = time();
             $variables['name'] = $this->frm->getField('name')->getValue();
             $variables['email'] = $this->frm->getField('email')->getValue();
             $variables['message'] = $this->frm->getField('message')->getValue();
             if ($spamFilterEnabled) {
                 // if the comment is spam alter the comment status so it will appear in the spam queue
                 if (FrontendModel::isSpam($variables['message'], SITE_URL . FrontendNavigation::getURLForBlock('Faq'), $variables['name'], $variables['email'])) {
                     $this->status = 'errorSpam';
                     return;
                 }
             }
             $from = $this->get('fork.settings')->get('Core', 'mailer_from');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = \Common\Mailer\Message::newInstance(sprintf(FL::getMessage('FaqOwnQuestionSubject'), $variables['name']))->setFrom(array($from['email'] => $from['name']))->setTo(array($variables['email'] => $variables['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Faq/Layout/Templates/Mails/OwnQuestion.tpl', $variables, true);
             $this->get('mailer')->send($message);
             $this->status = 'success';
         }
     }
 }
コード例 #9
0
ファイル: Model.php プロジェクト: forkcms/forkcms
 /**
  * Send mail
  *
  * @param string $subject
  * @param string $templatePath
  * @param array $variables
  * @param string $toEmail
  * @param string $toDisplayName
  */
 protected static function sendMail($subject, $templatePath = null, $variables, $toEmail, $toDisplayName = null)
 {
     if (empty($templatePath)) {
         $templatePath = FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.html.twig';
     }
     // define variables
     $from = BackendModel::get('fork.settings')->get('Core', 'mailer_from');
     $replyTo = BackendModel::get('fork.settings')->get('Core', 'mailer_reply_to');
     // create a message object and set all the needed properties
     $message = Message::newInstance($subject)->setFrom(array($from['email'] => $from['name']))->setTo(array($toEmail => $toDisplayName))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml($templatePath, $variables, true);
     // send it through the mailer service
     BackendModel::get('mailer')->send($message);
 }
コード例 #10
0
ファイル: Model.php プロジェクト: Comsa-Veurne/modules
 /**
  * Notify the admin
  *
  * @param array $subscription The subscription that was submitted.
  */
 public static function notifyAdmin(array $subscription)
 {
     // don't notify admin in case of spam
     if ($subscription['status'] == 'spam') {
         return;
     }
     // build data for push notification
     if ($subscription['status'] == 'moderation') {
         $key = 'AGENDA_SUBSCRIPTION_MOD';
     } else {
         $key = 'AGENDA_SUBSCRIPTION';
     }
     $name = $subscription['name'];
     if (mb_strlen($name) > 20) {
         $name = mb_substr($name, 0, 19) . '…';
     }
     $alert = array('loc-key' => $key, 'loc-args' => array($name));
     // build data
     $data = array('api' => SITE_URL . '/api/1.0', 'id' => $subscription['id']);
     // push it
     FrontendModel::pushToAppleApp($alert, null, 'default', $data);
     // get settings
     $notifyByMailOnSubscription = FrontendModel::get('fork.settings')->get('Agenda', 'notify_by_email_on_new_subscription', false);
     $notifyByMailOnSubscription = FrontendModel::get('fork.settings')->get('Agenda', 'notify_by_email_on_new_subscription_to_moderate', false);
     // create URLs
     $backendURL = SITE_URL . FrontendNavigation::getBackendURLForBlock('subscriptions', 'agenda') . '#tabModeration';
     // notify on all comments
     if ($notifyByMailOnSubscription) {
         // init var
         $message = null;
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         if ($subscription['status'] == 'moderation') {
             $message = \Common\Mailer\Message::newInstance(FL::msg('NotificationSubject'))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl', array('message' => vsprintf(FL::msg('AgendaEmailNotificationsNewSubscriptionToModerate'), array($subscription['name'], $subscription['agenda_title'], $backendURL))), true)->setTo('*****@*****.**')->setFrom(array($from['email'] => $from['name']));
         } elseif ($subscription['status'] == 'published') {
             $message = \Common\Mailer\Message::newInstance(FL::msg('NotificationSubject'))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl', array('message' => vsprintf(FL::msg('AgendaEmailNotificationsNewSubscription'), array($subscription['name'], $subscription['agenda_title']))), true)->setTo('*****@*****.**')->setFrom(array($from['email'] => $from['name']));
         }
         FrontendModel::get('mailer')->send($message);
         // send the mail
         //            FrontendModel::get('mailer')->addEmail(
         //                FL::msg('NotificationSubject'),
         //                FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl',
         //                $variables,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                true
         //            );
     } elseif ($notifyByMailOnSubscriptionToModerate && $subscription['status'] == 'moderation') {
         $message = null;
         $from = FrontendModel::get('fork.settings')->get('Core', 'mailer_from');
         $message = \Common\Mailer\Message::newInstance(FL::msg('NotificationSubject'))->parseHtml(FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl', array('message' => vsprintf(FL::msg('AgendaEmailNotificationsNewSubscriptionToModerate'), array($subscription['name'], $subscription['agenda_title'], $backendURL))), true)->setTo('*****@*****.**')->setFrom(array($from['email'] => $from['name']));
         FrontendModel::get('mailer')->send($message);
         // set variables
         //            $variables['message'] = vsprintf(FL::msg('AgendaEmailNotificationsNewSubscriptionToModerate'),
         //                array($subscription['name'], $subscription['agenda_title'], $backendURL));
         //
         //            // send the mail
         //            FrontendModel::get('mailer')->addEmail(
         //                FL::msg('NotificationSubject'),
         //                FRONTEND_CORE_PATH . '/Layout/Templates/Mails/Notification.tpl',
         //                $variables,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                null,
         //                true
         //            );
     }
 }
コード例 #11
0
ファイル: ResendActivation.php プロジェクト: forkcms/forkcms
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get field
         $txtEmail = $this->frm->getField('email');
         // field is filled in?
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email exists?
                 if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     // get profile id using the filled in email
                     $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
                     // get profile
                     $profile = FrontendProfilesModel::get($profileId);
                     // must be inactive
                     if ($profile->getStatus() != FrontendProfilesAuthentication::LOGIN_INACTIVE) {
                         $txtEmail->addError(FL::getError('ProfileIsActive'));
                     }
                 } else {
                     // email don't exist
                     $txtEmail->addError(FL::getError('EmailIsInvalid'));
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // activation URL
             $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Activate') . '/' . $profile->getSetting('activation_key');
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_resend_activation', array('id' => $profileId));
             // send email
             $from = $this->get('fork.settings')->get('Core', 'mailer_from');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = Message::newInstance(FL::getMessage('RegisterSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($profile->getEmail() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Profiles/Layout/Templates/Mails/Register.html.twig', $mailValues, true);
             $this->get('mailer')->send($message);
             // redirect
             $this->redirect(SITE_URL . $this->URL->getQueryString() . '?sent=true');
         } else {
             $this->tpl->assign('resendActivationHasError', true);
         }
     }
 }
コード例 #12
0
ファイル: Detail.php プロジェクト: Comsa-Veurne/modules
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // get settings
     $commentsAllowed = isset($this->settings['allow_comments']) && $this->settings['allow_comments'];
     // comments aren't allowed so we don't have to validate
     if (!$commentsAllowed) {
         return false;
     }
     if ($this->frmContact->isSubmitted()) {
         //--Clean fields
         $this->frmContact->cleanUpFields();
         //--Get the fields
         $fields = $this->frmContact->getFields();
         //--Check if the fields are filled in
         $fields['name']->isFilled(FL::err('NameIsRequired'));
         $fields['emailContact']->isEmail(FL::err('EmailIsRequired'));
         //--Check if frm is correct
         if ($this->frmContact->isCorrect()) {
             //--Create variable array
             $arrVariables["sentOn"] = time();
             $arrVariables["product"] = $this->record['title'];
             $arrVariables["name"] = $fields['name']->getValue();
             $arrVariables["email"] = $fields['emailContact']->getValue();
             $arrVariables["phone"] = $fields['phone']->getValue();
             $arrVariables["message"] = nl2br($fields['messageContact']->getValue());
             $message = \Common\Mailer\Message::newInstance(FL::getMessage('Contact') . ": " . $this->record['title']);
             $message->parseHtml(FRONTEND_MODULES_PATH . '/Catalog/Layout/Templates/Mails/Contact.tpl', $arrVariables, true);
             //                $message->setTo(array('*****@*****.**'));
             $message->setTo(array('*****@*****.**'));
             $message->setFrom(array($arrVariables["email"] => $arrVariables['name']));
             $this->get('mailer')->send($message);
             $this->tpl->assign("showContactSend", true);
         }
     }
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // does the key exists?
         if (\SpoonSession::exists('catalog_comment_' . $this->record['id'])) {
             // calculate difference
             $diff = time() - (int) \SpoonSession::get('catalog_comment_' . $this->record['id']);
             // calculate difference, it it isn't 10 seconds the we tell the user to slow down
             if ($diff < 10 && $diff != 0) {
                 $this->frm->getField('message')->addError(FL::err('CommentTimeout'));
             }
         }
         // validate required fields
         $this->frm->getField('author')->isFilled(FL::err('AuthorIsRequired'));
         $this->frm->getField('email')->isEmail(FL::err('EmailIsRequired'));
         $this->frm->getField('message')->isFilled(FL::err('MessageIsRequired'));
         // validate optional fields
         if ($this->frm->getField('website')->isFilled() && $this->frm->getField('website')->getValue() != 'http://') {
             $this->frm->getField('website')->isURL(FL::err('InvalidURL'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // get module setting
             $spamFilterEnabled = isset($this->settings['spamfilter']) && $this->settings['spamfilter'];
             $moderationEnabled = isset($this->settings['moderation']) && $this->settings['moderation'];
             // reformat data
             $author = $this->frm->getField('author')->getValue();
             $email = $this->frm->getField('email')->getValue();
             $website = $this->frm->getField('website')->getValue();
             if (trim($website) == '' || $website == 'http://') {
                 $website = null;
             }
             $text = $this->frm->getField('message')->getValue();
             // build array
             $comment['product_id'] = $this->record['id'];
             $comment['language'] = FRONTEND_LANGUAGE;
             $comment['created_on'] = FrontendModel::getUTCDate();
             $comment['author'] = $author;
             $comment['email'] = $email;
             $comment['website'] = $website;
             $comment['text'] = $text;
             $comment['status'] = 'published';
             $comment['data'] = serialize(array('server' => $_SERVER));
             // get URL for article
             $permaLink = $this->record['full_url'];
             $redirectLink = $permaLink;
             // is moderation enabled
             if ($moderationEnabled) {
                 // if the commenter isn't moderated before alter the comment status so it will appear in the moderation queue
                 if (!FrontendCatalogModel::isModerated($author, $email)) {
                     $comment['status'] = 'moderation';
                 }
             }
             // should we check if the item is spam
             if ($spamFilterEnabled) {
                 // check for spam
                 $result = FrontendModel::isSpam($text, SITE_URL . $permaLink, $author, $email, $website);
                 // if the comment is spam alter the comment status so it will appear in the spam queue
                 if ($result) {
                     $comment['status'] = 'spam';
                 } elseif ($result == 'unknown') {
                     $comment['status'] = 'moderation';
                 }
             }
             // insert comment
             $comment['id'] = FrontendCatalogModel::insertComment($comment);
             // trigger event
             FrontendModel::triggerEvent('catalog', 'after_add_comment', array('comment' => $comment));
             // append a parameter to the URL so we can show moderation
             if (strpos($redirectLink, '?') === false) {
                 if ($comment['status'] == 'moderation') {
                     $redirectLink .= '?comment=moderation#' . FL::act('Comment');
                 }
                 if ($comment['status'] == 'spam') {
                     $redirectLink .= '?comment=spam#' . FL::act('Comment');
                 }
                 if ($comment['status'] == 'published') {
                     $redirectLink .= '?comment=true#comment-' . $comment['id'];
                 }
             } else {
                 if ($comment['status'] == 'moderation') {
                     $redirectLink .= '&comment=moderation#' . FL::act('Comment');
                 }
                 if ($comment['status'] == 'spam') {
                     $redirectLink .= '&comment=spam#' . FL::act('Comment');
                 }
                 if ($comment['status'] == 'published') {
                     $redirectLink .= '&comment=true#comment-' . $comment['id'];
                 }
             }
             // set title
             $comment['product_title'] = $this->record['title'];
             $comment['product_url'] = $this->record['url'];
             // notify the admin
             FrontendCatalogModel::notifyAdmin($comment);
             // store timestamp in session so we can block excessive usage
             \SpoonSession::set('catalog_comment_' . $this->record['id'], time());
             // store author-data in cookies
             try {
                 Cookie::set('comment_author', $author);
                 Cookie::set('comment_email', $email);
                 Cookie::set('comment_website', $website);
             } catch (Exception $e) {
                 // settings cookies isn't allowed, but because this isn't a real problem we ignore the exception
             }
             // redirect
             $this->redirect($redirectLink);
         }
     }
 }
コード例 #13
0
ファイル: Detail.php プロジェクト: forkcms/forkcms
 /**
  * Validate the form
  */
 private function validateForm()
 {
     $feedbackAllowed = isset($this->settings['allow_feedback']) && $this->settings['allow_feedback'];
     if (!$feedbackAllowed) {
         return false;
     }
     if ($this->frm->isSubmitted()) {
         // reformat data
         $useful = $this->frm->getField('useful')->getValue() == 'Y';
         // the form has been sent
         $this->tpl->assign('hideFeedbackNoInfo', $useful);
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate required fields
         if (!$useful) {
             $this->frm->getField('message')->isFilled(FL::err('FeedbackIsRequired'));
         }
         if ($this->frm->isCorrect()) {
             // reformat data
             $text = $this->frm->getField('message')->getValue();
             // get feedback in session
             $previousFeedback = \SpoonSession::exists('faq_feedback_' . $this->record['id']) ? \SpoonSession::get('faq_feedback_' . $this->record['id']) : null;
             // update counters
             FrontendFaqModel::updateFeedback($this->record['id'], $useful, $previousFeedback);
             // save feedback in session
             \SpoonSession::set('faq_feedback_' . $this->record['id'], $useful);
             // answer is yes so there's no feedback
             if (!$useful) {
                 // get module setting
                 $spamFilterEnabled = isset($this->settings['spamfilter']) && $this->settings['spamfilter'];
                 // build array
                 $variables['question_id'] = $this->record['id'];
                 $variables['sentOn'] = time();
                 $variables['text'] = $text;
                 // should we check if the item is spam
                 if ($spamFilterEnabled) {
                     // the comment is spam
                     if (FrontendModel::isSpam($text, $variables['question_link'])) {
                         // set the status to spam
                         $this->redirect($this->record['full_url'] . '/' . FL::getAction('Spam'));
                     }
                 }
                 // save the feedback
                 FrontendFaqModel::saveFeedback($variables);
                 // send email on new feedback?
                 if ($this->get('fork.settings')->get('Faq', 'send_email_on_new_feedback')) {
                     // add the question
                     $variables['question'] = $this->record['question'];
                     $to = $this->get('fork.settings')->get('Core', 'mailer_to');
                     $from = $this->get('fork.settings')->get('Core', 'mailer_from');
                     $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
                     $message = Message::newInstance(sprintf(FL::getMessage('FaqFeedbackSubject'), $this->record['question']))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Faq/Layout/Templates/Mails/Feedback.html.twig', $variables, true);
                     $this->get('mailer')->send($message);
                 }
             }
             // trigger event
             FrontendModel::triggerEvent('Faq', 'after_add_feedback', array('comment' => $text));
             // save status
             $this->redirect($this->record['full_url'] . '/' . FL::getAction('Success'));
         }
     } else {
         // form hasn't been sent
         $this->tpl->assign('hideFeedbackNoInfo', true);
     }
 }
コード例 #14
0
ファイル: ForgotPassword.php プロジェクト: bwgraves/forkcms
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get field
         $txtEmail = $this->frm->getField('email');
         // field is filled in?
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email exists?
                 if (!FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     $txtEmail->addError(FL::getError('EmailIsUnknown'));
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // get profile id
             $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
             // generate forgot password key
             $key = FrontendProfilesModel::getEncryptedString($profileId . microtime(), FrontendProfilesModel::getRandomString());
             // insert forgot password key
             FrontendProfilesModel::setSetting($profileId, 'forgot_password_key', $key);
             // reset url
             $mailValues['resetUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ResetPassword') . '/' . $key;
             $mailValues['firstName'] = FrontendProfilesModel::getSetting($profileId, 'first_name');
             $mailValues['lastName'] = FrontendProfilesModel::getSetting($profileId, 'last_name');
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_forgot_password', array('id' => $profileId));
             // send email
             $from = $this->get('fork.settings')->get('Core', 'mailer_from');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = \Common\Mailer\Message::newInstance(FL::getMessage('ForgotPasswordSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Profiles/Layout/Templates/Mails/ForgotPassword.tpl', $mailValues, true);
             $this->get('mailer')->send($message);
             // redirect
             $this->redirect(SITE_URL . '/' . $this->URL->getQueryString() . '?sent=true');
         } else {
             $this->tpl->assign('forgotPasswordHasError', true);
         }
     }
 }