blob: ed60292042fc8cd395117f2eaae538e1f774ab12 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<?php
/**
* Smarty Resource Extension
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
*/
/**
* Smarty Resource Extension
* Default template and config file handling
*
* @package Smarty
* @subpackage TemplateResources
*/
class Smarty_Internal_Extension_DefaultTemplateHandler
{
/**
* get default content from template of config resource handler
*
* @param Smarty_Internal_Template $_template
* @param Smarty_Internal_Template_Source $source
* @param Smarty_Resource $resObj
*/
static function _getDefault(Smarty_Internal_Template $_template, &$source, &$resObj)
{
if ($source->isConfig) {
$default_handler = $_template->smarty->default_config_handler_func;
} else {
$default_handler = $_template->smarty->default_template_handler_func;
}
$_content = $_timestamp = null;
$_return = call_user_func_array($default_handler,
array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty));
if (is_string($_return)) {
$source->exists = is_file($_return);
if ($source->exists) {
$source->timestamp = filemtime($_return);
}
$source->filepath = $_return;
} elseif ($_return === true) {
$source->content = $_content;
$source->timestamp = $_timestamp;
$source->exists = true;
$source->recompiled = true;
$source->filepath = false;
}
}
/**
* register template default handler
*
* @param Smarty $smarty
* @param mixed $callback
*
* @throws SmartyException
*/
static function registerDefaultTemplateHandler(Smarty $smarty, $callback)
{
if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback;
} else {
throw new SmartyException("Default template handler not callable");
}
}
/**
* register config default handler
*
* @param Smarty $smarty
* @param mixed $callback
*
* @throws SmartyException
*/
static function registerDefaultConfigHandler(Smarty $smarty, $callback)
{
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {
throw new SmartyException("Default config handler not callable");
}
}
}
|