1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16: 17:
18: class Smarty_Internal_Resource_File extends Smarty_Resource
19: {
20: 21: 22: 23: 24: 25:
26: public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
27: {
28: $source->filepath = $this->buildFilepath($source, $_template);
29:
30: if ($source->filepath !== false) {
31: if (is_object($source->smarty->security_policy)) {
32: $source->smarty->security_policy->isTrustedResourceDir($source->filepath);
33: }
34:
35: $source->uid = sha1(realpath($source->filepath));
36: if ($source->smarty->compile_check && !isset($source->timestamp)) {
37: $source->timestamp = @filemtime($source->filepath);
38: $source->exists = !!$source->timestamp;
39: }
40: }
41: }
42:
43: 44: 45: 46: 47:
48: public function populateTimestamp(Smarty_Template_Source $source)
49: {
50: $source->timestamp = @filemtime($source->filepath);
51: $source->exists = !!$source->timestamp;
52: }
53:
54: 55: 56: 57: 58: 59: 60: 61:
62: public function getContent(Smarty_Template_Source $source)
63: {
64: if ($source->timestamp) {
65: return file_get_contents($source->filepath);
66: }
67: if ($source instanceof Smarty_Config_Source) {
68: throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
69: }
70: throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
71: }
72:
73: 74: 75: 76: 77: 78: 79:
80: public function getBasename(Smarty_Template_Source $source)
81: {
82: $_file = $source->name;
83: if (($_pos = strpos($_file, ']')) !== false) {
84: $_file = substr($_file, $_pos + 1);
85: }
86:
87: return basename($_file);
88: }
89: }
90: