| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Smarty Internal Plugin Debug | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * Class to collect data for the Smarty Debugging Consol | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * @package Smarty | 
					
						
							|  |  |  | * @subpackage Debug | 
					
						
							|  |  |  | * @author Uwe Tews  | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Smarty Internal Plugin Debug Class | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | class Smarty_Internal_Debug extends Smarty_Internal_TemplateBase { | 
					
						
							| 
									
										
										
										
											2009-11-11 22:09:06 +00:00
										 |  |  |     // template data
 | 
					
						
							|  |  |  |     static $template_data = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * Start logging of compile time | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     public static function start_compile($template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $key = self::get_key($template); | 
					
						
							|  |  |  |         self::$template_data[$key]['start_time'] = self::get_time(); | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * End logging of compile time | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     public static function end_compile($template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $key = self::get_key($template); | 
					
						
							|  |  |  |         self::$template_data[$key]['compile_time'] = self::get_time() - self::$template_data[$key]['start_time']; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * Start logging of render time | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     public static function start_render($template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $key = self::get_key($template); | 
					
						
							|  |  |  |         self::$template_data[$key]['start_time'] = self::get_time(); | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * End logging of compile time | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     public static function end_render($template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $key = self::get_key($template); | 
					
						
							|  |  |  |         self::$template_data[$key]['render_time'] = self::get_time() - self::$template_data[$key]['start_time']; | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * Start logging of cache time | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     public static function start_cache($template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $key = self::get_key($template); | 
					
						
							|  |  |  |         self::$template_data[$key]['start_time'] = self::get_time(); | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * End logging of cache time | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     public static function end_cache($template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $key = self::get_key($template); | 
					
						
							|  |  |  |         self::$template_data[$key]['cache_time'] = self::get_time() - self::$template_data[$key]['start_time']; | 
					
						
							|  |  |  |     }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |     * Opens a window for the Smarty Debugging Consol and display the data | 
					
						
							|  |  |  |     */ | 
					
						
							| 
									
										
										
										
											2009-09-19 13:22:32 +00:00
										 |  |  |     public static function display_debug($smarty) | 
					
						
							| 
									
										
										
										
											2009-11-11 22:09:06 +00:00
										 |  |  |     {  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // prepare information of assigned variables
 | 
					
						
							| 
									
										
										
										
											2009-05-05 17:19:33 +00:00
										 |  |  |         $_assigned_vars = $smarty->tpl_vars; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         ksort($_assigned_vars); | 
					
						
							| 
									
										
										
										
											2009-05-05 17:19:33 +00:00
										 |  |  |         $_config_vars = $smarty->config_vars; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         ksort($_config_vars); | 
					
						
							| 
									
										
										
										
											2009-08-08 17:28:23 +00:00
										 |  |  |         $_template = new Smarty_Template ($smarty->debug_tpl, $smarty); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $_template->caching = false; | 
					
						
							|  |  |  |         $_template->force_compile = false; | 
					
						
							|  |  |  |         $_template->security = false; | 
					
						
							| 
									
										
										
										
											2009-11-11 22:09:06 +00:00
										 |  |  |         $_template->assign('template_data', self::$template_data); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $_template->assign('assigned_vars', $_assigned_vars); | 
					
						
							|  |  |  |         $_template->assign('config_vars', $_config_vars); | 
					
						
							| 
									
										
										
										
											2009-05-05 17:19:33 +00:00
										 |  |  |         $_template->assign('execution_time', $smarty->_get_time() - $smarty->start_time); | 
					
						
							|  |  |  |         echo $smarty->fetch($_template); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     }  | 
					
						
							| 
									
										
										
										
											2009-11-11 22:09:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * get_key | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     static function get_key($template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $key = 'F' . abs(crc32($template->getTemplateFilepath())); | 
					
						
							|  |  |  |         if (isset(self::$template_data[$key])) { | 
					
						
							|  |  |  |             return $key; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             self::$template_data[$key]['name'] = $template->getTemplateFilepath(); | 
					
						
							|  |  |  |             self::$template_data[$key]['compile_time'] = 0; | 
					
						
							|  |  |  |             self::$template_data[$key]['render_time'] = 0; | 
					
						
							|  |  |  |             self::$template_data[$key]['cache_time'] = 0; | 
					
						
							|  |  |  |             return $key; | 
					
						
							|  |  |  |         }  | 
					
						
							|  |  |  |     }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |     * return current time | 
					
						
							|  |  |  |     *  | 
					
						
							|  |  |  |     * @returns double current time | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  |     static function get_time() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $_mtime = microtime(); | 
					
						
							|  |  |  |         $_mtime = explode(" ", $_mtime); | 
					
						
							|  |  |  |         return (double)($_mtime[1]) + (double)($_mtime[0]); | 
					
						
							|  |  |  |     }  | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |