[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora 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; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 define('EMBARGOFILENAME', dirname(__FILE__). '/../../data/embargo.php'); 20 21 function writeEmbargo ($date) { 22 $embargos = array(); 23 24 if (file_exists(EMBARGOFILENAME)) { 25 $embargos = file(EMBARGOFILENAME); 26 } 27 28 // lock 29 $embargos[] = $date; 30 $embargos = array_unique($embargos); 31 32 if ($f = fopen(EMBARGOFILENAME, 'w')) { 33 // boucle d'attente 34 while (!flock($f, LOCK_EX)); 35 36 fwrite($f, implode("\n", $embargos)); 37 flock($f, LOCK_UN); // libère le verrou 38 fclose($f); 39 } 40 // unlock 41 } 42 43 function removeEmbargo ($date) { 44 if (file_exists(EMBARGOFILENAME)) { 45 $embargos = file(EMBARGOFILENAME); 46 } 47 48 if (!is_null($key = array_search($date->getDate(), $embargos))) { 49 unset($embargos[$key]); 50 } 51 52 // TODO : 53 // consolider le fichier, au moins gicler les lignes vides, au mieux gicler les trucs qui sont pas des dates 54 55 // lock 56 if ($f = fopen(EMBARGOFILENAME, 'w')) { 57 // boucle d'attente 58 while (!flock($f, LOCK_EX)); 59 60 fwrite($f, implode("\n", $embargos)); 61 flock($f, LOCK_UN); // libere le verrou 62 fclose($f); 63 } 64 // unlock 65 } 66 67 function readNextEmbargo () { 68 if (file_exists(EMBARGOFILENAME)) { 69 // on accede pas au fichier plus de 4 fois par minutes 70 if ((time() - fileatime(EMBARGOFILENAME)) > 15) { 71 $embargos = file(EMBARGOFILENAME); 72 if (count($embargos) == 0) { // plus rien a traiter 73 unlink(EMBARGOFILENAME); 74 } 75 else { 76 touch(EMBARGOFILENAME); // on a traiter le fichier donc on update sa date 77 } 78 } 79 } 80 81 if ($embargos) { 82 asort($embargos); 83 return new Date($embargos[0]); 84 } 85 else { 86 return false; 87 } 88 } 89 90 function clearCache ($fonds) { 91 require_once dirname(__FILE__). "/../date.php"; 92 93 if (($nextEmbargo = readNextEmbargo()) != false) { 94 $now = new Date(); 95 if (Date::compare($nextEmbargo->getDate(), $now->getDate()) <= 0) { 96 include_once(dirname(__FILE__). '/../cacheHTML/inc_cacheHTML_factory.php'); 97 98 if (!file_exists(dirname(__FILE__). '/embargo.conf.php')) 99 die('embargo ... je ne trouve pas mon fichier de conf : embargo.conf.php'); 100 101 require(dirname(__FILE__). '/embargo.conf.php'); 102 103 while (list(, $fond) = each($fonds)) { 104 $cacheHTML = &recuperer_instance_cacheHTML($fond, null, null, null); 105 $cacheHTML->destroyAllCache(); 106 } 107 removeEmbargo($nextEmbargo); 108 } 109 } 110 } 111 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |