public static function renderEntries(JournalEntryQuery $oQuery, Template $oEntryTemplate)
 {
     $oTemplate = new Template(TemplateIdentifier::constructIdentifier('container', 'entries'), null, true);
     $oModule = new JournalPageTypeModule();
     $oModule->renderJournalEntries($oQuery, $oEntryTemplate, $oTemplate, null, 'entries');
     return $oTemplate;
 }
Ejemplo n.º 2
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");
         }
     }
 }