getMessage() public static method

Get a message from the language-file
public static getMessage ( string $key, boolean $fallback = true ) : string
$key string The key to get.
$fallback boolean Should we provide a fallback in English?
return string
 /**
  * @param FormBuilderSubmittedEvent $event
  */
 public function onFormSubmitted(FormBuilderSubmittedEvent $event)
 {
     $form = $event->getForm();
     // need to send mail
     if ($form['method'] == 'database_email') {
         // build our message
         $from = $this->modulesSettings->get('Core', 'mailer_from');
         $fieldData = $this->getEmailFields($event->getData());
         $message = Message::newInstance(sprintf(Language::getMessage('FormBuilderSubject'), $form['name']))->parseHtml('/FormBuilder/Layout/Templates/Mails/Form.html.twig', 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 = $this->modulesSettings->get('Core', 'mailer_reply_to');
             $message->setReplyTo(array($replyTo['email'] => $replyTo['name']));
         }
         $this->mailer->send($message);
     }
 }
Ejemplo n.º 2
0
 /**
  * Get a message from the language-file
  *
  * @param string $key      The key to get.
  * @param bool   $fallback Should we provide a fallback in English?
  *
  * @return string
  */
 public static function getMessage($key, $fallback = true)
 {
     trigger_error('Frontend\\Core\\Engine\\Language is deprecated.
          It has been moved to Frontend\\Core\\Language\\Language', E_USER_DEPRECATED);
     return parent::getMessage($key, $fallback);
 }
Ejemplo n.º 3
0
 /**
  * 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'));
         $txtDisplayName->isFilled(FL::getError('FieldIsRequired'));
         // no errors
         if ($this->frm->isCorrect()) {
             // init values
             $settings = array();
             $values = array();
             // generate salt
             $settings['salt'] = FrontendProfilesModel::getRandomString();
             $settings['language'] = 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 = Message::newInstance(FL::getMessage('RegisterSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->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');
             } catch (\Exception $e) {
                 // make sure RedirectExceptions get thrown
                 if ($e instanceof RedirectException) {
                     throw $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);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * 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);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * 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);
     }
 }
Ejemplo n.º 6
0
 /**
  * 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');
             $to = $this->get('fork.settings')->get('Core', 'mailer_to');
             $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
             $message = Message::newInstance(sprintf(FL::getMessage('FaqOwnQuestionSubject'), $variables['name']))->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Faq/Layout/Templates/Mails/OwnQuestion.html.twig', $variables, true);
             $this->get('mailer')->send($message);
             $this->status = 'success';
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * 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 = Message::newInstance(FL::getMessage('ForgotPasswordSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml('/Profiles/Layout/Templates/Mails/ForgotPassword.html.twig', $mailValues, true);
             $this->get('mailer')->send($message);
             // redirect
             $this->redirect(SITE_URL . $this->URL->getQueryString() . '?sent=true');
         } else {
             $this->tpl->assign('forgotPasswordHasError', true);
         }
     }
 }