<?php
/**
* SmartTemplateDebugger Class
* Used by SmartTemplate Class
*
* @desc Used by SmartTemplate Class
* @author Philipp v. Criegern philipp@criegern.com
* @author Manuel 'EndelWar' Dalla Lana endelwar@aregar.it
* @version 1.2.1 03.07.2006
*
* CVS ID: $Id: class.smarttemplatedebugger.php,v 1.5 2006/07/02 22:17:15 endelwar Exp $
*/
class SmartTemplateDebugger
{
/**
* The template Filename
*
* @access private
*/
var $filename;
/**
* The template itself
*
* @access private
*/
var $template;
/**
* SmartTemplateParser Constructor
*
* @param string $template_filename HTML Template Filename
*/
function SmartTemplateDebugger ( $template_filename )
{
$this->filename = $template_filename;
// Load Template
if ($hd = @fopen($template_filename, "r"))
{
$this->template = fread($hd, filesize($template_filename));
fclose($hd);
}
else
{
$this->template = "SmartTemplate Debugger Error: File not found: '$template_filename'";
}
$this->tab[0] = '';
for ($i=1; $i < 10; $i++) {
$this->tab[$i] = str_repeat(' ', $i);
}
}
/**
* Main Template Parser
*
* @param string $compiled_template_filename Compiled Template Filename
* @desc Creates Compiled PHP Template
*/
function start ( $vars )
{
$page = $this->template;
$page = preg_replace("/(<!-- BEGIN [ a-zA-Z0-9_.]* -->)/", "\n$1\n", $page);
$page = preg_replace("/(<!-- IF .+? -->)/", "\n$1\n", $page);
$page = preg_replace("/(<!-- END.*? -->)/", "\n$1\n", $page);
$page = preg_replace("/(<!-- ELSEIF .+? -->)/", "\n$1\n", $page);
$page = preg_replace("/(<!-- ELSE [ a-zA-Z0-9_.]*-->)/", "\n$1\n", $page);
$page = $this->highlight_html($page);
$rows = explode("\n", $page);
$page_arr = array();
$level = 0;
$blocklvl = 0;
$rowcnt = 0;
$spancnt = 0;
$offset = 22;
$lvl_block = array();
$lvl_row = array();
$lvl_typ = array();
foreach ($rows as $row)
{
if ($row = trim($row))
{
$closespan = false;
if (substr($row, $offset, 12) == '<!-- END ')
{
if ($level < 1)
{
$level++;
$error[$rowcnt] = "END Without BEGIN";
}
elseif ($lvl_typ[$level] != 'BEGIN')
{
$error[$lvl_row[$level]] = "IF without ENDIF";
$error[$rowcnt] = "END Without BEGIN";
}
$blocklvl--;
$level--;
$closespan = true;
}
if (substr($row, $offset, 14) == '<!-- ENDIF ')
{
if ($level < 1)
{
$level++;
$error[$rowcnt] = "ENDIF Without IF";
}
elseif ($lvl_typ[$level] != 'IF')
{
$error[$lvl_row[$level]] = "BEGIN without END";
$error[$rowcnt] = "ENDIF Without IF";
}
$closespan = true;
$level--;
}
if ($closespan)
{
$page_arr[$rowcnt-1] .= '</span>';
}
$this_row = $this->tab[$level] . $row;
if (substr($row, $offset, 12) == '<!-- ELSE')
{
if ($level < 1)
{
$error[$rowcnt] = "ELSE Without IF";
}
elseif ($lvl_typ[$level] != 'IF')
{
$error[$rowcnt] = "ELSE Without IF";
}
else
{
$this_row = $this->tab[$level-1] . $row;
}
}
if (substr($row, $offset, 14) == '<!-- BEGIN ')
{
if ($blocklvl == 0)
{
if ($lp = strpos($row, '-->'))
{
if ($blockname = trim(substr($row, $offset + 14, $lp -$offset -14)))
{
if ($nr = count($vars[$blockname]))
{
$this_row .= $this->toggleview("$nr Entries");
}
else
{
$this_row .= $this->toggleview("Emtpy");
}
}
}
}
else
{
$this_row .= $this->toggleview('[');
}
$blocklvl++;
$level++;
$lvl_row[$level] = $rowcnt;
$lvl_typ[$level] = 'BEGIN';
}
elseif (substr($row, $offset, 11) == '<!-- IF ')
{
$level++;
$lvl_row[$level] = $rowcnt;
$lvl_typ[$level] = 'IF';
$this_row .= $this->toggleview();
}
$page_arr[] = $this_row;
$lvl_block[$rowcnt] = $blocklvl;
$rowcnt++;
}
}
if ($level > 0)
{
$error[$lvl_row[$level]] = "Block not closed";
}
$page = join("\n", $page_arr);
$rows = explode("\n", $page);
$cnt = count($rows);
for ($i = 0; $i < $cnt; $i++)
{
// Add Errortext
if (isset($error))
{
if ($err = $error[$i])
{
$rows[$i] = '<b>' . $rows[$i] . ' ERROR: ' . $err . '!</b>';
}
}
// Replace Scalars
if (preg_match_all('/{([a-zA-Z0-9_. &;]+)}/', $rows[$i], $var))
{
foreach ($var[1] as $tag)
{
$fulltag = $tag;
if ($delim = strpos($tag, ' > '))
{
$tag = substr($tag, 0, $delim);
}
if (substr($tag, 0, 4) == 'top.')
{
$title = $this->tip($vars[substr($tag, 4)]);
}
elseif ($lvl_block[$i] == 0)
{
$title = $this->tip($vars[$tag]);
}
else
{
$title = '[BLOCK?]';
}
$code = '<b title="' . $title . '">{' . $fulltag . '}</b>';
$rows[$i] = str_replace('{'.$fulltag.'}', $code, $rows[$i]);
}
}
// Replace Extensions
if (preg_match_all('/{([a-zA-Z0-9_]+):([^}]*)}/', $rows[$i], $var))
{
foreach ($var[2] as $tmpcnt => $tag)
{
$fulltag = $tag;
if ($delim = strpos($tag, ' > '))
{
$tag = substr($tag, 0, $delim);
}
if (strpos($tag, ','))
{
list($tag, $addparam) = explode(',', $tag, 2);
}
$extension = $var[1][$tmpcnt];
if (substr($tag, 0, 4) == 'top.')
{
$title = $this->tip($vars[substr($tag, 4)]);
}
elseif ($lvl_block[$i] == 0)
{
$title = $this->tip($vars[$tag]);
}
else
{
$title = '[BLOCK?]';
}
$code = '<b title="' . $title . '">{' . $extension . ':' . $fulltag . '}</b>';
$rows[$i] = str_replace('{'.$extension . ':' . $fulltag .'}', $code, $rows[$i]);
}
}
// 'IF nnn' Blocks
if (preg_match_all('/<!-- IF ([a-zA-Z0-9_.]+) -->/', $rows[$i], $var))
{
foreach ($var[1] as $tag)
{
if (substr($tag, 0, 4) == 'top.')
{
$title = $this->tip($vars[substr($tag, 4)]);
}
elseif ($lvl_block[$i] == 0)
{
$title = $this->tip($vars[$tag]);
}
else
{
$title = '[BLOCK?]';
}
$code = '<span title="' . $title . '"><!-- IF ' . $tag . ' --></span>';
$rows[$i] = str_replace("<!-- IF $tag -->", $code, $rows[$i]);
if ($title == '[NULL]')
{
$rows[$i] = str_replace('Hide', 'Show', $rows[$i]);
$rows[$i] = str_replace('block', 'none', $rows[$i]);
}
}
}
}
$page = join("<br>", $rows);
// Print Header
echo '<html><head><script type="text/javascript">
function toggleVisibility(el, src) {
var v = el.style.display == "block";
var str = src.innerHTML;
el.style.display = v ? "none" : "block";
src.innerHTML = v ? str.replace(/Hide/, "Show") : str.replace(/Show/, "Hide");}
</script></head><body>';
// Print Index
echo '<font face="Arial" Size="3"><b>';
echo 'SmartTemplate Debugger<br>';
echo '<font size="2"><li>PHP-Script: ' . $_SERVER['PATH_TRANSLATED'] . '</li><li>Template: ' . $this->filename . '</li></font><hr>';
echo '<li><a href="#template_code">Template</a></li>';
echo '<li><a href="#compiled_code">Compiled Template</a></li>';
echo '<li><a href="#data_code">Data</a></li>';
echo '</b></font><hr>';
// Print Template
echo '<a name="template_code"><br><font face="Arial" Size="3"><b>Template:</b> [<a href="javascr
CrMylive.
- 粉丝: 1w+
- 资源: 4万+
最新资源
- 其实这就是历年摘出来的
- 前端分析-2023071100789
- 前端分析-2023071100789
- 基于卷积神经网络的AV1视频编码环路滤波技术
- 用vb语言编写一个抄底的源代码程序实例_抄底源码-CSDN博客.html
- 2023-04-06-项目笔记 - 第三百五十九阶段 - 4.4.2.357全局变量的作用域-357 -2025.12.26
- 地理遥感图像区域合并分割的大规模高效算法研究
- 2023-04-06-项目笔记 - 第三百五十九阶段 - 4.4.2.357全局变量的作用域-357 -2025.12.26
- EsptouchForAndroid-master.zip
- Javaweb大学专升本系统
- Neck Deep - In Bloom [mqms2].mgg2.flac
- Pyside6(3): 自动生成UI的Qt参数输入对话框demo
- ArcGIS教程(009)所需练习数据
- Hudi安装配置(容器环境)大数据技能竞赛平台搭建父模块pom.xml
- Dialogue System for Unity v2.2.50.1 (22 Nov 2024).unitypackage 对话系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