diff --git a/code/sitefeatures/PageComment.php b/code/sitefeatures/PageComment.php index 16eb8971..39639212 100755 --- a/code/sitefeatures/PageComment.php +++ b/code/sitefeatures/PageComment.php @@ -52,18 +52,23 @@ class PageComment extends DataObject { function SpamLink() { $member = Member::currentUser(); - if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain') && !$this->getField('IsSpam')) { + if(Permission::check('CMS_ACCESS_CMSMain') && !$this->getField('IsSpam')) { return "PageComment/reportspam/$this->ID"; } } function HamLink() { - $member = Member::currentUser(); - if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) { + if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) { return "PageComment/reportham/$this->ID"; } } + function AcceptLink() { + if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('NeedsModeration')) { + return "PageComment/accept/$this->ID"; + } + } + function SpamClass() { if($this->getField('IsSpam')) { return 'spam'; @@ -72,65 +77,83 @@ class PageComment extends DataObject { } } - function reportspam() { - if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain')) { + function accept() { + if(Permission::check('CMS_ACCESS_CMSMain')) { $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); + $comment->NeedsModeration = false; + $comment->write(); - if($comment) { - try { - $akismet = new SSAkismet(); - $akismet->setCommentAuthor($comment->getField('Name')); - $akismet->setCommentContent($comment->getField('Comment')); - - $akismet->submitSpam(); - } catch (Exception $e) { - // Akismet didn't work, most likely the service is down. - } - - if(SSAkismet::getSaveSpam()) { - $comment->setField('IsSpam', true); - $comment->write(); - } else { - $comment->delete(); - } - } - } - - if(Director::is_ajax()) { - if(SSAkismet::getSaveSpam()) { + if(Director::is_ajax()) { echo $comment->renderWith('PageCommentInterface_singlecomment'); } else { - echo ''; + Director::redirectBack(); + } + } + } + + function reportspam() { + if(SSAkismet::isEnabled()) { + if(Permission::check('CMS_ACCESS_CMSMain')) { + $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); + + if($comment) { + try { + $akismet = new SSAkismet(); + $akismet->setCommentAuthor($comment->getField('Name')); + $akismet->setCommentContent($comment->getField('Comment')); + + $akismet->submitSpam(); + } catch (Exception $e) { + // Akismet didn't work, most likely the service is down. + } + + if(SSAkismet::getSaveSpam()) { + $comment->setField('IsSpam', true); + $comment->write(); + } else { + $comment->delete(); + } + } + } + + if(Director::is_ajax()) { + if(SSAkismet::getSaveSpam()) { + echo $comment->renderWith('PageCommentInterface_singlecomment'); + } else { + echo ''; + } + } else { + Director::redirectBack(); } - } else { - Director::redirectBack(); } } function reportham() { - if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain')) { - $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); - - if($comment) { - try { - $akismet = new SSAkismet(); - $akismet->setCommentAuthor($comment->getField('Name')); - $akismet->setCommentContent($comment->getField('Comment')); - - $akismet->submitHam(); - } catch (Exception $e) { - // Akismet didn't work, most likely the service is down. - } + if(SSAkismet::isEnabled()) { + if(Permission::check('CMS_ACCESS_CMSMain')) { + $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); - $comment->setField('IsSpam', false); - $comment->write(); + if($comment) { + try { + $akismet = new SSAkismet(); + $akismet->setCommentAuthor($comment->getField('Name')); + $akismet->setCommentContent($comment->getField('Comment')); + + $akismet->submitHam(); + } catch (Exception $e) { + // Akismet didn't work, most likely the service is down. + } + + $comment->setField('IsSpam', false); + $comment->write(); + } } - } - if(Director::is_ajax()) { - echo $comment->renderWith('PageCommentInterface_singlecomment'); - } else { - Director::redirectBack(); + if(Director::is_ajax()) { + echo $comment->renderWith('PageCommentInterface_singlecomment'); + } else { + Director::redirectBack(); + } } } @@ -158,7 +181,7 @@ class PageComment extends DataObject { } static function moderationEnabled() { - return self::moderate; + return self::$moderate; } } diff --git a/code/sitefeatures/PageCommentInterface.php b/code/sitefeatures/PageCommentInterface.php index 8de0bdc6..16cdfcf8 100755 --- a/code/sitefeatures/PageCommentInterface.php +++ b/code/sitefeatures/PageCommentInterface.php @@ -142,9 +142,9 @@ class PageCommentInterface_Form extends Form { $comment = Object::create('PageComment'); $this->saveInto($comment); $comment->IsSpam = false; - $comment->write(); + $comment->NeedsModeration = PageComment::moderationEnabled(); - $comment->NeedsModeration = PageComment::moderationEnable(); + $comment->write(); if(Director::is_ajax()) { echo $comment->renderWith('PageCommentInterface_singlecomment'); diff --git a/javascript/PageCommentInterface.js b/javascript/PageCommentInterface.js index 07ee4a47..d82da0bd 100755 --- a/javascript/PageCommentInterface.js +++ b/javascript/PageCommentInterface.js @@ -19,6 +19,9 @@ PageCommentInterface.prototype = { }, '#PageComments a.hamlink' : { onclick : this.reportHam + }, + '#PageComments a.acceptlink' : { + onclick : this.acceptComment } }); }, @@ -179,6 +182,33 @@ PageCommentInterface.prototype = { } }); + return false; + }, + + /** + * Ajax handler of ham reporting + */ + acceptComment: function() { + var __comment = this.parentNode.parentNode.parentNode; + + __comment.getElementsByTagName('span')[0].innerHTML = "Marking comment as accepted..."; + + new Ajax.Request(this.href + '?ajax=1', { + onSuccess : function(response) { + // Load the response into the
  • + __comment.innerHTML = response.responseText; + Behaviour.apply(__comment); + + // Flash it using Scriptaculous + new Effect.Highlight(__comment, { endcolor: '#e9e9e9' } ); + __comment.className = 'notspam'; + }, + + onFailure : function(response) { + alert(response.responseText); + } + }); + return false; } } diff --git a/templates/PageCommentInterface_singlecomment.ss b/templates/PageCommentInterface_singlecomment.ss index ed103b03..72d8dcfd 100755 --- a/templates/PageCommentInterface_singlecomment.ss +++ b/templates/PageCommentInterface_singlecomment.ss @@ -1,10 +1,15 @@ -

    $Comment.XML

    +

    + <% if NeedsModeration %> +

    Unmoderated comment

    + <% end_if %> + $Comment.XML +

    Posted by $Name.XML, $Created.Nice ($Created.Ago)
    - <% if DeleteLink %> - remove this comment + <% if AcceptLink %> + accept this comment <% end_if %> <% if SpamLink %> this comment is spam @@ -12,5 +17,8 @@ <% if HamLink %> this comment is not spam <% end_if %> + <% if DeleteLink %> + remove this comment + <% end_if %>