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