/** * @param string $content * @param array $conf * @return string */ public function getTemplateFromName($content, $conf) { $basename = $content; if ($conf['paths'][0] === '<') { $key = trim(substr($conf['paths'], 1)); $typoScriptParser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser'); list($name, $conf['paths.']) = $typoScriptParser->getVal($key, $GLOBALS['TSFE']->tmpl->setup); } $paths = ArrayUtility::sortArrayWithIntegerKeys($conf['paths.']); $paths = array_reverse($paths, TRUE); foreach ($paths as $path) { // why does it have to be relative? $test_file = PathUtility::getRelativePathTo(GeneralUtility::getFileAbsFileName($path)) . $basename; if (is_file($test_file)) { return $test_file; } if (is_file($test_file . '.html')) { return $test_file . '.html'; } } return $content; }
/** * Handles the path resolving for *rootPath(s) * singular one is deprecated and will be removed two versions after 6.2 * if deprecated setting is found, use it as the very last fallback target * * numerical arrays get ordered by key ascending * * @param array $extbaseFrameworkConfiguration * @param string $setting parameter name from TypoScript * @param string $deprecatedSetting parameter name from TypoScript * * @return array */ protected function getViewProperty($extbaseFrameworkConfiguration, $setting, $deprecatedSetting = '') { $values = array(); if (!empty($extbaseFrameworkConfiguration['view'][$setting]) && is_array($extbaseFrameworkConfiguration['view'][$setting])) { $values = \TYPO3\CMS\Extbase\Utility\ArrayUtility::sortArrayWithIntegerKeys($extbaseFrameworkConfiguration['view'][$setting]); $values = array_reverse($values, TRUE); } // @todo remove handling of deprecatedSetting two versions after 6.2 if (isset($extbaseFrameworkConfiguration['view'][$deprecatedSetting]) && strlen($extbaseFrameworkConfiguration['view'][$deprecatedSetting]) > 0) { $values[] = $extbaseFrameworkConfiguration['view'][$deprecatedSetting]; } return $values; }
/** * Builds a list of possible candidates for a given template name * * @param string $templateName Name of the template to search for * @param array $paths Paths to search in * @param string $format The file format to use. e.g 'html' or 'txt' * @return array Array of paths to search for the template file */ protected function buildListOfTemplateCandidates($templateName, array $paths, $format) { $upperCasedTemplateName = $this->ucFileNameInPath($templateName); $possibleTemplatePaths = array(); $paths = ArrayUtility::sortArrayWithIntegerKeys($paths); $paths = array_reverse($paths, TRUE); foreach ($paths as $layoutRootPath) { $possibleTemplatePaths[] = $this->resolveFileNamePath($layoutRootPath . '/' . $upperCasedTemplateName . '.' . $format); $possibleTemplatePaths[] = $this->resolveFileNamePath($layoutRootPath . '/' . $upperCasedTemplateName); if ($upperCasedTemplateName !== $templateName) { $possibleTemplatePaths[] = $this->resolveFileNamePath($layoutRootPath . '/' . $templateName . '.' . $format); $possibleTemplatePaths[] = $this->resolveFileNamePath($layoutRootPath . '/' . $templateName); } } return $possibleTemplatePaths; }
/** * Resolve the partial path and filename based on $this->getPartialRootPaths() and request format * * @param string $partialName The name of the partial * @return string The full path which should be used. The path definitely exists. * @throws InvalidTemplateResourceException */ protected function getPartialPathAndFilename($partialName) { $upperCasedPartialName = ucfirst($partialName); $paths = ArrayUtility::sortArrayWithIntegerKeys($this->getPartialRootPaths()); $paths = array_reverse($paths, TRUE); $possiblePartialPaths = array(); foreach ($paths as $partialRootPath) { $possiblePartialPaths[] = GeneralUtility::fixWindowsFilePath($partialRootPath . '/' . $upperCasedPartialName . '.' . $this->getRequest()->getFormat()); $possiblePartialPaths[] = GeneralUtility::fixWindowsFilePath($partialRootPath . '/' . $upperCasedPartialName); if ($upperCasedPartialName !== $partialName) { $possiblePartialPaths[] = GeneralUtility::fixWindowsFilePath($partialRootPath . '/' . $partialName . '.' . $this->getRequest()->getFormat()); $possiblePartialPaths[] = GeneralUtility::fixWindowsFilePath($partialRootPath . '/' . $partialName); } } foreach ($possiblePartialPaths as $partialPathAndFilename) { if ($this->testFileExistence($partialPathAndFilename)) { return $partialPathAndFilename; } } throw new InvalidTemplateResourceException('Could not load partial file. Tried following paths: "' . implode('", "', $possiblePartialPaths) . '".', 1288092556); }
/** * @param array $extbaseFrameworkConfiguration * @return array */ protected static function grabRootPathsFromExtConf(array $extbaseFrameworkConfiguration) { $rootPaths = array(); if (!empty($extbaseFrameworkConfiguration['view']['templateRootPaths']) && is_array($extbaseFrameworkConfiguration['view']['templateRootPaths'])) { $rootPaths = \TYPO3\CMS\Extbase\Utility\ArrayUtility::sortArrayWithIntegerKeys($extbaseFrameworkConfiguration['view']['templateRootPaths']); $rootPaths = array_reverse($rootPaths, TRUE); } // @todo remove handling of deprecatedSetting two versions after 6.2 if (isset($extbaseFrameworkConfiguration['view']['templateRootPath']) && strlen($extbaseFrameworkConfiguration['view']['templateRootPath']) > 0) { $rootPaths[] = $extbaseFrameworkConfiguration['view']['templateRootPath']; } return $rootPaths; }
/** * Handles the path resolving for *rootPath(s) * * numerical arrays get ordered by key ascending * * @param array $extbaseFrameworkConfiguration * @param string $setting parameter name from TypoScript * * @return array */ protected function getViewProperty($extbaseFrameworkConfiguration, $setting) { $values = array(); if (!empty($extbaseFrameworkConfiguration['view'][$setting]) && is_array($extbaseFrameworkConfiguration['view'][$setting])) { $values = ArrayUtility::sortArrayWithIntegerKeys($extbaseFrameworkConfiguration['view'][$setting]); $values = array_reverse($values, true); } return $values; }
/** * @test * * @param array $arrayToSort * @param array $expectedArray * * @dataProvider sortArrayWithIntegerKeysDataProvider */ public function sortArrayWithIntegerKeysSortsNumericArrays(array $arrayToSort, array $expectedArray) { $sortedArray = \TYPO3\CMS\Extbase\Utility\ArrayUtility::sortArrayWithIntegerKeys($arrayToSort); $this->assertSame($sortedArray, $expectedArray); }
/** * Create and return the armor fields for this validator * * @return \string Armor fields */ protected function _armor() { $now = null; // Add the HMAC hidden field $armor = '<input type="hidden" name="' . htmlspecialchars($this->_token) . '[hmac]" value="' . htmlspecialchars($this->_hmac($now)) . '"/>'; // Add the timestamp field if ($now !== null) { $armor .= '<input type="hidden" name="' . htmlspecialchars($this->_token) . '[ts]" value="' . intval($now) . '"/>'; } // Add the honeypot field if ($this->_honeypotEnabled()) { $viewSettings = $this->_setup('view.'); /* @var $standaloneView \TYPO3\CMS\Fluid\View\StandaloneView */ $standaloneView = $this->_objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView'); if (version_compare(TYPO3_version, '7.3.0', '>=')) { $standaloneView->setTemplateRootPaths($viewSettings['templateRootPaths.']); $standaloneView->setTemplate('Armor/Honeypot.html'); } else { $templateRootPaths = \TYPO3\CMS\Extbase\Utility\ArrayUtility::sortArrayWithIntegerKeys($viewSettings['templateRootPaths.']); foreach (array_reverse($templateRootPaths) as $templateRootPath) { $templateRootPathAndFileName = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(\TYPO3\CMS\Core\Utility\GeneralUtility::fixWindowsFilePath($templateRootPath . '/Armor/Honeypot.html'), FALSE); if (@file_exists($templateRootPathAndFileName) && @is_readable($templateRootPathAndFileName)) { $standaloneView->setTemplatePathAndFilename($templateRootPathAndFileName); break; } } } $standaloneView->setPartialRootPaths($viewSettings['partialRootPaths.']); $standaloneView->setLayoutRootPaths($viewSettings['layoutRootPaths.']); $standaloneView->assign('honeypots', array_keys($this->_honeypotFields())); $armor .= $standaloneView->render(); } return $armor; }
protected function getViewFileName(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext) { // try to get the view name based upon the controller/action $controller = $controllerContext->getRequest()->getControllerName(); $action = $controllerContext->getRequest()->getControllerActionName(); $file = $controller . '/' . ucfirst($action) . '.tpl'; $paths = $this->getTemplateRootPaths(); $paths = \TYPO3\CMS\Extbase\Utility\ArrayUtility::sortArrayWithIntegerKeys($paths); $paths = array_reverse($paths, true); foreach ($paths as $rootPath) { $fileName = GeneralUtility::fixWindowsFilePath($rootPath . '/' . $file); $fileName = GeneralUtility::getFileAbsFileName($fileName); if (file_exists($fileName)) { return $fileName; } } // no view found throw new \Exception('Template not found for ' . $controller . '->' . $action); }