PEEL Shopping
Open source ecommerce : PEEL Shopping
smarty_internal_config.php
Go to the documentation of this file.
1 <?php
23 
29  public $smarty = null;
35  public $data = null;
40  public $config_resource = null;
46  public $compiled_config = null;
52  public $compiled_filepath = null;
58  public $compiled_timestamp = null;
63  public $mustCompile = null;
69  public $compiler_object = null;
70 
78  public function __construct($config_resource, $smarty, $data = null)
79  {
80  $this->data = $data;
81  $this->smarty = $smarty;
82  $this->config_resource = $config_resource;
83  }
84 
90  public function getCompiledFilepath()
91  {
92  return $this->compiled_filepath === null ?
93  ($this->compiled_filepath = $this->buildCompiledFilepath()) :
94  $this->compiled_filepath;
95  }
96 
102  public function buildCompiledFilepath()
103  {
104  $_compile_id = isset($this->smarty->compile_id) ? preg_replace('![^\w\|]+!', '_', $this->smarty->compile_id) : null;
105  $_flag = (int) $this->smarty->config_read_hidden + (int) $this->smarty->config_booleanize * 2
106  + (int) $this->smarty->config_overwrite * 4;
107  $_filepath = sha1($this->source->name . $_flag);
108  // if use_sub_dirs, break file into directories
109  if ($this->smarty->use_sub_dirs) {
110  $_filepath = substr($_filepath, 0, 2) . DS
111  . substr($_filepath, 2, 2) . DS
112  . substr($_filepath, 4, 2) . DS
113  . $_filepath;
114  }
115  $_compile_dir_sep = $this->smarty->use_sub_dirs ? DS : '^';
116  if (isset($_compile_id)) {
117  $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
118  }
119  $_compile_dir = $this->smarty->getCompileDir();
120  return $_compile_dir . $_filepath . '.' . basename($this->source->name) . '.config' . '.php';
121  }
122 
128  public function getCompiledTimestamp()
129  {
130  return $this->compiled_timestamp === null
131  ? ($this->compiled_timestamp = (file_exists($this->getCompiledFilepath())) ? filemtime($this->getCompiledFilepath()) : false)
133  }
134 
142  public function mustCompile()
143  {
144  return $this->mustCompile === null ?
145  $this->mustCompile = ($this->smarty->force_compile || $this->getCompiledTimestamp () === false || $this->smarty->compile_check && $this->getCompiledTimestamp () < $this->source->timestamp):
146  $this->mustCompile;
147  }
148 
156  public function getCompiledConfig()
157  {
158  if ($this->compiled_config === null) {
159  // see if template needs compiling.
160  if ($this->mustCompile()) {
161  $this->compileConfigSource();
162  } else {
163  $this->compiled_config = file_get_contents($this->getCompiledFilepath());
164  }
165  }
166  return $this->compiled_config;
167  }
168 
174  public function compileConfigSource()
175  {
176  // compile template
177  if (!is_object($this->compiler_object)) {
178  // load compiler
179  $this->compiler_object = new Smarty_Internal_Config_File_Compiler($this->smarty);
180  }
181  // compile locking
182  if ($this->smarty->compile_locking) {
183  if ($saved_timestamp = $this->getCompiledTimestamp()) {
184  touch($this->getCompiledFilepath());
185  }
186  }
187  // call compiler
188  try {
189  $this->compiler_object->compileSource($this);
190  } catch (Exception $e) {
191  // restore old timestamp in case of error
192  if ($this->smarty->compile_locking && $saved_timestamp) {
193  touch($this->getCompiledFilepath(), $saved_timestamp);
194  }
195  throw $e;
196  }
197  // compiling succeded
198  // write compiled template
200  }
201 
208  public function loadConfigVars($sections = null, $scope = 'local')
209  {
210  if ($this->data instanceof Smarty_Internal_Template) {
211  $this->data->properties['file_dependency'][sha1($this->source->filepath)] = array($this->source->filepath, $this->source->timestamp, 'file');
212  }
213  if ($this->mustCompile()) {
214  $this->compileConfigSource();
215  }
216  // pointer to scope
217  if ($scope == 'local') {
218  $scope_ptr = $this->data;
219  } elseif ($scope == 'parent') {
220  if (isset($this->data->parent)) {
221  $scope_ptr = $this->data->parent;
222  } else {
223  $scope_ptr = $this->data;
224  }
225  } elseif ($scope == 'root' || $scope == 'global') {
226  $scope_ptr = $this->data;
227  while (isset($scope_ptr->parent)) {
228  $scope_ptr = $scope_ptr->parent;
229  }
230  }
231  $_config_vars = array();
232  include($this->getCompiledFilepath());
233  // copy global config vars
234  foreach ($_config_vars['vars'] as $variable => $value) {
235  if ($this->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
236  $scope_ptr->config_vars[$variable] = $value;
237  } else {
238  $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
239  }
240  }
241  // scan sections
242  if (!empty($sections)) {
243  foreach ((array) $sections as $this_section) {
244  if (isset($_config_vars['sections'][$this_section])) {
245  foreach ($_config_vars['sections'][$this_section]['vars'] as $variable => $value) {
246  if ($this->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
247  $scope_ptr->config_vars[$variable] = $value;
248  } else {
249  $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
250  }
251  }
252  }
253  }
254  }
255  }
256 
264  public function __set($property_name, $value)
265  {
266  switch ($property_name) {
267  case 'source':
268  case 'compiled':
269  $this->$property_name = $value;
270  return;
271  }
272 
273  throw new SmartyException("invalid config property '$property_name'.");
274  }
275 
282  public function __get($property_name)
283  {
284  switch ($property_name) {
285  case 'source':
286  if (empty($this->config_resource)) {
287  throw new SmartyException("Unable to parse resource name \"{$this->config_resource}\"");
288  }
289  $this->source = Smarty_Resource::config($this);
290  return $this->source;
291 
292  case 'compiled':
293  $this->compiled = $this->source->getCompiled($this);
294  return $this->compiled;
295  }
296 
297  throw new SmartyException("config attribute '$property_name' does not exist.");
298  }
299 
300 }
301 
302 ?>
getCompiledTimestamp()
Returns the timpestamp of the compiled file.
mustCompile()
Returns if the current config file must be compiled.
__construct($config_resource, $smarty, $data=null)
Constructor of config file object.
getCompiledFilepath()
Returns the compiled filepath.
loadConfigVars($sections=null, $scope= 'local')
load config variables
static config(Smarty_Internal_Config $_config)
initialize Config Source Object for given resource
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
compileConfigSource()
Compiles the config files.
__get($property_name)
get Smarty property in template context
getCompiledConfig()
Returns the compiled config file.
buildCompiledFilepath()
Get file path.
static writeFile($_filepath, $_contents, Smarty $smarty)
Writes file in a safe way to disk.
__set($property_name, $value)
set Smarty property in template context

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:17 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.