converted to unix-style eol
[www-register-wizard.git] / libraries / Output.php
index 98a941a..b93963a 100644 (file)
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
-/**\r
- * CodeIgniter\r
- *\r
- * An open source application development framework for PHP 4.3.2 or newer\r
- *\r
- * @package            CodeIgniter\r
- * @author             ExpressionEngine Dev Team\r
- * @copyright  Copyright (c) 2008, EllisLab, Inc.\r
- * @license            http://codeigniter.com/user_guide/license.html\r
- * @link               http://codeigniter.com\r
- * @since              Version 1.0\r
- * @filesource\r
- */\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * Output Class\r
- *\r
- * Responsible for sending final output to browser\r
- *\r
- * @package            CodeIgniter\r
- * @subpackage Libraries\r
- * @category   Output\r
- * @author             ExpressionEngine Dev Team\r
- * @link               http://codeigniter.com/user_guide/libraries/output.html\r
- */\r
-class CI_Output {\r
-\r
-       var $final_output;\r
-       var $cache_expiration   = 0;\r
-       var $headers                    = array();\r
-       var $enable_profiler    = FALSE;\r
-\r
-\r
-       function CI_Output()\r
-       {\r
-               log_message('debug', "Output Class Initialized");\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Get Output\r
-        *\r
-        * Returns the current output string\r
-        *\r
-        * @access      public\r
-        * @return      string\r
-        */     \r
-       function get_output()\r
-       {\r
-               return $this->final_output;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Set Output\r
-        *\r
-        * Sets the output string\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      void\r
-        */     \r
-       function set_output($output)\r
-       {\r
-               $this->final_output = $output;\r
-       }\r
-\r
-       // --------------------------------------------------------------------\r
-\r
-       /**\r
-        * Append Output\r
-        *\r
-        * Appends data onto the output string\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      void\r
-        */     \r
-       function append_output($output)\r
-       {\r
-               if ($this->final_output == '')\r
-               {\r
-                       $this->final_output = $output;\r
-               }\r
-               else\r
-               {\r
-                       $this->final_output .= $output;\r
-               }\r
-       }\r
-\r
-       // --------------------------------------------------------------------\r
-\r
-       /**\r
-        * Set Header\r
-        *\r
-        * Lets you set a server header which will be outputted with the final display.\r
-        *\r
-        * Note:  If a file is cached, headers will not be sent.  We need to figure out\r
-        * how to permit header data to be saved with the cache data...\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      void\r
-        */     \r
-       function set_header($header, $replace = TRUE)\r
-       {\r
-               $this->headers[] = array($header, $replace);\r
-       }\r
-\r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Set HTTP Status Header\r
-        *\r
-        * @access      public\r
-        * @param       int     the status code\r
-        * @param       string  \r
-        * @return      void\r
-        */     \r
-       function set_status_header($code = '200', $text = '')\r
-       {\r
-               $stati = array(\r
-                                                       '200'   => 'OK',\r
-                                                       '201'   => 'Created',\r
-                                                       '202'   => 'Accepted',\r
-                                                       '203'   => 'Non-Authoritative Information',\r
-                                                       '204'   => 'No Content',\r
-                                                       '205'   => 'Reset Content',\r
-                                                       '206'   => 'Partial Content',\r
-                                                       \r
-                                                       '300'   => 'Multiple Choices',\r
-                                                       '301'   => 'Moved Permanently',\r
-                                                       '302'   => 'Found',\r
-                                                       '304'   => 'Not Modified',\r
-                                                       '305'   => 'Use Proxy',\r
-                                                       '307'   => 'Temporary Redirect',\r
-                                                       \r
-                                                       '400'   => 'Bad Request',\r
-                                                       '401'   => 'Unauthorized',\r
-                                                       '403'   => 'Forbidden',\r
-                                                       '404'   => 'Not Found',\r
-                                                       '405'   => 'Method Not Allowed',\r
-                                                       '406'   => 'Not Acceptable',\r
-                                                       '407'   => 'Proxy Authentication Required',\r
-                                                       '408'   => 'Request Timeout',\r
-                                                       '409'   => 'Conflict',\r
-                                                       '410'   => 'Gone',\r
-                                                       '411'   => 'Length Required',\r
-                                                       '412'   => 'Precondition Failed',\r
-                                                       '413'   => 'Request Entity Too Large',\r
-                                                       '414'   => 'Request-URI Too Long',\r
-                                                       '415'   => 'Unsupported Media Type',\r
-                                                       '416'   => 'Requested Range Not Satisfiable',\r
-                                                       '417'   => 'Expectation Failed',\r
-               \r
-                                                       '500'   => 'Internal Server Error',\r
-                                                       '501'   => 'Not Implemented',\r
-                                                       '502'   => 'Bad Gateway',\r
-                                                       '503'   => 'Service Unavailable',\r
-                                                       '504'   => 'Gateway Timeout',\r
-                                                       '505'   => 'HTTP Version Not Supported'\r
-                                               );\r
-\r
-               if ($code == '' OR ! is_numeric($code))\r
-               {\r
-                       show_error('Status codes must be numeric');\r
-               }\r
-\r
-               if (isset($stati[$code]) AND $text == '')\r
-               {                               \r
-                       $text = $stati[$code];\r
-               }\r
-               \r
-               if ($text == '')\r
-               {\r
-                       show_error('No status text available.  Please check your status code number or supply your own message text.');\r
-               }\r
-               \r
-               $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;\r
-       \r
-               if (substr(php_sapi_name(), 0, 3) == 'cgi')\r
-               {\r
-                       header("Status: {$code} {$text}", TRUE);\r
-               }\r
-               elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0')\r
-               {\r
-                       header($server_protocol." {$code} {$text}", TRUE, $code);\r
-               }\r
-               else\r
-               {\r
-                       header("HTTP/1.1 {$code} {$text}", TRUE, $code);\r
-               }\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Enable/disable Profiler\r
-        *\r
-        * @access      public\r
-        * @param       bool\r
-        * @return      void\r
-        */     \r
-       function enable_profiler($val = TRUE)\r
-       {\r
-               $this->enable_profiler = (is_bool($val)) ? $val : TRUE;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Set Cache\r
-        *\r
-        * @access      public\r
-        * @param       integer\r
-        * @return      void\r
-        */     \r
-       function cache($time)\r
-       {\r
-               $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Display Output\r
-        *\r
-        * All "view" data is automatically put into this variable by the controller class:\r
-        *\r
-        * $this->final_output\r
-        *\r
-        * This function sends the finalized output data to the browser along\r
-        * with any server headers and profile data.  It also stops the\r
-        * benchmark timer so the page rendering speed and memory usage can be shown.\r
-        *\r
-        * @access      public\r
-        * @return      mixed\r
-        */             \r
-       function _display($output = '')\r
-       {       \r
-               // Note:  We use globals because we can't use $CI =& get_instance()\r
-               // since this function is sometimes called by the caching mechanism,\r
-               // which happens before the CI super object is available.\r
-               global $BM, $CFG;\r
-               \r
-               // --------------------------------------------------------------------\r
-               \r
-               // Set the output data\r
-               if ($output == '')\r
-               {\r
-                       $output =& $this->final_output;\r
-               }\r
-               \r
-               // --------------------------------------------------------------------\r
-               \r
-               // Do we need to write a cache file?\r
-               if ($this->cache_expiration > 0)\r
-               {\r
-                       $this->_write_cache($output);\r
-               }\r
-               \r
-               // --------------------------------------------------------------------\r
-\r
-               // Parse out the elapsed time and memory usage,\r
-               // then swap the pseudo-variables with the data\r
-\r
-               $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');         \r
-               $output = str_replace('{elapsed_time}', $elapsed, $output);\r
-               \r
-               $memory  = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';\r
-               $output = str_replace('{memory_usage}', $memory, $output);              \r
-\r
-               // --------------------------------------------------------------------\r
-               \r
-               // Is compression requested?\r
-               if ($CFG->item('compress_output') === TRUE)\r
-               {\r
-                       if (extension_loaded('zlib'))\r
-                       {\r
-                               if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)\r
-                               {\r
-                                       ob_start('ob_gzhandler');\r
-                               }\r
-                       }\r
-               }\r
-\r
-               // --------------------------------------------------------------------\r
-               \r
-               // Are there any server headers to send?\r
-               if (count($this->headers) > 0)\r
-               {\r
-                       foreach ($this->headers as $header)\r
-                       {\r
-                               @header($header[0], $header[1]);\r
-                       }\r
-               }               \r
-\r
-               // --------------------------------------------------------------------\r
-               \r
-               // Does the get_instance() function exist?\r
-               // If not we know we are dealing with a cache file so we'll\r
-               // simply echo out the data and exit.\r
-               if ( ! function_exists('get_instance'))\r
-               {\r
-                       echo $output;\r
-                       log_message('debug', "Final output sent to browser");\r
-                       log_message('debug', "Total execution time: ".$elapsed);\r
-                       return TRUE;\r
-               }\r
-       \r
-               // --------------------------------------------------------------------\r
-\r
-               // Grab the super object.  We'll need it in a moment...\r
-               $CI =& get_instance();\r
-               \r
-               // Do we need to generate profile data?\r
-               // If so, load the Profile class and run it.\r
-               if ($this->enable_profiler == TRUE)\r
-               {\r
-                       $CI->load->library('profiler');                         \r
-                                                                               \r
-                       // If the output data contains closing </body> and </html> tags\r
-                       // we will remove them and add them back after we insert the profile data\r
-                       if (preg_match("|</body>.*?</html>|is", $output))\r
-                       {\r
-                               $output  = preg_replace("|</body>.*?</html>|is", '', $output);\r
-                               $output .= $CI->profiler->run();\r
-                               $output .= '</body></html>';\r
-                       }\r
-                       else\r
-                       {\r
-                               $output .= $CI->profiler->run();\r
-                       }\r
-               }\r
-               \r
-               // --------------------------------------------------------------------\r
-\r
-               // Does the controller contain a function named _output()?\r
-               // If so send the output there.  Otherwise, echo it.\r
-               if (method_exists($CI, '_output'))\r
-               {\r
-                       $CI->_output($output);\r
-               }\r
-               else\r
-               {\r
-                       echo $output;  // Send it to the browser!\r
-               }\r
-               \r
-               log_message('debug', "Final output sent to browser");\r
-               log_message('debug', "Total execution time: ".$elapsed);                \r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Write a Cache File\r
-        *\r
-        * @access      public\r
-        * @return      void\r
-        */     \r
-       function _write_cache($output)\r
-       {\r
-               $CI =& get_instance();  \r
-               $path = $CI->config->item('cache_path');\r
-       \r
-               $cache_path = ($path == '') ? BASEPATH.'cache/' : $path;\r
-               \r
-               if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))\r
-               {\r
-                       return;\r
-               }\r
-               \r
-               $uri =  $CI->config->item('base_url').\r
-                               $CI->config->item('index_page').\r
-                               $CI->uri->uri_string();\r
-               \r
-               $cache_path .= md5($uri);\r
-\r
-               if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))\r
-               {\r
-                       log_message('error', "Unable to write cache file: ".$cache_path);\r
-                       return;\r
-               }\r
-               \r
-               $expire = time() + ($this->cache_expiration * 60);\r
-               \r
-               if (flock($fp, LOCK_EX))\r
-               {\r
-                       fwrite($fp, $expire.'TS--->'.$output);\r
-                       flock($fp, LOCK_UN);\r
-               }\r
-               else\r
-               {\r
-                       log_message('error', "Unable to secure a file lock for file at: ".$cache_path);\r
-                       return;\r
-               }\r
-               fclose($fp);\r
-               @chmod($cache_path, DIR_WRITE_MODE);\r
-\r
-               log_message('debug', "Cache file written: ".$cache_path);\r
-       }\r
-\r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Update/serve a cached file\r
-        *\r
-        * @access      public\r
-        * @return      void\r
-        */     \r
-       function _display_cache(&$CFG, &$URI)\r
-       {\r
-               $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path');\r
-                       \r
-               if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))\r
-               {\r
-                       return FALSE;\r
-               }\r
-               \r
-               // Build the file path.  The file name is an MD5 hash of the full URI\r
-               $uri =  $CFG->item('base_url').\r
-                               $CFG->item('index_page').\r
-                               $URI->uri_string;\r
-                               \r
-               $filepath = $cache_path.md5($uri);\r
-               \r
-               if ( ! @file_exists($filepath))\r
-               {\r
-                       return FALSE;\r
-               }\r
-       \r
-               if ( ! $fp = @fopen($filepath, FOPEN_READ))\r
-               {\r
-                       return FALSE;\r
-               }\r
-                       \r
-               flock($fp, LOCK_SH);\r
-               \r
-               $cache = '';\r
-               if (filesize($filepath) > 0)\r
-               {\r
-                       $cache = fread($fp, filesize($filepath));\r
-               }\r
-       \r
-               flock($fp, LOCK_UN);\r
-               fclose($fp);\r
-                                       \r
-               // Strip out the embedded timestamp             \r
-               if ( ! preg_match("/(\d+TS--->)/", $cache, $match))\r
-               {\r
-                       return FALSE;\r
-               }\r
-               \r
-               // Has the file expired? If so we'll delete it.\r
-               if (time() >= trim(str_replace('TS--->', '', $match['1'])))\r
-               {               \r
-                       @unlink($filepath);\r
-                       log_message('debug', "Cache file has expired. File deleted");\r
-                       return FALSE;\r
-               }\r
-\r
-               // Display the cache\r
-               $this->_display(str_replace($match['0'], '', $cache));\r
-               log_message('debug', "Cache file is current. Sending it to browser.");          \r
-               return TRUE;\r
-       }\r
-\r
-\r
-}\r
-// END Output Class\r
-\r
-/* End of file Output.php */\r
+<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package            CodeIgniter
+ * @author             ExpressionEngine Dev Team
+ * @copyright  Copyright (c) 2008, EllisLab, Inc.
+ * @license            http://codeigniter.com/user_guide/license.html
+ * @link               http://codeigniter.com
+ * @since              Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Output Class
+ *
+ * Responsible for sending final output to browser
+ *
+ * @package            CodeIgniter
+ * @subpackage Libraries
+ * @category   Output
+ * @author             ExpressionEngine Dev Team
+ * @link               http://codeigniter.com/user_guide/libraries/output.html
+ */
+class CI_Output {
+
+       var $final_output;
+       var $cache_expiration   = 0;
+       var $headers                    = array();
+       var $enable_profiler    = FALSE;
+
+
+       function CI_Output()
+       {
+               log_message('debug', "Output Class Initialized");
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Get Output
+        *
+        * Returns the current output string
+        *
+        * @access      public
+        * @return      string
+        */     
+       function get_output()
+       {
+               return $this->final_output;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Set Output
+        *
+        * Sets the output string
+        *
+        * @access      public
+        * @param       string
+        * @return      void
+        */     
+       function set_output($output)
+       {
+               $this->final_output = $output;
+       }
+
+       // --------------------------------------------------------------------
+
+       /**
+        * Append Output
+        *
+        * Appends data onto the output string
+        *
+        * @access      public
+        * @param       string
+        * @return      void
+        */     
+       function append_output($output)
+       {
+               if ($this->final_output == '')
+               {
+                       $this->final_output = $output;
+               }
+               else
+               {
+                       $this->final_output .= $output;
+               }
+       }
+
+       // --------------------------------------------------------------------
+
+       /**
+        * Set Header
+        *
+        * Lets you set a server header which will be outputted with the final display.
+        *
+        * Note:  If a file is cached, headers will not be sent.  We need to figure out
+        * how to permit header data to be saved with the cache data...
+        *
+        * @access      public
+        * @param       string
+        * @return      void
+        */     
+       function set_header($header, $replace = TRUE)
+       {
+               $this->headers[] = array($header, $replace);
+       }
+
+       // --------------------------------------------------------------------
+       
+       /**
+        * Set HTTP Status Header
+        *
+        * @access      public
+        * @param       int     the status code
+        * @param       string  
+        * @return      void
+        */     
+       function set_status_header($code = '200', $text = '')
+       {
+               $stati = array(
+                                                       '200'   => 'OK',
+                                                       '201'   => 'Created',
+                                                       '202'   => 'Accepted',
+                                                       '203'   => 'Non-Authoritative Information',
+                                                       '204'   => 'No Content',
+                                                       '205'   => 'Reset Content',
+                                                       '206'   => 'Partial Content',
+                                                       
+                                                       '300'   => 'Multiple Choices',
+                                                       '301'   => 'Moved Permanently',
+                                                       '302'   => 'Found',
+                                                       '304'   => 'Not Modified',
+                                                       '305'   => 'Use Proxy',
+                                                       '307'   => 'Temporary Redirect',
+                                                       
+                                                       '400'   => 'Bad Request',
+                                                       '401'   => 'Unauthorized',
+                                                       '403'   => 'Forbidden',
+                                                       '404'   => 'Not Found',
+                                                       '405'   => 'Method Not Allowed',
+                                                       '406'   => 'Not Acceptable',
+                                                       '407'   => 'Proxy Authentication Required',
+                                                       '408'   => 'Request Timeout',
+                                                       '409'   => 'Conflict',
+                                                       '410'   => 'Gone',
+                                                       '411'   => 'Length Required',
+                                                       '412'   => 'Precondition Failed',
+                                                       '413'   => 'Request Entity Too Large',
+                                                       '414'   => 'Request-URI Too Long',
+                                                       '415'   => 'Unsupported Media Type',
+                                                       '416'   => 'Requested Range Not Satisfiable',
+                                                       '417'   => 'Expectation Failed',
+               
+                                                       '500'   => 'Internal Server Error',
+                                                       '501'   => 'Not Implemented',
+                                                       '502'   => 'Bad Gateway',
+                                                       '503'   => 'Service Unavailable',
+                                                       '504'   => 'Gateway Timeout',
+                                                       '505'   => 'HTTP Version Not Supported'
+                                               );
+
+               if ($code == '' OR ! is_numeric($code))
+               {
+                       show_error('Status codes must be numeric');
+               }
+
+               if (isset($stati[$code]) AND $text == '')
+               {                               
+                       $text = $stati[$code];
+               }
+               
+               if ($text == '')
+               {
+                       show_error('No status text available.  Please check your status code number or supply your own message text.');
+               }
+               
+               $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
+       
+               if (substr(php_sapi_name(), 0, 3) == 'cgi')
+               {
+                       header("Status: {$code} {$text}", TRUE);
+               }
+               elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0')
+               {
+                       header($server_protocol." {$code} {$text}", TRUE, $code);
+               }
+               else
+               {
+                       header("HTTP/1.1 {$code} {$text}", TRUE, $code);
+               }
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Enable/disable Profiler
+        *
+        * @access      public
+        * @param       bool
+        * @return      void
+        */     
+       function enable_profiler($val = TRUE)
+       {
+               $this->enable_profiler = (is_bool($val)) ? $val : TRUE;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Set Cache
+        *
+        * @access      public
+        * @param       integer
+        * @return      void
+        */     
+       function cache($time)
+       {
+               $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Display Output
+        *
+        * All "view" data is automatically put into this variable by the controller class:
+        *
+        * $this->final_output
+        *
+        * This function sends the finalized output data to the browser along
+        * with any server headers and profile data.  It also stops the
+        * benchmark timer so the page rendering speed and memory usage can be shown.
+        *
+        * @access      public
+        * @return      mixed
+        */             
+       function _display($output = '')
+       {       
+               // Note:  We use globals because we can't use $CI =& get_instance()
+               // since this function is sometimes called by the caching mechanism,
+               // which happens before the CI super object is available.
+               global $BM, $CFG;
+               
+               // --------------------------------------------------------------------
+               
+               // Set the output data
+               if ($output == '')
+               {
+                       $output =& $this->final_output;
+               }
+               
+               // --------------------------------------------------------------------
+               
+               // Do we need to write a cache file?
+               if ($this->cache_expiration > 0)
+               {
+                       $this->_write_cache($output);
+               }
+               
+               // --------------------------------------------------------------------
+
+               // Parse out the elapsed time and memory usage,
+               // then swap the pseudo-variables with the data
+
+               $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');         
+               $output = str_replace('{elapsed_time}', $elapsed, $output);
+               
+               $memory  = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';
+               $output = str_replace('{memory_usage}', $memory, $output);              
+
+               // --------------------------------------------------------------------
+               
+               // Is compression requested?
+               if ($CFG->item('compress_output') === TRUE)
+               {
+                       if (extension_loaded('zlib'))
+                       {
+                               if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
+                               {
+                                       ob_start('ob_gzhandler');
+                               }
+                       }
+               }
+
+               // --------------------------------------------------------------------
+               
+               // Are there any server headers to send?
+               if (count($this->headers) > 0)
+               {
+                       foreach ($this->headers as $header)
+                       {
+                               @header($header[0], $header[1]);
+                       }
+               }               
+
+               // --------------------------------------------------------------------
+               
+               // Does the get_instance() function exist?
+               // If not we know we are dealing with a cache file so we'll
+               // simply echo out the data and exit.
+               if ( ! function_exists('get_instance'))
+               {
+                       echo $output;
+                       log_message('debug', "Final output sent to browser");
+                       log_message('debug', "Total execution time: ".$elapsed);
+                       return TRUE;
+               }
+       
+               // --------------------------------------------------------------------
+
+               // Grab the super object.  We'll need it in a moment...
+               $CI =& get_instance();
+               
+               // Do we need to generate profile data?
+               // If so, load the Profile class and run it.
+               if ($this->enable_profiler == TRUE)
+               {
+                       $CI->load->library('profiler');                         
+                                                                               
+                       // If the output data contains closing </body> and </html> tags
+                       // we will remove them and add them back after we insert the profile data
+                       if (preg_match("|</body>.*?</html>|is", $output))
+                       {
+                               $output  = preg_replace("|</body>.*?</html>|is", '', $output);
+                               $output .= $CI->profiler->run();
+                               $output .= '</body></html>';
+                       }
+                       else
+                       {
+                               $output .= $CI->profiler->run();
+                       }
+               }
+               
+               // --------------------------------------------------------------------
+
+               // Does the controller contain a function named _output()?
+               // If so send the output there.  Otherwise, echo it.
+               if (method_exists($CI, '_output'))
+               {
+                       $CI->_output($output);
+               }
+               else
+               {
+                       echo $output;  // Send it to the browser!
+               }
+               
+               log_message('debug', "Final output sent to browser");
+               log_message('debug', "Total execution time: ".$elapsed);                
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Write a Cache File
+        *
+        * @access      public
+        * @return      void
+        */     
+       function _write_cache($output)
+       {
+               $CI =& get_instance();  
+               $path = $CI->config->item('cache_path');
+       
+               $cache_path = ($path == '') ? BASEPATH.'cache/' : $path;
+               
+               if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
+               {
+                       return;
+               }
+               
+               $uri =  $CI->config->item('base_url').
+                               $CI->config->item('index_page').
+                               $CI->uri->uri_string();
+               
+               $cache_path .= md5($uri);
+
+               if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))
+               {
+                       log_message('error', "Unable to write cache file: ".$cache_path);
+                       return;
+               }
+               
+               $expire = time() + ($this->cache_expiration * 60);
+               
+               if (flock($fp, LOCK_EX))
+               {
+                       fwrite($fp, $expire.'TS--->'.$output);
+                       flock($fp, LOCK_UN);
+               }
+               else
+               {
+                       log_message('error', "Unable to secure a file lock for file at: ".$cache_path);
+                       return;
+               }
+               fclose($fp);
+               @chmod($cache_path, DIR_WRITE_MODE);
+
+               log_message('debug', "Cache file written: ".$cache_path);
+       }
+
+       // --------------------------------------------------------------------
+       
+       /**
+        * Update/serve a cached file
+        *
+        * @access      public
+        * @return      void
+        */     
+       function _display_cache(&$CFG, &$URI)
+       {
+               $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path');
+                       
+               if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
+               {
+                       return FALSE;
+               }
+               
+               // Build the file path.  The file name is an MD5 hash of the full URI
+               $uri =  $CFG->item('base_url').
+                               $CFG->item('index_page').
+                               $URI->uri_string;
+                               
+               $filepath = $cache_path.md5($uri);
+               
+               if ( ! @file_exists($filepath))
+               {
+                       return FALSE;
+               }
+       
+               if ( ! $fp = @fopen($filepath, FOPEN_READ))
+               {
+                       return FALSE;
+               }
+                       
+               flock($fp, LOCK_SH);
+               
+               $cache = '';
+               if (filesize($filepath) > 0)
+               {
+                       $cache = fread($fp, filesize($filepath));
+               }
+       
+               flock($fp, LOCK_UN);
+               fclose($fp);
+                                       
+               // Strip out the embedded timestamp             
+               if ( ! preg_match("/(\d+TS--->)/", $cache, $match))
+               {
+                       return FALSE;
+               }
+               
+               // Has the file expired? If so we'll delete it.
+               if (time() >= trim(str_replace('TS--->', '', $match['1'])))
+               {               
+                       @unlink($filepath);
+                       log_message('debug', "Cache file has expired. File deleted");
+                       return FALSE;
+               }
+
+               // Display the cache
+               $this->_display(str_replace($match['0'], '', $cache));
+               log_message('debug', "Cache file is current. Sending it to browser.");          
+               return TRUE;
+       }
+
+
+}
+// END Output Class
+
+/* End of file Output.php */
 /* Location: ./system/libraries/Output.php */
\ No newline at end of file