mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
Additional minor updates to ProcessCommentsManager
This commit is contained in:
@@ -414,6 +414,7 @@ class ProcessCommentsManager extends Process {
|
|||||||
*/
|
*/
|
||||||
protected function ___executeEdit() {
|
protected function ___executeEdit() {
|
||||||
|
|
||||||
|
$sanitizer = $this->wire()->sanitizer;
|
||||||
$input = $this->wire()->input;
|
$input = $this->wire()->input;
|
||||||
$user = $this->wire()->user;
|
$user = $this->wire()->user;
|
||||||
$submit = false;
|
$submit = false;
|
||||||
@@ -456,14 +457,18 @@ class ProcessCommentsManager extends Process {
|
|||||||
$comment->cite = $user->get('title|name');
|
$comment->cite = $user->get('title|name');
|
||||||
$comment->email = $user->get('email');
|
$comment->email = $user->get('email');
|
||||||
$comment->created = time();
|
$comment->created = time();
|
||||||
|
$comment->status = Comment::statusApproved;
|
||||||
if($parentId) {
|
if($parentId) {
|
||||||
// new comment that is reply to existing comment
|
// new comment that is reply to existing comment
|
||||||
$parentComment = $field->getCommentByID($page, $parentId);
|
$parentComment = $field->getCommentByID($page, $parentId);
|
||||||
if(!$parentComment) throw new WireException("Cannot find parent comment $parentId");
|
if(!$parentComment) throw new WireException("Cannot find parent comment $parentId");
|
||||||
$comment->parent_id = $parentId;
|
$comment->parent_id = $parentId;
|
||||||
$this->headline(sprintf($this->_('Comment #%d by %s'), $parentId, $comment->getFormatted('cite')));
|
$this->headline(sprintf($this->_('Comment #%d by %s'), $parentId, $parentComment->getFormatted('cite')));
|
||||||
// show comment being replied to
|
// show comment being replied to
|
||||||
$out .= '<blockquote><p>' . $parentComment->getFormattedCommentText() . '</p></blockquote>';
|
$text = $sanitizer->entities1($parentComment->getFormattedCommentText());
|
||||||
|
$when = date('Y/m/d H:i', $parentComment->created) . ' • ' . wireRelativeTimeStr($parentComment->created);
|
||||||
|
$out .= "<p class='detail'>$when</p>";
|
||||||
|
$out .= "<blockquote><p>$text</p></blockquote>";
|
||||||
$out .= "<h2>" . $this->_('Your reply') . "</h2>";
|
$out .= "<h2>" . $this->_('Your reply') . "</h2>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,7 +610,7 @@ class ProcessCommentsManager extends Process {
|
|||||||
/** @var InputfieldText $f */
|
/** @var InputfieldText $f */
|
||||||
$f = $modules->get('InputfieldText');
|
$f = $modules->get('InputfieldText');
|
||||||
$f->attr('name', 'cite');
|
$f->attr('name', 'cite');
|
||||||
$f->label = $this->_('Cite');
|
$f->label = $this->_('Cite / author');
|
||||||
$f->val($comment->cite);
|
$f->val($comment->cite);
|
||||||
$f->required = true;
|
$f->required = true;
|
||||||
$f->columnWidth = 50;
|
$f->columnWidth = 50;
|
||||||
@@ -661,24 +666,14 @@ class ProcessCommentsManager extends Process {
|
|||||||
$f->required = true;
|
$f->required = true;
|
||||||
$form->add($f);
|
$form->add($f);
|
||||||
|
|
||||||
if($field->useStars && $comment->id) {
|
|
||||||
/** @var InputfieldMarkup $f */
|
|
||||||
$f = $modules->get('InputfieldMarkup');
|
|
||||||
$f->attr('name', 'stars');
|
|
||||||
$f->label = $this->_('Stars');
|
|
||||||
$f->value =
|
|
||||||
"<input type='hidden' name='stars' value='$comment->stars' />" .
|
|
||||||
$comment->renderStars(array('input' => true));
|
|
||||||
$form->add($f);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($field->useVotes) {
|
if($field->useVotes) {
|
||||||
/** @var InputfieldInteger $f */
|
/** @var InputfieldInteger $f */
|
||||||
$f = $modules->get('InputfieldInteger');
|
$f = $modules->get('InputfieldInteger');
|
||||||
$f->attr('name', 'upvotes');
|
$f->attr('name', 'upvotes');
|
||||||
$f->label = $this->_('Upvotes');
|
$f->label = $this->_('Upvotes');
|
||||||
$f->val($comment->upvotes);
|
$f->val($comment->upvotes);
|
||||||
$f->columnWidth = 50;
|
$f->columnWidth = $field->useStars ? 25 : 50;
|
||||||
|
$f->inputType = 'number';
|
||||||
$form->add($f);
|
$form->add($f);
|
||||||
|
|
||||||
/** @var InputfieldInteger $f */
|
/** @var InputfieldInteger $f */
|
||||||
@@ -686,26 +681,49 @@ class ProcessCommentsManager extends Process {
|
|||||||
$f->attr('name', 'downvotes');
|
$f->attr('name', 'downvotes');
|
||||||
$f->label = $this->_('Downvotes');
|
$f->label = $this->_('Downvotes');
|
||||||
$f->val($comment->upvotes);
|
$f->val($comment->upvotes);
|
||||||
$f->columnWidth = 50;
|
$f->columnWidth = $field->useStars ? 25 : 50;
|
||||||
|
$f->inputType = 'number';
|
||||||
$form->add($f);
|
$form->add($f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var InputfieldSelect $f */
|
if($field->useStars) {
|
||||||
$f = $modules->get('InputfieldSelect');
|
/** @var InputfieldMarkup $f */
|
||||||
|
$f = $modules->get('InputfieldMarkup');
|
||||||
|
$f->attr('name', 'stars');
|
||||||
|
$f->label = $this->_('Stars');
|
||||||
|
$f->value =
|
||||||
|
"<input type='hidden' name='stars' value='$comment->stars' />" .
|
||||||
|
$comment->renderStars(array('input' => true));
|
||||||
|
if($field->useVotes) $f->columnWidth = 50;
|
||||||
|
$form->add($f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** @var InputfieldRadios $f */
|
||||||
|
$f = $modules->get('InputfieldRadios');
|
||||||
$f->attr('name', 'notify_author');
|
$f->attr('name', 'notify_author');
|
||||||
$f->label = $this->_('Notify comment author');
|
$f->label = $this->_('Notify the email listed above when');
|
||||||
$f->addOption(0, $this->_('Do not send author notifications'));
|
$f->addOption(0, $this->_('Never'));
|
||||||
if($field->depth) $f->addOption(Comment::flagNotifyReply, $this->_('Notify author of replies to this comment'));
|
if($field->depth) $f->addOption(Comment::flagNotifyReply, $this->_('There is a reply to this comment'));
|
||||||
$f->addOption(Comment::flagNotifyAll, $this->_('Notify author of all new comments on page'));
|
$f->addOption(Comment::flagNotifyAll, $this->_('Anytime a new comment is posted on this page'));
|
||||||
|
if($comment->flags & Comment::flagNotifyAll) {
|
||||||
|
$f->val(Comment::flagNotifyAll);
|
||||||
|
} else if($comment->flags & Comment::flagNotifyReply) {
|
||||||
|
$f->val(Comment::flagNotifyReply);
|
||||||
|
} else {
|
||||||
|
$f->val(0);
|
||||||
|
}
|
||||||
$form->add($f);
|
$form->add($f);
|
||||||
|
|
||||||
/** @var InputfieldToggle $f */
|
/** @var InputfieldToggle $f */
|
||||||
if(!$comment->id) {
|
if(!$comment->id) {
|
||||||
|
$f->columnWidth = 50;
|
||||||
$f = $modules->get('InputfieldToggle');
|
$f = $modules->get('InputfieldToggle');
|
||||||
$f->attr('name', 'notify');
|
$f->attr('name', 'notify');
|
||||||
$f->label = $this->_('Allow notifications to be sent for this comment?');
|
$f->label = $this->_('Allow notifications to others?');
|
||||||
$f->description = $this->_('When “Yes”, emails about this new comment will be sent to users that have opted in to receive notifications.');
|
$f->detail = $this->_('When “Yes”, emails about this new comment will be sent to users that have opted in to receive notifications.');
|
||||||
$f->val(true);
|
$f->val(true);
|
||||||
|
$f->columnWidth = 50;
|
||||||
$form->add($f);
|
$form->add($f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,21 +805,27 @@ class ProcessCommentsManager extends Process {
|
|||||||
|
|
||||||
if($field->get('useVotes')) {
|
if($field->get('useVotes')) {
|
||||||
foreach(array("upvotes", "downvotes") as $name) {
|
foreach(array("upvotes", "downvotes") as $name) {
|
||||||
$votes = (int) $input->post("Comment" . ucfirst($name) . $comment->id);
|
$votes = $input->post("Comment" . ucfirst($name) . $comment->id);
|
||||||
if($votes != $comment->$name) {
|
if($votes !== null) {
|
||||||
$comment->set($name, $votes);
|
$votes = (int) $votes;
|
||||||
$properties[$name] = $comment->$name;
|
if($votes != $comment->$name) {
|
||||||
$numChanged++;
|
$comment->set($name, $votes);
|
||||||
|
$properties[$name] = $comment->$name;
|
||||||
|
$numChanged++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($field->get('useStars')) {
|
if($field->get('useStars')) {
|
||||||
$stars = (int) $input->post("CommentStars$comment->id");
|
$stars = $input->post("CommentStars$comment->id");
|
||||||
if($stars != $comment->stars) {
|
if($stars !== null) {
|
||||||
$comment->set('stars', $stars);
|
$stars = (int) $stars;
|
||||||
$properties['stars'] = $comment->stars;
|
if($stars != $comment->stars) {
|
||||||
$numChanged++;
|
$comment->set('stars', $stars);
|
||||||
|
$properties['stars'] = $comment->stars;
|
||||||
|
$numChanged++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,7 +846,7 @@ class ProcessCommentsManager extends Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$notify = $input->post("CommentNotify$comment->id");
|
$notify = $input->post("CommentNotify$comment->id");
|
||||||
if($field->useNotify && ctype_digit($notify)) {
|
if($notify !== null && $field->useNotify && ctype_digit($notify)) {
|
||||||
$notify = (int) $notify;
|
$notify = (int) $notify;
|
||||||
if($this->applyCommentNotifyFlag($comment, $notify)) {
|
if($this->applyCommentNotifyFlag($comment, $notify)) {
|
||||||
$properties['flags'] = $comment->flags;
|
$properties['flags'] = $comment->flags;
|
||||||
@@ -1510,6 +1534,11 @@ class ProcessCommentsManager extends Process {
|
|||||||
$flags = $flags | Comment::flagNotifyReply; // add
|
$flags = $flags | Comment::flagNotifyReply; // add
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($notify && !$comment->id) {
|
||||||
|
// comments added in admin do not need email confirmation
|
||||||
|
$flags = $flags | Comment::flagNotifyConfirmed;
|
||||||
|
}
|
||||||
|
|
||||||
if($flags != $flagsPrev) {
|
if($flags != $flagsPrev) {
|
||||||
$comment->flags = $flags;
|
$comment->flags = $flags;
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user