Version 3.4.5

This commit is contained in:
Neo committed 2025-12-19 00:38:12 -08:00
1 parent fb6b5baabc
commit e4478369d8
1360 files changed
+228921 -179445

No files matched your search

+51 -42
View File
@@ -33,11 +33,11 @@
* </code>
*
* For more control over headers, use getHeaders() and getData() and send your
* own output.
*
* Note: If you don't need header mgmt, use PHP's native gzencode, gzdeflate,
* and gzcompress functions for gzip, deflate, and compress-encoding
* respectively.
* own output.
*
* Note: If you don't need header mgmt, use PHP's native gzencode, gzdeflate,
* and gzcompress functions for gzip, deflate, and compress-encoding
* respectively.
*
* @package Minify
* @subpackage HTTP
@@ -59,7 +59,7 @@ class HTTP_Encoder {
*
* @var bool
*/
public static $encodeToIe6 = false;
public static $encodeToIe6 = true;
/**
@@ -85,13 +85,16 @@ class HTTP_Encoder {
* method. If not set, the best method will be chosen by getAcceptedEncoding()
* The available methods are 'gzip', 'deflate', 'compress', and '' (no
* encoding)
*
* @return null
*/
public function __construct($spec)
public function __construct($spec)
{
$this->_useMbStrlen = (function_exists('mb_strlen')
&& (ini_get('mbstring.func_overload') !== '')
&& ((int)ini_get('mbstring.func_overload') & 2));
$this->_content = $spec['content'];
$this->_headers['Content-Length'] = (string)strlen($this->_content);
$this->_headers['Content-Length'] = $this->_useMbStrlen
? (string)mb_strlen($this->_content, '8bit')
: (string)strlen($this->_content);
if (isset($spec['type'])) {
$this->_headers['Content-Type'] = $spec['type'];
}
@@ -109,9 +112,9 @@ class HTTP_Encoder {
*
* Call after encode() for encoded content.
*
* return string
* @return string
*/
public function getContent()
public function getContent()
{
return $this->_content;
}
@@ -130,7 +133,7 @@ class HTTP_Encoder {
*
* @return array
*/
public function getHeaders()
public function getHeaders()
{
return $this->_headers;
}
@@ -143,10 +146,8 @@ class HTTP_Encoder {
* not handled purposefully.
*
* @see getHeaders()
*
* @return null
*/
public function sendHeaders()
public function sendHeaders()
{
foreach ($this->_headers as $name => $val) {
header($name . ': ' . $val);
@@ -161,10 +162,8 @@ class HTTP_Encoder {
* You must call this before headers are sent and it probably cannot be
* used in conjunction with zlib output buffering / mod_gzip. Errors are
* not handled purposefully.
*
* @return null
*/
public function sendAll()
public function sendAll()
{
$this->sendHeaders();
echo $this->_content;
@@ -181,21 +180,21 @@ class HTTP_Encoder {
* be non 0. The methods are favored in order of gzip, deflate, then
* compress. Deflate is always smallest and generally faster, but is
* rarely sent by servers, so client support could be buggier.
*
*
* @param bool $allowCompress allow the older compress encoding
*
* @param bool $allowDeflate allow the more recent deflate encoding
* @param bool $allowDeflate allow the more recent deflate encoding
*
* @return array two values, 1st is the actual encoding method, 2nd is the
* alias of that method to use in the Content-Encoding header (some browsers
* call gzip "x-gzip" etc.)
*/
public static function getAcceptedEncoding($allowCompress = true, $allowDeflate = true)
public static function getAcceptedEncoding($allowCompress = true, $allowDeflate = true)
{
// @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
if (! isset($_SERVER['HTTP_ACCEPT_ENCODING'])
|| self::_isBuggyIe())
|| self::isBuggyIe())
{
return array('', '');
}
@@ -244,16 +243,18 @@ class HTTP_Encoder {
* this fails, false is returned.
*
* The header "Vary: Accept-Encoding" is added. If encoding is successful,
* the Content-Length header is updated, and Content-Encoding is also added.
*
* the Content-Length header is updated, and Content-Encoding is also added.
*
* @param int $compressionLevel given to zlib functions. If not given, the
* class default will be used.
*
* @return bool success true if the content was actually compressed
*/
public function encode($compressionLevel = null)
public function encode($compressionLevel = null)
{
$this->_headers['Vary'] = 'Accept-Encoding';
if (! self::isBuggyIe()) {
$this->_headers['Vary'] = 'Accept-Encoding';
}
if (null === $compressionLevel) {
$compressionLevel = self::$compressionLevel;
}
@@ -262,9 +263,9 @@ class HTTP_Encoder {
|| !extension_loaded('zlib'))
{
return false;
}
if ($this->_encodeMethod[0] === 'deflate') {
$encoded = gzdeflate($this->_content, $compressionLevel);
}
if ($this->_encodeMethod[0] === 'deflate') {
$encoded = gzdeflate($this->_content, $compressionLevel);
} elseif ($this->_encodeMethod[0] === 'gzip') {
$encoded = gzencode($this->_content, $compressionLevel);
} else {
@@ -273,7 +274,9 @@ class HTTP_Encoder {
if (false === $encoded) {
return false;
}
$this->_headers['Content-Length'] = strlen($encoded);
$this->_headers['Content-Length'] = $this->_useMbStrlen
? (string)mb_strlen($encoded, '8bit')
: (string)strlen($encoded);
$this->_headers['Content-Encoding'] = $this->_encodeMethod[1];
$this->_content = $encoded;
return true;
@@ -285,7 +288,7 @@ class HTTP_Encoder {
* This is a convenience method for common use of the class
*
* @param string $content
*
*
* @param int $compressionLevel given to zlib functions. If not given, the
* class default will be used.
*
@@ -296,21 +299,22 @@ class HTTP_Encoder {
if (null === $compressionLevel) {
$compressionLevel = self::$compressionLevel;
}
$he = new HTTP_Encoder(array('content' => $content));
$ret = $he->encode($compressionLevel);
$he = new HTTP_Encoder(array('content' => $content));
$ret = $he->encode($compressionLevel);
$he->sendAll();
return $ret;
}
protected $_content = '';
protected $_headers = array();
protected $_encodeMethod = array('', '');
}
/**
* Is the browser an IE version earlier than 6 SP2?
* Is the browser an IE version earlier than 6 SP2?
*
* @return bool
*/
protected static function _isBuggyIe()
public static function isBuggyIe()
{
if (empty($_SERVER['HTTP_USER_AGENT'])) {
return false;
}
$ua = $_SERVER['HTTP_USER_AGENT'];
// quick escape for non-IEs
if (0 !== strpos($ua, 'Mozilla/4.0 (compatible; MSIE ')
@@ -318,9 +322,14 @@ class HTTP_Encoder {
return false;
}
// no regex = faaast
$version = (float)substr($ua, 30);
$version = (float)substr($ua, 30);
return self::$encodeToIe6
? ($version < 6 || ($version == 6 && false === strpos($ua, 'SV1')))
: ($version < 7);
}
protected $_content = '';
protected $_headers = array();
protected $_encodeMethod = array('', '');
protected $_useMbStrlen = false;
}