1: | <?php
|
2: |
|
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: |
|
12: | class Smarty_Internal_Method_RegisterDefaultTemplateHandler
|
13: | {
|
14: | |
15: | |
16: | |
17: | |
18: |
|
19: | public $objMap = 3;
|
20: |
|
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: |
|
32: | public function registerDefaultTemplateHandler(Smarty_Internal_TemplateBase $obj, $callback)
|
33: | {
|
34: | $smarty = $obj->_getSmartyObj();
|
35: | if (is_callable($callback)) {
|
36: | $smarty->default_template_handler_func = $callback;
|
37: | } else {
|
38: | throw new SmartyException('Default template handler not callable');
|
39: | }
|
40: | return $obj;
|
41: | }
|
42: |
|
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: |
|
50: | public static function _getDefaultTemplate(Smarty_Template_Source $source)
|
51: | {
|
52: | if ($source->isConfig) {
|
53: | $default_handler = $source->smarty->default_config_handler_func;
|
54: | } else {
|
55: | $default_handler = $source->smarty->default_template_handler_func;
|
56: | }
|
57: | $_content = $_timestamp = null;
|
58: | $_return = call_user_func_array(
|
59: | $default_handler,
|
60: | array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty)
|
61: | );
|
62: | if (is_string($_return)) {
|
63: | $source->exists = is_file($_return);
|
64: | if ($source->exists) {
|
65: | $source->timestamp = filemtime($_return);
|
66: | } else {
|
67: | throw new SmartyException(
|
68: | 'Default handler: Unable to load ' .
|
69: | ($source->isConfig ? 'config' : 'template') .
|
70: | " default file '{$_return}' for '{$source->type}:{$source->name}'"
|
71: | );
|
72: | }
|
73: | $source->name = $source->filepath = $_return;
|
74: | $source->uid = sha1($source->filepath);
|
75: | } elseif ($_return === true) {
|
76: | $source->content = $_content;
|
77: | $source->exists = true;
|
78: | $source->uid = $source->name = sha1($_content);
|
79: | $source->handler = Smarty_Resource::load($source->smarty, 'eval');
|
80: | } else {
|
81: | $source->exists = false;
|
82: | throw new SmartyException(
|
83: | 'Default handler: No ' . ($source->isConfig ? 'config' : 'template') .
|
84: | " default content for '{$source->type}:{$source->name}'"
|
85: | );
|
86: | }
|
87: | }
|
88: | }
|
89: | |