Skip to content

Commit

Permalink
[FEATURE] TYPO3 v12 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Zillion01 committed Apr 24, 2024
1 parent 3487951 commit 11e5b93
Show file tree
Hide file tree
Showing 26 changed files with 294 additions and 248 deletions.
122 changes: 71 additions & 51 deletions Classes/Controller/SubscriptionlistController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/***
Expand All @@ -27,41 +28,33 @@
/**
* SubscribtionlistController
*/
class SubscriptionlistController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController implements LoggerAwareInterface
class SubscriptionlistController extends ActionController implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* subscriptionlistRepository
*
* @var SubscriptionlistRepository
*/
protected $subscriptionlistRepository = null;
protected SubscriptionlistRepository $subscriptionlistRepository;

/**
* @param SubscriptionlistRepository $subscriptionlistRepository
*/
public function injectSubscriptionlistRepository(SubscriptionlistRepository $subscriptionlistRepository)
public function __construct(
SubscriptionlistRepository $subscriptionlistRepository,
RequestFactory $requestFactory
)
{
$this->subscriptionlistRepository = $subscriptionlistRepository;
$this->requestFactory = $requestFactory;
}

/** @var RequestFactory */
protected $requestFactory = null;

/**
* @param RequestFactory $requestFactory
*/
public function injectRequestFactory(RequestFactory $requestFactory)
{
$this->requestFactory = $requestFactory;
}

/**
* action subscribe
*
* @param array|null $messages
* @return void
* @return ResponseInterface
*/
public function subscribeAction(array $messages = null): ResponseInterface
{
Expand All @@ -87,7 +80,7 @@ public function subscribeAction(array $messages = null): ResponseInterface
* action unsubscribe
*
* @param array|null $messages
* @return void
* @return ResponseInterface
*/
public function unsubscribeAction(array $messages = null): ResponseInterface
{
Expand All @@ -114,8 +107,7 @@ public function unsubscribeAction(array $messages = null): ResponseInterface
*
* Communicate with Laposta API
*
* @return void
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @return ResponseInterface
*/
public function restAction(): ResponseInterface
{
Expand Down Expand Up @@ -147,7 +139,7 @@ public function restAction(): ResponseInterface
$customFields = [];

foreach ($argumentKeys as $argumentKey) {
if (strpos($argumentKey, $customFieldLabel) !== false) {
if (str_contains($argumentKey, $customFieldLabel)) {
$customFieldKeys[] = str_replace($customFieldLabel, '', $argumentKey);
}
}
Expand Down Expand Up @@ -198,19 +190,27 @@ public function restAction(): ResponseInterface
if ($response->getStatusCode() === 201) {
if ($list->getDoubleOptIn()) {
// Double opt-in, user needs to verify his registration with email
$registrationMessage = LocalizationUtility::translate('tx_laposta.message.doubleOptinSubscribed',
'laposta') . ' ' . $list->getListLabel();
$verificationMessage = LocalizationUtility::translate('tx_laposta.message.emailVerification',
'laposta');
$registrationMessage = LocalizationUtility::translate(
'tx_laposta.message.doubleOptinSubscribed',
'laposta'
) . ' ' . $list->getListLabel();
$verificationMessage = LocalizationUtility::translate(
'tx_laposta.message.emailVerification',
'laposta'
);
$messages[] = $registrationMessage . '.<br/>' . $verificationMessage;
if ($enableLog) {
$this->logger->log(LogLevel::INFO,
$email . ' -> ' . $registrationMessage . ' ' . $verificationMessage);
$this->logger->log(
LogLevel::INFO,
$email . ' -> ' . $registrationMessage . ' ' . $verificationMessage
);
}
} else {
// No double opt-in, user is subscribed
$subscribeMessage = LocalizationUtility::translate('tx_laposta.message.subscribed',
'laposta') . ' ' . $list->getListLabel();
$subscribeMessage = LocalizationUtility::translate(
'tx_laposta.message.subscribed',
'laposta'
) . ' ' . $list->getListLabel();
$messages[] = $subscribeMessage;
if ($enableLog) {
$this->logger->log(LogLevel::INFO, $email . ' -> ' . $subscribeMessage);
Expand All @@ -231,8 +231,10 @@ public function restAction(): ResponseInterface

// OK, user deleted from list (code 200)
if ($response->getStatusCode() === 200) {
$deletedMessage = LocalizationUtility::translate('tx_laposta.message.unsubscribed',
'laposta') . ' ' . $list->getListLabel();
$deletedMessage = LocalizationUtility::translate(
'tx_laposta.message.unsubscribed',
'laposta'
) . ' ' . $list->getListLabel();
$messages[] = $deletedMessage;
if ($enableLog) {
$this->logger->log(LogLevel::INFO, $email . ' -> ' . $deletedMessage);
Expand All @@ -246,44 +248,60 @@ public function restAction(): ResponseInterface

if ($crudAction === 'create') {
// E-mail already registered (code 204)
if (strpos($response, '"code": 204') !== false) {
$emailAlreadyRegisteredMessage = LocalizationUtility::translate('tx_laposta.warning.emailregistered',
'laposta') . ' ' . htmlspecialchars($list->getListLabel());
if (str_contains($response, '"code": 204')) {
$emailAlreadyRegisteredMessage = LocalizationUtility::translate(
'tx_laposta.warning.emailregistered',
'laposta'
) . ' ' . htmlspecialchars($list->getListLabel());
$messages[] = $emailAlreadyRegisteredMessage;
if ($enableLog) {
$this->logger->log(LogLevel::INFO,
$email . ' -> ' . $emailAlreadyRegisteredMessage);
$this->logger->log(
LogLevel::INFO,
$email . ' -> ' . $emailAlreadyRegisteredMessage
);
}
} else {
// Some error while trying to POST to Laposta
$netWorkError = LocalizationUtility::translate('tx_laposta.warning.network',
'laposta');
$netWorkError = LocalizationUtility::translate(
'tx_laposta.warning.network',
'laposta'
);
$messages[] = $netWorkError;
if ($enableLog) {
$this->logger->log(LogLevel::WARNING,
'Action: subscribe / create. ' . $netWorkError . '. ' . $response . ' User ip: ' . $ip . ', user email: ' . $email . ', source url: ' . $sourceUrl);
$this->logger->log(
LogLevel::WARNING,
'Action: subscribe / create. ' . $netWorkError . '. ' . $response . ' User ip: ' . $ip . ', user email: ' . $email . ', source url: ' . $sourceUrl
);
}
}
}

if ($crudAction === 'delete') {
// Member does not exist
if (strpos($response, '"code": 202') !== false) {
$unknownMemberMessage = LocalizationUtility::translate('tx_laposta.warning.invalidMember1',
'laposta') . ' ' . htmlspecialchars($list->getListLabel()) . ' ' . LocalizationUtility::translate('tx_laposta.warning.invalidMember2',
'laposta') . ' ' . $email;
if (str_contains($response, '"code": 202')) {
$unknownMemberMessage = LocalizationUtility::translate(
'tx_laposta.warning.invalidMember1',
'laposta'
) . ' ' . htmlspecialchars($list->getListLabel()) . ' ' . LocalizationUtility::translate(
'tx_laposta.warning.invalidMember2',
'laposta'
) . ' ' . $email;
$messages[] = $unknownMemberMessage;
if ($enableLog) {
$this->logger->log(LogLevel::INFO, $unknownMemberMessage);
}
} else {
// Some error while trying to POST to Laposta
$netWorkError = LocalizationUtility::translate('tx_laposta.warning.network',
'laposta');
$netWorkError = LocalizationUtility::translate(
'tx_laposta.warning.network',
'laposta'
);
$messages[] = $netWorkError;
if ($enableLog) {
$this->logger->log(LogLevel::WARNING,
'Action: unsubscribe / delete. ' . $netWorkError . '. ' . $response . 'User ip: ' . $ip . ', user email: ' . $email . ', source url: ' . $sourceUrl);
$this->logger->log(
LogLevel::WARNING,
'Action: unsubscribe / delete. ' . $netWorkError . '. ' . $response . 'User ip: ' . $ip . ', user email: ' . $email . ', source url: ' . $sourceUrl
);
}
}
}
Expand All @@ -299,17 +317,19 @@ public function restAction(): ResponseInterface
}
} else {
if ($enableLog && ((int)($this->settings['logHoneyTrap']) === 1)) {
$this->logger->log(LogLevel::INFO,
'Spam attempt? Honey pot field filled with: ' . htmlspecialchars($arguments['laposta.important']) . '. User ip: ' . $ip . ', source url: ' . $sourceUrl);
$this->logger->log(
LogLevel::INFO,
'Spam attempt? Honey pot field filled with: ' . htmlspecialchars($arguments['laposta.important']) . '. User ip: ' . $ip . ', source url: ' . $sourceUrl
);
}
}

if ($crudAction === 'create') {
$this->redirect('subscribe', 'Subscriptionlist', 'laposta', ['messages' => $messages]);
return $this->redirect('subscribe', 'Subscriptionlist', 'laposta', ['messages' => $messages]);
}

if ($crudAction === 'delete') {
$this->redirect('unsubscribe', 'Subscriptionlist', 'laposta', ['messages' => $messages]);
return $this->redirect('unsubscribe', 'Subscriptionlist', 'laposta', ['messages' => $messages]);
}
}
}
45 changes: 24 additions & 21 deletions Classes/Domain/Model/Subscriptionlist.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,82 @@
<?php

namespace Proudnerds\Laposta\Domain\Model;

use TYPO3\CMS\Extbase\Annotation\Validate;

/**
* Subscriptionlist
*/
class Subscriptionlist extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* The label of the list to subscribe to
*
*
* @var string
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
*/
#[Validate(['validator' => 'NotEmpty'])]
protected $listLabel = '';

/**
* The Laposta id of the list to subscribe to
*
*
* @var string
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
*/
#[Validate(['validator' => 'NotEmpty'])]
protected $listId = '';

/**
* Is there double opt-in for this list
*
* @var bool
*/
protected $doubleOptIn = '';
protected bool $doubleOptIn = false;

/**
* Additional information on this list
*
*
* @var string
*/
protected $info = '';
protected string $info = '';

/**
* Returns the listLabel
*
*
* @return string $listLabel
*/
public function getListLabel()
public function getListLabel(): string
{
return $this->listLabel;
}

/**
* Sets the listLabel
*
*
* @param string $listLabel
* @return void
*/
public function setListLabel($listLabel)
public function setListLabel(string $listLabel): void
{
$this->listLabel = $listLabel;
}

/**
* Returns the listId
*
*
* @return string $listId
*/
public function getListId()
public function getListId(): string
{
return $this->listId;
}

/**
* Sets the listId
*
*
* @param string $listId
* @return void
*/
public function setListId($listId)
public function setListId(string $listId): void
{
$this->listId = $listId;
}
Expand All @@ -83,7 +86,7 @@ public function setListId($listId)
*
* @return bool
*/
public function getDoubleOptIn()
public function getDoubleOptIn(): bool
{
return $this->doubleOptIn;
}
Expand All @@ -94,28 +97,28 @@ public function getDoubleOptIn()
* @param bool $doubleOptIn
* @return void
*/
public function setDoubleOptIn($doubleOptIn)
public function setDoubleOptIn(bool $doubleOptIn): void
{
$this->doubleOptIn = $doubleOptIn;
}

/**
* Returns the info
*
*
* @return string $info
*/
public function getInfo()
public function getInfo(): string
{
return $this->info;
}

/**
* Sets the info
*
*
* @param string $info
* @return void
*/
public function setInfo($info)
public function setInfo(string $info): void
{
$this->info = $info;
}
Expand Down
2 changes: 2 additions & 0 deletions Classes/Domain/Repository/SubscriptionlistRepository.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Proudnerds\Laposta\Domain\Repository;

/***
Expand All @@ -11,6 +12,7 @@
* (c) 2020 Jacco van der Post <[email protected]>
*
***/

/**
* The repository for Subscriptionlist
*/
Expand Down
Loading

0 comments on commit 11e5b93

Please sign in to comment.