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 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: * @version $Id$
17: */
18:
19:
20: class Smarty_Resource_Admin extends Smarty_Resource_Custom
21: {
22: /**
23: * Fetch a template and its modification time from database
24: *
25: * @param string $name template name
26: * @param string $source template source
27: * @param integer $mtime template modification timestamp (epoch)
28: *
29: * @return void
30: */
31: protected function fetch($name, &$source, &$mtime)
32: {
33: $tpl = $this->adminTplInfo($name);
34: $stat = stat($tpl);
35:
36: // Did we fail to get stat information?
37: if ($stat) {
38: $mtime = $stat['mtime'];
39: $filesize = $stat['size'];
40: $fp = fopen($tpl, 'r');
41: $source = ($filesize > 0) ? fread($fp, $filesize) : '';
42: fclose($fp);
43:
44: } else {
45: $source = null;
46: $mtime = null;
47: }
48: }
49:
50: /**
51: * Translate template name to absolute file name path
52: *
53: * @param string $tpl_name template name
54: *
55: * @return string absolute file name path
56: */
57: private function adminTplInfo($tpl_name)
58: {
59: static $cache = array();
60: $xoops = Xoops::getInstance();
61: $tpl_info = $xoops->getTplInfo('admin:'.$tpl_name);
62: $tpl_name = $tpl_info['tpl_name'];
63: $dirname = $tpl_info['module'];
64: $file = $tpl_info['file'];
65:
66: $theme_set = $xoops->getConfig('theme_set') ? $xoops->getConfig('theme_set') : 'default';
67: if (!file_exists($file_path = $xoops->path("themes/{$theme_set}/modules/{$dirname}/admin/{$file}"))) {
68: $file_path = $xoops->path("modules/{$dirname}/templates/admin/{$file}");
69: }
70: return $cache[$tpl_name] = $file_path;
71: }
72: }
73: