This repository has been archived by the owner on Oct 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Editing of Comments by Author - Deleting of Comments by Author - Send Mail to News Author on Comment Submit
- Loading branch information
David Chalupsky
committed
Sep 12, 2023
1 parent
ebe1d7a
commit 2a765b9
Showing
28 changed files
with
800 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
* | 2015 Dennis Roemmich <[email protected]> | ||
* | 2016-2017 Christian Wolfram <[email protected]> | ||
*/ | ||
|
||
use GeorgRinger\News\Domain\Repository\NewsRepository; | ||
use T3\PwComments\Domain\Model\Comment; | ||
use T3\PwComments\Domain\Model\Vote; | ||
use T3\PwComments\Domain\Repository\CommentRepository; | ||
|
@@ -17,10 +19,14 @@ | |
use T3\PwComments\Utility\Mail; | ||
use T3\PwComments\Utility\Settings; | ||
use T3\PwComments\Utility\StringUtility; | ||
use TYPO3\CMS\Core\DataHandling\DataHandler; | ||
use TYPO3\CMS\Core\Messaging\FlashMessage; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser; | ||
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository; | ||
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException; | ||
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException; | ||
use TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException; | ||
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; | ||
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult; | ||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; | ||
|
@@ -208,12 +214,14 @@ public function indexAction(Comment $commentToReplyTo = null) | |
} | ||
} | ||
} | ||
|
||
$this->view->assign('upvotedCommentUids', $upvotedCommentUids); | ||
$this->view->assign('downvotedCommentUids', $downvotedCommentUids); | ||
|
||
$this->view->assign('comments', $comments); | ||
$this->view->assign('commentCount', $this->calculateCommentCount($comments)); | ||
$this->view->assign('commentToReplyTo', $commentToReplyTo); | ||
$this->view->assign('userIdent', $this->currentAuthorIdent); | ||
} | ||
|
||
/** | ||
|
@@ -254,8 +262,8 @@ public function createAction(Comment $newComment = null) | |
$newComment->setAuthor($author); | ||
} else { | ||
$newComment->setAuthor(null); | ||
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_unregistredUserName', $newComment->getAuthorName()); | ||
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_unregistredUserMail', $newComment->getAuthorMail()); | ||
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_unregisteredUserName', $newComment->getAuthorName()); | ||
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_unregisteredUserMail', $newComment->getAuthorMail()); | ||
} | ||
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_lastComment', time()); | ||
|
||
|
@@ -280,6 +288,16 @@ public function createAction(Comment $newComment = null) | |
$this->commentRepository->add($newComment); | ||
$this->getPersistenceManager()->persistAll(); | ||
|
||
if (isset($this->settings['sendMailOnNewCommentsToNewsAuthor']) && $this->settings['sendMailOnNewCommentsToNewsAuthor']) { | ||
$newsRepository = GeneralUtility::makeInstance(NewsRepository::class); | ||
$news = $newsRepository->findByUid($newComment->getEntryUid()); | ||
$this->mailUtility->setFluidTemplate($this->makeFluidTemplateObject()); | ||
$this->mailUtility->setControllerContext($this->controllerContext); | ||
$this->mailUtility->setReceivers($news->getAuthorEmail()); | ||
$this->mailUtility->setTemplatePath($this->settings['sendMailNewsAuthorTemplate']); | ||
$this->mailUtility->sendMail($newComment, HashEncryptionUtility::createHashForComment($newComment)); | ||
} | ||
|
||
if (isset($this->settings['sendMailOnNewCommentsTo']) && $this->settings['sendMailOnNewCommentsTo']) { | ||
$this->mailUtility->setFluidTemplate($this->makeFluidTemplateObject()); | ||
$this->mailUtility->setControllerContext($this->controllerContext); | ||
|
@@ -326,22 +344,192 @@ public function newAction(Comment $newComment = null, Comment $commentToReplyTo | |
} | ||
$this->view->assign('commentToReplyTo', $commentToReplyTo); | ||
|
||
// Get name of unregistred user | ||
// Get name of unregistered user | ||
if ($newComment !== null && $newComment->getAuthorName()) { | ||
$unregistredUserName = $newComment->getAuthorName(); | ||
$unregisteredUserName = $newComment->getAuthorName(); | ||
} else { | ||
$unregistredUserName = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_pwcomments_unregistredUserName'); | ||
$unregisteredUserName = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_pwcomments_unregisteredUserName'); | ||
} | ||
|
||
// Get mail of unregistred user | ||
// Get mail of unregistered user | ||
if ($newComment !== null && $newComment->getAuthorMail()) { | ||
$unregistredUserMail = $newComment->getAuthorMail(); | ||
$unregisteredUserMail = $newComment->getAuthorMail(); | ||
} else { | ||
$unregisteredUserMail = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_pwcomments_unregisteredUserMail'); | ||
} | ||
|
||
$this->view->assign('unregisteredUserName', $unregisteredUserName); | ||
$this->view->assign('unregisteredUserMail', $unregisteredUserMail); | ||
} | ||
|
||
/** | ||
* Edit action | ||
* | ||
* @param Comment|null $updateComment Comment | ||
* @return void | ||
* | ||
* @TYPO3\CMS\Extbase\Annotation\IgnoreValidation("updateComment") | ||
*/ | ||
public function editAction(Comment $updateComment = null): void | ||
{ | ||
if ($updateComment !== null) { | ||
$this->view->assign('updateComment', $updateComment); | ||
} | ||
|
||
// Get name of unregistered user | ||
if ($updateComment !== null && $updateComment->getAuthorName()) { | ||
$unregisteredUserName = $updateComment->getAuthorName(); | ||
} else { | ||
$unregistredUserMail = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_pwcomments_unregistredUserMail'); | ||
$unregisteredUserName = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_pwcomments_unregisteredUserName'); | ||
} | ||
|
||
$this->view->assign('unregistredUserName', $unregistredUserName); | ||
$this->view->assign('unregistredUserMail', $unregistredUserMail); | ||
// Get mail of unregistered user | ||
if ($updateComment !== null && $updateComment->getAuthorMail()) { | ||
$unregisteredUserMail = $updateComment->getAuthorMail(); | ||
} else { | ||
$unregisteredUserMail = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_pwcomments_unregisteredUserMail'); | ||
} | ||
|
||
$this->view->assign('unregisteredUserName', $unregisteredUserName); | ||
$this->view->assign('unregisteredUserMail', $unregisteredUserMail); | ||
} | ||
|
||
/** | ||
* Update action | ||
* | ||
* @param Comment|null $updateComment | ||
* @return bool | ||
* @throws StopActionException | ||
* @throws IllegalObjectTypeException | ||
* @throws UnknownObjectException | ||
* @TYPO3\CMS\Extbase\Annotation\Validate("T3\PwComments\Domain\Validator\CommentValidator", param="updateComment") | ||
*/ | ||
public function updateAction(Comment $updateComment = null): bool | ||
{ | ||
// Hidden field Spam-Protection | ||
if (isset($this->settings['hiddenFieldSpamProtection']) && $this->settings['hiddenFieldSpamProtection'] | ||
&& $this->request->hasArgument($this->settings['hiddenFieldName']) | ||
&& $this->request->getArgument($this->settings['hiddenFieldName'])) { | ||
$this->redirectToUri($this->buildUriByUid($this->pageUid) . '#' . $this->settings['updateCommentAnchor']); | ||
return false; | ||
} | ||
if ($updateComment === null) { | ||
$this->redirectToUri($this->buildUriByUid($this->pageUid)); | ||
return false; | ||
} | ||
$this->createAuthorIdent(); | ||
|
||
$updateComment->setMessage( | ||
StringUtility::prepareCommentMessage($updateComment->getMessage(), $this->settings['linkUrlsInComments']) | ||
); | ||
|
||
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_pwcomments_lastComment', time()); | ||
|
||
$translateArguments = [ | ||
'name' => $updateComment->getAuthorName(), | ||
'email' => $updateComment->getCommentAuthorMailAddress(), | ||
'message' => $updateComment->getMessage(), | ||
]; | ||
|
||
// Modify comment if moderation is active | ||
if (isset($this->settings['moderateNewComments']) && $this->settings['moderateNewComments']) { | ||
$updateComment->setHidden(true); | ||
$this->addFlashMessage( | ||
LocalizationUtility::translate('tx_pwcomments.moderationNotice', 'PwComments', $translateArguments) | ||
); | ||
} else { | ||
$this->addFlashMessage( | ||
LocalizationUtility::translate('tx_pwcomments.updateSuccess', 'PwComments', $translateArguments) | ||
); | ||
} | ||
|
||
$this->commentRepository->update($updateComment); | ||
$this->getPersistenceManager()->persistAll(); | ||
$newsRepository = GeneralUtility::makeInstance(NewsRepository::class); | ||
$news = $newsRepository->findByUid($updateComment->getEntryUid()); | ||
|
||
|
||
if (isset($this->settings['sendMailOnNewCommentsToNewsAuthor']) && $this->settings['sendMailOnNewCommentsToNewsAuthor']) { | ||
$newsRepository = GeneralUtility::makeInstance(NewsRepository::class); | ||
$news = $newsRepository->findByUid($updateComment->getEntryUid()); | ||
$this->mailUtility->setFluidTemplate($this->makeFluidTemplateObject()); | ||
$this->mailUtility->setControllerContext($this->controllerContext); | ||
$this->mailUtility->setReceivers($news->getAuthorEmail()); | ||
$this->mailUtility->setTemplatePath($this->settings['sendMailNewsAuthorUpdateTemplate']); | ||
$this->mailUtility->setSubjectLocallangKey('tx_pwcomments.notificationMail.update.subject'); | ||
$this->mailUtility->sendMail($updateComment, HashEncryptionUtility::createHashForComment($updateComment)); | ||
} | ||
|
||
if (isset($this->settings['sendMailOnNewCommentsTo']) && $this->settings['sendMailOnNewCommentsTo']) { | ||
$this->mailUtility->setFluidTemplate($this->makeFluidTemplateObject()); | ||
$this->mailUtility->setControllerContext($this->controllerContext); | ||
$this->mailUtility->setReceivers($this->settings['sendMailOnNewCommentsTo']); | ||
$this->mailUtility->setTemplatePath($news === null ? $this->settings['sendMailUpdateTemplate'] : $this->settings['sendMailNewsAuthorUpdateTemplate']); | ||
$this->mailUtility->setSubjectLocallangKey('tx_pwcomments.notificationMail.update.subject'); | ||
$this->mailUtility->sendMail($updateComment, HashEncryptionUtility::createHashForComment($updateComment)); | ||
} | ||
|
||
if (isset($this->settings['sendMailToAuthorAfterSubmit']) && | ||
$this->settings['sendMailToAuthorAfterSubmit'] && | ||
$updateComment->hasCommentAuthorMailAddress() | ||
) { | ||
$this->mailUtility->setFluidTemplate($this->makeFluidTemplateObject()); | ||
$this->mailUtility->setControllerContext($this->controllerContext); | ||
$this->mailUtility->setReceivers($updateComment->getCommentAuthorMailAddress()); | ||
$this->mailUtility->setTemplatePath($news === null ? $this->settings['sendMailToAuthorAfterSubmitUpdateTemplate'] : $this->settings['sendMailNewsAuthorUpdateTemplate']); | ||
$this->mailUtility->setSubjectLocallangKey('tx_pwcomments.notificationMail.update.subject'); | ||
$this->mailUtility->sendMail($updateComment); | ||
} | ||
|
||
if (isset($this->settings['moderateNewComments']) && $this->settings['moderateNewComments']) { | ||
$anchor = '#' . $this->settings['successfulAnchor']; | ||
} else { | ||
$anchor = '#' . $this->settings['commentAnchorPrefix'] . $updateComment->getUid(); | ||
} | ||
|
||
$this->redirectToUri($this->buildUriByUid($this->pageUid, true) . $anchor); | ||
} | ||
|
||
/** | ||
* Delete action | ||
* | ||
* @param string $commentUid Comment | ||
* @return void | ||
* | ||
* @TYPO3\CMS\Extbase\Annotation\IgnoreValidation("commentUid") | ||
*/ | ||
public function deleteAction(string $commentUid): void | ||
{ | ||
$commentWithReplies = $this->commentRepository->findByCommentUid($commentUid); | ||
$dataHandler = GeneralUtility::makeInstance(DataHandler::class); | ||
if (null !== $commentWithReplies) { | ||
$votes = $commentWithReplies->getVotes()->toArray(); | ||
if (!empty($votes)) { | ||
foreach ($votes as $vote) { | ||
$cmd['tx_pwcomments_domain_model_vote'][$vote->getUid()]['delete'] = 1; | ||
} | ||
} | ||
$replies = $commentWithReplies->getReplies()->toArray(); | ||
if ($replies !== null) { | ||
foreach ($replies as $reply) { | ||
$cmd['tx_pwcomments_domain_model_comment'][$reply->getUid()]['delete'] = 1; | ||
$replyVotes = $reply->getVotes()->toArray(); | ||
if (!empty($replyVotes)) { | ||
foreach ($replyVotes as $replyVote) { | ||
$cmd['tx_pwcomments_domain_model_vote'][$replyVote->getUid()]['delete'] = 1; | ||
} | ||
} | ||
} | ||
} | ||
$cmd['tx_pwcomments_domain_model_comment'][$commentWithReplies->getUid()]['delete'] = 1; | ||
$dataHandler->start([], $cmd); | ||
$dataHandler->process_cmdmap(); | ||
$this->addFlashMessage( | ||
LocalizationUtility::translate('tx_pwcomments.custom.deletedComment', 'PwComments') | ||
); | ||
} | ||
|
||
$this->redirectToUri($this->buildUriByUid($this->pageUid, true)); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
* | 2015 Dennis Roemmich <[email protected]> | ||
* | 2016-2017 Christian Wolfram <[email protected]> | ||
*/ | ||
|
||
use GeorgRinger\News\Domain\Repository\NewsRepository; | ||
use TYPO3\CMS\Core\Mail\MailMessage; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext; | ||
|
@@ -156,15 +158,23 @@ protected function getMailMessage(Comment $comment, $hash) | |
if (!file_exists($mailTemplate)) { | ||
throw new \Exception('Mail template (' . $mailTemplate . ') not found. '); | ||
} | ||
|
||
$this->fluidTemplate->setTemplatePathAndFilename($mailTemplate); | ||
$this->fluidTemplate->assignMultiple( | ||
[ | ||
'hash' => $hash, | ||
'comment' => $comment, | ||
'settings' => $this->settings | ||
] | ||
); | ||
$params = [ | ||
'hash' => $hash, | ||
'comment' => $comment, | ||
'settings' => $this->settings | ||
]; | ||
|
||
if (isset($this->settings['sendMailOnNewCommentsToNewsAuthor'])) { | ||
$newsRepository = GeneralUtility::makeInstance(NewsRepository::class); | ||
$news = $newsRepository->findByUid($comment->getEntryUid()); | ||
if (null !== $news) { | ||
$params['news'] = $news; | ||
$params['site'] = GeneralUtility::getIndpEnv('HTTP_HOST'); | ||
} | ||
} | ||
$this->fluidTemplate->assignMultiple($params); | ||
|
||
return $this->fluidTemplate->render(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.