[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZBinaryFile class 4 // 5 // Created on: <30-Apr-2002 16:47:08 bf> 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 /*! 30 \class eZBinaryFile ezbinaryfile.php 31 \ingroup eZDatatype 32 \brief The class eZBinaryFile handles registered binaryfiles 33 34 */ 35 36 include_once ( 'lib/ezdb/classes/ezdb.php' ); 37 include_once ( 'kernel/classes/ezpersistentobject.php' ); 38 include_once ( 'kernel/classes/ezcontentclassattribute.php' ); 39 include_once ( 'kernel/classes/ezbinaryfilehandler.php' ); 40 41 class eZBinaryFile extends eZPersistentObject 42 { 43 function eZBinaryFile( $row ) 44 { 45 $this->eZPersistentObject( $row ); 46 } 47 48 function definition() 49 { 50 return array( 'fields' => array( 'contentobject_attribute_id' => array( 'name' => 'ContentObjectAttributeID', 51 'datatype' => 'integer', 52 'default' => 0, 53 'required' => true, 54 'foreign_class' => 'eZContentObjectAttribute', 55 'foreign_attribute' => 'id', 56 'multiplicity' => '1..*' ), 57 'version' => array( 'name' => 'Version', 58 'datatype' => 'integer', 59 'default' => 0, 60 'required' => true ), 61 'filename' => array( 'name' => 'Filename', 62 'datatype' => 'string', 63 'default' => '', 64 'required' => true ), 65 'original_filename' => array( 'name' => 'OriginalFilename', 66 'datatype' => 'string', 67 'default' => '', 68 'required' => true ), 69 'mime_type' => array( 'name' => 'MimeType', 70 'datatype' => 'string', 71 'default' => '', 72 'required' => true ), 73 'download_count' => array( 'name' => 'DownloadCount', 74 'datatype' => 'integer', 75 'default' => 0, 76 'required' => true ) ), 77 'keys' => array( 'contentobject_attribute_id', 'version' ), 78 'relations' => array( 'contentobject_attribute_id' => array( 'class' => 'ezcontentobjectattribute', 79 'field' => 'id' ) ), 80 "function_attributes" => array( 'filesize' => 'fileSize', 81 'filepath' => 'filePath', 82 'mime_type_category' => 'mimeTypeCategory', 83 'mime_type_part' => 'mimeTypePart' ), 84 'class_name' => 'eZBinaryFile', 85 'name' => 'ezbinaryfile' ); 86 } 87 88 89 function &fileSize() 90 { 91 $fileInfo = $this->storedFileInfo(); 92 93 // VS-DBFILE 94 95 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 96 $file = eZClusterFileHandler::instance( $fileInfo['filepath'] ); 97 if ( $file->exists() ) 98 { 99 $stat = $file->stat(); 100 $fileSize = $stat['size']; 101 } 102 else 103 $fileSize = 0; 104 return $fileSize; 105 } 106 107 function &filePath() 108 { 109 $fileInfo = $this->storedFileInfo(); 110 return $fileInfo['filepath']; 111 } 112 113 function &mimeTypeCategory() 114 { 115 $types = explode( '/', eZPersistentObject::attribute( 'mime_type' ) ); 116 return $types[0]; 117 } 118 119 function &mimeTypePart() 120 { 121 $types = explode( '/', eZPersistentObject::attribute( 'mime_type' ) ); 122 return $types[1]; 123 } 124 125 function create( $contentObjectAttributeID, $version ) 126 { 127 $row = array( 'contentobject_attribute_id' => $contentObjectAttributeID, 128 'version' => $version, 129 'filename' => '', 130 'original_filename' => '', 131 'mime_type' => '' 132 ); 133 return new eZBinaryFile( $row ); 134 } 135 136 function fetch( $id, $version = null, $asObject = true ) 137 { 138 if ( $version == null ) 139 { 140 return eZPersistentObject::fetchObjectList( eZBinaryFile::definition(), 141 null, 142 array( 'contentobject_attribute_id' => $id ), 143 null, 144 null, 145 $asObject ); 146 } 147 else 148 { 149 return eZPersistentObject::fetchObject( eZBinaryFile::definition(), 150 null, 151 array( 'contentobject_attribute_id' => $id, 152 'version' => $version ), 153 $asObject ); 154 } 155 } 156 157 function fetchByFileName( $filename, $version = null, $asObject = true ) 158 { 159 if ( $version == null ) 160 { 161 return eZPersistentObject::fetchObjectList( eZBinaryFile::definition(), 162 null, 163 array( 'filename' => $filename ), 164 null, 165 null, 166 $asObject ); 167 } 168 else 169 { 170 return eZPersistentObject::fetchObject( eZBinaryFile::definition(), 171 null, 172 array( 'filename' => $filename, 173 'version' => $version ), 174 $asObject ); 175 } 176 } 177 178 function remove( $id, $version ) 179 { 180 if ( $version == null ) 181 { 182 eZPersistentObject::removeObject( eZBinaryFile::definition(), 183 array( 'contentobject_attribute_id' => $id ) ); 184 } 185 else 186 { 187 eZPersistentObject::removeObject( eZBinaryFile::definition(), 188 array( 'contentobject_attribute_id' => $id, 189 'version' => $version ) ); 190 } 191 } 192 193 194 /*! 195 \return the medatata from the binary file, if extraction is supported 196 for the current mimetype. 197 */ 198 function &metaData() 199 { 200 $metaData = ""; 201 $binaryINI =& eZINI::instance( 'binaryfile.ini' ); 202 203 $handlerSettings = $binaryINI->variable( 'HandlerSettings', 'MetaDataExtractor' ); 204 205 if ( isset( $handlerSettings[$this->MimeType] ) ) 206 { 207 // Check if plugin exists 208 if ( eZExtension::findExtensionType( array( 'ini-name' => 'binaryfile.ini', 209 'repository-group' => 'HandlerSettings', 210 'repository-variable' => 'Repositories', 211 'extension-group' => 'HandlerSettings', 212 'extension-variable' => 'ExtensionRepositories', 213 'type-directory' => false, 214 'type' => $handlerSettings[$this->MimeType], 215 'subdir' => 'plugins', 216 'extension-subdir' => 'plugins', 217 'suffix-name' => 'parser.php' ), 218 $out ) ) 219 { 220 $filePath = $out['found-file-path']; 221 include_once( $filePath ); 222 $class = $handlerSettings[$this->MimeType] . 'Parser'; 223 224 $parserObject = new $class( ); 225 $fileInfo = $this->storedFileInfo(); 226 227 // VS-DBFILE 228 229 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 230 $file = eZClusterFileHandler::instance( $fileInfo['filepath'] ); 231 if ( $file->exists() ) 232 { 233 $file->fetch(); 234 $metaData =& $parserObject->parseFile( $fileInfo['filepath'] ); 235 $file->deleteLocal(); 236 } 237 } 238 else 239 { 240 eZDebug::writeWarning( "Plugin for $this->MimeType was not found", 'eZBinaryFile' ); 241 } 242 } 243 else 244 { 245 eZDebug::writeWarning( "Mimetype $this->MimeType not supported for indexing", 'eZBinaryFile' ); 246 } 247 248 return $metaData; 249 } 250 251 function storedFileInfo() 252 { 253 $fileName = $this->attribute( 'filename' ); 254 $mimeType = $this->attribute( 'mime_type' ); 255 $originalFileName = $this->attribute( 'original_filename' ); 256 $storageDir = eZSys::storageDirectory(); 257 list( $group, $type ) = explode( '/', $mimeType ); 258 $filePath = $storageDir . '/original/' . $group . '/' . $fileName; 259 return array( 'filename' => $fileName, 260 'original_filename' => $originalFileName, 261 'filepath' => $filePath, 262 'mime_type' => $mimeType ); 263 } 264 265 var $ContentObjectAttributeID; 266 var $Filename; 267 var $OriginalFilename; 268 var $MimeType; 269 } 270 271 ?>
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 |