diff --git a/_config.php b/_config.php index d4076d79..980948c3 100644 --- a/_config.php +++ b/_config.php @@ -10,7 +10,6 @@ Director::addRules(50, array( 'admin/help//$Action/$ID' => 'CMSHelp', 'admin/bulkload//$Action/$ID/$OtherID' => 'BulkLoaderAdmin', 'admin/cms//$Action/$ID/$OtherID' => 'CMSMain', - 'PageComment//$Action/$ID' => 'PageComment_Controller', 'dev/buildcache/$Action' => 'RebuildStaticCacheTask', )); diff --git a/code/CommentAdmin.php b/code/CommentAdmin.php deleted file mode 100644 index 620430de..00000000 --- a/code/CommentAdmin.php +++ /dev/null @@ -1,320 +0,0 @@ -getEditForm(); - return $form->formHtmlContent(); - } - - public function Section() { - $url = rtrim($_SERVER['REQUEST_URI'], '/'); - if(strrpos($url, '&')) { - $url = substr($url, 0, strrpos($url, '&')); - } - $section = substr($url, strrpos($url, '/') + 1); - - if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') { - $section = Session::get('CommentsSection'); - } - - if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') { - $section = 'approved'; - } - - return $section; - } - - public function getEditForm($id = null) { - $section = $this->Section(); - - if($section == 'approved') { - $filter = "\"IsSpam\" = 0 AND \"NeedsModeration\" = 0"; - $title = "
- * $akismet = new Akismet('http://www.example.com/blog/', 'aoeu1aoue');
- * $akismet->setCommentAuthor($name);
- * $akismet->setCommentAuthorEmail($email);
- * $akismet->setCommentAuthorURL($url);
- * $akismet->setCommentContent($comment);
- * $akismet->setPermalink('http://www.example.com/blog/alex/someurl/');
- * if($akismet->isCommentSpam())
- * // store the comment but mark it as spam (in case of a mis-diagnosis)
- * else
- * // store the comment normally
- *
- *
- * @version 0.2
- * @author Alex Potsides
- * @link http://www.achingbrain.net/
- * @package cms
- * @subpackage comments
- */
-class Akismet
- {
- private $version = '0.2';
- private $wordPressAPIKey;
- private $blogURL;
- private $comment;
- private $apiPort;
- private $akismetServer;
- private $akismetVersion;
-
- // This prevents some potentially sensitive information from being sent accross the wire.
- private $ignore = array('HTTP_COOKIE',
- 'HTTP_X_FORWARDED_FOR',
- 'HTTP_X_FORWARDED_HOST',
- 'HTTP_MAX_FORWARDS',
- 'HTTP_X_FORWARDED_SERVER',
- 'REDIRECT_STATUS',
- 'SERVER_PORT',
- 'PATH',
- 'DOCUMENT_ROOT',
- 'SERVER_ADMIN',
- 'QUERY_STRING',
- 'PHP_SELF' );
-
-
- /**
- * @throws Exception An exception is thrown if your API key is invalid.
- * @param string Your WordPress API key.
- * @param string $blogURL The URL of your blog.
- */
- public function __construct($blogURL, $wordPressAPIKey)
- {
- $this->blogURL = $blogURL;
- $this->wordPressAPIKey = $wordPressAPIKey;
-
- // Set some default values
- $this->apiPort = 80;
- $this->akismetServer = 'rest.akismet.com';
- $this->akismetVersion = '1.1';
-
- // Start to populate the comment data
- $this->comment['blog'] = $blogURL;
- $this->comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
- $this->comment['referrer'] = $_SERVER['HTTP_REFERER'];
-
- // This is necessary if the server PHP5 is running on has been set up to run PHP4 and
- // PHP5 concurently and is actually running through a separate proxy al a these instructions:
- // http://www.schlitt.info/applications/blog/archives/83_How_to_run_PHP4_and_PHP_5_parallel.html
- // and http://wiki.coggeshall.org/37.html
- // Otherwise the user_ip appears as the IP address of the PHP4 server passing the requests to the
- // PHP5 one...
- $this->comment['user_ip'] = $_SERVER['REMOTE_ADDR'] != getenv('SERVER_ADDR') ? $_SERVER['REMOTE_ADDR'] : getenv('HTTP_X_FORWARDED_FOR');
-
- // Check to see if the key is valid
- $response = $this->http_post('key=' . $this->wordPressAPIKey . '&blog=' . $this->blogURL, $this->akismetServer, '/' . $this->akismetVersion . '/verify-key');
-
- if($response[1] != 'valid')
- {
- // Whoops, no it's not. Throw an exception as we can't proceed without a valid API key.
- throw new Exception('Invalid API key. Please obtain one from http://wordpress.com/api-keys/');
- }
- }
-
- private function http_post($request, $host, $path)
- {
- $http_request = "POST " . $path . " HTTP/1.1\r\n";
- $http_request .= "Host: " . $host . "\r\n";
- $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
- $http_request .= "Content-Length: " . strlen($request) . "\r\n";
- $http_request .= "User-Agent: Akismet PHP5 Class " . $this->version . " | Akismet/1.11\r\n";
- $http_request .= "\r\n";
- $http_request .= $request;
-
- $socketWriteRead = new SocketWriteRead($host, $this->apiPort, $http_request);
- $socketWriteRead->send();
-
- return explode("\r\n\r\n", $socketWriteRead->getResponse(), 2);
- }
-
- // Formats the data for transmission echo $sql;
- private function getQueryString()
- {
- foreach($_SERVER as $key => $value)
- {
- if(!in_array($key, $this->ignore))
- {
- if($key == 'REMOTE_ADDR')
- {
- $this->comment[$key] = $this->comment['user_ip'];
- }
- else
- {
- $this->comment[$key] = $value;
- }
- }
- }
-
- $query_string = '';
-
- foreach($this->comment as $key => $data)
- {
- @$query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
- }
-
- return $query_string;
- }
-
- /**
- * Tests for spam.
- *
- * Uses the web service provided by {@link http://www.akismet.com Akismet} to see whether or not the submitted comment is spam. Returns a boolean value.
- *
- * @return bool True if the comment is spam, false if not
- */
- public function isCommentSpam()
- {
- $response = $this->http_post($this->getQueryString(), $this->wordPressAPIKey . '.rest.akismet.com', '/' . $this->akismetVersion . '/comment-check');
-
- return ($response[1] == 'true');
- }
-
- /**
- * Submit spam that is incorrectly tagged as ham.
- *
- * Using this function will make you a good citizen as it helps Akismet to learn from its mistakes. This will improve the service for everybody.
- */
- public function submitSpam()
- {
- $this->http_post($this->getQueryString(), $this->wordPressAPIKey . '.' . $this->akismetServer, '/' . $this->akismetVersion . '/submit-spam');
- }
-
- /**
- * Submit ham that is incorrectly tagged as spam.
- *
- * Using this function will make you a good citizen as it helps Akismet to learn from its mistakes. This will improve the service for everybody.
- */
- public function submitHam()
- {
- $this->http_post($this->getQueryString(), $this->wordPressAPIKey . '.' . $this->akismetServer, '/' . $this->akismetVersion . '/submit-ham');
- }
-
- /**
- * To override the user IP address when submitting spam/ham later on
- *
- * @param string $userip An IP address. Optional.
- */
- public function setUserIP($userip)
- {
- $this->comment['user_ip'] = $userip;
- }
-
- /**
- * To override the referring page when submitting spam/ham later on
- *
- * @param string $referrer The referring page. Optional.
- */
- public function setReferrer($referrer)
- {
- $this->comment['referrer'] = $referrer;
- }
-
- /**
- * A permanent URL referencing the blog post the comment was submitted to.
- *
- * @param string $permalink The URL. Optional.
- */
- public function setPermalink($permalink)
- {
- $this->comment['permalink'] = $permalink;
- }
-
- /**
- * The type of comment being submitted.
- *
- * May be blank, comment, trackback, pingback, or a made up value like "registration" or "wiki".
- */
- public function setCommentType($commentType)
- {
- $this->comment['comment_type'] = $commentType;
- }
-
- /**
- * The name that the author submitted with the comment.
- */
- public function setCommentAuthor($commentAuthor)
- {
- $this->comment['comment_author'] = $commentAuthor;
- }
-
- /**
- * The email address that the author submitted with the comment.
- *
- * The address is assumed to be valid.
- */
- public function setCommentAuthorEmail($authorEmail)
- {
- $this->comment['comment_author_email'] = $authorEmail;
- }
-
- /**
- * The URL that the author submitted with the comment.
- */
- public function setCommentAuthorURL($authorURL)
- {
- $this->comment['comment_author_url'] = $authorURL;
- }
-
- /**
- * The comment's body text.
- */
- public function setCommentContent($commentBody)
- {
- $this->comment['comment_content'] = $commentBody;
- }
-
- /**
- * Defaults to 80
- */
- public function setAPIPort($apiPort)
- {
- $this->apiPort = $apiPort;
- }
-
- /**
- * Defaults to rest.akismet.com
- */
- public function setAkismetServer($akismetServer)
- {
- $this->akismetServer = $akismetServer;
- }
-
- /**
- * Defaults to '1.1'
- */
- public function setAkismetVersion($akismetVersion)
- {
- $this->akismetVersion = $akismetVersion;
- }
- }
-
-/**
- * Utility class used by Akismet
- *
- * This class is used by Akismet to do the actual sending and receiving of data. It opens a connection to a remote host, sends some data and the reads the response and makes it available to the calling program.
- *
- * The code that makes up this class originates in the Akismet WordPress plugin, which is {@link http://akismet.com/download/ available on the Akismet website}.
- *
- * N.B. It is not necessary to call this class directly to use the Akismet class. This is included here mainly out of a sense of completeness.
- *
- * @name SocketWriteRead
- * @version 0.1
- * @author Alex Potsides
- * @link http://www.achingbrain.net/
- * @package cms
- * @subpackage comments
- */
-class SocketWriteRead
- {
- private $host;
- private $port;
- private $request;
- private $response;
- private $responseLength;
- private $errorNumber;
- private $errorString;
-
- /**
- * @param string $host The host to send/receive data.
- * @param int $port The port on the remote host.
- * @param string $request The data to send.
- * @param int $responseLength The amount of data to read. Defaults to 1160 bytes.
- */
- public function __construct($host, $port, $request, $responseLength = 1160)
- {
- $this->host = $host;
- $this->port = $port;
- $this->request = $request;
- $this->responseLength = $responseLength;
- $this->errorNumber = 0;
- $this->errorString = '';
- }
-
- /**
- * Sends the data to the remote host.
- *
- * @throws An exception is thrown if a connection cannot be made to the remote host.
- */
- public function send()
- {
- $this->response = '';
-
- $fs = fsockopen($this->host, $this->port, $this->errorNumber, $this->errorString, 3);
-
- if($this->errorNumber != 0)
- {
- throw new Exception('Error connecting to host: ' . $this->host . ' Error number: ' . $this->errorNumber . ' Error message: ' . $this->errorString);
- }
-
- if($fs !== false)
- {
- @fwrite($fs, $this->request);
-
- while(!feof($fs))
- {
- $this->response .= fgets($fs, $this->responseLength);
- }
-
- fclose($fs);
- }
-
- }
-
- /**
- * Returns the server response text
- *
- * @return string
- */
- public function getResponse()
- {
- return $this->response;
- }
-
- /**
- * Returns the error number
- *
- * If there was no error, 0 will be returned.
- *
- * @return int
- */
- public function getErrorNumner()
- {
- return $this->errorNumber;
- }
-
- /**
- * Returns the error string
- *
- * If there was no error, an empty string will be returned.
- *
- * @return string
- */
- public function getErrorString()
- {
- return $this->errorString;
- }
- }
-?>
\ No newline at end of file
diff --git a/code/sitefeatures/MathSpamProtection.php b/code/sitefeatures/MathSpamProtection.php
deleted file mode 100644
index 4b770610..00000000
--- a/code/sitefeatures/MathSpamProtection.php
+++ /dev/null
@@ -1,91 +0,0 @@
- "Varchar(200)",
- "Comment" => "Text",
- "IsSpam" => "Boolean",
- "NeedsModeration" => "Boolean",
- "CommenterURL" => "Varchar(255)",
- "SessionID" => "Varchar(255)"
- );
-
- static $has_one = array(
- "Parent" => "SiteTree",
- "Author" => "Member" // Only set when the user is logged in when posting
- );
-
- static $has_many = array();
-
- static $many_many = array();
-
- static $defaults = array();
-
- static $casting = array(
- "RSSTitle" => "Varchar",
- );
-
- // Number of comments to show before paginating
- static $comments_per_page = 10;
-
- static $moderate = false;
-
- static $bbcode = false;
-
- /**
- * Return a link to this comment
- * @return string link to this comment.
- */
- function Link() {
- return $this->Parent()->Link() . '#PageComment_'. $this->ID;
- }
-
- function getRSSName() {
- if($this->Name) {
- return $this->Name;
- } elseif($this->Author()) {
- return $this->Author()->getName();
- }
- }
-
- function ParsedBBCode(){
- $parser = new BBCodeParser($this->Comment);
- return $parser->parse();
- }
-
- function DeleteLink() {
- return ($this->canDelete()) ? "PageComment_Controller/deletecomment/$this->ID" : false;
- }
-
- function CommentTextWithLinks() {
- $pattern = '|([a-zA-Z]+://)([a-zA-Z0-9?&%.;:/=+_-]*)|is';
- $replace = '$1$2';
- return preg_replace($pattern, $replace, $this->Comment);
- }
-
- function SpamLink() {
- return ($this->canEdit() && !$this->IsSpam) ? "PageComment_Controller/reportspam/$this->ID" : false;
- }
-
- function HamLink() {
- return ($this->canEdit() && $this->IsSpam) ? "PageComment_Controller/reportham/$this->ID" : false;
- }
-
- function ApproveLink() {
- return ($this->canEdit() && $this->NeedsModeration) ? "PageComment_Controller/approve/$this->ID" : false;
- }
-
- function SpamClass() {
- if($this->getField('IsSpam')) {
- return 'spam';
- } else if($this->getField('NeedsModeration')) {
- return 'unmoderated';
- } else {
- return 'notspam';
- }
- }
-
-
- function RSSTitle() {
- return sprintf(
- _t('PageComment.COMMENTBY', "Comment by '%s' on %s", PR_MEDIUM, 'Name, Page Title'),
- Convert::raw2xml($this->getRSSName()),
- $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;
- }
-
- /**
- *
- * @param boolean $includerelations a boolean value to indicate if the labels returned include relation fields
- *
- */
- function fieldLabels($includerelations = true) {
- $labels = parent::fieldLabels($includerelations);
- $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;
- }
-
- /**
- * 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(strtolower(substr($url, 0, 8)) != 'https://' && strtolower(substr($url, 0, 7)) != 'http://') {
- $this->CommenterURL = 'http://' . $url;
- }
- }
- }
-
- /**
- * This always returns true, and should be handled by {@link PageCommentInterface->CanPostComment()}.
- *
- * @todo Integrate with PageCommentInterface::$comments_require_permission and $comments_require_login
- *
- * @param Member $member
- * @return Boolean
- */
- function canCreate($member = null) {
- return true;
- }
-
- /**
- * Checks for association with a page,
- * and {@link SiteTree->ProvidePermission} flag being set to TRUE.
- * Note: There's an additional layer of permission control
- * in {@link PageCommentInterface}.
- *
- * @param Member $member
- * @return Boolean
- */
- function canView($member = null) {
- if(!$member) $member = Member::currentUser();
-
- // Standard mechanism for accepting permission changes from decorators
- $extended = $this->extendedCan('canView', $member);
- if($extended !== null) return $extended;
-
- $page = $this->Parent();
- return (
- ($page && $page->ProvideComments)
- || (bool)Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin')
- );
- }
-
- /**
- * Checks for "CMS_ACCESS_CommentAdmin" permission codes
- * and {@link canView()}.
- *
- * @param Member $member
- * @return Boolean
- */
- function canEdit($member = null) {
- if(!$member) $member = Member::currentUser();
-
- // Standard mechanism for accepting permission changes from decorators
- $extended = $this->extendedCan('canEdit', $member);
- if($extended !== null) return $extended;
-
- if(!$this->canView($member)) return false;
-
- return (bool)Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin');
- }
-
- /**
- * Checks for "CMS_ACCESS_CommentAdmin" permission codes
- * and {@link canEdit()}.
- *
- * @param Member $member
- * @return Boolean
- */
- function canDelete($member = null) {
- if(!$member) $member = Member::currentUser();
-
- // Standard mechanism for accepting permission changes from decorators
- $extended = $this->extendedCan('canDelete', $member);
- if($extended !== null) return $extended;
-
- return $this->canEdit($member);
- }
-}
-
-
-/**
- * @package cms
- * @subpackage comments
- */
-class PageComment_Controller extends Controller {
- function rss() {
- $parentcheck = isset($_REQUEST['pageid']) ? "\"ParentID\" = " . (int) $_REQUEST['pageid'] : "\"ParentID\" > 0";
- $unmoderatedfilter = Permission::check('ADMIN') ? '' : "AND \"NeedsModeration\" = 0";
- $comments = DataObject::get("PageComment", "$parentcheck AND \"IsSpam\" = 0 $unmoderatedfilter", "\"Created\" DESC", "", 10);
- if(!isset($comments)) {
- $comments = new DataObjectSet();
- }
-
- $rss = new RSSFeed($comments, "home/", "Page comments", "", "RSSTitle", "Comment", "RSSName");
- $rss->outputToBrowser();
- }
-
- /**
- * Deletes all comments on the page referenced by the url param pageid
- */
- function deleteallcomments() {
- $pageId = $_REQUEST['pageid'];
- if(preg_match('/^\d+$/', $pageId)) {
- $comments = DataObject::get("PageComment", "\"ParentID\" = $pageId");
- if($comments) foreach($comments as $c) {
- if($c->canDelete()) $c->delete();
- }
- }
-
- if($this->isAjax()) {
- echo "";
- } else {
- $this->redirectBack();
- }
- }
-
- function deletecomment() {
- $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
- if($comment && $comment->canDelete()) {
- $comment->delete();
- }
-
- if($this->isAjax()) {
- echo "";
- } else {
- $this->redirectBack();
- }
- }
-
- function approve() {
- $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
-
- if($comment && $comment->canEdit()) {
- $comment->NeedsModeration = false;
- $comment->write();
-
- // @todo Report to spamprotecter this is true
-
- if($this->isAjax()) {
- echo $comment->renderWith('PageCommentInterface_singlecomment');
- } else {
- Director::redirectBack();
- }
- }
- }
-
- function reportspam() {
- $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
- if($comment && $comment->canEdit()) {
- // if spam protection module exists
- if(class_exists('SpamProtectorManager')) {
- SpamProtectorManager::send_feedback($comment, 'spam');
- }
-
- // If Akismet is enabled
- else 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.
- }
- }
-
- $comment->IsSpam = true;
- $comment->NeedsModeration = false;
- $comment->write();
- }
- if($this->isAjax()) {
- if(SSAkismet::isEnabled() && SSAkismet::getSaveSpam()) {
- echo $comment->renderWith('PageCommentInterface_singlecomment');
- } else {
- echo '';
- }
- } else {
- $this->redirectBack();
- }
- }
- /**
- * Report a Spam Comment as valid comment (not spam)
- */
- function reportham() {
- $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
- if($comment && $comment->canEdit()) {
- // if spam protection module exists
- if(class_exists('SpamProtectorManager')) {
- SpamProtectorManager::send_feedback($comment, 'ham');
- }
-
- 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.
- }
- }
- $comment->setField('IsSpam', false);
- $comment->write();
- }
- if($this->isAjax()) {
- echo $comment->renderWith('PageCommentInterface_singlecomment');
- } else {
- $this->redirectBack();
- }
- }
-
-}
-
-?>
\ No newline at end of file
diff --git a/code/sitefeatures/PageCommentInterface.php b/code/sitefeatures/PageCommentInterface.php
deleted file mode 100755
index 83f4641e..00000000
--- a/code/sitefeatures/PageCommentInterface.php
+++ /dev/null
@@ -1,377 +0,0 @@
- '$Item',
- );
- static $allowed_actions = array(
- 'PostCommentForm',
- );
-
- protected $controller, $methodName, $page;
-
- /**
- * If this is true, you must be logged in to post a comment
- * (and therefore, you don't need to specify a 'Your name' field unless
- * your name is blank)
- *
- * @var bool
- */
- static $comments_require_login = false;
-
- /**
- * If this is a valid permission code, you must be logged in
- * and have the appropriate permission code on your account before you can
- * post a comment.
- *
- * @var string
- */
- static $comments_require_permission = "";
-
- /**
- * If this is true it will include the javascript for AJAX
- * commenting. If it is set to false then it will not load
- * the files required and it will fall back
- *
- * @var bool
- */
- static $use_ajax_commenting = true;
-
- /**
- * If this is true then we should show the existing comments on
- * the page even when we have disabled the comment form.
- *
- * If this is false the form + existing comments will be hidden
- *
- * @var bool
- * @since 2.4 - Always show them by default
- */
- static $show_comments_when_disabled = true;
-
- /**
- * Define how you want to order page comments by. By default order by newest
- * to oldest.
- *
- * @var String - used as $orderby in DB query
- * @since 2.4
- */
- static $order_comments_by = "\"Created\" DESC";
-
- /**
- * Create a new page comment interface
- * @param controller The controller that the interface is used on
- * @param methodName The method to return this PageCommentInterface object
- * @param page The page that we're commenting on
- */
- function __construct($controller, $methodName, $page) {
- $this->controller = $controller;
- $this->methodName = $methodName;
- $this->page = $page;
- parent::__construct();
- }
-
- function Link() {
- return Controller::join_links($this->controller->Link(), $this->methodName);
- }
-
- /**
- * See {@link PageCommentInterface::$comments_require_login}
- *
- * @param boolean state The new state of this static field
- */
- static function set_comments_require_login($state) {
- self::$comments_require_login = (boolean) $state;
- }
-
- /**
- * See {@link PageCommentInterface::$comments_require_permission}
- *
- * @param string permission The permission to check against.
- */
- static function set_comments_require_permission($permission) {
- self::$comments_require_permission = $permission;
- }
-
- /**
- * See {@link PageCommentInterface::$show_comments_when_disabled}
- *
- * @param bool - show / hide the existing comments when disabled
- */
- static function set_show_comments_when_disabled($state) {
- self::$show_comments_when_disabled = $state;
- }
-
- /**
- * See {@link PageCommentInterface::$order_comments_by}
- *
- * @param String
- */
- static function set_order_comments_by($order) {
- self::$order_comments_by = $order;
- }
-
- /**
- * See {@link PageCommentInterface::$use_ajax_commenting}
- *
- * @param bool
- */
- static function set_use_ajax_commenting($state) {
- self::$use_ajax_commenting = $state;
- }
-
- function forTemplate() {
- return $this->renderWith('PageCommentInterface');
- }
-
- /**
- * @return boolean true if the currently logged in user can post a comment,
- * false if they can't. Users can post comments by default, enforce
- * security by using
- * @link PageCommentInterface::set_comments_require_login() and
- * @link {PageCommentInterface::set_comments_require_permission()}.
- */
- static function CanPostComment() {
- $member = Member::currentUser();
- if(self::$comments_require_permission && $member && Permission::check(self::$comments_require_permission)) {
- return true; // Comments require a certain permission, and the user has the correct permission
- } elseif(self::$comments_require_login && $member && !self::$comments_require_permission) {
- return true; // Comments only require that a member is logged in
- } elseif(!self::$comments_require_permission && !self::$comments_require_login) {
- return true; // Comments don't require anything - anyone can add a comment
- }
-
- return false;
- }
-
- /**
- * if this page comment form requires users to have a
- * valid permission code in order to post (used to customize the error
- * message).
- *
- * @return bool
- */
- function PostingRequiresPermission() {
- return self::$comments_require_permission;
- }
-
- function Page() {
- return $this->page;
- }
-
- function PostCommentForm() {
- if(!$this->page->ProvideComments){
- return false;
- }
- $fields = new FieldSet(
- new HiddenField("ParentID", "ParentID", $this->page->ID)
- );
-
- $member = Member::currentUser();
-
- if((self::$comments_require_login || self::$comments_require_permission) && $member && $member->FirstName) {
- // note this was a ReadonlyField - which displayed the name in a span as well as the hidden field but
- // it was not saving correctly. Have changed it to a hidden field. It passes the data correctly but I
- // believe the id of the form field is wrong.
- $fields->push(new ReadonlyField("NameView", _t('PageCommentInterface.YOURNAME', 'Your name'), $member->getName()));
- $fields->push(new HiddenField("Name", "", $member->getName()));
- } else {
- $fields->push(new TextField("Name", _t('PageCommentInterface.YOURNAME', 'Your name')));
- }
-
- // optional commenter URL
- $fields->push(new TextField("CommenterURL", _t('PageCommentInterface.COMMENTERURL', "Your website URL")));
-
- if(MathSpamProtection::isEnabled()){
- $fields->push(new TextField("Math", sprintf(_t('PageCommentInterface.SPAMQUESTION', "Spam protection question: %s"), MathSpamProtection::getMathQuestion())));
- }
-
- $fields->push(new TextareaField("Comment", _t('PageCommentInterface.YOURCOMMENT', "Comments")));
-
- $form = new PageCommentInterface_Form($this, "PostCommentForm", $fields, new FieldSet(
- new FormAction("postcomment", _t('PageCommentInterface.POST', 'Post'))), new RequiredFields('Name', 'Comment'));
-
- // Set it so the user gets redirected back down to the form upon form fail
- $form->setRedirectToFormOnValidationError(true);
-
- // Optional Spam Protection.
- if(class_exists('SpamProtectorManager')) {
- SpamProtectorManager::update_form($form, null, array('Name' => 'author_name', 'CommenterURL' => 'author_url', 'Comment' => 'post_body'));
- self::set_use_ajax_commenting(false);
- }
-
- // Shall We use AJAX?
- if(self::$use_ajax_commenting) {
- Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js');
- Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js');
- Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/effects.js');
- Requirements::javascript(CMS_DIR . '/javascript/PageCommentInterface.js');
- }
-
- $this->extend('updatePageCommentForm', $form);
-
- // Load the users data from a cookie
- if($cookie = Cookie::get("PageCommentInterface_Data")) {
- $form->loadDataFrom(unserialize($cookie));
- }
-
- return $form;
- }
-
- function Comments() {
- // Comment limits
- $limit = array();
- $limit['start'] = isset($_GET['commentStart']) ? (int)$_GET['commentStart'] : 0;
- $limit['limit'] = PageComment::$comments_per_page;
-
- $spamfilter = isset($_GET['showspam']) ? '' : "AND \"IsSpam\" = 0";
- $unmoderatedfilter = Permission::check('CMS_ACCESS_CommentAdmin') ? '' : "AND \"NeedsModeration\" = 0";
- $order = self::$order_comments_by;
- $comments = DataObject::get("PageComment", "\"ParentID\" = '" . Convert::raw2sql($this->page->ID) . "' $spamfilter $unmoderatedfilter", $order, "", $limit);
-
- if(is_null($comments)) {
- return;
- }
-
- // This allows us to use the normal 'start' GET variables as well (In the weird circumstance where you have paginated comments AND something else paginated)
- $comments->setPaginationGetVar('commentStart');
-
- return $comments;
- }
-
- function CommentRssLink() {
- return Director::absoluteBaseURL() . "PageComment/rss?pageid=" . $this->page->ID;
- }
-
- /**
- * A link to PageComment_Controller.deleteallcomments() which deletes all
- * comments on a page referenced by the url param pageid
- */
- function DeleteAllLink() {
- if(Permission::check('CMS_ACCESS_CommentAdmin')) {
- return Director::absoluteBaseURL() . "PageComment/deleteallcomments?pageid=" . $this->page->ID;
- }
- }
-
-}
-
-/**
- * @package cms
- * @subpackage comments
- */
-class PageCommentInterface_Form extends Form {
- function postcomment($data) {
- Cookie::set("PageCommentInterface_Data", serialize($data));
-
- // Spam filtering
- if(SSAkismet::isEnabled()) {
- try {
- $akismet = new SSAkismet();
-
- $akismet->setCommentAuthor($data['Name']);
- $akismet->setCommentContent($data['Comment']);
-
- if($akismet->isCommentSpam()) {
- if(SSAkismet::getSaveSpam()) {
- $comment = Object::create('PageComment');
- $this->saveInto($comment);
- $comment->setField("IsSpam", true);
- $comment->write();
- }
- echo ""._t('PageCommentInterface_Form.SPAMDETECTED', 'Spam detected!!') . "Loading...
'; - - - // Submit the form via ajax - Ajax.SubmitForm(form, "action_postcomment", { - onSuccess : function(response) { - - // Create an Ajax request to regenerate the spam protection question - //need to check if there is actually a spam question to change first - if(form.elements.Math){ - new Ajax.Request(document.getElementsByTagName('base')[0].href+'PageCommentInterface_Controller/newspamquestion', { - onSuccess: loadSpamQuestion, - onFailure: Ajax.Evaluator - }); - } - - if(response.responseText != "spamprotectionfailed"){ - __newComment.className ="even"; - // Load the response into the newNo one has commented on this page yet.
"; - } - } - } ); - }, - - onFailure : function(response) { - alert(response.responseText); - } - }); - - return false; - }, - - /** - * Ajax handler of spam reporting - */ - reportSpam: function() { - var __comment = this.parentNode.parentNode.parentNode.parentNode; - - __comment.getElementsByTagName('span')[0].innerHTML = "Reporting spam..."; - - - new Ajax.Request(this.href + '?ajax=1', { - onSuccess : function(response) { - if(response.responseText != '') { - // Load the response into theNo one has commented on this page yet.
"; - } - } - } ); - } - }, - - onFailure : function(response) { - alert(response.responseText); - } - }); - - return false; - }, - - /** - * Ajax handler of ham reporting - */ - reportHam: function() { - var __comment = this.parentNode.parentNode.parentNode.parentNode; - - __comment.getElementsByTagName('span')[0].innerHTML = "Reporting as not spam..."; - - new Ajax.Request(this.href + '?ajax=1', { - onSuccess : function(response) { - // Load the response into the<% _t('COMMENTLOGINERROR', 'You cannot post comments until you have logged in') %><% if PostingRequiresPermission %>,<% _t('COMMENTPERMISSIONERROR', 'and that you have an appropriate permission level') %><% end_if %>. - <% _t('COMMENTPOSTLOGIN', 'Login Here') %>. -
- <% end_if %> - <% else %> -<% _t('COMMENTSDISABLED', 'Posting comments has been disabled') %>.
- <% end_if %> - -- <% if Comments.PrevLink %> - « <% _t('PREV','previous') %> - <% end_if %> - - <% if Comments.Pages %> - <% control Comments.Pages %> - <% if CurrentBool %> - $PageNum - <% else %> - $PageNum - <% end_if %> - <% end_control %> - <% end_if %> - - <% if Comments.NextLink %> - <% _t('NEXT','next') %> » - <% end_if %> -
-<% _t('NOCOMMENTSYET','No one has commented on this page yet.') %>
- <% end_if %> -- <% _t('PageCommentInterface.DELETEALLCOMMENTS','Delete all comments on this page') %> -
- <% end_if %> -- <% _t('RSSFEEDCOMMENTS', 'RSS feed for comments on this page') %> | - <% _t('RSSFEEDALLCOMMENTS', 'RSS feed for all comments') %> -
-- <% if bbCodeEnabled %> - $ParsedBBCode - <% else %> - $Comment.XML - <% end_if %> -
-- <% if CommenterURL %> - <% _t('PBY','Posted by') %> $Name.XML, $Created.Nice ($Created.Ago) - <% else %> - <% _t('PBY','Posted by') %> $Name.XML, $Created.Nice ($Created.Ago) - <% end_if %> -
- -