mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
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
This commit is contained in:
parent
6666021921
commit
8c9f5900b5
130
code/CommentTableField.php
Normal file
130
code/CommentTableField.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
class CommentTableField extends ComplexTableField {
|
||||
protected $template = "CommentTableField";
|
||||
protected $mode;
|
||||
|
||||
function __construct($controller, $name, $sourceClass, $mode, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
||||
$this->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";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -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();
|
||||
|
@ -148,6 +148,11 @@ class PageComment extends DataObject {
|
||||
$rss->outputToBrowser();
|
||||
}
|
||||
|
||||
|
||||
function PageTitle() {
|
||||
return $this->Parent()->Title;
|
||||
}
|
||||
|
||||
static function enableModeration() {
|
||||
self::$moderate = true;
|
||||
}
|
||||
|
42
javascript/CommentTableField.js
Normal file
42
javascript/CommentTableField.js
Normal file
@ -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');
|
89
templates/Includes/CommentTableField.ss
Normal file
89
templates/Includes/CommentTableField.ss
Normal file
@ -0,0 +1,89 @@
|
||||
<div id="$id" class="$Classes">
|
||||
<% include TableListField_PageControls %>
|
||||
<table class="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<% if Markable %><th width="18"> </th><% end_if %>
|
||||
<% control Headings %>
|
||||
<th class="$Name">
|
||||
<% if IsSortable %>
|
||||
<span class="sortTitle">
|
||||
<a href="$SortLink">$Title</a>
|
||||
</span>
|
||||
<span class="sortLink <% if SortBy %><% else %>sortLinkHidden<% end_if %>">
|
||||
<a href="$SortLink"">
|
||||
<% if SortDirection = desc %>
|
||||
<img src="cms/images/bullet_arrow_up.png" alt="Sort ascending" />
|
||||
<% else %>
|
||||
<img src="cms/images/bullet_arrow_down.png" alt="Sort descending" />
|
||||
<% end_if %>
|
||||
</a>
|
||||
|
||||
</span>
|
||||
<% else %>
|
||||
$Title
|
||||
<% end_if %>
|
||||
</th>
|
||||
<% end_control %>
|
||||
<% if Can(edit) %><th width="18"> </th><% end_if %>
|
||||
<% if HasAcceptButton %><th width="18"> </th><% end_if %>
|
||||
<% if HasSpamButton %><th width="18"> </th><% end_if %>
|
||||
<% if HasHamButton %><th width="18"> </th><% end_if %>
|
||||
<% if Can(delete) %><th width="18"> </th><% end_if %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<% if HasSummary %>
|
||||
<tr class="summary">
|
||||
<% if Markable %><th width="18"> </th><% end_if %>
|
||||
<td><i>$SummaryTitle</i></td>
|
||||
<% control SummaryFields %>
|
||||
<td<% if Function %> class="$Function"<% end_if %>> </td>
|
||||
<% end_control %>
|
||||
<% if Can(edit) %><th width="18"> </th><% end_if %>
|
||||
<% if HasAcceptButton %><th width="18"> </th><% end_if %>
|
||||
<% if HasSpamButton %><th width="18"> </th><% end_if %>
|
||||
<% if HasHamButtom %><th width="18"> </th><% end_if %>
|
||||
<% if Can(delete) %><th width="18"> </th><% end_if %>
|
||||
</tr>
|
||||
<% end_if %>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
<% if Items %>
|
||||
<% control Items %>
|
||||
<tr id="record-$Parent.id-$ID"<% if HighlightClasses %> class="$HighlightClasses"<% end_if %>>
|
||||
<% if Markable %><td width="18" class="markingcheckbox">$MarkingCheckbox</td><% end_if %>
|
||||
<% control Fields %>
|
||||
<td>$Value</td>
|
||||
<% end_control %>
|
||||
<% if Can(edit) %>
|
||||
<td width="18"><a class="popuplink editlink" href="$EditLink" target="_blank"><img src="cms/images/edit.gif" alt="edit" /></a></td>
|
||||
<% end_if %>
|
||||
<% if HasAcceptButton %>
|
||||
<td width="18"><a class="acceptlink" href="$AcceptLink" title="Accept this comment"><img src="cms/images/accept.gif" alt="accept" /></a></td>
|
||||
<% end_if %>
|
||||
<% if HasSpamButton %>
|
||||
<td width="18"><a class="spamlink" href="$SpamLink" title="Mark this comment as spam"><img src="cms/images/spam.gif" alt="spam" /></a></td>
|
||||
<% end_if %>
|
||||
<% if HasHamButton %>
|
||||
<td width="18"><a class="hamlink" href="$HamLink" title="Mark this comment as not spam"><img src="cms/images/ham.gif" alt="ham" /></a></td>
|
||||
<% end_if %>
|
||||
<% if Can(delete) %>
|
||||
<td width="18"><a class="deletelink" href="$DeleteLink" title="Delete this row"><img src="cms/images/delete.gif" alt="delete" /></a></td>
|
||||
<% end_if %>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
<% else %>
|
||||
<tr class="notfound">
|
||||
<% if Markable %><th width="18"> </th><% end_if %>
|
||||
<td colspan="$Headings.Count"><i>No items found</i></td>
|
||||
<% if Can(edit) %><th width="18"> </th><% end_if %>
|
||||
<% if HasAcceptButton %><th width="18"> </th><% end_if %>
|
||||
<% if HasSpamButton %><th width="18"> </th><% end_if %>
|
||||
<% if HasHamButtom %><th width="18"> </th><% end_if %>
|
||||
<% if Can(delete) %><th width="18"> </th><% end_if %>
|
||||
</tr>
|
||||
<% end_if %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user