[ PHPXref.com ] [ Generated: Sun Jul 20 19:05:09 2008 ] [ onPHP 0.4.6 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/main/Utils/ -> HeaderUtils.class.php (source)

   1  <?php
   2  /***************************************************************************
   3   *   Copyright (C) 2004-2006 by Konstantin V. Arkhipov                     *
   4   *                                                                         *
   5   *   This program is free software; you can redistribute it and/or modify  *
   6   *   it under the terms of the GNU General Public License as published by  *
   7   *   the Free Software Foundation; either version 2 of the License, or     *
   8   *   (at your option) any later version.                                   *
   9   *                                                                         *
  10   ***************************************************************************/
  11  /* $Id: HeaderUtils.class.php 1684 2006-06-10 20:58:39Z voxus $ */
  12  
  13      /**
  14       * Collection of static header functions.
  15       * 
  16       * @ingroup Utils
  17      **/
  18      final class HeaderUtils extends StaticFactory
  19      {
  20          private static $headerSent        = false;
  21          private static $redirectSent    = false;
  22          private static $cacheLifeTime   = 3600;
  23          
  24  		public static function redirectRaw($url)
  25          {
  26              header("Location: {$url}");
  27  
  28              self::$headerSent = true;
  29              self::$redirectSent = true;
  30          }
  31  
  32  		public static function redirect(BaseModule $mod)
  33          {
  34              $qs = null;
  35              
  36              if ($mod->getParameters())
  37                  foreach ($mod->getParameters() as $key => $val)
  38                      $qs .= "&{$key}={$val}";
  39              
  40              $url =
  41                  (defined('ADMIN_AREA')
  42                      ? PATH_WEB_ADMIN
  43                      : PATH_WEB)
  44                  .'?area='
  45                  .$mod->getName()
  46                  .$qs;
  47              
  48              header("Location: {$url}");
  49  
  50              self::$headerSent = true;
  51              self::$redirectSent = true;
  52          }
  53          
  54  		public static function redirectBack()
  55          {
  56              if (isset($_SERVER['HTTP_REFERER'])) {
  57                  header("Location: {$_SERVER['HTTP_REFERER']}");
  58                  self::$headerSent = true;
  59                  self::$redirectSent = true;
  60                  return true;
  61              } else
  62                  return false;
  63          }
  64          
  65  		public static function getParsedURI(/* ... */)
  66          {
  67              if ($num = func_num_args()) {
  68                  $out = self::getURI();
  69                  $uri = null;
  70                  $arr = func_get_args();
  71                  
  72                  for ($i = 0; $i < $num; ++$i)
  73                      unset($out[$arr[$i]]);
  74                  
  75                  foreach ($out as $key => $val) {
  76                      if (is_array($val)) {
  77                          foreach ($val as $k => $v)
  78                              $uri .= "&{$key}[{$k}]={$v}";
  79                      } else 
  80                          $uri .= "&{$key}={$val}";
  81                  }
  82  
  83                  return $uri;
  84              }
  85  
  86              return null;
  87          }
  88          
  89  		public static function sendCachedHeader()
  90          {
  91              header('Cache-control: private, max-age=3600');
  92              
  93              header(
  94                  'Expires: '
  95                  .date('D, d M Y H:i:s', date('U') + self::$cacheLifeTime)
  96                  .' GMT'
  97              );
  98              
  99              self::$headerSent = true;
 100          }
 101  
 102  		public static function sendNotCachedHeader()
 103          {
 104              header('Cache-control: no-cache');
 105              header(
 106                  'Expires: '
 107                  .date('D, d M Y H:i:s', date('U') - self::$cacheLifeTime)
 108                  .' GMT'
 109              );
 110              
 111              self::$headerSent = true;
 112          }
 113          
 114  		public static function sendContentLength($length)
 115          {
 116              Assert::isInteger($length);
 117              
 118              header(
 119                  "Content-Length: {$length}"
 120              );
 121              
 122              self::$headerSent = true;
 123          }
 124          
 125  		public static function isHeaderSent()
 126          {
 127              return self::$headerSent;
 128          }
 129          
 130  		public static function forceHeaderSent()
 131          {
 132              self::$headerSent = true;
 133          }
 134          
 135  		public static function isRedirectSent()
 136          {
 137              return self::$redirectSent;
 138          }
 139          
 140  		public static function setCacheLifeTime($cacheLifeTime)
 141          {
 142              self::$cacheLifeTime = $cacheLifeTime;
 143          }
 144          
 145  		public static function getCacheLifeTime()
 146          {
 147              return self::$cacheLifeTime;
 148          }
 149  
 150  		private static function getURI()
 151          {
 152              $out = null;
 153              
 154              parse_str($_SERVER['QUERY_STRING'], $out);
 155              
 156              return $out;
 157          }
 158      }
 159  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]