MODX Revolution PHP Cross Reference Content Management Systems

Source: /core/model/smarty/sysplugins/smarty_internal_debug.php - 133 lines - 3900 bytes - Summary - Text - Print

Description: Smarty Internal Plugin Debug Class to collect data for the Smarty Debugging Consol

   1  <?php
   2  
   3  /**
   4   * Smarty Internal Plugin Debug
   5   * 
   6   * Class to collect data for the Smarty Debugging Consol
   7   * 
   8   * @package Smarty
   9   * @subpackage Debug
  10   * @author Uwe Tews 
  11   */
  12  
  13  /**
  14   * Smarty Internal Plugin Debug Class
  15   */
  16  class Smarty_Internal_Debug extends Smarty_Internal_Data {
  17      // template data
  18      static $template_data = array();
  19  
  20      /**
  21       * Start logging of compile time
  22       */
  23      public static function start_compile($template)
  24      {
  25          $key = self::get_key($template);
  26          self::$template_data[$key]['start_time'] = microtime(true);
  27      } 
  28  
  29      /**
  30       * End logging of compile time
  31       */
  32      public static function end_compile($template)
  33      {
  34          $key = self::get_key($template);
  35          self::$template_data[$key]['compile_time'] += microtime(true) - self::$template_data[$key]['start_time'];
  36      } 
  37  
  38      /**
  39       * Start logging of render time
  40       */
  41      public static function start_render($template)
  42      {
  43          $key = self::get_key($template);
  44          self::$template_data[$key]['start_time'] = microtime(true);
  45      } 
  46  
  47      /**
  48       * End logging of compile time
  49       */
  50      public static function end_render($template)
  51      {
  52          $key = self::get_key($template);
  53          self::$template_data[$key]['render_time'] += microtime(true) - self::$template_data[$key]['start_time'];
  54      } 
  55  
  56      /**
  57       * Start logging of cache time
  58       */
  59      public static function start_cache($template)
  60      {
  61          $key = self::get_key($template);
  62          self::$template_data[$key]['start_time'] = microtime(true);
  63      } 
  64  
  65      /**
  66       * End logging of cache time
  67       */
  68      public static function end_cache($template)
  69      {
  70          $key = self::get_key($template);
  71          self::$template_data[$key]['cache_time'] += microtime(true) - self::$template_data[$key]['start_time'];
  72      } 
  73      /**
  74       * Opens a window for the Smarty Debugging Consol and display the data
  75       */
  76      public static function display_debug($obj)
  77      { 
  78          // prepare information of assigned variables
  79          $ptr = $obj;
  80          while (isset($ptr->parent)) {
  81              $ptr = $ptr->parent;
  82          }
  83          if ($obj instanceof Smarty) {
  84              $smarty = $obj;
  85          } else {
  86                 $smarty = $obj->smarty;
  87           }            
  88          $_assigned_vars = $ptr->tpl_vars;
  89          ksort($_assigned_vars);
  90          $_config_vars = $ptr->config_vars;
  91          ksort($_config_vars);
  92          $ldelim = $smarty->left_delimiter;
  93          $rdelim = $smarty->right_delimiter;
  94          $smarty->left_delimiter = '{';
  95          $smarty->right_delimiter = '}';
  96          $_template = new Smarty_Internal_Template ($smarty->debug_tpl, $smarty);
  97          $_template->caching = false;
  98          $_template->force_compile = false;
  99          $_template->disableSecurity();
 100          $_template->cache_id = null;
 101          $_template->compile_id = null;
 102          $_template->assign('template_data', self::$template_data);
 103          $_template->assign('assigned_vars', $_assigned_vars);
 104          $_template->assign('config_vars', $_config_vars);
 105          $_template->assign('execution_time', microtime(true) - $smarty->start_time);
 106          echo $smarty->fetch($_template);
 107          $smarty->left_delimiter = $ldelim;
 108          $smarty->right_delimiter = $rdelim;
 109      } 
 110  
 111      /**
 112       * get_key
 113       */
 114      static function get_key($template)
 115      { 
 116          // calculate Uid if not already done
 117          if ($template->templateUid == '') {
 118              $template->getTemplateFilepath();
 119          } 
 120          $key = $template->templateUid;
 121          if (isset(self::$template_data[$key])) {
 122              return $key;
 123          } else {
 124              self::$template_data[$key]['name'] = $template->getTemplateFilepath();
 125              self::$template_data[$key]['compile_time'] = 0;
 126              self::$template_data[$key]['render_time'] = 0;
 127              self::$template_data[$key]['cache_time'] = 0;
 128              return $key;
 129          } 
 130      } 
 131  } 
 132  
 133  ?>

title

Description

title

Description

title

Description

title

title

Body