| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605 |
- <?php
- /* vim: set expandtab tabstop=4 shiftwidth=4: */
- // +----------------------------------------------------------------------+
- // | PHP version 4.3.x (and higher), tested with 5.1.4 |
- // +----------------------------------------------------------------------+
- // | Copyright (c) 2002-2006 Kelvin Jones, Claus van Beek, Stefan Deussen |
- // +----------------------------------------------------------------------+
- // | Authors: Kelvin Jones, Claus van Beek, Stefan Deussen |
- // +----------------------------------------------------------------------+
- //
- // $Id: debug.php 3041 2007-05-22 19:19:55Z b4rt $
- /**
- * Class uses all of vlibTemplate's functionality but debugs the template files.
- * Outputs a debug console to an html page, only use this for html files.
- *
- * NB: This class is not as well documented as the main vlibTemplate class as all
- * functions are private. This will be cleaned up in the future but it's quite
- * far down the priority list. It works, and right now, that's what counts.
- *
- * @author Kelvin Jones, Claus van Beek, Stefan Deussen
- * @since 21/01/2002
- * @package vLIB
- * @access public
- */
- class vlibTemplateDebug extends vlibTemplate {
- /*-----------------------------------------------------------------------------\
- | DO NOT TOUCH ANYTHING IN THIS CLASS IT MAY NOT WORK OTHERWISE |
- \-----------------------------------------------------------------------------*/
- var $VLIBTEMPLATE_DEBUGMOD = './vlibTemplate/vlibTemplate_debugmod.html';
- var $VLIBTEMPLATE_DEBUGWRAPPER = './vlibTemplate/vlibTemplate_debugmodwrapper.html';
- // 2006-08-12, SD: new option 'DEBUG_WITHOUT_JAVASCRIPT'
- var $VLIBTEMPLATE_DEBUGMOD_NO_JAVASCRIPT = './vlibTemplate/vlibTemplate_debugmod_no_javascript.html';
- var $VLIBTEMPLATE_DEBUGWRAPPER_NO_JAVASCRIPT = './vlibTemplate/vlibTemplate_debugmodwrapper_no_javascript.html';
- /**
- * boolean var prints out vlibTemplate debug module
- * @see $_tmplfilep
- */
- var $_debug = 1;
- var $_debugIncludedfiles = array();
- var $_debugTemplatevars = array();
- var $_debugalltags = array();
- var $_debugtags = array();
- var $_debugwarnings = array();
- var $_debugwarningmsgscontrol = array();
- var $_debugwarningmsgs = array();
- /**
- * Builds entire debug module window
- * prints it by default.
- *
- * @access private
- */
- function doDebug() {
- // 2006-08-12, SD: new option 'DEBUG_WITHOUT_JAVASCRIPT'
- if($this->OPTIONS['DEBUG_WITHOUT_JAVASCRIPT'])
- {
- $vLIBtmpl = new vlibTemplate ($this->VLIBTEMPLATE_DEBUGMOD_NO_JAVASCRIPT);
- }
- else
- {
- $vLIBtmpl = new vlibTemplate ($this->VLIBTEMPLATE_DEBUGMOD);
- }
- // set vars needed for JavaScript in popup window
- $filename_enc = md5($this->_tmplfilename);
- $vLIBtmpl->setvar('vLIB_template_name', $this->_tmplfilename);
- $vLIBtmpl->setvar('filename_enc', $filename_enc);
- // grab the vars and loops array
- ob_start();
- print_r($this->_arrvars);
- $vLIB_allarrvars = ob_get_contents();
- ob_end_clean();
- ob_start();
- print_r($this->_vars);
- $vLIB_allvars = ob_get_contents();
- ob_end_clean();
- $vLIBtmpl->setvar('vLIB_allarrvars', wordwrap($vLIB_allarrvars, 70, "\n", 1));
- $vLIBtmpl->setvar('vLIB_allvars', wordwrap($vLIB_allvars, 70, "\n", 1));
- $vLIBtmpl->setvar('vLIB_num_global_vars', (count($this->_vars)) ? count($this->_vars) : '0');
- $vLIBtmpl->setvar('vLIB_num_top_level_loops', (count($this->_arrvars)) ? count($this->_arrvars) : '0');
- // get all files included using <tmpl_include>
- $incdpaths = "";
- foreach($this->_debugIncludedfiles as $v) {
- $incdpaths .= $v.'<br>';
- }
- // get the Options and some other stuff
- $params = array('vlibTemplate Root' => $this->VLIBTEMPLATE_ROOT);
- foreach ($this->OPTIONS as $option => $value) {
- (empty($value)) and $value = '<i>null</i>';
- (is_array($value)) and $value = join('<br>', $value);
- $params[$option] = $value;
- }
- $paramsarr = array();
- foreach($params as $k => $v) {
- array_push($paramsarr, array(
- 'param_name' => $k,
- 'param_value' => $v
- ));
- }
- $vLIBtmpl->setloop('vLIB_list_params', $paramsarr);
- // template vars and stuff
- $filesarr = array();
- if (!is_array($this->_debugTemplatevars['include'])) $this->_debugTemplatevars['include'] = array();
- foreach($this->_debugTemplatevars['include'] as $v) {
- array_push($filesarr, array(
- 'filename' => $v
- ));
- }
- $vLIBtmpl->setloop('vLIB_include_files', $filesarr);
- $varsarr = array();
- if (!is_array($this->_debugTemplatevars['var'])) $this->_debugTemplatevars['var'] = array();
- foreach($this->_debugTemplatevars['var'] as $v) {
- array_push($varsarr, array(
- 'varname' => $v
- ));
- }
- $vLIBtmpl->setloop('vLIB_vars', $varsarr);
- $ifsarr = array();
- if (!is_array($this->_debugTemplatevars['if'])) $this->_debugTemplatevars['if'] = array();
- foreach($this->_debugTemplatevars['if'] as $v) {
- array_push($ifsarr, array(
- 'ifname' => $v
- ));
- }
- $vLIBtmpl->setloop('vLIB_ifs', $ifsarr);
- $elseifsarr = array();
- if (!is_array($this->_debugTemplatevars['elseif'])) $this->_debugTemplatevars['elseif'] = array();
- foreach($this->_debugTemplatevars['elseif'] as $v) {
- array_push($elseifsarr, array(
- 'elseifname' => $v
- ));
- }
- $vLIBtmpl->setloop('vLIB_elseifs', $elseifsarr);
- $unlessarr = array();
- if (!is_array($this->_debugTemplatevars['unless'])) $this->_debugTemplatevars['unless'] = array();
- foreach($this->_debugTemplatevars['unless'] as $v) {
- array_push($unlessarr, array(
- 'unlessname' => $v
- ));
- }
- $vLIBtmpl->setloop('vLIB_unless', $unlessarr);
- $loopsarr = array();
- if (!is_array($this->_debugTemplatevars['loop'])) $this->_debugTemplatevars['loop'] = array();
- foreach($this->_debugTemplatevars['loop'] as $v) {
- array_push($loopsarr, array(
- 'loopname' => $v
- ));
- }
- $vLIBtmpl->setloop('vLIB_loops', $loopsarr);
- $varsarr = array();
- foreach($this->_vars as $k => $v) {
- array_push($varsarr, array(
- 'varname' => $k
- ));
- }
- $vLIBtmpl->setloop('vLIB_tmplvars', $varsarr);
- $loopsarr = array();
- $loopst = array_keys($this->_arrvars);
- foreach ($loopst as $v) {
- array_push($loopsarr, array(
- 'loopname' => $v
- ));
- }
- $vLIBtmpl->setloop('vLIB_tmplloops', $loopsarr);
- $this->doDebugParse(); // does real debugging
- $warningsarr = array();
- if (count($this->_debugwarningmsgs) > 0) $vLIBtmpl->setvar('warnings', 1);
- foreach($this->_debugwarningmsgs as $v) {
- $vals = array_values($v);
- list($problem, $detail, $location) = $vals;
- array_push($warningsarr, array(
- 'problem' => $problem,
- 'detail' => $detail,
- 'location'=> $location
- ));
- }
- $vLIBtmpl->setloop('vLIB_warnings', $warningsarr);
- // finally grab and echo in JS formatted way
- $output = $vLIBtmpl->grab();
- // 2006-08-12, SD: new option 'DEBUG_WITHOUT_JAVASCRIPT'
- if($this->OPTIONS['DEBUG_WITHOUT_JAVASCRIPT'])
- {
- $wrapper_tmpl = new vlibTemplate($this->VLIBTEMPLATE_DEBUGWRAPPER_NO_JAVASCRIPT);
- }
- else
- {
- $wrapper_tmpl = new vlibTemplate($this->VLIBTEMPLATE_DEBUGWRAPPER);
- }
- $filename = $this->_tmplfilename;
- $filename = str_replace('\\', "\\\\", $filename);
- $filename = str_replace('\'', "\\'", $filename);
- $filename = str_replace("\r", '', $filename);
- $filename = str_replace("\n", "\\n", $filename);
- $filename = str_replace("\t", "\\t", $filename);
- $wrapper_tmpl->setVar('filename', $filename);
- $wrapper_tmpl->setvar('filename_enc', $filename_enc);
- $wrapper_tmpl->setvar('securecode', md5(time()));
- // 2006-08-12, SD: new option 'DEBUG_WITHOUT_JAVASCRIPT'
- if($this->OPTIONS['DEBUG_WITHOUT_JAVASCRIPT'])
- {
- $wrapper_tmpl->setVar('debug_content', $output);
- }
- else
- {
- $wrapper_tmpl->setVar('debug_content', $this->enjavanate($output, 120));
- }
- $wrapper_tmpl->pparse();
- }
- /**
- * rearranges all vars from below regex
- *
- *
- */
- function arrangeTags ($arr) {
- $temparr = array();
- $temparr['tag'] = $arr['tag'];
- $temparr['openclose'] = $arr['openclose'];
- $temparr['file'] = $arr['file'];
- $temparr['line'] = $arr['line'];
- $temparr['entire_tag'] = $arr['entire_tag'];
- for($i=1; $i < 4; $i++) {
- if (empty($arr['paramname'.$i]) && empty($arr['paramval'.$i])) break;
- (empty($arr['paramname'.$i])) ? $key = 'name' : $key = strtolower($arr['paramname'.$i]);
- $temparr[$key] = trim($arr['paramval'.$i]);
- }
- array_push($this->_debugalltags, $temparr);
- }
- /**
- * parses the template files
- *
- * @param array $data data of files line by line
- * @param string $filename name of current template file
- * @access private
- */
- function doDebugWarnings ($data, $filename) {
- $regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s*';
- $regex.= '(?:tmpl_)?';
- $regex.= '(var|if|elseif|else|endif|unless|endunless|loop|endloop|include|phpinclude|comment|endcomment)\s*';
- $regex.= '(?:';
- $regex.= '(?:';
- $regex.= '(name|format|escape|op|value)';
- $regex.= '\s*=\s*';
- $regex.= ')?';
- $regex.= '(?:[\"\'])?';
- $regex.= '((?<=[\"\'])';
- $regex.= '[^\"\']*|[a-z0-9_\.]*)';
- $regex.= '[\"\']?';
- $regex.= ')?\s*';
- $regex.= '(?:';
- $regex.= '(?:';
- $regex.= '(name|format|escape|op|value)';
- $regex.= '\s*=\s*';
- $regex.= ')';
- $regex.= '(?:[\"\'])?';
- $regex.= '((?<=[\"\'])';
- $regex.= '[^\"\']*|[a-z0-9_\.]*)';
- $regex.= '[\"\']?';
- $regex.= ')?\s*';
- $regex.= '(?:';
- $regex.= '(?:';
- $regex.= '(name|format|escape|op|value)';
- $regex.= '\s*=\s*';
- $regex.= ')';
- $regex.= '(?:[\"\'])?';
- $regex.= '((?<=[\"\'])';
- $regex.= '[^\"\']*|[a-z0-9_\.]*)';
- $regex.= '[\"\']?';
- $regex.= ')?\s*';
- $regex.= '(?:>|\/>|}|-->){1}';
- $regex.= '/ie';
- for ($i = 0; $i < count($data); $i++) {
- $file = preg_replace(
- $regex,
- "\$this->arrangeTags(array(
- 'tag' => strtolower('\\2'),
- 'paramname1' => strtolower('\\3'),
- 'paramval1' => strtolower('\\4'),
- 'paramname2' => strtolower('\\5'),
- 'paramval2' => strtolower('\\6'),
- 'paramname3' => strtolower('\\7'),
- 'paramval3' => strtolower('\\8'),
- 'openclose' => '\\1',
- 'file' => realpath('$filename'),
- 'line' => ".($i+1).",
- 'entire_tag' => '\\0')
- );"
- ,
- $data[$i]
- );
- }
- }
- /**
- * takes values from preg_replace in _intparse and determines the replace string
- *
- * @access private
- * @return string replace values
- */
- function doDebugParse() {
- $valid_tags = array('var','loop','if','elseif','else','unless','endloop',
- 'endif','endunless', 'include', 'phpinclude', 'comment', 'endcomment');
- foreach($this->_debugalltags as $v) {
- $lasttag = $this->_debugtags[(count($this->_debugtags)-1)];
- $tag = $v['tag'];
- $escape = $v['escape'];
- $format = $v['format'];
- $op = $v['op'];
- $value = $v['value'];
- $var = trim($v['name']);
- $openclose = $v['openclose'];
- $file = $v['file'];
- $line = $v['line'];
- $entire_tag = stripslashes($v['entire_tag']);
- // continue if it's a one=line comment
- if ($tag == 'comment' && !empty($var)) continue;
- // bad tag
- if (!in_array($tag, $valid_tags)) {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Warning: Invalid tag',
- 'detail' => "The following tag is not valid:\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- continue;
- }
- // bad escape
- if (!empty($escape)){
- if (!isset($this->ESCAPE_TAGS[$escape])) {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Warning: Invalid escape type',
- 'detail' => "The escape attribute of the following tag is not valid:\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- }
- // bad format
- if (!empty($format)){
- if (!isset($this->FORMAT_TAGS[$format])) {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Warning: Invalid format type',
- 'detail' => "The format attribute of the following tag is not valid:\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- }
- // bad operator
- if (!empty($op)){
- if (!in_array($op, $this->allowed_if_ops)) {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Warning: Invalid operator type',
- 'detail' => "The op attribute of the following tag is not supported:\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- }
- if (preg_match("/^([a-z0-9_]+\.)*([a-z0-9_]+[_a-z0-9]*)$/i", $var, $matches) && !preg_match('/include|comment/', $tag)) $var = $matches[2];
- // out of sequences
- if ($tag == 'else') {
- if (preg_match('/if|elseif|unless/', $lasttag[0])) {
- continue;
- } else {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Error: tmpl_else out of sequence',
- 'detail' => "The following tag is out of sequence:\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- }
- if ($tag == 'elseif') {
- if (preg('/if|elseif/', $lasttag[0])) {
- array_pop($this->_debugtags);
- } else {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Error: tmpl_elseif out of sequence',
- 'detail' => "The following tag is out of sequence:\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- }
- // bad syntax
- if (!preg_match("/^([a-z_]+[_a-z0-9\.]*)$/i", $var) && !preg_match('/include|comment/', $tag) && !empty($var)) {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Warning: Invalid variable name',
- 'detail' => "The variable name in the following tag does not comply with the correct php syntax:\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- // if it's a closing tag return
- if (preg_match("/^<\/|{\/|<!--\/$/s", $openclose) || preg_match("/endloop|endif|endunless|endcomment/", $tag)) {
- $closetag = 1;
- if ($tag == 'loop' || $tag == 'endloop') $tag = 'loop';
- if ($tag == 'if' || $tag == 'endif') $tag = 'if';
- if ($tag == 'unless' || $tag == 'endunless') $tag = 'unless';
- if ($tag == 'comment' || $tag == 'endcomment') $tag = 'comment';
- if ($tag == 'loop') {
- if ($lasttag[0] == 'unless') {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Notice: tmpl_endloop',
- 'detail' => "The following end loop tag was found as a closing tag to a tmpl_unless:".$entire_tag
- .", whilst this 'may' not cause an error, it is incorrect vlibTemplate syntax (this maybe because of previous errors).",
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- array_pop($this->_debugtags);
- }
- elseif ($lasttag[0] == 'if') {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Error: tmpl_endloop',
- 'detail' => "The following end loop tag was found as a closing tag to a tmpl_if:".$entire_tag
- .", whilst this 'may' not cause an error, it is incorrect vlibTemplate syntax (this maybe because of previous errors).",
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- elseif($lasttag[0] != 'comment') {
- array_pop($this->_debugtags);
- }
- }
- elseif ($tag == 'if') {
- if ($lasttag[0] == 'unless') {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Notice: tmpl_endif',
- 'detail' => "The following end if tag was found as a closing tag to a tmpl_unless:".$entire_tag
- .", whilst this may not cause an error, it is incorrect vlibTemplate syntax (this maybe because of previous errors).",
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- array_pop($this->_debugtags);
- }
- elseif ($lasttag[0] == 'loop') {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Error: tmpl_endif',
- 'detail' => "The following end if tag was found without it's opening tag (this maybe because of previous errors):\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- elseif($lasttag[0] != 'comment') {
- array_pop($this->_debugtags);
- }
- }
- elseif ($tag == 'unless') {
- if ($lasttag[0] == 'if') {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Notice: tmpl_endunless',
- 'detail' => "The following end unless tag was found as a closing tag to a tmpl_if:".$entire_tag
- .", whilst this may not cause an error, it is incorrect vlibTemplate syntax (this maybe because of previous errors).",
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- array_pop($this->_debugtags);
- }
- elseif ($lasttag[0] == 'loop') {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Error: tmpl_endunless',
- 'detail' => "The following end unless tag was found without it's opening tag (this maybe because of previous errors):\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- elseif($lasttag[0] != 'comment') {
- array_pop($this->_debugtags);
- }
- }
- elseif ($tag == 'comment') {
- if ($lasttag[0] != 'comment') {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Error: tmpl_'.$tag,
- 'detail' => "The following end comment tag was found without it's opening tag (this maybe because of previous errors):\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- else {
- array_pop($this->_debugtags);
- }
- }
- if (empty($lasttag[0])) {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Error: tmpl_'.$tag,
- 'detail' => "The following end ".$tag." tag was found without it's opening tag (this maybe because of previous errors):\n".$entire_tag,
- 'location' => 'Line: '.$line.', in file: '.$file
- ));
- }
- }
- if (preg_match('/if|unless|loop|elseif|comment/', $tag) && !$closetag) {
- array_push($this->_debugtags, array(
- $tag,
- $file,
- $line,
- $entire_tag
- ));
- }
- unset($closetag);
- } // foreach
- // check for any unclosed tags
- foreach($this->_debugtags as $v) {
- array_push($this->_debugwarningmsgs, array(
- 'problem' => 'Error: tmpl_'.$v[0],
- 'detail' => "The following tmpl_".$v[0]." tag was found without it's closing tag (this maybe because of previous errors):\n".$v[3],
- 'location' => 'Line: '.$v[2].', in file: '.$v[1]
- ));
- }
- }
- /**
- * Puts a text string into document.write functions calls in javascript
- */
- function enjavanate ($str, $limit=60) {
- $str = str_replace("\r", '', $str);
- $retstr; // string to return
- $retstr .= "var vlib_debug_str2add = '';\n\n";
- while (strlen($str) > 0)
- {
- $line = substr ($str, 0, $limit);
- $str = substr ($str, $limit);
- $line = str_replace('\\', "\\\\", $line);
- $line = str_replace('\'', "\\'", $line);
- $line = str_replace("\r", '', $line);
- $line = str_replace("\n", "\\n", $line);
- $line = str_replace("\t", "\\t", $line);
- $line = str_replace('<', "<'+'", $line);
- $retstr .= "vlib_debug_str2add += '$line';\n";
- }
- $retstr .= "\nvlib_window_obj.document.write(vlib_debug_str2add);\n";
- return $retstr;
- }
- /**
- * Resets the debug module ready for more information
- */
- function _debugReset () {
- $this->_debugIncludedfiles = array();
- $this->_debugTemplatevars = array();
- $this->_debugtags = array();
- $this->_debugwarnings = array();
- $this->_debugwarningmsgscontrol = array();
- $this->_debugwarningmsgs = array();
- }
- /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- The following functions have no use and are included just so that if the user
- is making use of vlibTemplateCache functions, this doesn't crash when changed to
- vlibTemplateDebug.
- The reason it would crash is that when you call vlibTemplateDebug, it bypasses
- the cache class.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
- function clearCache() {}
- function recache() {}
- function setCacheLifeTime() {}
- function setCacheExtension() {}
- }
- ?>
|