Skip to content

Commit

Permalink
Merge pull request #456 from SSFGizmo/develop
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
SSFGizmo authored Dec 13, 2023
2 parents 55b7c99 + 56ec8c3 commit a780d57
Show file tree
Hide file tree
Showing 73 changed files with 1,154 additions and 436 deletions.
6 changes: 6 additions & 0 deletions Classes/DirectMailUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ protected static function addUserPass(string $url, array $params): string
public static function getFullUrlsForDirectMailRecord(array $row): array
{
// Finding the domain to use
if (!$_SERVER['HTTP_HOST']) {
// In CLI / Scheduler context, $_SERVER['HTTP_HOST'] can be null
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$site = $siteFinder->getSiteByPageId((int)$row['page']);
$_SERVER['HTTP_HOST'] = $site->getBase()->getHost();
}
$result = [
'baseUrl' => self::getTypolinkURL((int)$row['page']),
'htmlUrl' => '',
Expand Down
18 changes: 14 additions & 4 deletions Classes/Dmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,17 @@ public function sendAdvanced(array $recipientRow, string $tableNameChar): int
$this->dmailer['sys_dmail_rec']['return_path'] = str_replace('###XID###', $midRidId, $this->dmailer['sys_dmail_rec']['return_path']);

if ($returnCode) {
$recipient = $this->createRecipient($recipientRow['email'], $this->ensureCorrectEncoding($recipientRow['name']));
$recipientName = $recipientRow['name'] ?? '';
if ($recipientName == '') {
if ($recipientRow['first_name'] ?? '') {
$recipientName = $recipientRow['first_name'] . ' ';
}
if ($recipientRow['middle_name'] ?? '') {
$recipientName .= $recipientRow['middle_name'] . ' ';
}
$recipientName .= $recipientRow['last_name'] ?? '';
}
$recipient = $this->createRecipient($recipientRow['email'], $this->ensureCorrectEncoding($recipientName));
$this->sendTheMail($recipient, $recipientRow);
}
}
Expand Down Expand Up @@ -864,7 +874,7 @@ protected function setContent(MailMessage $mailer): void
if ((int)$this->dmailer['sys_dmail_rec']['attachment'] > 0) {
$files = DirectMailUtility::getAttachments((int)$this->dmailer['sys_dmail_rec']['uid']);
foreach ($files as $file) {
$mailer->attachFromPath($file->getForLocalProcessing());
$mailer->attachFromPath($file->getForLocalProcessing(), $file->getName());
}
}
}
Expand All @@ -886,7 +896,7 @@ protected function sendTheMail(Address $recipient, array $recipientRow = null):
}

if (GeneralUtility::validEmail($this->dmailer['sys_dmail_rec']['return_path'])) {
$mailer->sender($this->dmailer['sys_dmail_rec']['return_path']);
$mailer->returnPath($this->dmailer['sys_dmail_rec']['return_path']);
}

// TODO: setContent should set the images (includeMedia) or add attachment
Expand Down Expand Up @@ -989,7 +999,7 @@ protected function substHREFsInHTML(): void
return;
}
foreach ($this->theParts['html']['hrefs'] as $urlId => $val) {
if ($val['no_jumpurl']) {
if ($val['no_jumpurl'] ?? false) {
// A tag attribute "no_jumpurl=1" allows to disable jumpurl for custom links
$substVal = $val['absRef'];
} elseif ($this->jumperURLPrefix && ($val['tag'] != 'form') && (!strstr($val['ref'], 'mailto:'))) {
Expand Down
42 changes: 22 additions & 20 deletions Classes/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ public function displayImport(): array
}

// check if "email" is mapped
$error = [];
if (isset($stepCurrent) && $stepCurrent === 'startImport') {
$map = $this->indata['map'];
$error = [];
// check noMap
$newMap = ArrayUtility::removeArrayEntryByValue(array_unique($map), 'noMap');
if (empty($newMap)) {
Expand All @@ -227,6 +227,9 @@ public function displayImport(): array
}

$out = '';
if(!isset($stepCurrent)) {
$stepCurrent = '';
}
switch ($stepCurrent) {
case 'conf':
$output['conf']['show'] = true;
Expand Down Expand Up @@ -269,7 +272,7 @@ public function displayImport(): array
['val' =>'name', 'text' => 'name'],
];

$output['conf']['disableInput'] = $this->params['inputDisable'] == 1 ? true : false;
$output['conf']['disableInput'] = ($this->params['inputDisable'] ?? 0) == 1 ? true : false;

// show configuration
$output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_header_conf');
Expand All @@ -279,10 +282,10 @@ public function displayImport(): array
$output['conf']['storageSelected'] = $this->indata['storage'] ?? '';

// remove existing option
$output['conf']['remove_existing'] = !$this->indata['remove_existing'] ? false : true;
$output['conf']['remove_existing'] = !($this->indata['remove_existing'] ?? false) ? false : true;

// first line in csv is to be ignored
$output['conf']['first_fieldname'] = !$this->indata['first_fieldname'] ? false : true;
$output['conf']['first_fieldname'] = !($this->indata['first_fieldname'] ?? false) ? false : true;

// csv separator
$output['conf']['delimiter'] = $optDelimiter;
Expand All @@ -293,13 +296,13 @@ public function displayImport(): array
$output['conf']['encapsulationSelected'] = $this->indata['encapsulation'] ?? '';

// import only valid email
$output['conf']['valid_email'] = !$this->indata['valid_email'] ? false : true;
$output['conf']['valid_email'] = !($this->indata['valid_email'] ?? false) ? false : true;

// only import distinct records
$output['conf']['remove_dublette'] = !$this->indata['remove_dublette'] ? false : true;
$output['conf']['remove_dublette'] = !($this->indata['remove_dublette'] ?? false) ? false : true;

// update the record instead renaming the new one
$output['conf']['update_unique'] = !$this->indata['update_unique'] ? false : true;
$output['conf']['update_unique'] = !($this->indata['update_unique'] ?? false) ? false : true;

// which field should be use to show uniqueness of the records
$output['conf']['record_unique'] = $optUnique;
Expand All @@ -320,7 +323,7 @@ public function displayImport(): array
$output['mapping']['remove_dublette'] = $this->indata['remove_dublette'];
$output['mapping']['update_unique'] = $this->indata['update_unique'];
$output['mapping']['record_unique'] = $this->indata['record_unique'];
$output['mapping']['all_html'] = !$this->indata['all_html'] ? false : true;
$output['mapping']['all_html'] = !($this->indata['all_html'] ?? false) ? false : true;
$output['mapping']['error'] = $error;

// show charset selector
Expand Down Expand Up @@ -386,7 +389,7 @@ public function displayImport(): array
$output['mapping']['table'][] = [
'mapping_description' => $csv_firstRow[$i],
'mapping_i' => $i,
'mapping_mappingSelected' => $this->indata['map'][$i],
'mapping_mappingSelected' => $this->indata['map'][$i] ?? '',
'mapping_value' => $exampleLines,
];
}
Expand Down Expand Up @@ -427,8 +430,8 @@ public function displayImport(): array
$output['startImport']['remove_dublette'] = $this->indata['remove_dublette'];
$output['startImport']['update_unique'] = $this->indata['update_unique'];
$output['startImport']['record_unique'] = $this->indata['record_unique'];
$output['startImport']['all_html'] = !$this->indata['all_html'] ? false : true;
$output['startImport']['add_cat'] = $this->indata['add_cat'] ? true : false;
$output['startImport']['all_html'] = !($this->indata['all_html'] ?? false) ? false : true;
$output['startImport']['add_cat'] = ($this->indata['add_cat'] ?? false) ? true : false;

$output['startImport']['error'] = $error;

Expand All @@ -454,7 +457,7 @@ public function displayImport(): array

foreach ($endOrder as $order) {
$rowsTable = [];
if (is_array($result[$order])) {
if (is_array($result[$order] ?? false)) {
foreach ($result[$order] as $v) {
$mapKeys = array_keys($v);
$rowsTable[] = [
Expand All @@ -471,12 +474,12 @@ public function displayImport(): array
}

// back button
if (is_array($this->indata['map'])) {
if (is_array($this->indata['map'] ?? false)) {
foreach ($this->indata['map'] as $fieldNr => $fieldMapped) {
$output['startImport']['hiddenMap'][] = ['name' => htmlspecialchars('CSV_IMPORT[map][' . $fieldNr . ']'), 'value' => htmlspecialchars($fieldMapped)];
}
}
if (is_array($this->indata['cat'])) {
if (is_array($this->indata['cat'] ?? false)) {
foreach ($this->indata['cat'] as $k => $catUid) {
$output['startImport']['hiddenCat'][] = ['name' => htmlspecialchars('CSV_IMPORT[cat][' . $k . ']'), 'value' => htmlspecialchars($catUid)];
}
Expand All @@ -487,8 +490,7 @@ public function displayImport(): array
default:
// show upload file form
$output['subtitle'] = $this->getLanguageService()->getLL('mailgroup_import_header_upload');

if (($this->indata['mode'] === 'file') && !(((strpos($currentFileInfo['file'], 'import') === false) ? 0 : 1) && ($currentFileInfo['realFileext'] === 'txt'))) {
if ((($this->indata['mode'] ?? '') === 'file') && !(((strpos($currentFileInfo['file'], 'import') === false) ? 0 : 1) && ($currentFileInfo['realFileext'] === 'txt'))) {
$output['upload']['current'] = true;
$file = $this->getFileById((int)$this->indata['newFileUid']);
if (is_object($file)) {
Expand All @@ -510,8 +512,8 @@ public function displayImport(): array
$output['upload']['csv'] = htmlspecialchars($this->indata['csv'] ?? '');
$output['upload']['target'] = htmlspecialchars($this->userTempFolder());
$output['upload']['target_disabled'] = GeneralUtility::_POST('importNow') ? 'disabled' : '';
$output['upload']['newFile'] = $this->indata['newFile'];
$output['upload']['newFileUid'] = $this->indata['newFileUid'];
$output['upload']['newFile'] = $this->indata['newFile'] ?? '';
$output['upload']['newFileUid'] = $this->indata['newFileUid'] ?? 0;
}

$output['title'] = $this->getLanguageService()->getLL('mailgroup_import') . BackendUtility::cshItem($this->cshTable ?? '', 'mailgroup_import');
Expand Down Expand Up @@ -726,7 +728,7 @@ public function doImport(array $csvData): array
* Hook for doImport Mail
* will be called every time a record is inserted
*/
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['doImport'])) {
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['doImport'] ?? false)) {
$hookObjectsArr = [];
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['direct_mail/mod3/class.tx_directmail_recipient_list.php']['doImport'] as $classRef) {
$hookObjectsArr[] = GeneralUtility::makeInstance($classRef);
Expand Down Expand Up @@ -756,7 +758,7 @@ public function addDataArray(array &$data, $id, array $dataArray): void
if ($this->indata['all_html']) {
$data['tt_address'][$id]['module_sys_dmail_html'] = $this->indata['all_html'];
}
if (is_array($this->indata['cat']) && !in_array('cats', $this->indata['map'])) {
if (is_array($this->indata['cat'] ?? false) && !in_array('cats', $this->indata['map'])) {
foreach ($this->indata['cat'] as $k => $v) {
$data['tt_address'][$id]['module_sys_dmail_category'][$k] = $v;
}
Expand Down
41 changes: 23 additions & 18 deletions Classes/Middleware/JumpurlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

if ($this->shouldProcess()) {
$mailId = (int)$this->request->getQueryParams()['mid'];
$submittedRecipient = (string)$this->request->getQueryParams()['rid'];
$submittedAuthCode = $this->request->getQueryParams()['aC'];
$jumpurl = $this->request->getQueryParams()['jumpurl'];
$submittedRecipient = isset($this->request->getQueryParams()['rid']) ? (string)$this->request->getQueryParams()['rid'] : '';
$submittedAuthCode = $this->request->getQueryParams()['aC'] ?? '';
$jumpurl = $this->request->getQueryParams()['jumpurl'] ?? '';

$urlId = 0;
if (MathUtility::canBeInterpretedAsInteger($jumpurl)) {
$urlId = $jumpurl;
$this->initDirectMailRecord($mailId);
$this->initRecipientRecord($submittedRecipient);
$rid = $this->recipientRecord['uid'] ?? 0;

$jumpurl = $this->getTargetUrl((int)$jumpurl);

// try to build the ready-to-use target url
Expand Down Expand Up @@ -123,7 +125,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}

// to count the dmailerping correctly, we need something unique
$recipientUid = $submittedAuthCode;
$submittedAuthCode = preg_replace("/[^a-zA-Z0-9]/", "", $submittedAuthCode);
}

if ($this->responseType !== 0) {
Expand All @@ -134,7 +136,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
'response_type' => $this->responseType,
'url_id' => (int)$urlId,
'rtbl' => mb_substr($this->recipientTable, 0, 1),
'rid' => (int)($recipientUid ?? $this->recipientRecord['uid']),
'rid' => $rid ?? $submittedAuthCode,
];
$sysDmailMaillogRepository = GeneralUtility::makeInstance(SysDmailMaillogRepository::class);
if ($sysDmailMaillogRepository->hasRecentLog($mailLogParams) === false) {
Expand Down Expand Up @@ -177,25 +179,28 @@ protected function initDirectMailRecord(int $mailId): void
* Fetches the target url from the direct mail record
*
* @param int $targetIndex
* @return string|null
* @return string
*/
protected function getTargetUrl(int $targetIndex): ?string
protected function getTargetUrl(int $targetIndex): string
{
$targetUrl = null;
$targetUrl = '';

if (!empty($this->directMailRecord)) {
$mailContent = unserialize(
base64_decode($this->directMailRecord['mailContent']),
base64_decode((string)$this->directMailRecord['mailContent']),
['allowed_classes' => false]
);
if ($targetIndex >= 0) {
// Link (number)
$this->responseType = self::RESPONSE_TYPE_HREF;
$targetUrl = $mailContent['html']['hrefs'][$targetIndex]['absRef'];
} else {
// Link (number, plaintext)
$this->responseType = self::RESPONSE_TYPE_PLAIN;
$targetUrl = $mailContent['plain']['link_ids'][abs($targetIndex)];

if(is_array($mailContent)) {
if ($targetIndex >= 0) {
// Link (number)
$this->responseType = self::RESPONSE_TYPE_HREF;
$targetUrl = $mailContent['html']['hrefs'][$targetIndex]['absRef'];
} else {
// Link (number, plaintext)
$this->responseType = self::RESPONSE_TYPE_PLAIN;
$targetUrl = $mailContent['plain']['link_ids'][abs($targetIndex)];
}
}
$targetUrl = htmlspecialchars_decode(urldecode($targetUrl));
}
Expand Down Expand Up @@ -261,7 +266,7 @@ protected function substituteUserMarkersFromTargetUrl(string $targetUrl): string
if (isset($this->recipientRecord[$substField])) {
$processedTargetUrl = str_replace(
'###USER_' . $substField . '###',
$this->recipientRecord[$substField],
(string) $this->recipientRecord[$substField],
$processedTargetUrl
);
}
Expand Down
11 changes: 5 additions & 6 deletions Classes/Module/DmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1258,9 +1258,8 @@ protected function sendMail($row)
protected function sendTestMailToTable(array $idLists, string $table, Dmailer $htmlmail): int
{
$sentFlag = 0;
if (is_array($idLists[$table])) {
$rows = ($table != 'PLAINLIST') ? GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists[$table], $table, '*') : $idLists['PLAINLIST'];

if (isset($idLists[$table]) && is_array($idLists[$table])) {
$rows = ($table != 'PLAINLIST') ? GeneralUtility::makeInstance(TempRepository::class)->fetchRecordsListValues($idLists[$table], $table, ['*']) : $idLists['PLAINLIST'];
foreach ($rows as $row) {
$recipRow = $htmlmail->convertFields($row);
$recipRow['sys_dmail_categories_list'] = $htmlmail->getListOfRecipentCategories($table, $recipRow['uid']);
Expand Down Expand Up @@ -1573,11 +1572,11 @@ protected function getSingleMailGroup($groupUid)
break;
case 1:
// List of mails
$mailGroupList = (string)$mailGroup['list'];
if ($mailGroup['csv'] == 1) {
$dmCsvUtility = GeneralUtility::makeInstance(DmCsvUtility::class);
$recipients = $dmCsvUtility->rearrangeCsvValues($dmCsvUtility->getCsvValues($mailGroup['list']), $this->fieldList);
$recipients = $dmCsvUtility->rearrangeCsvValues($dmCsvUtility->getCsvValues($mailGroupList), $this->getFieldList());
} else {
$mailGroupList = $mailGroup['list'];
$recipients = $mailGroupList ? $this->rearrangePlainMails(array_unique(preg_split('|[[:space:],;]+|', $mailGroupList))) : [];
}
$idLists['PLAINLIST'] = $this->cleanPlainList($recipients);
Expand Down Expand Up @@ -1636,7 +1635,7 @@ protected function getSingleMailGroup($groupUid)
public function updateSpecialQuery(array $mailGroup)
{
$set = GeneralUtility::_GP('SET');
$queryTable = $set['queryTable'];
$queryTable = $set['queryTable'] ?? '';
$queryLimit = $set['queryLimit'] ?? $mailGroup['queryLimit'] ?? 100;
$queryLimitDisabled = ($set['queryLimitDisabled'] ?? $mailGroup['queryLimitDisabled']) == '' ? 0 : 1;
$queryConfig = GeneralUtility::_GP('queryConfig');
Expand Down
Loading

0 comments on commit a780d57

Please sign in to comment.