1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: |
|
9: |
|
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: |
|
17: | abstract class Smarty_Resource_Custom extends Smarty_Resource
|
18: | {
|
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: |
|
26: | abstract protected function fetch($name, &$source, &$mtime);
|
27: |
|
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: |
|
37: | protected function fetchTimestamp($name)
|
38: | {
|
39: | return null;
|
40: | }
|
41: |
|
42: | |
43: | |
44: | |
45: | |
46: | |
47: |
|
48: | public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
49: | {
|
50: | $source->filepath = $source->type . ':' . substr(preg_replace('/[^A-Za-z0-9.]/', '', $source->name), 0, 25);
|
51: | $source->uid = sha1($source->type . ':' . $source->name);
|
52: | $mtime = $this->fetchTimestamp($source->name);
|
53: | if ($mtime !== null) {
|
54: | $source->timestamp = $mtime;
|
55: | } else {
|
56: | $this->fetch($source->name, $content, $timestamp);
|
57: | $source->timestamp = isset($timestamp) ? $timestamp : false;
|
58: | if (isset($content)) {
|
59: | $source->content = $content;
|
60: | }
|
61: | }
|
62: | $source->exists = !!$source->timestamp;
|
63: | }
|
64: |
|
65: | |
66: | |
67: | |
68: | |
69: | |
70: | |
71: | |
72: |
|
73: | public function getContent(Smarty_Template_Source $source)
|
74: | {
|
75: | $this->fetch($source->name, $content, $timestamp);
|
76: | if (isset($content)) {
|
77: | return $content;
|
78: | }
|
79: | throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
80: | }
|
81: |
|
82: | |
83: | |
84: | |
85: | |
86: | |
87: | |
88: |
|
89: | public function getBasename(Smarty_Template_Source $source)
|
90: | {
|
91: | return basename(substr(preg_replace('/[^A-Za-z0-9.]/', '', $source->name), 0, 25));
|
92: | }
|
93: | }
|
94: | |