Skip to content

Commit

Permalink
Merge pull request #48 from Zillion01/dev
Browse files Browse the repository at this point in the history
TYPO3 12
  • Loading branch information
Zillion01 authored Jun 23, 2023
2 parents 1b25981 + 4e86cb1 commit db3723d
Show file tree
Hide file tree
Showing 55 changed files with 9,776 additions and 226 deletions.
2 changes: 1 addition & 1 deletion Classes/Controller/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CategoryController extends ActionController
/**
* @var CategoryRepository
*/
protected $categoryRepository;
protected CategoryRepository $categoryRepository;

/**
* @param CategoryRepository $categoryRepository
Expand Down
47 changes: 12 additions & 35 deletions Classes/Controller/CategorycommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;

class CategorycommentController extends ActionController
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public function initializeAction(): void
*/
public function commentAction(array $catUids, int $pluginUid): ResponseInterface
{
$currentUid = $this->getCurrentUid();
$currentUid = $this->request->getAttribute('currentContentObject')->data['uid'];

if ($currentUid == $pluginUid) {
$this->view->assignMultiple([
Expand Down Expand Up @@ -96,8 +97,7 @@ public function commentAction(array $catUids, int $pluginUid): ResponseInterface
*
* @return ResponseInterface
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws IllegalObjectTypeException
*/
public function addCommentAction(
Categorycomment $newCategorycomment,
Expand All @@ -109,7 +109,7 @@ public function addCommentAction(
$this->redirect('list', 'Question');
}

$currentUid = $this->getCurrentUid();
$currentUid = $this->request->getAttribute('currentContentObject')->data['uid'];

$categories = [];
$categoryNames = '';
Expand Down Expand Up @@ -147,40 +147,29 @@ public function addCommentAction(

$this->categorycommentRepository->add($newCategorycomment);

// SignalSlotDispatcher, connect with this to run a custom action after comment creation
try {
$this->signalSlotDispatcher->dispatch(
__CLASS__,
'NewCategoriesComment',
[$categories, $newCategorycomment]
);
} catch (\Exception $exception) {
// do nothing
}

// Send notification emails
$emailSettings = $this->settings['category']['comment']['email'];

if ($emailSettings['enable']) {
$sender = [htmlspecialchars($emailSettings['sender']['email']) => htmlspecialchars($emailSettings['sender']['name'])];

$emailBodyCenterText = '<br/><strong>' . $categoryNames . '</strong>' . '<p><i>' . $this->formatRte($newCategorycomment->getComment()) . '</i></p><p><i>' . htmlspecialchars($newCategorycomment->getName()) . '<br/>' . htmlspecialchars($newCategorycomment->getEmail()) . '</i></p><br/>';
$emailBodyCenterText = '<br/><strong>' . $categoryNames . '</strong>' . '<p><i>' . $this->formatRte($this->request->getAttribute('currentContentObject'), $newCategorycomment->getComment()) . '</i></p><p><i>' . htmlspecialchars($newCategorycomment->getName()) . '<br/>' . htmlspecialchars($newCategorycomment->getEmail()) . '</i></p><br/>';

SendMailService::sendMail(
$receivers = htmlspecialchars($emailSettings['receivers']['email']),
$sender,
$subject = $emailSettings['subject'],
$body = $this->formatRte($emailSettings['introText']) . $emailBodyCenterText . $this->formatRte($emailSettings['closeText'])
$body = $this->formatRte($this->request->getAttribute('currentContentObject'), $emailSettings['introText']) . $emailBodyCenterText . $this->formatRte($this->request->getAttribute('currentContentObject'), $emailSettings['closeText'])
);

if ($emailSettings['sendCommenterNotification']) {
$emailBodyCenterText = '<br/>' . '<p><i>' . $this->formatRte($newCategorycomment->getComment()) . '</i></p><p><i>' . htmlspecialchars($newCategorycomment->getName()) . '<br/>' . htmlspecialchars($newCategorycomment->getEmail()) . '</i></p><br/>';
$emailBodyCenterText = '<br/>' . '<p><i>' . $this->formatRte($this->request->getAttribute('currentContentObject'), $newCategorycomment->getComment()) . '</i></p><p><i>' . htmlspecialchars($newCategorycomment->getName()) . '<br/>' . htmlspecialchars($newCategorycomment->getEmail()) . '</i></p><br/>';

SendMailService::sendMail(
$receivers = htmlspecialchars($newCategorycomment->getEmail()),
$sender,
$subject = htmlspecialchars($emailSettings['commenter']['subject']),
$body = $this->formatRte($emailSettings['commenter']['introText']) . $emailBodyCenterText . $this->formatRte($emailSettings['commenter']['closeText'])
$body = $this->formatRte($this->request->getAttribute('currentContentObject'), $emailSettings['commenter']['introText']) . $emailBodyCenterText . $this->formatRte($this->request->getAttribute('currentContentObject'), $emailSettings['commenter']['closeText'])
);
}
}
Expand All @@ -204,7 +193,7 @@ public function addCommentAction(
*/
public function thankForCommentAction(Categorycomment $newCategorycomment, int $pluginUid): ResponseInterface
{
$currentUid = $this->getCurrentUid();
$currentUid = $this->request->getAttribute('currentContentObject')->data['uid'];

$emailNotification = (int)$this->settings['category']['comment']['email']['sendCommenterNotification'];

Expand All @@ -229,28 +218,16 @@ public function thankForCommentAction(Categorycomment $newCategorycomment, int $
->createResponse();
}

/**
* Get current uid of content element
*
* @return int
*/
private function getCurrentUid()
{
$cObj = $this->configurationManager->getContentObject();
$currentUid = $cObj->data['uid'];

return $currentUid;
}

/**
* Format / clean a string with parseFunc
*
* @param $request
* @param $str
*
* @return string
*/
private function formatRte($str): string
private function formatRte($request, $str): string
{
return $this->configurationManager->getContentObject()->parseFunc($str, [], '< lib.parseFunc_RTE');
return $request->parseFunc($str, [], '< lib.parseFunc_RTE');
}
}
20 changes: 3 additions & 17 deletions Classes/Controller/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ public function initializeAction(): void
$this->settings['questions']['categories'][] = (int)$category;
}
}

// $str = $this->cObj->parseFunc($str, [], '< lib.parseFunc_RTE');
// return $str;
}

/**
Expand All @@ -96,7 +93,7 @@ public function listAction(): ResponseInterface
$restrictToCategories = ['no categories'];
}

$currentUid = $this->getCurrentUid();
$currentUid = $this->request->getAttribute('currentContentObject')->data['uid'];

$this->view->assignMultiple([
'showSearchForm' => (int)$this->settings['flexform']['showSearch'],
Expand Down Expand Up @@ -125,9 +122,9 @@ public function listAction(): ResponseInterface
* @throws IllegalObjectTypeException
* @throws UnknownObjectException
*/
public function helpfulnessAction(Question $question, bool $helpful, int $pluginUid)
public function helpfulnessAction(Question $question, bool $helpful, int $pluginUid): ResponseInterface|ForwardResponse
{
$currentUid = $this->getCurrentUid();
$currentUid = $this->request->getAttribute('currentContentObject')->data['uid'];

if ($currentUid == $pluginUid) {
$this->updateHelpful($question, $helpful);
Expand All @@ -148,17 +145,6 @@ public function helpfulnessAction(Question $question, bool $helpful, int $plugin
->createResponse();
}

/**
* Get current uid of content element
*
* @return int
*/
private function getCurrentUid(): int
{
$cObj = $this->configurationManager->getContentObject();
return $cObj->data['uid'];
}

/**
* Update helpful or nothelpful of a question in db and session
*
Expand Down
41 changes: 11 additions & 30 deletions Classes/Controller/QuestioncommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
use TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException;

Expand Down Expand Up @@ -74,7 +73,7 @@ public function initializeAction(): void
*/
public function commentAction(Question $question): ResponseInterface
{
$currentUid = $this->getCurrentUid();
$currentUid = $this->request->getAttribute('currentContentObject')->data['uid'];

$this->view->assignMultiple([
'currentUid' => $currentUid,
Expand All @@ -94,16 +93,15 @@ public function commentAction(Question $question): ResponseInterface
* @param int $pluginUid
*
* @return ResponseInterface|ForwardResponse
* @throws StopActionException
*/
public function addCommentAction(Question $question, Questioncomment $newQuestioncomment, int $pluginUid)
public function addCommentAction(Question $question, Questioncomment $newQuestioncomment, int $pluginUid): ResponseInterface|ForwardResponse
{
// If honeypot field 'finfo' is filled by spambot do not add new comment
if ($newQuestioncomment->getFinfo()) {
$this->redirect('list', 'Question');
}

$currentUid = $this->getCurrentUid();
$currentUid = $this->request->getAttribute('currentContentObject')->data['uid'];
$anonymizeIpSetting = null;

if ($currentUid == $pluginUid) {
Expand Down Expand Up @@ -132,36 +130,29 @@ public function addCommentAction(Question $question, Questioncomment $newQuestio
} catch (IllegalObjectTypeException|UnknownObjectException $e) {
}

// SignalSlotDispatcher, connect with this to run a custom action after comment creation
try {
$this->signalSlotDispatcher->dispatch(__CLASS__, 'NewFaqComment', [$question, $newQuestioncomment]);
} catch (\Exception $exception) {
// do nothing
}

// Send notification emails
$emailSettings = $this->settings['question']['comment']['email'];

if ($emailSettings['enable']) {
$emailBodyCenterText = '<br/><strong>' . $question->getUid() . '. ' . $question->getQuestion() . '</strong>' . '<p><i>' . $this->formatRte($newQuestioncomment->getComment()) . '</i></p><p><i>' . htmlspecialchars($newQuestioncomment->getName()) . '<br/>' . htmlspecialchars($newQuestioncomment->getEmail()) . '</i></p><br/>';
$emailBodyCenterText = '<br/><strong>' . $question->getUid() . '. ' . $question->getQuestion() . '</strong>' . '<p><i>' . $this->formatRte($this->request->getAttribute('currentContentObject'), $newQuestioncomment->getComment()) . '</i></p><p><i>' . htmlspecialchars($newQuestioncomment->getName()) . '<br/>' . htmlspecialchars($newQuestioncomment->getEmail()) . '</i></p><br/>';

$sender = [htmlspecialchars($emailSettings['sender']['email']) => htmlspecialchars($emailSettings['sender']['name'])];

SendMailService::sendMail(
$receivers = htmlspecialchars($emailSettings['receivers']['email']),
$sender,
$subject = htmlspecialchars($emailSettings['subject']),
$body = $this->formatRte($emailSettings['introText']) . $emailBodyCenterText . $this->formatRte($emailSettings['closeText'])
$body = $this->formatRte($this->request->getAttribute('currentContentObject'), $emailSettings['introText']) . $emailBodyCenterText . $this->formatRte($this->request->getAttribute('currentContentObject'), $emailSettings['closeText'])
);

if ($emailSettings['sendCommenterNotification']) {
$emailBodyCenterText = '<br/><strong>' . $question->getQuestion() . '</strong>' . '<p><i>' . $this->formatRte($newQuestioncomment->getComment()) . '</i></p><p><i>' . htmlspecialchars($newQuestioncomment->getName()) . '<br/>' . htmlspecialchars($newQuestioncomment->getEmail()) . '</i></p><br/>';
$emailBodyCenterText = '<br/><strong>' . $question->getQuestion() . '</strong>' . '<p><i>' . $this->formatRte($this->request->getAttribute('currentContentObject'), $newQuestioncomment->getComment()) . '</i></p><p><i>' . htmlspecialchars($newQuestioncomment->getName()) . '<br/>' . htmlspecialchars($newQuestioncomment->getEmail()) . '</i></p><br/>';

SendMailService::sendMail(
$receivers = htmlspecialchars($newQuestioncomment->getEmail()),
$sender,
$subject = htmlspecialchars($emailSettings['commenter']['subject']),
$body = $this->formatRte($emailSettings['commenter']['introText']) . $emailBodyCenterText . $this->formatRte($emailSettings['commenter']['closeText'])
$body = $this->formatRte($this->request->getAttribute('currentContentObject'), $emailSettings['commenter']['introText']) . $emailBodyCenterText . $this->formatRte($this->request->getAttribute('currentContentObject'), $emailSettings['commenter']['closeText'])
);
}
}
Expand All @@ -185,7 +176,7 @@ public function addCommentAction(Question $question, Questioncomment $newQuestio
*/
public function thankForCommentAction(Questioncomment $newQuestioncomment, int $pluginUid): ResponseInterface
{
$currentUid = $this->getCurrentUid();
$currentUid = $this->request->getAttribute('currentContentObject')->data['uid'];

$emailNotification = (int)$this->settings['question']['comment']['email']['sendCommenterNotification'];

Expand All @@ -210,26 +201,16 @@ public function thankForCommentAction(Questioncomment $newQuestioncomment, int $
->createResponse();
}

/**
* Get current uid of content element
*
* @return int
*/
private function getCurrentUid(): int
{
$cObj = $this->configurationManager->getContentObject();
return $cObj->data['uid'];
}

/**
* Format / clean a string with parseFunc
*
* @param $request
* @param $str
*
* @return string
*/
private function formatRte($str): string
private function formatRte($request, $str): string
{
return $this->configurationManager->getContentObject()->parseFunc($str, [], '< lib.parseFunc_RTE');
return $request->parseFunc($str, [], '< lib.parseFunc_RTE');
}
}
2 changes: 0 additions & 2 deletions Classes/Domain/Model/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Question extends AbstractEntity
/**
* answer
*
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
*
* @var string
*/
protected $answer = '';
Expand Down
17 changes: 9 additions & 8 deletions Classes/Domain/Repository/QuestionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jp\Jpfaq\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
Expand All @@ -24,10 +25,10 @@ class QuestionRepository extends Repository
* @param array $categories
* @param bool $excludeAlreadyDisplayedQuestions
*
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @return array|QueryResultInterface
* @throws InvalidQueryException
*/
public function findQuestionsWithConstraints(array $categories = [], bool $excludeAlreadyDisplayedQuestions = false)
public function findQuestionsWithConstraints(array $categories = [], bool $excludeAlreadyDisplayedQuestions = false): QueryResultInterface|array
{
$query = $this->createQuery();
$constraintsOr = [];
Expand All @@ -50,14 +51,14 @@ public function findQuestionsWithConstraints(array $categories = [], bool $exclu
}

if (!empty($constraintsOr) && !empty($constraintsAnd)) {
$query->matching($query->logicalAnd([
$query->logicalOr($constraintsOr),
$query->logicalOr($constraintsAnd)
]));
$query->matching($query->logicalAnd(
$query->logicalOr(...$constraintsOr),
$query->logicalOr(...$constraintsAnd)
));
} elseif (!empty($constraintsOr)) {
$query->matching($query->logicalOr($constraintsOr));
$query->matching($query->logicalOr(...$constraintsOr));
} elseif (!empty($constraintsAnd)) {
$query->matching($query->logicalAnd($constraintsAnd));
$query->matching($query->logicalAnd(...$constraintsAnd));
}

return $query->execute();
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/SendMailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SendMailService
*
* @return bool mail was sent?
*/
public static function sendMail(string $receivers, array $sender, string $subject, string $body)
public static function sendMail(string $receivers, array $sender, string $subject, string $body): bool
{
$mail = GeneralUtility::makeInstance(MailMessage::class);

Expand Down
3 changes: 1 addition & 2 deletions Classes/Utility/TypoScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ protected function getValue($data, $path)
* Set value in array by path
*
* @param array $array
* @param array $path
* @param mixed $value
* @param string[] $path
*
* @param mixed $value
* @return array
*/
protected function setValue(array $array, array $path, $value): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ExcludeAlreadyDisplayedQuestionsViewHelper extends AbstractViewHelper
/**
* Initialize arguments
*/
public function initializeArguments()
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('question', Question::class, 'question item', true);
Expand All @@ -49,7 +49,8 @@ public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
): void
{
$question = $arguments['question'];
$uid = $question->getUid();

Expand Down
8 changes: 8 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Jp\Jpfaq\:
resource: '../Classes/*'
Loading

0 comments on commit db3723d

Please sign in to comment.