/** * Traverses the input $markContentArray array and for each key the marker * by the same name (possibly wrapped and in upper case) will be * substituted with the keys value in the array. * * This is very useful if you have a data-record to substitute in some * content. In particular when you use the $wrap and $uppercase values to * pre-process the markers. Eg. a key name like "myfield" could effectively * be represented by the marker "###MYFIELD###" if the wrap value * was "###|###" and the $uppercase boolean TRUE. * * @param string $content The content stream, typically HTML template content. * @param array $markContentArray The array of key/value pairs being marker/content values used in the substitution. For each element in this array the function will substitute a marker in the content stream with the content. * @param string $wrap A wrap value - [part 1] | [part 2] - for the markers before substitution * @param bool $uppercase If set, all marker string substitution is done with upper-case markers. * @param bool $deleteUnused If set, all unused marker are deleted. * @return string The processed output stream * @see substituteMarker(), substituteMarkerInObject(), TEMPLATE() */ public function substituteMarkerArray($content, array $markContentArray, $wrap = '', $uppercase = false, $deleteUnused = false) { return $this->templateService->substituteMarkerArray($content, $markContentArray, $wrap, $uppercase, $deleteUnused); }
/** * Build the mail content * * @param int $curPage Id of the current page * @param string $pageList List of pages id * @param array $markerArray Array of markers * @param array $oldBrokenLink Marker array with the number of link found * @return string Content of the mail */ protected function buildMail($curPage, $pageList, array $markerArray, array $oldBrokenLink) { $pageSectionHtml = $this->templateService->getSubpart($this->templateMail, '###PAGE_SECTION###'); // Hook if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['buildMailMarkers'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['buildMailMarkers'] as $userFunc) { $params = array('curPage' => $curPage, 'pageList' => $pageList, 'markerArray' => $markerArray, 'oldBrokenLink' => $oldBrokenLink, 'pObj' => &$this); $newMarkers = GeneralUtility::callUserFunction($userFunc, $params, $this); if (is_array($newMarkers)) { $markerArray = $newMarkers + $markerArray; } unset($params); } } if (is_array($markerArray)) { foreach ($markerArray as $markerKey => $markerValue) { if (empty($oldBrokenLink[$markerKey])) { $oldBrokenLink[$markerKey] = 0; } if ($markerValue != $oldBrokenLink[$markerKey]) { $this->isDifferentToLastRun = true; } $markerArray[$markerKey . '_old'] = $oldBrokenLink[$markerKey]; } } $markerArray['title'] = BackendUtility::getRecordTitle('pages', BackendUtility::getRecord('pages', $curPage)); $content = ''; if ($markerArray['brokenlinkCount'] > 0) { $content = $this->templateService->substituteMarkerArray($pageSectionHtml, $markerArray, '###|###', true, true); } return $content; }
/** * 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 . '"> ' . 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); }
/** * 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 * @dataProvider substituteMarkerArrayDataProvider * @param string $content The content stream, typically HTML template content. * @param array $markContentArray The array of key/value pairs being marker/content values used in the substitution. For each element in this array the function will substitute a marker in the content stream with the content. * @param string $wrap A wrap value - [part 1] | [part 2] - for the markers before substitution * @param bool $uppercase If set, all marker string substitution is done with upper-case markers. * @param bool $deleteUnused If set, all unused marker are deleted. * @param string $expected */ public function substituteMarkerArray($content, $markContentArray, $wrap, $uppercase, $deleteUnused, $expected) { $this->assertSame($expected, $this->templateService->substituteMarkerArray($content, $markContentArray, $wrap, $uppercase, $deleteUnused)); }