PageRenderTime 32ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/document/error/error.php

https://github.com/cosmocommerce/joomla
PHP | 173 lines | 95 code | 20 blank | 58 comment | 11 complexity | 8f33922790481de53bd396e33f0e27bd MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Framework
  5. * @subpackage Document
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. // No direct access
  10. defined('JPATH_BASE') or die;
  11. /**
  12. * DocumentError class, provides an easy interface to parse and display an error page
  13. *
  14. * @package Joomla.Framework
  15. * @subpackage Document
  16. * @since 1.5
  17. */
  18. jimport('joomla.document.document');
  19. class JDocumentError extends JDocument
  20. {
  21. /**
  22. * Error Object
  23. * @var object
  24. */
  25. var $_error;
  26. /**
  27. * Class constructor
  28. *
  29. * @access protected
  30. * @param string $type (either html or tex)
  31. * @param array $attributes Associative array of attributes
  32. */
  33. function __construct($options = array())
  34. {
  35. parent::__construct($options);
  36. //set mime type
  37. $this->_mime = 'text/html';
  38. //set document type
  39. $this->_type = 'error';
  40. }
  41. /**
  42. * Set error object
  43. *
  44. * @access public
  45. * @param object $error Error object to set
  46. * @return boolean True on success
  47. * @since 1.5
  48. */
  49. function setError($error)
  50. {
  51. if (JError::isError($error)) {
  52. $this->_error = & $error;
  53. return true;
  54. } else {
  55. return false;
  56. }
  57. }
  58. /**
  59. * Render the document
  60. *
  61. * @access public
  62. * @param boolean $cache If true, cache the output
  63. * @param array $params Associative array of attributes
  64. */
  65. function render($cache = false, $params = array())
  66. {
  67. // If no error object is set return null
  68. if (!isset($this->_error)) {
  69. return;
  70. }
  71. //Set the status header
  72. JResponse::setHeader('status', $this->_error->getCode().' '.str_replace("\n", ' ', $this->_error->getMessage()));
  73. $file = 'error.php';
  74. // check template
  75. $directory = isset($params['directory']) ? $params['directory'] : 'templates';
  76. $template = isset($params['template']) ? JFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';
  77. if (!file_exists($directory.DS.$template.DS.$file)) {
  78. $template = 'system';
  79. }
  80. //set variables
  81. $this->baseurl = JURI::base(true);
  82. $this->template = $template;
  83. $this->debug = isset($params['debug']) ? $params['debug'] : false;
  84. $this->error = $this->_error;
  85. // load
  86. $data = $this->_loadTemplate($directory.DS.$template, $file);
  87. parent::render();
  88. return $data;
  89. }
  90. /**
  91. * Load a template file
  92. *
  93. * @param string $template The name of the template
  94. * @param string $filename The actual filename
  95. * @return string The contents of the template
  96. */
  97. function _loadTemplate($directory, $filename)
  98. {
  99. $contents = '';
  100. //Check to see if we have a valid template file
  101. if (file_exists($directory.DS.$filename))
  102. {
  103. //store the file path
  104. $this->_file = $directory.DS.$filename;
  105. //get the file content
  106. ob_start();
  107. require_once $directory.DS.$filename;
  108. $contents = ob_get_contents();
  109. ob_end_clean();
  110. }
  111. return $contents;
  112. }
  113. function renderBacktrace()
  114. {
  115. $contents = null;
  116. $backtrace = $this->_error->getTrace();
  117. if (is_array($backtrace))
  118. {
  119. ob_start();
  120. $j = 1;
  121. echo '<table border="0" cellpadding="0" cellspacing="0" class="Table">';
  122. echo ' <tr>';
  123. echo ' <td colspan="3" align="left" class="TD"><strong>Call stack</strong></td>';
  124. echo ' </tr>';
  125. echo ' <tr>';
  126. echo ' <td class="TD"><strong>#</strong></td>';
  127. echo ' <td class="TD"><strong>Function</strong></td>';
  128. echo ' <td class="TD"><strong>Location</strong></td>';
  129. echo ' </tr>';
  130. for ($i = count($backtrace)-1; $i >= 0 ; $i--)
  131. {
  132. echo ' <tr>';
  133. echo ' <td class="TD">'.$j.'</td>';
  134. if (isset($backtrace[$i]['class'])) {
  135. echo ' <td class="TD">'.$backtrace[$i]['class'].$backtrace[$i]['type'].$backtrace[$i]['function'].'()</td>';
  136. } else {
  137. echo ' <td class="TD">'.$backtrace[$i]['function'].'()</td>';
  138. }
  139. if (isset($backtrace[$i]['file'])) {
  140. echo ' <td class="TD">'.$backtrace[$i]['file'].':'.$backtrace[$i]['line'].'</td>';
  141. } else {
  142. echo ' <td class="TD">&nbsp;</td>';
  143. }
  144. echo ' </tr>';
  145. $j++;
  146. }
  147. echo '</table>';
  148. $contents = ob_get_contents();
  149. ob_end_clean();
  150. }
  151. return $contents;
  152. }
  153. }