31 $file = $source->name;
32 preg_match(
'#^(?P<absolute>[\\\/]|[a-zA-Z]:[\\\/])|(\[(?P<index>[^\]]+)\])|(?P<rel>\.[\\\/])#', $file, $fileMatch);
34 if (!empty($fileMatch[
'absolute'])) {
36 return is_file($file) ? $file :
false;
40 if ($_template->parent->source->type !=
'file' && $_template->parent->source->type !=
'extends' && !$_template->parent->allow_relative_path) {
41 throw new SmartyException(
"Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
43 $path = dirname($_template->parent->source->filepath) . DS . $file;
47 return is_file($path) ? $path :
false;
50 if ($source->isConfig) {
51 $_directories = $source->smarty->getConfigDir();
53 $_directories = $source->smarty->getTemplateDir();
56 if (!empty($fileMatch[
'index'])) {
57 $index = $fileMatch[
'index'];
60 if (isset($_directories[$index])) {
61 $_directory = $_directories[$index];
62 } elseif (is_numeric($index)) {
64 $index = (int) $index;
65 if (isset($_directories[$index])) {
66 $_directory = $_directories[$index];
69 $keys = array_keys($_directories);
70 $_directory = $_directories[$keys[$index]];
74 preg_match(
'#\](.+)$#', $file, $fileMatch);
75 $path = $_directory . $fileMatch[1];
87 foreach ($_directories as $_directory) {
88 $_filepath = $_directory . $file;
93 if ($source->smarty->use_include_path && !preg_match(
'/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_directory)) {
95 if (function_exists(
'stream_resolve_include_path')) {
96 $_filepath = stream_resolve_include_path($_filepath);
100 if ($_filepath !==
false) {
102 if (is_file($path)) {
110 return is_file($path) ? $path :
false;
124 if ($path[0] ==
'.') {
125 $path = getcwd() . DS . $path;
127 $path = preg_replace(
'#[\\\/]+([.][\\\/]+)*#', DS, $path);
128 while (strrpos($path,
'.' . DS) !==
false) {
129 $path = preg_replace(
'#([\\\/]([^\\\/]+[\\\/]){2}([.][.][\\\/]){2})|([\\\/][^\\\/]+[\\\/][.][.][\\\/])#', DS, $path);
144 $source->timestamp = is_file($file) ? @filemtime($file) :
false;
145 return $source->exists = !!$source->timestamp;
156 $source->filepath = $this->
buildFilepath($source, $_template);
158 if ($source->filepath !==
false) {
159 if (is_object($source->smarty->security_policy)) {
160 $source->smarty->security_policy->isTrustedResourceDir($source->filepath);
162 $source->exists =
true;
163 $source->uid = sha1($source->filepath);
164 if ($source->smarty->compile_check && !isset($source->timestamp)) {
165 $source->timestamp = @filemtime($source->filepath);
168 $source->timestamp =
false;
169 $source->exists =
false;
180 $source->timestamp = $source->exists = is_file($source->filepath);
181 if ($source->exists) {
182 $source->timestamp = @filemtime($source->filepath);
196 if ($source->timestamp) {
197 return file_get_contents($source->filepath);
199 if ($source instanceof Smarty_Config_Source) {
200 throw new SmartyException(
"Unable to read config {$source->type} '{$source->name}'");
202 throw new SmartyException(
"Unable to read template {$source->type} '{$source->name}'");
214 return basename($source->filepath);