diff --git a/typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php b/typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php index 405a8a36347fd616bb3fa4d01e5e50d4a2bd7f0b..73730aff4780090a0cd15164e91e6417ce08734b 100644 --- a/typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php +++ b/typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php @@ -23,11 +23,12 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MailUtility; use TYPO3\CMS\Lang\LanguageService; use TYPO3\CMS\Linkvalidator\LinkAnalyzer; +use TYPO3\CMS\Scheduler\Task\AbstractTask; /** * This class provides Scheduler plugin implementation */ -class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask +class ValidatorTask extends AbstractTask { /** * @var int @@ -119,6 +120,13 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask */ protected $templateService; + /** + * Default language file of the extension linkvalidator + * + * @var string + */ + protected $languageFile = 'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf'; + /** * Get the value of the protected property email * @@ -256,8 +264,7 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask $this->setCliArguments(); $this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); $successfullyExecuted = true; - if ( - !file_exists(($file = GeneralUtility::getFileAbsFileName($this->emailTemplateFile))) + if (!file_exists(($file = GeneralUtility::getFileAbsFileName($this->emailTemplateFile))) && !empty($this->email) ) { if ($this->emailTemplateFile === 'EXT:linkvalidator/res/mailtemplate.html') { @@ -265,8 +272,9 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask $this->emailTemplateFile = 'EXT:linkvalidator/Resources/Private/Templates/mailtemplate.html'; $this->save(); } else { + $lang = $this->getLanguageService(); throw new \InvalidArgumentException( - $this->getLanguageService()->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidEmailTemplateFile'), + $lang->sL($this->languageFile . ':tasks.error.invalidEmailTemplateFile'), '1295476972' ); } @@ -286,7 +294,10 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask if ($this->totalBrokenLink != $this->oldTotalBrokenLink) { $this->isDifferentToLastRun = true; } - if ($this->totalBrokenLink > 0 && (!$this->emailOnBrokenLinkOnly || $this->isDifferentToLastRun) && !empty($this->email)) { + if ($this->totalBrokenLink > 0 + && (!$this->emailOnBrokenLinkOnly || $this->isDifferentToLastRun) + && !empty($this->email) + ) { $successfullyExecuted = $this->reportEmail($pageSections, $modTs); } return $successfullyExecuted; @@ -351,7 +362,9 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask $parseObj = GeneralUtility::makeInstance(TypoScriptParser::class); $parseObj->parse($this->configuration); if (!empty($parseObj->errors)) { - $parseErrorMessage = $this->getLanguageService()->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidTSconfig') . '<br />'; + $languageService = $this->getLanguageService(); + $parseErrorMessage = $languageService->sL($this->languageFile . ':tasks.error.invalidTSconfig') + . '<br />'; foreach ($parseObj->errors as $errorInfo) { $parseErrorMessage .= $errorInfo[0] . '<br />'; } @@ -395,7 +408,9 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask $linkTypes = array(); $typesTmp = GeneralUtility::trimExplode(',', $modTS['linktypes'], true); if (is_array($typesTmp)) { - if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks']) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])) { + if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks']) + && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks']) + ) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] as $type => $value) { if (in_array($type, $typesTmp)) { $linkTypes[$type] = 1; @@ -416,15 +431,17 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask */ protected function reportEmail($pageSections, array $modTsConfig) { + $lang = $this->getLanguageService(); $content = $this->templateService->substituteSubpart($this->templateMail, '###PAGE_SECTION###', $pageSections); /** @var array $markerArray */ - $markerArray = array(); + $markerArray = []; /** @var array $validEmailList */ - $validEmailList = array(); + $validEmailList = []; /** @var bool $sendEmail */ $sendEmail = true; $markerArray['totalBrokenLink'] = $this->totalBrokenLink; $markerArray['totalBrokenLink_old'] = $this->oldTotalBrokenLink; + // Hook if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['reportEmailMarkers'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['reportEmailMarkers'] as $userFunc) { @@ -451,7 +468,10 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask if (GeneralUtility::validEmail($modTsConfig['mail.']['fromemail'])) { $mail->setFrom(array($modTsConfig['mail.']['fromemail'] => $modTsConfig['mail.']['fromname'])); } else { - throw new \Exception($this->getLanguageService()->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidFromEmail'), '1295476760'); + throw new \Exception( + $lang->sL($this->languageFile . ':tasks.error.invalidFromEmail'), + '1295476760' + ); } if (GeneralUtility::validEmail($modTsConfig['mail.']['replytoemail'])) { $mail->setReplyTo(array($modTsConfig['mail.']['replytoemail'] => $modTsConfig['mail.']['replytoname'])); @@ -459,7 +479,10 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask if (!empty($modTsConfig['mail.']['subject'])) { $mail->setSubject($modTsConfig['mail.']['subject']); } else { - throw new \Exception($this->getLanguageService()->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.noSubject'), '1295476808'); + throw new \Exception( + $lang->sL($this->languageFile . ':tasks.error.noSubject'), + '1295476808' + ); } if (!empty($this->email)) { // Check if old input field value is still there and save the value a @@ -473,7 +496,10 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask foreach ($emailList as $emailAdd) { if (!GeneralUtility::validEmail($emailAdd)) { - throw new \Exception($this->getLanguageService()->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidToEmail'), '1295476821'); + throw new \Exception( + $lang->sL($this->languageFile . ':tasks.error.invalidToEmail'), + '1295476821' + ); } else { $validEmailList[] = $emailAdd; } @@ -537,7 +563,13 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask ); $content = ''; if ($markerArray['brokenlinkCount'] > 0) { - $content = $this->templateService->substituteMarkerArray($pageSectionHtml, $markerArray, '###|###', true, true); + $content = $this->templateService->substituteMarkerArray( + $pageSectionHtml, + $markerArray, + '###|###', + true, + true + ); } return $content; } @@ -562,12 +594,12 @@ class ValidatorTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask } } $lang = $this->getLanguageService(); - $additionalInformation[] = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.page') . ': ' . $pageLabel; - $depth = (int)$this->getDepth(); - $additionalInformation[] = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.depth') . ': ' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_' . ($depth === 999 ? 'infi' : $depth)); - - $additionalInformation[] = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.email') . ': ' . $this->getEmail(); + $additionalInformation[] = $lang->sL($this->languageFile . ':tasks.validate.page') . ': ' . $pageLabel; + $additionalInformation[] = $lang->sL($this->languageFile . ':tasks.validate.depth') . ': ' + . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_' . ($depth === 999 ? 'infi' : $depth)); + $additionalInformation[] = $lang->sL($this->languageFile . ':tasks.validate.email') . ': ' + . $this->getEmail(); return implode(', ', $additionalInformation); } diff --git a/typo3/sysext/linkvalidator/Classes/Task/ValidatorTaskAdditionalFieldProvider.php b/typo3/sysext/linkvalidator/Classes/Task/ValidatorTaskAdditionalFieldProvider.php index ae26ed29a54d7e989ab54614eb83530d7c1b0e64..9528188ac021a9140ea3e65a5de84dfe0d6efcdf 100644 --- a/typo3/sysext/linkvalidator/Classes/Task/ValidatorTaskAdditionalFieldProvider.php +++ b/typo3/sysext/linkvalidator/Classes/Task/ValidatorTaskAdditionalFieldProvider.php @@ -27,6 +27,13 @@ use TYPO3\CMS\Scheduler\Task\AbstractTask; */ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface { + /** + * Default language file of the extension linkvalidator + * + * @var string + */ + protected $languageFile = 'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf'; + /** * Render additional information fields within the scheduler backend. * @@ -34,7 +41,7 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt * @param ValidatorTask $task Task object * @param SchedulerModuleController $schedulerModule Reference to the BE module of the Scheduler * @return array Additional fields - * @see \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface->getAdditionalFields($taskInfo, $task, $schedulerModule) + * @see AdditionalFieldProviderInterface->getAdditionalFields($taskInfo, $task, $schedulerModule) */ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule) { @@ -94,9 +101,13 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt } } $fieldId = 'task_page'; - $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[linkvalidator][page]" id="' . $fieldId . '" value="' . htmlspecialchars($taskInfo['page']) . '">'; + $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[linkvalidator][page]" id="' + . $fieldId + . '" value="' + . htmlspecialchars($taskInfo['page']) + . '">'; $lang = $this->getLanguageService(); - $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.page'); + $label = $lang->sL($this->languageFile . ':tasks.validate.page'); $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label); $additionalFields[$fieldId] = array( 'code' => $fieldCode, @@ -114,48 +125,61 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt ); $fieldCode = '<select class="form-control" name="tx_scheduler[linkvalidator][depth]" id="' . $fieldId . '">'; foreach ($fieldValueArray as $depth => $label) { - $fieldCode .= "\t" . '<option value="' . htmlspecialchars($depth) . '"' . - (($depth == $taskInfo['depth']) ? ' selected="selected"' : '') . - '>' . $label . '</option>'; + $fieldCode .= "\t" . '<option value="' . htmlspecialchars($depth) . '"' + . (($depth == $taskInfo['depth']) ? ' selected="selected"' : '') . '>' + . $label + . '</option>'; } $fieldCode .= '</select>'; - $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.depth'); + $label = $lang->sL($this->languageFile . ':tasks.validate.depth'); $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label); $additionalFields[$fieldId] = array( 'code' => $fieldCode, 'label' => $label ); $fieldId = 'task_configuration'; - $fieldCode = '<textarea class="form-control" name="tx_scheduler[linkvalidator][configuration]" id="' . $fieldId . '" >' . - htmlspecialchars($taskInfo['configuration']) . '</textarea>'; - $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.conf'); + $fieldCode = '<textarea class="form-control" name="tx_scheduler[linkvalidator][configuration]" id="' + . $fieldId + . '" >' + . htmlspecialchars($taskInfo['configuration']) + . '</textarea>'; + $label = $lang->sL($this->languageFile . ':tasks.validate.conf'); $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label); $additionalFields[$fieldId] = array( 'code' => $fieldCode, 'label' => $label ); $fieldId = 'task_email'; - $fieldCode = '<textarea class="form-control" rows="5" cols="50" name="tx_scheduler[linkvalidator][email]" id="' . $fieldId . '">' . - htmlspecialchars($taskInfo['email']) . '</textarea>'; - $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.email'); + $fieldCode = '<textarea class="form-control" rows="5" cols="50" name="tx_scheduler[linkvalidator][email]" id="' + . $fieldId + . '">' + . htmlspecialchars($taskInfo['email']) + . '</textarea>'; + $label = $lang->sL($this->languageFile . ':tasks.validate.email'); $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label); $additionalFields[$fieldId] = array( 'code' => $fieldCode, 'label' => $label ); $fieldId = 'task_emailOnBrokenLinkOnly'; - $fieldCode = '<div class="checkbox"><label><input type="checkbox" name="tx_scheduler[linkvalidator][emailOnBrokenLinkOnly]" id="' . $fieldId . '" ' . - (htmlspecialchars($taskInfo['emailOnBrokenLinkOnly']) ? 'checked="checked"' : '') . '></label></div>'; - $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.emailOnBrokenLinkOnly'); + $fieldCode = '<div class="checkbox"><label>' + . '<input type="checkbox" name="tx_scheduler[linkvalidator][emailOnBrokenLinkOnly]" id="' . $fieldId . '" ' + . (htmlspecialchars($taskInfo['emailOnBrokenLinkOnly']) ? 'checked="checked"' : '') + . '></label></div>'; + $label = $lang->sL($this->languageFile . ':tasks.validate.emailOnBrokenLinkOnly'); $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label); $additionalFields[$fieldId] = array( 'code' => $fieldCode, 'label' => $label ); $fieldId = 'task_emailTemplateFile'; - $fieldCode = '<input class="form-control" type="text" name="tx_scheduler[linkvalidator][emailTemplateFile]" id="' . $fieldId . - '" value="' . htmlspecialchars($taskInfo['emailTemplateFile']) . '">'; - $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.emailTemplateFile'); + $fieldCode = '<input class="form-control" type="text" name="tx_scheduler[linkvalidator][emailTemplateFile]" ' + . 'id="' + . $fieldId + . '" value="' + . htmlspecialchars($taskInfo['emailTemplateFile']) + . '">'; + $label = $lang->sL($this->languageFile . ':tasks.validate.emailTemplateFile'); $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label); $additionalFields[$fieldId] = array( 'code' => $fieldCode, @@ -191,14 +215,18 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule) { $isValid = true; - // @todo add validation to validate the $submittedData['configuration'] which is normally a comma separated string + // @todo add validation to validate the $submittedData['configuration'] + // @todo which is normally a comma separated string $lang = $this->getLanguageService(); if (!empty($submittedData['linkvalidator']['email'])) { $emailList = GeneralUtility::trimExplode(',', $submittedData['linkvalidator']['email']); foreach ($emailList as $emailAdd) { if (!GeneralUtility::validEmail($emailAdd)) { $isValid = false; - $schedulerModule->addMessage($lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidEmail'), FlashMessage::ERROR); + $schedulerModule->addMessage( + $lang->sL($this->languageFile . ':tasks.validate.invalidEmail'), + FlashMessage::ERROR + ); } } } @@ -207,14 +235,14 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt if (empty($row)) { $isValid = false; $schedulerModule->addMessage( - $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidPage'), + $lang->sL($this->languageFile . ':tasks.validate.invalidPage'), FlashMessage::ERROR ); } if ($submittedData['linkvalidator']['depth'] < 0) { $isValid = false; $schedulerModule->addMessage( - $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidDepth'), + $lang->sL($this->languageFile . ':tasks.validate.invalidDepth'), FlashMessage::ERROR ); }