Support Joomla!

Packages

Package: Joomla-Framework

License

Content on this site is copyright © 2005 - 2008 Open Source Matters Inc and can be used in accordance with the Joomla! Electronic Documentation License. Some parts of this website may be subject to other licenses.
Source code for file /joomla/document/error/error.php

Documentation is available at error.php

  1. <?php
  2. /**
  3. @version        $Id: error.php 10707 2008-08-21 09:52:47Z eddieajau $
  4. @package        Joomla.Framework
  5. @subpackage    Document
  6. @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  7. @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * DocumentError class, provides an easy interface to parse and display an error page
  20.  *
  21.  * @package        Joomla.Framework
  22.  * @subpackage    Document
  23.  * @since        1.5
  24.  */
  25. class JDocumentError extends JDocument
  26. {
  27.     /**
  28.      * Error Object
  29.      * @var    object 
  30.      */
  31.     var $_error;
  32.  
  33.     /**
  34.      * Class constructor
  35.      *
  36.      * @access protected
  37.      * @param    string    $type         (either html or tex)
  38.      * @param    array    $attributes Associative array of attributes
  39.      */
  40.     function __construct($options array())
  41.     {
  42.         parent::__construct($options);
  43.  
  44.         //set mime type
  45.         $this->_mime 'text/html';
  46.  
  47.         //set document type
  48.         $this->_type 'error';
  49.     }
  50.  
  51.     /**
  52.      * Set error object
  53.      *
  54.      * @access    public
  55.      * @param    object    $error    Error object to set
  56.      * @return    boolean    True on success
  57.      * @since    1.5
  58.      */
  59.     function setError($error)
  60.     {
  61.         if (JError::isError($error)) {
  62.             $this->_error = $error;
  63.             return true;
  64.         else {
  65.             return false;
  66.         }
  67.     }
  68.  
  69.     /**
  70.      * Render the document
  71.      *
  72.      * @access public
  73.      * @param boolean     $cache        If true, cache the output
  74.      * @param array        $params        Associative array of attributes
  75.      */
  76.     function render$cache false$params array())
  77.     {
  78.         // If no error object is set return null
  79.         if (!isset($this->_error)) {
  80.             return;
  81.         }
  82.  
  83.         //Set the status header
  84.         JResponse::setHeader('status'$this->_error->code.' '.str_replace"\n"' '$this->_error->message ));
  85.         $file 'error.php';
  86.  
  87.         // check template
  88.         $directory    = isset($params['directory']$params['directory''templates';
  89.         $template    = isset($params['template']JFilterInput::clean($params['template']'cmd''system';
  90.  
  91.         if !file_exists$directory.DS.$template.DS.$file) ) {
  92.             $template 'system';
  93.         }
  94.  
  95.         //set variables
  96.         $this->baseurl  JURI::base(true);
  97.         $this->template $template;
  98.         $this->debug    = isset($params['debug']$params['debug'false;
  99.         $this->error    $this->_error;
  100.  
  101.         // load
  102.         $data $this->_loadTemplate($directory.DS.$template$file);
  103.  
  104.         parent::render();
  105.         return $data;
  106.     }
  107.  
  108.     /**
  109.      * Load a template file
  110.      *
  111.      * @param string     $template    The name of the template
  112.      * @param string     $filename    The actual filename
  113.      * @return string The contents of the template
  114.      */
  115.     function _loadTemplate($directory$filename)
  116.     {
  117.         $contents '';
  118.  
  119.         //Check to see if we have a valid template file
  120.         if file_exists$directory.DS.$filename ) )
  121.         {
  122.             //store the file path
  123.             $this->_file $directory.DS.$filename;
  124.  
  125.             //get the file content
  126.             ob_start();
  127.             require_once $directory.DS.$filename;
  128.             $contents ob_get_contents();
  129.             ob_end_clean();
  130.         }
  131.  
  132.         return $contents;
  133.     }
  134.  
  135.     function renderBacktrace()
  136.     {
  137.         $contents    null;
  138.         $backtrace    $this->_error->getTrace();
  139.         ifis_array$backtrace ) )
  140.         {
  141.             ob_start();
  142.             $j    =    1;
  143.             echo      '<table border="0" cellpadding="0" cellspacing="0" class="Table">';
  144.             echo      '    <tr>';
  145.             echo      '        <td colspan="3" align="left" class="TD"><strong>Call stack</strong></td>';
  146.             echo      '    </tr>';
  147.             echo      '    <tr>';
  148.             echo      '        <td class="TD"><strong>#</strong></td>';
  149.             echo      '        <td class="TD"><strong>Function</strong></td>';
  150.             echo      '        <td class="TD"><strong>Location</strong></td>';
  151.             echo      '    </tr>';
  152.             for$i count$backtrace )-1$i >= $i-- )
  153.             {
  154.                 echo      '    <tr>';
  155.                 echo      '        <td class="TD">'.$j.'</td>';
  156.                 ifisset$backtrace[$i]['class') ) {
  157.                     echo      '    <td class="TD">'.$backtrace[$i]['class'].$backtrace[$i]['type'].$backtrace[$i]['function'].'()</td>';
  158.                 else {
  159.                     echo      '    <td class="TD">'.$backtrace[$i]['function'].'()</td>';
  160.                 }
  161.                 ifisset$backtrace[$i]['file') ) {
  162.                     echo      '        <td class="TD">'.$backtrace[$i]['file'].':'.$backtrace[$i]['line'].'</td>';
  163.                 else {
  164.                     echo      '        <td class="TD">&nbsp;</td>';
  165.                 }
  166.                 echo      '    </tr>';
  167.                 $j++;
  168.             }
  169.             echo      '</table>';
  170.             $contents ob_get_contents();
  171.             ob_end_clean();
  172.         }
  173.         return $contents;
  174.     }
  175. }

Documentation generated on Mon, 22 Sep 2008 12:08:42 +0100 by phpDocumentor 1.3.1