Example #1
0
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // form was sent?
     if ($this->URL->getParameter('sent') == 'true') {
         // show message
         $this->tpl->assign('unsubscribeIsSuccess', true);
         // hide form
         $this->tpl->assign('unsubscribeHideForm', true);
     }
     // unsubscribe was issued for a specific group/address
     if (SpoonFilter::isEmail($this->email) && FrontendMailmotorModel::existsGroup($this->group)) {
         // unsubscribe the address from this group
         if (FrontendMailmotorModel::unsubscribe($this->email, $this->group)) {
             // hide form
             $this->tpl->assign('unsubscribeHideForm', true);
             // show message
             $this->tpl->assign('unsubscribeIsSuccess', true);
         } else {
             // show message
             $this->tpl->assign('unsubscribeHasError', true);
         }
     }
     // parse the form
     $this->frm->parse($this->tpl);
 }
Example #2
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $fields = $this->frm->getFields();
         $fields['email']->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->isCorrect()) {
             //--Get the mail
             $mailing = BackendMailengineModel::get($this->id);
             //--Get the template
             $template = BackendMailengineModel::getTemplate($mailing['template_id']);
             //--Create basic mail
             $text = BackendMailengineModel::createMail($mailing, $template);
             $mailing['from_email'] = $template['from_email'];
             $mailing['from_name'] = html_entity_decode($template['from_name']);
             $mailing['reply_email'] = $template['reply_email'];
             $mailing['reply_name'] = html_entity_decode($template['reply_name']);
             $emails = explode(',', $fields['email']->getValue());
             if (!empty($emails)) {
                 foreach ($emails as $email) {
                     $email = trim($email);
                     if (\SpoonFilter::isEmail($email)) {
                         //--Send test mailing
                         BackendMailengineModel::sendMail(html_entity_decode($mailing['subject']), $text, $email, 'Test Recepient', $mailing);
                     }
                 }
             }
             //--Redirect
             \SpoonHTTP::redirect(BackendModel::createURLForAction('index', $this->module) . "&id=" . $this->id . "&report=TestEmailSend");
         }
     }
     $this->frm->parse($this->tpl);
 }
Example #3
0
 public function setEmaUsu($emailUsuario)
 {
     if (SpoonFilter::isEmail($emailUsuario) && SpoonFilter::isSmallerThan(50, strlen($emailUsuario))) {
         $this->emaUsu = $emailUsuario;
     } else {
         echo "Ha introducido un valor Incorrecto  para el correo";
         exit;
     }
 }
 /**
  * Validates the given data
  */
 private function validateForm()
 {
     // validate
     if (!\SpoonFilter::isEmail($this->email)) {
         $this->output(self::ERROR);
     }
     if ($this->email == '') {
         $this->output(self::ERROR);
     }
 }
Example #5
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('email')->isFilled(BL::err('EmailIsRequired'));
         // get addresses
         $addresses = (array) explode(',', $this->frm->getField('email')->getValue());
         // loop addresses
         foreach ($addresses as $email) {
             // validate email
             if (!\SpoonFilter::isEmail(trim($email))) {
                 // add error if needed
                 $this->frm->getField('email')->addError(BL::err('ContainsInvalidEmail'));
                 // stop looking
                 break;
             }
         }
         $this->frm->getField('groups')->isFilled(BL::err('ChooseAtLeastOneGroup'));
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item = $this->frm->getValues();
             $item['source'] = BL::lbl('Manual');
             $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
             // loop the groups
             foreach ($item['groups'] as $group) {
                 foreach ($addresses as $email) {
                     BackendMailmotorCMHelper::subscribe(trim($email), $group);
                 }
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_address', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Addresses') . (!empty($this->groupId) ? '&group_id=' . $this->groupId : '') . '&report=added');
         }
     }
 }
Example #6
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $fromEmail = \SpoonFilter::getPostValue('mailer_from_email', null, '');
     $fromName = \SpoonFilter::getPostValue('mailer_from_name', null, '');
     $toEmail = \SpoonFilter::getPostValue('mailer_to_email', null, '');
     $toName = \SpoonFilter::getPostValue('mailer_to_name', null, '');
     $replyToEmail = \SpoonFilter::getPostValue('mailer_reply_to_email', null, '');
     $replyToName = \SpoonFilter::getPostValue('mailer_reply_to_name', null, '');
     // init validation
     $errors = array();
     // validate
     if ($fromEmail == '' || !\SpoonFilter::isEmail($fromEmail)) {
         $errors['from'] = BL::err('EmailIsInvalid');
     }
     if ($toEmail == '' || !\SpoonFilter::isEmail($toEmail)) {
         $errors['to'] = BL::err('EmailIsInvalid');
     }
     if ($replyToEmail == '' || !\SpoonFilter::isEmail($replyToEmail)) {
         $errors['reply'] = BL::err('EmailIsInvalid');
     }
     // got errors?
     if (!empty($errors)) {
         $this->output(self::BAD_REQUEST, array('errors' => $errors), 'invalid fields');
     } else {
         $message = \Swift_Message::newInstance('Test')->setFrom(array($fromEmail => $fromName))->setTo(array($toEmail => $toName))->setReplyTo(array($replyToEmail => $replyToName))->setBody(BL::msg('TestMessage'), 'text/plain');
         $transport = \Common\Mailer\TransportFactory::create(\SpoonFilter::getPostValue('mailer_type', array('smtp', 'mail'), 'mail'), \SpoonFilter::getPostValue('smtp_server', null, ''), \SpoonFilter::getPostValue('smtp_port', null, ''), \SpoonFilter::getPostValue('smtp_username', null, ''), \SpoonFilter::getPostValue('smtp_password', null, ''), \SpoonFilter::getPostValue('smtp_secure_layer', null, ''));
         $mailer = \Swift_Mailer::newInstance($transport);
         try {
             if ($mailer->send($message)) {
                 $this->output(self::OK, null, '');
             } else {
                 $this->output(self::ERROR, null, 'unknown');
             }
         } catch (\Exception $e) {
             $this->output(self::ERROR, null, $e->getMessage());
         }
     }
 }
Example #7
0
 /**
  * RCPT TO command, function that shows the host the recipients's email address.
  *
  * @return	bool
  * @param	string $email	The recipient's e-mail address.
  */
 public function rcptTo($email)
 {
     // check input
     if (!SpoonFilter::isEmail($email)) {
         throw new SpoonEmailException('No valid email given for ' . __METHOD__);
     }
     // push MAIL FROM command
     $this->say('RCPT TO: <' . $email . '>');
     // smtp code 250 means success
     return $this->repliedCode === 250 ? true : false;
 }
Example #8
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // shorten the fields
         $txtName = $this->frm->getField('name');
         $txtEmail = $this->frm->getField('email');
         $ddmMethod = $this->frm->getField('method');
         $txtSuccessMessage = $this->frm->getField('success_message');
         $txtIdentifier = $this->frm->getField('identifier');
         $emailAddresses = (array) explode(',', $txtEmail->getValue());
         // validate fields
         $txtName->isFilled(BL::getError('NameIsRequired'));
         $txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired'));
         if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') {
             $error = false;
             // check the addresses
             foreach ($emailAddresses as $address) {
                 $address = trim($address);
                 if (!SpoonFilter::isEmail($address)) {
                     $error = true;
                     break;
                 }
             }
             // add error
             if ($error) {
                 $txtEmail->addError(BL::getError('EmailIsInvalid'));
             }
         }
         // identifier
         if ($txtIdentifier->isFilled()) {
             // invalid characters
             if (!SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) {
                 $txtIdentifier->setError(BL::getError('InvalidIdentifier'));
             } elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue(), $this->id)) {
                 $txtIdentifier->setError(BL::getError('UniqueIdentifier'));
             }
         }
         if ($this->frm->isCorrect()) {
             // build array
             $values['name'] = $txtName->getValue();
             $values['method'] = $ddmMethod->getValue();
             $values['email'] = $ddmMethod->getValue() == 'database_email' ? serialize($emailAddresses) : null;
             $values['success_message'] = $txtSuccessMessage->getValue(true);
             $values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier();
             $values['edited_on'] = BackendModel::getUTCDate();
             // insert the item
             $id = (int) BackendFormBuilderModel::update($this->id, $values);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $values));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($values['name']) . '&highlight=row-' . $id);
         }
     }
 }
 public function testIsEmail()
 {
     $this->assertTrue(SpoonFilter::isEmail('*****@*****.**'));
     $this->assertTrue(SpoonFilter::isEmail('*****@*****.**'));
     $this->assertTrue(SpoonFilter::isEmail('*****@*****.**'));
     $this->assertTrue(SpoonFilter::isEmail('*****@*****.**'));
     $this->assertTrue(SpoonFilter::isEmail('*****@*****.**'));
     $this->assertTrue(SpoonFilter::isEmail('*****@*****.**'));
     $this->assertFalse(SpoonFilter::isEmail(array()));
     $this->assertFalse(SpoonFilter::isEmail(array('*****@*****.**')));
 }
