Exemplo n.º 1
0
 public function renderFile()
 {
     $aCurrentValues = $this->oFormStorage->saveCurrentValuesToSession();
     $oFlash = Flash::getFlash();
     $oFlash->setArrayToCheck($aCurrentValues);
     $bHasCaptcha = false;
     foreach ($this->oFormStorage->getFormObjects() as $oFormObject) {
         if ($oFormObject instanceof CaptchaObject) {
             $bHasCaptcha = true;
         }
         if ($oFormObject->shouldExcludeFromReport()) {
             continue;
         }
         if ($oFormObject->isRequired()) {
             $oFlash->checkForValue($oFormObject->getName());
         }
         $oEmailItemTemplateInstance = clone $this->oEmailItemTemplate;
         $oEmailItemTemplateInstance->replaceIdentifier('name', $oFormObject->getName());
         $oEmailItemTemplateInstance->replaceIdentifier('label', $oFormObject->getLabel());
         $oEmailItemTemplateInstance->replaceIdentifier('value', $oFormObject->getCurrentValue());
         $this->oEmailTemplate->replaceIdentifierMultiple('form_content', $oEmailItemTemplateInstance);
     }
     if ($bHasCaptcha && !FormFrontendModule::validateRecaptchaInput()) {
         $oFlash->addMessage('captcha_code_required');
     }
     $oFlash->finishReporting();
     if (Flash::noErrors()) {
         $oEmail = new EMail(TranslationPeer::getString('wns.form_module.email_subject', null, null, array('page' => $this->sPageName)), $this->oEmailTemplate);
         $oEmail->addRecipient($this->sEmailAddress);
         $oEmail->send();
         $this->oFormStorage->deleteCurrentValuesFromSession();
         LinkUtil::redirect($_REQUEST['origin'] . '?form_success=true');
     } else {
         $oFlash->stick();
         LinkUtil::redirect($_REQUEST['origin']);
     }
 }
Exemplo n.º 2
0
 protected function getFieldCode($iFormId)
 {
     return FormFrontendModule::getRecaptchaCode('form_frontend_module_' . $iFormId);
 }
 private function renderAddComment(JournalEntry $oEntry = null)
 {
     if ($oEntry === null) {
         $oEntry = $this->oEntry;
     }
     if (!$oEntry->commentsEnabled()) {
         return null;
     }
     //Disabled comments at this point means moderated
     $oLeaveCommentTemplate = $this->constructTemplate(!$oEntry->getJournal()->getEnableComments() ? 'leave_comment_moderated' : 'leave_comment');
     // Display catcha if enabled and user is not authenticated
     if ($oEntry->getJournal()->getUseCaptcha() && !Session::getSession()->isAuthenticated()) {
         $oLeaveCommentTemplate->replaceIdentifier('captcha', FormFrontendModule::getRecaptchaCode('journal_comment'));
     } elseif (!Manager::isPost()) {
         if ($oUser = Session::user()) {
             $_REQUEST['comment_name'] = $oUser->getFullName();
             $_REQUEST['comment_email'] = $oUser->getEmail();
         }
     }
     $oLeaveCommentTemplate->replaceIdentifier('is_authenticated', Session::getSession()->isAuthenticated() ? true : null);
     $oLeaveCommentTemplate->replaceIdentifier('comment_action', LinkUtil::link($oEntry->getLink($this->oPage, 'add_comment')));
     return $oLeaveCommentTemplate;
 }
