Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/document/error/error.php

Documentation is available at error.php

  1. <?php
  2. /**
  3. @version        $Id: error.php 6472 2007-02-03 10:47:26Z pasamio $
  4. @package        Joomla.Framework
  5. @subpackage    Document
  6. @copyright    Copyright (C) 2005 - 2007 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.  * @author        Louis Landry <[email protected]>
  22.  * @package        Joomla.Framework
  23.  * @subpackage    Document
  24.  * @since        1.5
  25.  */
  26. class JDocumentError extends JDocument
  27. {
  28.     /**
  29.      * Error Object
  30.      * @var    object 
  31.      */
  32.     var $_error;
  33.  
  34.     /**
  35.      * Class constructor
  36.      *
  37.      * @access protected
  38.      * @param    string    $type         (either html or tex)
  39.      * @param    array    $attributes Associative array of attributes
  40.      */
  41.     function __construct($options array())
  42.     {
  43.         parent::__construct($options);
  44.  
  45.         //set mime type
  46.         $this->_mime 'text/html';
  47.  
  48.         //set document type
  49.         $this->_type 'error';
  50.     }
  51.  
  52.     /**
  53.      * Set error object
  54.      *
  55.      * @access    public
  56.      * @param    object    $error    Error object to set
  57.      * @return    boolean    True on success
  58.      * @since    1.5
  59.      */
  60.     function setError($error)
  61.     {
  62.         if (JError::isError($error)) {
  63.             $this->_error = $error;
  64.             return true;
  65.         else {
  66.             return false;
  67.         }
  68.     }
  69.  
  70.     /**
  71.      * Render the document
  72.      *
  73.      * @access public
  74.      * @param boolean     $cache        If true, cache the output
  75.      * @param array        $params        Associative array of attributes
  76.      */
  77.     function render$cache false$params array())
  78.     {
  79.         global $mainframe;
  80.  
  81.         // If no error object is set return null
  82.         if (!isset($this->_error)) {
  83.             return;
  84.         }
  85.  
  86.         // Send error header and set error page file
  87.         switch ($this->_error->code)
  88.         {
  89.             case '403':
  90.                 JResponse::setHeader('status''403 Forbidden');
  91.                 $file "403.php";
  92.                 break;
  93.  
  94.             case '404':
  95.                 JResponse::setHeader('status''404 Not Found');
  96.                 $file "404.php";
  97.                 break;
  98.  
  99.             case '500':
  100.             default:
  101.                 JResponse::setHeader('status''500 Internal Server Error');
  102.                 $file "500.php";
  103.                 break;
  104.         }
  105.  
  106.         // check template
  107.         $directory    = isset($params['directory']$params['directory''templates';
  108.         $template    = isset($params['template']$params['template''_system';
  109.  
  110.         if !file_exists$directory.DS.$template.DS.$file) ) {
  111.             $template '_system';
  112.         }
  113.  
  114.         //set variables
  115.         $this->template $template;
  116.         $this->debug    = isset($params['debug']$params['debug'false;
  117.         $this->message    JText::_($this->_error->message);
  118.  
  119.         // load
  120.         $data $this->_loadTemplate($directory.DS.$template$file);
  121.  
  122.         parent::render();
  123.         return $data;
  124.     }
  125.  
  126.     /**
  127.      * Load a template file
  128.      *
  129.      * @param string     $template    The name of the template
  130.      * @param string     $filename    The actual filename
  131.      * @return string The contents of the template
  132.      */
  133.     function _loadTemplate($directory$filename)
  134.     {
  135.         $contents '';
  136.  
  137.         //Check to see if we have a valid template file
  138.         if file_exists$directory.DS.$filename ) )
  139.         {
  140.             //store the file path
  141.             $this->_file $directory.DS.$filename;
  142.  
  143.             //get the file content
  144.             ob_start();
  145.             require_once($directory.DS.$filename );
  146.             $contents ob_get_contents();
  147.             ob_end_clean();
  148.         }
  149.  
  150.         return $contents;
  151.     }
  152.  
  153.     function renderBacktrace()
  154.     {
  155.         $contents    null;
  156.         $backtrace    $this->_error->getBacktrace();
  157.         ifis_array$backtrace ) )
  158.         {
  159.             ob_start();
  160.             $j    =    1;
  161.             echo      '<table border="0" cellpadding="0" cellspacing="0" class="Table">';
  162.             echo      '    <tr>';
  163.             echo      '        <td colspan="3" align="left" class="TD"><strong>Call stack</strong></td>';
  164.             echo      '    </tr>';
  165.             echo      '    <tr>';
  166.             echo      '        <td class="TD"><strong>#</strong></td>';
  167.             echo      '        <td class="TD"><strong>Function</strong></td>';
  168.             echo      '        <td class="TD"><strong>Location</strong></td>';
  169.             echo      '    </tr>';
  170.             for$i count$backtrace )-1$i >= $i-- )
  171.             {
  172.                 echo      '    <tr>';
  173.                 echo      '        <td class="TD">'.$j.'</td>';
  174.                 ifisset$backtrace[$i]['class') ) {
  175.                     echo      '    <td class="TD">'.$backtrace[$i]['class'].$backtrace[$i]['type'].$backtrace[$i]['function'].'()</td>';
  176.                 else {
  177.                     echo      '    <td class="TD">'.$backtrace[$i]['function'].'()</td>';
  178.                 }
  179.                 ifisset$backtrace[$i]['file') ) {
  180.                     echo      '        <td class="TD">'.$backtrace[$i]['file'].':'.$backtrace[$i]['line'].'</td>';
  181.                 else {
  182.                     echo      '        <td class="TD">&nbsp;</td>';
  183.                 }
  184.                 echo      '    </tr>';
  185.                 $j++;
  186.             }
  187.             echo      '</table>';
  188.             $contents ob_get_contents();
  189.             ob_end_clean();
  190.         }
  191.         return $contents;
  192.     }
  193. }
  194. ?>

Documentation generated on Mon, 05 Mar 2007 20:57:54 +0000 by phpDocumentor 1.3.1