mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 01:44:26 +02:00
@@ -6,8 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [5.0.0-rc2] - 2023-11-11
|
### Fixed
|
||||||
|
- The {debug} tag was broken in v5 [#922](https://github.com/smarty-php/smarty/issues/922)
|
||||||
|
|
||||||
|
## [5.0.0-rc2] - 2023-11-11
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Registered output filters wouldn't run [#899](https://github.com/smarty-php/smarty/issues/899)
|
- Registered output filters wouldn't run [#899](https://github.com/smarty-php/smarty/issues/899)
|
||||||
|
@@ -6,16 +6,7 @@ namespace Smarty;
|
|||||||
* Smarty Internal Plugin Debug
|
* Smarty Internal Plugin Debug
|
||||||
* Class to collect data for the Smarty Debugging Console
|
* Class to collect data for the Smarty Debugging Console
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Debug Class
|
|
||||||
*
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class Debug extends Data
|
class Debug extends Data
|
||||||
{
|
{
|
||||||
@@ -24,14 +15,14 @@ class Debug extends Data
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $template_data = array();
|
public $template_data = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of uid's which shall be ignored
|
* List of uid's which shall be ignored
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $ignore_uid = array();
|
public $ignore_uid = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index of display() and fetch() calls
|
* Index of display() and fetch() calls
|
||||||
@@ -50,10 +41,10 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Start logging template
|
* Start logging template
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template template
|
* @param Template $template template
|
||||||
* @param null $mode true: display false: fetch null: subtemplate
|
* @param null $mode true: display false: fetch null: subtemplate
|
||||||
*/
|
*/
|
||||||
public function start_template(\Smarty\Template $template, $mode = null)
|
public function start_template(Template $template, $mode = null)
|
||||||
{
|
{
|
||||||
if (isset($mode) && !$template->_isSubTpl()) {
|
if (isset($mode) && !$template->_isSubTpl()) {
|
||||||
$this->index++;
|
$this->index++;
|
||||||
@@ -67,9 +58,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* End logging of cache time
|
* End logging of cache time
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template cached template
|
* @param Template $template cached template
|
||||||
*/
|
*/
|
||||||
public function end_template(\Smarty\Template $template)
|
public function end_template(Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'total_time' ] +=
|
$this->template_data[ $this->index ][ $key ][ 'total_time' ] +=
|
||||||
@@ -79,9 +70,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Start logging of compile time
|
* Start logging of compile time
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template
|
* @param Template $template
|
||||||
*/
|
*/
|
||||||
public function start_compile(\Smarty\Template $template)
|
public function start_compile(Template $template)
|
||||||
{
|
{
|
||||||
static $_is_stringy = array('string' => true, 'eval' => true);
|
static $_is_stringy = array('string' => true, 'eval' => true);
|
||||||
if (!empty($template->getCompiler()->trace_uid)) {
|
if (!empty($template->getCompiler()->trace_uid)) {
|
||||||
@@ -101,9 +92,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* End logging of compile time
|
* End logging of compile time
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template
|
* @param Template $template
|
||||||
*/
|
*/
|
||||||
public function end_compile(\Smarty\Template $template)
|
public function end_compile(Template $template)
|
||||||
{
|
{
|
||||||
if (!empty($template->getCompiler()->trace_uid)) {
|
if (!empty($template->getCompiler()->trace_uid)) {
|
||||||
$key = $template->getCompiler()->trace_uid;
|
$key = $template->getCompiler()->trace_uid;
|
||||||
@@ -120,9 +111,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Start logging of render time
|
* Start logging of render time
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template
|
* @param Template $template
|
||||||
*/
|
*/
|
||||||
public function start_render(\Smarty\Template $template)
|
public function start_render(Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
|
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
|
||||||
@@ -131,9 +122,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* End logging of compile time
|
* End logging of compile time
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template
|
* @param Template $template
|
||||||
*/
|
*/
|
||||||
public function end_render(\Smarty\Template $template)
|
public function end_render(Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'render_time' ] +=
|
$this->template_data[ $this->index ][ $key ][ 'render_time' ] +=
|
||||||
@@ -143,9 +134,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Start logging of cache time
|
* Start logging of cache time
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template cached template
|
* @param Template $template cached template
|
||||||
*/
|
*/
|
||||||
public function start_cache(\Smarty\Template $template)
|
public function start_cache(Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
|
$this->template_data[ $this->index ][ $key ][ 'start_time' ] = microtime(true);
|
||||||
@@ -154,9 +145,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* End logging of cache time
|
* End logging of cache time
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template cached template
|
* @param Template $template cached template
|
||||||
*/
|
*/
|
||||||
public function end_cache(\Smarty\Template $template)
|
public function end_cache(Template $template)
|
||||||
{
|
{
|
||||||
$key = $this->get_key($template);
|
$key = $this->get_key($template);
|
||||||
$this->template_data[ $this->index ][ $key ][ 'cache_time' ] +=
|
$this->template_data[ $this->index ][ $key ][ 'cache_time' ] +=
|
||||||
@@ -166,9 +157,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Register template object
|
* Register template object
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template cached template
|
* @param Template $template cached template
|
||||||
*/
|
*/
|
||||||
public function register_template(\Smarty\Template $template)
|
public function register_template(Template $template)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,13 +175,13 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Opens a window for the Smarty Debugging Console and display the data
|
* Opens a window for the Smarty Debugging Console and display the data
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template|\Smarty $obj object to debug
|
* @param Template|Smarty $obj object to debug
|
||||||
* @param bool $full
|
* @param bool $full
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @throws \Smarty\Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function display_debug($obj, $full = false)
|
public function display_debug($obj, bool $full = false)
|
||||||
{
|
{
|
||||||
if (!$full) {
|
if (!$full) {
|
||||||
$this->offset++;
|
$this->offset++;
|
||||||
@@ -200,18 +191,18 @@ class Debug extends Data
|
|||||||
$smarty = $obj->getSmarty();
|
$smarty = $obj->getSmarty();
|
||||||
// create fresh instance of smarty for displaying the debug console
|
// create fresh instance of smarty for displaying the debug console
|
||||||
// to avoid problems if the application did overload the Smarty class
|
// to avoid problems if the application did overload the Smarty class
|
||||||
$debObj = new \Smarty\Smarty();
|
$debObj = new Smarty();
|
||||||
// copy the working dirs from application
|
// copy the working dirs from application
|
||||||
$debObj->setCompileDir($smarty->getCompileDir());
|
$debObj->setCompileDir($smarty->getCompileDir());
|
||||||
$debObj->compile_check = \Smarty::COMPILECHECK_ON;
|
$debObj->compile_check = Smarty::COMPILECHECK_ON;
|
||||||
$debObj->security_policy = null;
|
$debObj->security_policy = null;
|
||||||
$debObj->debugging = false;
|
$debObj->debugging = false;
|
||||||
$debObj->debugging_ctrl = 'NONE';
|
$debObj->debugging_ctrl = 'NONE';
|
||||||
$debObj->error_reporting = E_ALL & ~E_NOTICE;
|
$debObj->error_reporting = E_ALL & ~E_NOTICE;
|
||||||
$debObj->debug_tpl = $smarty->debug_tpl ?? 'file:' . __DIR__ . '/../debug.tpl';
|
$debObj->debug_tpl = $smarty->debug_tpl ?? 'file:' . __DIR__ . '/debug.tpl';
|
||||||
$debObj->registered_resources = array();
|
$debObj->registered_resources = array();
|
||||||
$debObj->escape_html = true;
|
$debObj->escape_html = true;
|
||||||
$debObj->caching = \Smarty::CACHING_OFF;
|
$debObj->caching = Smarty::CACHING_OFF;
|
||||||
// prepare information of assigned variables
|
// prepare information of assigned variables
|
||||||
$ptr = $this->get_debug_vars($obj);
|
$ptr = $this->get_debug_vars($obj);
|
||||||
$_assigned_vars = $ptr->tpl_vars;
|
$_assigned_vars = $ptr->tpl_vars;
|
||||||
@@ -223,7 +214,7 @@ class Debug extends Data
|
|||||||
$displayMode = $debugging === 2 || !$full;
|
$displayMode = $debugging === 2 || !$full;
|
||||||
$offset = $this->offset * 50;
|
$offset = $this->offset * 50;
|
||||||
$_template = $debObj->doCreateTemplate($debObj->debug_tpl);
|
$_template = $debObj->doCreateTemplate($debObj->debug_tpl);
|
||||||
if ($obj instanceof \Smarty\Template) {
|
if ($obj instanceof Template) {
|
||||||
$_template->assign('template_name', $templateName);
|
$_template->assign('template_name', $templateName);
|
||||||
} elseif ($obj instanceof Smarty || $full) {
|
} elseif ($obj instanceof Smarty || $full) {
|
||||||
$_template->assign('template_data', $this->template_data[$this->index]);
|
$_template->assign('template_data', $this->template_data[$this->index]);
|
||||||
@@ -298,11 +289,11 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Return key into $template_data for template
|
* Return key into $template_data for template
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template template object
|
* @param Template $template template object
|
||||||
*
|
*
|
||||||
* @return string key into $template_data
|
* @return string key into $template_data
|
||||||
*/
|
*/
|
||||||
private function get_key(\Smarty\Template $template)
|
private function get_key(Template $template)
|
||||||
{
|
{
|
||||||
static $_is_stringy = array('string' => true, 'eval' => true);
|
static $_is_stringy = array('string' => true, 'eval' => true);
|
||||||
|
|
||||||
@@ -319,9 +310,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* Ignore template
|
* Ignore template
|
||||||
*
|
*
|
||||||
* @param \Smarty\Template $template
|
* @param Template $template
|
||||||
*/
|
*/
|
||||||
public function ignore(\Smarty\Template $template)
|
public function ignore(Template $template)
|
||||||
{
|
{
|
||||||
$this->ignore_uid[$template->getSource()->uid] = true;
|
$this->ignore_uid[$template->getSource()->uid] = true;
|
||||||
}
|
}
|
||||||
@@ -329,9 +320,9 @@ class Debug extends Data
|
|||||||
/**
|
/**
|
||||||
* handle 'URL' debugging mode
|
* handle 'URL' debugging mode
|
||||||
*
|
*
|
||||||
* @param \Smarty $smarty
|
* @param Smarty $smarty
|
||||||
*/
|
*/
|
||||||
public function debugUrl(\Smarty $smarty)
|
public function debugUrl(Smarty $smarty)
|
||||||
{
|
{
|
||||||
if (isset($_SERVER[ 'QUERY_STRING' ])) {
|
if (isset($_SERVER[ 'QUERY_STRING' ])) {
|
||||||
$_query_string = $_SERVER[ 'QUERY_STRING' ];
|
$_query_string = $_SERVER[ 'QUERY_STRING' ];
|
||||||
@@ -360,12 +351,12 @@ class Debug extends Data
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $_is_stringy
|
* @param array $_is_stringy
|
||||||
* @param \Smarty\Template $template
|
* @param Template $template
|
||||||
* @param string $key
|
* @param string $key
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function saveTemplateData(array $_is_stringy, \Smarty\Template $template, string $key): void {
|
private function saveTemplateData(array $_is_stringy, Template $template, string $key): void {
|
||||||
if (isset($_is_stringy[$template->getSource()->type])) {
|
if (isset($_is_stringy[$template->getSource()->type])) {
|
||||||
$this->template_data[$this->index][$key]['name'] =
|
$this->template_data[$this->index][$key]['name'] =
|
||||||
'\'' . substr($template->getSource()->name, 0, 25) . '...\'';
|
'\'' . substr($template->getSource()->name, 0, 25) . '...\'';
|
||||||
|
@@ -251,9 +251,10 @@ class Smarty extends \Smarty\TemplateBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* debug mode
|
* debug mode
|
||||||
* Setting this to true enables the debug-console.
|
* Setting this to true enables the debug-console. Setting it to 2 enables individual Debug Console window by
|
||||||
|
* template name.
|
||||||
*
|
*
|
||||||
* @var boolean
|
* @var boolean|int
|
||||||
*/
|
*/
|
||||||
public $debugging = false;
|
public $debugging = false;
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
{capture name='_smarty_debug' assign=debug_output}
|
{capture name='_smarty_debug' assign='debug_output'}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>Smarty {Smarty::SMARTY_VERSION} Debug Console
|
<h1>Smarty {\Smarty\Smarty::SMARTY_VERSION} Debug Console
|
||||||
- {if isset($template_name)}{$template_name|debug_print_var nofilter} {/if}{if !empty($template_data)}Total Time {$execution_time|string_format:"%.5f"}{/if}</h1>
|
- {if isset($template_name)}{$template_name|debug_print_var nofilter} {/if}{if !empty($template_data)}Total Time {$execution_time|string_format:"%.5f"}{/if}</h1>
|
||||||
|
|
||||||
{if !empty($template_data)}
|
{if !empty($template_data)}
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{/capture}
|
{/capture}
|
||||||
<script type="text/javascript">
|
<script>
|
||||||
_smarty_console = window.open("", "console{$targetWindow}", "width=1024,height=600,left={$offset},top={$offset},resizable,scrollbars=yes");
|
_smarty_console = window.open("", "console{$targetWindow}", "width=1024,height=600,left={$offset},top={$offset},resizable,scrollbars=yes");
|
||||||
_smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}");
|
_smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}");
|
||||||
_smarty_console.document.close();
|
_smarty_console.document.close();
|
||||||
|
22
tests/UnitTests/TemplateSource/TagTests/Debug/DebugTest.php
Normal file
22
tests/UnitTests/TemplateSource/TagTests/Debug/DebugTest.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace UnitTests\TemplateSource\TagTests\Debug;
|
||||||
|
use PHPUnit_Smarty;
|
||||||
|
use Smarty\Smarty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty PHPunit tests of {debug} tag
|
||||||
|
*/
|
||||||
|
class PluginModifierStripTagsTest extends PHPUnit_Smarty {
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
$this->setUpSmarty(__DIR__);
|
||||||
|
}
|
||||||
|
public function testDefault() {
|
||||||
|
$tpl = $this->smarty->createTemplate('eval:{debug}');
|
||||||
|
$output = $this->smarty->fetch($tpl);
|
||||||
|
$this->assertStringContainsString("<script", $output);
|
||||||
|
$this->assertStringContainsString("</script>", $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user