Example #10
0
File: text.php Project: szLuis/oac
 /**
  * Checks this field for a valid e-mail address.
  *
  * @return	bool
  * @param	string[optional] $error		The error message to set.
  */
 public function isEmail($error = null)
 {
     // filled
     if ($this->isFilled()) {
         // post/get data
         $data = $this->getMethod(true);
         // validate
         if (!isset($data[$this->attributes['name']]) || !SpoonFilter::isEmail($data[$this->attributes['name']])) {
             if ($error !== null) {
                 $this->setError($error);
             }
             return false;
         }
         return true;
     }
     // has error
     if ($error !== null) {
         $this->setError($error);
     }
     return false;
 }
Example #11
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create form
     $this->frm = new FrontendForm('commentsForm');
     $this->frm->setAction($this->frm->getAction() . '#' . FL::act('Comment'));
     // init vars
     $author = Cookie::exists('comment_author') ? Cookie::get('comment_author') : null;
     $email = Cookie::exists('comment_email') && \SpoonFilter::isEmail(Cookie::get('comment_email')) ? Cookie::get('comment_email') : null;
     $website = Cookie::exists('comment_website') && \SpoonFilter::isURL(Cookie::get('comment_website')) ? Cookie::get('comment_website') : 'http://';
     // create elements
     $this->frm->addText('author', $author)->setAttributes(array('required' => null));
     $this->frm->addText('email', $email)->setAttributes(array('required' => null, 'type' => 'email'));
     $this->frm->addText('website', $website, null);
     $this->frm->addTextarea('message')->setAttributes(array('required' => null));
     $this->frmContact = new FrontendForm('contact', null, 'post');
     $this->frmContact->addText('name')->setAttribute('class', 'form-control');
     $this->frmContact->addText('emailContact', null, 255, 'form-control');
     //->setAttribute('class', 'form-control');
     $this->frmContact->addText('phone')->setAttribute('class', 'form-control');
     $this->frmContact->addTextarea('messageContact', Language::lbl('ProductMoreInfo') . ' ' . $this->record['title'])->setAttribute('class', 'form-control');
 }
Example #12
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create form
     $this->frm = new FrontendForm('subscriptionsForm');
     $this->frm->setAction($this->frm->getAction() . '#' . FL::act('Subscribe'));
     // init vars
     $name = Cookie::exists('subscription_author') ? Cookie::get('subscription_author') : null;
     $email = Cookie::exists('subscription_email') && \SpoonFilter::isEmail(Cookie::get('subscription_email')) ? Cookie::get('subscription_email') : null;
     // create elements
     $this->frm->addText('name', $name, 255, 'form-control')->setAttributes(array('required' => null));
     $this->frm->addText('email', $email, 255, 'form-control')->setAttributes(array('required' => null, 'type' => 'email'));
 }
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // mailer type
     $mailerType = SpoonFilter::getPostValue('mailer_type', array('smtp', 'mail'), 'mail');
     // create new SpoonEmail-instance
     $email = new SpoonEmail();
     $email->setTemplateCompileDirectory(BACKEND_CACHE_PATH . '/compiled_templates');
     // send via SMTP
     if ($mailerType == 'smtp') {
         // get settings
         $SMTPServer = SpoonFilter::getPostValue('smtp_server', null, '');
         $SMTPPort = SpoonFilter::getPostValue('smtp_port', null, '');
         $SMTPUsername = SpoonFilter::getPostValue('smtp_username', null, '');
         $SMTPPassword = SpoonFilter::getPostValue('smtp_password', null, '');
         if ($SMTPServer == '') {
             $this->output(self::BAD_REQUEST, null, BL::err('ServerIsRequired'));
         }
         if ($SMTPPort == '') {
             $this->output(self::BAD_REQUEST, null, BL::err('PortIsRequired'));
         }
         try {
             // set server and connect with SMTP
             $email->setSMTPConnection($SMTPServer, $SMTPPort, 10);
         } catch (SpoonEmailException $e) {
             $this->output(self::ERROR, null, $e->getMessage());
         }
         // set authentication if needed
         if ($SMTPUsername != '' && $SMTPPassword != '') {
             $email->setSMTPAuth($SMTPUsername, $SMTPPassword);
         }
     }
     $fromEmail = SpoonFilter::getPostValue('mailer_from_email', null, '');
     $fromName = SpoonFilter::getPostValue('mailer_from_name', null, '');
     $toEmail = SpoonFilter::getPostValue('mailer_to_email', null, '');
     $toName = SpoonFilter::getPostValue('mailer_to_name', null, '');
     $replyToEmail = SpoonFilter::getPostValue('mailer_reply_to_email', null, '');
     $replyToName = SpoonFilter::getPostValue('mailer_reply_to_name', null, '');
     // validate
     if ($fromEmail == '' || !SpoonFilter::isEmail($fromEmail)) {
         $this->output(self::BAD_REQUEST, null, BL::err('EmailIsInvalid'));
     }
     if ($toEmail == '' || !SpoonFilter::isEmail($toEmail)) {
         $this->output(self::BAD_REQUEST, null, BL::err('EmailIsInvalid'));
     }
     if ($replyToEmail == '' || !SpoonFilter::isEmail($replyToEmail)) {
         $this->output(self::BAD_REQUEST, null, BL::err('EmailIsInvalid'));
     }
     // set some properties
     $email->setFrom($fromEmail, $fromName);
     $email->addRecipient($toEmail, $toName);
     $email->setReplyTo($replyToEmail, $replyToName);
     $email->setSubject('Test');
     $email->setHTMLContent(BL::msg('TestMessage'));
     $email->setCharset(SPOON_CHARSET);
     try {
         if ($email->send()) {
             $this->output(self::OK, null, '');
         } else {
             $this->output(self::ERROR, null, 'unknown');
         }
     } catch (SpoonEmailException $e) {
         $this->output(self::ERROR, null, $e->getMessage());
     }
 }
Example #14
0
 /**
  * Updates the custom fields for a given group. Accepts an optional third parameter $email that will update the values for that e-mail.
  *
  * @param array $fields The fields.
  * @param int $groupId The group to update.
  * @param string[optional] $email The email you want to update the custom fields for.
  * @return int
  */
 public static function updateCustomFields($fields, $groupId, $email = null)
 {
     // get DB
     $db = BackendModel::getDB(true);
     // set values to update
     $values = array();
     // no email address set means we just update the custom fields (ie adding new ones)
     if (!empty($email) && SpoonFilter::isEmail($email)) {
         // set custom fields values
         $values['custom_fields'] = serialize($fields);
         // update field values for this email
         $db->update('mailmotor_addresses_groups', $values, 'email = ? AND group_id = ?', array($email, (int) $groupId));
     }
     // fetch array keys if $fields isn't a boolean
     if ($fields !== false && !isset($fields[0])) {
         $fields = array_keys($fields);
     }
     // overwrite custom fields so we only have the keys
     $values['custom_fields'] = serialize($fields);
     // update the field values for this e-mail address
     return (int) $db->update('mailmotor_groups', $values, 'id = ?', array((int) $groupId));
 }
Example #15
0
 /**
  * Adds an email to the queue.
  *
  * @param string $subject The subject for the email.
  * @param string $template The template to use.
  * @param array[optional] $variables Variables that should be assigned in the email.
  * @param string[optional] $toEmail The to-address for the email.
  * @param string[optional] $toName The to-name for the email.
  * @param string[optional] $fromEmail The from-address for the mail.
  * @param string[optional] $fromName The from-name for the mail.
  * @param string[optional] $replyToEmail The replyto-address for the mail.
  * @param string[optional] $replyToName The replyto-name for the mail.
  * @param bool[optional] $queue Should the mail be queued?
  * @param int[optional] $sendOn When should the email be send, only used when $queue is true.
  * @param bool[optional] $isRawHTML If this is true $template will be handled as raw HTML, so no parsing of $variables is done.
  * @param string[optional] $plainText The plain text version.
  * @param array[optional] $attachments Paths to attachments to include.
  * @return int The id of the inserted mail.
  */
 public static function addEmail($subject, $template, array $variables = null, $toEmail = null, $toName = null, $fromEmail = null, $fromName = null, $replyToEmail = null, $replyToName = null, $queue = false, $sendOn = null, $isRawHTML = false, $plainText = null, array $attachments = null)
 {
     $subject = (string) strip_tags($subject);
     $template = (string) $template;
     // set defaults
     $to = BackendModel::getModuleSetting('core', 'mailer_to');
     $from = BackendModel::getModuleSetting('core', 'mailer_from');
     $replyTo = BackendModel::getModuleSetting('core', 'mailer_reply_to');
     // set recipient/sender headers
     $email['to_email'] = $toEmail === null ? (string) $to['email'] : $toEmail;
     $email['to_name'] = $toName === null ? (string) $to['name'] : $toName;
     $email['from_email'] = $fromEmail === null ? (string) $from['email'] : $fromEmail;
     $email['from_name'] = $fromName === null ? (string) $from['name'] : $fromName;
     $email['reply_to_email'] = $replyToEmail === null ? (string) $replyTo['email'] : $replyToEmail;
     $email['reply_to_name'] = $replyToName === null ? (string) $replyTo['name'] : $replyToName;
     // validate
     if (!SpoonFilter::isEmail($email['to_email'])) {
         throw new BackendException('Invalid e-mail address for recipient.');
     }
     if (!SpoonFilter::isEmail($email['from_email'])) {
         throw new BackendException('Invalid e-mail address for sender.');
     }
     if (!SpoonFilter::isEmail($email['reply_to_email'])) {
         throw new BackendException('Invalid e-mail address for reply-to address.');
     }
     // build array
     $email['subject'] = SpoonFilter::htmlentitiesDecode($subject);
     if ($isRawHTML) {
         $email['html'] = $template;
     } else {
         $email['html'] = self::getTemplateContent($template, $variables);
     }
     if ($plainText !== null) {
         $email['plain_text'] = $plainText;
     }
     $email['created_on'] = BackendModel::getUTCDate();
     // init var
     $matches = array();
     // get internal links
     preg_match_all('|href="/(.*)"|i', $email['html'], $matches);
     // any links?
     if (!empty($matches[0])) {
         // init vars
         $search = array();
         $replace = array();
         // loop the links
         foreach ($matches[0] as $key => $link) {
             $search[] = $link;
             $replace[] = 'href="' . SITE_URL . '/' . $matches[1][$key] . '"';
         }
         // replace
         $email['html'] = str_replace($search, $replace, $email['html']);
     }
     // init var
     $matches = array();
     // get internal urls
     preg_match_all('|src="/(.*)"|i', $email['html'], $matches);
     // any links?
     if (!empty($matches[0])) {
         // init vars
         $search = array();
         $replace = array();
         // loop the links
         foreach ($matches[0] as $key => $link) {
             $search[] = $link;
             $replace[] = 'src="' . SITE_URL . '/' . $matches[1][$key] . '"';
         }
         // replace
         $email['html'] = str_replace($search, $replace, $email['html']);
     }
     // attachments added
     if (!empty($attachments)) {
         // add attachments one by one
         foreach ($attachments as $attachment) {
             // only add existing files
             if (SpoonFile::exists($attachment)) {
                 $email['attachments'][] = $attachment;
             }
         }
         // serialize :)
         if (!empty($email['attachments'])) {
             $email['attachments'] = serialize($email['attachments']);
         }
     }
     // set send date
     if ($queue) {
         if ($sendOn === null) {
             $email['send_on'] = BackendModel::getUTCDate('Y-m-d H') . ':00:00';
         } else {
             $email['send_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', (int) $sendOn);
         }
     }
     // insert the email into the database
     $id = BackendModel::getDB(true)->insert('emails', $email);
     // trigger event
     BackendModel::triggerEvent('core', 'after_email_queued', array('id' => $id));
     // if queue was not enabled, send this mail right away
     if (!$queue) {
         self::send($id);
     }
     // return
     return $id;
 }
Example #16
0
 /**
  * Sets the initial To: header to your liking, and thus masks a list of multiple recipients.
  * This will have no effect if you don't use SMTP (the mail() function does not accept it).
  *
  * @param	string $name			The name used in the To: header.
  * @param	string[optional] $email	The e-mail used in the To: header.
  */
 public function setTo($name, $email = null)
 {
     // check input
     if (!SpoonFilter::isEmail($email)) {
         throw new SpoonEmailException('Not a valid e-mail address for the TO header.');
     }
     // save the 'to' information
     $this->to['name'] = (string) $name;
     $this->to['email'] = (string) $email;
 }
Example #17
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create form
     $this->frm = new FrontendForm('commentsForm');
     $this->frm->setAction($this->frm->getAction() . '#' . FL::act('Comment'));
     // init vars
     $author = CommonCookie::exists('comment_author') ? CommonCookie::get('comment_author') : null;
     $email = CommonCookie::exists('comment_email') && \SpoonFilter::isEmail(CommonCookie::get('comment_email')) ? CommonCookie::get('comment_email') : null;
     $website = CommonCookie::exists('comment_website') && \SpoonFilter::isURL(CommonCookie::get('comment_website')) ? CommonCookie::get('comment_website') : 'http://';
     // create elements
     $this->frm->addText('author', $author)->setAttributes(array('required' => null));
     $this->frm->addText('email', $email)->setAttributes(array('required' => null, 'type' => 'email'));
     $this->frm->addText('website', $website, null);
     $this->frm->addTextarea('message')->setAttributes(array('required' => null));
 }
