2007-08-08 08:00:20 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Special kind of ComplexTableField for managing comments.
|
|
|
|
* @package cms
|
|
|
|
* @subpackage comments
|
|
|
|
*/
|
2007-08-08 08:00:20 +02:00
|
|
|
class CommentTableField extends ComplexTableField {
|
|
|
|
protected $template = "CommentTableField";
|
|
|
|
protected $mode;
|
|
|
|
|
2008-11-13 03:18:49 +01:00
|
|
|
function __construct($controller, $name, $sourceClass, $mode, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "Created", $sourceJoin = "") {
|
2007-08-08 08:00:20 +02:00
|
|
|
$this->mode = $mode;
|
2007-08-10 02:03:30 +02:00
|
|
|
|
2007-08-08 08:00:20 +02:00
|
|
|
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
|
|
|
|
|
2007-08-10 02:03:30 +02:00
|
|
|
$this->Markable = true;
|
2007-08-10 02:46:37 +02:00
|
|
|
$this->setPageSize(15);
|
|
|
|
|
|
|
|
// search
|
2007-08-10 02:03:30 +02:00
|
|
|
$search = isset($_REQUEST['CommentSearch']) ? Convert::raw2sql($_REQUEST['CommentSearch']) : null;
|
|
|
|
if(!empty($_REQUEST['CommentSearch'])) {
|
2008-11-23 01:31:13 +01:00
|
|
|
$this->sourceFilter[] = "( \"Name\" LIKE '%$search%' OR \"Comment\" LIKE '%$search%')";
|
2007-08-10 02:03:30 +02:00
|
|
|
}
|
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::javascript(CMS_DIR . '/javascript/CommentTableField.js');
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
2008-04-26 08:39:10 +02:00
|
|
|
$childId = Convert::raw2sql($_REQUEST['ctf']['childID']);
|
2007-08-08 08:00:20 +02:00
|
|
|
|
|
|
|
if (is_numeric($childId)) {
|
2007-08-13 01:11:37 +02:00
|
|
|
$comment = DataObject::get_by_id($this->sourceClass, $childId);
|
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = true;
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
|
|
|
|
|
|
|
if(SSAkismet::isEnabled()) {
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
}
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ham() {
|
|
|
|
if(!Permission::check('ADMIN')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->methodName = "ham";
|
|
|
|
|
2008-04-26 08:39:10 +02:00
|
|
|
$childId = Convert::raw2sql($_REQUEST['ctf']['childID']);
|
2007-08-08 08:00:20 +02:00
|
|
|
|
|
|
|
if (is_numeric($childId)) {
|
2007-08-13 01:11:37 +02:00
|
|
|
$comment = DataObject::get_by_id($this->sourceClass, $childId);
|
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = false;
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
|
|
|
|
|
|
|
if(SSAkismet::isEnabled()) {
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
}
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
function approve() {
|
2007-08-08 08:00:20 +02:00
|
|
|
if(!Permission::check('ADMIN')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->methodName = "accept";
|
|
|
|
|
2008-04-26 08:39:10 +02:00
|
|
|
$childId = Convert::raw2sql($_REQUEST['ctf']['childID']);
|
2007-08-08 08:00:20 +02:00
|
|
|
|
|
|
|
if(is_numeric($childId)) {
|
|
|
|
$childObject = DataObject::get_by_id($this->sourceClass, $childId);
|
|
|
|
if($childObject) {
|
|
|
|
$childObject->IsSpam = false;
|
|
|
|
$childObject->NeedsModeration = false;
|
|
|
|
$childObject->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function HasSpamButton() {
|
2007-08-13 00:19:06 +02:00
|
|
|
return $this->mode == 'approved' || $this->mode == 'unmoderated';
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
function HasApproveButton() {
|
2007-08-08 08:00:20 +02:00
|
|
|
return $this->mode == 'unmoderated';
|
|
|
|
}
|
|
|
|
|
|
|
|
function HasHamButton() {
|
|
|
|
return $this->mode == 'spam';
|
|
|
|
}
|
|
|
|
|
2007-08-10 00:24:38 +02:00
|
|
|
function SearchForm() {
|
|
|
|
$searchFields = new FieldGroup(
|
2008-02-25 03:10:37 +01:00
|
|
|
new TextField('CommentSearch', _t('CommentTableField.SEARCH', 'Search')),
|
2007-08-10 02:03:30 +02:00
|
|
|
new HiddenField("ctf[ID]",'',$this->mode),
|
|
|
|
new HiddenField('CommentFieldName','',$this->name)
|
2007-08-10 00:24:38 +02:00
|
|
|
);
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
$actionFields = new LiteralField('CommentFilterButton','<input type="submit" name="CommentFilterButton" value="'. _t('CommentTableField.FILTER', 'Filter') .'" id="CommentFilterButton"/>');
|
2007-08-10 00:24:38 +02:00
|
|
|
|
|
|
|
$fieldContainer = new FieldGroup(
|
|
|
|
$searchFields,
|
|
|
|
$actionFields
|
|
|
|
);
|
|
|
|
|
|
|
|
return $fieldContainer->FieldHolder();
|
|
|
|
}
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Single row of a {@link CommentTableField}
|
|
|
|
* @package cms
|
|
|
|
* @subpackage comments
|
|
|
|
*/
|
2007-08-08 08:00:20 +02:00
|
|
|
class CommentTableField_Item extends ComplexTableField_Item {
|
|
|
|
function HasSpamButton() {
|
|
|
|
return $this->parent()->HasSpamButton();
|
|
|
|
}
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
function HasApproveButton() {
|
|
|
|
return $this->parent()->HasApproveButton();
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function HasHamButton() {
|
|
|
|
return $this->parent()->HasHamButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
function SpamLink() {
|
2008-08-28 06:26:59 +02:00
|
|
|
return Controller::join_links($this->Link(), "?methodName=spam");
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function HamLink() {
|
2008-08-28 06:26:59 +02:00
|
|
|
return Controller::join_links($this->Link(), "?methodName=ham");
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
function ApproveLink() {
|
2008-08-28 06:26:59 +02:00
|
|
|
return Controller::join_links($this->Link(), "?methodName=approve");
|
2007-08-08 08:00:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
?>
|