[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezbinaryfilehandler.php (source)

   1  <?php
   2  //
   3  // Definition of eZBinaryFileHandler 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   \group eZBinaryHandlers Binary file handlers
  31  */
  32  
  33  /*!
  34    \class eZBinaryFileHandler ezbinaryfilehandler.php
  35    \ingroup eZKernel
  36    \brief Interface for all binary file handlers
  37  
  38  */
  39  
  40  define( "EZ_BINARY_FILE_HANDLE_UPLOAD", 0x1 );
  41  define( "EZ_BINARY_FILE_HANDLE_DOWNLOAD", 0x2 );
  42  
  43  define( "EZ_BINARY_FILE_HANDLE_ALL", EZ_BINARY_FILE_HANDLE_UPLOAD |
  44                                       EZ_BINARY_FILE_HANDLE_DOWNLOAD );
  45  
  46  define( "EZ_BINARY_FILE_TYPE_FILE", 'file' );
  47  define( "EZ_BINARY_FILE_TYPE_MEDIA", 'media' );
  48  
  49  define( "EZ_BINARY_FILE_RESULT_OK", 1 );
  50  define( "EZ_BINARY_FILE_RESULT_UNAVAILABLE", 2 );
  51  
  52  class eZBinaryFileHandler
  53  {
  54      function eZBinaryFileHandler( $identifier, $name, $handleType )
  55      {
  56          $this->Info = array();
  57          $this->Info['identifier'] = $identifier;
  58          $this->Info['name'] = $name;
  59          $this->Info['handle-type'] = $handleType;
  60      }
  61  
  62      function attributes()
  63      {
  64          return array_keys( $this->Info );
  65      }
  66  
  67      function hasAttribute( $attribute )
  68      {
  69          return isset( $this->Info[$attribute] );
  70      }
  71  
  72      function &attribute( $attribute )
  73      {
  74          if ( isset( $this->Info[$attribute] ) )
  75              return $this->Info[$attribute];
  76          else
  77          {
  78              eZDebug::writeError( "Attribute '$attribute' does not exist", 'eZBinaryFileHandler::attribute' );
  79              $retValue = null;
  80              return $retValue;
  81          }
  82      }
  83  
  84      /*!
  85       \return the suffix for the template name which will be used for attribute viewing.
  86       \note Default returns false which means no special template.
  87      */
  88      function &viewTemplate( &$contentobjectAttribute )
  89      {
  90          $retVal = false;
  91          return $retVal;
  92      }
  93  
  94      /*!
  95       \return the suffix for the template name which will be used for attribute viewing.
  96       \note Default returns false which means no special template.
  97      */
  98      function &editTemplate( &$contentobjectAttribute )
  99      {
 100          $retVal = false;
 101          return $retVal;
 102      }
 103  
 104      /*!
 105       \return the suffix for the template name which will be used for attribute viewing.
 106       \note Default returns false which means no special template.
 107      */
 108      function &informationTemplate( &$contentobjectAttribute )
 109      {
 110          $retVal = false;
 111          return $retVal;
 112      }
 113  
 114      /*!
 115       Figures out the filename from the binary object \a $binary.
 116       Currently supports eZBinaryFile, eZMedia and eZImageAliasHandler.
 117       \return \c false if no file was found.
 118       \param $returnMimeData If this is set to \c true then it will return a mime structure, otherwise it returns the filename.
 119       \deprecated
 120      */
 121      function storedFilename( &$binary, $returnMimeData = false )
 122      {
 123  
 124          $origDir = eZSys::storageDirectory() . '/original';
 125  
 126          $class = get_class( $binary );
 127          $fileName = false;
 128          $originalFilename = false;
 129          if ( in_array( $class, array( 'ezbinaryfile', 'ezmedia' ) ) )
 130          {
 131              $fileName = $origDir . "/" . $binary->attribute( 'mime_type_category' ) . '/'.  $binary->attribute( "filename" );
 132              $originalFilename = $binary->attribute( 'original_filename' );
 133          }
 134          else if ( $class == 'ezimagealiashandler' )
 135          {
 136              $alias = $binary->attribute( 'original' );
 137              if ( $alias )
 138                  $fileName = $alias['url'];
 139              $originalFilename = $binary->attribute( 'original_filename' );
 140          }
 141          if ( $fileName )
 142          {
 143              $mimeData = eZMimeType::findByFileContents( $fileName );
 144              $mimeData['original_filename'] = $originalFilename;
 145  
 146              if ( !isSet( $mimeData['name'] ) )
 147                  $mimeData['name'] = 'application/octet-stream';
 148  
 149              if ( $returnMimeData )
 150                  return $mimeData;
 151              else
 152                  return $mimeData['url'];
 153          }
 154          return false;
 155      }
 156  
 157      function handleUpload()
 158      {
 159          return false;
 160      }
 161  
 162      /*!
 163       \return the file object which corresponds to \a $contentObject and \a $contentObjectAttribute.
 164      */
 165      function downloadFileObject( &$contentObject, &$contentObjectAttribute )
 166      {
 167          $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
 168          $version = $contentObject->attribute( 'current_version' );
 169          $fileObject = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
 170          if ( $fileObject )
 171              return $fileObject;
 172          $fileObject = eZMedia::fetch( $contentObjectAttributeID, $version );
 173          return $fileObject;
 174      }
 175  
 176      /*!
 177       \return the file object type which corresponds to \a $contentObject and \a $contentObjectAttribute.
 178       \deprecated
 179      */
 180      function downloadType( &$contentObject, &$contentObjectAttribute )
 181      {
 182          $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
 183          $version = $contentObject->attribute( 'current_version' );
 184          $fileObject = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
 185          if ( $fileObject )
 186              return EZ_BINARY_FILE_TYPE_FILE;
 187          $fileObject = eZMedia::fetch( $contentObjectAttributeID, $version );
 188          if ( $fileObject )
 189              return EZ_BINARY_FILE_TYPE_MEDIA;
 190          return false;
 191      }
 192  
 193      /*!
 194       \return the download url for the file object which corresponds to \a $contentObject and \a $contentObjectAttribute.
 195       \deprecated
 196      */
 197      function downloadURL( &$contentObject, &$contentObjectAttribute )
 198      {
 199          $contentObjectID = $contentObject->attribute( 'id' );
 200          $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
 201          $downloadType = eZBinaryFileHandler::downloadType( $contentObject, $contentObjectAttribute );
 202          $downloadObject = eZBinaryFileHandler::downloadFileObject( $contentObject, $contentObjectAttribute );
 203          $name = '';
 204          switch ( $downloadType )
 205          {
 206              case EZ_BINARY_FILE_TYPE_FILE:
 207              {
 208                  $name = $downloadObject->attribute( 'original_filename' );
 209              } break;
 210              case EZ_BINARY_FILE_TYPE_MEDIA:
 211              {
 212                  $name = $downloadObject->attribute( 'original_filename' );
 213              } break;
 214              default:
 215              {
 216                  eZDebug::writeWarning( "Unknown binary file type '$downloadType'", 'eZBinaryFileHandler::downloadURL' );
 217              } break;
 218          }
 219          $url = "/content/download/$contentObjectID/$contentObjectAttributeID/$downloadType/$name";
 220          return $url;
 221      }
 222  
 223      function handleDownload( &$contentObject, &$contentObjectAttribute, $type )
 224      {
 225          include_once ( 'lib/ezutils/classes/ezmimetype.php' );
 226          include_once ( 'kernel/classes/datatypes/ezimage/ezimagealiashandler.php' );
 227          $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
 228          $version = $contentObject->attribute( 'current_version' );
 229  
 230  
 231  
 232          if ( !$contentObjectAttribute->hasStoredFileInformation( $contentObject, $version,
 233                                                                   $contentObjectAttribute->attribute( 'language_code' ) ) )
 234              return EZ_BINARY_FILE_RESULT_UNAVAILABLE;
 235  
 236          $fileInfo = $contentObjectAttribute->storedFileInformation( $contentObject, $version,
 237                                                                      $contentObjectAttribute->attribute( 'language_code' ) );
 238          if ( !$fileInfo )
 239              return EZ_BINARY_FILE_RESULT_UNAVAILABLE;
 240          if ( !$fileInfo['mime_type'] )
 241              return EZ_BINARY_FILE_RESULT_UNAVAILABLE;
 242  
 243          $contentObjectAttribute->handleDownload( $contentObject, $version,
 244                                                   $contentObjectAttribute->attribute( 'language_code' ) );
 245  
 246          return $this->handleFileDownload( $contentObject, $contentObjectAttribute, $type, $fileInfo );
 247      }
 248  
 249      function handleFileDownload( &$contentObject, &$contentObjectAttribute, $type, $mimeData )
 250      {
 251          return false;
 252      }
 253  
 254      function repositories()
 255      {
 256          return array( 'kernel/classes/binaryhandlers' );
 257      }
 258  
 259      function &instance( $identifier = false )
 260      {
 261          if ( $identifier === false )
 262          {
 263              $fileINI =& eZINI::instance( 'file.ini' );
 264              $identifier = $fileINI->variable( 'BinaryFileSettings', 'Handler' );
 265          }
 266          $instance =& $GLOBALS['eZBinaryFileHandlerInstance-' . $identifier];
 267          if ( !isset( $instance ) )
 268          {
 269              $handlerDirectory = $identifier;
 270              $handlerFilename = $identifier . "handler.php";
 271              if ( eZExtension::findExtensionType( array( 'ini-name' => 'file.ini',
 272                                                      'repository-group' => 'BinaryFileSettings',
 273                                                      'repository-variable' => 'Repositories',
 274                                                      'extension-group' => 'BinaryFileSettings',
 275                                                      'extension-variable' => 'ExtensionRepositories',
 276                                                      'type-directory' => true,
 277                                                      'type' => $identifier,
 278                                                      'subdir' => 'binaryhandlers',
 279                                                      'extension-subdir' => 'binaryhandlers',
 280                                                      'suffix-name' => 'handler.php' ),
 281                                               $out ) )
 282              {
 283                  include_once( $out['found-file-path'] );
 284                  $classname = $identifier . "handler";
 285                  $instance = new $classname();
 286              }
 287              else
 288                  eZDebug::writeError( "Could not find binary file handler '$identifier'", 'eZBinaryFileHandler::instance' );
 289          }
 290          return $instance;
 291      }
 292  
 293      /// \privatesection
 294      var $Info;
 295  }
 296  
 297  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7