Example #18
0
 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();
 }
Example #19
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // shorten the fields
         $txtName = $this->frm->getField('name');
         $txtEmail = $this->frm->getField('email');
         $ddmMethod = $this->frm->getField('method');
         $txtSuccessMessage = $this->frm->getField('success_message');
         $txtIdentifier = $this->frm->getField('identifier');
         $emailAddresses = (array) explode(',', $txtEmail->getValue());
         // validate fields
         $txtName->isFilled(BL::getError('NameIsRequired'));
         $txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired'));
         if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') {
             $error = false;
             // check the addresses
             foreach ($emailAddresses as $address) {
                 $address = trim($address);
                 if (!\SpoonFilter::isEmail($address)) {
                     $error = true;
                     break;
                 }
             }
             // add error
             if ($error) {
                 $txtEmail->addError(BL::getError('EmailIsInvalid'));
             }
         }
         // identifier
         if ($txtIdentifier->isFilled()) {
             // invalid characters
             if (!\SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) {
                 $txtIdentifier->setError(BL::getError('InvalidIdentifier'));
             } elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue())) {
                 // unique identifier
                 $txtIdentifier->setError(BL::getError('UniqueIdentifier'));
             }
         }
         if ($this->frm->isCorrect()) {
             // build array
             $values['language'] = BL::getWorkingLanguage();
             $values['user_id'] = BackendAuthentication::getUser()->getUserId();
             $values['name'] = $txtName->getValue();
             $values['method'] = $ddmMethod->getValue();
             $values['email'] = $ddmMethod->getValue() == 'database_email' ? serialize($emailAddresses) : null;
             $values['success_message'] = $txtSuccessMessage->getValue(true);
             $values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier();
             $values['created_on'] = BackendModel::getUTCDate();
             $values['edited_on'] = BackendModel::getUTCDate();
             // insert the item
             $id = BackendFormBuilderModel::insert($values);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values));
             // set frontend locale
             FL::setLocale(BL::getWorkingLanguage(), true);
             // create submit button
             $field['form_id'] = $id;
             $field['type'] = 'submit';
             $field['settings'] = serialize(array('values' => \SpoonFilter::ucfirst(FL::getLabel('Send'))));
             BackendFormBuilderModel::insertField($field);
             // everything is saved, so redirect to the editform
             $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $id . '&report=added&var=' . urlencode($values['name']) . '#tabFields');
         }
     }
 }
Example #20
0
 /**
  * Set the author.
  *
  * @param string $author The author to use.
  */
 public function setAuthor($author)
 {
     // remove special chars
     $author = (string) \SpoonFilter::htmlspecialcharsDecode($author);
     // add fake-emailaddress
     if (!\SpoonFilter::isEmail($author)) {
         $author = CommonUri::getUrl($author) . '@example.com (' . $author . ')';
     }
     // add fake email address
     if (!\SpoonFilter::isEmail($author)) {
         $author = \SpoonFilter::urlise($author) . '@example.com (' . $author . ')';
     }
     // set author
     parent::setAuthor($author);
 }
Example #21
0
     $msgUsername = '******';
     $allOk = false;
 } else {
     // User already exists
     if (User::existsUser($username) !== false) {
         $msgUsername = '******';
         $allOk = false;
     }
 }
 // check mail
 if ($mail === "") {
     $msgMail = 'please fill in your mail address';
     $allOk = false;
 } else {
     // check if is right format
     if (!SpoonFilter::isEmail($mail)) {
         $msgMail = 'please fill in a correct mail address';
         $allOk = false;
     }
 }
 // check password
 if ($password === "") {
     $msgPassword = '******';
     $allOk = false;
 }
 if ($allOk === true) {
     $user = new User();
     $user->first_name = $first_name;
     $user->last_name = $last_name;
     $user->username = $username;
     $user->mail = $mail;