Файл: adultscript-2.0.3-pro/files/libraries/framework/response.php
Строк: 102
<?php
defined('_VALID') or die('Restricted Access!');
define('CLEAN_OUTPUT', FALSE);
class VResponse
{
private static $headers = array();
public static function add_header($name, $value=FALSE, $replace=FALSE)
{
$name = (string) $name;
if ($value !== FALSE) {
$value = (string) $value;
}
if ($replace !== FALSE) {
self::del_header($name);
}
$set = FALSE;
foreach (self::$headers as $header) {
if ($header['name'] == $name) {
$set = TRUE;
}
}
if ($set === FALSE) {
self::$headers[] = array('name' => $name, 'value' => $value);
}
}
public static function del_header($name)
{
foreach (self::$headers as $key => $header) {
if ($header['name'] == $name) {
unset(self::$headers[$key]);
}
}
}
public static function clear_headers()
{
self::$headers = array();
}
public static function send_headers()
{
if (!headers_sent()) {
if (is_array(self::$headers)) {
foreach (self::$headers as $header) {
if ('Status' == $header['name']) {
header('Status: '.$header['value'], TRUE, (int) $header['value']);
} else {
if ($header['value'] === FALSE) {
header($header['name']);
} else {
header($header['name']. ': ' .$header['value']);
}
}
}
}
}
}
public static function set_expires($seconds=60)
{
if (!headers_sent()) {
$now = $expires = time();
$expires += $seconds;
self::add_header('Last-Modified', gmdate('D, d M Y H:i:s T', $now));
self::add_header('Expires', gmdate('D, d M Y H:i:s T', $expires));
self::add_header('Cache-Control', 'max-age='.$seconds);
return TRUE;
}
return FALSE;
}
public static function check_expires($seconds=60)
{
if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !headers_sent()) {
if (($strpos = strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], ';')) !== FALSE) {
$mod_time = substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, $strpos);
} else {
$mod_time = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
}
$mod_time = strtotime($mod_time);
$mod_time_diff = $mod_time + $seconds - time();
if ($mod_time_diff > 0) {
self::add_header('Last-Modified', gmdate('D, d M Y H:i:s T', $mod_time));
self::add_header('Expires', gmdate('D, d M Y H:i:s T', time() + $mod_time_diff));
self::add_header('Cache-Control', 'max-age='.$mod_time_diff);
self::add_header('Status', '304 Not Modified');
self::send_headers();
exit;
}
}
return FALSE;
}
public static function output($content, $cache=FALSE, $seconds=600)
{
if (CLEAN_OUTPUT === TRUE) {
$content = preg_replace("/(^[rn]*|[rn]+)[st]*[rn]+/", "n", $content);
$content = preg_replace('/ss+/', '', $content);
$content = str_replace("rn", '', $content);
$content = str_replace("n", '', $content);
}
if (VF::cfg_item('cache') == '0') {
$cache = FALSE;
}
if ($cache !== FALSE) {
self::check_expires($seconds);
self::set_expires($seconds);
}
self::send_headers();
return $content;
}
private static function get_client_encoding()
{
$encoding = false;
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$hae = $_SERVER['HTTP_ACCEPT_ENCODING'];
if (strpos($hae, 'deflate') !== FALSE) {
$encoding = 'deflate';
} elseif (strpos($hae, 'deflate') !== FALSE) {
$encoding = 'gzip';
} elseif (strpos($hae, 'compress') !== FALSE) {
$encoding = 'compress';
}
}
return $encoding;
}
private static function is_ie6()
{
}
}
?>