1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
21: function smarty_resource_db_source($tpl_name, &$tpl_source, &$smarty)
22: {
23: if (!$tpl = smarty_resource_db_tplinfo($tpl_name)) {
24: return false;
25: }
26: if (is_object($tpl)) {
27: $tpl_source = $tpl->getVar('tpl_source', 'n');
28: } else {
29: $fp = fopen($tpl, 'r');
30: $filesize = filesize($tpl);
31: $tpl_source = ($filesize > 0) ? fread($fp, $filesize) : '';
32: fclose($fp);
33: }
34:
35: return true;
36: }
37:
38: 39: 40: 41: 42: 43: 44:
45: function smarty_resource_db_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
46: {
47: if (!$tpl = smarty_resource_db_tplinfo($tpl_name)) {
48: return false;
49: }
50: if (is_object($tpl)) {
51: $tpl_timestamp = $tpl->getVar('tpl_lastmodified', 'n');
52: } else {
53: $tpl_timestamp = filemtime($tpl);
54: }
55:
56: return true;
57: }
58:
59: 60: 61: 62: 63: 64:
65: function smarty_resource_db_secure($tpl_name, &$smarty)
66: {
67:
68: return true;
69: }
70:
71: 72: 73: 74:
75: function smarty_resource_db_trusted($tpl_name, &$smarty)
76: {
77:
78: }
79:
80: 81: 82: 83: 84:
85: function smarty_resource_db_tplinfo($tpl_name)
86: {
87: static $cache = array();
88: global $xoopsConfig;
89:
90: if (isset($cache[$tpl_name])) {
91: return $cache[$tpl_name];
92: }
93: $tplset = $xoopsConfig['template_set'];
94: $theme = isset($xoopsConfig['theme_set']) ? $xoopsConfig['theme_set'] : 'default';
95: $tplfile_handler = xoops_getHandler('tplfile');
96:
97: if ($tplset !== 'default') {
98: $tplobj = $tplfile_handler->find($tplset, null, null, null, $tpl_name, true);
99: if (count($tplobj)) {
100: return $cache[$tpl_name] = $tplobj[0];
101: }
102: }
103:
104: $tplobj = $tplfile_handler->find('default', null, null, null, $tpl_name, true);
105:
106: if (!count($tplobj)) {
107: return $cache[$tpl_name] = false;
108: }
109: $tplobj = $tplobj[0];
110: $module = $tplobj->getVar('tpl_module', 'n');
111: $type = $tplobj->getVar('tpl_type', 'n');
112:
113: switch ($type) {
114: case 'block':
115: $directory = XOOPS_THEME_PATH;
116: $path = 'blocks/';
117: break;
118: case 'admin':
119: $theme = isset($xoopsConfig['cpanel']) ? $xoopsConfig['cpanel'] : 'default';
120: $directory = XOOPS_ADMINTHEME_PATH;
121: $path = 'admin/';
122: break;
123: default:
124: $directory = XOOPS_THEME_PATH;
125: $path = '';
126: break;
127: }
128:
129: $filepath = $directory . "/{$theme}/modules/{$module}/{$path}{$tpl_name}";
130: if (!file_exists($filepath)) {
131:
132: $filepath = XOOPS_ROOT_PATH . "/modules/{$module}/templates/{$path}{$tpl_name}";
133: if (!file_exists($filepath)) {
134: return $cache[$tpl_name] = $tplobj;
135: }
136: }
137:
138: return $cache[$tpl_name] = $filepath;
139: }
140: