2010-12-06 11:08:38 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
namespace SilverStripe\Comments\Controllers;
|
|
|
|
|
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\Comments\Extensions\CommentsExtension;
|
2018-09-24 18:16:03 +02:00
|
|
|
use SilverStripe\Comments\Forms\CommentForm;
|
2017-01-16 20:57:37 +01:00
|
|
|
use SilverStripe\Comments\Model\Comment;
|
|
|
|
use SilverStripe\Control\Controller;
|
2018-09-24 18:16:03 +02:00
|
|
|
use SilverStripe\Control\Director;
|
2017-01-16 20:57:37 +01:00
|
|
|
use SilverStripe\Control\HTTP;
|
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2018-09-24 18:16:03 +02:00
|
|
|
use SilverStripe\Control\HTTPResponse;
|
|
|
|
use SilverStripe\Control\HTTPResponse_Exception;
|
2017-01-16 20:57:37 +01:00
|
|
|
use SilverStripe\Control\RSS\RSSFeed;
|
2018-09-24 18:16:03 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
use SilverStripe\Forms\Form;
|
2017-01-16 20:57:37 +01:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2018-09-24 18:16:03 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
2017-01-16 20:57:37 +01:00
|
|
|
use SilverStripe\ORM\PaginatedList;
|
|
|
|
use SilverStripe\Security\Security;
|
|
|
|
|
2010-12-06 11:08:38 +01:00
|
|
|
/**
|
|
|
|
* @package comments
|
|
|
|
*/
|
2016-02-19 01:48:25 +01:00
|
|
|
class CommentingController extends Controller
|
|
|
|
{
|
2017-01-16 20:57:37 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2018-09-24 18:16:03 +02:00
|
|
|
private static $allowed_actions = [
|
2016-02-19 01:48:25 +01:00
|
|
|
'delete',
|
|
|
|
'spam',
|
|
|
|
'ham',
|
|
|
|
'approve',
|
|
|
|
'rss',
|
|
|
|
'CommentsForm',
|
|
|
|
'reply',
|
|
|
|
'doPostComment',
|
2018-09-24 18:16:03 +02:00
|
|
|
'doPreviewComment',
|
|
|
|
];
|
2016-02-19 01:48:25 +01:00
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2018-09-24 18:16:03 +02:00
|
|
|
private static $url_handlers = [
|
2016-02-19 01:48:25 +01:00
|
|
|
'reply/$ParentCommentID//$ID/$OtherID' => 'reply',
|
2018-09-24 18:16:03 +02:00
|
|
|
];
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fields required for this form
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @config
|
|
|
|
*/
|
2018-09-24 18:16:03 +02:00
|
|
|
private static $required_fields = [
|
2016-02-19 01:48:25 +01:00
|
|
|
'Name',
|
|
|
|
'Email',
|
2018-09-24 18:16:03 +02:00
|
|
|
'Comment',
|
|
|
|
];
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-16 20:57:37 +01:00
|
|
|
* Parent class this commenting form is for
|
2016-02-19 01:48:25 +01:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-01-16 20:57:37 +01:00
|
|
|
private $parentClass = '';
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The record this commenting form is for
|
|
|
|
*
|
|
|
|
* @var DataObject
|
|
|
|
*/
|
2018-09-24 18:16:03 +02:00
|
|
|
private $ownerRecord;
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parent controller record
|
|
|
|
*
|
|
|
|
* @var Controller
|
|
|
|
*/
|
2018-09-24 18:16:03 +02:00
|
|
|
private $ownerController;
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Backup url to return to
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2018-09-24 18:16:03 +02:00
|
|
|
protected $fallbackReturnURL;
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-16 20:57:37 +01:00
|
|
|
* Set the parent class name to use
|
2016-02-19 01:48:25 +01:00
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
*/
|
2017-01-16 20:57:37 +01:00
|
|
|
public function setParentClass($class)
|
2016-02-19 01:48:25 +01:00
|
|
|
{
|
2017-01-16 20:57:37 +01:00
|
|
|
$this->parentClass = $this->encodeClassName($class);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 20:57:37 +01:00
|
|
|
* Get the parent class name used
|
2016-02-19 01:48:25 +01:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-16 20:57:37 +01:00
|
|
|
public function getParentClass()
|
2016-02-19 01:48:25 +01:00
|
|
|
{
|
2017-01-16 20:57:37 +01:00
|
|
|
return $this->decodeClassName($this->parentClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encode a fully qualified class name to a URL-safe version
|
|
|
|
*
|
|
|
|
* @param string $input
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function encodeClassName($input)
|
|
|
|
{
|
|
|
|
return str_replace('\\', '-', $input);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode an "encoded" fully qualified class name back to its original
|
|
|
|
*
|
|
|
|
* @param string $input
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function decodeClassName($input)
|
|
|
|
{
|
|
|
|
return str_replace('-', '\\', $input);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the record this controller is working on
|
|
|
|
*
|
|
|
|
* @param DataObject $record
|
|
|
|
*/
|
|
|
|
public function setOwnerRecord($record)
|
|
|
|
{
|
|
|
|
$this->ownerRecord = $record;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the record
|
|
|
|
*
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function getOwnerRecord()
|
|
|
|
{
|
|
|
|
return $this->ownerRecord;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the parent controller
|
|
|
|
*
|
|
|
|
* @param Controller $controller
|
|
|
|
*/
|
|
|
|
public function setOwnerController($controller)
|
|
|
|
{
|
|
|
|
$this->ownerController = $controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the parent controller
|
|
|
|
*
|
|
|
|
* @return Controller
|
|
|
|
*/
|
|
|
|
public function getOwnerController()
|
|
|
|
{
|
|
|
|
return $this->ownerController;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the commenting option for the current state
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @return mixed Result if the setting is available, or null otherwise
|
|
|
|
*/
|
|
|
|
public function getOption($key)
|
|
|
|
{
|
|
|
|
// If possible use the current record
|
|
|
|
if ($record = $this->getOwnerRecord()) {
|
2018-09-24 18:16:03 +02:00
|
|
|
/** @var DataObject|CommentsExtension $record */
|
2016-02-19 01:48:25 +01:00
|
|
|
return $record->getCommentsOption($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise a singleton of that record
|
2017-01-16 20:57:37 +01:00
|
|
|
if ($class = $this->getParentClass()) {
|
2016-02-19 01:48:25 +01:00
|
|
|
return singleton($class)->getCommentsOption($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise just use the default options
|
2017-01-16 20:57:37 +01:00
|
|
|
return singleton(CommentsExtension::class)->getCommentsOption($key);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
/**
|
|
|
|
* Returns all the commenting options for the current instance.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getOptions()
|
|
|
|
{
|
|
|
|
if ($record = $this->getOwnerRecord()) {
|
2018-09-24 18:16:03 +02:00
|
|
|
/** @var DataObject|CommentsExtension $record */
|
2017-09-18 04:16:24 +02:00
|
|
|
return $record->getCommentsOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise a singleton of that record
|
|
|
|
if ($class = $this->getParentClass()) {
|
|
|
|
return singleton($class)->getCommentsOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise just use the default options
|
|
|
|
return singleton(CommentsExtension::class)->getCommentsOptions();
|
|
|
|
}
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
/**
|
|
|
|
* Workaround for generating the link to this controller
|
|
|
|
*
|
2017-01-16 20:57:37 +01:00
|
|
|
* @param string $action
|
|
|
|
* @param int $id
|
|
|
|
* @param string $other
|
2016-02-19 01:48:25 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function Link($action = '', $id = '', $other = '')
|
|
|
|
{
|
2017-01-16 20:57:37 +01:00
|
|
|
return Controller::join_links(Director::baseURL(), 'comments', $action, $id, $other);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the RSS feed of comments
|
|
|
|
*
|
2018-09-24 18:16:03 +02:00
|
|
|
* @return DBHTMLText
|
2016-02-19 01:48:25 +01:00
|
|
|
*/
|
|
|
|
public function rss()
|
|
|
|
{
|
|
|
|
return $this->getFeed($this->request)->outputToBrowser();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an RSSFeed of comments for a given set of comments or all
|
|
|
|
* comments on the website.
|
|
|
|
*
|
2017-01-16 20:57:37 +01:00
|
|
|
* @param HTTPRequest
|
2016-02-19 01:48:25 +01:00
|
|
|
*
|
|
|
|
* @return RSSFeed
|
|
|
|
*/
|
2017-01-16 20:57:37 +01:00
|
|
|
public function getFeed(HTTPRequest $request)
|
2016-02-19 01:48:25 +01:00
|
|
|
{
|
|
|
|
$link = $this->Link('rss');
|
2017-01-16 20:57:37 +01:00
|
|
|
$class = $this->decodeClassName($request->param('ID'));
|
2016-02-19 01:48:25 +01:00
|
|
|
$id = $request->param('OtherID');
|
|
|
|
|
|
|
|
// Support old pageid param
|
|
|
|
if (!$id && !$class && ($id = $request->getVar('pageid'))) {
|
2017-01-16 20:57:37 +01:00
|
|
|
$class = SiteTree::class;
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
2018-09-24 18:16:03 +02:00
|
|
|
$comments = Comment::get()->filter([
|
2016-02-19 01:48:25 +01:00
|
|
|
'Moderated' => 1,
|
|
|
|
'IsSpam' => 0,
|
2018-09-24 18:16:03 +02:00
|
|
|
]);
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
// Check if class filter
|
|
|
|
if ($class) {
|
2017-01-16 20:57:37 +01:00
|
|
|
if (!is_subclass_of($class, DataObject::class) || !$class::has_extension(CommentsExtension::class)) {
|
2016-02-19 01:48:25 +01:00
|
|
|
return $this->httpError(404);
|
|
|
|
}
|
2017-01-16 20:57:37 +01:00
|
|
|
$this->setParentClass($class);
|
|
|
|
$comments = $comments->filter('ParentClass', $class);
|
|
|
|
$link = Controller::join_links($link, $this->encodeClassName($class));
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
// Check if id filter
|
|
|
|
if ($id) {
|
|
|
|
$comments = $comments->filter('ParentID', $id);
|
|
|
|
$link = Controller::join_links($link, $id);
|
|
|
|
$this->setOwnerRecord(DataObject::get_by_id($class, $id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 01:04:34 +01:00
|
|
|
$title = _t(__CLASS__ . '.RSSTITLE', "Comments RSS Feed");
|
2018-09-24 18:16:03 +02:00
|
|
|
$comments = PaginatedList::create($comments, $request);
|
2016-02-19 01:48:25 +01:00
|
|
|
$comments->setPageLength($this->getOption('comments_per_page'));
|
|
|
|
|
2018-09-24 18:16:03 +02:00
|
|
|
return RSSFeed::create(
|
2016-02-19 01:48:25 +01:00
|
|
|
$comments,
|
|
|
|
$link,
|
|
|
|
$title,
|
|
|
|
$link,
|
2017-01-16 20:57:37 +01:00
|
|
|
'Title',
|
|
|
|
'EscapedComment',
|
|
|
|
'AuthorName'
|
2016-02-19 01:48:25 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a given {@link Comment} via the URL.
|
|
|
|
*/
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$comment = $this->getComment();
|
|
|
|
if (!$comment) {
|
|
|
|
return $this->httpError(404);
|
|
|
|
}
|
|
|
|
if (!$comment->canDelete()) {
|
|
|
|
return Security::permissionFailure($this, 'You do not have permission to delete this comment');
|
|
|
|
}
|
|
|
|
if (!$comment->getSecurityToken()->checkRequest($this->request)) {
|
|
|
|
return $this->httpError(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
$comment->delete();
|
|
|
|
|
|
|
|
return $this->request->isAjax()
|
|
|
|
? true
|
|
|
|
: $this->redirectBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks a given {@link Comment} as spam. Removes the comment from display
|
|
|
|
*/
|
|
|
|
public function spam()
|
|
|
|
{
|
|
|
|
$comment = $this->getComment();
|
|
|
|
if (!$comment) {
|
|
|
|
return $this->httpError(404);
|
|
|
|
}
|
|
|
|
if (!$comment->canEdit()) {
|
|
|
|
return Security::permissionFailure($this, 'You do not have permission to edit this comment');
|
|
|
|
}
|
|
|
|
if (!$comment->getSecurityToken()->checkRequest($this->request)) {
|
|
|
|
return $this->httpError(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
$comment->markSpam();
|
2016-02-10 09:47:24 +01:00
|
|
|
return $this->renderChangedCommentState($comment);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks a given {@link Comment} as ham (not spam).
|
|
|
|
*/
|
|
|
|
public function ham()
|
|
|
|
{
|
|
|
|
$comment = $this->getComment();
|
|
|
|
if (!$comment) {
|
|
|
|
return $this->httpError(404);
|
|
|
|
}
|
|
|
|
if (!$comment->canEdit()) {
|
|
|
|
return Security::permissionFailure($this, 'You do not have permission to edit this comment');
|
|
|
|
}
|
|
|
|
if (!$comment->getSecurityToken()->checkRequest($this->request)) {
|
|
|
|
return $this->httpError(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
$comment->markApproved();
|
2016-02-10 09:47:24 +01:00
|
|
|
return $this->renderChangedCommentState($comment);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks a given {@link Comment} as approved.
|
|
|
|
*/
|
|
|
|
public function approve()
|
|
|
|
{
|
|
|
|
$comment = $this->getComment();
|
|
|
|
if (!$comment) {
|
|
|
|
return $this->httpError(404);
|
|
|
|
}
|
|
|
|
if (!$comment->canEdit()) {
|
|
|
|
return Security::permissionFailure($this, 'You do not have permission to approve this comment');
|
|
|
|
}
|
|
|
|
if (!$comment->getSecurityToken()->checkRequest($this->request)) {
|
|
|
|
return $this->httpError(400);
|
|
|
|
}
|
|
|
|
$comment->markApproved();
|
2016-02-10 09:47:24 +01:00
|
|
|
return $this->renderChangedCommentState($comment);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-02-10 09:47:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect back to referer if available, ensuring that only site URLs
|
|
|
|
* are allowed to avoid phishing. If it's an AJAX request render the
|
|
|
|
* comment in it's new state
|
2018-09-24 18:16:03 +02:00
|
|
|
*
|
|
|
|
* @param Comment $comment
|
|
|
|
* @return DBHTMLText|HTTPResponse|false
|
2016-02-10 09:47:24 +01:00
|
|
|
*/
|
2016-02-19 01:48:25 +01:00
|
|
|
private function renderChangedCommentState($comment)
|
|
|
|
{
|
2016-02-10 09:47:24 +01:00
|
|
|
$referer = $this->request->getHeader('Referer');
|
|
|
|
|
|
|
|
// Render comment using AJAX
|
|
|
|
if ($this->request->isAjax()) {
|
2017-01-16 20:57:37 +01:00
|
|
|
return $comment->renderWith('Includes/CommentsInterface_singlecomment');
|
2016-02-10 09:47:24 +01:00
|
|
|
}
|
2018-09-24 18:16:03 +02:00
|
|
|
|
|
|
|
// Redirect to either the comment or start of the page
|
|
|
|
if (empty($referer)) {
|
|
|
|
return $this->redirectBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect to the comment, but check for phishing
|
|
|
|
$url = $referer . '#comment-' . $comment->ID;
|
|
|
|
// absolute redirection URLs not located on this site may cause phishing
|
|
|
|
if (Director::is_site_url($url)) {
|
|
|
|
return $this->redirect($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-02-10 09:47:24 +01:00
|
|
|
}
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
/**
|
|
|
|
* Returns the comment referenced in the URL (by ID). Permission checking
|
|
|
|
* should be done in the callee.
|
|
|
|
*
|
|
|
|
* @return Comment|false
|
|
|
|
*/
|
|
|
|
public function getComment()
|
|
|
|
{
|
|
|
|
$id = isset($this->urlParams['ID']) ? $this->urlParams['ID'] : false;
|
2017-09-15 23:06:03 +02:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
if ($id) {
|
2018-09-24 18:16:03 +02:00
|
|
|
/** @var Comment $comment */
|
2017-01-16 20:57:37 +01:00
|
|
|
$comment = Comment::get()->byId($id);
|
2016-02-19 01:48:25 +01:00
|
|
|
if ($comment) {
|
|
|
|
$this->fallbackReturnURL = $comment->Link();
|
|
|
|
return $comment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a reply form for a specified comment
|
|
|
|
*
|
2017-01-16 20:57:37 +01:00
|
|
|
* @param Comment $comment
|
|
|
|
* @return Form
|
2016-02-19 01:48:25 +01:00
|
|
|
*/
|
|
|
|
public function ReplyForm($comment)
|
|
|
|
{
|
|
|
|
// Enables multiple forms with different names to use the same handler
|
|
|
|
$form = $this->CommentsForm();
|
2017-01-16 20:57:37 +01:00
|
|
|
$form->setName('ReplyForm_' . $comment->ID);
|
2018-04-26 07:42:08 +02:00
|
|
|
$form->setHTMLID(null);
|
2016-02-19 01:48:25 +01:00
|
|
|
$form->addExtraClass('reply-form');
|
|
|
|
|
|
|
|
// Load parent into reply form
|
2018-09-24 18:16:03 +02:00
|
|
|
$form->loadDataFrom([
|
2016-02-19 01:48:25 +01:00
|
|
|
'ParentCommentID' => $comment->ID
|
2018-09-24 18:16:03 +02:00
|
|
|
]);
|
2016-02-19 01:48:25 +01:00
|
|
|
|
|
|
|
// Customise action
|
|
|
|
$form->setFormAction($this->Link('reply', $comment->ID));
|
|
|
|
|
|
|
|
$this->extend('updateReplyForm', $form);
|
2017-09-15 23:06:03 +02:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request handler for reply form.
|
2017-09-15 23:06:03 +02:00
|
|
|
*
|
2016-02-19 01:48:25 +01:00
|
|
|
* This method will disambiguate multiple reply forms in the same method
|
|
|
|
*
|
2017-01-16 20:57:37 +01:00
|
|
|
* @param HTTPRequest $request
|
|
|
|
* @throws HTTPResponse_Exception
|
2016-02-19 01:48:25 +01:00
|
|
|
*/
|
2017-01-16 20:57:37 +01:00
|
|
|
public function reply(HTTPRequest $request)
|
2016-02-19 01:48:25 +01:00
|
|
|
{
|
|
|
|
// Extract parent comment from reply and build this way
|
|
|
|
if ($parentID = $request->param('ParentCommentID')) {
|
2018-09-24 18:16:03 +02:00
|
|
|
/** @var Comment $comment */
|
2017-01-16 20:57:37 +01:00
|
|
|
$comment = DataObject::get_by_id(Comment::class, $parentID, true);
|
2016-02-19 01:48:25 +01:00
|
|
|
if ($comment) {
|
|
|
|
return $this->ReplyForm($comment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->httpError(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post a comment form
|
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function CommentsForm()
|
|
|
|
{
|
2018-04-04 05:45:45 +02:00
|
|
|
$form = Injector::inst()->create(CommentForm::class, __FUNCTION__, $this);
|
|
|
|
|
|
|
|
// hook to allow further extensions to alter the comments form
|
|
|
|
$this->extend('alterCommentForm', $form);
|
|
|
|
|
|
|
|
return $form;
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
/**
|
|
|
|
* @return HTTPResponse|false
|
|
|
|
*/
|
2016-02-19 01:48:25 +01:00
|
|
|
public function redirectBack()
|
|
|
|
{
|
|
|
|
// Don't cache the redirect back ever
|
|
|
|
HTTP::set_cache_age(0);
|
|
|
|
|
|
|
|
$url = null;
|
|
|
|
|
|
|
|
// In edge-cases, this will be called outside of a handleRequest() context; in that case,
|
|
|
|
// redirect to the homepage - don't break into the global state at this stage because we'll
|
|
|
|
// be calling from a test context or something else where the global state is inappropraite
|
|
|
|
if ($this->request) {
|
|
|
|
if ($this->request->requestVar('BackURL')) {
|
|
|
|
$url = $this->request->requestVar('BackURL');
|
|
|
|
} elseif ($this->request->isAjax() && $this->request->getHeader('X-Backurl')) {
|
|
|
|
$url = $this->request->getHeader('X-Backurl');
|
|
|
|
} elseif ($this->request->getHeader('Referer')) {
|
|
|
|
$url = $this->request->getHeader('Referer');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$url) {
|
|
|
|
$url = $this->fallbackReturnURL;
|
|
|
|
}
|
|
|
|
if (!$url) {
|
|
|
|
$url = Director::baseURL();
|
|
|
|
}
|
|
|
|
|
|
|
|
// absolute redirection URLs not located on this site may cause phishing
|
|
|
|
if (Director::is_site_url($url)) {
|
|
|
|
return $this->redirect($url);
|
|
|
|
}
|
2018-09-24 18:16:03 +02:00
|
|
|
|
|
|
|
return false;
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2012-08-08 02:51:14 +02:00
|
|
|
}
|