| 
									
										
										
										
											2009-03-22 16:09:05 +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
 | 
					
						
							| 
									
										
										
										
											2009-09-23 16:50:16 +00:00
										 |  |  |         $include_file = $_attr['file']; | 
					
						
							|  |  |  |         $has_compiled_template = false; | 
					
						
							| 
									
										
										
										
											2009-10-13 19:44:38 +00:00
										 |  |  |         if ($compiler->smarty->merge_compiled_includes) { | 
					
						
							| 
									
										
										
										
											2009-09-23 16:50:16 +00:00
										 |  |  |             // check if compiled code can be merged
 | 
					
						
							|  |  |  |             if (strpos($include_file, '$_smarty_tpl') === false) { | 
					
						
							| 
									
										
										
										
											2009-10-07 15:52:57 +00:00
										 |  |  |                 eval("\$tmp = $include_file;"); | 
					
						
							|  |  |  |                 $tpl = $compiler->smarty->createTemplate ($tmp, $compiler->template->cache_id, $compiler->template->compile_id, $compiler->template); | 
					
						
							| 
									
										
										
										
											2009-09-23 16:50:16 +00:00
										 |  |  |                 do { | 
					
						
							|  |  |  |                     $must_compile = false; | 
					
						
							|  |  |  |                     $prop = array(); | 
					
						
							|  |  |  |                     $compiled_tpl = $tpl->getCompiledTemplate(); | 
					
						
							| 
									
										
										
										
											2009-10-07 15:52:57 +00:00
										 |  |  |                     preg_match('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>)/', $compiled_tpl, $matches); | 
					
						
							|  |  |  |                     $compiled_tpl = preg_replace(array('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>.*\n)/', '/(\<\?php if\(\!defined\(\'SMARTY_DIR\'\)\))(.*)(\?\>.*\n)/'), '', $compiled_tpl);  | 
					
						
							|  |  |  |                     // var_dump($matches, $compiled_tpl);
 | 
					
						
							| 
									
										
										
										
											2009-09-23 16:50:16 +00:00
										 |  |  |                     if (isset($matches[2])) { | 
					
						
							|  |  |  |                         $prop = unserialize($matches[2]); | 
					
						
							|  |  |  |                         foreach ($prop['file_dependency'] as $_file_to_check) { | 
					
						
							|  |  |  |                             If (is_file($_file_to_check[0])) { | 
					
						
							|  |  |  |                                 $mtime = filemtime($_file_to_check[0]); | 
					
						
							|  |  |  |                             } else { | 
					
						
							|  |  |  |                                 $tpl->parseResourceName($_file_to_check[0], $resource_type, $resource_name, $resource_handler); | 
					
						
							|  |  |  |                                 $mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name); | 
					
						
							|  |  |  |                             }  | 
					
						
							|  |  |  |                             If ($mtime != $_file_to_check[1]) { | 
					
						
							|  |  |  |                                 $must_compile = true; | 
					
						
							|  |  |  |                                 break; | 
					
						
							|  |  |  |                             }  | 
					
						
							|  |  |  |                         }  | 
					
						
							|  |  |  |                         if ($must_compile) { | 
					
						
							|  |  |  |                             // recompile
 | 
					
						
							|  |  |  |                             $tpl->compileTemplateSource(); | 
					
						
							|  |  |  |                         }  | 
					
						
							|  |  |  |                     }  | 
					
						
							|  |  |  |                 } while ($must_compile); | 
					
						
							|  |  |  |                 if (isset($prop['file_dependency'])) { | 
					
						
							|  |  |  |                     $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $prop['file_dependency']); | 
					
						
							|  |  |  |                 }  | 
					
						
							|  |  |  |                 $has_compiled_template = true; | 
					
						
							|  |  |  |             }  | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |         }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         if (isset($_attr['assign'])) { | 
					
						
							|  |  |  |             // output will be stored in a smarty variable instead of beind displayed
 | 
					
						
							|  |  |  |             $_assign = $_attr['assign']; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-07 16:22:31 +00:00
										 |  |  |         $_parent_scope = SMARTY_LOCAL_SCOPE; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         if (isset($_attr['scope'])) { | 
					
						
							|  |  |  |             if ($_attr['scope'] == '\'parent\'') { | 
					
						
							| 
									
										
										
										
											2009-04-07 16:22:31 +00:00
										 |  |  |                 $_parent_scope = SMARTY_PARENT_SCOPE; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             } elseif ($_attr['scope'] == '\'root\'') { | 
					
						
							| 
									
										
										
										
											2009-04-07 16:22:31 +00:00
										 |  |  |                 $_parent_scope = SMARTY_ROOT_SCOPE; | 
					
						
							| 
									
										
										
										
											2009-04-10 12:33:51 +00:00
										 |  |  |             } elseif ($_attr['scope'] == '\'global\'') { | 
					
						
							|  |  |  |                 $_parent_scope = SMARTY_GLOBAL_SCOPE; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-04-26 16:56:17 +00:00
										 |  |  |         // default for included templates
 | 
					
						
							| 
									
										
										
										
											2009-09-23 16:50:16 +00:00
										 |  |  |         if ($compiler->template->caching) { | 
					
						
							|  |  |  |             $_caching = SMARTY_CACHING_LIFETIME_CURRENT; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $_caching = SMARTY_CACHING_OFF; | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +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 | 
					
						
							|  |  |  |         */ | 
					
						
							| 
									
										
										
										
											2009-09-01 21:11:42 +00:00
										 |  |  |         if (isset($_attr['cache_lifetime'])) { | 
					
						
							|  |  |  |             $_cache_lifetime = $_attr['cache_lifetime']; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             $this->compiler->tag_nocache = true; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         if (isset($_attr['nocache'])) { | 
					
						
							|  |  |  |             if ($_attr['nocache'] == 'true') { | 
					
						
							|  |  |  |                 $this->compiler->tag_nocache = true; | 
					
						
							|  |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         if (isset($_attr['caching'])) { | 
					
						
							|  |  |  |             if ($_attr['caching'] == 'true') { | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |                 $_caching = SMARTY_CACHING_LIFETIME_CURRENT; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $_caching = SMARTY_CACHING_OFF; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         // create template object
 | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  |         $_output = "<?php \$_template = new Smarty_Template ($include_file, \$_smarty_tpl->smarty, \$_smarty_tpl, \$_smarty_tpl->cache_id,  \$_smarty_tpl->compile_id);";  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // delete {include} standard attributes
 | 
					
						
							| 
									
										
										
										
											2009-09-01 21:11:42 +00:00
										 |  |  |         unset($_attr['file'], $_attr['assign'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope']);  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // remaining attributes must be assigned as smarty variable
 | 
					
						
							|  |  |  |         if (!empty($_attr)) { | 
					
						
							| 
									
										
										
										
											2009-04-07 16:22:31 +00:00
										 |  |  |             if ($_parent_scope == SMARTY_LOCAL_SCOPE) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 // create variables
 | 
					
						
							|  |  |  |                 foreach ($_attr as $_key => $_value) { | 
					
						
							|  |  |  |                     $_output .= "\$_template->assign('$_key',$_value);"; | 
					
						
							|  |  |  |                 }  | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2009-04-06 02:53:09 +00:00
										 |  |  |                 $this->compiler->trigger_template_error('variable passing not allowed in parent/global scope'); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             }  | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |         // add caching parameter if required
 | 
					
						
							| 
									
										
										
										
											2009-09-01 21:11:42 +00:00
										 |  |  |         if (isset($_cache_lifetime)) { | 
					
						
							|  |  |  |             $_output .= "\$_template->cache_lifetime = $_cache_lifetime;"; | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |             $_caching = SMARTY_CACHING_LIFETIME_CURRENT; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-04-26 16:56:17 +00:00
										 |  |  |         $_output .= "\$_template->caching = $_caching;";  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // was there an assign attribute
 | 
					
						
							|  |  |  |         if (isset($_assign)) { | 
					
						
							| 
									
										
										
										
											2009-10-13 19:44:38 +00:00
										 |  |  |             $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch()); ?>"; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |             if ($has_compiled_template) { | 
					
						
							| 
									
										
										
										
											2009-09-23 16:50:16 +00:00
										 |  |  |                 $_output .= " \$_tpl_stack[] = \$_smarty_tpl; \$_smarty_tpl = \$_template;?>\n"; | 
					
						
							| 
									
										
										
										
											2009-10-17 03:36:47 +00:00
										 |  |  |                 $_output .= $compiled_tpl . "<?php /*  End of included template \"" . $tpl->getTemplateFilepath() . "\" */ ?>"; | 
					
						
							| 
									
										
										
										
											2009-09-23 16:50:16 +00:00
										 |  |  |                 $_output .= "<?php  \$_smarty_tpl = array_pop(\$_tpl_stack);?>"; | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2009-10-13 19:44:38 +00:00
										 |  |  |                 $_output .= " echo \$_template->fetch(); ?>"; | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |             }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-04-14 10:31:02 +00:00
										 |  |  |         if ($_parent_scope != SMARTY_LOCAL_SCOPE) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             $_output .= "<?php \$_template->updateParentVariables($_parent_scope); ?>"; | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-10-13 19:44:38 +00:00
										 |  |  |            $_output .= "<?php unset(\$_template); ?>"; | 
					
						
							|  |  |  |          return $_output; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     }  | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |