1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 00:06:55 +02:00
This commit is contained in:
Ryan Cramer
2017-04-14 06:12:44 -04:00
parent b914586f6c
commit fb1cc857f2

View File

@@ -2,7 +2,16 @@
class CommentNotifications extends Wire { class CommentNotifications extends Wire {
/**
* @var Page
*
*/
protected $page; protected $page;
/**
* @var Field
*
*/
protected $field; protected $field;
/* /*
@@ -42,7 +51,7 @@ class CommentNotifications extends Wire {
$actionURL = $page->httpUrl . "?field=$field->name&page_id=$page->id&code=$comment->code&comment_success="; $actionURL = $page->httpUrl . "?field=$field->name&page_id=$page->id&code=$comment->code&comment_success=";
// skip notification when spam // skip notification when spam
if($comment->status == Comment::statusSpam && !$field->notifySpam) return; if($comment->status == Comment::statusSpam && !$field->notifySpam) return 0;
if($comment->status == Comment::statusPending) { if($comment->status == Comment::statusPending) {
$status = $this->_("Pending Approval"); $status = $this->_("Pending Approval");
@@ -117,7 +126,8 @@ class CommentNotifications extends Wire {
$value = "$info[value] (<a href='$actionURL'>$actionLabel</a>)"; $value = "$info[value] (<a href='$actionURL'>$actionLabel</a>)";
} else if($key == 'page') { } else if($key == 'page') {
$value = "<a href='$info[value]'>$page->title</a> (<a href='$page->editUrl'>" . $this->_('Edit') . ")"; $editUrl = $page->editUrl(true);
$value = "<a href='$info[value]'>$page->title</a> (<a href='$editUrl'>" . $this->_('Edit') . ")";
} else { } else {
$value = $this->wire('sanitizer')->entities($info['value']); $value = $this->wire('sanitizer')->entities($info['value']);
@@ -241,6 +251,9 @@ class CommentNotifications extends Wire {
$action = $this->wire('sanitizer')->pageName($action); $action = $this->wire('sanitizer')->pageName($action);
$status = null; $status = null;
/** @var FieldtypeComments $fieldtype */
$fieldtype = $this->field->type;
switch($action) { switch($action) {
case 'approve': $status = Comment::statusApproved; break; case 'approve': $status = Comment::statusApproved; break;
case 'spam': $status = Comment::statusSpam; break; case 'spam': $status = Comment::statusSpam; break;
@@ -278,7 +291,7 @@ class CommentNotifications extends Wire {
return $info; return $info;
} else if($action == 'upvote' || $action == 'downvote') { } else if($action == 'upvote' || $action == 'downvote') {
$info = array_merge($info, $this->field->type->checkVoteAction($this->page)); $info = array_merge($info, $fieldtype->checkVoteAction($this->page));
return $info; return $info;
} }
@@ -316,7 +329,7 @@ class CommentNotifications extends Wire {
$info['valid'] = true; // all required vars are present $info['valid'] = true; // all required vars are present
$comment = $this->field->type->getCommentByCode($page, $field, $code); $comment = $fieldtype->getCommentByCode($page, $field, $code);
if(!$comment) { if(!$comment) {
$info['message'] = "Invalid comment code or code has already been used"; $info['message'] = "Invalid comment code or code has already been used";
return $info; return $info;
@@ -328,7 +341,7 @@ class CommentNotifications extends Wire {
'code' => null // remove code, since it is a 1-time use code 'code' => null // remove code, since it is a 1-time use code
); );
if($this->field->type->updateComment($page, $field, $comment, $properties)) { if($fieldtype->updateComment($page, $field, $comment, $properties)) {
$info['message'] = "Updated comment $comment->id to '$action'"; $info['message'] = "Updated comment $comment->id to '$action'";
$info['success'] = true; $info['success'] = true;
$this->wire('log')->message($info['message']); $this->wire('log')->message($info['message']);
@@ -408,8 +421,9 @@ class CommentNotifications extends Wire {
* Send a user (not admin) notification email * Send a user (not admin) notification email
* *
* @param Comment $comment * @param Comment $comment
* @param $email * @param string $email
* @param $subcode * @param string $subcode
* @return int
* *
*/ */
public function ___sendNotificationEmail(Comment $comment, $email, $subcode) { public function ___sendNotificationEmail(Comment $comment, $email, $subcode) {