blob: 3bb8f8dc015934d962882b6f944998c2dc704530 [file] [log] [blame]
Andrey Andreev1f5fbb62012-01-07 20:53:29 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev1f5fbb62012-01-07 20:53:29 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev1f5fbb62012-01-07 20:53:29 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * Output Class
30 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030031 * Responsible for sending final output to the browser.
Derek Allard2067d1a2008-11-13 22:59:24 +000032 *
33 * @package CodeIgniter
34 * @subpackage Libraries
35 * @category Output
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/libraries/output.html
38 */
39class CI_Output {
40
David Behler07b53422011-08-15 00:25:06 +020041 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030042 * Final output string
David Behler07b53422011-08-15 00:25:06 +020043 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030044 * @var string
David Behler07b53422011-08-15 00:25:06 +020045 */
Andrey Andreev0f221172012-04-13 14:52:16 +030046 public $final_output;
Andrey Andreev92ebfb62012-05-17 12:49:24 +030047
David Behler07b53422011-08-15 00:25:06 +020048 /**
49 * Cache expiration time
50 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030051 * @var int
David Behler07b53422011-08-15 00:25:06 +020052 */
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030053 public $cache_expiration = 0;
Andrey Andreev92ebfb62012-05-17 12:49:24 +030054
David Behler07b53422011-08-15 00:25:06 +020055 /**
56 * List of server headers
57 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030058 * @var array
David Behler07b53422011-08-15 00:25:06 +020059 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040060 public $headers = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030061
David Behler07b53422011-08-15 00:25:06 +020062 /**
63 * List of mime types
64 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030065 * @var array
David Behler07b53422011-08-15 00:25:06 +020066 */
Andrey Andreev6ef498b2012-06-05 22:01:58 +030067 public $mimes = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030068
David Behler07b53422011-08-15 00:25:06 +020069 /**
Thor (atiredmachine)242115c2012-01-24 23:08:11 -080070 * Mime-type for the current page
71 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030072 * @var string
Thor (atiredmachine)242115c2012-01-24 23:08:11 -080073 */
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030074 protected $mime_type = 'text/html';
Andrey Andreev0140ddd2012-06-16 01:12:56 +030075
Thor (atiredmachine)242115c2012-01-24 23:08:11 -080076 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030077 * Enable Profiler flag
David Behler07b53422011-08-15 00:25:06 +020078 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030079 * @var bool
David Behler07b53422011-08-15 00:25:06 +020080 */
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030081 public $enable_profiler = FALSE;
Andrey Andreev92ebfb62012-05-17 12:49:24 +030082
David Behler07b53422011-08-15 00:25:06 +020083 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030084 * zLib output compression flag
David Behler07b53422011-08-15 00:25:06 +020085 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030086 * @var bool
David Behler07b53422011-08-15 00:25:06 +020087 */
Andrey Andreev0140ddd2012-06-16 01:12:56 +030088 protected $_zlib_oc = FALSE;
Andrey Andreev92ebfb62012-05-17 12:49:24 +030089
David Behler07b53422011-08-15 00:25:06 +020090 /**
91 * List of profiler sections
92 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030093 * @var array
David Behler07b53422011-08-15 00:25:06 +020094 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040095 protected $_profiler_sections = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030096
David Behler07b53422011-08-15 00:25:06 +020097 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +030098 * Parse markers flag
David Behler07b53422011-08-15 00:25:06 +020099 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300100 * Whether or not to parse variables like {elapsed_time} and {memory_usage}.
101 *
102 * @var bool
David Behler07b53422011-08-15 00:25:06 +0200103 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400104 public $parse_exec_vars = TRUE;
Derek Jonesee71c802010-03-10 10:05:05 -0600105
Timothy Warrenad475052012-04-19 13:21:06 -0400106 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300107 * Class constructor
108 *
109 * Determines whether zLib output compression will be used.
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300110 *
111 * @return void
Timothy Warrenad475052012-04-19 13:21:06 -0400112 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200113 public function __construct()
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 {
Andrey Andreev9ba661b2012-06-04 14:44:34 +0300115 $this->_zlib_oc = (bool) @ini_get('zlib.output_compression');
Barry Mienydd671972010-10-04 16:33:58 +0200116
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000117 // Get mime types for later
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300118 $this->mimes =& get_mimes();
Greg Akerd96f8822011-12-27 16:23:47 -0600119
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200120 log_message('debug', 'Output Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 }
Barry Mienydd671972010-10-04 16:33:58 +0200122
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200124
Derek Allard2067d1a2008-11-13 22:59:24 +0000125 /**
126 * Get Output
127 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300128 * Returns the current output string.
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200131 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200132 public function get_output()
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 {
134 return $this->final_output;
135 }
Barry Mienydd671972010-10-04 16:33:58 +0200136
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200138
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 /**
140 * Set Output
141 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300142 * Sets the output string.
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300144 * @param string $output Output data
145 * @return object $this
Barry Mienydd671972010-10-04 16:33:58 +0200146 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200147 public function set_output($output)
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 {
149 $this->final_output = $output;
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000150 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 }
152
153 // --------------------------------------------------------------------
154
155 /**
156 * Append Output
157 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300158 * Appends data onto the output string.
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300160 * @param string $output Data to append
161 * @return object $this
Barry Mienydd671972010-10-04 16:33:58 +0200162 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200163 public function append_output($output)
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 {
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300165 if (empty($this->final_output))
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 {
167 $this->final_output = $output;
168 }
169 else
170 {
171 $this->final_output .= $output;
172 }
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000173
174 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 }
176
177 // --------------------------------------------------------------------
178
179 /**
180 * Set Header
181 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300182 * Lets you set a server header which will be sent with the final output.
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300184 * Note: If a file is cached, headers will not be sent.
185 * @todo We need to figure out how to permit headers to be cached.
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300187 * @param string $header Header
188 * @param bool $replace Whether to replace the old header value, if already set
189 * @return object $this
Barry Mienydd671972010-10-04 16:33:58 +0200190 */
Andrey Andreev44dc50e2012-10-28 13:30:21 +0200191 public function set_header($header, $replace = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 {
Pascal Kriete676e1cd2010-04-09 21:16:16 +0200193 // If zlib.output_compression is enabled it will compress the output,
194 // but it will not modify the content-length header to compensate for
195 // the reduction, causing the browser to hang waiting for more data.
196 // We'll just skip content-length in those cases.
Alex Bilbieed944a32012-06-02 11:07:47 +0100197 if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) === 0)
Pascal Kriete676e1cd2010-04-09 21:16:16 +0200198 {
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300199 return $this;
Pascal Kriete676e1cd2010-04-09 21:16:16 +0200200 }
Barry Mienydd671972010-10-04 16:33:58 +0200201
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 $this->headers[] = array($header, $replace);
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000203 return $this;
204 }
205
206 // --------------------------------------------------------------------
207
208 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300209 * Set Content-Type Header
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000210 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300211 * @param string $mime_type Extension of the file we're outputting
212 * @param string $charset Character set (default: NULL)
213 * @return object $this
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000214 */
Andrey Andreev47b67332012-06-06 15:58:05 +0300215 public function set_content_type($mime_type, $charset = NULL)
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000216 {
217 if (strpos($mime_type, '/') === FALSE)
218 {
219 $extension = ltrim($mime_type, '.');
220
221 // Is this extension supported?
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300222 if (isset($this->mimes[$extension]))
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000223 {
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300224 $mime_type =& $this->mimes[$extension];
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000225
226 if (is_array($mime_type))
227 {
228 $mime_type = current($mime_type);
229 }
230 }
231 }
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300232
Thor (atiredmachine)242115c2012-01-24 23:08:11 -0800233 $this->mime_type = $mime_type;
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000234
Andrey Andreev47b67332012-06-06 15:58:05 +0300235 if (empty($charset))
236 {
237 $charset = config_item('charset');
238 }
239
240 $header = 'Content-Type: '.$mime_type
241 .(empty($charset) ? NULL : '; charset='.strtolower($charset));
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000242
243 $this->headers[] = array($header, TRUE);
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000244 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 }
Andrey Andreev00adf1d2012-04-03 12:30:50 +0300246
Songpol Sripaoeiam52fe7bb2012-04-01 11:43:20 +0700247 // --------------------------------------------------------------------
Andrey Andreev00adf1d2012-04-03 12:30:50 +0300248
Songpol Sripaoeiam52fe7bb2012-04-01 11:43:20 +0700249 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300250 * Get Current Content-Type Header
Songpol Sripaoeiam52fe7bb2012-04-01 11:43:20 +0700251 *
Andrey Andreev00adf1d2012-04-03 12:30:50 +0300252 * @return string 'text/html', if not already set
Songpol Sripaoeiam52fe7bb2012-04-01 11:43:20 +0700253 */
Songpol Sripaoeiam614db072012-04-03 01:29:28 +0700254 public function get_content_type()
Songpol Sripaoeiam52fe7bb2012-04-01 11:43:20 +0700255 {
Andrey Andreev00adf1d2012-04-03 12:30:50 +0300256 for ($i = 0, $c = count($this->headers); $i < $c; $i++)
Songpol Sripao-eiam38c0a722012-04-01 20:10:35 +0700257 {
Andrey Andreev00adf1d2012-04-03 12:30:50 +0300258 if (preg_match('/^Content-Type:\s(.+)$/', $this->headers[$i][0], $matches))
Songpol Sripaoeiamb9667012012-04-01 17:13:44 +0700259 {
Andrey Andreev00adf1d2012-04-03 12:30:50 +0300260 return $matches[1];
Songpol Sripaoeiam52fe7bb2012-04-01 11:43:20 +0700261 }
Songpol Sripaoeiamb9667012012-04-01 17:13:44 +0700262 }
Andrey Andreev00adf1d2012-04-03 12:30:50 +0300263
Songpol Sripaoeiamb9667012012-04-01 17:13:44 +0700264 return 'text/html';
Songpol Sripaoeiam52fe7bb2012-04-01 11:43:20 +0700265 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000266
267 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200268
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 /**
270 * Set HTTP Status Header
Barry Mienydd671972010-10-04 16:33:58 +0200271 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300272 * As of version 1.7.2, this is an alias for common function
273 * set_status_header().
274 *
275 * @param int $code Status code (default: 200)
276 * @param string $text Optional message
277 * @return object $this
Barry Mienydd671972010-10-04 16:33:58 +0200278 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200279 public function set_status_header($code = 200, $text = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 {
Derek Jones817163a2009-07-11 17:05:58 +0000281 set_status_header($code, $text);
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000282 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 }
Barry Mienydd671972010-10-04 16:33:58 +0200284
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200286
Derek Allard2067d1a2008-11-13 22:59:24 +0000287 /**
288 * Enable/disable Profiler
289 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300290 * @param bool $val TRUE to enable or FALSE to disable
291 * @return object $this
Barry Mienydd671972010-10-04 16:33:58 +0200292 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200293 public function enable_profiler($val = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000294 {
Andrey Andreev7b53d042012-03-26 23:02:32 +0300295 $this->enable_profiler = is_bool($val) ? $val : TRUE;
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000296 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 }
Barry Mienydd671972010-10-04 16:33:58 +0200298
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 // --------------------------------------------------------------------
Derek Jonesee71c802010-03-10 10:05:05 -0600300
301 /**
302 * Set Profiler Sections
303 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300304 * Allows override of default/config settings for
305 * Profiler section display.
Derek Jonesee71c802010-03-10 10:05:05 -0600306 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300307 * @param array $sections Profiler sections
308 * @return object $this
Derek Jonesee71c802010-03-10 10:05:05 -0600309 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200310 public function set_profiler_sections($sections)
Derek Jonesee71c802010-03-10 10:05:05 -0600311 {
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300312 if (isset($sections['query_toggle_count']))
313 {
314 $this->_profiler_sections['query_toggle_count'] = (int) $sections['query_toggle_count'];
315 unset($sections['query_toggle_count']);
316 }
317
Derek Jonesee71c802010-03-10 10:05:05 -0600318 foreach ($sections as $section => $enable)
319 {
Andrey Andreev7b53d042012-03-26 23:02:32 +0300320 $this->_profiler_sections[$section] = ($enable !== FALSE);
Derek Jonesee71c802010-03-10 10:05:05 -0600321 }
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000322
323 return $this;
Derek Jonesee71c802010-03-10 10:05:05 -0600324 }
325
326 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200327
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 /**
329 * Set Cache
330 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300331 * @param int $time Cache expiration time in seconds
332 * @return object $this
Barry Mienydd671972010-10-04 16:33:58 +0200333 */
Michiel Vugteveen0609d582012-01-08 13:26:17 +0100334 public function cache($time)
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 {
Andrey Andreev7b53d042012-03-26 23:02:32 +0300336 $this->cache_expiration = is_numeric($time) ? $time : 0;
Phil Sturgeon60ed1a32011-03-08 21:43:54 +0000337 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 }
Barry Mienydd671972010-10-04 16:33:58 +0200339
Derek Allard2067d1a2008-11-13 22:59:24 +0000340 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200341
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 /**
343 * Display Output
344 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300345 * Processes sends the sends finalized output data to the browser along
346 * with any server headers and profile data. It also stops benchmark
347 * timers so the page rendering speed and memory usage can be shown.
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300349 * Note: All "view" data is automatically put into $this->final_output
350 * by controller class.
Derek Allard2067d1a2008-11-13 22:59:24 +0000351 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300352 * @uses CI_Output::$final_output
353 * @param string $output Output data override
354 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200355 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200356 public function _display($output = '')
Barry Mienydd671972010-10-04 16:33:58 +0200357 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500358 // Note: We use globals because we can't use $CI =& get_instance()
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 // since this function is sometimes called by the caching mechanism,
360 // which happens before the CI super object is available.
361 global $BM, $CFG;
Derek Jonesd7633492010-09-28 13:14:57 -0500362
363 // Grab the super object if we can.
Greg Akercc922102010-11-17 20:25:08 -0600364 if (class_exists('CI_Controller'))
Derek Jonesd7633492010-09-28 13:14:57 -0500365 {
366 $CI =& get_instance();
367 }
368
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200370
Derek Allard2067d1a2008-11-13 22:59:24 +0000371 // Set the output data
Alex Bilbieed944a32012-06-02 11:07:47 +0100372 if ($output === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 {
374 $output =& $this->final_output;
375 }
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300376
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800377 // --------------------------------------------------------------------
378
379 // Is minify requested?
380 if ($CFG->item('minify_output') === TRUE)
381 {
Thor (atiredmachine)5528c0e2012-01-25 01:02:28 -0800382 $output = $this->minify($output, $this->mime_type);
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800383 }
384
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200386
vkeranova8349bc2012-10-27 18:07:59 +0300387 // Do we need to write a cache file? Only if the controller does not have its
Derek Jonesd7633492010-09-28 13:14:57 -0500388 // own _output() method and we are not dealing with a cache file, which we
389 // can determine by the existence of the $CI object above
390 if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 {
392 $this->_write_cache($output);
393 }
Barry Mienydd671972010-10-04 16:33:58 +0200394
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 // --------------------------------------------------------------------
396
397 // Parse out the elapsed time and memory usage,
398 // then swap the pseudo-variables with the data
Barry Mienydd671972010-10-04 16:33:58 +0200399
400 $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');
Derek Jones46520492010-03-02 13:53:25 -0600401
402 if ($this->parse_exec_vars === TRUE)
403 {
Andrey Andreevc839d282012-06-07 14:35:27 +0300404 $memory = round(memory_get_usage() / 1024 / 1024, 2).'MB';
Barry Mienydd671972010-10-04 16:33:58 +0200405
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200406 $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output);
Derek Jones46520492010-03-02 13:53:25 -0600407 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000408
409 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200410
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 // Is compression requested?
Alex Bilbieed944a32012-06-02 11:07:47 +0100412 if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc === FALSE
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200413 && extension_loaded('zlib')
414 && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 {
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200416 ob_start('ob_gzhandler');
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 }
418
419 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200420
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 // Are there any server headers to send?
422 if (count($this->headers) > 0)
423 {
424 foreach ($this->headers as $header)
425 {
426 @header($header[0], $header[1]);
427 }
Barry Mienydd671972010-10-04 16:33:58 +0200428 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000429
430 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200431
Derek Jonesd7633492010-09-28 13:14:57 -0500432 // Does the $CI object exist?
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 // If not we know we are dealing with a cache file so we'll
434 // simply echo out the data and exit.
Derek Jonesd7633492010-09-28 13:14:57 -0500435 if ( ! isset($CI))
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 {
437 echo $output;
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200438 log_message('debug', 'Final output sent to browser');
439 log_message('debug', 'Total execution time: '.$elapsed);
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300440 return;
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 }
Barry Mienydd671972010-10-04 16:33:58 +0200442
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 // Do we need to generate profile data?
446 // If so, load the Profile class and run it.
Alex Bilbieed944a32012-06-02 11:07:47 +0100447 if ($this->enable_profiler === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 {
Barry Mienydd671972010-10-04 16:33:58 +0200449 $CI->load->library('profiler');
Derek Jonesee71c802010-03-10 10:05:05 -0600450 if ( ! empty($this->_profiler_sections))
451 {
452 $CI->profiler->set_sections($this->_profiler_sections);
Barry Mienydd671972010-10-04 16:33:58 +0200453 }
Derek Jonesee71c802010-03-10 10:05:05 -0600454
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 // If the output data contains closing </body> and </html> tags
456 // we will remove them and add them back after we insert the profile data
Andrey Andreevcba20b12012-01-09 10:16:41 +0200457 $output = preg_replace('|</body>.*?</html>|is', '', $output, -1, $count).$CI->profiler->run();
458 if ($count > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000459 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 $output .= '</body></html>';
461 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 }
Barry Mienydd671972010-10-04 16:33:58 +0200463
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 // Does the controller contain a function named _output()?
Derek Jones37f4b9c2011-07-01 17:56:50 -0500465 // If so send the output there. Otherwise, echo it.
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 if (method_exists($CI, '_output'))
467 {
468 $CI->_output($output);
469 }
470 else
471 {
Andrey Andreevedc87552012-01-09 09:35:10 +0200472 echo $output; // Send it to the browser!
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 }
Barry Mienydd671972010-10-04 16:33:58 +0200474
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200475 log_message('debug', 'Final output sent to browser');
476 log_message('debug', 'Total execution time: '.$elapsed);
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 }
Barry Mienydd671972010-10-04 16:33:58 +0200478
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200480
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300482 * Write Cache
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300484 * @param string $output Output data to cache
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200486 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200487 public function _write_cache($output)
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 {
Barry Mienydd671972010-10-04 16:33:58 +0200489 $CI =& get_instance();
Derek Allard2067d1a2008-11-13 22:59:24 +0000490 $path = $CI->config->item('cache_path');
Alex Bilbieed944a32012-06-02 11:07:47 +0100491 $cache_path = ($path === '') ? APPPATH.'cache/' : $path;
Barry Mienydd671972010-10-04 16:33:58 +0200492
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
494 {
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200495 log_message('error', 'Unable to write cache file: '.$cache_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 return;
497 }
Barry Mienydd671972010-10-04 16:33:58 +0200498
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 $uri = $CI->config->item('base_url').
500 $CI->config->item('index_page').
501 $CI->uri->uri_string();
Barry Mienydd671972010-10-04 16:33:58 +0200502
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 $cache_path .= md5($uri);
504
505 if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))
506 {
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200507 log_message('error', 'Unable to write cache file: '.$cache_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000508 return;
509 }
Barry Mienydd671972010-10-04 16:33:58 +0200510
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 $expire = time() + ($this->cache_expiration * 60);
Barry Mienydd671972010-10-04 16:33:58 +0200512
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 if (flock($fp, LOCK_EX))
514 {
515 fwrite($fp, $expire.'TS--->'.$output);
516 flock($fp, LOCK_UN);
517 }
518 else
519 {
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200520 log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 return;
522 }
523 fclose($fp);
Derek Jones172e1612009-10-13 14:32:48 +0000524 @chmod($cache_path, FILE_WRITE_MODE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000525
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200526 log_message('debug', 'Cache file written: '.$cache_path);
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300527
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800528 // Send HTTP cache-control headers to browser to match file cache settings.
Thor (atiredmachine)5528c0e2012-01-25 01:02:28 -0800529 $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 }
531
532 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200533
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300535 * Update/serve cached output
Derek Allard2067d1a2008-11-13 22:59:24 +0000536 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300537 * @uses CI_Config
538 * @uses CI_URI
539 *
540 * @param object &$CFG CI_Config class instance
541 * @param object &$URI CI_URI class instance
542 * @return bool TRUE on success or FALSE on failure
Barry Mienydd671972010-10-04 16:33:58 +0200543 */
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200544 public function _display_cache(&$CFG, &$URI)
Derek Allard2067d1a2008-11-13 22:59:24 +0000545 {
Alex Bilbieed944a32012-06-02 11:07:47 +0100546 $cache_path = ($CFG->item('cache_path') === '') ? APPPATH.'cache/' : $CFG->item('cache_path');
Barry Mienydd671972010-10-04 16:33:58 +0200547
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200548 // Build the file path. The file name is an MD5 hash of the full URI
549 $uri = $CFG->item('base_url').$CFG->item('index_page').$URI->uri_string;
Derek Allard2067d1a2008-11-13 22:59:24 +0000550 $filepath = $cache_path.md5($uri);
Barry Mienydd671972010-10-04 16:33:58 +0200551
Andrey Andreevc90d6512012-01-08 04:35:02 +0200552 if ( ! @file_exists($filepath) OR ! $fp = @fopen($filepath, FOPEN_READ))
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 {
554 return FALSE;
555 }
Barry Mienydd671972010-10-04 16:33:58 +0200556
Derek Allard2067d1a2008-11-13 22:59:24 +0000557 flock($fp, LOCK_SH);
Barry Mienydd671972010-10-04 16:33:58 +0200558
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200559 $cache = (filesize($filepath) > 0) ? fread($fp, filesize($filepath)) : '';
Barry Mienydd671972010-10-04 16:33:58 +0200560
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 flock($fp, LOCK_UN);
562 fclose($fp);
Barry Mienydd671972010-10-04 16:33:58 +0200563
564 // Strip out the embedded timestamp
vlakoff239e0e52012-09-16 19:16:33 +0200565 if ( ! preg_match('/^(\d+)TS--->/', $cache, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000566 {
567 return FALSE;
568 }
Barry Mienydd671972010-10-04 16:33:58 +0200569
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800570 $last_modified = filemtime($cache_path);
vlakoff239e0e52012-09-16 19:16:33 +0200571 $expire = $match[1];
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800572
573 // Has the file expired?
574 if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path))
Derek Jonesd99e6032010-03-19 19:57:33 -0500575 {
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800576 // If so we'll delete it.
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200577 @unlink($filepath);
578 log_message('debug', 'Cache file has expired. File deleted.');
579 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 }
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800581 else
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300582 {
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800583 // Or else send the HTTP cache control headers.
Thor (atiredmachine)5528c0e2012-01-25 01:02:28 -0800584 $this->set_cache_header($last_modified, $expire);
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800585 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000586
587 // Display the cache
vlakoff1288fe32012-07-23 16:22:06 +0200588 $this->_display(substr($cache, strlen($match[0])));
Andrey Andreev1f5fbb62012-01-07 20:53:29 +0200589 log_message('debug', 'Cache file is current. Sending it to browser.');
Derek Allard2067d1a2008-11-13 22:59:24 +0000590 return TRUE;
591 }
592
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800593 // --------------------------------------------------------------------
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300594
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800595 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300596 * Set Cache Header
597 *
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800598 * Set the HTTP headers to match the server-side file cache settings
599 * in order to reduce bandwidth.
600 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300601 * @param int $last_modified Timestamp of when the page was last modified
602 * @param int $expiration Timestamp of when should the requested page expire from cache
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800603 * @return void
604 */
Thor (atiredmachine)5528c0e2012-01-25 01:02:28 -0800605 public function set_cache_header($last_modified, $expiration)
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300606 {
607 $max_age = $expiration - $_SERVER['REQUEST_TIME'];
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800608
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300609 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800610 {
611 $this->set_status_header(304);
612 exit;
613 }
614 else
615 {
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300616 header('Pragma: public');
Thor (atiredmachine)c8efb802012-01-24 13:33:39 -0800617 header('Cache-Control: max-age=' . $max_age . ', public');
618 header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT');
619 header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT');
620 }
621 }
622
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800623 // --------------------------------------------------------------------
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300624
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800625 /**
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300626 * Minify
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800627 *
Andrey Andreevb9fe7e92012-10-27 18:45:59 +0300628 * Reduce excessive size of HTML/CSS/JavaScript content.
629 *
630 * @param string $output Output to minify
631 * @param string $type Output content MIME type
632 * @return string Minified output
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800633 */
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300634 public function minify($output, $type = 'text/html')
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800635 {
636 switch ($type)
637 {
Thor (atiredmachine)1d0661a2012-01-24 21:39:16 -0800638 case 'text/html':
Thor (atiredmachine)f59ec6f2012-01-24 22:19:14 -0800639
640 $size_before = strlen($output);
641
Phil Sturgeon7a744a82012-06-23 17:21:00 +0100642 if ($size_before === 0)
643 {
644 return '';
645 }
646
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800647 // Find all the <pre>,<code>,<textarea>, and <javascript> tags
648 // We'll want to return them to this unprocessed state later.
Thor (atiredmachine)5528c0e2012-01-25 01:02:28 -0800649 preg_match_all('{<pre.+</pre>}msU', $output, $pres_clean);
650 preg_match_all('{<code.+</code>}msU', $output, $codes_clean);
651 preg_match_all('{<textarea.+</textarea>}msU', $output, $textareas_clean);
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800652 preg_match_all('{<script.+</script>}msU', $output, $javascript_clean);
Thor (atiredmachine)79db4cd2012-01-24 20:44:51 -0800653
Thor (atiredmachine)d68c8192012-01-24 20:56:21 -0800654 // Minify the CSS in all the <style> tags.
Thor (atiredmachine)5528c0e2012-01-25 01:02:28 -0800655 preg_match_all('{<style.+</style>}msU', $output, $style_clean);
Thor (atiredmachine)79db4cd2012-01-24 20:44:51 -0800656 foreach ($style_clean[0] as $s)
657 {
Thor1b8d0ef2012-01-28 01:48:04 -0800658 $output = str_replace($s, $this->minify($s, 'text/css'), $output);
Thor (atiredmachine)79db4cd2012-01-24 20:44:51 -0800659 }
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300660
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800661 // Minify the javascript in <script> tags.
662 foreach ($javascript_clean[0] as $s)
663 {
Thor1b8d0ef2012-01-28 01:48:04 -0800664 $javascript_mini[] = $this->minify($s, 'text/javascript');
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800665 }
Thor (atiredmachine)79db4cd2012-01-24 20:44:51 -0800666
Thor (atiredmachine)a2ae6e12012-01-24 20:57:48 -0800667 // Replace multiple spaces with a single space.
Thor1b8d0ef2012-01-28 01:48:04 -0800668 $output = preg_replace('!\s{2,}!', ' ', $output);
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300669
Thor (atiredmachine)5de11752012-01-24 22:08:36 -0800670 // Remove comments (non-MSIE conditionals)
Thor (atiredmachine)5528c0e2012-01-25 01:02:28 -0800671 $output = preg_replace('{\s*<!--[^\[].*-->\s*}msU', '', $output);
Thor (atiredmachine)5de11752012-01-24 22:08:36 -0800672
Thor (atiredmachine)a2ae6e12012-01-24 20:57:48 -0800673 // Remove spaces around block-level elements.
Phil Sturgeon3b6af432012-06-21 09:21:17 -0500674 $output = preg_replace('/\s*(<\/?(html|head|title|meta|script|link|style|body|h[1-6]|div|p|br)[^>]*>)\s*/is', '$1', $output);
Thor (atiredmachine)79db4cd2012-01-24 20:44:51 -0800675
Thor (atiredmachine)d68c8192012-01-24 20:56:21 -0800676 // Replace mangled <pre> etc. tags with unprocessed ones.
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300677
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800678 if ( ! empty($pres_clean))
679 {
680 preg_match_all('{<pre.+</pre>}msU', $output, $pres_messed);
681 $output = str_replace($pres_messed[0], $pres_clean[0], $output);
682 }
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300683
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800684 if ( ! empty($codes_clean))
685 {
686 preg_match_all('{<code.+</code>}msU', $output, $codes_messed);
687 $output = str_replace($codes_messed[0], $codes_clean[0], $output);
688 }
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300689
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800690 if ( ! empty($codes_clean))
691 {
692 preg_match_all('{<textarea.+</textarea>}msU', $output, $textareas_messed);
693 $output = str_replace($textareas_messed[0], $textareas_clean[0], $output);
694 }
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300695
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800696 if (isset($javascript_mini))
697 {
698 preg_match_all('{<script.+</script>}msU', $output, $javascript_messed);
699 $output = str_replace($javascript_messed[0], $javascript_mini, $output);
700 }
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300701
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800702 $size_removed = $size_before - strlen($output);
703 $savings_percent = round(($size_removed / $size_before * 100));
704
705 log_message('debug', 'Minifier shaved '.($size_removed / 1000).'KB ('.$savings_percent.'%) off final HTML output.');
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800706
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800707 break;
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300708
Thor (atiredmachine)1d0661a2012-01-24 21:39:16 -0800709 case 'text/css':
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300710
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800711 //Remove CSS comments
712 $output = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $output);
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300713
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800714 // Remove spaces around curly brackets, colons,
715 // semi-colons, parenthesis, commas
716 $output = preg_replace('!\s*(:|;|,|}|{|\(|\))\s*!', '$1', $output);
717
718 break;
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300719
Thor (atiredmachine)5c078ce2012-01-26 17:18:35 -0800720 case 'text/javascript':
721
Thor1b8d0ef2012-01-28 01:48:04 -0800722 // Currently leaves JavaScript untouched.
Thor (atiredmachine)79db4cd2012-01-24 20:44:51 -0800723 break;
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300724
725 default: break;
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800726 }
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300727
Thor (atiredmachine)63678a22012-01-24 16:56:01 -0800728 return $output;
729 }
730
Derek Allard2067d1a2008-11-13 22:59:24 +0000731}
Derek Allard2067d1a2008-11-13 22:59:24 +0000732
733/* End of file Output.php */
Andrey Andreev0140ddd2012-06-16 01:12:56 +0300734/* Location: ./system/core/Output.php */