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

Language PHP Lines 174
MD5 Hash 8f33922790481de53bd396e33f0e27bd
Repository https://github.com/cosmocommerce/joomla.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
 * @version		$Id$
 * @package		Joomla.Framework
 * @subpackage	Document
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access
defined('JPATH_BASE') or die;

/**
 * DocumentError class, provides an easy interface to parse and display an error page
 *
 * @package		Joomla.Framework
 * @subpackage	Document
 * @since		1.5
 */

jimport('joomla.document.document');

class JDocumentError extends JDocument
{
	/**
	 * Error Object
	 * @var	object
	 */
	var $_error;

	/**
	 * Class constructor
	 *
	 * @access protected
	 * @param	string	$type		(either html or tex)
	 * @param	array	$attributes Associative array of attributes
	 */
	function __construct($options = array())
	{
		parent::__construct($options);

		//set mime type
		$this->_mime = 'text/html';

		//set document type
		$this->_type = 'error';
	}

	/**
	 * Set error object
	 *
	 * @access	public
	 * @param	object	$error	Error object to set
	 * @return	boolean	True on success
	 * @since	1.5
	 */
	function setError($error)
	{
		if (JError::isError($error)) {
			$this->_error = & $error;
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Render the document
	 *
	 * @access public
	 * @param boolean	$cache		If true, cache the output
	 * @param array		$params		Associative array of attributes
	 */
	function render($cache = false, $params = array())
	{
		// If no error object is set return null
		if (!isset($this->_error)) {
			return;
		}

		//Set the status header
		JResponse::setHeader('status', $this->_error->getCode().' '.str_replace("\n", ' ', $this->_error->getMessage()));
		$file = 'error.php';

		// check template
		$directory	= isset($params['directory']) ? $params['directory'] : 'templates';
		$template	= isset($params['template']) ? JFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';

		if (!file_exists($directory.DS.$template.DS.$file)) {
			$template = 'system';
		}

		//set variables
		$this->baseurl  = JURI::base(true);
		$this->template = $template;
		$this->debug	= isset($params['debug']) ? $params['debug'] : false;
		$this->error	= $this->_error;

		// load
		$data = $this->_loadTemplate($directory.DS.$template, $file);

		parent::render();
		return $data;
	}

	/**
	 * Load a template file
	 *
	 * @param string	$template	The name of the template
	 * @param string	$filename	The actual filename
	 * @return string The contents of the template
	 */
	function _loadTemplate($directory, $filename)
	{
		$contents = '';

		//Check to see if we have a valid template file
		if (file_exists($directory.DS.$filename))
		{
			//store the file path
			$this->_file = $directory.DS.$filename;

			//get the file content
			ob_start();
			require_once $directory.DS.$filename;
			$contents = ob_get_contents();
			ob_end_clean();
		}

		return $contents;
	}

	function renderBacktrace()
	{
		$contents	= null;
		$backtrace	= $this->_error->getTrace();
		if (is_array($backtrace))
		{
			ob_start();
			$j	=	1;
			echo	'<table border="0" cellpadding="0" cellspacing="0" class="Table">';
			echo	'	<tr>';
			echo	'		<td colspan="3" align="left" class="TD"><strong>Call stack</strong></td>';
			echo	'	</tr>';
			echo	'	<tr>';
			echo	'		<td class="TD"><strong>#</strong></td>';
			echo	'		<td class="TD"><strong>Function</strong></td>';
			echo	'		<td class="TD"><strong>Location</strong></td>';
			echo	'	</tr>';
			for ($i = count($backtrace)-1; $i >= 0 ; $i--)
			{
				echo	'	<tr>';
				echo	'		<td class="TD">'.$j.'</td>';
				if (isset($backtrace[$i]['class'])) {
					echo	'	<td class="TD">'.$backtrace[$i]['class'].$backtrace[$i]['type'].$backtrace[$i]['function'].'()</td>';
				} else {
					echo	'	<td class="TD">'.$backtrace[$i]['function'].'()</td>';
				}
				if (isset($backtrace[$i]['file'])) {
					echo	'		<td class="TD">'.$backtrace[$i]['file'].':'.$backtrace[$i]['line'].'</td>';
				} else {
					echo	'		<td class="TD">&nbsp;</td>';
				}
				echo	'	</tr>';
				$j++;
			}
			echo	'</table>';
			$contents = ob_get_contents();
			ob_end_clean();
		}
		return $contents;
	}
}
Back to Top