From 8c9f5900b5486db560b5936a6c3629811535e037 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Wed, 8 Aug 2007 06:00:20 +0000 Subject: [PATCH] Allowing marking of comment as spam, ham or accepted in cms git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@39738 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CommentTableField.php | 130 ++++++++++++++++++++++++ code/FeedbackAdmin.php | 12 ++- code/sitefeatures/PageComment.php | 5 + javascript/CommentTableField.js | 42 ++++++++ templates/Includes/CommentTableField.ss | 89 ++++++++++++++++ 5 files changed, 275 insertions(+), 3 deletions(-) create mode 100644 code/CommentTableField.php create mode 100644 javascript/CommentTableField.js create mode 100644 templates/Includes/CommentTableField.ss diff --git a/code/CommentTableField.php b/code/CommentTableField.php new file mode 100644 index 00000000..4eceadf8 --- /dev/null +++ b/code/CommentTableField.php @@ -0,0 +1,130 @@ +mode = $mode; + $this->Markable = true; + parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); + + Requirements::javascript('cms/javascript/CommentTableField.js'); + } + + function Items() { + $this->sourceItems = $this->sourceItems(); + + if(!$this->sourceItems) { + return null; + } + + $pageStart = (isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) ? $_REQUEST['ctf'][$this->Name()]['start'] : 0; + $this->sourceItems->setPageLimits($pageStart, $this->pageSize, $this->totalCount); + + $output = new DataObjectSet(); + foreach($this->sourceItems as $pageIndex=>$item) { + $output->push(Object::create('CommentTableField_Item',$item, $this, $pageStart+$pageIndex)); + } + return $output; + } + + function spam() { + if(!Permission::check('ADMIN')) { + return false; + } + + $this->methodName = "spam"; + + $childId = Convert::raw2sql($_REQUEST['tf']['childID']); + + if (is_numeric($childId)) { + $childObject = DataObject::get_by_id($this->sourceClass, $childId); + if($childObject) { + $childObject->IsSpam = true; + $childObject->NeedsModeration = false; + $childObject->write(); + } + } + } + + function ham() { + if(!Permission::check('ADMIN')) { + return false; + } + + $this->methodName = "ham"; + + $childId = Convert::raw2sql($_REQUEST['tf']['childID']); + + if (is_numeric($childId)) { + $childObject = DataObject::get_by_id($this->sourceClass, $childId); + if($childObject) { + $childObject->IsSpam = false; + $childObject->NeedsModeration = false; + $childObject->write(); + } + } + } + + function accept() { + if(!Permission::check('ADMIN')) { + return false; + } + + $this->methodName = "accept"; + + $childId = Convert::raw2sql($_REQUEST['tf']['childID']); + + if(is_numeric($childId)) { + $childObject = DataObject::get_by_id($this->sourceClass, $childId); + if($childObject) { + $childObject->IsSpam = false; + $childObject->NeedsModeration = false; + $childObject->write(); + } + } + } + + function HasSpamButton() { + return $this->mode == 'accepted' || $this->mode == 'unmoderated'; + } + + function HasAcceptButton() { + return $this->mode == 'unmoderated'; + } + + function HasHamButton() { + return $this->mode == 'spam'; + } + +} + + +class CommentTableField_Item extends ComplexTableField_Item { + function HasSpamButton() { + return $this->parent()->HasSpamButton(); + } + + function HasAcceptButton() { + return $this->parent()->HasAcceptButton(); + } + + function HasHamButton() { + return $this->parent()->HasHamButton(); + } + + function SpamLink() { + return $this->BaseLink() . "&methodName=spam"; + } + + function HamLink() { + return $this->BaseLink() . "&methodName=ham"; + } + + function AcceptLink() { + return $this->BaseLink() . "&methodName=accept"; + } +} + +?> \ No newline at end of file diff --git a/code/FeedbackAdmin.php b/code/FeedbackAdmin.php index c30e4334..7fcffc6b 100644 --- a/code/FeedbackAdmin.php +++ b/code/FeedbackAdmin.php @@ -26,20 +26,26 @@ class FeedbackAdmin extends LeftAndMain { if($section == 'accepted') { $filter = 'IsSpam=0 AND NeedsModeration=0'; - } else if($section == 'unmoderation') { + } else if($section == 'unmoderated') { $filter = 'NeedsModeration=1'; } else { $filter = 'IsSpam=1'; } $tableFields = array( - "Name" => "Name", + "Name" => "Author", "Comment" => "Comment", "PageTitle" => "Page" ); + $popupFields = new FieldSet( + new TextField("Name"), + new TextareaField("Comment", "Comment") + ); + $idField = new HiddenField('ID'); - $table = new ComplexTableField($this, "Comments", "PageComment", $tableFields, new FieldSet(), $filter); + $table = new CommentTableField($this, "Comments", "PageComment", $section, $tableFields, $popupFields, $filter); + $table->setParentClass(false); $fields = new FieldSet($idField, $table); $actions = new FieldSet(); diff --git a/code/sitefeatures/PageComment.php b/code/sitefeatures/PageComment.php index 5b775e67..16eb8971 100755 --- a/code/sitefeatures/PageComment.php +++ b/code/sitefeatures/PageComment.php @@ -148,6 +148,11 @@ class PageComment extends DataObject { $rss->outputToBrowser(); } + + function PageTitle() { + return $this->Parent()->Title; + } + static function enableModeration() { self::$moderate = true; } diff --git a/javascript/CommentTableField.js b/javascript/CommentTableField.js new file mode 100644 index 00000000..43ab32a7 --- /dev/null +++ b/javascript/CommentTableField.js @@ -0,0 +1,42 @@ +CommentTableField = Class.create(); +CommentTableField.prototype = { + initialize: function() { + var rules = {}; + + rules['#'+this.id+' table.data a.spamlink'] = { + onclick: this.removeRowAfterAjax.bind(this) + }; + + rules['#'+this.id+' table.data a.acceptlink'] = { + onclick: this.removeRowAfterAjax.bind(this) + }; + + rules['#'+this.id+' table.data a.hamlink'] = { + onclick: this.removeRowAfterAjax.bind(this) + }; + + Behaviour.register(rules); + }, + + removeRowAfterAjax: function(e) { + var img = Event.element(e); + var link = Event.findElement(e,"a"); + var row = Event.findElement(e,"tr"); + + img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work in Firefox1.5+ + new Ajax.Request( + link.getAttribute("href"), + { + method: 'post', + postBody: 'forceajax=1', + onComplete: function(){ + Effect.Fade(row); + }.bind(this), + onFailure: ajaxErrorHandler + } + ); + Event.stop(e); + } +} + +CommentTableField.applyTo('div.CommentTableField'); \ No newline at end of file diff --git a/templates/Includes/CommentTableField.ss b/templates/Includes/CommentTableField.ss new file mode 100644 index 00000000..8e32ae9e --- /dev/null +++ b/templates/Includes/CommentTableField.ss @@ -0,0 +1,89 @@ +
+ <% include TableListField_PageControls %> + + + + <% if Markable %><% end_if %> + <% control Headings %> + + <% end_control %> + <% if Can(edit) %><% end_if %> + <% if HasAcceptButton %><% end_if %> + <% if HasSpamButton %><% end_if %> + <% if HasHamButton %><% end_if %> + <% if Can(delete) %><% end_if %> + + + + <% if HasSummary %> + + <% if Markable %><% end_if %> + + <% control SummaryFields %> + class="$Function"<% end_if %>>  + <% end_control %> + <% if Can(edit) %><% end_if %> + <% if HasAcceptButton %><% end_if %> + <% if HasSpamButton %><% end_if %> + <% if HasHamButtom %><% end_if %> + <% if Can(delete) %><% end_if %> + + <% end_if %> + + + <% if Items %> + <% control Items %> + class="$HighlightClasses"<% end_if %>> + <% if Markable %><% end_if %> + <% control Fields %> + + <% end_control %> + <% if Can(edit) %> + + <% end_if %> + <% if HasAcceptButton %> + + <% end_if %> + <% if HasSpamButton %> + + <% end_if %> + <% if HasHamButton %> + + <% end_if %> + <% if Can(delete) %> + + <% end_if %> + + <% end_control %> + <% else %> + + <% if Markable %><% end_if %> + + <% if Can(edit) %><% end_if %> + <% if HasAcceptButton %><% end_if %> + <% if HasSpamButton %><% end_if %> + <% if HasHamButtom %><% end_if %> + <% if Can(delete) %><% end_if %> + + <% end_if %> + +
  + <% if IsSortable %> + + $Title + + + + <% if SortDirection = desc %> + Sort ascending + <% else %> + Sort descending + <% end_if %> + +   + + <% else %> + $Title + <% end_if %> +      
 $SummaryTitle     
$MarkingCheckbox$Valueeditacceptspamhamdelete
 No items found     
+
\ No newline at end of file