function postcomment($data)
 {
     // Spam filtering
     if (SSAkismet::isEnabled()) {
         try {
             $akismet = new SSAkismet();
             $akismet->setCommentAuthor($data['Name']);
             $akismet->setCommentContent($data['Comment']);
             if ($akismet->isCommentSpam()) {
                 if (SSAkismet::getSaveSpam()) {
                     $comment = Object::create('PageComment');
                     $this->saveInto($comment);
                     $comment->setField("IsSpam", true);
                     $comment->write();
                 }
                 echo "<b>" . _t('PageCommentInterface_Form.SPAMDETECTED', 'Spam detected!!') . "</b><br /><br />";
                 printf("If you believe this was in error, please email %s.", ereg_replace("@", " _(at)_", Email::getAdminEmail()));
                 echo "<br /><br />" . _t('PageCommentInterface_Form.MSGYOUPOSTED', 'The message you posted was:') . "<br /><br />";
                 echo $data['Comment'];
                 return;
             }
         } catch (Exception $e) {
             // Akismet didn't work, continue without spam check
         }
     }
     //check if spam question was right.
     if (MathSpamProtection::isEnabled()) {
         if (!MathSpamProtection::correctAnswer($data['Math'])) {
             if (!Director::is_ajax()) {
                 Director::redirectBack();
             }
             return "spamprotectionfalied";
             //used by javascript for checking if the spam question was wrong
         }
     }
     Cookie::set("PageCommentInterface_Name", $data['Name']);
     $comment = Object::create('PageComment');
     $this->saveInto($comment);
     $comment->IsSpam = false;
     $comment->NeedsModeration = PageComment::moderationEnabled();
     $comment->write();
     if (Director::is_ajax()) {
         if ($comment->NeedsModeration) {
             echo _t('PageCommentInterface_Form.AWAITINGMODERATION', "Your comment has been submitted and is now awating moderation.");
         } else {
             echo $comment->renderWith('PageCommentInterface_singlecomment');
         }
     } else {
         Director::redirectBack();
     }
 }
 function postcomment($data)
 {
     // Spam filtering
     Cookie::set("PageCommentInterface_Name", $data['Name']);
     Cookie::set("PageCommentInterface_CommenterURL", $data['CommenterURL']);
     Cookie::set("PageCommentInterface_Comment", $data['Comment']);
     if (SSAkismet::isEnabled()) {
         try {
             $akismet = new SSAkismet();
             $akismet->setCommentAuthor($data['Name']);
             $akismet->setCommentContent($data['Comment']);
             if ($akismet->isCommentSpam()) {
                 if (SSAkismet::getSaveSpam()) {
                     $comment = Object::create('PageComment');
                     $this->saveInto($comment);
                     $comment->setField("IsSpam", true);
                     $comment->write();
                 }
                 echo "<b>" . _t('PageCommentInterface_Form.SPAMDETECTED', 'Spam detected!!') . "</b><br /><br />";
                 printf("If you believe this was in error, please email %s.", ereg_replace("@", " _(at)_", Email::getAdminEmail()));
                 echo "<br /><br />" . _t('PageCommentInterface_Form.MSGYOUPOSTED', 'The message you posted was:') . "<br /><br />";
                 echo $data['Comment'];
                 return;
             }
         } catch (Exception $e) {
             // Akismet didn't work, continue without spam check
         }
     }
     //check if spam question was right.
     if (MathSpamProtection::isEnabled()) {
         if (!MathSpamProtection::correctAnswer($data['Math'])) {
             if (!Director::is_ajax()) {
                 Director::redirectBack();
             }
             return "spamprotectionfailed";
             //used by javascript for checking if the spam question was wrong
         }
     }
     // If commenting can only be done by logged in users, make sure the user is logged in
     $member = Member::currentUser();
     if (PageCommentInterface::CanPostComment() && $member) {
         $this->Fields()->push(new HiddenField("AuthorID", "Author ID", $member->ID));
     } elseif (!PageCommentInterface::CanPostComment()) {
         echo "You're not able to post comments to this page. Please ensure you are logged in and have an appropriate permission level.";
         return;
     }
     $comment = Object::create('PageComment');
     $this->saveInto($comment);
     // Store the Session ID if needed for Spamprotection
     if ($session = Session::get('mollom_user_session_id')) {
         $comment->SessionID = $session;
         Session::clear('mollom_user_session_id');
     }
     $comment->IsSpam = false;
     $comment->NeedsModeration = PageComment::moderationEnabled();
     $comment->write();
     Cookie::set("PageCommentInterface_Comment", '');
     if (Director::is_ajax()) {
         if ($comment->NeedsModeration) {
             echo _t('PageCommentInterface_Form.AWAITINGMODERATION', "Your comment has been submitted and is now awaiting moderation.");
         } else {
             echo $comment->renderWith('PageCommentInterface_singlecomment');
         }
     } else {
         // since it is not ajax redirect user down to their comment since it has been posted
         // get the pages url off the comments parent ID.
         if ($comment->ParentID) {
             $page = DataObject::get_by_id("Page", $comment->ParentID);
             if ($page) {
                 // Redirect to the actual post on the page.
                 return Director::redirect(Director::baseURL() . $page->URLSegment . '#PageComment_' . $comment->ID);
             }
         }
         return Director::redirectBack();
         // worst case, just go back to the page
     }
 }