1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * @copyright 2008-2015 XOOPS Project (http://xoops.org)
14: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15: * @author trabis <lusopoemas@gmail.com>
16: */
17: class Smarty_Resource_Module extends Smarty_Resource_Custom
18: {
19: /**
20: * Fetch a template and its modification time from database
21: *
22: * @param string $name template name
23: * @param string $source template source
24: * @param integer $mtime template modification timestamp (epoch)
25: *
26: * @return void
27: */
28: protected function fetch($name, &$source, &$mtime)
29: {
30: $tpl = $this->moduleTplInfo($name);
31: $stat = stat($tpl);
32:
33: // Did we fail to get stat information?
34: if ($stat) {
35: $mtime = $stat['mtime'];
36: $filesize = $stat['size'];
37: $fp = fopen($tpl, 'r');
38: $source = ($filesize > 0) ? fread($fp, $filesize) : '';
39: fclose($fp);
40:
41: } else {
42: $source = null;
43: $mtime = null;
44: }
45: }
46:
47: /**
48: * Translate template name to absolute file name path
49: *
50: * @param string $tpl_name template name
51: *
52: * @return string absolute file name path
53: */
54: private function moduleTplInfo($tpl_name)
55: {
56: static $cache = array();
57: $xoops = \Xoops::getInstance();
58: $tpl_info = $xoops->getTplInfo('module:'.$tpl_name);
59: $tpl_name = $tpl_info['tpl_name'];
60: $dirname = $tpl_info['module'];
61: $file = $tpl_info['file'];
62:
63: if (isset($cache[$tpl_name])) {
64: return $cache[$tpl_name];
65: }
66:
67: $theme_set = $xoops->getConfig('theme_set') ? $xoops->getConfig('theme_set') : 'default';
68: if (!file_exists($file_path = $xoops->path("themes/{$theme_set}/modules/{$dirname}/{$file}"))) {
69: $file_path = $xoops->path("modules/{$dirname}/templates/{$file}");
70: }
71: return $cache[$tpl_name] = $file_path;
72: }
73: }
74: