phpDocumentor lodel
[ class tree: lodel ] [ index: lodel ] [ all elements ]

Source for file cachefunc.php

Documentation is available at cachefunc.php

  1. <?php
  2. /**
  3.  * Fichier utilitaire pour la gestion du cache
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  10.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  11.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  12.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  13.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  14.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  15.  *
  16.  * Home page: http://www.lodel.org
  17.  *
  18.  * E-Mail: lodel@lodel.org
  19.  *
  20.  * All Rights Reserved
  21.  *
  22.  * This program is free software; you can redistribute it and/or modify
  23.  * it under the terms of the GNU General Public License as published by
  24.  * the Free Software Foundation; either version 2 of the License, or
  25.  * (at your option) any later version.
  26.  *
  27.  * This program is distributed in the hope that it will be useful,
  28.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30.  * GNU General Public License for more details.
  31.  *
  32.  * You should have received a copy of the GNU General Public License
  33.  * along with this program; if not, write to the Free Software
  34.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35.  *
  36.  * @author Ghislain Picard
  37.  * @author Jean Lamy
  38.  * @author Pierre-Alain Mignot
  39.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  40.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  41.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  42.  * @licence http://www.gnu.org/copyleft/gpl.html
  43.  * @version CVS:$Id:
  44.  * @package lodel
  45.  */
  46.  
  47.  
  48. /**
  49.  * Nettoyage du répertoire de CACHE
  50.  *
  51.  * Cette fonction appelle removefilesincache() si $allCache = true
  52.  * @param bool $allCache 
  53.  * @see func.php -> function update()
  54.  */
  55. function clearcache($allCache=true)
  56. {
  57.     global $site;
  58.     $_REQUEST['clearcache'false// to avoid to erase the CACHE again
  59.     if($allCache{
  60.         if (defined("SITEROOT")) {
  61.             removefilesincache(SITEROOTSITEROOT."lodel/edition"SITEROOT."lodel/admin");
  62.         }    else {
  63.             removefilesincache(".");
  64.         }
  65.     else // seules les données ont été modifiées : on supprime seulement les fichiers HTML mis en cache
  66.         require_once 'Cache/Lite.php';
  67.         $options $GLOBALS['cacheOptions'];
  68.         if (defined("SITEROOT")) {
  69.             $cacheReps array(SITEROOTSITEROOT."lodel/edition"SITEROOT."lodel/admin");
  70.             while(list(,$repeach($cacheReps)) {
  71.                 $rep "./".$rep;
  72.                 $options['cacheDir'$rep.'/CACHE/';
  73.                 if(!file_exists($options['cacheDir']))
  74.                     continue;
  75.                 $cache new Cache_Lite($options);
  76.                 if($site{
  77.                     $cache->clean($site)// html
  78.                 else {
  79.                     $cache->clean();
  80.                 }
  81.                 $cache null;
  82.             }
  83.         else {
  84.             $cache new Cache_Lite($GLOBALS['cacheOptions']);
  85.             if($site{
  86.                 $cache->clean($site)// html
  87.             else {
  88.                 $cache->clean();
  89.             }
  90.         }
  91.     }
  92. }
  93.  
  94. /**
  95.  * Nettoyage des fichiers du répertoire de CACHE
  96.  *
  97.  * On ajoute le répertoire CACHE dans le code, ce qui empêche de détruire le contenu d'un autre
  98.  * répertoire.
  99.  */
  100. function removefilesincache()
  101. {
  102.     global $site;
  103.     $options $GLOBALS['cacheOptions'];
  104.     foreach (func_get_args(as $rep{
  105.         $rep "./".$rep;
  106.         if(FALSE === strpos($rep'/CACHE/'))
  107.             $rep .= "/CACHE/";
  108.  
  109.         // fichiers/répertoires gérés indépendament de cache_lite
  110.         if(!file_exists($rep))
  111.             continue;
  112.         $fd opendir($repor die("Impossible d'ouvrir $rep");
  113.         clearstatcache();
  114.         while (($file readdir($fd)) !== false{
  115.             if (($file[0== "."|| ($file == "CVS"|| ($file == "upload"|| (FALSE !== strpos($file'require_caching')))
  116.                 continue;
  117.             $file $rep"/"$file;
  118.             if (is_dir($file)) //si c'est un répertoire on execute la fonction récursivement
  119.                 removefilesincache($file);
  120.             elseif (file_exists($file&& is_writeable($file)) {
  121.                 @unlink($file);
  122.             }
  123.         }
  124.         closedir($fd);    
  125.     }
  126. }
  127.  
  128. /**
  129.  * Fonction générant le nom du fichier caché (prise de Cache_Lite)
  130.  * @param string $id base du nom du fichier à générer
  131.  * @param string $group groupe du fichier
  132.  * @param array $options options du cache
  133. */
  134. function getCachedFileName($id$group$options{
  135.         if ($options['fileNameProtection']{
  136.             $suffix 'cache_'.md5($group).'_'.md5($id);
  137.         else {
  138.             $suffix 'cache_'.$group.'_'.$id;
  139.         }
  140.         $root $options['cacheDir'$options['cacheDir''./CACHE/';
  141.         if ($options['hashedDirectoryLevel']>0{
  142.             $hash md5($suffix);
  143.             for ($i=$i<$options['hashedDirectoryLevel'$i++{
  144.                 $root $root 'cache_' substr($hash0$i 1'/';
  145.             }   
  146.         }
  147.         return $root.$suffix;
  148. }
  149. ?>

Documentation generated on Thu, 24 Jul 2008 05:07:16 +0200 by phpDocumentor 1.4.0a2