Fixed bug #15580: Add calls to logDeprecatedFunction() for more deprecated functions...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_fecompression.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2010 Dmitry Dulepov <dmitry@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * This class contains compression functions for the TYPO3 Frontend. It can be
27 * used only in EXT:cms/tslib/index_ts.php
28 *
29 * $Id$
30 *
31 * @author Dmitry Dulepov <dmitry@typo3.org>
32 * @package TYPO3
33 * @subpackage tx_cms
34 */
35 class tslib_fecompression implements t3lib_Singleton {
36
37 /**
38 * Accumulates content length for the compressed content. It is necessary to
39 * replace the Content-length HTTP header after compression if it was added
40 * by TYPO3 before compression.
41 *
42 * @var int
43 */
44 protected $contentLength = 0;
45
46 /**
47 * Corrects HTTP "Content-length" header if it was sent by TYPO3 and compression
48 * is enabled.
49 *
50 * @param string $outputBuffer Output buffer to compress
51 * @param int $mode One of PHP_OUTPUT_HANDLER_xxx contants
52 * @return string Compressed string
53 * @see ob_start()
54 * @see ob_gzhandler()
55 */
56 function compressionOutputHandler($outputBuffer, $mode) {
57 // Compress the content
58 $outputBuffer = ob_gzhandler($outputBuffer, $mode);
59 if ($outputBuffer !== false) {
60 // Save compressed size
61 $this->contentLength += strlen($outputBuffer);
62
63 // Check if this was the last content chunk
64 if (0 != ($mode & PHP_OUTPUT_HANDLER_END)) {
65 // Check if we have content-length header
66 foreach (headers_list() as $header) {
67 if (0 == strncasecmp('Content-length:', $header, 15)) {
68 header('Content-length: ' . $this->contentLength);
69 break;
70 }
71 }
72 }
73 }
74 return $outputBuffer;
75 }
76 }
77
78 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/tslib/class.tslib_fecompression.php']) {
79 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/tslib/class.tslib_fecompression.php']);
80 }
81
82 ?>