Added Feature #16641: Here comes FAL - beta2 version
[Packages/TYPO3.CMS.git] / typo3 / sysext / fal / classes / class.tx_fal_File.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 FAL development team <fal@wmdb.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * File Abtraction Layer File
30 *
31 * @author FAL development team <fal@wmdb.de>
32 * @package TYPO3
33 * @subpackage tx_fal
34 * @version $Id$
35 */
36 class tx_fal_File {
37
38 /**
39 * The uid of this file's record
40 *
41 * @var integer
42 */
43 protected $uid;
44
45 /**
46 * The name of this file. This is only the filename without the path
47 *
48 * @var string
49 */
50 protected $filename;
51
52 /**
53 * The mount this file is located in
54 *
55 * @var t3lib_file_Mount
56 */
57 protected $mount;
58
59 /**
60 * The path to this file (inside the file mount)
61 *
62 * @var string
63 */
64 protected $path = NULL;
65
66 /**
67 * The file size
68 *
69 * @var integer
70 */
71 protected $size;
72
73 /**
74 * The SHA-1 hash sum of the file
75 *
76 * @var string
77 */
78 protected $hash;
79
80 /**
81 * DESCRIPTION
82 *
83 * @param tx_fal_Mount $mount DESCRIPTION
84 * @param array $fileData DESCRIPTION
85 * @return void
86 */
87 public function __construct(tx_fal_Mount $mount, array $fileData) {
88 $this->mount = $mount;
89 $this->uid = $fileData['uid'];
90 $this->name = $fileData['file_name'];
91 $this->path = $fileData['file_path'];
92 $this->size = $fileData['file_size'];
93 $this->hash = $fileData['file_hash'];
94 }
95
96 /**
97 * Getter for thumbnail
98 *
99 * @todo Implement tx_fal_File::getThumbnail
100 *
101 * @return [to be defined]
102 */
103 public function getThumbnail() {
104 }
105
106 /**
107 * Getter for thumbnail url
108 *
109 * @todo Implement tx_fal_File::getThumbnailUrl
110 *
111 * @return [to be defined]
112 */
113 public function getThumbnailUrl() {
114 }
115
116 /**
117 * Setter for relations
118 *
119 * @todo Implement tx_fal_File::setRelation
120 *
121 * @param string $table DESCRIPTION
122 * @param integer $uid DESCRIPTION
123 * @return void
124 */
125 public function setRelation($table, $uid) {
126 }
127
128 /**
129 * Getter for related records
130 *
131 * @todo Implement tx_fal_File::getRelatedRecords
132 *
133 * @param string $table DESCRIPTION
134 * @return [to be defined]
135 */
136 public function getRelatedRecords($table = '') {
137 }
138
139 /**
140 * Getter for url of file
141 *
142 * @return string DESCRIPTION
143 */
144 public function getUrl() {
145 return $this->path . $this->name;
146 }
147
148 /**
149 *
150 * DESCRIPTION
151 *
152 * @todo Implement tx_fal_File::writeFile
153 *
154 * @param [to be defined] $content DESCRIPTION
155 * @return [to be defined]
156 */
157 public function writeFile($content) {
158 }
159
160 /**
161 * Getter for uid of file in sys_files
162 *
163 * @return integer Uid of file in sys_files
164 */
165 public function getUid() {
166 return $this->uid;
167 }
168
169 /**
170 * Getter for name of file in sys_files
171 *
172 * @return string Name of file in sys_files
173 */
174 public function getName() {
175 return $this->name;
176 }
177
178 /**
179 * Getter for path of file
180 *
181 * @return string Path of file
182 */
183 public function getPath() {
184 return $this->path;
185 }
186
187 /**
188 * Getter for size in bytes of file
189 *
190 * @return integer Size in bytes of file
191 */
192 public function getSize() {
193 return $this->size;
194 }
195
196 /**
197 * Getter for hash (which one? SHA? CRC? MD5?) of file
198 *
199 * @return [to be defined] Hash (which one? SHA? CRC? MD5?) of file
200 */
201 public function getHash() {
202 return $this->hash;
203 }
204
205 /**
206 * DESCRIPTION
207 *
208 * @return [to be defined] DESCRIPTION
209 */
210 public function delete() {
211 $result = $this->mount->getStorageBackend()->delete($this->getUrl());
212
213
214 // @todo: @todo: <rupert.germann>, 01.12.2010 check if the file was actually deleted
215
216
217 tx_fal_Indexer::deleteFileFromIndex($this->uid);
218
219 return $result;
220 }
221
222 /**
223 * Renames the file. This can not change the path! Use moveInsideMount() or moveToMount() for that
224 *
225 * @param string $newName
226 * @return boolean TRUE if renaming succeeded
227 */
228 public function rename($newName) {
229 $newPath = $this->path . $newName;
230
231 $this->moveInsideMount($newPath);
232 }
233
234 /**
235 * DESCRIPTION
236 *
237 * @param string $filePath DESCRIPTION
238 * @return [to be defined] DESCRIPTION
239 */
240 public function replaceWithLocalFile($filePath) {
241 }
242
243 /**
244 * DESCRIPTION
245 *
246 * @return [to be defined] DESCRIPTION
247 */
248 public function getFileCopyForLocalProcessing() {
249 }
250
251 /**
252 * DESCRIPTION
253 *
254 * @param string $newPath DESCRIPTION
255 * @return [to be defined] DESCRIPTION
256 */
257 public function copyInsideMount($newPath) {
258 }
259
260 /**
261 * DESCRIPTION
262 *
263 * @param tx_fal_Mount $mount DESCRIPTION
264 * @param string $newPath DESCRIPTION
265 * @return [to be defined] DESCRIPTION
266 */
267 public function copyToMount(tx_fal_Mount $mount, $newPath) {
268 }
269
270 /**
271 * Moves the file to a new location inside its current mount.
272 *
273 * @param string $newPath The path to move the file to
274 * @return boolean
275 */
276 public function moveInsideMount($newPath) {
277 $oldPath = $this->path . $this->name;
278
279 $result = $this->mount->getStorageBackend()->moveFile($oldPath, $newPath);
280
281 // @todo: <rupert.germann>, 26.11.2010 check if the file was actually moved
282
283 $this->name = basename($newPath);
284 $this->path = dirname($newPath);
285 tx_fal_Indexer::updateFileIndex($this);
286
287 return $result;
288 }
289
290 /**
291 * DESCRIPTION
292 *
293 * @param string $newPath DESCRIPTION
294 * @return [to be defined] DESCRIPTION
295 */
296 public function moveFileToFolder($newPath) {
297
298 $basePath = str_replace(PATH_site, '', $this->mount->getStorageBackend()->getBasePath());
299
300 $oldPath = $this->path . $this->name;
301 $relNewPath = str_replace(PATH_site . $basePath, '', $newPath) . $this->name;
302
303 $result = $this->mount->getStorageBackend()->moveFile($oldPath, $relNewPath, 'move');
304
305 // @todo: <rupert.germann>, 26.11.2010 check if the file was actually moved
306
307 $this->path = str_replace(PATH_site . $basePath, '', $newPath);
308 tx_fal_Indexer::updateFileIndex($this);
309
310 return $result;
311 }
312
313 /**
314 * DESCRIPTION
315 *
316 * @todo Implement tx_fal_File::moveToMount
317 *
318 * @param tx_fal_Mount $mount DESCRIPTION
319 * @param string $newPath DESCRIPTION
320 * @return [to be defined] DESCRIPTION
321 */
322 public function moveToMount(tx_fal_Mount $mount, $newPath) {
323 }
324
325 /**
326 * DESCRIPTION
327 *
328 * @todo Implement tx_fal_File::getContents
329 *
330 * @return [to be defined] DESCRIPTION
331 */
332 public function getContents() {
333 }
334
335 /**
336 * DESCRIPTION
337 *
338 * @param [to be defined] $mode DESCRIPTION
339 * @return [to be defined] DESCRIPTION
340 */
341 public function getFileHandle($mode) {
342 }
343 }
344
345 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/fal/classes/class.tx_fal_File.php'])) {
346 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/fal/classes/class.tx_fal_File.php']);
347 }
348 ?>