mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Merge branch '3.1'
This commit is contained in:
commit
97461f8f35
@ -6,17 +6,5 @@
|
|||||||
<rule ref="PSR2" >
|
<rule ref="PSR2" >
|
||||||
<!-- Current exclusions -->
|
<!-- Current exclusions -->
|
||||||
<exclude name="PSR1.Methods.CamelCapsMethodName" />
|
<exclude name="PSR1.Methods.CamelCapsMethodName" />
|
||||||
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
|
|
||||||
<exclude name="PSR2.Classes.PropertyDeclaration" />
|
|
||||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration" /> <!-- causes php notice while linting -->
|
|
||||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
|
|
||||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenerdefault" />
|
|
||||||
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
|
|
||||||
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
|
|
||||||
<exclude name="Squiz.Scope.MethodScope" />
|
|
||||||
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
|
|
||||||
<exclude name="Generic.Files.LineLength.TooLong" />
|
|
||||||
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
|
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
</ruleset>
|
</ruleset>
|
@ -3,22 +3,19 @@
|
|||||||
namespace SilverStripe\Comments\Admin;
|
namespace SilverStripe\Comments\Admin;
|
||||||
|
|
||||||
use SilverStripe\Admin\LeftAndMain;
|
use SilverStripe\Admin\LeftAndMain;
|
||||||
use SilverStripe\Comments\Admin\CommentsGridField;
|
|
||||||
use SilverStripe\Comments\Model\Comment;
|
use SilverStripe\Comments\Model\Comment;
|
||||||
use SilverStripe\Forms\Tab;
|
|
||||||
use SilverStripe\Forms\TabSet;
|
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
use SilverStripe\Security\PermissionProvider;
|
use SilverStripe\Forms\Tab;
|
||||||
|
use SilverStripe\Forms\TabSet;
|
||||||
use SilverStripe\Security\Security;
|
use SilverStripe\Security\Security;
|
||||||
use SilverStripe\View\SSViewer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment administration system within the CMS
|
* Comment administration system within the CMS
|
||||||
*
|
*
|
||||||
* @package comments
|
* @package comments
|
||||||
*/
|
*/
|
||||||
class CommentAdmin extends LeftAndMain implements PermissionProvider
|
class CommentAdmin extends LeftAndMain
|
||||||
{
|
{
|
||||||
private static $url_segment = 'comments';
|
private static $url_segment = 'comments';
|
||||||
|
|
||||||
@ -28,7 +25,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
|
|
||||||
private static $menu_icon_class = 'font-icon-comment';
|
private static $menu_icon_class = 'font-icon-comment';
|
||||||
|
|
||||||
private static $allowed_actions = array(
|
private static $allowed_actions = [
|
||||||
'approvedmarked',
|
'approvedmarked',
|
||||||
'deleteall',
|
'deleteall',
|
||||||
'deletemarked',
|
'deletemarked',
|
||||||
@ -37,18 +34,18 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
'spammarked',
|
'spammarked',
|
||||||
'EditForm',
|
'EditForm',
|
||||||
'unmoderated'
|
'unmoderated'
|
||||||
);
|
];
|
||||||
|
|
||||||
private static $required_permission_codes = 'CMS_ACCESS_CommentAdmin';
|
private static $required_permission_codes = 'CMS_ACCESS_CommentAdmin';
|
||||||
|
|
||||||
public function providePermissions()
|
public function providePermissions()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
"CMS_ACCESS_CommentAdmin" => array(
|
'CMS_ACCESS_CommentAdmin' => [
|
||||||
'name' => _t(__CLASS__ . '.ADMIN_PERMISSION', "Access to 'Comments' section"),
|
'name' => _t(__CLASS__ . '.ADMIN_PERMISSION', "Access to 'Comments' section"),
|
||||||
'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
|
'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +66,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
|
|
||||||
$newComments = Comment::get()->filter('Moderated', 0);
|
$newComments = Comment::get()->filter('Moderated', 0);
|
||||||
|
|
||||||
$newGrid = new CommentsGridField(
|
$newGrid = CommentsGridField::create(
|
||||||
'NewComments',
|
'NewComments',
|
||||||
'',
|
'',
|
||||||
$newComments,
|
$newComments,
|
||||||
@ -78,7 +75,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
|
|
||||||
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
|
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
|
||||||
|
|
||||||
$approvedGrid = new CommentsGridField(
|
$approvedGrid = CommentsGridField::create(
|
||||||
'ApprovedComments',
|
'ApprovedComments',
|
||||||
'',
|
'',
|
||||||
$approvedComments,
|
$approvedComments,
|
||||||
@ -87,7 +84,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
|
|
||||||
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
|
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
|
||||||
|
|
||||||
$spamGrid = new CommentsGridField(
|
$spamGrid = CommentsGridField::create(
|
||||||
'SpamComments',
|
'SpamComments',
|
||||||
'',
|
'',
|
||||||
$spamComments,
|
$spamComments,
|
||||||
@ -136,7 +133,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
$actions
|
$actions
|
||||||
);
|
);
|
||||||
|
|
||||||
$form->addExtraClass('cms-edit-form');
|
$form->addExtraClass('cms-edit-form fill-height');
|
||||||
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
||||||
|
|
||||||
if ($form->Fields()->hasTabset()) {
|
if ($form->Fields()->hasTabset()) {
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Comments\Admin;
|
namespace SilverStripe\Comments\Admin;
|
||||||
|
|
||||||
use SilverStripe\Forms\FormField;
|
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
use SilverStripe\View\HTML;
|
use SilverStripe\View\HTML;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
*/
|
*/
|
||||||
public function getColumnAttributes($gridField, $record, $columnName)
|
public function getColumnAttributes($gridField, $record, $columnName)
|
||||||
{
|
{
|
||||||
return array('class' => 'col-buttons');
|
return ['class' => 'col-buttons'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,8 +34,8 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
*/
|
*/
|
||||||
public function getColumnMetadata($gridField, $columnName)
|
public function getColumnMetadata($gridField, $columnName)
|
||||||
{
|
{
|
||||||
if ($columnName == 'Actions') {
|
if ($columnName === 'Actions') {
|
||||||
return array('title' => '');
|
return ['title' => ''];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
*/
|
*/
|
||||||
public function getColumnsHandled($gridField)
|
public function getColumnsHandled($gridField)
|
||||||
{
|
{
|
||||||
return array('Actions');
|
return ['Actions'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,7 +64,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
'CustomAction' . $record->ID . 'Spam',
|
'CustomAction' . $record->ID . 'Spam',
|
||||||
_t(__CLASS__ . '.SPAM', 'Spam'),
|
_t(__CLASS__ . '.SPAM', 'Spam'),
|
||||||
'spam',
|
'spam',
|
||||||
array('RecordID' => $record->ID)
|
['RecordID' => $record->ID]
|
||||||
)
|
)
|
||||||
->addExtraClass('btn btn-secondary grid-field__icon-action')
|
->addExtraClass('btn btn-secondary grid-field__icon-action')
|
||||||
->Field();
|
->Field();
|
||||||
@ -76,7 +76,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
'CustomAction' . $record->ID . 'Approve',
|
'CustomAction' . $record->ID . 'Approve',
|
||||||
_t(__CLASS__ . '.APPROVE', 'Approve'),
|
_t(__CLASS__ . '.APPROVE', 'Approve'),
|
||||||
'approve',
|
'approve',
|
||||||
array('RecordID' => $record->ID)
|
['RecordID' => $record->ID]
|
||||||
)
|
)
|
||||||
->addExtraClass('btn btn-secondary grid-field__icon-action')
|
->addExtraClass('btn btn-secondary grid-field__icon-action')
|
||||||
->Field();
|
->Field();
|
||||||
@ -90,7 +90,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
*/
|
*/
|
||||||
public function getActions($gridField)
|
public function getActions($gridField)
|
||||||
{
|
{
|
||||||
return array('spam', 'approve');
|
return ['spam', 'approve'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,7 +98,8 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
*/
|
*/
|
||||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||||
{
|
{
|
||||||
if ($actionName == 'spam') {
|
if ($actionName === 'spam') {
|
||||||
|
/** @var Comment $comment */
|
||||||
$comment = Comment::get()->byID($arguments['RecordID']);
|
$comment = Comment::get()->byID($arguments['RecordID']);
|
||||||
$comment->markSpam();
|
$comment->markSpam();
|
||||||
|
|
||||||
@ -109,7 +110,8 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($actionName == 'approve') {
|
if ($actionName === 'approve') {
|
||||||
|
/** @var Comment $comment */
|
||||||
$comment = Comment::get()->byID($arguments['RecordID']);
|
$comment = Comment::get()->byID($arguments['RecordID']);
|
||||||
$comment->markApproved();
|
$comment->markApproved();
|
||||||
|
|
||||||
|
@ -20,8 +20,9 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
|
|||||||
$this->addComponent(new CommentsGridFieldAction());
|
$this->addComponent(new CommentsGridFieldAction());
|
||||||
|
|
||||||
// Format column
|
// Format column
|
||||||
|
/** @var GridFieldDataColumns $columns */
|
||||||
$columns = $this->getComponentByType(GridFieldDataColumns::class);
|
$columns = $this->getComponentByType(GridFieldDataColumns::class);
|
||||||
$columns->setFieldFormatting(array(
|
$columns->setFieldFormatting([
|
||||||
'ParentTitle' => function ($value, &$item) {
|
'ParentTitle' => function ($value, &$item) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
|
'<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
|
||||||
@ -29,10 +30,10 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
|
|||||||
$item->obj('ParentTitle')->forTemplate()
|
$item->obj('ParentTitle')->forTemplate()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
));
|
]);
|
||||||
|
|
||||||
// Add bulk option
|
// Add bulk option
|
||||||
$manager = new BulkManager(null, false);
|
$manager = BulkManager::create(null, false);
|
||||||
|
|
||||||
$spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam'));
|
$spamAction = SpamHandler::create()->setLabel(_t(__CLASS__ . '.SPAM', 'Spam'));
|
||||||
$approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve'));
|
$approveAction = ApproveHandler::create()->setLabel(_t(__CLASS__ . '.APPROVE', 'Approve'));
|
||||||
|
@ -4,20 +4,21 @@ namespace SilverStripe\Comments\Controllers;
|
|||||||
|
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Comments\Extensions\CommentsExtension;
|
use SilverStripe\Comments\Extensions\CommentsExtension;
|
||||||
|
use SilverStripe\Comments\Forms\CommentForm;
|
||||||
use SilverStripe\Comments\Model\Comment;
|
use SilverStripe\Comments\Model\Comment;
|
||||||
use SilverStripe\Control\Director;
|
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Email\Email;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Control\HTTP;
|
use SilverStripe\Control\HTTP;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
use SilverStripe\Control\HTTPResponse_Exception;
|
||||||
use SilverStripe\Control\RSS\RSSFeed;
|
use SilverStripe\Control\RSS\RSSFeed;
|
||||||
use SilverStripe\Control\Session;
|
|
||||||
use SilverStripe\ORM\DataObject;
|
|
||||||
use SilverStripe\ORM\PaginatedList;
|
|
||||||
use SilverStripe\Security\Member;
|
|
||||||
use SilverStripe\Security\Security;
|
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Comments\Forms\CommentForm;
|
use SilverStripe\Forms\Form;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||||
|
use SilverStripe\ORM\PaginatedList;
|
||||||
|
use SilverStripe\Security\Security;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package comments
|
* @package comments
|
||||||
@ -27,7 +28,7 @@ class CommentingController extends Controller
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
private static $allowed_actions = array(
|
private static $allowed_actions = [
|
||||||
'delete',
|
'delete',
|
||||||
'spam',
|
'spam',
|
||||||
'ham',
|
'ham',
|
||||||
@ -36,15 +37,15 @@ class CommentingController extends Controller
|
|||||||
'CommentsForm',
|
'CommentsForm',
|
||||||
'reply',
|
'reply',
|
||||||
'doPostComment',
|
'doPostComment',
|
||||||
'doPreviewComment'
|
'doPreviewComment',
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
private static $url_handlers = array(
|
private static $url_handlers = [
|
||||||
'reply/$ParentCommentID//$ID/$OtherID' => 'reply',
|
'reply/$ParentCommentID//$ID/$OtherID' => 'reply',
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fields required for this form
|
* Fields required for this form
|
||||||
@ -52,11 +53,11 @@ class CommentingController extends Controller
|
|||||||
* @var array
|
* @var array
|
||||||
* @config
|
* @config
|
||||||
*/
|
*/
|
||||||
private static $required_fields = array(
|
private static $required_fields = [
|
||||||
'Name',
|
'Name',
|
||||||
'Email',
|
'Email',
|
||||||
'Comment'
|
'Comment',
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent class this commenting form is for
|
* Parent class this commenting form is for
|
||||||
@ -70,21 +71,21 @@ class CommentingController extends Controller
|
|||||||
*
|
*
|
||||||
* @var DataObject
|
* @var DataObject
|
||||||
*/
|
*/
|
||||||
private $ownerRecord = null;
|
private $ownerRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent controller record
|
* Parent controller record
|
||||||
*
|
*
|
||||||
* @var Controller
|
* @var Controller
|
||||||
*/
|
*/
|
||||||
private $ownerController = null;
|
private $ownerController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backup url to return to
|
* Backup url to return to
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $fallbackReturnURL = null;
|
protected $fallbackReturnURL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the parent class name to use
|
* Set the parent class name to use
|
||||||
@ -178,6 +179,7 @@ class CommentingController extends Controller
|
|||||||
{
|
{
|
||||||
// If possible use the current record
|
// If possible use the current record
|
||||||
if ($record = $this->getOwnerRecord()) {
|
if ($record = $this->getOwnerRecord()) {
|
||||||
|
/** @var DataObject|CommentsExtension $record */
|
||||||
return $record->getCommentsOption($key);
|
return $record->getCommentsOption($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,6 +200,7 @@ class CommentingController extends Controller
|
|||||||
public function getOptions()
|
public function getOptions()
|
||||||
{
|
{
|
||||||
if ($record = $this->getOwnerRecord()) {
|
if ($record = $this->getOwnerRecord()) {
|
||||||
|
/** @var DataObject|CommentsExtension $record */
|
||||||
return $record->getCommentsOptions();
|
return $record->getCommentsOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +229,7 @@ class CommentingController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Outputs the RSS feed of comments
|
* Outputs the RSS feed of comments
|
||||||
*
|
*
|
||||||
* @return HTMLText
|
* @return DBHTMLText
|
||||||
*/
|
*/
|
||||||
public function rss()
|
public function rss()
|
||||||
{
|
{
|
||||||
@ -252,10 +255,10 @@ class CommentingController extends Controller
|
|||||||
$class = SiteTree::class;
|
$class = SiteTree::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
$comments = Comment::get()->filter(array(
|
$comments = Comment::get()->filter([
|
||||||
'Moderated' => 1,
|
'Moderated' => 1,
|
||||||
'IsSpam' => 0,
|
'IsSpam' => 0,
|
||||||
));
|
]);
|
||||||
|
|
||||||
// Check if class filter
|
// Check if class filter
|
||||||
if ($class) {
|
if ($class) {
|
||||||
@ -275,10 +278,10 @@ class CommentingController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$title = _t(__CLASS__ . '.RSSTITLE', "Comments RSS Feed");
|
$title = _t(__CLASS__ . '.RSSTITLE', "Comments RSS Feed");
|
||||||
$comments = new PaginatedList($comments, $request);
|
$comments = PaginatedList::create($comments, $request);
|
||||||
$comments->setPageLength($this->getOption('comments_per_page'));
|
$comments->setPageLength($this->getOption('comments_per_page'));
|
||||||
|
|
||||||
return new RSSFeed(
|
return RSSFeed::create(
|
||||||
$comments,
|
$comments,
|
||||||
$link,
|
$link,
|
||||||
$title,
|
$title,
|
||||||
@ -375,6 +378,9 @@ class CommentingController extends Controller
|
|||||||
* Redirect back to referer if available, ensuring that only site URLs
|
* Redirect back to referer if available, ensuring that only site URLs
|
||||||
* are allowed to avoid phishing. If it's an AJAX request render the
|
* are allowed to avoid phishing. If it's an AJAX request render the
|
||||||
* comment in it's new state
|
* comment in it's new state
|
||||||
|
*
|
||||||
|
* @param Comment $comment
|
||||||
|
* @return DBHTMLText|HTTPResponse|false
|
||||||
*/
|
*/
|
||||||
private function renderChangedCommentState($comment)
|
private function renderChangedCommentState($comment)
|
||||||
{
|
{
|
||||||
@ -383,22 +389,22 @@ class CommentingController extends Controller
|
|||||||
// Render comment using AJAX
|
// Render comment using AJAX
|
||||||
if ($this->request->isAjax()) {
|
if ($this->request->isAjax()) {
|
||||||
return $comment->renderWith('Includes/CommentsInterface_singlecomment');
|
return $comment->renderWith('Includes/CommentsInterface_singlecomment');
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Redirect to either the comment or start of the page
|
// Redirect to either the comment or start of the page
|
||||||
if (empty($referer)) {
|
if (empty($referer)) {
|
||||||
return $this->redirectBack();
|
return $this->redirectBack();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Redirect to the comment, but check for phishing
|
// Redirect to the comment, but check for phishing
|
||||||
$url = $referer . '#comment-' . $comment->ID;
|
$url = $referer . '#comment-' . $comment->ID;
|
||||||
// absolute redirection URLs not located on this site may cause phishing
|
// absolute redirection URLs not located on this site may cause phishing
|
||||||
if (Director::is_site_url($url)) {
|
if (Director::is_site_url($url)) {
|
||||||
return $this->redirect($url);
|
return $this->redirect($url);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the comment referenced in the URL (by ID). Permission checking
|
* Returns the comment referenced in the URL (by ID). Permission checking
|
||||||
@ -411,6 +417,7 @@ class CommentingController extends Controller
|
|||||||
$id = isset($this->urlParams['ID']) ? $this->urlParams['ID'] : false;
|
$id = isset($this->urlParams['ID']) ? $this->urlParams['ID'] : false;
|
||||||
|
|
||||||
if ($id) {
|
if ($id) {
|
||||||
|
/** @var Comment $comment */
|
||||||
$comment = Comment::get()->byId($id);
|
$comment = Comment::get()->byId($id);
|
||||||
if ($comment) {
|
if ($comment) {
|
||||||
$this->fallbackReturnURL = $comment->Link();
|
$this->fallbackReturnURL = $comment->Link();
|
||||||
@ -436,9 +443,9 @@ class CommentingController extends Controller
|
|||||||
$form->addExtraClass('reply-form');
|
$form->addExtraClass('reply-form');
|
||||||
|
|
||||||
// Load parent into reply form
|
// Load parent into reply form
|
||||||
$form->loadDataFrom(array(
|
$form->loadDataFrom([
|
||||||
'ParentCommentID' => $comment->ID
|
'ParentCommentID' => $comment->ID
|
||||||
));
|
]);
|
||||||
|
|
||||||
// Customise action
|
// Customise action
|
||||||
$form->setFormAction($this->Link('reply', $comment->ID));
|
$form->setFormAction($this->Link('reply', $comment->ID));
|
||||||
@ -461,6 +468,7 @@ class CommentingController extends Controller
|
|||||||
{
|
{
|
||||||
// Extract parent comment from reply and build this way
|
// Extract parent comment from reply and build this way
|
||||||
if ($parentID = $request->param('ParentCommentID')) {
|
if ($parentID = $request->param('ParentCommentID')) {
|
||||||
|
/** @var Comment $comment */
|
||||||
$comment = DataObject::get_by_id(Comment::class, $parentID, true);
|
$comment = DataObject::get_by_id(Comment::class, $parentID, true);
|
||||||
if ($comment) {
|
if ($comment) {
|
||||||
return $this->ReplyForm($comment);
|
return $this->ReplyForm($comment);
|
||||||
@ -518,8 +526,8 @@ class CommentingController extends Controller
|
|||||||
// absolute redirection URLs not located on this site may cause phishing
|
// absolute redirection URLs not located on this site may cause phishing
|
||||||
if (Director::is_site_url($url)) {
|
if (Director::is_site_url($url)) {
|
||||||
return $this->redirect($url);
|
return $this->redirect($url);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -9,10 +9,7 @@ use SilverStripe\Comments\Controllers\CommentingController;
|
|||||||
use SilverStripe\Comments\Model\Comment;
|
use SilverStripe\Comments\Model\Comment;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Control\Session;
|
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
|
||||||
use SilverStripe\Dev\Deprecation;
|
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\Forms\FieldGroup;
|
use SilverStripe\Forms\FieldGroup;
|
||||||
@ -20,9 +17,11 @@ use SilverStripe\Forms\FieldList;
|
|||||||
use SilverStripe\Forms\Tab;
|
use SilverStripe\Forms\Tab;
|
||||||
use SilverStripe\Forms\TabSet;
|
use SilverStripe\Forms\TabSet;
|
||||||
use SilverStripe\ORM\DataExtension;
|
use SilverStripe\ORM\DataExtension;
|
||||||
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\PaginatedList;
|
use SilverStripe\ORM\PaginatedList;
|
||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
use SilverStripe\Security\Permission;
|
use SilverStripe\Security\Permission;
|
||||||
|
use SilverStripe\Security\Security;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,13 +156,16 @@ class CommentsExtension extends DataExtension
|
|||||||
|
|
||||||
// Check if enabled setting should be cms configurable
|
// Check if enabled setting should be cms configurable
|
||||||
if ($this->owner->getCommentsOption('enabled_cms')) {
|
if ($this->owner->getCommentsOption('enabled_cms')) {
|
||||||
$options->push(new CheckboxField('ProvideComments', _t('SilverStripe\\Comments\\Model\\Comment.ALLOWCOMMENTS', 'Allow Comments')));
|
$options->push(CheckboxField::create('ProvideComments', _t(
|
||||||
|
'SilverStripe\\Comments\\Model\\Comment.ALLOWCOMMENTS',
|
||||||
|
'Allow Comments'
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we should require users to login to comment
|
// Check if we should require users to login to comment
|
||||||
if ($this->owner->getCommentsOption('require_login_cms')) {
|
if ($this->owner->getCommentsOption('require_login_cms')) {
|
||||||
$options->push(
|
$options->push(
|
||||||
new CheckboxField(
|
CheckboxField::create(
|
||||||
'CommentsRequireLogin',
|
'CommentsRequireLogin',
|
||||||
_t('Comments.COMMENTSREQUIRELOGIN', 'Require login to comment')
|
_t('Comments.COMMENTSREQUIRELOGIN', 'Require login to comment')
|
||||||
)
|
)
|
||||||
@ -180,16 +182,23 @@ class CommentsExtension extends DataExtension
|
|||||||
|
|
||||||
// Check if moderation should be enabled via cms configurable
|
// Check if moderation should be enabled via cms configurable
|
||||||
if ($this->owner->getCommentsOption('require_moderation_cms')) {
|
if ($this->owner->getCommentsOption('require_moderation_cms')) {
|
||||||
$moderationField = new DropdownField('ModerationRequired', _t(__CLASS__ . '.COMMENTMODERATION', 'Comment Moderation'), array(
|
$moderationField = DropdownField::create(
|
||||||
|
'ModerationRequired',
|
||||||
|
_t(
|
||||||
|
__CLASS__ . '.COMMENTMODERATION',
|
||||||
|
'Comment Moderation'
|
||||||
|
),
|
||||||
|
[
|
||||||
'None' => _t(__CLASS__ . '.MODERATIONREQUIRED_NONE', 'No moderation required'),
|
'None' => _t(__CLASS__ . '.MODERATIONREQUIRED_NONE', 'No moderation required'),
|
||||||
'Required' => _t(__CLASS__ . '.MODERATIONREQUIRED_REQUIRED', 'Moderate all comments'),
|
'Required' => _t(__CLASS__ . '.MODERATIONREQUIRED_REQUIRED', 'Moderate all comments'),
|
||||||
'NonMembersOnly' => _t(
|
'NonMembersOnly' => _t(
|
||||||
__CLASS__ . '.MODERATIONREQUIRED_NONMEMBERSONLY',
|
__CLASS__ . '.MODERATIONREQUIRED_NONMEMBERSONLY',
|
||||||
'Only moderate non-members'
|
'Only moderate non-members'
|
||||||
),
|
),
|
||||||
));
|
]
|
||||||
|
);
|
||||||
if ($fields->hasTabSet()) {
|
if ($fields->hasTabSet()) {
|
||||||
$fields->addFieldsToTab('Root.Settings', $moderationField);
|
$fields->addFieldToTab('Root.Settings', $moderationField);
|
||||||
} else {
|
} else {
|
||||||
$fields->push($moderationField);
|
$fields->push($moderationField);
|
||||||
}
|
}
|
||||||
@ -209,13 +218,17 @@ class CommentsExtension extends DataExtension
|
|||||||
{
|
{
|
||||||
if ($this->owner->getCommentsOption('require_moderation_cms')) {
|
if ($this->owner->getCommentsOption('require_moderation_cms')) {
|
||||||
return $this->owner->getField('ModerationRequired');
|
return $this->owner->getField('ModerationRequired');
|
||||||
} elseif ($this->owner->getCommentsOption('require_moderation')) {
|
|
||||||
return 'Required';
|
|
||||||
} elseif ($this->owner->getCommentsOption('require_moderation_nonmembers')) {
|
|
||||||
return 'NonMembersOnly';
|
|
||||||
} else {
|
|
||||||
return 'None';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->owner->getCommentsOption('require_moderation')) {
|
||||||
|
return 'Required';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->owner->getCommentsOption('require_moderation_nonmembers')) {
|
||||||
|
return 'NonMembersOnly';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'None';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -227,9 +240,8 @@ class CommentsExtension extends DataExtension
|
|||||||
{
|
{
|
||||||
if ($this->owner->getCommentsOption('require_login_cms')) {
|
if ($this->owner->getCommentsOption('require_login_cms')) {
|
||||||
return (bool) $this->owner->getField('CommentsRequireLogin');
|
return (bool) $this->owner->getField('CommentsRequireLogin');
|
||||||
} else {
|
|
||||||
return (bool) $this->owner->getCommentsOption('require_login');
|
|
||||||
}
|
}
|
||||||
|
return (bool) $this->owner->getCommentsOption('require_login');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -304,7 +316,7 @@ class CommentsExtension extends DataExtension
|
|||||||
$list = $this->Comments();
|
$list = $this->Comments();
|
||||||
|
|
||||||
// Add pagination
|
// Add pagination
|
||||||
$list = new PaginatedList($list, Controller::curr()->getRequest());
|
$list = PaginatedList::create($list, Controller::curr()->getRequest());
|
||||||
$list->setPaginationGetVar('commentsstart' . $this->owner->ID);
|
$list->setPaginationGetVar('commentsstart' . $this->owner->ID);
|
||||||
$list->setPageLength($this->owner->getCommentsOption('comments_per_page'));
|
$list->setPageLength($this->owner->getCommentsOption('comments_per_page'));
|
||||||
|
|
||||||
@ -378,7 +390,7 @@ class CommentsExtension extends DataExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check member is logged in
|
// Check member is logged in
|
||||||
$member = $member ?: Member::currentUser();
|
$member = $member ?: Security::getCurrentUser();
|
||||||
if (!$member) {
|
if (!$member) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -472,10 +484,10 @@ class CommentsExtension extends DataExtension
|
|||||||
// return back the same variables as previously done in comments
|
// return back the same variables as previously done in comments
|
||||||
return $this
|
return $this
|
||||||
->owner
|
->owner
|
||||||
->customise(array(
|
->customise([
|
||||||
'AddCommentForm' => $form,
|
'AddCommentForm' => $form,
|
||||||
'ModeratedSubmitted' => $moderatedSubmitted,
|
'ModeratedSubmitted' => $moderatedSubmitted,
|
||||||
))
|
])
|
||||||
->renderWith('CommentsInterface');
|
->renderWith('CommentsInterface');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,8 +535,6 @@ class CommentsExtension extends DataExtension
|
|||||||
*/
|
*/
|
||||||
public function getCommentsOptions()
|
public function getCommentsOptions()
|
||||||
{
|
{
|
||||||
$settings = [];
|
|
||||||
|
|
||||||
if ($this->owner) {
|
if ($this->owner) {
|
||||||
$settings = $this->owner->config()->get('comments');
|
$settings = $this->owner->config()->get('comments');
|
||||||
} else {
|
} else {
|
||||||
@ -545,7 +555,7 @@ class CommentsExtension extends DataExtension
|
|||||||
|
|
||||||
$newComments = $this->owner->AllComments()->filter('Moderated', 0);
|
$newComments = $this->owner->AllComments()->filter('Moderated', 0);
|
||||||
|
|
||||||
$newGrid = new CommentsGridField(
|
$newGrid = CommentsGridField::create(
|
||||||
'NewComments',
|
'NewComments',
|
||||||
_t('CommentsAdmin.NewComments', 'New'),
|
_t('CommentsAdmin.NewComments', 'New'),
|
||||||
$newComments,
|
$newComments,
|
||||||
@ -563,7 +573,7 @@ class CommentsExtension extends DataExtension
|
|||||||
|
|
||||||
$spamComments = $this->owner->AllComments()->filter('Moderated', 1)->filter('IsSpam', 1);
|
$spamComments = $this->owner->AllComments()->filter('Moderated', 1)->filter('IsSpam', 1);
|
||||||
|
|
||||||
$spamGrid = new CommentsGridField(
|
$spamGrid = CommentsGridField::create(
|
||||||
'SpamComments',
|
'SpamComments',
|
||||||
_t('CommentsAdmin.SpamComments', 'Spam'),
|
_t('CommentsAdmin.SpamComments', 'Spam'),
|
||||||
$spamComments,
|
$spamComments,
|
||||||
@ -575,19 +585,19 @@ class CommentsExtension extends DataExtension
|
|||||||
$spamCount = '(' . count($spamComments) . ')';
|
$spamCount = '(' . count($spamComments) . ')';
|
||||||
|
|
||||||
if ($fields->hasTabSet()) {
|
if ($fields->hasTabSet()) {
|
||||||
$tabs = new TabSet(
|
$tabs = TabSet::create(
|
||||||
'Comments',
|
'Comments',
|
||||||
new Tab(
|
Tab::create(
|
||||||
'CommentsNewCommentsTab',
|
'CommentsNewCommentsTab',
|
||||||
_t('SilverStripe\\Comments\\Admin\\CommentAdmin.NewComments', 'New') . ' ' . $newCount,
|
_t('SilverStripe\\Comments\\Admin\\CommentAdmin.NewComments', 'New') . ' ' . $newCount,
|
||||||
$newGrid
|
$newGrid
|
||||||
),
|
),
|
||||||
new Tab(
|
Tab::create(
|
||||||
'CommentsCommentsTab',
|
'CommentsCommentsTab',
|
||||||
_t('SilverStripe\\Comments\\Admin\\CommentAdmin.Comments', 'Approved') . ' ' . $approvedCount,
|
_t('SilverStripe\\Comments\\Admin\\CommentAdmin.Comments', 'Approved') . ' ' . $approvedCount,
|
||||||
$approvedGrid
|
$approvedGrid
|
||||||
),
|
),
|
||||||
new Tab(
|
Tab::create(
|
||||||
'CommentsSpamCommentsTab',
|
'CommentsSpamCommentsTab',
|
||||||
_t('SilverStripe\\Comments\\Admin\\CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount,
|
_t('SilverStripe\\Comments\\Admin\\CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount,
|
||||||
$spamGrid
|
$spamGrid
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Comments\Forms;
|
namespace SilverStripe\Comments\Forms;
|
||||||
|
|
||||||
|
use SilverStripe\Comments\Controllers\CommentingController;
|
||||||
|
use SilverStripe\Comments\Model\Comment;
|
||||||
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Forms\CompositeField;
|
use SilverStripe\Forms\CompositeField;
|
||||||
use SilverStripe\Forms\EmailField;
|
use SilverStripe\Forms\EmailField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
@ -13,14 +17,7 @@ use SilverStripe\Forms\ReadonlyField;
|
|||||||
use SilverStripe\Forms\RequiredFields;
|
use SilverStripe\Forms\RequiredFields;
|
||||||
use SilverStripe\Forms\TextareaField;
|
use SilverStripe\Forms\TextareaField;
|
||||||
use SilverStripe\Forms\TextField;
|
use SilverStripe\Forms\TextField;
|
||||||
use SilverStripe\Security\Member;
|
|
||||||
use SilverStripe\Control\Cookie;
|
|
||||||
use SilverStripe\Core\Convert;
|
|
||||||
use SilverStripe\Security\Security;
|
use SilverStripe\Security\Security;
|
||||||
use SilverStripe\Comments\Model\Comment;
|
|
||||||
use SilverStripe\Control\Controller;
|
|
||||||
use SilverStripe\Comments\Controllers\CommentingController;
|
|
||||||
use SilverStripe\Core\Config\Config;
|
|
||||||
|
|
||||||
class CommentForm extends Form
|
class CommentForm extends Form
|
||||||
{
|
{
|
||||||
@ -46,18 +43,27 @@ class CommentForm extends Form
|
|||||||
// Email
|
// Email
|
||||||
EmailField::create(
|
EmailField::create(
|
||||||
'Email',
|
'Email',
|
||||||
_t('SilverStripe\\Comments\\Controllers\\CommentingController.EMAILADDRESS', 'Your email address (will not be published)')
|
_t(
|
||||||
|
'SilverStripe\\Comments\\Controllers\\CommentingController.EMAILADDRESS',
|
||||||
|
'Your email address (will not be published)'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
->setCustomValidationMessage($emailRequired)
|
->setCustomValidationMessage($emailRequired)
|
||||||
->setAttribute('data-msg-required', $emailRequired)
|
->setAttribute('data-msg-required', $emailRequired)
|
||||||
->setAttribute('data-msg-email', $emailInvalid)
|
->setAttribute('data-msg-email', $emailInvalid)
|
||||||
->setAttribute('data-rule-email', true),
|
->setAttribute('data-rule-email', true),
|
||||||
// Url
|
// Url
|
||||||
TextField::create('URL', _t('SilverStripe\\Comments\\Controllers\\CommentingController.WEBSITEURL', 'Your website URL'))
|
TextField::create('URL', _t(
|
||||||
|
'SilverStripe\\Comments\\Controllers\\CommentingController.WEBSITEURL',
|
||||||
|
'Your website URL'
|
||||||
|
))
|
||||||
->setAttribute('data-msg-url', $urlInvalid)
|
->setAttribute('data-msg-url', $urlInvalid)
|
||||||
->setAttribute('data-rule-url', true),
|
->setAttribute('data-rule-url', true),
|
||||||
// Comment
|
// Comment
|
||||||
TextareaField::create('Comment', _t('SilverStripe\\Comments\\Controllers\\CommentingController.COMMENTS', 'Comments'))
|
TextareaField::create('Comment', _t(
|
||||||
|
'SilverStripe\\Comments\\Controllers\\CommentingController.COMMENTS',
|
||||||
|
'Comments'
|
||||||
|
))
|
||||||
->setCustomValidationMessage($commentRequired)
|
->setCustomValidationMessage($commentRequired)
|
||||||
->setAttribute('data-msg-required', $commentRequired)
|
->setAttribute('data-msg-required', $commentRequired)
|
||||||
),
|
),
|
||||||
@ -92,7 +98,7 @@ class CommentForm extends Form
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$required = new RequiredFields(
|
$required = RequiredFields::create(
|
||||||
$controller->config()->required_fields
|
$controller->config()->required_fields
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -102,51 +108,59 @@ class CommentForm extends Form
|
|||||||
// if the record exists load the extra required data
|
// if the record exists load the extra required data
|
||||||
if ($record = $controller->getOwnerRecord()) {
|
if ($record = $controller->getOwnerRecord()) {
|
||||||
// Load member data
|
// Load member data
|
||||||
$member = Member::currentUser();
|
$member = Security::getCurrentUser();
|
||||||
if (($record->CommentsRequireLogin || $record->PostingRequiredPermission) && $member) {
|
if (($record->CommentsRequireLogin || $record->PostingRequiredPermission) && $member) {
|
||||||
$fields = $this->Fields();
|
$fields = $this->Fields();
|
||||||
|
|
||||||
$fields->removeByName('Name');
|
$fields->removeByName('Name');
|
||||||
$fields->removeByName('Email');
|
$fields->removeByName('Email');
|
||||||
$fields->insertBefore(
|
$fields->insertBefore(
|
||||||
new ReadonlyField(
|
ReadonlyField::create(
|
||||||
'NameView',
|
'NameView',
|
||||||
_t('CommentInterface.YOURNAME', 'Your name'),
|
_t('CommentInterface.YOURNAME', 'Your name'),
|
||||||
$member->getName()
|
$member->getName()
|
||||||
),
|
),
|
||||||
'URL'
|
'URL'
|
||||||
);
|
);
|
||||||
$fields->push(new HiddenField('Name', '', $member->getName()));
|
$fields->push(HiddenField::create('Name', '', $member->getName()));
|
||||||
$fields->push(new HiddenField('Email', '', $member->Email));
|
$fields->push(HiddenField::create('Email', '', $member->Email));
|
||||||
}
|
}
|
||||||
|
|
||||||
// we do not want to read a new URL when the form has already been submitted
|
// we do not want to read a new URL when the form has already been submitted
|
||||||
// which in here, it hasn't been.
|
// which in here, it hasn't been.
|
||||||
$this->loadDataFrom(array(
|
$this->loadDataFrom([
|
||||||
'ParentID' => $record->ID,
|
'ParentID' => $record->ID,
|
||||||
'ReturnURL' => $controller->getRequest()->getURL(),
|
'ReturnURL' => $controller->getRequest()->getURL(),
|
||||||
'ParentClassName' => $controller->getParentClass()
|
'ParentClassName' => $controller->getParentClass()
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set it so the user gets redirected back down to the form upon form fail
|
// Set it so the user gets redirected back down to the form upon form fail
|
||||||
$this->setRedirectToFormOnValidationError(true);
|
$this->setRedirectToFormOnValidationError(true);
|
||||||
|
|
||||||
// load any data from the cookies
|
// load any data from the session
|
||||||
if ($data = Cookie::get('CommentsForm_UserData')) {
|
$data = $this->getSessionData();
|
||||||
$data = Convert::json2array($data);
|
if (!is_array($data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->loadDataFrom(array(
|
// load user data from previous form request back into form.
|
||||||
'Name' => isset($data['Name']) ? $data['Name'] : '',
|
if (array_key_exists('UserData', $data)) {
|
||||||
'URL' => isset($data['URL']) ? $data['URL'] : '',
|
$formData = Convert::json2array($data['UserData']);
|
||||||
'Email' => isset($data['Email']) ? $data['Email'] : ''
|
|
||||||
));
|
|
||||||
|
|
||||||
// allow previous value to fill if comment not stored in cookie (i.e. validation error)
|
$this->loadDataFrom([
|
||||||
$prevComment = Cookie::get('CommentsForm_Comment');
|
'Name' => isset($formData['Name']) ? $formData['Name'] : '',
|
||||||
|
'URL' => isset($formData['URL']) ? $formData['URL'] : '',
|
||||||
|
'Email' => isset($formData['Email']) ? $formData['Email'] : ''
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow previous value to fill if comment
|
||||||
|
if (array_key_exists('Comment', $data)) {
|
||||||
|
$prevComment = $data['Comment'];
|
||||||
|
|
||||||
if ($prevComment && $prevComment != '') {
|
if ($prevComment && $prevComment != '') {
|
||||||
$this->loadDataFrom(array('Comment' => $prevComment));
|
$this->loadDataFrom(['Comment' => $prevComment]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,8 +198,10 @@ class CommentForm extends Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cache users data
|
// cache users data
|
||||||
Cookie::set('CommentsForm_UserData', Convert::raw2json($data));
|
$form->setSessionData([
|
||||||
Cookie::set('CommentsForm_Comment', $data['Comment']);
|
'UserData' => Convert::raw2json($data),
|
||||||
|
'Comment' => $data['Comment']
|
||||||
|
]);
|
||||||
|
|
||||||
// extend hook to allow extensions. Also see onAfterPostComment
|
// extend hook to allow extensions. Also see onAfterPostComment
|
||||||
$this->controller->extend('onBeforePostComment', $form);
|
$this->controller->extend('onBeforePostComment', $form);
|
||||||
@ -203,7 +219,7 @@ class CommentForm extends Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($member = Security::getCurrentUser()) {
|
if ($member = Security::getCurrentUser()) {
|
||||||
$form->Fields()->push(new HiddenField('AuthorID', 'Author ID', $member->ID));
|
$form->Fields()->push(HiddenField::create('AuthorID', 'Author ID', $member->ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
// What kind of moderation is required?
|
// What kind of moderation is required?
|
||||||
@ -246,8 +262,16 @@ class CommentForm extends Form
|
|||||||
$this->getRequest()->getSession()->set('CommentsModerated', 1);
|
$this->getRequest()->getSession()->set('CommentsModerated', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the users comment since it passed validation
|
// clear the users comment since the comment was successful.
|
||||||
Cookie::set('CommentsForm_Comment', false);
|
if ($comment->exists()) {
|
||||||
|
// Remove the comment data as it's been saved already.
|
||||||
|
unset($data['Comment']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cache users data (name, email, etc to prepopulate on other forms).
|
||||||
|
$form->setSessionData([
|
||||||
|
'UserData' => Convert::raw2json($data),
|
||||||
|
]);
|
||||||
|
|
||||||
// Find parent link
|
// Find parent link
|
||||||
if (!empty($data['ReturnURL'])) {
|
if (!empty($data['ReturnURL'])) {
|
||||||
|
Loading…
Reference in New Issue
Block a user