Пример #1
0
 /**
  * Substitute subpart in input template stream.
  * This function substitutes a subpart in $content with the content of
  * $subpartContent.
  * Wrapper for \TYPO3\CMS\Core\Utility\MarkerBasedTemplateService::substituteSubpart which behaves identical
  *
  * @param string $content The content stream, typically HTML template content.
  * @param string $marker The marker string, typically on the form "###[the marker string]###
  * @param mixed $subpartContent The content to insert instead of the subpart found. If a string, then just plain substitution happens (includes removing the HTML comments of the subpart if found). If $subpartContent happens to be an array, it's [0] and [1] elements are wrapped around the EXISTING content of the subpart (fetched by getSubpart()) thereby not removing the original content.
  * @param bool|int $recursive If $recursive is set, the function calls itself with the content set to the remaining part of the content after the second marker. This means that proceding subparts are ALSO substituted!
  * @return string The processed HTML content string.
  */
 public function substituteSubpart($content, $marker, $subpartContent, $recursive = 1)
 {
     return $this->templateService->substituteSubpart($content, $marker, $subpartContent, $recursive);
 }
Пример #2
0
 /**
  * Build and send warning email when new broken links were found
  *
  * @param string $pageSections Content of page section
  * @param array $modTsConfig TSconfig array
  * @return bool TRUE if mail was sent, FALSE if or not
  * @throws \Exception if required modTsConfig settings are missing
  */
 protected function reportEmail($pageSections, array $modTsConfig)
 {
     $content = $this->templateService->substituteSubpart($this->templateMail, '###PAGE_SECTION###', $pageSections);
     /** @var array $markerArray */
     $markerArray = array();
     /** @var array $validEmailList */
     $validEmailList = array();
     /** @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) {
             $params = array('pObj' => &$this, 'markerArray' => $markerArray);
             $newMarkers = GeneralUtility::callUserFunction($userFunc, $params, $this);
             if (is_array($newMarkers)) {
                 $markerArray = $newMarkers + $markerArray;
             }
             unset($params);
         }
     }
     $content = $this->templateService->substituteMarkerArray($content, $markerArray, '###|###', true, true);
     /** @var $mail MailMessage */
     $mail = GeneralUtility::makeInstance(MailMessage::class);
     if (empty($modTsConfig['mail.']['fromemail'])) {
         $modTsConfig['mail.']['fromemail'] = MailUtility::getSystemFromAddress();
     }
     if (empty($modTsConfig['mail.']['fromname'])) {
         $modTsConfig['mail.']['fromname'] = MailUtility::getSystemFromName();
     }
     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');
     }
     if (GeneralUtility::validEmail($modTsConfig['mail.']['replytoemail'])) {
         $mail->setReplyTo(array($modTsConfig['mail.']['replytoemail'] => $modTsConfig['mail.']['replytoname']));
     }
     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');
     }
     if (!empty($this->email)) {
         // Check if old input field value is still there and save the value a
         if (strpos($this->email, ',') !== false) {
             $emailList = GeneralUtility::trimExplode(',', $this->email, true);
             $this->email = implode(LF, $emailList);
             $this->save();
         } else {
             $emailList = GeneralUtility::trimExplode(LF, $this->email, true);
         }
         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');
             } else {
                 $validEmailList[] = $emailAdd;
             }
         }
     }
     if (is_array($validEmailList) && !empty($validEmailList)) {
         $mail->setTo($validEmailList);
     } else {
         $sendEmail = false;
     }
     if ($sendEmail) {
         $mail->setBody($content, 'text/html');
         $mail->send();
     }
     return $sendEmail;
 }
 /**
  * Builds the checkboxes out of the hooks array
  *
  * @param array $brokenLinkOverView Array of broken links information
  * @param string $prefix
  * @return string code content
  */
 protected function getCheckOptions(array $brokenLinkOverView, $prefix = '')
 {
     $markerArray = array();
     if (!empty($prefix)) {
         $additionalAttr = ' class="' . $prefix . '"';
     } else {
         $additionalAttr = ' class="refresh"';
     }
     $checkOptionsTemplate = $this->templateService->getSubpart($this->doc->moduleTemplate, '###CHECKOPTIONS_SECTION###');
     $hookSectionTemplate = $this->templateService->getSubpart($checkOptionsTemplate, '###HOOK_SECTION###');
     $markerArray['statistics_header'] = $this->doc->sectionHeader($this->getLanguageService()->getLL('report.statistics.header'));
     $markerArray['total_count_label'] = BackendUtility::wrapInHelp('linkvalidator', 'checkboxes', $this->getLanguageService()->getLL('overviews.nbtotal'));
     $markerArray['total_count'] = $brokenLinkOverView['brokenlinkCount'] ?: '0';
     $linktypes = GeneralUtility::trimExplode(',', $this->modTS['linktypes'], true);
     $hookSectionContent = '';
     if (is_array($linktypes)) {
         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, $linktypes)) {
                     $hookSectionMarker = array('count' => $brokenLinkOverView[$type] ?: '0');
                     $translation = $this->getLanguageService()->getLL('hooks.' . $type) ?: $type;
                     $hookSectionMarker['option'] = '<input type="checkbox"' . $additionalAttr . ' id="' . $prefix . 'SET_' . $type . '" name="' . $prefix . 'SET[' . $type . ']" value="1"' . ($this->pObj->MOD_SETTINGS[$type] ? ' checked="checked"' : '') . '/>' . '<label for="' . $prefix . 'SET_' . $type . '">&nbsp;' . htmlspecialchars($translation) . '</label>';
                     $hookSectionContent .= $this->templateService->substituteMarkerArray($hookSectionTemplate, $hookSectionMarker, '###|###', true, true);
                 }
             }
         }
     }
     $checkOptionsTemplate = $this->templateService->substituteSubpart($checkOptionsTemplate, '###HOOK_SECTION###', $hookSectionContent);
     return $this->templateService->substituteMarkerArray($checkOptionsTemplate, $markerArray, '###|###', true, true);
 }
Пример #4
0
 /**
  * Fill the button lists with the defined HTML
  *
  * @param array $buttons HTML for all buttons
  * @return array Containing HTML for both buttonlists
  */
 protected function getDocHeaderButtons($buttons)
 {
     $markers = array();
     // Fill buttons for left and right float
     $floats = array('left', 'right');
     foreach ($floats as $key) {
         // Get the template for each float
         $buttonTemplate = $this->templateService->getSubpart($this->moduleTemplate, '###BUTTON_GROUPS_' . strtoupper($key) . '###');
         // Fill the button markers in this float
         $buttonTemplate = $this->templateService->substituteMarkerArray($buttonTemplate, $buttons, '###|###', true);
         // getting the wrap for each group
         $buttonWrap = $this->templateService->getSubpart($this->moduleTemplate, '###BUTTON_GROUP_WRAP###');
         // looping through the groups (max 6) and remove the empty groups
         for ($groupNumber = 1; $groupNumber < 6; $groupNumber++) {
             $buttonMarker = '###BUTTON_GROUP' . $groupNumber . '###';
             $buttonGroup = $this->templateService->getSubpart($buttonTemplate, $buttonMarker);
             if (trim($buttonGroup)) {
                 if ($buttonWrap) {
                     $buttonGroup = $this->templateService->substituteMarker($buttonWrap, '###BUTTONS###', $buttonGroup);
                 }
                 $buttonTemplate = $this->templateService->substituteSubpart($buttonTemplate, $buttonMarker, trim($buttonGroup));
             }
         }
         // Replace the marker with the template and remove all line breaks (for IE compat)
         $markers['BUTTONLIST_' . strtoupper($key)] = str_replace(LF, '', $buttonTemplate);
     }
     // Hook for manipulating docHeaderButtons
     if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'])) {
         $params = array('buttons' => $buttons, 'markers' => &$markers, 'pObj' => &$this);
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'] as $funcRef) {
             GeneralUtility::callUserFunction($funcRef, $params, $this);
         }
     }
     return $markers;
 }
 /**
  * @test
  * @param string $content
  * @param string $marker
  * @param array $subpartContent
  * @param bool $recursive
  * @param bool $keepMarker
  * @param string $expected
  * @dataProvider substituteSubpartDataProvider
  */
 public function substituteSubpart($content, $marker, $subpartContent, $recursive, $keepMarker, $expected)
 {
     $this->assertSame($expected, $this->templateService->substituteSubpart($content, $marker, $subpartContent, $recursive, $keepMarker));
 }