filepath = $source->type . ':' . $this->generateSafeName($source->name); $source->uid = sha1($source->type . ':' . $source->name); $mtime = $this->fetchTimestamp($source->name); if ($mtime !== null) { $source->timestamp = $mtime; } else { $this->fetch($source->name, $content, $timestamp); $source->timestamp = isset($timestamp) ? $timestamp : false; if (isset($content)) { $source->content = $content; } } $source->exists = !!$source->timestamp; } /** * Load template's source into current template object * * @param Smarty_Template_Source $source source object * * @return string template source * @throws SmartyException if source cannot be loaded */ public function getContent(Smarty_Template_Source $source) { $this->fetch($source->name, $content, $timestamp); if (isset($content)) { return $content; } throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); } /** * Determine basename for compiled filename * * @param Smarty_Template_Source $source source object * * @return string resource's basename */ public function getBasename(Smarty_Template_Source $source) { return basename($this->generateSafeName($source->name)); } /** * Removes special characters from $name and limits its length to 127 characters. * * @param $name * * @return string */ private function generateSafeName($name): string { return substr(preg_replace('/[^A-Za-z0-9._]/', '', (string) $name), 0, 127); } }