PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

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