[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZExpiryHandler class 4 // 5 // Created on: <28-Feb-2003 16:52:53 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezexpiryhandler.php 30 */ 31 32 /*! 33 \class eZExpiryHandler ezexpiryhandler.php 34 \brief Keeps track of expiry keys and their timestamps 35 36 */ 37 38 //include_once( 'lib/ezutils/classes/ezphpcreator.php' ); 39 40 class eZExpiryHandler 41 { 42 /*! 43 Constructor 44 */ 45 function eZExpiryHandler() 46 { 47 $this->Timestamps = array(); 48 $this->IsModified = false; 49 $this->restore(); 50 } 51 52 /*! 53 Will load timestamp values from disk. 54 */ 55 function restore() 56 { 57 // VS-DBFILE 58 59 $cacheDirectory = eZSys::cacheDirectory(); 60 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 61 $expiryFile = eZClusterFileHandler::instance( $cacheDirectory . '/' . 'expiry.php' ); 62 if ( $expiryFile->exists() ) 63 { 64 $expiryFile->fetch(); 65 66 include( $cacheDirectory . "/" . 'expiry.php' ); 67 $this->Timestamps = $Timestamps; 68 $this->IsModified = false; 69 70 $expiryFile->deleteLocal(); 71 } 72 } 73 74 /*! 75 Will store the current timestamp values to disk. 76 */ 77 function store() 78 { 79 // VS-DBFILE 80 81 $cacheDirectory = eZSys::cacheDirectory(); 82 83 $uniqid = md5( uniqid( "ezp". getmypid(), true ) ); 84 $fp = @fopen( "$cacheDirectory/.expiry.php.$uniqid.tmp", 'w' ); 85 if ( $fp ) 86 { 87 $storeString = "<?php\n\$Timestamps = array( "; 88 $i = 0; 89 foreach ( $this->Timestamps as $key => $value ) 90 { 91 if ( $i > 0 ) 92 $storeString .= ",\n" . str_repeat( ' ', 21 ); 93 $storeString .= "'$key' => $value"; 94 ++$i; 95 } 96 $storeString .= " );\n?>"; 97 98 fwrite( $fp, $storeString ); 99 fclose( $fp ); 100 include_once ( 'lib/ezutils/classes/ezfile.php' ); 101 eZFile::rename( "$cacheDirectory/.expiry.php.$uniqid.tmp", "$cacheDirectory/expiry.php" ); 102 103 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 104 $fileHandler = eZClusterFileHandler::instance(); 105 $fileHandler->fileStore( "$cacheDirectory/expiry.php", 'expirycache', true ); 106 107 $this->IsModified = false; 108 } 109 } 110 111 /*! 112 Sets the timestamp value \a $value for expiry key \a $name. 113 */ 114 function setTimestamp( $name, $value ) 115 { 116 $this->Timestamps[$name] = $value; 117 $this->IsModified = true; 118 } 119 120 /*! 121 \return true if the expiry key \a $name exists. 122 */ 123 function hasTimestamp( $name ) 124 { 125 return isset( $this->Timestamps[$name] ); 126 } 127 128 /*! 129 \return the timestamp value for the expiry key \a $name if it exists or \c false if not, 130 */ 131 function timestamp( $name ) 132 { 133 if ( !isset( $this->Timestamps[$name] ) ) 134 { 135 eZDebug::writeError( "Unknown expiry timestamp called '$name'", 'eZExpiryHandler::timestamp' ); 136 return false; 137 } 138 return $this->Timestamps[$name]; 139 } 140 141 /*! 142 \static 143 \return the unique instance of the expiry handler. 144 */ 145 function &instance() 146 { 147 $expiryInstance =& $GLOBALS['eZExpiryHandlerInstance']; 148 if ( !isset( $expiryInstance ) ) 149 { 150 $expiryInstance = new eZExpiryHandler(); 151 } 152 return $expiryInstance; 153 } 154 155 /*! 156 \return true if the expiry handler has modified data. 157 */ 158 function isModified() 159 { 160 return $this->IsModified; 161 } 162 163 /// \privatesection 164 var $Timestamps; 165 var $IsModified; 166 } 167 168 /*! 169 Called at the end of execution and will store the data if it is modified. 170 */ 171 function eZExpiryHandlerShutdownHandler() 172 { 173 $expiryInstance =& $GLOBALS['eZExpiryHandlerInstance']; 174 if ( isset( $expiryInstance ) and 175 get_class( $expiryInstance ) == 'ezexpiryhandler' ) 176 { 177 $instance =& eZExpiryHandler::instance(); 178 if ( $instance->isModified() ) 179 { 180 $instance->store(); 181 } 182 } 183 } 184 185 register_shutdown_function( 'eZExpiryHandlerShutdownHandler' ); 186 187 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |