Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Output Class |
| 30 | * |
| 31 | * Responsible for sending final output to browser |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Libraries |
| 35 | * @category Output |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/libraries/output.html |
| 38 | */ |
| 39 | class CI_Output { |
| 40 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 41 | /** |
| 42 | * Current output string |
| 43 | * |
| 44 | * @var string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 45 | */ |
Andrey Andreev | 0f22117 | 2012-04-13 14:52:16 +0300 | [diff] [blame] | 46 | public $final_output; |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 47 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 48 | /** |
| 49 | * Cache expiration time |
| 50 | * |
| 51 | * @var int |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 52 | */ |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 53 | public $cache_expiration = 0; |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 54 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 55 | /** |
| 56 | * List of server headers |
| 57 | * |
| 58 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 59 | */ |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 60 | public $headers = array(); |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 61 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 62 | /** |
| 63 | * List of mime types |
| 64 | * |
| 65 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 66 | */ |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 67 | public $mime_types = array(); |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 68 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 69 | /** |
| 70 | * Determines wether profiler is enabled |
| 71 | * |
| 72 | * @var book |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 73 | */ |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 74 | public $enable_profiler = FALSE; |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 75 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 76 | /** |
| 77 | * Determines if output compression is enabled |
| 78 | * |
| 79 | * @var bool |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 80 | */ |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 81 | protected $_zlib_oc = FALSE; |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 82 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 83 | /** |
| 84 | * List of profiler sections |
| 85 | * |
| 86 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 87 | */ |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 88 | protected $_profiler_sections = array(); |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 89 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 90 | /** |
| 91 | * Whether or not to parse variables like {elapsed_time} and {memory_usage} |
| 92 | * |
| 93 | * @var bool |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 94 | */ |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 95 | public $parse_exec_vars = TRUE; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 96 | |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 97 | /** |
| 98 | * Set up Output class |
| 99 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 100 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | { |
Pascal Kriete | 676e1cd | 2010-04-09 21:16:16 +0200 | [diff] [blame] | 102 | $this->_zlib_oc = @ini_get('zlib.output_compression'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 103 | |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 104 | // Get mime types for later |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 105 | if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 106 | { |
| 107 | include APPPATH.'config/'.ENVIRONMENT.'/mimes.php'; |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | include APPPATH.'config/mimes.php'; |
| 112 | } |
| 113 | |
Eric Barnes | bb5d4f7 | 2011-03-18 13:39:58 -0400 | [diff] [blame] | 114 | |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 115 | $this->mime_types = $mimes; |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 116 | log_message('debug', 'Output Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 117 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 118 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 120 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 121 | /** |
| 122 | * Get Output |
| 123 | * |
| 124 | * Returns the current output string |
| 125 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 127 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 128 | public function get_output() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | { |
| 130 | return $this->final_output; |
| 131 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 132 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 133 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 134 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | /** |
| 136 | * Set Output |
| 137 | * |
| 138 | * Sets the output string |
| 139 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 140 | * @param string |
| 141 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 142 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 143 | public function set_output($output) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 144 | { |
| 145 | $this->final_output = $output; |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 146 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | // -------------------------------------------------------------------- |
| 150 | |
| 151 | /** |
| 152 | * Append Output |
| 153 | * |
| 154 | * Appends data onto the output string |
| 155 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 156 | * @param string |
| 157 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 158 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 159 | public function append_output($output) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 160 | { |
| 161 | if ($this->final_output == '') |
| 162 | { |
| 163 | $this->final_output = $output; |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | $this->final_output .= $output; |
| 168 | } |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 169 | |
| 170 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // -------------------------------------------------------------------- |
| 174 | |
| 175 | /** |
| 176 | * Set Header |
| 177 | * |
| 178 | * Lets you set a server header which will be outputted with the final display. |
| 179 | * |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 180 | * Note: If a file is cached, headers will not be sent. We need to figure out |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 181 | * how to permit header data to be saved with the cache data... |
| 182 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | * @param string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 184 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 186 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 187 | public function set_header($header, $replace = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 188 | { |
Pascal Kriete | 676e1cd | 2010-04-09 21:16:16 +0200 | [diff] [blame] | 189 | // If zlib.output_compression is enabled it will compress the output, |
| 190 | // but it will not modify the content-length header to compensate for |
| 191 | // the reduction, causing the browser to hang waiting for more data. |
| 192 | // We'll just skip content-length in those cases. |
Pascal Kriete | 676e1cd | 2010-04-09 21:16:16 +0200 | [diff] [blame] | 193 | if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) == 0) |
| 194 | { |
| 195 | return; |
| 196 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 197 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 198 | $this->headers[] = array($header, $replace); |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 199 | return $this; |
| 200 | } |
| 201 | |
| 202 | // -------------------------------------------------------------------- |
| 203 | |
| 204 | /** |
| 205 | * Set Content Type Header |
| 206 | * |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 207 | * @param string extension of the file we're outputting |
| 208 | * @return void |
| 209 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 210 | public function set_content_type($mime_type) |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 211 | { |
| 212 | if (strpos($mime_type, '/') === FALSE) |
| 213 | { |
| 214 | $extension = ltrim($mime_type, '.'); |
| 215 | |
| 216 | // Is this extension supported? |
| 217 | if (isset($this->mime_types[$extension])) |
| 218 | { |
| 219 | $mime_type =& $this->mime_types[$extension]; |
| 220 | |
| 221 | if (is_array($mime_type)) |
| 222 | { |
| 223 | $mime_type = current($mime_type); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | $header = 'Content-Type: '.$mime_type; |
| 229 | |
| 230 | $this->headers[] = array($header, TRUE); |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 231 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | } |
Andrey Andreev | 00adf1d | 2012-04-03 12:30:50 +0300 | [diff] [blame] | 233 | |
Songpol Sripaoeiam | 52fe7bb | 2012-04-01 11:43:20 +0700 | [diff] [blame] | 234 | // -------------------------------------------------------------------- |
Andrey Andreev | 00adf1d | 2012-04-03 12:30:50 +0300 | [diff] [blame] | 235 | |
Songpol Sripaoeiam | 52fe7bb | 2012-04-01 11:43:20 +0700 | [diff] [blame] | 236 | /** |
| 237 | * Get Current Content Type Header |
Songpol Sripaoeiam | 52fe7bb | 2012-04-01 11:43:20 +0700 | [diff] [blame] | 238 | * |
Andrey Andreev | 00adf1d | 2012-04-03 12:30:50 +0300 | [diff] [blame] | 239 | * @return string 'text/html', if not already set |
Songpol Sripaoeiam | 52fe7bb | 2012-04-01 11:43:20 +0700 | [diff] [blame] | 240 | */ |
Songpol Sripaoeiam | 614db07 | 2012-04-03 01:29:28 +0700 | [diff] [blame] | 241 | public function get_content_type() |
Songpol Sripaoeiam | 52fe7bb | 2012-04-01 11:43:20 +0700 | [diff] [blame] | 242 | { |
Andrey Andreev | 00adf1d | 2012-04-03 12:30:50 +0300 | [diff] [blame] | 243 | for ($i = 0, $c = count($this->headers); $i < $c; $i++) |
Songpol Sripao-eiam | 38c0a72 | 2012-04-01 20:10:35 +0700 | [diff] [blame] | 244 | { |
Andrey Andreev | 00adf1d | 2012-04-03 12:30:50 +0300 | [diff] [blame] | 245 | if (preg_match('/^Content-Type:\s(.+)$/', $this->headers[$i][0], $matches)) |
Songpol Sripaoeiam | b966701 | 2012-04-01 17:13:44 +0700 | [diff] [blame] | 246 | { |
Andrey Andreev | 00adf1d | 2012-04-03 12:30:50 +0300 | [diff] [blame] | 247 | return $matches[1]; |
Songpol Sripaoeiam | 52fe7bb | 2012-04-01 11:43:20 +0700 | [diff] [blame] | 248 | } |
Songpol Sripaoeiam | b966701 | 2012-04-01 17:13:44 +0700 | [diff] [blame] | 249 | } |
Andrey Andreev | 00adf1d | 2012-04-03 12:30:50 +0300 | [diff] [blame] | 250 | |
Songpol Sripaoeiam | b966701 | 2012-04-01 17:13:44 +0700 | [diff] [blame] | 251 | return 'text/html'; |
Songpol Sripaoeiam | 52fe7bb | 2012-04-01 11:43:20 +0700 | [diff] [blame] | 252 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | |
| 254 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 255 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 256 | /** |
| 257 | * Set HTTP Status Header |
Derek Jones | 817163a | 2009-07-11 17:05:58 +0000 | [diff] [blame] | 258 | * moved to Common procedural functions in 1.7.2 |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 259 | * |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 260 | * @param int the status code |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 261 | * @param string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 263 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 264 | public function set_status_header($code = 200, $text = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 265 | { |
Derek Jones | 817163a | 2009-07-11 17:05:58 +0000 | [diff] [blame] | 266 | set_status_header($code, $text); |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 267 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 269 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 271 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 272 | /** |
| 273 | * Enable/disable Profiler |
| 274 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | * @param bool |
| 276 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 277 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 278 | public function enable_profiler($val = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | { |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 280 | $this->enable_profiler = is_bool($val) ? $val : TRUE; |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 281 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 282 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 283 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | // -------------------------------------------------------------------- |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 285 | |
| 286 | /** |
| 287 | * Set Profiler Sections |
| 288 | * |
| 289 | * Allows override of default / config settings for Profiler section display |
| 290 | * |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 291 | * @param array |
| 292 | * @return void |
| 293 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 294 | public function set_profiler_sections($sections) |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 295 | { |
| 296 | foreach ($sections as $section => $enable) |
| 297 | { |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 298 | $this->_profiler_sections[$section] = ($enable !== FALSE); |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 299 | } |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 300 | |
| 301 | return $this; |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 305 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 306 | /** |
| 307 | * Set Cache |
| 308 | * |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 309 | * @param int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 310 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 311 | */ |
Michiel Vugteveen | 0609d58 | 2012-01-08 13:26:17 +0100 | [diff] [blame] | 312 | public function cache($time) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | { |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 314 | $this->cache_expiration = is_numeric($time) ? $time : 0; |
Phil Sturgeon | 60ed1a3 | 2011-03-08 21:43:54 +0000 | [diff] [blame] | 315 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 317 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 319 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 320 | /** |
| 321 | * Display Output |
| 322 | * |
| 323 | * All "view" data is automatically put into this variable by the controller class: |
| 324 | * |
| 325 | * $this->final_output |
| 326 | * |
| 327 | * This function sends the finalized output data to the browser along |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 328 | * with any server headers and profile data. It also stops the |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | * benchmark timer so the page rendering speed and memory usage can be shown. |
| 330 | * |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 331 | * @param string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 332 | * @return mixed |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 333 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 334 | public function _display($output = '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 335 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 336 | // Note: We use globals because we can't use $CI =& get_instance() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | // since this function is sometimes called by the caching mechanism, |
| 338 | // which happens before the CI super object is available. |
| 339 | global $BM, $CFG; |
Derek Jones | d763349 | 2010-09-28 13:14:57 -0500 | [diff] [blame] | 340 | |
| 341 | // Grab the super object if we can. |
Greg Aker | cc92210 | 2010-11-17 20:25:08 -0600 | [diff] [blame] | 342 | if (class_exists('CI_Controller')) |
Derek Jones | d763349 | 2010-09-28 13:14:57 -0500 | [diff] [blame] | 343 | { |
| 344 | $CI =& get_instance(); |
| 345 | } |
| 346 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 348 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | // Set the output data |
| 350 | if ($output == '') |
| 351 | { |
| 352 | $output =& $this->final_output; |
| 353 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 354 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 356 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 357 | // Do we need to write a cache file? Only if the controller does not have its |
Derek Jones | d763349 | 2010-09-28 13:14:57 -0500 | [diff] [blame] | 358 | // own _output() method and we are not dealing with a cache file, which we |
| 359 | // can determine by the existence of the $CI object above |
| 360 | if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 361 | { |
| 362 | $this->_write_cache($output); |
| 363 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 364 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | // -------------------------------------------------------------------- |
| 366 | |
| 367 | // Parse out the elapsed time and memory usage, |
| 368 | // then swap the pseudo-variables with the data |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 369 | |
| 370 | $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); |
Derek Jones | 4652049 | 2010-03-02 13:53:25 -0600 | [diff] [blame] | 371 | |
| 372 | if ($this->parse_exec_vars === TRUE) |
| 373 | { |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 374 | $memory = function_exists('memory_get_usage') ? round(memory_get_usage()/1024/1024, 2).'MB' : '0'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 375 | |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 376 | $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output); |
Derek Jones | 4652049 | 2010-03-02 13:53:25 -0600 | [diff] [blame] | 377 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 378 | |
| 379 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 380 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 381 | // Is compression requested? |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 382 | if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE |
| 383 | && extension_loaded('zlib') |
| 384 | && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | { |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 386 | ob_start('ob_gzhandler'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 390 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 391 | // Are there any server headers to send? |
| 392 | if (count($this->headers) > 0) |
| 393 | { |
| 394 | foreach ($this->headers as $header) |
| 395 | { |
| 396 | @header($header[0], $header[1]); |
| 397 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 398 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 399 | |
| 400 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 401 | |
Derek Jones | d763349 | 2010-09-28 13:14:57 -0500 | [diff] [blame] | 402 | // Does the $CI object exist? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 403 | // If not we know we are dealing with a cache file so we'll |
| 404 | // simply echo out the data and exit. |
Derek Jones | d763349 | 2010-09-28 13:14:57 -0500 | [diff] [blame] | 405 | if ( ! isset($CI)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | { |
| 407 | echo $output; |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 408 | log_message('debug', 'Final output sent to browser'); |
| 409 | log_message('debug', 'Total execution time: '.$elapsed); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | return TRUE; |
| 411 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 412 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 413 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 414 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 415 | // Do we need to generate profile data? |
| 416 | // If so, load the Profile class and run it. |
| 417 | if ($this->enable_profiler == TRUE) |
| 418 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 419 | $CI->load->library('profiler'); |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 420 | if ( ! empty($this->_profiler_sections)) |
| 421 | { |
| 422 | $CI->profiler->set_sections($this->_profiler_sections); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 423 | } |
Derek Jones | ee71c80 | 2010-03-10 10:05:05 -0600 | [diff] [blame] | 424 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 425 | // If the output data contains closing </body> and </html> tags |
| 426 | // we will remove them and add them back after we insert the profile data |
Andrey Andreev | cba20b1 | 2012-01-09 10:16:41 +0200 | [diff] [blame] | 427 | $output = preg_replace('|</body>.*?</html>|is', '', $output, -1, $count).$CI->profiler->run(); |
| 428 | if ($count > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 429 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | $output .= '</body></html>'; |
| 431 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 432 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 433 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 434 | // Does the controller contain a function named _output()? |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 435 | // If so send the output there. Otherwise, echo it. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 436 | if (method_exists($CI, '_output')) |
| 437 | { |
| 438 | $CI->_output($output); |
| 439 | } |
| 440 | else |
| 441 | { |
Andrey Andreev | edc8755 | 2012-01-09 09:35:10 +0200 | [diff] [blame] | 442 | echo $output; // Send it to the browser! |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 443 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 444 | |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 445 | log_message('debug', 'Final output sent to browser'); |
| 446 | log_message('debug', 'Total execution time: '.$elapsed); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 447 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 448 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 449 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 450 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 451 | /** |
| 452 | * Write a Cache File |
| 453 | * |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 454 | * @param string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 455 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 456 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 457 | public function _write_cache($output) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 459 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 460 | $path = $CI->config->item('cache_path'); |
Greg Aker | 2eaa407 | 2010-12-21 11:44:08 -0600 | [diff] [blame] | 461 | $cache_path = ($path == '') ? APPPATH.'cache/' : $path; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 462 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 463 | if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) |
| 464 | { |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 465 | log_message('error', 'Unable to write cache file: '.$cache_path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 466 | return; |
| 467 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 468 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 469 | $uri = $CI->config->item('base_url'). |
| 470 | $CI->config->item('index_page'). |
| 471 | $CI->uri->uri_string(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 472 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 473 | $cache_path .= md5($uri); |
| 474 | |
| 475 | if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE)) |
| 476 | { |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 477 | log_message('error', 'Unable to write cache file: '.$cache_path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 478 | return; |
| 479 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 480 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 481 | $expire = time() + ($this->cache_expiration * 60); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 482 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 483 | if (flock($fp, LOCK_EX)) |
| 484 | { |
| 485 | fwrite($fp, $expire.'TS--->'.$output); |
| 486 | flock($fp, LOCK_UN); |
| 487 | } |
| 488 | else |
| 489 | { |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 490 | log_message('error', 'Unable to secure a file lock for file at: '.$cache_path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 491 | return; |
| 492 | } |
| 493 | fclose($fp); |
Derek Jones | 172e161 | 2009-10-13 14:32:48 +0000 | [diff] [blame] | 494 | @chmod($cache_path, FILE_WRITE_MODE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 495 | |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 496 | log_message('debug', 'Cache file written: '.$cache_path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 500 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 501 | /** |
| 502 | * Update/serve a cached file |
| 503 | * |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 504 | * @param object config class |
| 505 | * @param object uri class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 506 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 507 | */ |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 508 | public function _display_cache(&$CFG, &$URI) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 509 | { |
Greg Aker | 2eaa407 | 2010-12-21 11:44:08 -0600 | [diff] [blame] | 510 | $cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 511 | |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 512 | // Build the file path. The file name is an MD5 hash of the full URI |
| 513 | $uri = $CFG->item('base_url').$CFG->item('index_page').$URI->uri_string; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 514 | $filepath = $cache_path.md5($uri); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 515 | |
Andrey Andreev | c90d651 | 2012-01-08 04:35:02 +0200 | [diff] [blame] | 516 | if ( ! @file_exists($filepath) OR ! $fp = @fopen($filepath, FOPEN_READ)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 517 | { |
| 518 | return FALSE; |
| 519 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 520 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 521 | flock($fp, LOCK_SH); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 522 | |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 523 | $cache = (filesize($filepath) > 0) ? fread($fp, filesize($filepath)) : ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 524 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 525 | flock($fp, LOCK_UN); |
| 526 | fclose($fp); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 527 | |
| 528 | // Strip out the embedded timestamp |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 529 | if ( ! preg_match('/(\d+TS--->)/', $cache, $match)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 530 | { |
| 531 | return FALSE; |
| 532 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 533 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 534 | // Has the file expired? If so we'll delete it. |
Andrey Andreev | c90d651 | 2012-01-08 04:35:02 +0200 | [diff] [blame] | 535 | if (time() >= trim(str_replace('TS--->', '', $match[1])) && is_really_writable($cache_path)) |
Derek Jones | d99e603 | 2010-03-19 19:57:33 -0500 | [diff] [blame] | 536 | { |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 537 | @unlink($filepath); |
| 538 | log_message('debug', 'Cache file has expired. File deleted.'); |
| 539 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | // Display the cache |
Andrey Andreev | 1f5fbb6 | 2012-01-07 20:53:29 +0200 | [diff] [blame] | 543 | $this->_display(str_replace($match[0], '', $cache)); |
| 544 | log_message('debug', 'Cache file is current. Sending it to browser.'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 545 | return TRUE; |
| 546 | } |
| 547 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 548 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 549 | |
| 550 | /* End of file Output.php */ |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 551 | /* Location: ./system/core/Output.php */ |