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 {
|
2009-01-20 04:46:29 +01:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
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",
|
2008-12-11 04:34:39 +01:00
|
|
|
"NeedsModeration" => "Boolean",
|
2009-03-11 05:45:41 +01:00
|
|
|
"CommenterURL" => "Varchar(255)",
|
|
|
|
"SessionID" => "Varchar(255)"
|
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
|
|
|
);
|
|
|
|
|
2009-01-20 04:46:29 +01:00
|
|
|
static $has_many = array();
|
|
|
|
|
|
|
|
static $many_many = array();
|
|
|
|
|
|
|
|
static $defaults = array();
|
|
|
|
|
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;
|
2009-01-20 04:46:29 +01:00
|
|
|
|
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() {
|
2009-09-15 05:38:31 +02:00
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain')) ? "PageComment_Controller/deletecomment/$this->ID" : false;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function SpamLink() {
|
2009-09-15 05:38:31 +02:00
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain') && !$this->IsSpam) ? "PageComment_Controller/reportspam/$this->ID" : false;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function HamLink() {
|
2009-09-15 05:38:31 +02:00
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain') && $this->IsSpam) ? "PageComment_Controller/reportham/$this->ID" : false;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
function ApproveLink() {
|
2009-09-15 05:38:31 +02:00
|
|
|
return (Permission::check('CMS_ACCESS_CMSMain') && $this->NeedsModeration) ? "PageComment_Controller/approve/$this->ID" : false;
|
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;
|
|
|
|
}
|
|
|
|
|
2009-04-22 00:25:09 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param boolean $includerelations a boolean value to indicate if the labels returned include relation fields
|
|
|
|
*
|
|
|
|
*/
|
2009-04-21 07:02:01 +02:00
|
|
|
function fieldLabels($includerelations = true) {
|
|
|
|
$labels = parent::fieldLabels($includerelations);
|
2008-11-02 21:04:26 +01:00
|
|
|
$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-12-15 08:04:58 +01:00
|
|
|
/**
|
|
|
|
* This method is called just before this object is
|
|
|
|
* written to the database.
|
|
|
|
*
|
|
|
|
* Specifically, make sure "http://" exists at the start
|
|
|
|
* of the URL, if it doesn't have https:// or http://
|
|
|
|
*/
|
|
|
|
public function onBeforeWrite() {
|
|
|
|
parent::onBeforeWrite();
|
|
|
|
|
|
|
|
$url = $this->CommenterURL;
|
|
|
|
|
|
|
|
if($url) {
|
|
|
|
if(substr($url, 0, 8) != 'https://') {
|
|
|
|
if(substr($url, 0, 7) != 'http://') {
|
|
|
|
$url = $this->CommenterURL = 'http://' . $url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-14 00:54:49 +02:00
|
|
|
$this->CommenterURL = $url;
|
2008-12-15 08:04:58 +01:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-23 06:18:11 +01:00
|
|
|
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']);
|
2009-09-15 05:38:31 +02:00
|
|
|
|
|
|
|
if($comment) {
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2009-09-15 05:38:31 +02:00
|
|
|
// @todo Report to spamprotecter this is true
|
2009-03-11 05:45:41 +01:00
|
|
|
|
2009-09-15 05:38:31 +02:00
|
|
|
if(Director::is_ajax()) {
|
|
|
|
echo $comment->renderWith('PageCommentInterface_singlecomment');
|
|
|
|
} else {
|
|
|
|
Director::redirectBack();
|
|
|
|
}
|
2007-08-10 03:29:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function reportspam() {
|
2009-03-11 05:45:41 +01:00
|
|
|
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
|
|
|
|
if($comment) {
|
|
|
|
// check they have access
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Permission::check('CMS_ACCESS_CMSMain')) {
|
|
|
|
|
2009-03-11 05:45:41 +01:00
|
|
|
// if spam protection module exists
|
2009-06-05 01:40:27 +02:00
|
|
|
if(class_exists('SpamProtectorManager')) {
|
|
|
|
SpamProtectorManager::send_feedback($comment, 'spam');
|
2009-03-11 05:45:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// If Akismet is enabled
|
|
|
|
else if(SSAkismet::isEnabled()) {
|
2007-08-10 03:29:09 +02:00
|
|
|
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
|
|
|
}
|
2009-09-15 05:38:31 +02:00
|
|
|
|
|
|
|
$comment->IsSpam = true;
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
2007-08-10 03:29:09 +02:00
|
|
|
}
|
2009-03-11 05:45:41 +01:00
|
|
|
}
|
|
|
|
if(Director::is_ajax()) {
|
|
|
|
if(SSAkismet::getSaveSpam()) {
|
|
|
|
echo $comment->renderWith('PageCommentInterface_singlecomment');
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
2009-03-11 05:45:41 +01:00
|
|
|
echo '';
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2009-03-11 05:45:41 +01:00
|
|
|
} else {
|
|
|
|
Director::redirectBack();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2009-03-11 05:45:41 +01:00
|
|
|
/**
|
|
|
|
* Report a Spam Comment as valid comment (not spam)
|
|
|
|
*/
|
2007-07-19 12:40:05 +02:00
|
|
|
function reportham() {
|
2009-03-11 05:45:41 +01:00
|
|
|
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
|
|
|
|
if($comment) {
|
2007-08-10 03:29:09 +02:00
|
|
|
if(Permission::check('CMS_ACCESS_CMSMain')) {
|
2009-03-11 05:45:41 +01:00
|
|
|
|
|
|
|
// if spam protection module exists
|
2009-06-05 01:40:27 +02:00
|
|
|
if(class_exists('SpamProtectorManager')) {
|
|
|
|
SpamProtectorManager::send_feedback($comment, 'ham');
|
2009-03-11 05:45:41 +01:00
|
|
|
$comment->setField('IsSpam', false);
|
|
|
|
$comment->write();
|
|
|
|
}
|
2007-08-10 03:29:09 +02:00
|
|
|
|
2009-03-11 05:45:41 +01:00
|
|
|
if(SSAkismet::isEnabled()) {
|
2007-08-10 03:29:09 +02:00
|
|
|
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();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
2009-03-11 05:45:41 +01:00
|
|
|
}
|
|
|
|
if(Director::is_ajax()) {
|
|
|
|
echo $comment->renderWith('PageCommentInterface_singlecomment');
|
|
|
|
} else {
|
|
|
|
Director::redirectBack();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
2008-12-15 08:04:58 +01:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
2008-12-04 23:41:34 +01:00
|
|
|
?>
|