00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00018 final class HeaderUtils extends StaticFactory
00019 {
00020 private static $headerSent = false;
00021 private static $redirectSent = false;
00022 private static $cacheLifeTime = 3600;
00023
00024 public static function redirectRaw($url)
00025 {
00026 header("Location: {$url}");
00027
00028 self::$headerSent = true;
00029 self::$redirectSent = true;
00030 }
00031
00035 public static function redirect(BaseModule $mod)
00036 {
00037 $qs = null;
00038
00039 if ($mod->getParameters())
00040 foreach ($mod->getParameters() as $key => $val)
00041 $qs .= "&{$key}={$val}";
00042
00043 $url =
00044 (defined('ADMIN_AREA')
00045 ? PATH_WEB_ADMIN
00046 : PATH_WEB)
00047 .'?area='
00048 .$mod->getName()
00049 .$qs;
00050
00051 header("Location: {$url}");
00052
00053 self::$headerSent = true;
00054 self::$redirectSent = true;
00055 }
00056
00057 public static function redirectBack()
00058 {
00059 if (isset($_SERVER['HTTP_REFERER'])) {
00060 header("Location: {$_SERVER['HTTP_REFERER']}");
00061 self::$headerSent = true;
00062 self::$redirectSent = true;
00063 return $_SERVER['HTTP_REFERER'];
00064 } else
00065 return false;
00066 }
00067
00068 public static function getParsedURI()
00069 {
00070 if ($num = func_num_args()) {
00071 $out = self::getURI();
00072 $uri = null;
00073 $arr = func_get_args();
00074
00075 for ($i = 0; $i < $num; ++$i)
00076 unset($out[$arr[$i]]);
00077
00078 foreach ($out as $key => $val) {
00079 if (is_array($val)) {
00080 foreach ($val as $k => $v)
00081 $uri .= "&{$key}[{$k}]={$v}";
00082 } else
00083 $uri .= "&{$key}={$val}";
00084 }
00085
00086 return $uri;
00087 }
00088
00089 return null;
00090 }
00091
00092 public static function sendCachedHeader()
00093 {
00094 header('Cache-control: private, max-age=3600');
00095
00096 header(
00097 'Expires: '
00098 .date('D, d M Y H:i:s', date('U') + self::$cacheLifeTime)
00099 .' GMT'
00100 );
00101
00102 self::$headerSent = true;
00103 }
00104
00105 public static function sendNotCachedHeader()
00106 {
00107 header('Cache-control: no-cache');
00108 header(
00109 'Expires: '
00110 .date('D, d M Y H:i:s', date('U') - self::$cacheLifeTime)
00111 .' GMT'
00112 );
00113
00114 self::$headerSent = true;
00115 }
00116
00117 public static function sendContentLength($length)
00118 {
00119 Assert::isInteger($length);
00120
00121 header(
00122 "Content-Length: {$length}"
00123 );
00124
00125 self::$headerSent = true;
00126 }
00127
00128 public static function sendHttpStatus(HttpStatus $status)
00129 {
00130 header($status->toString());
00131
00132 self::$headerSent = true;
00133 }
00134
00135 public static function isHeaderSent()
00136 {
00137 return self::$headerSent;
00138 }
00139
00140 public static function forceHeaderSent()
00141 {
00142 self::$headerSent = true;
00143 }
00144
00145 public static function isRedirectSent()
00146 {
00147 return self::$redirectSent;
00148 }
00149
00150 public static function setCacheLifeTime($cacheLifeTime)
00151 {
00152 self::$cacheLifeTime = $cacheLifeTime;
00153 }
00154
00155 public static function getCacheLifeTime()
00156 {
00157 return self::$cacheLifeTime;
00158 }
00159
00160 private static function getURI()
00161 {
00162 $out = null;
00163
00164 parse_str($_SERVER['QUERY_STRING'], $out);
00165
00166 return $out;
00167 }
00168 }
00169 ?>