phpDocumentor PHP_Debug
[ class tree: PHP_Debug ] [ index: PHP_Debug ] [ all elements ]

Source for file debug.php

Documentation is available at debug.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6. * PHP_Debug : A simple and fast way to debug PHP code
  7. *
  8. * This PHP debug libray offers you the ability to debug your PHP code
  9. *
  10. * - PHP Pear integration
  11. * - Process time
  12. * - Database and query process time
  13. * - Dump of all type of variable in a graphical way
  14. * - Functionnal debug
  15. * - Debug queries
  16. * - Allow to search in all debug infos
  17. * - Direct links to test queries in Phpmyadmin
  18. * - Show globals var ($GLOBALS, $_POST, $_GET ...)
  19. * - Enable or disable the debug infos you want to see
  20. * - Check performance of chunk of php code
  21. * - Customize the general display of your debug info
  22. * - ... ( see doc for complete specification )
  23. *
  24. * PHP versions 4 and 5
  25. *
  26. * LICENSE: This source file is subject to version 3.0 of the PHP license
  27. * that is available through the world-wide-web at the following URI:
  28. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  29. * the PHP License and are unable to obtain it through the web, please
  30. * send a note to license@php.net so we can mail you a copy immediately.
  31. *
  32. * @category Debug Tools
  33. * @package PHP_Debug
  34. * @author Loic Vernet, COil <qrf_coil@yahoo.fr>
  35. * @copyright 2003-2005 Vernet Loic
  36. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  37. * @version 1.1.0
  38. * @link http://phpdebug.sourceforge.net
  39. * @link http://www.php-debug.com
  40. * @see Pear::Var_Dump, Pear::SQL_Parser
  41. * @since 1.0BETA
  42. * @todo Check TODO file or
  43. * https://sourceforge.net/tracker/?group_id=95715
  44. * @filesource
  45. */
  46.  
  47. // {{{ constants
  48. /**
  49. * Possible version of class Debug
  50. */
  51. define('DBG_VERSION_STANDALONE', 0);
  52. define('DBG_VERSION_PEAR', 1);
  53. define('DBG_VERSION_DEFAULT', DBG_VERSION_STANDALONE);
  54. define('DBG_VERSION', DBG_VERSION_STANDALONE);
  55. define('DBG_RELEASE', 'V1.1.0');
  56.  
  57. // }}}
  58. // {{{ includes
  59.  
  60.  
  61.  
  62. /**
  63. * Only include Pear libraries for Pear version
  64. */
  65. if (DBG_VERSION == DBG_VERSION_PEAR) {
  66. /**
  67. * Include Pear Library
  68. */
  69. include_once('PEAR.php');
  70. /**
  71. * Include Pear::Var_Dump Library
  72. */
  73. include_once('Var_Dump.php');
  74.  
  75. /**
  76. * Include Pear::SQL_Parser Library
  77. */
  78. include_once('SQL/Parser.php');
  79. }
  80.  
  81. // }}}
  82. // {{{ constants
  83.  
  84.  
  85.  
  86. /**
  87. * Eventual external constants
  88. */
  89. if (!defined('STR_N'))
  90. define('STR_N', "");
  91.  
  92. if (!defined('CR'))
  93. define('CR', "\r\n");
  94.  
  95. /**
  96. * DBG_MODE Constants, define the different available debug modes.
  97. *
  98. * Here are the available modes :
  99. * - DBG_MODE_OFF : Debug mode is OFF
  100. * - DBG_MODE_USERPERF : Base debug mode,
  101. * - DBG_MODE_QUERY : DBG_MODE_USERPERF + queries
  102. * - DBG_MODE_QUERYTEMP : DBG_MODE_QUERY + included files
  103. * - DBG_MODE_FULL : All available debug infos ( including $GLOBALS array that is quiet big )
  104. * - DBG_MODE_AUTO : Mode auto take the mode of Debug Object
  105. */
  106. define('DBG_MODE_OFF', 0);
  107. define('DBG_MODE_USERPERF', 1);
  108. define('DBG_MODE_QUERY', 2);
  109. define('DBG_MODE_QUERYTEMP', 3);
  110. define('DBG_MODE_FULL', 4);
  111. define('DBG_MODE_AUTO', 5);
  112. define('DBG_MODE_DEFAULT', DBG_MODE_QUERYTEMP);
  113.  
  114. /**
  115. * This is a constant for the credits. For me :p
  116. */
  117. define('DBG_CREDITS', '== PHP_Debug ['. DBG_RELEASE .'] | By COil (2005) | '.
  118. '<a href="mailto:qrf_coil@yahoo.fr">qrf_coil@yahoo.fr</a> | '.
  119. '<a href="http://phpdebug.sourceforge.net/">PHP_Debug Project Home</a>');
  120.  
  121. /**
  122. * These are constant for DumpArr() and DumpObj() functions.
  123. *
  124. * - DUMP_ARR_DISP : Tell the functions to display the debug info.
  125. * - DUMP_ARR_STR : Tell the fonction to return the debug info as a string
  126. * - DBG_ARR_TABNAME : Default name of Array
  127. * - DBG_ARR_OBJNAME : Default name of Object
  128. */
  129. define('DUMP_ARR_DISP', 1);
  130. define('DUMP_ARR_STR', 2);
  131. define('DUMP_ARR_TABNAME', 'Array');
  132. define('DUMP_ARR_OBJNAME', 'Object');
  133.  
  134. /**
  135. * These are constants to define Super array environment variables
  136. */
  137. define('DBG_GLOBAL_GET', 0);
  138. define('DBG_GLOBAL_POST', 1);
  139. define('DBG_GLOBAL_FILES', 2);
  140. define('DBG_GLOBAL_COOKIE', 3);
  141. define('DBG_GLOBAL_REQUEST', 4);
  142. define('DBG_GLOBAL_SESSION', 5);
  143. define('DBG_GLOBAL_GLOBALS', 6);
  144.  
  145. // }}}
  146.  
  147. /**
  148. * Global var for references to available debug objects
  149. */
  150. $DEBUG_OBJECT = array();
  151.  
  152. /**
  153. * Debug : Main class that manage debug and debugline objects
  154. *
  155. * @category Debug Tools
  156. * @package PHP_Debug
  157. * @author COil, Loic Vernet <qrf_coil@yahoo.fr>
  158. * @copyright 1997-2005 The PHP Group
  159. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  160. * @version V1.1.0
  161. * @link http://pear.php.net/package/Easy_Debug
  162. * @see Pear::Var_Dump, Pear::SQL_Parser
  163. * @since Class available since Release 1.0BETA
  164. *
  165. */
  166. class Debug
  167. {
  168. /**
  169. * ID of debug object (0 = First object)
  170. *
  171. * @see $DEBUG_OBJECT
  172. * @since 24 Dec 2003
  173. * @access public
  174. */
  175. var $DebugObjectID = null;
  176. /**
  177. * Debug Mode
  178. *
  179. * @var integer
  180. * @access public
  181. * @see DBG_MODE constants.
  182. */
  183. var $DebugMode = DBG_MODE_DEFAULT;
  184.  
  185. /**
  186. * This is the array where debug line are.
  187. *
  188. * @var array $_DebugBuffer
  189. * @access private
  190. * @see DebugLine
  191. */
  192. var $_DebugBuffer = array();
  193.  
  194. /**
  195. * Enable or disable Credits in debug infos.
  196. *
  197. * @var integer $DisableCredits
  198. * @access public
  199. * @see DebugLine
  200. */
  201. var $DisableCredits = false;
  202.  
  203. /**
  204. * Process perf status, 1 = a process is being running, 0 = no activity
  205. *
  206. * @var String $_ProcessPerfStatus
  207. * @access private
  208. */
  209. var $_ProcessPerfStatus = false;
  210.  
  211. /**
  212. * General debug start time
  213. *
  214. * @var integer $_ProcessPerfStart
  215. * @access private
  216. */
  217. var $_ProcessPerfStartGen = 0; // Global Start Time
  218. /**
  219. * Debug Start time
  220. *
  221. * @var integer $_ProcessPerfStart
  222. * @access private
  223. */
  224. var $_ProcessPerfStart = 0; // Local Start Time
  225.  
  226.  
  227. /**
  228. * Debug End time
  229. *
  230. * @var integer $_ProcessPerfEnd
  231. * @access private
  232. */
  233. var $_ProcessPerfEnd = 0;
  234.  
  235. /**
  236. * Global database process time
  237. *
  238. * @var integer $_DataPerfTotal
  239. * @access private
  240. */
  241. var $_DataPerfTotal = 0;
  242.  
  243. /**
  244. * Number of performed queries
  245. *
  246. * @var integer $_DataPerfQry
  247. * @access private
  248. */
  249. var $_DataPerfQry = 0;
  250.  
  251. /**
  252. * Enable or disable, included and required files
  253. *
  254. * @var boolean $ShowTemplates
  255. * @access public
  256. */
  257. var $ShowTemplates = true;
  258.  
  259. /**
  260. * Enable or disable, pattern removing in included files
  261. *
  262. * @var boolean $RemoveTemplatesPattern
  263. * @access public
  264. */
  265. var $RemoveTemplatesPattern = false;
  266.  
  267. /**
  268. * Pattern list to remove in the display of included files
  269. *
  270. * @var boolean $RemoveTemplatesPattern
  271. * @access private
  272. */
  273. var $_TemplatesPattern = array();
  274.  
  275. /**
  276. * Enable or disable $globals var in debug
  277. *
  278. * @var boolean $ShowGlobals
  279. * @access public
  280. */
  281. var $ShowGlobals = false;
  282.  
  283. /**
  284. * Enable or disable search in debug
  285. *
  286. * @var boolean $EnableSearch
  287. * @access public
  288. */
  289. var $EnableSearch = true;
  290.  
  291. /**
  292. * Enable or disable the use of $_REQUEST array instead of
  293. * $_POST + _$GET + $_COOKIE + $_FILES
  294. *
  295. * @var boolean $UseRequestArr
  296. * @access public
  297. */
  298. var $UseRequestArr = false;
  299. /**
  300. * View Source script path
  301. *
  302. * @var string $ViewSourceScriptPath, default : Current directory
  303. * @access public
  304. */
  305. var $ViewSourceScriptPath = '.';
  306. /**
  307. * View Source script path
  308. *
  309. * @var string $ViewSourceScripName
  310. * @access public
  311. */
  312. var $ViewSourceScriptName = 'source.php';
  313.  
  314. /**
  315. * Lables Color for DebugType : $DebugType => Color Code of text
  316. *
  317. * @var array $DebugTypeLabel
  318. * @access public
  319. */
  320. var $DebugTypeLabel = array(DBGLINE_ANY => 'ALL',
  321. DBGLINE_STD => 'Standart',
  322. DBGLINE_QUERY => 'Query',
  323. DBGLINE_QUERY_REL => 'Database Related',
  324. DBGLINE_ENV => 'Environment',
  325. DBGLINE_CURRENTFILE => 'Current File',
  326. DBGLINE_APPERROR => 'Application Error',
  327. DBGLINE_CREDITS => 'Credits',
  328. DBGLINE_SEARCH => 'Search mode',
  329. DBGLINE_OBJECT => 'Object Debug',
  330. DBGLINE_PROCESSPERF => 'Performance analysis',
  331. DBGLINE_TEMPLATES => 'Included and required files',
  332. DBGLINE_PAGEACTION => 'Page main action',
  333. DBGLINE_ARRAY => 'Array Debug',
  334. DBGLINE_SQLPARSE => 'SQL Parse error');
  335.  
  336. /**
  337. * Color for DebugType : $DebugType => Color Code of text
  338. *
  339. * @var array $CellColors
  340. * @access public
  341. */
  342. var $CellColors = array(DBGLINE_STD => '#000000',
  343. DBGLINE_QUERY => '#FF8C00',
  344. DBGLINE_QUERY_REL => '#228B22',
  345. DBGLINE_ENV => '#FF0000',
  346. DBGLINE_CURRENTFILE => '#000000',
  347. DBGLINE_APPERROR => '#FF0000',
  348. DBGLINE_CREDITS => '#000000',
  349. DBGLINE_SEARCH => '#000000',
  350. DBGLINE_OBJECT => '#000000',
  351. DBGLINE_PROCESSPERF => '#000000',
  352. DBGLINE_TEMPLATES => '#000080',
  353. DBGLINE_PAGEACTION => '#708090',
  354. DBGLINE_ARRAY => '#000000',
  355. DBGLINE_SQLPARSE => '#228B22');
  356.  
  357. /**
  358. * Array for other class color to generate
  359. *
  360. * @since 26 Dec 2003
  361. */
  362. var $_StyleClassColor = array('IncFiles' => '#000080',
  363. 'HighLightKeyWord' => '#FFA500',
  364. 'SQLParseError' => '#800000');
  365. /**
  366. * HTML Start String
  367. *
  368. * Start string of HTML layout
  369. *
  370. * @var string $HtmlTableStart
  371. * @access public
  372. */
  373. var $HtmlTableStart = '
  374. <div>
  375. <br /><br />
  376. <a name="debug" id="debug" />
  377. <table cellspacing="0" cellpadding="1" width="100%" class="dbgMainTable">';
  378. /**
  379. * HTML end string to close HTML display for debug layout
  380. *
  381. * @var string $HtmlTableEnd
  382. * @access public
  383. */
  384. var $HtmlTableEnd = '
  385. </table>
  386. </div>';
  387. /**
  388. * Base Internal Style sheet
  389. *
  390. * @since 26 Dec 2003
  391. */
  392. var $_BaseStyle = array(0 => '.dbgBold { font-weight: bold; }',
  393. 1 => '.dbgNormal { font-weight: normal; color: #000000; }',
  394. 2 => '.dbgMainTable { border:1px solid #000080; background-color:#F8F8FF; border-bottom: 0px; }',
  395. 3 => '.dbgTD { color:black; font-family:courier new,arial; font-size:small; border-bottom: 1px solid #000080; }',
  396. 4 => '.dbgHR { border: 0px; height: 1px; background-color: #000080; }'
  397. );
  398.  
  399. /**
  400. * Variable to tell if we must generate a XHML 1.0 Strict output
  401. *
  402. * @since 13 May 2005
  403. */
  404. var $genXHTMLOutput = false;
  405.  
  406. /**
  407. * Bold style for DebugType : $DebugType => Bold Style
  408. *
  409. * @var array $CellBoldStatus
  410. * @access public
  411. */
  412. var $CellBoldStatus = array(DBGLINE_STD => false,
  413. DBGLINE_QUERY => true,
  414. DBGLINE_QUERY_REL => false,
  415. DBGLINE_ENV => false,
  416. DBGLINE_CURRENTFILE => true,
  417. DBGLINE_APPERROR => true,
  418. DBGLINE_CREDITS => true,
  419. DBGLINE_SEARCH => false,
  420. DBGLINE_OBJECT => false,
  421. DBGLINE_PROCESSPERF => false,
  422. DBGLINE_TEMPLATES => false,
  423. DBGLINE_PAGEACTION => true,
  424. DBGLINE_ARRAY => false,
  425. DBGLINE_SQLPARSE => true);
  426.  
  427. /**
  428. * Bold style for DebugType : $DebugType => Bold Style
  429. *
  430. * @var array $CellBoldStatus
  431. * @access public
  432. */
  433. var $DisplayTypeInSearch = array(DBGLINE_STD => false,
  434. DBGLINE_QUERY => false,
  435. DBGLINE_QUERY_REL => false,
  436. DBGLINE_ENV => false,
  437. DBGLINE_CURRENTFILE => true,
  438. DBGLINE_APPERROR => false,
  439. DBGLINE_CREDITS => true,
  440. DBGLINE_SEARCH => true,
  441. DBGLINE_OBJECT => false,
  442. DBGLINE_PROCESSPERF => true,
  443. DBGLINE_TEMPLATES => false,
  444. DBGLINE_PAGEACTION => false,
  445. DBGLINE_ARRAY => false,
  446. DBGLINE_SQLPARSE => false);
  447.  
  448. /**
  449. * Enable or not PhpMyAdmin direct links for queries
  450. *
  451. * @var boolean $EnablePhpMyAdminLinks
  452. * @access public
  453. */
  454. var $EnablePhpMyAdminLinks = true;
  455.  
  456. /**
  457. * Base URL of phpmyadmin
  458. *
  459. * @var string $PhpMyAdminUrl
  460. * @access public
  461. */
  462. var $PhpMyAdminUrl = 'http://127.0.0.1/mysql';
  463.  
  464. /**
  465. * Name of database that we are working on
  466. *
  467. * @var string $CurrentDatabase
  468. * @access public
  469. */
  470. var $DatabaseName = 'mysql';
  471. /**
  472. * Max Length of query to display on a single line
  473. *
  474. * @var string $maxQueryLength
  475. * @access public
  476. */
  477. var $maxQueryLineLength = 120;
  478.  
  479. /**
  480. * Pear::SQL_Parser object (If applicable)
  481. *
  482. * @var Object $SQLParser
  483. * @access private
  484. */
  485. var $_SQLParser = null;
  486.  
  487. /**
  488. * Debug() : Constructor of Debug object
  489. *
  490. * Set debugmode, credits line and search line are added at creation
  491. * if they are activated.
  492. *
  493. * @param integer $debugmode
  494. *
  495. * @return mixed Debug Object
  496. *
  497. * @see Debug()
  498. * @since 17 Oct 2003
  499. * @access public
  500. */
  501. function Debug($DebugMode = DBG_MODE_DEFAULT)
  502. {
  503. global $DEBUG_OBJECT;
  504.  
  505. if ($DebugMode == DBG_MODE_OFF) {
  506. $this->DebugMode = DBG_MODE_OFF;
  507. return;
  508. }
  509.  
  510. $this->DebugMode = $DebugMode;
  511. $this->_ProcessPerfStartGen = $this->getMicroTime(microtime());
  512.  
  513. // Set DebugObjectID
  514. $this->DebugObjectID = (!empty($DEBUG_OBJECT) ? count($DEBUG_OBJECT) : 0);
  515.  
  516. // Fix reference and ID of debugobject
  517. $this->_setDebugObjectRef($this);
  518. // Credits line
  519. if ($this->DisableCredits == false)
  520. $this->addDebug(DBG_CREDITS, DBGLINE_CREDITS);
  521. // Search line
  522. if ($this->EnableSearch == true)
  523. $this->addDebug(STR_N, DBGLINE_SEARCH);
  524. // SQL Parser if Pear is used
  525. if (DBG_VERSION == DBG_VERSION_PEAR)
  526. $this->_SQLParser = new SQL_Parser();
  527. }
  528.  
  529. /**
  530. * _setDebugObjectRef() : Set object ref in global var $DEBUG_OBJECT
  531. *
  532. * @since 24 Dec 2003
  533. * @access private
  534. */
  535. function _setDebugObjectRef(& $DebugObject)
  536. {
  537. global $DEBUG_OBJECT;
  538. $DEBUG_OBJECT[$this->DebugObjectID] = & $DebugObject;
  539. }
  540. /**
  541. * getDebugMode() : Return current debug mode
  542. *
  543. * @see $DebugMode
  544. * @since 14 Nov 2003
  545. * @access public
  546. */
  547. function getDebugMode()
  548. {
  549. return($this->DebugMode);
  550. }
  551.  
  552. /**
  553. * setDebugMode() : Set debug mode of Debug Object
  554. *
  555. * @param integer $debugmode
  556. *
  557. * @see $DebugMode
  558. * @since 14 Nov 2003
  559. * @access public
  560. */
  561. function setDebugMode($debugmode)
  562. {
  563. $this->DebugMode = $debugmode;
  564. }
  565.  
  566. /**
  567. * getColorCodeType() : Retrieve color code of the debug cell
  568. *
  569. * @return string
  570. *
  571. * @see CellColors
  572. * @since 25 Oct 2003
  573. * @access public
  574. */
  575. function getColorCodeType($DebugLineType)
  576. {
  577. return $this->CellColors[$DebugLineType];
  578. }
  579.  
  580. /**
  581. * getColorCodeClass() : Retrieve color code class from a color
  582. *
  583. * @return string
  584. *
  585. * @see CellColors
  586. * @since 25 Oct 2003
  587. * @access public
  588. */
  589. function getColorCodeClass($DebugLineType)
  590. {
  591. return 'style'. substr($this->getColorCodeType($DebugLineType), 1);
  592. }
  593. /**
  594. * setColorCodeType() : Set color code of the debug cell type
  595. *
  596. * @param Integer $DebugLineType Type of debug line
  597. * @param String $Color Color of cell
  598. *
  599. * @since 18 Dec 2003
  600. * @access public
  601. */
  602. function setColorCodeType($DebugLineType, $color)
  603. {
  604. $this->CellColors[$DebugLineType] = $color;
  605. }
  606.  
  607. /**
  608. * getBoldCodeType() : Retrieve Bold cell status of the debug cell
  609. *
  610. * @return boolean
  611. *
  612. * @since 25 Oct 2003
  613. * @access public
  614. */
  615. function getBoldCodeType($DebugLineType)
  616. {
  617. return $this->CellBoldStatus[$DebugLineType];
  618. }
  619.  
  620. /**
  621. * setBoldCodeType() : Set Bold cell status of a debug type
  622. *
  623. * @param Integer $DebugLineType Type of debug line
  624. * @param boolean $BoldStatus Status of cell true or false
  625. *
  626. * @since 25 Oct 2003
  627. * @access public
  628. */
  629. function setBoldCodeType($DebugLineType, $BoldStatus)
  630. {
  631. $this->CellBoldStatus[$DebugLineType] = $BoldStatus;
  632. }
  633.  
  634. /**
  635. * getTypeInSearch() : Retrieve if debug type is displayed in search mode
  636. *
  637. * @return boolean
  638. *
  639. * @since 25 Oct 2003
  640. * @access public
  641. */
  642. function getTypeInSearch($DebugLineType)
  643. {
  644. return $this->DisplayTypeInSearch[$DebugLineType];
  645. }
  646.  
  647. /**
  648. * setTypeInSearch() : Set if debug type is displayed in search mode
  649. *
  650. * @param Integer $DebugLineType Type of debug line
  651. * @param boolean $BoldStatus Status of cell true or false
  652. *
  653. * @since 25 Oct 2003
  654. * @access public
  655. */
  656. function setTypeInSearch($DebugLineType, $Status)
  657. {
  658. $this->DisplayTypeInSearch[$DebugLineType] = $Status;
  659. }
  660.  
  661. /**
  662. * getPhpMyAdminUrl() : Get the url of PhpmyAdmin
  663. *
  664. * @see PhpMyAdminUrl
  665. * @since 14 Nov 2003
  666. * @access public
  667. */
  668. function getPhpMyAdminUrl()
  669. {
  670. return $this->PhpMyAdminUrl;
  671. }
  672.  
  673. /**
  674. * setPhpMyAdminUrl() : Set the url of PhpmyAdmin
  675. *
  676. * @param string URL OF phpmyadmin
  677. *
  678. * @see PhpMyAdminUrl
  679. * @since 14 Nov 2003
  680. * @access public
  681. */
  682. function setPhpMyAdminUrl($PhpMyadminUrl)
  683. {
  684. $this->PhpMyAdminUrl = $PhpMyadminUrl;
  685. }
  686.  
  687. /**
  688. * getPhpMyAdminStatus() : Get PhpmyAdmin status
  689. *
  690. * @see EnablePhpMyAdminLinks
  691. * @since 25 Dec 2003
  692. * @access public
  693. */
  694. function getPhpMyAdminStatus()
  695. {
  696. return $this->EnablePhpMyAdminLinks;
  697. }
  698.  
  699. /**
  700. * setPhpMyAdminStatus($status) : Set status of phpmyadmin
  701. *
  702. * @param boolean True or false
  703. *
  704. * @see EnablePhpMyAdminLinks
  705. * @since 25 Dec 2003
  706. * @access public
  707. */
  708. function setPhpMyAdminStatus($status)
  709. {
  710. $this->EnablePhpMyAdminLinks = $status;
  711. }
  712.  
  713. /**
  714. * getDatabaseName() : Get the name of database
  715. *
  716. * @see DatabaseName
  717. * @since 25 Dec 2003
  718. * @access public
  719. */
  720. function getDatabaseName()
  721. {
  722. return $this->DatabaseName;
  723. }
  724.  
  725. /**
  726. * setDatabaseName() : Set database name for phpmyadmin links
  727. *
  728. * @param string Name of database
  729. *
  730. * @see DatabaseName
  731. * @since 25 Dec 2003
  732. * @access public
  733. */
  734. function setDatabaseName($DataBaseName)
  735. {
  736. $this->DatabaseName = $DataBaseName;
  737. }
  738.  
  739. /**
  740. * getMaxQueryLineLength() : Get max query line length
  741. *
  742. * @see maxQueryLineLength
  743. * @since 26 Dec 2003
  744. * @access public
  745. */
  746. function getMaxQueryLineLength()
  747. {
  748. return $this->maxQueryLineLength;
  749. }
  750. /**
  751. * setMaxQueryLineLength() : Set max query line length
  752. *
  753. * @see maxQueryLineLength
  754. * @since 26 Dec 2003
  755. * @access public
  756. */
  757. function setMaxQueryLineLength($length)
  758. {
  759. $this->maxQueryLineLength = $length;
  760. }
  761.  
  762. /**
  763. * getMicroTime() : Return micotime from a timestamp
  764. *
  765. * @param $time Timestamp to retrieve micro time
  766. * @return numeric Micotime of timestamp param
  767. *
  768. * @see $DebugMode
  769. * @since 14 Nov 2003
  770. * @static
  771. * @access public
  772. */
  773. function getMicroTime($time)
  774. {
  775. list($usec, $sec) = explode(' ', $time);
  776. return ((float)$usec + (float)$sec);
  777. }
  778.  
  779. /**
  780. * getElapsedTime() : get elapsed time between 2 timestamp
  781. *
  782. * @param $timeStart Start time ref
  783. * @param $timeEnd End time ref
  784. * @return numeric difference between the two time ref
  785. *
  786. * @see getProcessTime()
  787. * @since 20 Oct 2003
  788. * @static
  789. * @access public
  790. */
  791. function getElapsedTime($timeStart, $timeEnd)
  792. {
  793. return round($timeEnd - $timeStart, 4);
  794. }
  795. /**
  796. * getProcessTime() : Get global process time
  797. *
  798. * @return numeric Elapsed time between the start and end time
  799. *
  800. * @see getElapsedTime()
  801. * @since 20 Oct 2003
  802. * @access public
  803. */
  804. function getProcessTime()
  805. {
  806. return ($this->getElapsedTime($this->_ProcessPerfStartGen,
  807. $this->_ProcessPerfEnd));
  808. }
  809.  
  810. /**
  811. * _StopProcessTime() : Fix the end time of process
  812. *
  813. * @since 17 Novt 2003
  814. * @access private
  815. */
  816. function _StopProcessTime()
  817. {
  818. $this->_ProcessPerfEnd = $this->getMicroTime(microtime());
  819. }
  820. /**
  821. * DumpArr() : Display all content of an array
  822. *
  823. * Mode DUMP_ARR_DISP display the array
  824. * Mode DUMP_ARR_STR return the infos as a string
  825. *
  826. * @param array $arr array Array to debug
  827. * @param string $varname Name of the variable
  828. * @param integer $mode Mode of function
  829. * @return mixed Nothing or string depending on the mode
  830. *
  831. * @since 20 Oct 2003
  832. * @static
  833. * @access public
  834. */
  835. function DumpArr($arr, $varname = DUMP_ARR_TABNAME, $mode = DUMP_ARR_DISP)
  836. {
  837. ob_start();
  838. print_r($arr);
  839. $dbg_arrbuffer = htmlentities(ob_get_contents());
  840. ob_end_clean();
  841. $dbg_arrbuffer = "<br /><pre><b>$varname</b> :".
  842. CR. $dbg_arrbuffer. '</pre>';
  843.  
  844. switch ($mode) {
  845. default:
  846.  
  847. case DUMP_ARR_DISP:
  848. print($dbg_arrbuffer);
  849. break;
  850.  
  851. case DUMP_ARR_STR:
  852. return($dbg_arrbuffer);
  853. break;
  854. }
  855. }
  856.  
  857. /**
  858. * DumpObj() : Debug an object or array with Var_Dump pear package
  859. *
  860. * ( Not useable with standalone version )
  861. * Mode DUMP_ARR_DISP display the array
  862. * Mode DUMP_ARR_STR return the infos as a string
  863. *
  864. * @param array $obj Object to debug
  865. * @param string $varname Name of the variable
  866. * @param integer $mode Mode of function
  867. * @return mixed Nothing or string depending on the mode
  868. *
  869. * @since 10 Nov 2003
  870. * @static
  871. * @access public
  872. */
  873. function DumpObj($obj, $varname = DUMP_ARR_OBJNAME, $mode = DUMP_ARR_DISP)
  874. {
  875. // Check Pear Activation
  876. if (DBG_VERSION == DBG_VERSION_STANDALONE)
  877. return Debug::DumpArr($obj, $varname, $mode);
  878. ob_start();
  879. Var_Dump::display($obj);
  880. $dbg_arrbuffer = ob_get_contents();
  881. ob_end_clean();
  882.  
  883. if (empty($varname))
  884. $varname = DUMP_ARR_OBJNAME;
  885.  
  886. $dbg_arrbuffer = "<br /><pre><b>$varname</b> :".
  887. CR. $dbg_arrbuffer. '</pre>';
  888.  
  889. switch ($mode) {
  890. default:
  891. case DUMP_ARR_DISP:
  892. print($dbg_arrbuffer);
  893. break;
  894.  
  895. case DUMP_ARR_STR:
  896. return($dbg_arrbuffer);
  897. break;
  898. }
  899. }
  900.  
  901. /**
  902. * addDebug() : Build a new debug line info.
  903. *
  904. * If $str is a String or an object we switch automatically to the corresponding
  905. * debug info type. If debug mode is OFF does not do anything and return.
  906. * Debug line is build, then it is added in the DebugLine array.
  907. *
  908. * @param string $str Debug string/object
  909. * @param integer $typeDebug Debug type of line
  910. * (Optional, Default = DBGLINE_STD)
  911. * @param string $file File of debug info
  912. * (Optional, Default = "")
  913. * @param string $line Line of debug info
  914. * (Optional, Default = "")
  915. * @param string $title Title of variable if applicable
  916. * (Optional, Default = "")
  917. *
  918. * @since 10 Nov 2003
  919. * @access public
  920. */
  921. function addDebug($str, $typeDebug = DBGLINE_STD, $file = STR_N, $line = STR_N,
  922. $title = STR_N)
  923. {
  924. if ($this->DebugMode == DBG_MODE_OFF)
  925. return;
  926.  
  927. // If argument is an array change debug type
  928. if (is_array($str) && $typeDebug == DBGLINE_STD)
  929. $typeDebug = DBGLINE_ARRAY;
  930.  
  931. // If argument is an object change debug type
  932. if (is_object($str) && $typeDebug == DBGLINE_STD)
  933. $typeDebug = DBGLINE_OBJECT;
  934.  
  935. // Add Object
  936. $this->_DebugBuffer[] = new DebugLine($this->DebugObjectID, $str,
  937. $typeDebug, $file , $line, $title);
  938. }
  939.  
  940. /**
  941. * DebugPerf() : Get process time and stats about database processing.
  942. *
  943. * If $processtype is DBG_PERF_QRY then a query has been run, otherwise it
  944. * is another database process. The start and end time is computed, and the
  945. * global time is updated.
  946. *
  947. * @param integer $processtype Type of database debug query or
  948. * database related.
  949. *
  950. * @since 20 Oct 2003
  951. * @access public
  952. */
  953. function DebugPerf($processtype = DBGLINE_QUERY)
  954. {
  955. if ($this->DebugMode == DBG_MODE_OFF)
  956. return;
  957.  
  958. // Lang
  959. $txtPHP = 'PHP';
  960. $txtSQL = 'SQL';
  961. $txtSECOND = 's';
  962.  
  963. switch ($this->_ProcessPerfStatus) {
  964.  
  965. // Start Timer
  966. default:
  967.  
  968. case false:
  969. $this->_ProcessPerfStart = $this->getMicroTime(microtime());
  970. $this->_ProcessPerfStatus = true;
  971. // Additional processing depending of dataperf type request
  972. switch ($processtype) {
  973.  
  974. case(DBGLINE_QUERY):
  975. $this->_DataPerfQry++;
  976. break;
  977.  
  978. default:
  979. break;
  980. }
  981. break;
  982. // Stop Timer and add to database perf total
  983. case true;
  984. $this->_ProcessPerfEnd = $this->getMicroTime(microtime());
  985. $qry_time = $this->getElapsedTime($this->_ProcessPerfStart,
  986. $this->_ProcessPerfEnd);
  987.  
  988. $this->_ProcessPerfStart = $this->_ProcessPerfEnd = 0;
  989. $this->_ProcessPerfStatus = false;
  990. // Additional processing depending of dataperf type request
  991. switch ($processtype) {
  992.  
  993. default:
  994.  
  995. case(DBGLINE_STD);
  996. $this->_DebugBuffer[$this->_getLastDebugLineID($processtype)]->setProcessTime(" <b>" . DebugLine::colorizeFont("[ $txtPHP : ". $qry_time ."$txtSECOND ]", '#000000'). "</b>");
  997. break;
  998.  
  999. case(DBGLINE_QUERY_REL):
  1000.  
  1001. case(DBGLINE_QUERY):
  1002. //Now set the Time for the query in the DebugLine info
  1003. $this->_DebugBuffer[$this->_getLastDebugLineID($processtype)]->setProcessTime(" <b>" .DebugLine::colorizeFont("[ $txtSQL+$txtPHP : ". $qry_time ."$txtSECOND ]", '#000000') ."</b>");
  1004.  
  1005. // Global database perf
  1006. $this->_DataPerfTotal += $qry_time;
  1007. break;
  1008. }
  1009. break;
  1010. }
  1011. }
  1012.  
  1013. /**
  1014. * CancelPerf() : Cancel a process time monitoring, error or misc exception
  1015. *
  1016. * @param Integer $processtype Type of the process to cancel
  1017. *
  1018. * @since 13 Dec 2003
  1019. * @access public
  1020. */
  1021. function CancelPerf($processtype)
  1022. {
  1023. if ($this->DebugMode == DBG_MODE_OFF)
  1024. return;
  1025.  
  1026. $this->_ProcessPerfStart = $this->_ProcessPerfEnd = 0;
  1027. $this->_ProcessPerfStatus = false;
  1028. switch ($processtype) {
  1029. case(DBGLINE_QUERY):
  1030. $this->_DataPerfQry--;
  1031. break;
  1032.  
  1033. default:
  1034. break;
  1035. }
  1036. }
  1037. /**
  1038. * getLastDebugLineID : Retrieve the ID of last debugline type in
  1039. * _DebugBuffer array
  1040. *
  1041. * @param integer $debugtype Type of debug we want to get the last
  1042. * index
  1043. *
  1044. * @see DebugPerf(), _DebugBuffer
  1045. * @since 20 Nov 2003
  1046. * @access private
  1047. */
  1048. function _getLastDebugLineID($debugtype)
  1049. {
  1050. $tmparr = $this->_DebugBuffer;
  1051. krsort($tmparr);
  1052.  
  1053. foreach ( $tmparr as $lkey => $lvalue )
  1054. {
  1055. if ($lvalue->DebugType == $debugtype)
  1056. return $lkey;
  1057. }
  1058. }
  1059.  
  1060. /**
  1061. * _IncludeRequiredFiles() : Build debug line with all included or required
  1062. * files for current file.
  1063. *
  1064. * Use the get_required_files() function, then build the formatted string with
  1065. * links to edit and to view source of each files. Debug info line is added in
  1066. * current debug object.
  1067. *
  1068. * @since 20 Oct 2003
  1069. * @access private
  1070. */
  1071. function _IncludeRequiredFiles()
  1072. {
  1073. // Lang
  1074. $txtViewSource = 'View Source';
  1075. $txtEditSource = 'Edit';
  1076. $txtIncRecFiles = 'Included/Required files';
  1077.  
  1078. $l_reqfiles = get_required_files();
  1079. $l_strinc = "<b>== $txtIncRecFiles (". count($l_reqfiles). ') :</b><br />'. CR;
  1080.  
  1081. foreach( $l_reqfiles as $f_file ) {
  1082. $view_source_link = $edit_link = $f_file;
  1083.  
  1084. // Pattern deletion
  1085. if ($this->RemoveTemplatesPattern == true && count($this->_TemplatesPattern))
  1086. $f_file = strtr($f_file, $this->_TemplatesPattern);
  1087.  
  1088. $view_source_link = ' [ <a href="'. $this->ViewSourceScriptPath. '/'.
  1089. $this->ViewSourceScriptName. '?script='.
  1090. $view_source_link. '">'. $txtViewSource. '</a> ]';
  1091.  
  1092. $edit_link = ' [ <a href="'. $edit_link. '">'. $txtEditSource. '</a> ]';
  1093.  
  1094. $l_strinc .= $f_file. $view_source_link. $edit_link. '<br />'. CR;
  1095. }
  1096.  
  1097. $this->addDebug($l_strinc, DBGLINE_TEMPLATES);
  1098. }
  1099.  
  1100. /**
  1101. * addRequiredFilesPattern() : Add a remove pattern to remove pattern array.
  1102. *
  1103. * @param string $pattern Pattern to add
  1104. *
  1105. * @since 20 Oct 2003
  1106. * @access public
  1107. */
  1108. function addRequiredFilesPattern($pattern, $replace_str = STR_N)
  1109. {
  1110. if ($this->DebugMode == DBG_MODE_OFF)
  1111. return;
  1112.  
  1113. $this->_TemplatesPattern[$pattern] = $replace_str;
  1114. }
  1115.  
  1116. /**
  1117. * delRequiredFilesPattern() : Del a remove pattern from remove pattern array.
  1118. *
  1119. * @param string $pattern Pattern to remove
  1120. *
  1121. * @since 20 Oct 2003
  1122. * @access public
  1123. */
  1124. function delRequiredFilesPattern($pattern)
  1125. {
  1126. if ($this->DebugMode == DBG_MODE_OFF)
  1127. return;
  1128.  
  1129. unset($this->_TemplatesPattern[$pattern]);
  1130. }
  1131.  
  1132. /**
  1133. * addSuperArray() : Add a super array to the debug informations
  1134. *
  1135. * @see DBG_GLOBAL, DebugDisplay()
  1136. * @since 12 Dec 2003
  1137. * @access private
  1138. */
  1139. function _addSuperArray($SuperArrayType)
  1140. {
  1141. // Lang
  1142. $txtVariable = "Var";
  1143. $txtNoVariable = "NO VARIABLE";
  1144. $NoVariable = " -- $txtNoVariable -- ";
  1145.  
  1146. switch ($SuperArrayType) {
  1147.  
  1148. case(DBG_GLOBAL_GET):
  1149. $SuperArray = $_GET;
  1150. $ArrayTitle = '_GET';
  1151. $Title = "$ArrayTitle $txtVariable";
  1152. break;
  1153.  
  1154. case(DBG_GLOBAL_POST):
  1155. $SuperArray = $_POST;
  1156. $ArrayTitle = '_POST';
  1157. $Title = "$ArrayTitle $txtVariable";
  1158. break;
  1159.  
  1160. case(DBG_GLOBAL_FILES):
  1161. $SuperArray = $_FILES;
  1162. $ArrayTitle = '_FILES';
  1163. $Title = "$ArrayTitle $txtVariable";
  1164. break;
  1165.  
  1166. case(DBG_GLOBAL_COOKIE):
  1167. $SuperArray = $_COOKIE;
  1168. $ArrayTitle = '_COOKIE';
  1169. $Title = "$ArrayTitle $txtVariable";
  1170. break;
  1171.  
  1172. case(DBG_GLOBAL_REQUEST):
  1173. $SuperArray = $_REQUEST;
  1174. $ArrayTitle = '_REQUEST';
  1175. $Title = "$ArrayTitle $txtVariable (_GET + _POST + _FILES + _COOKIE)";
  1176. break;
  1177.  
  1178. case(DBG_GLOBAL_SESSION):
  1179. $SuperArray = $_SESSION;
  1180. $ArrayTitle = '_SESSION';
  1181. $Title = "$ArrayTitle $txtVariable";
  1182. break;
  1183. case(DBG_GLOBAL_GLOBALS):
  1184. $SuperArray = $GLOBALS;
  1185. $ArrayTitle = 'GLOBALS';
  1186. $Title = "$ArrayTitle $txtVariable";
  1187. break;
  1188.  
  1189. default:
  1190. break;
  1191. }
  1192. $SectionBasetitle = "<b>== $Title (". count($SuperArray). ') :';
  1193.  
  1194. if (count($SuperArray))
  1195. $this->addDebug($SectionBasetitle. '</b>'.
  1196. $this->DumpArr($SuperArray, $ArrayTitle, DUMP_ARR_STR), DBGLINE_ENV);
  1197. else
  1198. $this->addDebug($SectionBasetitle. "$NoVariable</b>", DBGLINE_ENV);
  1199. }
  1200.  
  1201. /**
  1202. * _addProcessTime() : Add the process time information to the debug infos
  1203. *
  1204. * @see DBG_GLOBAL, DebugDisplay()
  1205. * @since 12 Dec 2003
  1206. * @access private
  1207. */
  1208. function _addProcessTime()
  1209. {
  1210. // Lang
  1211. $txtExecutionTime = 'Execution Time Global';
  1212. $txtPHP = 'PHP';
  1213. $txtSQL = 'SQL';
  1214. $txtSECOND = 's';
  1215. $txtOneQry = 'Query';
  1216. $txtMultQry = 'Queries';
  1217. $txtQuery = $this->_DataPerfQry > 1 ? $txtMultQry : $txtOneQry;
  1218.  
  1219. // Performance Debug
  1220. $ProcessTime = $this->getProcessTime();
  1221. $php_time = $ProcessTime - $this->_DataPerfTotal;
  1222. $sql_time = $this->_DataPerfTotal;
  1223. $php_percent = round(($php_time / $ProcessTime) * 100, 2);
  1224. $sql_percent = round(($sql_time / $ProcessTime) * 100, 2);
  1225. $this->addDebug("<b>== $txtExecutionTime : " .
  1226. $ProcessTime . "$txtSECOND [ $txtPHP, ". $php_time ."$txtSECOND, ".
  1227. $php_percent .'% ] - '. "[ $txtSQL, ". $sql_time ."$txtSECOND, ".
  1228. $sql_percent .'%, '. $this->_DataPerfQry.
  1229. " $txtQuery ]</b>", DBGLINE_PROCESSPERF);
  1230. }
  1231. /**
  1232. * _HighLightKeyWords : Highligth a keyword in the debug info
  1233. */
  1234. function _HighLightKeyWords($SearchStr, $SearchCaseSensitiveType = false)
  1235. {
  1236. if (!empty($SearchStr) && !empty($this->_DebugBuffer)) {
  1237. for($i = 0 ; $i < count($this->_DebugBuffer) ; $i++) {
  1238. if ($this->DisplayTypeInSearch[$this->_DebugBuffer[$i]->DebugType] == false) {
  1239. if (!is_array($this->_DebugBuffer[$i]->_DebugString) && !is_object($this->_DebugBuffer[$i]->_DebugString)) {
  1240. if ( $SearchCaseSensitiveType == true)
  1241. $this->_DebugBuffer[$i]->_DebugString = ereg_replace("$SearchStr", DebugLine::colorizeFont("<b>$SearchStr</b>", '#FFA500'), $this->_DebugBuffer[$i]->_DebugString);
  1242. else
  1243. $this->_DebugBuffer[$i]->_DebugString = eregi_replace("$SearchStr", DebugLine::colorizeFont("<b>$SearchStr</b>", '#FFA500'), $this->_DebugBuffer[$i]->_DebugString);
  1244. $this->_DebugBuffer[$i]->_BuildDisplayString();
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250.  
  1251. /**
  1252. * parseSQL() : Function that parse a SQL String add a debug info if it is invalid
  1253. *
  1254. * @param string $sql SQL Query to parse
  1255. *
  1256. * @since 22 Dec 2003
  1257. * @access public
  1258. */
  1259. function parseSQL($sql)
  1260. {
  1261. if ($this->DebugMode == DBG_MODE_OFF)
  1262. return false;
  1263.  
  1264. // First Test Query Syntax (PEAR VERSION)
  1265. if (DBG_VERSION == DBG_VERSION_PEAR) {
  1266. $parseRes = $this->_SQLParser->parse($sql);
  1267. if (PEAR::isError($parseRes)) {
  1268. return $parseRes->getMessage();
  1269. }
  1270. }
  1271. else
  1272. return false;
  1273. }
  1274.  
  1275. /**
  1276. * generateStyleSheet()
  1277. */
  1278. function generateStyleSheet()
  1279. {
  1280. $ArrTemp = array_unique(array_merge($this->CellColors, $this->_StyleClassColor));
  1281. $StyleSheet = '<style type="text/css" id="phpdebugStyleSheet">';
  1282. foreach ($this->_BaseStyle as $lkey => $lvalue) {
  1283. $StyleSheet .= CR. $lvalue;
  1284. }
  1285. foreach ($ArrTemp as $lkey => $lvalue) {
  1286. $StyleSheet .= CR. ".style". substr($lvalue, 1) ." { color: $lvalue; }";
  1287. }
  1288. $StyleSheet .= CR. '</style>';
  1289.  
  1290. return $StyleSheet;
  1291. }
  1292. /**
  1293. * DebugDisplay() : This is the function to display debug infos
  1294. *
  1295. * @param string $search_str Search string ( Optional, default = "" )
  1296. * @param integer $display_mode Mode of display ( DBG_MODE_AUTO )
  1297. *
  1298. * @since 20 Oct 2003
  1299. * @access public
  1300. */
  1301. function DebugDisplay($display_mod = DBG_MODE_AUTO)
  1302. {
  1303. if ($this->DebugMode == DBG_MODE_OFF)
  1304. return;
  1305. // Fix display mode
  1306. elseif ($display_mod == DBG_MODE_AUTO)
  1307. $display_mod = $this->DebugMode;
  1308.  
  1309. // Fix end time process the sooner possible
  1310. $this->_StopProcessTime();
  1311. // Generate other style
  1312. if ($this->genXHTMLOutput == false)
  1313. print($this->generateStyleSheet());
  1314. // HTML START
  1315. print($this->HtmlTableStart);
  1316.  
  1317. // Process time debug informations
  1318. $this->_addProcessTime();
  1319.  
  1320. // Set variables depending on the current debug mode
  1321. switch ($display_mod) {
  1322.  
  1323. case DBG_MODE_OFF:
  1324. // We should never go here
  1325. return;
  1326. break;
  1327.  
  1328. case DBG_MODE_USERPERF:
  1329. $testShowTemplates = false;
  1330. $testShowSuperArray = true;
  1331. $testShowGlobals = false;
  1332. $testShowQueries = false;
  1333. break;
  1334.  
  1335. case DBG_MODE_QUERY:
  1336. $testShowTemplates = false;
  1337. $testShowSuperArray = true;
  1338. $testShowGlobals = false;
  1339. $testShowQueries = true;
  1340. break;
  1341.  
  1342. case DBG_MODE_QUERYTEMP:
  1343. $testShowSuperArray = true;
  1344. $testShowTemplates = true;
  1345. $testShowGlobals = false;
  1346. $testShowQueries = true;
  1347. break;
  1348.  
  1349. case DBG_MODE_FULL:
  1350. $testShowTemplates = true;
  1351. $testShowSuperArray = true;
  1352. $testShowGlobals = true;
  1353. $testShowQueries = true;
  1354. break;
  1355.  
  1356. default:
  1357. break;
  1358. }
  1359.  
  1360. // Include templates ===================================================
  1361. if ($testShowTemplates == true)
  1362. {
  1363. // Include debug of included files
  1364. if ($this->ShowTemplates == true)
  1365. $this->_IncludeRequiredFiles();
  1366. }
  1367. // Include super array =================================================
  1368. if ($testShowSuperArray == true)
  1369. {
  1370. // Divide Request tab
  1371. if ($this->UseRequestArr == false) {
  1372. // Include Post Var
  1373. $this->_addSuperArray(DBG_GLOBAL_POST);
  1374. // Include Get Var
  1375. $this->_addSuperArray(DBG_GLOBAL_GET);
  1376. // Include File Var
  1377. $this->_addSuperArray(DBG_GLOBAL_FILES);
  1378. // Include Cookie Var
  1379. $this->_addSuperArray(DBG_GLOBAL_COOKIE);
  1380. }
  1381. else
  1382. // Only display Request Tab
  1383. $this->_addSuperArray(DBG_GLOBAL_REQUEST);
  1384. // Include Sessions Var :Check if we have Session variables
  1385. if (!empty($_SESSION))
  1386. $this->_addSuperArray(DBG_GLOBAL_SESSION);
  1387.  
  1388. }
  1389.  
  1390. // Include Globals Var =================================================
  1391. if ($testShowGlobals == true || $this->ShowGlobals == true)
  1392. {
  1393. $this->_addSuperArray(DBG_GLOBAL_GLOBALS);
  1394. }
  1395.  
  1396. // Search ==============================================================
  1397. if ( !empty($_GET['DBG_SEARCH']) ) {
  1398. $SearchSTR = trim($_GET['DBG_SEARCH']);
  1399. }
  1400. else
  1401. $SearchSTR = '';
  1402.  
  1403. if ( !empty($_GET['DBG_SEARCH_TYPE']) ) {
  1404. $SearchType = $_GET['DBG_SEARCH_TYPE'];
  1405. }
  1406. else
  1407. $SearchType = 0;
  1408. $SearchCaseSensitiveType = !empty($_GET['DBG_SEARCH_CASESENSITIVE'])
  1409. ? true : false;
  1410.  
  1411. // Highlight Keywords
  1412. if (!empty($SearchSTR))
  1413. $this->_HighLightKeyWords($SearchSTR, $SearchCaseSensitiveType);
  1414. // Display Debug cells =================================================
  1415. foreach ($this->_DebugBuffer as $lkey =>$lvalue)
  1416. {
  1417. $bufstr = $lvalue->getDebugLineString();
  1418. // Display only cell that contains the search string or in force display array
  1419. $ShowDebugLine = false;
  1420.  
  1421. if (!empty($SearchSTR)) {
  1422. // Check if data is not an object or array
  1423. $searchInto = (is_array($lvalue->_DebugString) ||
  1424. is_object($lvalue->_DebugString) ?
  1425. $this->DumpArr($lvalue->_DebugString, STR_N, DUMP_ARR_STR) :
  1426. $lvalue->_DebugString);
  1427. // Search string found
  1428. if ( $SearchCaseSensitiveType == true ) {
  1429. if (strstr($searchInto, $SearchSTR) && $lvalue->DebugType)
  1430. $ShowDebugLine = true;
  1431. } else {
  1432. if (stristr($searchInto, $SearchSTR) && $lvalue->DebugType)
  1433. $ShowDebugLine = true;
  1434. }
  1435. }
  1436. else
  1437. $ShowDebugLine = true;
  1438.  
  1439. // Display only a type of debug info if applicable
  1440. if ($SearchType != 0) {
  1441. if ($lvalue->DebugType != $SearchType) {
  1442. $ShowDebugLine = false;
  1443. }
  1444. }
  1445.  
  1446. // Don't display queries if defined in mode
  1447. if ($testShowQueries == false && $lvalue->DebugType == DBGLINE_QUERY)
  1448. {
  1449. $ShowDebugLine = false;
  1450. }
  1451.  
  1452. // Forced debugline in search mode
  1453. if ($this->DisplayTypeInSearch[$lvalue->DebugType] == true)
  1454. $ShowDebugLine = true;
  1455. if ($ShowDebugLine == true)
  1456. print($bufstr);
  1457. }
  1458.  
  1459. // Close HTML Table
  1460. print($this->HtmlTableEnd);
  1461. }
  1462. /**
  1463. * UniTtests() : Make the unit tests of the debug class
  1464. *
  1465. * @since 22 Nov 2003
  1466. * @access public
  1467. */
  1468. function runUnitTests($fullmode = false)
  1469. {
  1470. $ClassName = get_class($this);
  1471. $txtTitle = "Class $ClassName Unit Tests (debug.php)";
  1472. $Title = "======== $txtTitle";
  1473.  
  1474. print('<pre><br /><br />');
  1475. print('<a name=\"'. $ClassName .'\"></a>');
  1476. print($Title);
  1477. if ($fullmode == true)
  1478. Debug::DumpObj($this, $ClassName, DUMP_ARR_DISP);
  1479. print('<br /><br /></pre>');
  1480. }
  1481. }
  1482.  
  1483. // {{{ constants
  1484.  
  1485. /**
  1486. * DEBUG LINE Types
  1487. *
  1488. * - DBGLINE_STD : Standart debug, fonctionnal or other
  1489. * - DBGLINE_QUERY : Query debug
  1490. * - DBGLINE_QUERY_REL : Database related debug
  1491. * - DBGLINE_ENV : Environment debug ( $GLOBALS... )
  1492. * - DBGLINE_CURRENTFILE: Output current file that is debugged
  1493. * - DBGLINE_APPERROR : Debug Error
  1494. * - DBGLINE_CREDITS : Credits
  1495. * - DBGLINE_SEARCH : Search mode in debug
  1496. * - DBGLINE_OBJECT : Debug object mode
  1497. * - DBGLINE_PROCESSPERF: Performance analysys
  1498. * - DBGLINE_TEMPLATES : Debug included templates
  1499. * - DBGLINE_PAGEACTION : Debug main page action
  1500. * - DBGLINE_ARRAY : Debug array mode
  1501. * - DBGLINE_SQLPARSE : Debug SQL Parse error
  1502. *
  1503. * @category DebugLine
  1504. */
  1505. define('DBGLINE_ANY', 0);
  1506. define('DBGLINE_STD', 1);
  1507. define('DBGLINE_QUERY', 2);
  1508. define('DBGLINE_QUERY_REL', 3);
  1509. define('DBGLINE_ENV', 4);
  1510. define('DBGLINE_CURRENTFILE', 5);
  1511. define('DBGLINE_APPERROR', 6);
  1512. define('DBGLINE_CREDITS', 7);
  1513. define('DBGLINE_SEARCH', 8);
  1514. define('DBGLINE_OBJECT', 9);
  1515. define('DBGLINE_PROCESSPERF', 10);
  1516. define('DBGLINE_TEMPLATES', 11);
  1517. define('DBGLINE_PAGEACTION', 12);
  1518. define('DBGLINE_ARRAY', 13);
  1519. define('DBGLINE_SQLPARSE', 14);
  1520. define('DBGLINE_DEFAULT', DBGLINE_STD);
  1521.  
  1522. /**
  1523. * DBGLINE_ERRORALERT, default error message for DBGLINE_APPERROR debug line type
  1524. */
  1525. define('DBGLINE_ERRORALERT', "/!\\");
  1526.  
  1527. /**
  1528. * DBGLINE_BOLD, constants for bold status function
  1529. */
  1530. define('DEBUGLINE_BOLD_CLOSE', 0);
  1531. define('DEBUGLINE_BOLD_OPEN', 1);
  1532.  
  1533. // }}}
  1534.  
  1535. /**
  1536. * DebugLine : Class that describe debug line informations
  1537. *
  1538. * Describe all infos and methods for a debug line, file location, color, type
  1539. * of debug, debug buffer, formatted debug buffer title of debug variable if
  1540. * applicable...
  1541. *
  1542. * @package PHP_Debug
  1543. * @author COil, Loic Vernet <qrf_coil@yahoo.fr>
  1544. * @version V1.1.0
  1545. * @since BETA1.0
  1546. */
  1547. class DebugLine
  1548. {
  1549. /**
  1550. * ID of parent Debug Object ID
  1551. *
  1552. * @var string $ProcessTimeString
  1553. * @access private
  1554. * @since 24 Dec 2003
  1555. */
  1556.  
  1557. var $_DebugObjectID = null;
  1558. /**
  1559. * File of debug info
  1560. *
  1561. * @var integer $_Fine
  1562. * @access private
  1563. */
  1564. var $_File = '';
  1565.  
  1566. /**
  1567. * Line of debug info
  1568. *
  1569. * @var integer $_Line
  1570. * @access private
  1571. */
  1572. var $_Line = '';
  1573. /**
  1574. * Complete Location ( formatted ) of debug infos ( Line + File )
  1575. *
  1576. * @var integer $_Location
  1577. * @access private
  1578. */
  1579. var $_Location = '';
  1580.  
  1581. /**
  1582. * Title of debug line ( Object var )
  1583. *
  1584. * @var String $_Linetitle
  1585. * @see DumpObj()
  1586. * @access private
  1587. */
  1588. var $_LineTitle = '';
  1589.  
  1590. /**
  1591. * String that store non formatted debug info
  1592. *
  1593. * @var string $_DebugString
  1594. * @access private
  1595. */
  1596. var $_DebugString = '';
  1597.  
  1598. /**
  1599. * Formatted Debug info
  1600. *
  1601. * @var string $_DebugString
  1602. * @access public
  1603. */
  1604. var $DebugDisplayString = '';
  1605.  
  1606. /**
  1607. * Debug Type
  1608. *
  1609. * @var integer $DebugType
  1610. * @see DBGLINE contants
  1611. * @access public
  1612. */
  1613. var $DebugType = DBGLINE_DEFAULT;
  1614. /**
  1615. * Background Color for debug info cell
  1616. *
  1617. * @var array $CellColor
  1618. * @access public
  1619. */
  1620. var $CellColor = '';
  1621.  
  1622. /**
  1623. * Base URL of phpmyadmin
  1624. *
  1625. * @var string $PhpMyAdminUrl
  1626. * @access public
  1627. */
  1628. var $PhpMyAdminUrl = '';
  1629.  
  1630. /**
  1631. * Name of database that we are working on
  1632. *
  1633. * @var string $CurrentDatabase
  1634. * @access public
  1635. */
  1636. var $DatabaseName = '';
  1637. /**
  1638. * Bold style for debug info cell
  1639. *
  1640. * @var array $CellBoldStatus
  1641. * @access public
  1642. */
  1643. var $CellBoldStatus = false;
  1644. /**
  1645. * Default Backgourd cell color
  1646. *
  1647. * @var string $DefaultCellBackColor
  1648. * @access public
  1649. */
  1650. var $DefaultCellBackColor = '#F8F8FF';
  1651. /**
  1652. * HTML Cell start code
  1653. *
  1654. * @var string $HtmlPreCell
  1655. * @access public
  1656. */
  1657. var $HtmlPreCell = '<tr>
  1658. <td class="dbgTD">';
  1659.  
  1660. /**
  1661. * HTML Cell end code
  1662. *
  1663. * @var string $HtmlPostCell
  1664. * @access public
  1665. */
  1666. var $HtmlPostCell = ' </td>
  1667. </tr>';
  1668. /**
  1669. * Process time infos if applicable
  1670. *
  1671. * @var string $ProcessTimeString
  1672. * @access public
  1673. * @since 19 Dec 2003
  1674. */
  1675. var $_ProcessTimeString = '';
  1676.  
  1677. /**
  1678. * Most of the time we will display a global span style for the debug
  1679. * cell but we must be able to desactive it in order to preserve XHTML
  1680. * compliance (DBGLINE_SEARCH for exemple)
  1681. *
  1682. * @var string $applySpanStyle
  1683. * @access public
  1684. * @since 13 May 2005
  1685. */
  1686. var $applySpanStyle = true;
  1687. /**
  1688. * DebugLine() Constructor of class
  1689. *
  1690. * _Location is Automatically created at object instantation.
  1691. * Then the formatted debug HTML row is created.
  1692. *
  1693. * @param string $str Debug Information to store
  1694. * @param integer $DebugType Type of debug information
  1695. * @param string $file File of debug information
  1696. * @param string $line Debug of debug information
  1697. * @param string $title Title of debuged var
  1698. *
  1699. * @return mixed DebugLine Object
  1700. *
  1701. * @see _BuildDebugLineLocation()
  1702. * @since 17 Oct 2003
  1703. * @access public
  1704. */
  1705. function DebugLine($DebugObjectID, $str, $DebugType, $file, $line, $title)
  1706. {
  1707. $this->_DebugObjectID = $DebugObjectID;
  1708. $this->_DebugString = $str;
  1709. $this->DebugType = $DebugType;
  1710. $this->_File = $file;
  1711. $this->_Line = $line;
  1712. $this->_LineTitle = $title;
  1713. // Don't apply global style for search cell.
  1714. if ($DebugType == DBGLINE_SEARCH)
  1715. $this->applySpanStyle = false;
  1716. }
  1717. /**
  1718. * _buildDebugLine() : Fucntions that build formatted datas of the debug cell
  1719. *
  1720. * @since 19 Dec 2003
  1721. */
  1722. function _buildDebugLine()
  1723. {
  1724. $this->_Location = $this->_BuildDebugLineLocation($this->_File,
  1725. $this->_Line);
  1726. $this->_BuildHtmlPreCell();
  1727. $this->_BuildDisplayString();
  1728. }
  1729.  
  1730. /**
  1731. * getPhpMyAdminUrl() : Return url of PhpmyAdmin
  1732. *
  1733. * @return string PhpMyAdminUrl
  1734. *
  1735. * @see PhpMyAdminUrl
  1736. * @since 25 Oct 2003
  1737. * @access public
  1738. */
  1739. function getPhpMyAdminUrl()
  1740. {
  1741. global $DEBUG_OBJECT;
  1742. return $DEBUG_OBJECT[$this->_DebugObjectID]->getPhpMyAdminUrl();
  1743. }
  1744. /**
  1745. * setProcessTime() : Process time string assignment function
  1746. *
  1747. * @since 19 Dec 2003
  1748. * @access public
  1749. */
  1750. function setProcessTime($Str)
  1751. {
  1752. $this->_ProcessTimeString = $Str;
  1753. }
  1754.  
  1755. /**
  1756. * _getCellColor() : Retrieve general HTML font color coding of debug cell
  1757. *
  1758. * @since 19 Dec 2003
  1759. * @access private
  1760. */
  1761. function _openCellColor()
  1762. {
  1763. if ($this->applySpanStyle == false)
  1764. return STR_N;
  1765. global $DEBUG_OBJECT;
  1766. return '<span class="'.
  1767. $DEBUG_OBJECT[$this->_DebugObjectID]->getColorCodeClass($this->DebugType).
  1768. '">';
  1769. }
  1770. /**
  1771. * _closeCellColor() : Close bold status of cell
  1772. *
  1773. * @since 19 Dec 2003
  1774. * @access private
  1775. */
  1776. function _closeCellColor()
  1777. {
  1778. if ($this->applySpanStyle == false)
  1779. return STR_N;
  1780.  
  1781. return '</span>';
  1782. }
  1783.  
  1784. /**
  1785. * applyTextStyle() : Apply a style to a string
  1786. *
  1787. * @since 26 Dec 2003
  1788. * @access public
  1789. * @static
  1790. */
  1791. function applyTextStyle($str, $style)
  1792. {
  1793. return('<span class="'. $style. '">'. $str. '</span>');
  1794. }
  1795.  
  1796. /**
  1797. * _getCellBoldStatus() : Get gen html open bold code status of debug cell
  1798. *
  1799. * @since 19 Dec 2003
  1800. * @access private
  1801. */
  1802. function _openBoldStatus()
  1803. {
  1804. return $this->_getBoldStatus(DEBUGLINE_BOLD_OPEN);
  1805. }
  1806.  
  1807. /**
  1808. * _getCellBoldStatus() : Get gen html close bold code status of debug cell
  1809. *
  1810. * @since 19 Dec 2003
  1811. * @access private
  1812. */
  1813. function _closeBoldStatus()
  1814. {
  1815. return $this->_getBoldStatus(DEBUGLINE_BOLD_CLOSE);
  1816. }
  1817.  
  1818. /**
  1819. * _getBoldStatus() : Get open or close bold status of a debug cell
  1820. *
  1821. * @since 19 Dec 2003
  1822. * @access private
  1823. */
  1824. function _getBoldStatus($mode = DEBUGLINE_BOLD_OPEN)
  1825. {
  1826. global $DEBUG_OBJECT;
  1827.  
  1828. switch ($mode) {
  1829. case (DEBUGLINE_BOLD_OPEN):
  1830. return ($DEBUG_OBJECT[$this->_DebugObjectID]->getBoldCodeType($this->DebugType) ? '<b>' : STR_N );
  1831. break;
  1832. case (DEBUGLINE_BOLD_CLOSE):
  1833. return ($DEBUG_OBJECT[$this->_DebugObjectID]->getBoldCodeType($this->DebugType) ? '</b>' : STR_N );
  1834. break;
  1835. default:
  1836. break;
  1837. }
  1838. }
  1839.  
  1840. /**
  1841. * colorizeFont() : Function that colorize a string with a given color
  1842. *
  1843. * @since 26 Dec 2003
  1844. * @access public
  1845. * @static
  1846. */
  1847. function colorizeFont($str, $color)
  1848. {
  1849. return '<span class="style'. substr($color, 1). '">'. $str. '</span>';
  1850. }
  1851. /**
  1852. * _BuildDisplayString() : Builds the formatted debug line
  1853. *
  1854. * Depending on the DebugType the formatted debug line is build.
  1855. * DebugDisplayString is built.
  1856. * One case by debug type.
  1857. *
  1858. * @see DebugType
  1859. * @since 20 Oct 2003
  1860. * @access private
  1861. */
  1862. function _BuildDisplayString()
  1863. {
  1864. global $DEBUG_OBJECT;
  1865.  
  1866. switch ($this->DebugType) {
  1867.  
  1868. // Standart output
  1869. case DBGLINE_STD:
  1870. $this->DebugDisplayString = $this->_DebugString;
  1871. break;
  1872.  
  1873. // Query
  1874. case DBGLINE_QUERY:
  1875. $txtExplain = 'Explain';
  1876. $txtQuery = 'Query';
  1877. // Format Query
  1878. $this->DebugDisplayString = $this->_FormatQueryString($this->_DebugString);
  1879. if ($DEBUG_OBJECT[$this->_DebugObjectID]->getPhpMyAdminStatus()) {
  1880. $basehtml = ' [ <a href="';
  1881.  
  1882. $url_query = $DEBUG_OBJECT[$this->_DebugObjectID]->getPhpMyAdminUrl()
  1883. .'/read_dump.php';
  1884.  
  1885. $url_query .= '?is_js_confirmed=0&amp;server=1&amp;db='.
  1886. $DEBUG_OBJECT[$this->_DebugObjectID]->getDatabaseName().
  1887. '&amp;pos=0&amp;goto=db_details.php&amp;zero_rows=&prev_sql_query=&amp;sql_file=&amp;sql_query=';
  1888.  
  1889. $url_explain = $url_query. 'explain '. urlencode($this->_DebugString);
  1890. $url_query = $url_query. urlencode($this->_DebugString);
  1891.  
  1892. $this->DebugDisplayString = $this->_FormatQueryString($this->_DebugString);
  1893. $this->DebugDisplayString = preg_replace('/\s+/', ' ', $this->DebugDisplayString);
  1894. // Parse SQL
  1895. if (DBG_VERSION == DBG_VERSION_PEAR) {
  1896. $parseRes = $DEBUG_OBJECT[$this->_DebugObjectID]->parseSQL($this->_DebugString);
  1897. if ($parseRes) {
  1898. $this->DebugDisplayString .= $this->colorizeFont('<pre>('. $parseRes .')</pre>', '#800000');
  1899. }
  1900. }
  1901.  
  1902. // Explain Link only for select Queries.
  1903. if (stristr($this->_DebugString, 'select'))
  1904. $this->DebugDisplayString .= $this->applyTextStyle($basehtml. $url_explain ."\">$txtExplain</a> ]", 'dbgNormal');
  1905. // Query Link
  1906. $this->DebugDisplayString .= $this->applyTextStyle($basehtml. $url_query. "\">$txtQuery</a> ]", 'dbgNormal');;
  1907. }
  1908. break;
  1909.  
  1910. // Database Related
  1911. case DBGLINE_QUERY_REL:
  1912. $this->DebugDisplayString = $this->_DebugString;
  1913. break;
  1914.  
  1915. // Environnment Related
  1916. case DBGLINE_ENV:
  1917. $this->DebugDisplayString = $this->_DebugString;
  1918. break;
  1919.  
  1920. // Current File
  1921. case DBGLINE_CURRENTFILE:
  1922. $txtCurrentFile = 'Current File';
  1923. $this->DebugDisplayString = "&laquo; $txtCurrentFile";
  1924. break;
  1925.  
  1926. // App Error
  1927. case DBGLINE_APPERROR:
  1928. $this->DebugDisplayString = DBGLINE_ERRORALERT. ' '. $this->_DebugString. ' '. DBGLINE_ERRORALERT;
  1929. break;
  1930.  
  1931. // Credits
  1932. case DBGLINE_CREDITS:
  1933. $this->DebugDisplayString = $this->_DebugString;
  1934. break;
  1935.  
  1936. // Search Debug
  1937. case DBGLINE_SEARCH:
  1938. // Repost all posted data
  1939. $txtSearchInDebug = 'Search in Debug Infos';
  1940. $txtGo = 'Go !';
  1941. $txtStringToSearch = 'Search for';
  1942. $txtCaseSensitive = 'Case sensitive';
  1943. $txtSelectByType = 'Select only info of type';
  1944. $txtAny = '-- Any --';
  1945. $dbg_search_value = isset($_REQUEST["DBG_SEARCH"]) ? trim($_REQUEST["DBG_SEARCH"]) : '';
  1946. $dbg_search_casesensitive_value = isset($_REQUEST["DBG_SEARCH_CASESENSITIVE"]) ? ' checked="checked"' : '';
  1947. $this->DebugDisplayString =
  1948. '== <b>'. $txtSearchInDebug .'</b> :
  1949. <form id="debugForm" action="'. $_SERVER['PHP_SELF']. '.">
  1950. <table>
  1951. <tr>
  1952. <td>'. $txtStringToSearch .'</td>
  1953. <td>:</td>
  1954. <td>
  1955. <input type="text" name="DBG_SEARCH" value="'. $dbg_search_value. '" />
  1956. </td>
  1957. <td>'. $txtCaseSensitive .'</td>
  1958. <td>:</td>
  1959. <td>
  1960. <input type="checkbox" name="DBG_SEARCH_CASESENSITIVE" '. $dbg_search_casesensitive_value .' />
  1961. </td>
  1962. <td>&nbsp;</td>
  1963. <td>'. $txtSelectByType. '</td>
  1964. <td>:</td>
  1965. <td>
  1966. <select name="DBG_SEARCH_TYPE">';
  1967. foreach ($DEBUG_OBJECT[$this->_DebugObjectID]->DebugTypeLabel as $lkey => $lvalue) {
  1968. $dbg_search_type_value = (!empty($_REQUEST["DBG_SEARCH_TYPE"]) && $lkey == $_REQUEST["DBG_SEARCH_TYPE"]) ? ' selected="selected"' : '';
  1969. $this->DebugDisplayString .= "<option value=\"$lkey\"$dbg_search_type_value>&raquo; $lvalue</option>". CR;
  1970. }
  1971. $this->DebugDisplayString .= '
  1972. </select>
  1973. <input type="submit" value="'. $txtGo. '" />
  1974. </td>
  1975. </tr>
  1976. </table></form>';
  1977. break;
  1978. // Object Debug
  1979. case DBGLINE_OBJECT:
  1980. $obj_title = empty($this->_LineTitle) ? get_class($this->_DebugString) : $this->_LineTitle;
  1981. $this->DebugDisplayString = Debug::DumpObj($this->_DebugString, $obj_title, DUMP_ARR_STR);
  1982. break;
  1983.  
  1984. // Process Perf
  1985. case DBGLINE_PROCESSPERF;
  1986. $this->DebugDisplayString = $this->_DebugString;
  1987. break;
  1988.  
  1989. // Temlates
  1990. case DBGLINE_TEMPLATES;
  1991. $this->DebugDisplayString = $this->_DebugString;
  1992. break;
  1993.  
  1994. // Main Page Action
  1995. case DBGLINE_PAGEACTION;
  1996. $txtPageAction = 'Page Action';
  1997. $this->DebugDisplayString = " [ $txtPageAction : ". $this->_DebugString .' ]';
  1998. break;
  1999.  
  2000. // Array Debug
  2001. case DBGLINE_ARRAY:
  2002. $this->DebugDisplayString = Debug::DumpArr($this->_DebugString, $this->_LineTitle, DUMP_ARR_STR);
  2003. break;
  2004.  
  2005. // SQL Parse error
  2006. case DBGLINE_SQLPARSE:
  2007. $txtSQLParseError = 'SQL_Parser :';
  2008. $this->DebugDisplayString = DBGLINE_ERRORALERT. ' '. $txtSQLParseError. $this->_DebugString. ' '. DBGLINE_ERRORALERT;
  2009. break;
  2010. }
  2011. }
  2012.  
  2013. /**
  2014. * _FormatQueryString() : Break a big query to display it on several lines
  2015. *
  2016. * @since 18 Dec 2003
  2017. * @see $maxQueryLength
  2018. * @access private
  2019. */
  2020. function _FormatQueryString($sql)
  2021. {
  2022. global $DEBUG_OBJECT;
  2023. $sql_arr = array();
  2024. $NewLineSqlKeyWords = array('SELECT', 'FROM', 'WHERE', 'AND', 'OR', 'ORDER', 'GROUP BY', 'UPDATE', 'SET', 'HAVING');
  2025.  
  2026. foreach($NewLineSqlKeyWords as $lkey => $lvalue) {
  2027. $sql = eregi_replace("$lvalue ", "<br />$lvalue " , $sql);
  2028. }
  2029.  
  2030. // Make an array with exploding by <br />, then split each string
  2031. $StrDecomp = explode('<br />', $sql);
  2032. // Parse each item and check the size
  2033. foreach ($StrDecomp as $lkey => $lvalue) {
  2034. if (strlen($lvalue) > $DEBUG_OBJECT[$this->_DebugObjectID]->getmaxQueryLineLength()) {
  2035. $sql_arr[] = $this->breakString($lvalue, $DEBUG_OBJECT[$this->_DebugObjectID]->getmaxQueryLineLength());
  2036. }
  2037. else
  2038. $sql_arr[] = $lvalue;
  2039. }
  2040. // Implode the array with <br />
  2041. $sql = implode('<br />', $sql_arr);
  2042. // $maxQueryLength
  2043. return $sql;
  2044. }
  2045. /**
  2046. * breakString() : Add Carriage return to a string
  2047. *
  2048. * @param String $Str String to break
  2049. * @param Integer $Length Length after we must break the string
  2050. * @param String $Separator Separator used to break string
  2051. *
  2052. * @access public
  2053. * @since 26 Dec 2003
  2054. */
  2055. function breakString($Str, $Length, $Separator = '<br />')
  2056. {
  2057. $FormatedStr = array();
  2058. for ($Idx = 0 ; $Idx < strlen($Str) ; $Idx++)
  2059. {
  2060. $FormatedStr[$Idx] = $Str{$Idx};
  2061. if ($Idx % $Length == 0 && $Idx != 0) {
  2062. $FormatedStr[$Idx] = $FormatedStr[$Idx]. $Separator;
  2063. }
  2064. }
  2065. return implode('',$FormatedStr);
  2066. }
  2067. /**
  2068. * _BuildHtmlPreCell() : Build HTML pre cell with backgroud attributes
  2069. *
  2070. * @since 11 Dec 2003
  2071. * @see DefaultCellBackColor, HtmlPreCell
  2072. * @access private
  2073. */
  2074. function _BuildHtmlPreCell()
  2075. {
  2076. $this->HtmlPreCell = sprintf($this->HtmlPreCell, $this->DefaultCellBackColor);
  2077. }
  2078. /**
  2079. * getDebugLineString() : Return Formated debug infos
  2080. *
  2081. * @return string The formatted string
  2082. *
  2083. * @since 25 Oct 2003
  2084. * @access public
  2085. */
  2086. function getDebugLineString()
  2087. {
  2088. // Build formatted datas
  2089. $this->_buildDebugLine();
  2090. return $this->HtmlPreCell.
  2091. $this->_Location.
  2092. $this->_openCellColor().
  2093. $this->_openBoldStatus().
  2094. $this->DebugDisplayString. $this->_ProcessTimeString.
  2095. $this->_closeBoldStatus().
  2096. $this->_closeCellColor().
  2097. $this->HtmlPostCell. CR;
  2098. }
  2099. /**
  2100. * _BuildDebugLineLocation() : Retrieve Localisation of debug info
  2101. *
  2102. * Check is $file and $line, build the location with available
  2103. * datas, if nothing return a default Info message.
  2104. *
  2105. * @param string $file File of debug info
  2106. * @param string $line Line number of debug info
  2107. *
  2108. * @return string The formatted location [file,line]
  2109. *
  2110. * @since 25 Oct 2003
  2111. * @access private
  2112. */
  2113. function _BuildDebugLineLocation($file, $line)
  2114. {
  2115. // Lang
  2116. $txtNoLocation = 'NO LOC';
  2117. $l_dbgloc = '';
  2118. if (!empty($file))
  2119. $l_dbgloc .= basename($file);
  2120. if (!empty($line)) {
  2121. if (!empty($l_dbgloc))
  2122. $l_dbgloc .= ',';
  2123. $l_dbgloc .= $line;
  2124. }
  2125.  
  2126. if (!empty($l_dbgloc))
  2127. $l_dbgloc = '['. $l_dbgloc. ']';
  2128. else {
  2129. if ($this->DebugType != DBGLINE_CREDITS &&
  2130. $this->DebugType != DBGLINE_SEARCH &&
  2131. $this->DebugType != DBGLINE_ENV &&
  2132. $this->DebugType != DBGLINE_PROCESSPERF &&
  2133. $this->DebugType != DBGLINE_TEMPLATES)
  2134. $l_dbgloc = "[-$txtNoLocation-]";
  2135. }
  2136. return $l_dbgloc;
  2137. }
  2138. }
  2139. ?>

Documentation generated on Sun, 12 Jun 2005 14:52:21 +0200 by phpDocumentor 1.3.0RC3