/** * Returns a subpart from the input content stream. * A subpart is a part of the input stream which is encapsulated in a * string matching the input string, $marker. If this string is found * inside of HTML comment tags the start/end points of the content block * returned will be that right outside that comment block. * Example: The contennt string is * "Hello <!--###sub1### begin--> World. How are <!--###sub1### end--> you?" * If $marker is "###sub1###" then the content returned is * " World. How are ". The input content string could just as well have * been "Hello ###sub1### World. How are ###sub1### you?" and the result * would be the same * Wrapper for \TYPO3\CMS\Core\Utility\MarkerBasedTemplateService::getSubpart 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]### * @return string The subpart found, if found. */ public function getSubpart($content, $marker) { return $this->templateService->getSubpart($content, $marker); }
/** * 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 * @param string $content * @param string $marker * @param string $expected * @dataProvider getSubpartDataProvider */ public function getSubpart($content, $marker, $expected) { $this->assertSame($expected, $this->templateService->getSubpart($content, $marker)); }