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_Block 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->blockTplInfo($name);
31: $stat = stat($tpl);
32: // Did we fail to get stat information?
33: if ($stat) {
34: $mtime = $stat['mtime'];
35: $filesize = $stat['size'];
36: $fp = fopen($tpl, 'r');
37: $source = ($filesize > 0) ? fread($fp, $filesize) : '';
38: fclose($fp);
39:
40: } else {
41: $source = null;
42: $mtime = null;
43: }
44: }
45:
46: /**
47: * Translate template name to absolute file name path
48: *
49: * @param string $tpl_name template name
50: *
51: * @return string absolute file name path
52: */
53: private function blockTplInfo($tpl_name)
54: {
55: static $cache = array();
56: $xoops = \Xoops::getInstance();
57: $tpl_info = $xoops->getTplInfo('block:'.$tpl_name);
58: $tpl_name = $tpl_info['tpl_name'];
59: $dirname = $tpl_info['module'];
60: $file = $tpl_info['file'];
61:
62: // why are we not checking $cache here?
63:
64: $theme_set = $xoops->getConfig('theme_set') ? $xoops->getConfig('theme_set') : 'default';
65: if (!file_exists($file_path = $xoops->path("themes/{$theme_set}/modules/{$dirname}/blocks/{$file}"))) {
66: $file_path = $xoops->path("modules/{$dirname}/templates/blocks/{$file}");
67: }
68: return $cache[$tpl_name] = $file_path;
69: }
70: }
71: