| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty plugin | 
					
						
							|  |  |  |  * @package Smarty | 
					
						
							|  |  |  |  * @subpackage plugins | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Extract non-cacheable parts out of compiled template and write it | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param string $compile_path | 
					
						
							|  |  |  |  * @param string $template_compiled | 
					
						
							|  |  |  |  * @return boolean | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2003-10-11 08:55:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-22 03:13:25 +00:00
										 |  |  | function smarty_core_write_compiled_include($params, &$smarty) | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-29 15:20:27 +00:00
										 |  |  |     $_tag_start = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; \};'; | 
					
						
							|  |  |  |     $_tag_end   = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\'; \};'; | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-11 08:55:53 +00:00
										 |  |  |     preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us', | 
					
						
							| 
									
										
										
										
											2003-06-21 09:24:44 +00:00
										 |  |  |                    $params['compiled_content'], $_match_source, PREG_SET_ORDER); | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // no nocache-parts found: done
 | 
					
						
							|  |  |  |     if (count($_match_source)==0) return; | 
					
						
							| 
									
										
										
										
											2003-10-11 08:55:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  |     // convert the matched php-code to functions
 | 
					
						
							| 
									
										
										
										
											2004-10-01 15:26:44 +00:00
										 |  |  |     $_include_compiled =  "<?php /* Smarty version ".$smarty->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; | 
					
						
							|  |  |  |     $_include_compiled .= "         compiled from " . strtr(urlencode($params['resource_name']), array('%2F'=>'/', '%3A'=>':')) . " */\n\n"; | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $_compile_path = $params['include_file_path']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-23 16:16:58 +00:00
										 |  |  |     $smarty->_cache_serials[$_compile_path] = $params['cache_serial']; | 
					
						
							| 
									
										
										
										
											2003-06-22 22:10:10 +00:00
										 |  |  |     $_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>"; | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $_include_compiled .= $params['plugins_code']; | 
					
						
							| 
									
										
										
										
											2003-07-17 19:22:47 +00:00
										 |  |  |     $_include_compiled .= "<?php"; | 
					
						
							| 
									
										
										
										
											2004-04-15 15:06:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $this_varname = ((double)phpversion() >= 5.0) ? '_smarty' : 'this'; | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  |     for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) { | 
					
						
							|  |  |  |         $_match =& $_match_source[$_i]; | 
					
						
							| 
									
										
										
										
											2004-04-15 15:06:09 +00:00
										 |  |  |         $source = $_match[4]; | 
					
						
							|  |  |  |         if ($this_varname == '_smarty') { | 
					
						
							|  |  |  |             /* rename $this to $_smarty in the sourcecode */ | 
					
						
							|  |  |  |             $tokens = token_get_all('<?php ' . $_match[4]); | 
					
						
							| 
									
										
										
										
											2005-01-27 08:51:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             /* remove trailing <?php */ | 
					
						
							|  |  |  |             $open_tag = ''; | 
					
						
							|  |  |  |             while ($tokens) { | 
					
						
							|  |  |  |                 $token = array_shift($tokens); | 
					
						
							|  |  |  |                 if (is_array($token)) { | 
					
						
							|  |  |  |                     $open_tag .= $token[1]; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $open_tag .= $token; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if ($open_tag == '<?php ') break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-15 15:06:09 +00:00
										 |  |  |             for ($i=0, $count = count($tokens); $i < $count; $i++) { | 
					
						
							|  |  |  |                 if (is_array($tokens[$i])) { | 
					
						
							|  |  |  |                     if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') { | 
					
						
							|  |  |  |                         $tokens[$i] = '$' . $this_varname; | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         $tokens[$i] = $tokens[$i][1]; | 
					
						
							|  |  |  |                     }                    | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $source = implode('', $tokens); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* add function to compiled include */ | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  |         $_include_compiled .= "
 | 
					
						
							| 
									
										
										
										
											2004-04-15 15:06:09 +00:00
										 |  |  | function _smarty_tplfunc_$_match[2]_$_match[3](&\$$this_varname) | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-04-15 15:06:09 +00:00
										 |  |  | $source | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ";
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $_include_compiled .= "\n\n?>\n"; | 
					
						
							| 
									
										
										
										
											2003-10-11 08:55:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $_params = array('filename' => $_compile_path, | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  |                      'contents' => $_include_compiled, 'create_dirs' => true); | 
					
						
							| 
									
										
										
										
											2003-10-11 08:55:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-16 23:07:32 +00:00
										 |  |  |     require_once(SMARTY_CORE_DIR . 'core.write_file.php'); | 
					
						
							| 
									
										
										
										
											2003-06-22 03:13:25 +00:00
										 |  |  |     smarty_core_write_file($_params, $smarty); | 
					
						
							| 
									
										
										
										
											2003-10-11 08:55:53 +00:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2003-06-18 23:01:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |