[ Index ]
 

Code source de Dotclear 1.2.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/layout/ -> lib.cache.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2004 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; either version 2 of the License, or
  10  # (at your option) any later version.
  11  # 
  12  # DotClear is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  # 
  17  # You should have received a copy of the GNU General Public License
  18  # along with DotClear; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  
  23  class cache
  24  {
  25      # Envoyer les en-têtes de cache HTTP en fonction d'une liste de fichiers
  26  	function http($files,$mod_ts=array())
  27      {
  28          if (empty($files) || !is_array($files)) {
  29              return false;
  30          }
  31          
  32          array_walk($files,create_function('&$v','$v = filemtime($v);'));
  33          
  34          $array_ts = array_merge($mod_ts,$files);
  35          
  36          rsort($array_ts);
  37          $ts = $array_ts[0];
  38          
  39          $since = NULL;
  40          if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
  41              $since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
  42              $since = preg_replace ('/^(.*)(Mon|Tue|Wed|Thu|Fri|Sat|Sun)(.*)(GMT)(.*)/', '$2$3 GMT', $since);
  43              $since = strtotime($since);
  44          }
  45          
  46          $status_mode = preg_match('/cgi/',php_sapi_name());
  47          
  48          # Listes des en-têtes communs
  49          $headers[] = 'Last-Modified: '.gmdate('D, d M Y H:i:s',$ts).' GMT';
  50          $headers[] = 'Cache-Control: must-revalidate, max-age=0';
  51          $headers[] = 'Pragma:';
  52          
  53          if ($since >= $ts)
  54          {
  55              if ($status_mode) {
  56                  header("Status: 304 Not Modified");
  57              } else {
  58                  if (version_compare(phpversion(),'4.3.0','>=')) {
  59                      header('Not Modified', TRUE, 304);
  60                  } else {
  61                      header('HTTP/1.x 304 Not Modified');
  62                  }
  63              }
  64              foreach ($headers as $v) {
  65                  header($v);
  66              }
  67              exit;
  68          }
  69          else
  70          {
  71              header('Date: '.gmdate('D, d M Y H:i:s').' GMT');
  72              foreach ($headers as $v) {
  73                  header($v);
  74              }
  75          }
  76      }
  77      
  78      
  79      # écriture d'un fichier de cache
  80  	function writeFile($file,$content)
  81      {
  82          $w = false;
  83          if (file_exists($file)) {
  84              $w = is_writable($file);
  85          } else {
  86              $w = is_writable(dirname($file));
  87          }
  88          
  89          if (!$w) {
  90              return false;
  91          }
  92          
  93          if (($fp = @fopen($file,'w')) !== false) {
  94              fwrite($fp,$content,strlen($content));
  95              fclose($fp);
  96          }
  97      }
  98      
  99      # Récupération d'un fichier en fonction d'une liste de fichiers
 100  	function getFile($file,$files)
 101      {
 102          if (empty($files) || !is_array($files) || !file_exists($file)) {
 103              return false;
 104          }
 105          
 106          array_walk($files,create_function('&$v','$v = filemtime($v);'));
 107          rsort($files);
 108          $ts = $files[0];
 109          
 110          $ftime = filemtime($file);
 111          
 112          if ($ts <= $ftime) {
 113              define('DC_CACHE_CONTENT',implode('',file($file)));
 114          }
 115      }
 116  }
 117  ?>


Généré le : Fri Feb 23 21:40:15 2007 par Balluche grâce à PHPXref 0.7