00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 class eZExpiryHandler
00043 {
00044
00045
00046
00047 function eZExpiryHandler()
00048 {
00049 $this->Timestamps = array();
00050 $this->IsModified = false;
00051 $this->restore();
00052 }
00053
00054
00055
00056
00057 function restore()
00058 {
00059
00060
00061 $cacheDirectory = eZSys::cacheDirectory();
00062 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00063 $expiryFile = eZClusterFileHandler::instance( $cacheDirectory . '/' . 'expiry.php' );
00064 if ( $expiryFile->exists() )
00065 {
00066
00067 $fetchedFilePath = $expiryFile->fetchUnique();
00068 include( $fetchedFilePath );
00069 $expiryFile->fileDeleteLocal( $fetchedFilePath );
00070
00071
00072
00073 $this->Timestamps = $Timestamps;
00074 $this->IsModified = false;
00075
00076
00077 }
00078 }
00079
00080
00081
00082
00083 function store()
00084 {
00085
00086
00087 $cacheDirectory = eZSys::cacheDirectory();
00088
00089 $uniqid = md5( uniqid( "ezp". getmypid(), true ) );
00090 $fp = @fopen( "$cacheDirectory/.expiry.php.$uniqid.tmp", 'w' );
00091 if ( $fp )
00092 {
00093 $storeString = "<?php\n\$Timestamps = array( ";
00094 $i = 0;
00095 foreach ( $this->Timestamps as $key => $value )
00096 {
00097 if ( $i > 0 )
00098 $storeString .= ",\n" . str_repeat( ' ', 21 );
00099 $storeString .= "'$key' => $value";
00100 ++$i;
00101 }
00102 $storeString .= " );\n?>";
00103
00104 fwrite( $fp, $storeString );
00105 fclose( $fp );
00106 include_once( 'lib/ezutils/classes/ezfile.php' );
00107 eZFile::rename( "$cacheDirectory/.expiry.php.$uniqid.tmp", "$cacheDirectory/expiry.php" );
00108
00109 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00110 $fileHandler = eZClusterFileHandler::instance();
00111 $fileHandler->fileStore( "$cacheDirectory/expiry.php", 'expirycache', true );
00112
00113 $this->IsModified = false;
00114 }
00115 }
00116
00117
00118
00119
00120 function setTimestamp( $name, $value )
00121 {
00122 $this->Timestamps[$name] = $value;
00123 $this->IsModified = true;
00124 }
00125
00126
00127
00128
00129 function hasTimestamp( $name )
00130 {
00131 return isset( $this->Timestamps[$name] );
00132 }
00133
00134
00135
00136
00137 function timestamp( $name )
00138 {
00139 if ( !isset( $this->Timestamps[$name] ) )
00140 {
00141 eZDebug::writeError( "Unknown expiry timestamp called '$name'", 'eZExpiryHandler::timestamp' );
00142 return false;
00143 }
00144 return $this->Timestamps[$name];
00145 }
00146
00147
00148
00149
00150
00151 function &instance()
00152 {
00153 $expiryInstance =& $GLOBALS['eZExpiryHandlerInstance'];
00154 if ( !isset( $expiryInstance ) )
00155 {
00156 $expiryInstance = new eZExpiryHandler();
00157 }
00158 return $expiryInstance;
00159 }
00160
00161
00162
00163
00164 function isModified()
00165 {
00166 return $this->IsModified;
00167 }
00168
00169
00170 var $Timestamps;
00171 var $IsModified;
00172 }
00173
00174
00175
00176
00177 function eZExpiryHandlerShutdownHandler()
00178 {
00179 $expiryInstance =& $GLOBALS['eZExpiryHandlerInstance'];
00180 if ( isset( $expiryInstance ) and
00181 get_class( $expiryInstance ) == 'ezexpiryhandler' )
00182 {
00183 $instance =& eZExpiryHandler::instance();
00184 if ( $instance->isModified() )
00185 {
00186 $instance->store();
00187 }
00188 }
00189 }
00190
00191 register_shutdown_function( 'eZExpiryHandlerShutdownHandler' );
00192
00193 ?>