private function _defaultPage($slug)
 {
     switch ($slug) {
         case 'home':
         case 'contact':
             //init security (crsf and captcha)
             $security = Security::getSecurity(Security::TYPE_FORM);
             $crsf = $security->getProtection('form1', Form::PROTECTION_CSRF);
             $crsf->create();
             $captcha = $security->getProtection('form1', Form::PROTECTION_CAPTCHA);
             $this->tpl->setVar('captchaImageUrl', $captcha->get('image', true), false, true)->setVar('captchaAudioUrl', $captcha->get('audio', true), false, true)->setVar('captchaRefreshUrl', $captcha->getRefreshUrl(), false, true);
             $this->tpl->setVar('token', $crsf->get(), false, true);
             //define vars and  overwrite template
             if ($slug == 'contact') {
                 $this->tpl->setFile('controllers' . DS . 'Pages' . DS . 'contact.tpl.php');
             } elseif ($slug == 'register') {
                 if (Member::isConnected()) {
                     Http::redirect($this->router->getUrl('index'));
                 }
                 $this->tpl->setFile('controllers' . DS . 'Pages' . DS . 'register.tpl.php');
             } else {
                 $this->tpl->setVar('news', $this->_readAll('new'), false, true);
                 $this->tpl->setFile('controllers' . DS . 'Pages' . DS . 'index.tpl.php');
             }
             //set in session
             $crsf->set();
             break;
         case 'news':
             $this->tpl->setVar('news', $this->_readAll('new'), false, true);
             $this->tpl->setFile('controllers' . DS . 'Pages' . DS . 'news.tpl.php');
         default:
             break;
     }
 }
 public function contact()
 {
     //get security
     $security = Security::getSecurity(Security::TYPE_FORM);
     $crsf = $security->getProtection('form1', Form::PROTECTION_CSRF);
     $captcha = $security->getProtection('form1', Form::PROTECTION_CAPTCHA);
     //create new and add to ajax data
     $crsf->create();
     $this->addAjaxDatas('token', $crsf->get());
     $error = false;
     //check security
     if (!$crsf->check(Http::getPost('token'))) {
         $error = true;
     }
     if (!$captcha->check(Http::getPost('captcha'))) {
         $this->addError($this->language->getVar('validate_security'), 'captcha');
         $error = true;
     }
     // send mail
     if ($error) {
         $this->notifyError($this->language->getVar('validate_error'));
     } else {
         //send mail
         SwiftMailer::getInstance();
         $mail = \Swift_Message::newInstance();
         $mail->setFrom(array(ADMIN_EMAIL => $this->language->getVar('site_name')));
         $mail->setTo(CONTACT_EMAIL);
         $mail->setSubject($this->language->getVar('site_name') . ' demande de contact');
         $contents = new MailContents($this->tpl->getPath() . 'mails' . DS . 'contact.tpl.php');
         $contents->addVar('message', nl2br(Http::getPost('message')))->addVar('name', Http::getPost('name'))->addVar('email', Http::getPost('email'))->addVar('subject', Http::getPost('subject'));
         $mail->addPart($contents->getMailContents(), 'text/html');
         $transport = defined('SMTP_SERVER') && !is_null(SMTP_SERVER) && SMTP_SERVER != '' ? \Swift_SmtpTransport::newInstance(SMTP_SERVER, 25) : \Swift_MailTransport::newInstance();
         $mailer = \Swift_Mailer::newInstance($transport);
         $mailer->send($mail);
         $this->notifySuccess($this->language->getVar('validate_success'));
     }
     //set in session
     $crsf->set();
 }