XOOPS  2.6.0
resource.db.php
Go to the documentation of this file.
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 
20 class Smarty_Resource_Db extends Smarty_Resource_Custom
21 {
22 
32  protected function fetch($name, &$source, &$mtime)
33  {
34  $tpl = $this->dbTplInfo($name);
35  if (is_object($tpl)) {
36  /* @var $tpl XoopsTplfile */
37  $source = $tpl->getVar('tpl_source', 'n');
38  $mtime = $tpl->getVar('tpl_lastmodified', 'n');
39  } else {
40  $stat = stat($tpl);
41 
42  // Did we fail to get stat information?
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 
63  private function dbTplInfo($tpl_name)
64  {
65  static $cache = array();
66  global $xoopsConfig;
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->getHandlerTplfile();
75  // If we're not using the "default" template set, then get the templates from the DB
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  // If we'using the default tplset, get the template from the filesystem
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  /* @var $tplobj XoopsTplfile */
89  $tplobj = $tplobj[0];
90  $module = $tplobj->getVar('tpl_module', 'n');
91  $type = $tplobj->getVar('tpl_type', 'n');
92  // Construct template path
93  switch ($type) {
94  case 'block':
95  $directory = \XoopsBaseConfig::get('themes-path');
96  $path = 'blocks/';
97  break;
98  case 'admin':
99  $theme = isset($xoopsConfig['cpanel']) ? $xoopsConfig['cpanel'] : 'default';
100  $directory = \XoopsBaseConfig::get('adminthemes-path');
101  $path = 'admin/';
102  break;
103  default:
104  $directory = \XoopsBaseConfig::get('themes-path');
105  $path = '';
106  break;
107  }
108  // First, check for an overloaded version within the theme folder
109  $filepath = $directory . "/{$theme}/modules/{$module}/{$path}{$tpl_name}";
110  if (!file_exists($filepath)) {
111  // If no custom version exists, get the tpl from its default location
112  $filepath = \XoopsBaseConfig::get('root-path') . "/modules/{$module}/templates/{$path}{$tpl_name}";
113  if (!file_exists($filepath)) {
114  return $cache[$tpl_name] = $tplobj ;
115  }
116  }
117  return $cache[$tpl_name] = $filepath;
118  }
119 }
$tpl
Definition: backend.php:39
$path
Definition: execute.php:31
static getInstance()
Definition: Xoops.php:160
$xoops
Definition: admin.php:25
fetch($name, &$source, &$mtime)
Definition: resource.db.php:32
static get($name)
$module
Definition: main.php:52
$type
Definition: misc.php:33
dbTplInfo($tpl_name)
Definition: resource.db.php:63
$xoopsConfig
Definition: common.php:130
if($file===false||$dir===false||!strstr($file, $dir)) if(empty($file)||strpos($file, '.php')!==false) $mtime
Definition: browse.php:71