/** * Render a TypoScript and resolve all references (eg. " < plugin.tx_form...") recursively * * @param array $typoScript * @return array * @todo Extract to core then... */ protected function resolveTypoScriptReferences(array $typoScript) { $ignoreKeys = array(); foreach ($typoScript as $key => $value) { if (isset($ignoreKeys[$key])) { continue; } // i am a reference if ($value[0] === '<') { if (isset($typoScript[$key . '.'])) { $oldTypoScript = $typoScript[$key . '.']; } else { $oldTypoScript = array(); } // detect search level $referencePath = trim(substr($value, 1)); $dotPosition = strpos($referencePath, '.'); if ($dotPosition === 0) { // same position x =< .y list($flatValue, $arrayValue) = $this->typoScriptParser->getVal(substr($referencePath, 1), $typoScript); } else { list($flatValue, $arrayValue) = $this->typoScriptParser->getVal($referencePath, $GLOBALS['TSFE']->tmpl->setup); } if (is_array($arrayValue)) { $typoScript[$key . '.'] = array_replace_recursive($arrayValue, $oldTypoScript); } if ($flatValue[0] === '<') { $temporaryTypoScript = array('temp' => $flatValue, 'temp.' => $typoScript[$key . '.']); $temporaryTypoScript = $this->resolveTypoScriptReferences($temporaryTypoScript); $arrayValue = array_replace_recursive($temporaryTypoScript['temp.'], $arrayValue, $oldTypoScript); } if (is_array($arrayValue)) { $typoScript[$key . '.'] = array_replace_recursive($arrayValue, $oldTypoScript); } elseif (isset($flatValue)) { $typoScript[$key] = $flatValue; } else { $typoScript[$key . '.'] = $oldTypoScript; } } // if array, then look deeper if (isset($typoScript[$key . '.'])) { $ignoreKeys[$key . '.'] = true; $typoScript[$key . '.'] = $this->resolveTypoScriptReferences($typoScript[$key . '.']); } elseif (is_array($typoScript[$key])) { // if array, then look deeper $typoScript[$key] = $this->resolveTypoScriptReferences($typoScript[$key]); } } return $typoScript; }
/** * SitemapRepository constructor. * @SuppressWarnings(superglobals) */ public function __construct() { $this->typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class); $this->pluginConfig = $this->typoScriptParser->getVal('plugin.tx_sitemapgenerator', $GLOBALS['TSFE']->tmpl->setup); }
/** * Call back method for preg_replace_callback in substituteConstants * * @param $matches * @return string Replacement * @see substituteConstants() */ public function substituteConstantsCallBack($matches) { $s = $this->parser->getVal($matches[1], $this->parser->setup); return isset($s[0]) ? $s[0] : $matches[0]; }