Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezcachefile.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezcachefile.php 9802 2003-04-10 08:37:08Z br $
5 //
6 // Definition of eZCacheFile class
7 //
8 // Created on: <07-Feb-2001 13:56:26 amos>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
29 // include_once( "kernel/classes/ezdatetime.php" );
30
33
48 class eZCacheFile
49 {
50 function __construct( $root, $component, $suffix = "cache", $separator = "-" )
51 {
52 if ( strlen( $root ) > 1 and $root[strlen($root) - 1] != "/" )
53 $root .= "/";
54 $this->Root = $root;
55 if ( !is_array( $component ) )
56 $component = array( $component );
57
58 //EP -- additional caching parameters -------------------
59 // $component[] = $GLOBALS["GlobalSectionID"] ;
60 //$component[] = $GLOBALS["HTTP_HOST"]; // future - multihost configuration
61 //-------------------------------------------------------
62
63 $this->Components = $component;
64 $this->Suffix = $suffix;
65 $this->Separator = $separator;
66 }
67
71 function &filename( $with_root = false )
72 {
73 if ( empty( $this->Filename ) )
74 {
75 //$part = (string) implode( $this->Separator[0], $this->Components );
76 $flatComponents = array_map(function ($item) {
77 return is_array($item) ? json_encode($item) : (string)$item;
78 }, $this->Components);
79
80 $part = implode($this->Separator[0], $flatComponents);
81
82 $this->Filename = $part . "." . $this->Suffix;
83 }
84 if ( $with_root and empty( $this->AbsFilename ) )
85 {
86 $this->AbsFilename = $this->Root . $this->Filename;
87 }
88
89
90 if ( $with_root )
91 return $this->AbsFilename;
92 else
93 return $this->Filename;
94 }
95
100 function exists()
101 {
102 $file =& $this->filename( true );
103 return file_exists( $file );
104 }
105
109 function delete()
110 {
111 // print( $this->filename( true ) . "<br>" );
112 if ( $this->exists() )
113 eZPBFile::unlink( $this->filename( true ) );
114 }
115
120 function isUpToDate( $modtime )
121 {
122 if ( $this->exists() )
123 {
124 $mod = eZPBFile::filemtime( $this->filename( true ) );
125 return $modtime <= $mod;
126 }
127 return false;
128 }
129
133 function &lastModified()
134 {
135 if ( $this->exists() )
136 {
137 $mod = eZPBFile::filemtime( $this->filename( true ) );
138 $datetime = new eZDateTime();
139
140 $datetime->setYear( date( "Y", $mod ) );
141 $datetime->setMonth( date( "m", $mod ) );
142 $datetime->setDay( date( "d", $mod ) );
143 $datetime->setHour( date( "H", $mod ) );
144 $datetime->setMinute( date( "i", $mod ) );
145 $datetime->setSecond( date( "s", $mod ) );
146
147 return $datetime;
148 }
149 return false;
150 }
151
155 function &contents()
156 {
157 if ( !$this->exists() )
158 print( "<br><b>Cache: File \"" . $this->filename( true ) . "\" does not exist</b><br>" );
159 else
160 {
161 $file = eZPBFile::fopen( $this->filename( true ), "r" );
162 if ( $file )
163 {
164 $fileSize = eZPBFile::filesize( $this->filename( true ) );
165 if( $fileSize != 0 )
166 $content =& fread( $file, $fileSize );
167 fclose( $file );
168 }
169 else
170 {
171 print( "<br><b>Cache: Cannot read contents of file \"" . $this->filename( true ) . "\"</b><br>" );
172 }
173 }
174 return $content;
175 }
176
180 function store( $content )
181 {
182 $file = eZPBFile::fopen( $this->filename( true ), "w" );
183 if ( $file )
184 {
185 fwrite( $file, $content );
186 fclose( $file );
187 }
188 else
189 {
190 print( "<br><b>Cache: Cannot write contents to file \"" . $this->filename( true ) . "\"</b><br>" );
191 }
192 return $content;
193 }
194
221 static public function files( $root, $components, $suffix = "cache", $separator = "-", $as_object = true )
222 {
223 if ( strlen( $root ) > 1 and $root[strlen($root) - 1] != "/" )
224 $root .= "/";
225 if ( !is_array( $components ) )
226 $components = array( $components );
227 $reg = "";
228 $i = 0;
229 foreach( $components as $comp )
230 {
231 if ( $i > 0 )
232 $reg .= $separator;
233 if ( isset( $comp ) )
234 {
235 if ( is_array( $comp ) )
236 {
237 $cond = "";
238 $j = 0;
239 foreach( $comp as $choices )
240 {
241 if ( $j > 0 )
242 $cond .= "|";
243 $cond .= $choices;
244 ++$j;
245 }
246 $cond = "($cond)";
247 $reg .= $cond;
248 }
249 else
250 {
251 $reg .= $comp;
252 }
253 }
254 else
255 {
256 $reg .= "[^" . $separator . "]*";
257 }
258 ++$i;
259 }
260 $reg = "/$reg/";
261 $dir = eZPBFile::dir( $root );
262 $ret = array();
263 while ( $entry = $dir->read() )
264 {
265 if ( $entry != "." && $entry != ".." )
266 {
267 if ( preg_match( $reg, $entry ) )
268 {
269 $parts = explode( ".", $entry );
270 if ( $as_object )
271 $ret[] = new eZCacheFile( $root, explode( $separator, $parts[0] ),
272 $parts[1], $separator );
273 else
274 $ret[] = $entry;
275 }
276 }
277 }
278
279 $dir->close();
280 return $ret;
281 }
282
283 var $Root;
284 var $Components;
285 var $Suffix;
286 var $Separator;
287 var $Filename;
288 var $AbsFilename;
289 }
290
291 ?>
$i
$i
Definition: admin/adlist.php:91
$datetime
$datetime
Definition: appointmentview.php:108
eZDateTime
Definition: ezdatetime.php:55
eZPBFile\fopen
static fopen( $filename, $options)
Definition: ezpbfile.php:326
eZPBFile\dir
static dir( $dir, $add_sitedir=true)
Definition: ezpbfile.php:384
eZPBFile\unlink
static unlink( $filename)
Definition: ezpbfile.php:352
eZPBFile\filemtime
static filemtime( $filename)
Definition: ezpbfile.php:306
eZPBFile\filesize
static filesize( $filename)
Definition: ezpbfile.php:339
$item
$item
Definition: classes/admin/linklist.php:228
$separator
else $separator
Definition: cron_alerts.php:52
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$suffix
$suffix
Definition: ezfilemanager/user/filedownload.php:168
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$content
$content
Definition: ezimagecatalogue/admin/filedownload.php:53
$fileSize
if(eZObjectPermission::hasPermission( $image->id(), "imagecatalogue_image", "r", $user)==false) $fileSize
Definition: ezimagecatalogue/admin/filedownload.php:51
$j
$j
Definition: ezimagecatalogue/admin/imagelist.php:345
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$part
$part
Definition: tag.php:46
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.