PEEL Shopping
Open source ecommerce : PEEL Shopping
smarty_internal_compile_include.php
Go to the documentation of this file.
1 <?php
19 
23  const CACHING_NOCACHE_CODE = 9999;
30  public $required_attributes = array('file');
37  public $shorttag_order = array('file');
44  public $option_flags = array('nocache', 'inline', 'caching');
51  public $optional_attributes = array('_any');
52 
61  public function compile($args, $compiler, $parameter)
62  {
63  // check and get attributes
64  $_attr = $this->getAttributes($compiler, $args);
65  // save posible attributes
66  $include_file = $_attr['file'];
67 
68  if (isset($_attr['assign'])) {
69  // output will be stored in a smarty variable instead of beind displayed
70  $_assign = $_attr['assign'];
71  }
72 
73  $_parent_scope = Smarty::SCOPE_LOCAL;
74  if (isset($_attr['scope'])) {
75  $_attr['scope'] = trim($_attr['scope'], "'\"");
76  if ($_attr['scope'] == 'parent') {
77  $_parent_scope = Smarty::SCOPE_PARENT;
78  } elseif ($_attr['scope'] == 'root') {
79  $_parent_scope = Smarty::SCOPE_ROOT;
80  } elseif ($_attr['scope'] == 'global') {
81  $_parent_scope = Smarty::SCOPE_GLOBAL;
82  }
83  }
84  $_caching = 'null';
85  if ($compiler->nocache || $compiler->tag_nocache) {
86  $_caching = Smarty::CACHING_OFF;
87  }
88  // default for included templates
89  if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) {
90  $_caching = self::CACHING_NOCACHE_CODE;
91  }
92  /*
93  * if the {include} tag provides individual parameter for caching
94  * it will not be included into the common cache file and treated like
95  * a nocache section
96  */
97  if (isset($_attr['cache_lifetime'])) {
98  $_cache_lifetime = $_attr['cache_lifetime'];
99  $compiler->tag_nocache = true;
101  } else {
102  $_cache_lifetime = 'null';
103  }
104  if (isset($_attr['cache_id'])) {
105  $_cache_id = $_attr['cache_id'];
106  $compiler->tag_nocache = true;
108  } else {
109  $_cache_id = '$_smarty_tpl->cache_id';
110  }
111  if (isset($_attr['compile_id'])) {
112  $_compile_id = $_attr['compile_id'];
113  } else {
114  $_compile_id = '$_smarty_tpl->compile_id';
115  }
116  if ($_attr['caching'] === true) {
118  }
119  if ($_attr['nocache'] === true) {
120  $compiler->tag_nocache = true;
121  $_caching = Smarty::CACHING_OFF;
122  }
123 
124  $has_compiled_template = false;
125  if (($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) && !$compiler->template->source->recompiled
126  && !($compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache)) && $_caching != Smarty::CACHING_LIFETIME_CURRENT) {
127  // check if compiled code can be merged (contains no variable part)
128  if (!$compiler->has_variable_string && (substr_count($include_file, '"') == 2 or substr_count($include_file, "'") == 2)
129  and substr_count($include_file, '(') == 0 and substr_count($include_file, '$_smarty_tpl->') == 0) {
130  $tpl_name = null;
131  eval("\$tpl_name = $include_file;");
132  if (!isset($compiler->smarty->merged_templates_func[$tpl_name]) || $compiler->inheritance) {
133  $tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id);
134  // save unique function name
135  $compiler->smarty->merged_templates_func[$tpl_name]['func'] = $tpl->properties['unifunc'] = 'content_'. str_replace('.', '_', uniqid('', true));
136  // use current nocache hash for inlined code
137  $compiler->smarty->merged_templates_func[$tpl_name]['nocache_hash'] = $tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
138  if ($compiler->template->caching) {
139  // needs code for cached page but no cache file
140  $tpl->caching = self::CACHING_NOCACHE_CODE;
141  }
142  // make sure whole chain gest compiled
143  $tpl->mustCompile = true;
144  if (!($tpl->source->uncompiled) && $tpl->source->exists) {
145  // get compiled code
146  $compiled_code = $tpl->compiler->compileTemplate($tpl);
147  // release compiler object to free memory
148  unset($tpl->compiler);
149  // merge compiled code for {function} tags
150  $compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $tpl->properties['function']);
151  // merge filedependency
152  $tpl->properties['file_dependency'][$tpl->source->uid] = array($tpl->source->filepath, $tpl->source->timestamp,$tpl->source->type);
153  $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $tpl->properties['file_dependency']);
154  // remove header code
155  $compiled_code = preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->properties['nocache_hash']}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s", '', $compiled_code);
156  if ($tpl->has_nocache_code) {
157  // replace nocache_hash
158  $compiled_code = str_replace("{$tpl->properties['nocache_hash']}", $compiler->template->properties['nocache_hash'], $compiled_code);
159  $compiler->template->has_nocache_code = true;
160  }
161  $compiler->merged_templates[$tpl->properties['unifunc']] = $compiled_code;
162  $has_compiled_template = true;
163  }
164  } else {
165  $has_compiled_template = true;
166  }
167  }
168  }
169  // delete {include} standard attributes
170  unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']);
171  // remaining attributes must be assigned as smarty variable
172  if (!empty($_attr)) {
173  if ($_parent_scope == Smarty::SCOPE_LOCAL) {
174  // create variables
175  foreach ($_attr as $key => $value) {
176  $_pairs[] = "'$key'=>$value";
177  }
178  $_vars = 'array('.join(',',$_pairs).')';
179  $_has_vars = true;
180  } else {
181  $compiler->trigger_template_error('variable passing not allowed in parent/global scope', $compiler->lex->taglineno);
182  }
183  } else {
184  $_vars = 'array()';
185  $_has_vars = false;
186  }
187  if ($has_compiled_template) {
188  $_hash = $compiler->smarty->merged_templates_func[$tpl_name]['nocache_hash'];
189  $_output = "<?php /* Call merged included template \"" . $tpl_name . "\" */\n";
190  $_output .= "\$_tpl_stack[] = \$_smarty_tpl;\n";
191  $_output .= " \$_smarty_tpl = \$_smarty_tpl->setupInlineSubTemplate($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, '$_hash');\n";
192  if (isset($_assign)) {
193  $_output .= 'ob_start(); ';
194  }
195  $_output .= $compiler->smarty->merged_templates_func[$tpl_name]['func']. "(\$_smarty_tpl);\n";
196  $_output .= "\$_smarty_tpl = array_pop(\$_tpl_stack); ";
197  if (isset($_assign)) {
198  $_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_variable(ob_get_clean());";
199  }
200  $_output .= "/* End of included template \"" . $tpl_name . "\" */?>";
201  return $_output;
202  }
203 
204  // was there an assign attribute
205  if (isset($_assign)) {
206  $_output = "<?php \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_variable(\$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope));?>\n";;
207  } else {
208  $_output = "<?php echo \$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope);?>\n";
209  }
210  return $_output;
211  }
212 
213 }
214 
215 ?>
const SCOPE_ROOT
const CACHING_OFF
define caching modes
const SCOPE_GLOBAL
const SCOPE_PARENT
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
getAttributes($compiler, $attributes)
This function checks if the attributes passed are valid.
compile($args, $compiler, $parameter)
Compiles code for the {include} tag.
const CACHING_LIFETIME_CURRENT
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
const CACHING_NOCACHE_CODE
caching mode to create nocache code but no cache file
const SCOPE_LOCAL
define variable scopes

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.