summaryrefslogtreecommitdiffstats
path: root/system/core/Output.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/core/Output.php')
-rw-r--r--system/core/Output.php95
1 files changed, 78 insertions, 17 deletions
diff --git a/system/core/Output.php b/system/core/Output.php
index 7fb9f7916..562dbb86b 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
@@ -28,19 +28,32 @@
*/
class CI_Output {
- var $final_output;
- var $cache_expiration = 0;
- var $headers = array();
- var $enable_profiler = FALSE;
- var $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage}
-
- var $_zlib_oc = FALSE;
- var $_profiler_sections = array();
+ protected $final_output;
+ protected $cache_expiration = 0;
+ protected $headers = array();
+ protected $mime_types = array();
+ protected $enable_profiler = FALSE;
+ protected $_zlib_oc = FALSE;
+ protected $_profiler_sections = array();
+ protected $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage}
function __construct()
{
$this->_zlib_oc = @ini_get('zlib.output_compression');
+ // Get mime types for later
+ if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
+ {
+ include APPPATH.'config/'.ENVIRONMENT.'/mimes.php';
+ }
+ else
+ {
+ include APPPATH.'config/mimes.php';
+ }
+
+
+ $this->mime_types = $mimes;
+
log_message('debug', "Output Class Initialized");
}
@@ -73,6 +86,8 @@ class CI_Output {
function set_output($output)
{
$this->final_output = $output;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -96,6 +111,8 @@ class CI_Output {
{
$this->final_output .= $output;
}
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -105,7 +122,7 @@ class CI_Output {
*
* 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
+ * 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
@@ -125,6 +142,42 @@ class CI_Output {
}
$this->headers[] = array($header, $replace);
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set Content Type Header
+ *
+ * @access public
+ * @param string extension of the file we're outputting
+ * @return void
+ */
+ function set_content_type($mime_type)
+ {
+ if (strpos($mime_type, '/') === FALSE)
+ {
+ $extension = ltrim($mime_type, '.');
+
+ // Is this extension supported?
+ if (isset($this->mime_types[$extension]))
+ {
+ $mime_type =& $this->mime_types[$extension];
+
+ if (is_array($mime_type))
+ {
+ $mime_type = current($mime_type);
+ }
+ }
+ }
+
+ $header = 'Content-Type: '.$mime_type;
+
+ $this->headers[] = array($header, TRUE);
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -141,6 +194,8 @@ class CI_Output {
function set_status_header($code = 200, $text = '')
{
set_status_header($code, $text);
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -155,6 +210,8 @@ class CI_Output {
function enable_profiler($val = TRUE)
{
$this->enable_profiler = (is_bool($val)) ? $val : TRUE;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -174,6 +231,8 @@ class CI_Output {
{
$this->_profiler_sections[$section] = ($enable !== FALSE) ? TRUE : FALSE;
}
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -188,6 +247,8 @@ class CI_Output {
function cache($time)
{
$this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -200,7 +261,7 @@ class CI_Output {
* $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
+ * 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
@@ -208,7 +269,7 @@ class CI_Output {
*/
function _display($output = '')
{
- // Note: We use globals because we can't use $CI =& get_instance()
+ // 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;
@@ -229,7 +290,7 @@ class CI_Output {
// --------------------------------------------------------------------
- // Do we need to write a cache file? Only if the controller does not have its
+ // Do we need to write a cache file? Only if the controller does not have its
// own _output() method and we are not dealing with a cache file, which we
// can determine by the existence of the $CI object above
if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output'))
@@ -307,7 +368,7 @@ class CI_Output {
// 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 = preg_replace("|</body>.*?</html>|is", '', $output);
$output .= $CI->profiler->run();
$output .= '</body></html>';
}
@@ -320,14 +381,14 @@ class CI_Output {
// --------------------------------------------------------------------
// Does the controller contain a function named _output()?
- // If so send the output there. Otherwise, echo it.
+ // 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!
+ echo $output; // Send it to the browser!
}
log_message('debug', "Final output sent to browser");
@@ -397,7 +458,7 @@ class CI_Output {
{
$cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path');
- // Build the file path. The file name is an MD5 hash of the full URI
+ // 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;