| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Smarty Internal Plugin Compile extend | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * Compiles the {extend} tag | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * @package Smarty | 
					
						
							|  |  |  | * @subpackage Compiler | 
					
						
							|  |  |  | * @author Uwe Tews  | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Smarty Internal Plugin Compile extend Class | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | class Smarty_Internal_Compile_Extend extends Smarty_Internal_CompileBase { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * Compiles code for the {extend} 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; | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |         $this->smarty =$compiler->smarty; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $this->required_attributes = array('file');  | 
					
						
							|  |  |  |         // check and get attributes
 | 
					
						
							|  |  |  |         $_attr = $this->_get_attributes($args); | 
					
						
							| 
									
										
										
										
											2009-04-12 05:40:30 +00:00
										 |  |  |         $_smarty_tpl = $compiler->template;  | 
					
						
							| 
									
										
										
										
											2009-04-12 02:30:54 +00:00
										 |  |  |         // $include_file = '';
 | 
					
						
							|  |  |  |         eval('$include_file = ' . $_attr['file'] . ';');  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // create template object
 | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |         $_template = new Smarty_Template ($include_file, $this->smarty, $compiler->template);  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // save file dependency
 | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |         $compiler->template->properties['file_dependency']['F'.abs(crc32($_template->getTemplateFilepath()))] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp()); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $_old_source = $compiler->template->template_source; | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |         if (preg_match_all('/(' . $this->smarty->left_delimiter . 'block(.+?)' . $this->smarty->right_delimiter . ')/', $_old_source, $s, PREG_OFFSET_CAPTURE) != | 
					
						
							|  |  |  |                 preg_match_all('/(' . $this->smarty->left_delimiter . '\/block(.*?)' . $this->smarty->right_delimiter . ')/', $_old_source, $c, PREG_OFFSET_CAPTURE)) { | 
					
						
							| 
									
										
										
										
											2009-07-20 15:38:11 +00:00
										 |  |  |             $this->compiler->trigger_template_error(" unmatched {block} {/block} pairs"); | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-09-10 23:08:06 +00:00
										 |  |  |         $block_count = count($s[0]); | 
					
						
							|  |  |  |         for ($i = 0; $i < $block_count; $i++) { | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |             $block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%', | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |                 substr($_old_source, $s[0][$i][1] + strlen($s[0][$i][0]), $c[0][$i][1] - $s[0][$i][1] - strlen($s[0][$i][0]))); | 
					
						
							| 
									
										
										
										
											2009-09-10 23:08:06 +00:00
										 |  |  |             $this->saveBlockData($block_content, $s[0][$i][0]); | 
					
						
							|  |  |  |         }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $compiler->template->template_source = $_template->getTemplateSource(); | 
					
						
							|  |  |  |         $compiler->abort_and_recompile = true; | 
					
						
							|  |  |  |         return ' '; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-10 23:08:06 +00:00
										 |  |  |     protected function saveBlockData($block_content, $block_tag) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-09-10 23:08:06 +00:00
										 |  |  |         if (0 == preg_match('/(.?)(name=)([^ ]*)/', $block_tag, $_match)) { | 
					
						
							|  |  |  |             $this->compiler->trigger_template_error("\"" . $block_tag . "\" missing name attribute"); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-04-12 02:30:54 +00:00
										 |  |  |             // compile block content
 | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |             $_tpl = $this->smarty->createTemplate('string:' . $block_content); | 
					
						
							| 
									
										
										
										
											2009-07-21 16:26:11 +00:00
										 |  |  |             $_tpl->template_filepath = $this->compiler->template->getTemplateFilepath(); | 
					
						
							| 
									
										
										
										
											2009-04-29 17:56:56 +00:00
										 |  |  |             $_tpl->suppressHeader = true; | 
					
						
							|  |  |  |             $_compiled_content = $_tpl->getCompiledTemplate(); | 
					
						
							|  |  |  |             unset($_tpl); | 
					
						
							| 
									
										
										
										
											2009-09-10 23:08:06 +00:00
										 |  |  |             $_name = trim($_match[3], "\"'}"); | 
					
						
							| 
									
										
										
										
											2009-04-12 02:30:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |             if (isset($this->smarty->block_data[$_name])) { | 
					
						
							|  |  |  |                 if (strpos($this->smarty->block_data[$_name]['compiled'], '%%%%SMARTY_PARENT%%%%') !== false) { | 
					
						
							|  |  |  |                     $this->smarty->block_data[$_name]['compiled'] = | 
					
						
							|  |  |  |                     str_replace('%%%%SMARTY_PARENT%%%%', $_compiled_content, $this->smarty->block_data[$_name]['compiled']); | 
					
						
							|  |  |  |                 } elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') { | 
					
						
							|  |  |  |                     $this->smarty->block_data[$_name]['compiled'] .= $_compiled_content; | 
					
						
							|  |  |  |                 } elseif ($this->smarty->block_data[$_name]['mode'] == 'append') { | 
					
						
							|  |  |  |                     $this->smarty->block_data[$_name]['compiled'] = $_compiled_content . $this->smarty->block_data[$_name]['compiled']; | 
					
						
							| 
									
										
										
										
											2009-04-12 22:26:02 +00:00
										 |  |  |                 }  | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |                 $this->smarty->block_data[$_name]['compiled'] = $_compiled_content; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             }  | 
					
						
							| 
									
										
										
										
											2009-09-10 23:08:06 +00:00
										 |  |  |             if (preg_match('/(.?)(append=true)(.*)/', $block_tag, $_match) != 0) { | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |                 $this->smarty->block_data[$_name]['mode'] = 'append'; | 
					
						
							| 
									
										
										
										
											2009-09-10 23:08:06 +00:00
										 |  |  |             } elseif (preg_match('/(.?)(prepend=true)(.*)/', $block_tag, $_match) != 0) { | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |                 $this->smarty->block_data[$_name]['mode'] = 'prepend'; | 
					
						
							| 
									
										
										
										
											2009-04-12 22:26:02 +00:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2009-10-12 14:37:31 +00:00
										 |  |  |                 $this->smarty->block_data[$_name]['mode'] = 'replace'; | 
					
						
							| 
									
										
										
										
											2009-04-12 22:26:02 +00:00
										 |  |  |             }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         }  | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |