/** * Return an asset source file path. * * A system of fallback enables file overriding. It will look for the template : * - in the current template in directory /modules/{module code}/ * - in the module in the current template if it exists * - in the module in the default template * * @param string $source a module code, or or SmartyParser::TEMPLATE_ASSETS_KEY * @param string $templateName a template name, or false to use the current template * @param string $fileName the filename * @param ParserInterface $parserInterface the current template parser * * @return mixed the path to directory containing the file, or null if the file doesn't exists. */ public function resolveAssetSourcePath($source, $templateName, $fileName, ParserInterface $parserInterface) { $filePath = null; $templateDefinition = $parserInterface->getTemplateDefinition(false); // Get all possible directories to search $paths = $this->getPossibleAssetSources($parserInterface->getTemplateDirectories($templateDefinition->getType()), $templateName ?: $templateDefinition->getName(), $source); // Normalize path separator if required (e.g., / becomes \ on windows) $fileName = $this->fixPathSeparator($fileName); /* Absolute paths are not allowed. This may be a mistake, such as '/assets/...' instead of 'assets/...'. Forgive it. */ $fileName = ltrim($fileName, DS); /* Navigating in the server's directory tree is not allowed :) */ if (preg_match('!\\.\\.\\' . DS . '!', $fileName)) { // This time, we will not forgive. throw new \InvalidArgumentException("Relative paths are not allowed in assets names."); } // Find the first occurrence of the file in the directories lists foreach ($paths as $path) { if ($this->filesExist($path, $fileName)) { // Got it ! $filePath = $path; break; } } return $filePath; }
/** * @param array $params * @param string $content * @param \Smarty_Internal_Template $template * @param string $templateTypeName * @return string */ protected function automaticFormFieldRendering($params, $content, $template, $templateFile) { $data = ''; $templateStyle = $this->getParam($params, 'template', 'standard'); $snippet_path = sprintf('%s' . DS . 'forms' . DS . '%s' . DS . '%s.html', $this->parser->getTemplateDefinition()->getAbsolutePath(), $templateStyle, $templateFile); if (false !== ($snippet_content = file_get_contents($snippet_path))) { $this->processFormField($params, $template); $form = $this->getParam($params, 'form', false); $field_name = $this->getParam($params, 'field', false); $field_extra_class = $this->getParam($params, 'extra_class', ''); $field_value = $this->getParam($params, 'value', ''); $show_label = $this->getParam($params, 'show_label', true); $value_key = $this->getParam($params, 'value_key', false); $template->assign(['content' => trim($content), 'form' => $form, 'field_name' => $field_name, 'field_extra_class' => $field_extra_class, 'field_value' => $field_value, 'field_template' => $templateStyle, 'value_key' => $value_key, 'show_label' => $show_label]); $data = $template->fetch(sprintf('string:%s', $snippet_content)); } return $data; }