Exemplo n.º 4
0
 private function handleNewJournalComment($oPage, $oEntry)
 {
     $oFlash = Flash::getFlash();
     // Validate form and create new comment and
     $oComment = new JournalComment();
     $oComment->setUsername($_POST['comment_name']);
     $oFlash->checkForValue('comment_name', 'comment_name_required');
     $oComment->setEmail($_POST['comment_email']);
     $oFlash->checkForEmail('comment_email', 'comment_email_required');
     if ($oEntry->getJournal()->getUseCaptcha() && !Session::getSession()->isAuthenticated() && !FormFrontendModule::validateRecaptchaInput() && !isset($_POST['preview'])) {
         $oFlash->addMessage('captcha_required');
     }
     $oPurifierConfig = HTMLPurifier_Config::createDefault();
     $oPurifierConfig->set('Cache.SerializerPath', MAIN_DIR . '/' . DIRNAME_GENERATED . '/' . DIRNAME_CACHES . '/purifier');
     $oPurifierConfig->set('HTML.Doctype', 'XHTML 1.0 Transitional');
     $oPurifierConfig->set('AutoFormat.AutoParagraph', true);
     $oPurifier = new HTMLPurifier($oPurifierConfig);
     $_POST['comment_text'] = $oPurifier->purify($_POST['comment_text']);
     $oComment->setText($_POST['comment_text']);
     $oFlash->checkForValue('comment_text', 'comment_required');
     $oFlash->finishReporting();
     if (isset($_POST['preview'])) {
         $oComment->setCreatedAt(date('c'));
         $_POST['preview'] = $oComment;
     } else {
         if (Flash::noErrors()) {
             $oEntry->addJournalComment($oComment);
             // Post is considered as spam
             $bIsProblablySpam = isset($_POST['important_note']) && $_POST['important_note'] != null;
             $sCommentNotificationTemplate = 'e_mail_comment_notified';
             // Prevent publication if comments are not enabled or post is spam
             if (!$oEntry->getJournal()->getEnableComments() || $bIsProblablySpam) {
                 if (!Session::getSession()->isAuthenticated()) {
                     $oComment->setIsPublished(false);
                     $sCommentNotificationTemplate = 'e_mail_comment_moderated';
                 }
             }
             $oComment->save();
             // Notify new comment
             if ($oEntry->getJournal()->getNotifyComments()) {
                 $oEmailContent = JournalPageTypeModule::templateConstruct($sCommentNotificationTemplate, $oPage->getPagePropertyValue('journal:template_set', 'default'));
                 $oEmailContent->replaceIdentifier('email', $oComment->getEmail());
                 $oEmailContent->replaceIdentifier('user', $oComment->getUsername());
                 if ($bIsProblablySpam) {
                     $oEmailContent->replaceIdentifier('this_comment_is_spam_note', TranslationPeer::getString('journal.this_comment_is_spam_note', null, null, array('important_note_content' => $_POST['important_note'])));
                 }
                 $oEmailContent->replaceIdentifier('comment', $oComment->getText());
                 $oEmailContent->replaceIdentifier('entry', $oEntry->getTitle());
                 $oEmailContent->replaceIdentifier('journal', $oEntry->getJournal()->getName());
                 $oEmailContent->replaceIdentifier('entry_link', LinkUtil::absoluteLink(LinkUtil::link($oEntry->getLink($oPage))));
                 $oEmailContent->replaceIdentifier('deactivation_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'deactivate'), 'FileManager'), null, LinkUtil::isSSL()));
                 $oEmailContent->replaceIdentifier('activation_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'activate'), 'FileManager'), null, LinkUtil::isSSL()));
                 $oEmailContent->replaceIdentifier('deletion_link', LinkUtil::absoluteLink(LinkUtil::link(array('journal_comment_moderation', $oComment->getActivationHash(), 'delete'), 'FileManager'), null, LinkUtil::isSSL()));
                 $sSubject = TranslationPeer::getString('journal.notification_subject', null, null, array('entry' => $oEntry->getTitle()));
                 $oEmail = new EMail($sSubject, $oEmailContent);
                 $oSender = $oEntry->getUserRelatedByCreatedBy();
                 $oEmail->addRecipient($oSender->getEmail(), $oSender->getFullName());
                 $oEmail->send();
             }
             $oSession = Session::getSession();
             Flash::getFlash()->unfinishReporting()->addMessage('journal.has_new_comment', array(), "journal_entry.new_comment_thank_you" . ($oEntry->getJournal()->getEnableComments() || $oSession->isAuthenticated() ? '' : '.moderated'), 'new_comment_thank_you_message', 'p')->stick();
             LinkUtil::redirect(LinkUtil::link($oEntry->getLink($oPage)) . "#comments");
         }
     }
 }