| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Smarty Internal Plugin Compile Include | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * Compiles the {include} tag | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * @package Smarty | 
					
						
							|  |  |  | * @subpackage Compiler | 
					
						
							|  |  |  | * @author Uwe Tews  | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Smarty Internal Plugin Compile Include Class | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * Compiles code for the {include} tag | 
					
						
							|  |  |  |     *  | 
					
						
							|  |  |  |     * @param array $args array with attributes from parser | 
					
						
							|  |  |  |     * @param object $compiler compiler object | 
					
						
							|  |  |  |     * @return string compiled code | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     public function compile($args, $compiler) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->compiler = $compiler; | 
					
						
							|  |  |  |         $this->required_attributes = array('file'); | 
					
						
							|  |  |  |         $this->optional_attributes = array('_any');  | 
					
						
							|  |  |  |         // check and get attributes
 | 
					
						
							|  |  |  |         $_attr = $this->_get_attributes($args);  | 
					
						
							|  |  |  |         // save posible attributes
 | 
					
						
							|  |  |  |         $include_file = $_attr['file']; | 
					
						
							|  |  |  |         $has_compiled_template = false; | 
					
						
							| 
									
										
										
										
											2009-12-16 17:05:31 +00:00
										 |  |  |         if ($compiler->smarty->merge_compiled_includes || isset($_attr['inline'])) { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             // check if compiled code can be merged (contains no variable part)
 | 
					
						
							|  |  |  |             if (!$compiler->has_variable_string && (substr_count($include_file, '"') == 2 or substr_count($include_file, "'") == 2) and substr_count($include_file, '(') == 0) { | 
					
						
							|  |  |  |                 eval("\$tmp = $include_file;"); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:04:32 +00:00
										 |  |  |                 if ($this->compiler->template->template_resource != $tmp) { | 
					
						
							|  |  |  |                     $tpl = $compiler->smarty->createTemplate ($tmp, $compiler->template->cache_id, $compiler->template->compile_id, $compiler->template); | 
					
						
							| 
									
										
										
										
											2009-12-27 15:06:49 +00:00
										 |  |  |                     if ($this->compiler->template->caching) { | 
					
						
							|  |  |  |                         // needs code for cached page but no cache file
 | 
					
						
							|  |  |  |                         $tpl->caching = 9999; | 
					
						
							|  |  |  |                     }  | 
					
						
							|  |  |  |                     if ($tpl->resource_object->usesCompiler && $tpl->isExisting()) { | 
					
						
							|  |  |  |                         // make sure that template is up to date and merge template properties
 | 
					
						
							|  |  |  |                         $tpl->renderTemplate();  | 
					
						
							| 
									
										
										
										
											2009-12-29 20:12:11 +00:00
										 |  |  |                         // compiled code for {function} tags
 | 
					
						
							| 
									
										
										
										
											2009-12-31 16:38:12 +00:00
										 |  |  |                         $compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $tpl->properties['function']); | 
					
						
							| 
									
										
										
										
											2009-12-27 15:06:49 +00:00
										 |  |  |                         // get compiled code
 | 
					
						
							|  |  |  |                         $compiled_tpl = $tpl->getCompiledTemplate();  | 
					
						
							|  |  |  |                         // remove header code
 | 
					
						
							| 
									
										
										
										
											2009-12-29 20:12:11 +00:00
										 |  |  |                         $compiled_tpl = preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->properties['nocache_hash']}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s", '', $compiled_tpl); | 
					
						
							|  |  |  |                         if ($tpl->has_nocache_code) { | 
					
						
							|  |  |  |                             // replace nocache_hash
 | 
					
						
							|  |  |  |                             $compiled_tpl = preg_replace("/{$tpl->properties['nocache_hash']}/", $compiler->template->properties['nocache_hash'], $compiled_tpl); | 
					
						
							|  |  |  |                             $compiler->template->has_nocache_code = true; | 
					
						
							|  |  |  |                         }  | 
					
						
							| 
									
										
										
										
											2009-11-10 16:04:32 +00:00
										 |  |  |                         $has_compiled_template = true; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |                     }  | 
					
						
							| 
									
										
										
										
											2009-11-10 16:04:32 +00:00
										 |  |  |                 }  | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($_attr['assign'])) { | 
					
						
							|  |  |  |             // output will be stored in a smarty variable instead of beind displayed
 | 
					
						
							|  |  |  |             $_assign = $_attr['assign']; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $_parent_scope = SMARTY_LOCAL_SCOPE; | 
					
						
							|  |  |  |         if (isset($_attr['scope'])) { | 
					
						
							|  |  |  |             if ($_attr['scope'] == '\'parent\'') { | 
					
						
							|  |  |  |                 $_parent_scope = SMARTY_PARENT_SCOPE; | 
					
						
							|  |  |  |             } elseif ($_attr['scope'] == '\'root\'') { | 
					
						
							|  |  |  |                 $_parent_scope = SMARTY_ROOT_SCOPE; | 
					
						
							|  |  |  |             } elseif ($_attr['scope'] == '\'global\'') { | 
					
						
							|  |  |  |                 $_parent_scope = SMARTY_GLOBAL_SCOPE; | 
					
						
							|  |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-12-17 16:58:44 +00:00
										 |  |  |         $_caching = 'null';  | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         // default for included templates
 | 
					
						
							| 
									
										
										
										
											2009-11-14 16:20:18 +00:00
										 |  |  |         if ($this->compiler->template->caching && !$this->compiler->nocache) { | 
					
						
							| 
									
										
										
										
											2009-11-18 17:25:18 +00:00
										 |  |  |             $_caching = 9999; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         }  | 
					
						
							|  |  |  |         /* | 
					
						
							|  |  |  |         * if the {include} tag provides individual parameter for caching | 
					
						
							|  |  |  |         * it will not be included into the common cache file and treated like | 
					
						
							|  |  |  |         * a nocache section | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         if (isset($_attr['cache_lifetime'])) { | 
					
						
							|  |  |  |             $_cache_lifetime = $_attr['cache_lifetime']; | 
					
						
							|  |  |  |             $this->compiler->tag_nocache = true; | 
					
						
							| 
									
										
										
										
											2009-11-18 17:25:18 +00:00
										 |  |  |             $_caching = SMARTY_CACHING_LIFETIME_CURRENT; | 
					
						
							| 
									
										
										
										
											2009-11-26 22:49:56 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-12-17 16:58:44 +00:00
										 |  |  |             $_cache_lifetime = 'null'; | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if (isset($_attr['nocache'])) { | 
					
						
							|  |  |  |             if ($_attr['nocache'] == 'true') { | 
					
						
							|  |  |  |                 $this->compiler->tag_nocache = true; | 
					
						
							| 
									
										
										
										
											2009-11-14 16:20:18 +00:00
										 |  |  |                 $_caching = SMARTY_CACHING_OFF; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         if (isset($_attr['caching'])) { | 
					
						
							|  |  |  |             if ($_attr['caching'] == 'true') { | 
					
						
							|  |  |  |                 $_caching = SMARTY_CACHING_LIFETIME_CURRENT; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2009-11-18 17:25:18 +00:00
										 |  |  |                 $this->compiler->tag_nocache = true; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |                 $_caching = SMARTY_CACHING_OFF; | 
					
						
							|  |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         // create template object
 | 
					
						
							| 
									
										
										
										
											2009-12-31 16:38:12 +00:00
										 |  |  |         $_output = "<?php \$_template = new {$compiler->smarty->template_class}($include_file, \$_smarty_tpl->smarty, \$_smarty_tpl, \$_smarty_tpl->cache_id, \$_smarty_tpl->compile_id, $_caching, $_cache_lifetime);\n";  | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         // delete {include} standard attributes
 | 
					
						
							| 
									
										
										
										
											2009-12-16 17:05:31 +00:00
										 |  |  |         unset($_attr['file'], $_attr['assign'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']);  | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         // remaining attributes must be assigned as smarty variable
 | 
					
						
							|  |  |  |         if (!empty($_attr)) { | 
					
						
							|  |  |  |             if ($_parent_scope == SMARTY_LOCAL_SCOPE) { | 
					
						
							|  |  |  |                 // create variables
 | 
					
						
							|  |  |  |                 foreach ($_attr as $_key => $_value) { | 
					
						
							|  |  |  |                     $_output .= "\$_template->assign('$_key',$_value);"; | 
					
						
							|  |  |  |                 }  | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $this->compiler->trigger_template_error('variable passing not allowed in parent/global scope'); | 
					
						
							|  |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         // was there an assign attribute
 | 
					
						
							|  |  |  |         if (isset($_assign)) { | 
					
						
							| 
									
										
										
										
											2009-12-17 16:58:44 +00:00
										 |  |  |             $_output .= "\$_smarty_tpl->assign($_assign,\$_template->getRenderedTemplate());?>"; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-11-14 16:20:18 +00:00
										 |  |  |             if ($has_compiled_template && !($compiler->template->caching && ($this->compiler->tag_nocache || $this->compiler->nocache))) { | 
					
						
							| 
									
										
										
										
											2009-12-31 16:38:12 +00:00
										 |  |  |                 $_output .= "\$_template->properties['nocache_hash']  = '{$compiler->template->properties['nocache_hash']}';\n"; | 
					
						
							| 
									
										
										
										
											2009-12-17 16:58:44 +00:00
										 |  |  |                 $_output .= "\$_tpl_stack[] = \$_smarty_tpl; \$_smarty_tpl = \$_template;?>\n"; | 
					
						
							|  |  |  |                 $_output .= $compiled_tpl; | 
					
						
							| 
									
										
										
										
											2010-01-14 20:57:27 +00:00
										 |  |  |                 $_output .= "<?php \$_smarty_tpl->updateParentVariables($_parent_scope);?>\n"; | 
					
						
							|  |  |  |                 $_output .= "<?php /*  End of included template \"" . $tpl->getTemplateFilepath() . "\" */ ?>\n"; | 
					
						
							| 
									
										
										
										
											2009-12-17 16:58:44 +00:00
										 |  |  |                 $_output .= "<?php \$_smarty_tpl = array_pop(\$_tpl_stack);?>"; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2009-12-17 16:58:44 +00:00
										 |  |  |                 $_output .= " echo \$_template->getRenderedTemplate();?>"; | 
					
						
							|  |  |  |                 $_output .= "<?php \$_template->updateParentVariables($_parent_scope);?>"; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2010-01-14 20:57:27 +00:00
										 |  |  |         $_output .= "<?php unset(\$_template);?>\n"; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         return $_output; | 
					
						
							| 
									
										
										
										
											2009-12-27 15:06:49 +00:00
										 |  |  |     }  | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | ?>
 |