2007-07-19 12:40:05 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Represents a single comment on a page
|
|
|
|
* @package cms
|
|
|
|
* @subpackage comments
|
|
|
|
*/
|
2007-07-19 12:40:05 +02:00
|
|
|
class PageComment extends DataObject {
|
|
|
|
static $db = array(
|
2008-08-18 02:10:26 +02:00
|
|
|
"Name" => "Varchar(200)",
|
2007-07-19 12:40:05 +02:00
|
|
|
"Comment" => "Text",
|
|
|
|
"IsSpam" => "Boolean",
|
2007-08-07 06:32:52 +02:00
|
|
|
"NeedsModeration" => "Boolean"
|
2007-07-19 12:40:05 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
static $has_one = array(
|
|
|
|
"Parent" => "SiteTree",
|
2008-08-12 04:59:27 +02:00
|
|
|
"Author" => "Member" // Only set when the user is logged in when posting
|
2007-07-19 12:40:05 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
static $casting = array(
|
|
|
|
"RSSTitle" => "Varchar",
|
|
|
|
);
|
|
|
|
|
|
|
|
// Number of comments to show before paginating
|
|
|
|
static $comments_per_page = 10;
|
|
|
|
|
2007-08-07 06:32:52 +02:00
|
|
|
static $moderate = false;
|
|
|
|
|
2007-10-02 04:47:02 +02:00
|
|
|
static $bbcode = false;
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
/**
|
|
|
|
* Return a link to this comment
|
|
|
|
* @return string link to this comment.
|
|
|
|
*/
|
|
|
|
function Link() {
|
2007-08-06 03:03:19 +02:00
|
|
|
return $this->Parent()->Link() . '#PageComment_'. $this->ID;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-10-02 04:47:02 +02:00
|
|
|
|
|
|
|
function ParsedBBCode(){
|
|
|
|
$parser = new BBCodeParser($this->Comment);
|
|
|
|
return $parser->parse();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
function DeleteLink() {
|
|
|
|
if(Permission::check('CMS_ACCESS_CMSMain')) {
|
|
|
|
return "PageComment/deletecomment/$this->ID";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function SpamLink() {
|
|
|
|
$member = Member::currentUser();
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Permission::check('CMS_ACCESS_CMSMain') && !$this->getField('IsSpam')) {
|
2007-07-19 12:40:05 +02:00
|
|
|
return "PageComment/reportspam/$this->ID";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function HamLink() {
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) {
|
2007-07-19 12:40:05 +02:00
|
|
|
return "PageComment/reportham/$this->ID";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
function ApproveLink() {
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('NeedsModeration')) {
|
2007-08-13 00:19:06 +02:00
|
|
|
return "PageComment/approve/$this->ID";
|
2007-08-10 03:29:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
function SpamClass() {
|
|
|
|
if($this->getField('IsSpam')) {
|
|
|
|
return 'spam';
|
2007-08-13 01:39:18 +02:00
|
|
|
} else if($this->getField('NeedsModeration')) {
|
|
|
|
return 'unmoderated';
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
|
|
|
return 'notspam';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-26 08:38:48 +02:00
|
|
|
|
|
|
|
function RSSTitle() {
|
|
|
|
return sprintf(
|
|
|
|
_t('PageComment.COMMENTBY', "Comment by '%s' on %s", PR_MEDIUM, 'Name, Page Title'),
|
|
|
|
Convert::raw2xml($this->Name),
|
|
|
|
$this->Parent()->Title
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function PageTitle() {
|
|
|
|
return $this->Parent()->Title;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function enableModeration() {
|
|
|
|
self::$moderate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function moderationEnabled() {
|
|
|
|
return self::$moderate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function enableBBCode() {
|
|
|
|
self::$bbcode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function bbCodeEnabled() {
|
|
|
|
return self::$bbcode;
|
|
|
|
}
|
|
|
|
|
2008-11-02 21:04:26 +01:00
|
|
|
function fieldLabels() {
|
|
|
|
$labels = parent::fieldLabels();
|
|
|
|
$labels['Name'] = _t('PageComment.Name', 'Author Name');
|
|
|
|
$labels['Comment'] = _t('PageComment.Comment', 'Comment');
|
|
|
|
$labels['IsSpam'] = _t('PageComment.IsSpam', 'Spam?');
|
|
|
|
$labels['NeedsModeration'] = _t('PageComment.NeedsModeration', 'Needs Moderation?');
|
|
|
|
|
|
|
|
return $labels;
|
|
|
|
}
|
|
|
|
|
2008-04-26 08:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PageComment_Controller extends Controller {
|
|
|
|
function rss() {
|
|
|
|
$parentcheck = isset($_REQUEST['pageid']) ? "ParentID = " . (int) $_REQUEST['pageid'] : "ParentID > 0";
|
|
|
|
$comments = DataObject::get("PageComment", "$parentcheck AND IsSpam=0", "Created DESC", "", 10);
|
|
|
|
if(!isset($comments)) {
|
|
|
|
$comments = new DataObjectSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
$rss = new RSSFeed($comments, "home/", "Page comments", "", "RSSTitle", "Comment", "Name");
|
|
|
|
$rss->outputToBrowser();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletecomment() {
|
|
|
|
if(Permission::check('CMS_ACCESS_CMSMain')) {
|
|
|
|
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
|
|
|
|
if($comment) {
|
|
|
|
$comment->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Director::is_ajax()) {
|
|
|
|
echo "";
|
|
|
|
} else {
|
|
|
|
Director::redirectBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function approve() {
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Permission::check('CMS_ACCESS_CMSMain')) {
|
2007-07-19 12:40:05 +02:00
|
|
|
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
|
2007-08-10 03:29:09 +02:00
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Director::is_ajax()) {
|
|
|
|
echo $comment->renderWith('PageCommentInterface_singlecomment');
|
|
|
|
} else {
|
|
|
|
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.
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-08-10 03:29:09 +02:00
|
|
|
if(SSAkismet::getSaveSpam()) {
|
|
|
|
$comment->setField('IsSpam', true);
|
|
|
|
$comment->write();
|
|
|
|
} else {
|
|
|
|
$comment->delete();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-08-10 03:29:09 +02:00
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Director::is_ajax()) {
|
2007-07-19 12:40:05 +02:00
|
|
|
if(SSAkismet::getSaveSpam()) {
|
2007-08-10 03:29:09 +02:00
|
|
|
echo $comment->renderWith('PageCommentInterface_singlecomment');
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
2007-08-10 03:29:09 +02:00
|
|
|
echo '';
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
} else {
|
2007-08-10 03:29:09 +02:00
|
|
|
Director::redirectBack();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function reportham() {
|
2007-08-10 03:29:09 +02:00
|
|
|
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->submitHam();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Akismet didn't work, most likely the service is down.
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-08-10 03:29:09 +02:00
|
|
|
$comment->setField('IsSpam', false);
|
|
|
|
$comment->write();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Director::is_ajax()) {
|
|
|
|
echo $comment->renderWith('PageCommentInterface_singlecomment');
|
|
|
|
} else {
|
|
|
|
Director::redirectBack();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
?>
|