|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZBinaryFileHandler class 00004 // 00005 // Created on: <30-Apr-2002 16:47:08 bf> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! 00032 \group eZBinaryHandlers Binary file handlers 00033 */ 00034 00035 /*! 00036 \class eZBinaryFileHandler ezbinaryfilehandler.php 00037 \ingroup eZKernel 00038 \brief Interface for all binary file handlers 00039 00040 */ 00041 00042 class eZBinaryFileHandler 00043 { 00044 const HANDLE_UPLOAD = 0x1; 00045 const HANDLE_DOWNLOAD = 0x2; 00046 00047 const HANDLE_ALL = 0x3; // HANDLE_UPLOAD | HANDLE_DOWNLOAD 00048 00049 const TYPE_FILE = 'file'; 00050 const TYPE_MEDIA = 'media'; 00051 00052 const RESULT_OK = 1; 00053 const RESULT_UNAVAILABLE = 2; 00054 00055 function eZBinaryFileHandler( $identifier, $name, $handleType ) 00056 { 00057 $this->Info = array(); 00058 $this->Info['identifier'] = $identifier; 00059 $this->Info['name'] = $name; 00060 $this->Info['handle-type'] = $handleType; 00061 } 00062 00063 function attributes() 00064 { 00065 return array_keys( $this->Info ); 00066 } 00067 00068 function hasAttribute( $attribute ) 00069 { 00070 return isset( $this->Info[$attribute] ); 00071 } 00072 00073 function attribute( $attribute ) 00074 { 00075 if ( isset( $this->Info[$attribute] ) ) 00076 { 00077 return $this->Info[$attribute]; 00078 } 00079 00080 eZDebug::writeError( "Attribute '$attribute' does not exist", 'eZBinaryFileHandler::attribute' ); 00081 return null; 00082 } 00083 00084 /*! 00085 \return the suffix for the template name which will be used for attribute viewing. 00086 \note Default returns false which means no special template. 00087 */ 00088 function viewTemplate( $contentobjectAttribute ) 00089 { 00090 $retVal = false; 00091 return $retVal; 00092 } 00093 00094 /*! 00095 \return the suffix for the template name which will be used for attribute viewing. 00096 \note Default returns false which means no special template. 00097 */ 00098 function editTemplate( $contentobjectAttribute ) 00099 { 00100 $retVal = false; 00101 return $retVal; 00102 } 00103 00104 /*! 00105 \return the suffix for the template name which will be used for attribute viewing. 00106 \note Default returns false which means no special template. 00107 */ 00108 function informationTemplate( $contentobjectAttribute ) 00109 { 00110 $retVal = false; 00111 return $retVal; 00112 } 00113 00114 /*! 00115 Figures out the filename from the binary object \a $binary. 00116 Currently supports eZBinaryFile, eZMedia and eZImageAliasHandler. 00117 \return \c false if no file was found. 00118 \param $returnMimeData If this is set to \c true then it will return a mime structure, otherwise it returns the filename. 00119 \deprecated 00120 */ 00121 function storedFilename( &$binary, $returnMimeData = false ) 00122 { 00123 00124 $origDir = eZSys::storageDirectory() . '/original'; 00125 00126 $class = get_class( $binary ); 00127 $fileName = false; 00128 $originalFilename = false; 00129 if ( in_array( $class, array( 'eZBinaryFile', 'eZMedia' ) ) ) 00130 { 00131 $fileName = $origDir . "/" . $binary->attribute( 'mime_type_category' ) . '/'. $binary->attribute( "filename" ); 00132 $originalFilename = $binary->attribute( 'original_filename' ); 00133 } 00134 else if ( $class == 'eZImageAliasHandler' ) 00135 { 00136 $alias = $binary->attribute( 'original' ); 00137 if ( $alias ) 00138 $fileName = $alias['url']; 00139 $originalFilename = $binary->attribute( 'original_filename' ); 00140 } 00141 if ( $fileName ) 00142 { 00143 $mimeData = eZMimeType::findByFileContents( $fileName ); 00144 $mimeData['original_filename'] = $originalFilename; 00145 00146 if ( !isSet( $mimeData['name'] ) ) 00147 $mimeData['name'] = 'application/octet-stream'; 00148 00149 if ( $returnMimeData ) 00150 return $mimeData; 00151 else 00152 return $mimeData['url']; 00153 } 00154 return false; 00155 } 00156 00157 function handleUpload() 00158 { 00159 return false; 00160 } 00161 00162 /*! 00163 \return the file object which corresponds to \a $contentObject and \a $contentObjectAttribute. 00164 */ 00165 function downloadFileObject( $contentObject, $contentObjectAttribute ) 00166 { 00167 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' ); 00168 $version = $contentObject->attribute( 'current_version' ); 00169 $fileObject = eZBinaryFile::fetch( $contentObjectAttributeID, $version ); 00170 if ( $fileObject ) 00171 return $fileObject; 00172 $fileObject = eZMedia::fetch( $contentObjectAttributeID, $version ); 00173 return $fileObject; 00174 } 00175 00176 /*! 00177 \return the file object type which corresponds to \a $contentObject and \a $contentObjectAttribute. 00178 \deprecated 00179 */ 00180 function downloadType( $contentObject, $contentObjectAttribute ) 00181 { 00182 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' ); 00183 $version = $contentObject->attribute( 'current_version' ); 00184 $fileObject = eZBinaryFile::fetch( $contentObjectAttributeID, $version ); 00185 if ( $fileObject ) 00186 return self::TYPE_FILE; 00187 $fileObject = eZMedia::fetch( $contentObjectAttributeID, $version ); 00188 if ( $fileObject ) 00189 return self::TYPE_MEDIA; 00190 return false; 00191 } 00192 00193 /*! 00194 \return the download url for the file object which corresponds to \a $contentObject and \a $contentObjectAttribute. 00195 \deprecated 00196 */ 00197 function downloadURL( $contentObject, $contentObjectAttribute ) 00198 { 00199 $contentObjectID = $contentObject->attribute( 'id' ); 00200 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' ); 00201 $downloadType = eZBinaryFileHandler::downloadType( $contentObject, $contentObjectAttribute ); 00202 $downloadObject = eZBinaryFileHandler::downloadFileObject( $contentObject, $contentObjectAttribute ); 00203 $name = ''; 00204 switch ( $downloadType ) 00205 { 00206 case self::TYPE_FILE: 00207 { 00208 $name = $downloadObject->attribute( 'original_filename' ); 00209 } break; 00210 case self::TYPE_MEDIA: 00211 { 00212 $name = $downloadObject->attribute( 'original_filename' ); 00213 } break; 00214 default: 00215 { 00216 eZDebug::writeWarning( "Unknown binary file type '$downloadType'", 'eZBinaryFileHandler::downloadURL' ); 00217 } break; 00218 } 00219 $url = "/content/download/$contentObjectID/$contentObjectAttributeID/$downloadType/$name"; 00220 return $url; 00221 } 00222 00223 function handleDownload( $contentObject, $contentObjectAttribute, $type ) 00224 { 00225 //include_once( 'lib/ezutils/classes/ezmimetype.php' ); 00226 //include_once( 'kernel/classes/datatypes/ezimage/ezimagealiashandler.php' ); 00227 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' ); 00228 $version = $contentObject->attribute( 'current_version' ); 00229 00230 00231 00232 if ( !$contentObjectAttribute->hasStoredFileInformation( $contentObject, $version, 00233 $contentObjectAttribute->attribute( 'language_code' ) ) ) 00234 return self::RESULT_UNAVAILABLE; 00235 00236 $fileInfo = $contentObjectAttribute->storedFileInformation( $contentObject, $version, 00237 $contentObjectAttribute->attribute( 'language_code' ) ); 00238 if ( !$fileInfo ) 00239 return self::RESULT_UNAVAILABLE; 00240 if ( !$fileInfo['mime_type'] ) 00241 return self::RESULT_UNAVAILABLE; 00242 00243 $contentObjectAttribute->handleDownload( $contentObject, $version, 00244 $contentObjectAttribute->attribute( 'language_code' ) ); 00245 00246 return $this->handleFileDownload( $contentObject, $contentObjectAttribute, $type, $fileInfo ); 00247 } 00248 00249 function handleFileDownload( $contentObject, $contentObjectAttribute, $type, $mimeData ) 00250 { 00251 return false; 00252 } 00253 00254 function repositories() 00255 { 00256 return array( 'kernel/classes/binaryhandlers' ); 00257 } 00258 00259 static function instance( $identifier = false ) 00260 { 00261 if ( $identifier === false ) 00262 { 00263 $fileINI = eZINI::instance( 'file.ini' ); 00264 $identifier = $fileINI->variable( 'BinaryFileSettings', 'Handler' ); 00265 } 00266 $instance =& $GLOBALS['eZBinaryFileHandlerInstance-' . $identifier]; 00267 if ( !isset( $instance ) ) 00268 { 00269 $handlerDirectory = $identifier; 00270 $handlerFilename = $identifier . "handler.php"; 00271 if ( eZExtension::findExtensionType( array( 'ini-name' => 'file.ini', 00272 'repository-group' => 'BinaryFileSettings', 00273 'repository-variable' => 'Repositories', 00274 'extension-group' => 'BinaryFileSettings', 00275 'extension-variable' => 'ExtensionRepositories', 00276 'type-directory' => true, 00277 'type' => $identifier, 00278 'subdir' => 'binaryhandlers', 00279 'extension-subdir' => 'binaryhandlers', 00280 'suffix-name' => 'handler.php' ), 00281 $out ) ) 00282 { 00283 include_once( $out['found-file-path'] ); 00284 $classname = $identifier . "handler"; 00285 $instance = new $classname(); 00286 } 00287 else 00288 { 00289 eZDebug::writeError( "Could not find binary file handler '$identifier'", 'eZBinaryFileHandler::instance' ); 00290 } 00291 } 00292 return $instance; 00293 } 00294 00295 /// \privatesection 00296 public $Info; 00297 } 00298 00299 ?>