Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezbinaryfile.php
Go to the documentation of this file.
1 <?php
18 class eZBinaryFile extends eZPersistentObject
19 {
20 static function definition()
21 {
22 static $definition = array( 'fields' => array( 'contentobject_attribute_id' => array( 'name' => 'ContentObjectAttributeID',
23 'datatype' => 'integer',
24 'default' => 0,
25 'required' => true,
26 'foreign_class' => 'eZContentObjectAttribute',
27 'foreign_attribute' => 'id',
28 'multiplicity' => '1..*' ),
29 'version' => array( 'name' => 'Version',
30 'datatype' => 'integer',
31 'default' => 0,
32 'required' => true ),
33 'filename' => array( 'name' => 'Filename',
34 'datatype' => 'string',
35 'default' => '',
36 'required' => true ),
37 'original_filename' => array( 'name' => 'OriginalFilename',
38 'datatype' => 'string',
39 'default' => '',
40 'required' => true ),
41 'mime_type' => array( 'name' => 'MimeType',
42 'datatype' => 'string',
43 'default' => '',
44 'required' => true ),
45 'download_count' => array( 'name' => 'DownloadCount',
46 'datatype' => 'integer',
47 'default' => 0,
48 'required' => true ) ),
49 'keys' => array( 'contentobject_attribute_id', 'version' ),
50 'relations' => array( 'contentobject_attribute_id' => array( 'class' => 'ezcontentobjectattribute',
51 'field' => 'id' ) ),
52 "function_attributes" => array( 'filesize' => 'fileSize',
53 'filepath' => 'filePath',
54 'mime_type_category' => 'mimeTypeCategory',
55 'mime_type_part' => 'mimeTypePart' ),
56 'class_name' => 'eZBinaryFile',
57 'name' => 'ezbinaryfile' );
58 return $definition;
59 }
60
61
62 function fileSize()
63 {
64 $fileInfo = $this->storedFileInfo();
65
66 $file = eZClusterFileHandler::instance( $fileInfo['filepath'] );
67 if ( $file->exists() )
68 {
69 $stat = $file->stat();
70 return $stat['size'];
71 }
72
73 return 0;
74 }
75
76 function filePath()
77 {
78 $fileInfo = $this->storedFileInfo();
79 return $fileInfo['filepath'];
80 }
81
82 function mimeTypeCategory()
83 {
84 $types = explode( '/', $this->attribute( 'mime_type' ) );
85 return $types[0];
86 }
87
88 function mimeTypePart()
89 {
90 $types = explode( '/', $this->attribute( 'mime_type' ) );
91 return $types[1];
92 }
93
94 static function create( $contentObjectAttributeID, $version )
95 {
96 $row = array( 'contentobject_attribute_id' => $contentObjectAttributeID,
97 'version' => $version,
98 'filename' => '',
99 'original_filename' => '',
100 'mime_type' => ''
101 );
102 return new eZBinaryFile( $row );
103 }
104
105 static function fetch( $id, $version = null, $asObject = true )
106 {
107 if ( $version == null )
108 {
109 return eZPersistentObject::fetchObjectList( eZBinaryFile::definition(),
110 null,
111 array( 'contentobject_attribute_id' => $id ),
112 null,
113 null,
114 $asObject );
115 }
116 else
117 {
118 return eZPersistentObject::fetchObject( eZBinaryFile::definition(),
119 null,
120 array( 'contentobject_attribute_id' => $id,
121 'version' => $version ),
122 $asObject );
123 }
124 }
125
126 static function fetchByFileName( $filename, $version = null, $asObject = true )
127 {
128 if ( $version == null )
129 {
130 return eZPersistentObject::fetchObjectList( eZBinaryFile::definition(),
131 null,
132 array( 'filename' => $filename ),
133 null,
134 null,
135 $asObject );
136 }
137 else
138 {
139 return eZPersistentObject::fetchObject( eZBinaryFile::definition(),
140 null,
141 array( 'filename' => $filename,
142 'version' => $version ),
143 $asObject );
144 }
145 }
146
147 static function removeByID( $id, $version )
148 {
149 if ( $version == null )
150 {
151 eZPersistentObject::removeObject( eZBinaryFile::definition(),
152 array( 'contentobject_attribute_id' => $id ) );
153 }
154 else
155 {
156 eZPersistentObject::removeObject( eZBinaryFile::definition(),
157 array( 'contentobject_attribute_id' => $id,
158 'version' => $version ) );
159 }
160 }
161
162
167 function metaData()
168 {
169 $metaData = "";
170 $binaryINI = eZINI::instance( 'binaryfile.ini' );
171
172 $handlerSettings = $binaryINI->variable( 'HandlerSettings', 'MetaDataExtractor' );
173
174 if ( isset( $handlerSettings[$this->MimeType] ) )
175 {
176 // Check if plugin exists
177 if ( eZExtension::findExtensionType( array( 'ini-name' => 'binaryfile.ini',
178 'repository-group' => 'HandlerSettings',
179 'repository-variable' => 'Repositories',
180 'extension-group' => 'HandlerSettings',
181 'extension-variable' => 'ExtensionRepositories',
182 'type-directory' => false,
183 'type' => $handlerSettings[$this->MimeType],
184 'subdir' => 'plugins',
185 'extension-subdir' => 'plugins',
186 'suffix-name' => 'parser.php' ),
187 $out ) )
188 {
189 $filePath = $out['found-file-path'];
190 include_once( $filePath );
191 $class = $handlerSettings[$this->MimeType] . 'Parser';
192
193 $parserObject = new $class( );
194 $fileInfo = $this->storedFileInfo();
195
196 $file = eZClusterFileHandler::instance( $fileInfo['filepath'] );
197 if ( $file->exists() )
198 {
199 $fetchedFilePath = $file->fetchUnique();
200 $metaData = $parserObject->parseFile( $fetchedFilePath );
201 $file->fileDeleteLocal( $fetchedFilePath );
202 }
203 }
204 else
205 {
206 eZDebug::writeWarning( "Plugin for $this->MimeType was not found", 'eZBinaryFile' );
207 }
208 }
209 else
210 {
211 eZDebug::writeWarning( "Mimetype $this->MimeType not supported for indexing", 'eZBinaryFile' );
212 }
213
214 return $metaData;
215 }
216
217 function storedFileInfo()
218 {
219 $fileName = $this->attribute( 'filename' );
220 $mimeType = $this->attribute( 'mime_type' );
221 $originalFileName = $this->attribute( 'original_filename' );
222 $storageDir = eZSys::storageDirectory();
223 list( $group, $type ) = explode( '/', $mimeType );
224 $filePath = $storageDir . '/original/' . $group . '/' . $fileName;
225 return array( 'filename' => $fileName,
226 'original_filename' => $originalFileName,
227 'filepath' => $filePath,
228 'mime_type' => $mimeType );
229 }
230
231 public $ContentObjectAttributeID;
232 public $Filename;
233 public $OriginalFilename;
234 public $MimeType;
235 }
236
237 ?>
eZBinaryFile
The class eZBinaryFile handles registered binaryfiles.
Definition: ezbinaryfile.php:19
eZBinaryFile\mimeTypePart
mimeTypePart()
Definition: ezbinaryfile.php:88
eZBinaryFile\storedFileInfo
storedFileInfo()
Definition: ezbinaryfile.php:217
eZBinaryFile\definition
static definition()
Definition: ezbinaryfile.php:20
eZBinaryFile\$ContentObjectAttributeID
$ContentObjectAttributeID
Definition: ezbinaryfile.php:231
eZBinaryFile\mimeTypeCategory
mimeTypeCategory()
Definition: ezbinaryfile.php:82
eZBinaryFile\fetchByFileName
static fetchByFileName( $filename, $version=null, $asObject=true)
Definition: ezbinaryfile.php:126
eZBinaryFile\fetch
static fetch( $id, $version=null, $asObject=true)
Definition: ezbinaryfile.php:105
eZBinaryFile\metaData
metaData()
Definition: ezbinaryfile.php:167
eZBinaryFile\$MimeType
$MimeType
Definition: ezbinaryfile.php:234
eZBinaryFile\$Filename
$Filename
Definition: ezbinaryfile.php:232
eZBinaryFile\filePath
filePath()
Definition: ezbinaryfile.php:76
eZBinaryFile\$OriginalFilename
$OriginalFilename
Definition: ezbinaryfile.php:233
eZBinaryFile\fileSize
fileSize()
Definition: ezbinaryfile.php:62
eZBinaryFile\create
static create( $contentObjectAttributeID, $version)
Definition: ezbinaryfile.php:94
eZBinaryFile\removeByID
static removeByID( $id, $version)
Definition: ezbinaryfile.php:147
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZExtension\findExtensionType
static findExtensionType( $parameters, &$out)
Definition: ezextension.php:385
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZSys\storageDirectory
static storageDirectory()
Definition: ezsys.php:514
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.