XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
resource.db.php
Go to the documentation of this file.
1 <?php
18 function smarty_resource_db_source($tpl_name, &$tpl_source, &$smarty)
19 {
20  if (!$tpl = smarty_resource_db_tplinfo($tpl_name)) {
21  return false;
22  }
23  if (is_object($tpl)) {
24  $tpl_source = $tpl->getVar('tpl_source', 'n');
25  } else {
26  $fp = fopen($tpl, 'r');
27  $filesize = filesize($tpl);
28  $tpl_source = ($filesize > 0) ? fread($fp, $filesize) : '';
29  fclose($fp);
30  }
31  return true;
32 }
33 
34 function smarty_resource_db_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
35 {
36  if (!$tpl = smarty_resource_db_tplinfo($tpl_name)) {
37  return false;
38  }
39  if (is_object($tpl)) {
40  $tpl_timestamp = $tpl->getVar('tpl_lastmodified', 'n');
41  } else {
42  $tpl_timestamp = filemtime($tpl);
43  }
44  return true;
45 }
46 
47 function smarty_resource_db_secure($tpl_name, &$smarty)
48 {
49  // assume all templates are secure
50  return true;
51 }
52 
53 function smarty_resource_db_trusted($tpl_name, &$smarty)
54 {
55  // not used for templates
56 }
57 
58 function smarty_resource_db_tplinfo($tpl_name)
59 {
60  static $cache = array();
61  global $xoopsConfig;
62 
63  if (isset($cache[$tpl_name])) {
64  return $cache[$tpl_name];
65  }
66  $tplset = $xoopsConfig['template_set'];
67  $theme = isset($xoopsConfig['theme_set']) ? $xoopsConfig['theme_set'] : 'default';
68  $tplfile_handler =& xoops_gethandler('tplfile');
69  // If we're not using the "default" template set, then get the templates from the DB
70  if ($tplset != "default") {
71  $tplobj = $tplfile_handler->find($tplset, null, null, null, $tpl_name, true);
72  if (count($tplobj)) {
73  return $cache[$tpl_name] = $tplobj[0];
74  }
75  }
76  // If we'using the default tplset, get the template from the filesystem
77  $tplobj = $tplfile_handler->find("default", null, null, null, $tpl_name, true);
78 
79  if (!count($tplobj)) {
80  return $cache[$tpl_name] = false;
81  }
82  $tplobj = $tplobj[0];
83  $module = $tplobj->getVar('tpl_module', 'n');
84  $type = $tplobj->getVar('tpl_type', 'n');
85  // Construct template path
86  switch ($type) {
87  case 'block':
88  $directory = XOOPS_THEME_PATH;
89  $path = 'blocks/';
90  break;
91  case 'admin':
92  $theme = isset($xoopsConfig['cpanel']) ? $xoopsConfig['cpanel'] : 'default';
93  $directory = XOOPS_ADMINTHEME_PATH;
94  $path = 'admin/';
95  break;
96  default:
97  $directory = XOOPS_THEME_PATH;
98  $path = '';
99  break;
100  }
101  // First, check for an overloaded version within the theme folder
102  $filepath = $directory . "/{$theme}/modules/{$module}/{$path}{$tpl_name}";
103  if (!file_exists($filepath)) {
104  // If no custom version exists, get the tpl from its default location
105  $filepath = XOOPS_ROOT_PATH . "/modules/{$module}/templates/{$path}{$tpl_name}";
106  if (!file_exists($filepath)) {
107  return $cache[$tpl_name] = $tplobj ;
108  }
109  }
110  return $cache[$tpl_name] = $filepath;
111 }
112 
113 ?>