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 define( "EZ_BINARY_FILE_HANDLE_UPLOAD", 0x1 );
00043 define( "EZ_BINARY_FILE_HANDLE_DOWNLOAD", 0x2 );
00044
00045 define( "EZ_BINARY_FILE_HANDLE_ALL", EZ_BINARY_FILE_HANDLE_UPLOAD |
00046 EZ_BINARY_FILE_HANDLE_DOWNLOAD );
00047
00048 define( "EZ_BINARY_FILE_TYPE_FILE", 'file' );
00049 define( "EZ_BINARY_FILE_TYPE_MEDIA", 'media' );
00050
00051 define( "EZ_BINARY_FILE_RESULT_OK", 1 );
00052 define( "EZ_BINARY_FILE_RESULT_UNAVAILABLE", 2 );
00053
00054 class eZBinaryFileHandler
00055 {
00056 function eZBinaryFileHandler( $identifier, $name, $handleType )
00057 {
00058 $this->Info = array();
00059 $this->Info['identifier'] = $identifier;
00060 $this->Info['name'] = $name;
00061 $this->Info['handle-type'] = $handleType;
00062 }
00063
00064 function attributes()
00065 {
00066 return array_keys( $this->Info );
00067 }
00068
00069 function hasAttribute( $attribute )
00070 {
00071 return isset( $this->Info[$attribute] );
00072 }
00073
00074 function &attribute( $attribute )
00075 {
00076 if ( isset( $this->Info[$attribute] ) )
00077 return $this->Info[$attribute];
00078 else
00079 {
00080 eZDebug::writeError( "Attribute '$attribute' does not exist", 'eZBinaryFileHandler::attribute' );
00081 $retValue = null;
00082 return $retValue;
00083 }
00084 }
00085
00086
00087
00088
00089
00090 function &viewTemplate( &$contentobjectAttribute )
00091 {
00092 $retVal = false;
00093 return $retVal;
00094 }
00095
00096
00097
00098
00099
00100 function &editTemplate( &$contentobjectAttribute )
00101 {
00102 $retVal = false;
00103 return $retVal;
00104 }
00105
00106
00107
00108
00109
00110 function &informationTemplate( &$contentobjectAttribute )
00111 {
00112 $retVal = false;
00113 return $retVal;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123 function storedFilename( &$binary, $returnMimeData = false )
00124 {
00125
00126 $origDir = eZSys::storageDirectory() . '/original';
00127
00128 $class = get_class( $binary );
00129 $fileName = false;
00130 $originalFilename = false;
00131 if ( in_array( $class, array( 'ezbinaryfile', 'ezmedia' ) ) )
00132 {
00133 $fileName = $origDir . "/" . $binary->attribute( 'mime_type_category' ) . '/'. $binary->attribute( "filename" );
00134 $originalFilename = $binary->attribute( 'original_filename' );
00135 }
00136 else if ( $class == 'ezimagealiashandler' )
00137 {
00138 $alias = $binary->attribute( 'original' );
00139 if ( $alias )
00140 $fileName = $alias['url'];
00141 $originalFilename = $binary->attribute( 'original_filename' );
00142 }
00143 if ( $fileName )
00144 {
00145 $mimeData = eZMimeType::findByFileContents( $fileName );
00146 $mimeData['original_filename'] = $originalFilename;
00147
00148 if ( !isSet( $mimeData['name'] ) )
00149 $mimeData['name'] = 'application/octet-stream';
00150
00151 if ( $returnMimeData )
00152 return $mimeData;
00153 else
00154 return $mimeData['url'];
00155 }
00156 return false;
00157 }
00158
00159 function handleUpload()
00160 {
00161 return false;
00162 }
00163
00164
00165
00166
00167 function downloadFileObject( &$contentObject, &$contentObjectAttribute )
00168 {
00169 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
00170 $version = $contentObject->attribute( 'current_version' );
00171 $fileObject = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
00172 if ( $fileObject )
00173 return $fileObject;
00174 $fileObject = eZMedia::fetch( $contentObjectAttributeID, $version );
00175 return $fileObject;
00176 }
00177
00178
00179
00180
00181
00182 function downloadType( &$contentObject, &$contentObjectAttribute )
00183 {
00184 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
00185 $version = $contentObject->attribute( 'current_version' );
00186 $fileObject = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
00187 if ( $fileObject )
00188 return EZ_BINARY_FILE_TYPE_FILE;
00189 $fileObject = eZMedia::fetch( $contentObjectAttributeID, $version );
00190 if ( $fileObject )
00191 return EZ_BINARY_FILE_TYPE_MEDIA;
00192 return false;
00193 }
00194
00195
00196
00197
00198
00199 function downloadURL( &$contentObject, &$contentObjectAttribute )
00200 {
00201 $contentObjectID = $contentObject->attribute( 'id' );
00202 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
00203 $downloadType = eZBinaryFileHandler::downloadType( $contentObject, $contentObjectAttribute );
00204 $downloadObject = eZBinaryFileHandler::downloadFileObject( $contentObject, $contentObjectAttribute );
00205 $name = '';
00206 switch ( $downloadType )
00207 {
00208 case EZ_BINARY_FILE_TYPE_FILE:
00209 {
00210 $name = $downloadObject->attribute( 'original_filename' );
00211 } break;
00212 case EZ_BINARY_FILE_TYPE_MEDIA:
00213 {
00214 $name = $downloadObject->attribute( 'original_filename' );
00215 } break;
00216 default:
00217 {
00218 eZDebug::writeWarning( "Unknown binary file type '$downloadType'", 'eZBinaryFileHandler::downloadURL' );
00219 } break;
00220 }
00221 $url = "/content/download/$contentObjectID/$contentObjectAttributeID/$downloadType/$name";
00222 return $url;
00223 }
00224
00225 function handleDownload( &$contentObject, &$contentObjectAttribute, $type )
00226 {
00227 include_once( 'lib/ezutils/classes/ezmimetype.php' );
00228 include_once( 'kernel/classes/datatypes/ezimage/ezimagealiashandler.php' );
00229 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
00230 $version = $contentObject->attribute( 'current_version' );
00231
00232
00233
00234 if ( !$contentObjectAttribute->hasStoredFileInformation( $contentObject, $version,
00235 $contentObjectAttribute->attribute( 'language_code' ) ) )
00236 return EZ_BINARY_FILE_RESULT_UNAVAILABLE;
00237
00238 $fileInfo = $contentObjectAttribute->storedFileInformation( $contentObject, $version,
00239 $contentObjectAttribute->attribute( 'language_code' ) );
00240 if ( !$fileInfo )
00241 return EZ_BINARY_FILE_RESULT_UNAVAILABLE;
00242 if ( !$fileInfo['mime_type'] )
00243 return EZ_BINARY_FILE_RESULT_UNAVAILABLE;
00244
00245 $contentObjectAttribute->handleDownload( $contentObject, $version,
00246 $contentObjectAttribute->attribute( 'language_code' ) );
00247
00248 return $this->handleFileDownload( $contentObject, $contentObjectAttribute, $type, $fileInfo );
00249 }
00250
00251 function handleFileDownload( &$contentObject, &$contentObjectAttribute, $type, $mimeData )
00252 {
00253 return false;
00254 }
00255
00256 function repositories()
00257 {
00258 return array( 'kernel/classes/binaryhandlers' );
00259 }
00260
00261 function &instance( $identifier = false )
00262 {
00263 if ( $identifier === false )
00264 {
00265 $fileINI =& eZINI::instance( 'file.ini' );
00266 $identifier = $fileINI->variable( 'BinaryFileSettings', 'Handler' );
00267 }
00268 $instance =& $GLOBALS['eZBinaryFileHandlerInstance-' . $identifier];
00269 if ( !isset( $instance ) )
00270 {
00271 $handlerDirectory = $identifier;
00272 $handlerFilename = $identifier . "handler.php";
00273 if ( eZExtension::findExtensionType( array( 'ini-name' => 'file.ini',
00274 'repository-group' => 'BinaryFileSettings',
00275 'repository-variable' => 'Repositories',
00276 'extension-group' => 'BinaryFileSettings',
00277 'extension-variable' => 'ExtensionRepositories',
00278 'type-directory' => true,
00279 'type' => $identifier,
00280 'subdir' => 'binaryhandlers',
00281 'extension-subdir' => 'binaryhandlers',
00282 'suffix-name' => 'handler.php' ),
00283 $out ) )
00284 {
00285 include_once( $out['found-file-path'] );
00286 $classname = $identifier . "handler";
00287 $instance = new $classname();
00288 }
00289 else
00290 eZDebug::writeError( "Could not find binary file handler '$identifier'", 'eZBinaryFileHandler::instance' );
00291 }
00292 return $instance;
00293 }
00294
00295
00296 var $Info;
00297 }
00298
00299 ?>