[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Definition of eZContentUpload class
   4  //
   5  // Created on: <28-Apr-2003 11:04:47 sp>
   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  /*! \file ezcontentupload.php
  30  */
  31  
  32  /*!
  33    \class eZContentUpload ezcontentupload.php
  34    \brief Handles simple creation of content objects by uploading files
  35  
  36    This class makes it easy to use the start a new file upload
  37    and let it be created as a content object.
  38  
  39    Using it is simply to call the \link upload \endlink function with some parameters.
  40  
  41  \code
  42  eZContentUpload::upload( array( 'action_name' => 'MyActionName' ), $module );
  43  \endcode
  44  
  45    It requires the module objects as the second parameter to redirect and the first
  46    define how the upload page should behave. Normally you just want to set \c action_name
  47    and define the behaviour of that action in settings/upload.ini.
  48  
  49    Fetching the result afterwards is done by calling the result() method, it will return
  50    the resulting node ID or object ID depending on the configuration of the upload action.
  51  
  52  \code
  53  eZContentUpload::result( 'MyActionName' );
  54  \endcode
  55  
  56    It is also possible to use this class to upload a given file (HTTP or regular) as an object.
  57    The correct class and location can be determined automatically.
  58  
  59    Simply create an instance and then call handleUpload() or handleLocalFile().
  60  
  61  \code
  62  $upload = new eZContentUpload();
  63  $upload->handleUpload( $result, 'UploadFile', 'auto', false );
  64  
  65  $upload->handleLocalFile( $result, 'a_yellow_flower.jpg', 'auto' );
  66  \endcode
  67  */
  68  
  69  include_once ( 'lib/ezutils/classes/ezhttptool.php' );
  70  include_once ( 'lib/ezutils/classes/ezini.php' );
  71  include_once ( 'kernel/classes/ezcontentobject.php' );
  72  
  73  define( "EZ_CONTENTUPLOAD_STATUS_PERMISSION_DENIED", 1 );
  74  
  75  class eZContentUpload
  76  {
  77      /*!
  78       Initializes the object with the session data if they are found.
  79       If \a $params is supplied it used instead.
  80      */
  81      function eZContentUpload( $params = false )
  82      {
  83          $http =& eZHTTPTool::instance();
  84          if ( !$params && $http->hasSessionVariable( 'ContentUploadParameters' ) )
  85          {
  86              $this->Parameters =& $http->sessionVariable( 'ContentUploadParameters' );
  87          }
  88          else
  89          {
  90              if ( $params === false )
  91                  $params = array();
  92              $this->Parameters = $params;
  93          }
  94      }
  95  
  96      /*!
  97       \return an array with attribute names.
  98      */
  99      function attributes()
 100      {
 101          return array_keys( $this->Parameters );
 102      }
 103  
 104      /*!
 105       \return true if the attribute name \a $attributeName is among the upload parameters.
 106      */
 107      function hasAttribute( $attributeName )
 108      {
 109          return array_key_exists( $attributeName, $this->Parameters );
 110      }
 111  
 112      /*!
 113       \return the attribute value of the attribute named \a $attributeName or \c null if no such attribute.
 114      */
 115      function &attribute( $attributeName )
 116      {
 117          if ( isset( $this->Parameters[$attributeName] ) )
 118              return $this->Parameters[$attributeName];
 119          {
 120              eZDebug::writeError( "Attribute '$attributeName' does not exist", 'eZContentUpload::attribute' );
 121              $attribute = null;
 122              return $attribute;
 123          }
 124      }
 125  
 126      /*!
 127       \static
 128       Sets some session data taken from \a $parameters and start the upload module by redirecting to it using \a $module.
 129       Most data will be automatically derived from the \c action_name value taken from settings/upload.ini, other
 130       values will override default values.
 131      */
 132      function upload( $parameters = array(), &$module )
 133      {
 134          $ini =& eZINI::instance( 'upload.ini' );
 135  
 136          if ( !isset( $parameters['action_name'] ) )
 137              $parameters['action_name'] = $ini->variable( 'UploadSettings', 'DefaultActionName' );
 138  
 139          if ( !isset( $parameters['result_action_name'] ) )
 140              $parameters['result_action_name'] = $parameters['action_name'];
 141  
 142          if ( !isset( $parameters['navigation_part_identifier'] ) )
 143              $parameters['navigation_part_identifier'] = false;
 144          if ( !$parameters['navigation_part_identifier'] and
 145               $ini->hasVariable( 'UploadSettings', 'NavigationPartIdentifier' ) )
 146              $parameters['navigation_part_identifier'] = $ini->variable( 'UploadSettings', 'NavigationPartIdentifier' );
 147  
 148          if ( !isset( $parameters['type'] ) )
 149              $parameters['type'] = $parameters['action_name'];
 150  
 151          if ( !isset( $parameters['return_type'] ) )
 152          {
 153              if ( $ini->hasVariable( $parameters['type'], 'ReturnType' ) )
 154                  $parameters['return_type'] = $ini->variable( $parameters['type'], 'ReturnType' );
 155              else
 156                  $parameters['return_type'] = $ini->variable( 'UploadSettings', 'DefaultReturnType' );
 157          }
 158  
 159          if ( !isset( $parameters['upload_custom_action'] ) )
 160              $parameters['upload_custom_action'] = false;
 161  
 162          if ( !isset( $parameters['custom_action_data'] ) )
 163              $parameters['custom_action_data'] = false;
 164  
 165          if ( !isset( $parameters['description_template'] ) )
 166              $parameters['description_template'] = false;
 167  
 168          if ( !isset( $parameters['parent_nodes'] ) )
 169          {
 170              $parameters['parent_nodes'] = false;
 171              if ( $ini->hasVariable( $parameters['type'], 'ParentNodes' ) )
 172              {
 173                  $parameters['parent_nodes'] = $ini->variable( $parameters['type'], 'ParentNodes' );
 174              }
 175          }
 176  
 177          if ( !isset( $parameters['persistent_data'] ) )
 178              $parameters['persistent_data'] = false;
 179  
 180          if ( isset( $parameters['parent_nodes'] ) and
 181               is_array( $parameters['parent_nodes'] ) )
 182          {
 183              foreach ( $parameters['parent_nodes'] as $key => $parentNode )
 184              {
 185                  if ( !is_numeric( $parentNode ) )
 186                  {
 187                      $parameters['parent_nodes'][$key] = eZContentUpload::nodeAliasID( $parentNode );
 188                  }
 189              }
 190          }
 191  
 192          if ( !isset( $parameters['result_uri'] ) )
 193              $parameters['result_uri'] = false;
 194  
 195          if ( !isset( $parameters['cancel_uri'] ) )
 196              $parameters['cancel_uri'] = false;
 197  
 198          if ( !isset( $parameters['result_module'] ) )
 199              $parameters['result_module'] = false;
 200  
 201          $parameters['result'] = false;
 202  
 203          $http =& eZHTTPTool::instance();
 204          $http->setSessionVariable( 'ContentUploadParameters', $parameters );
 205  
 206          if ( is_null( $module ) )
 207          {
 208              return "/content/upload/";
 209          }
 210          else
 211          {
 212              $module->redirectTo( "/content/upload/" );
 213              return "/content/upload/";
 214          }
 215      }
 216  
 217      /*!
 218       Fetches the local file, figures out its MIME-type and creates the proper content object out of it.
 219  
 220       \param $filePath Path to file which should be stored.
 221       \param $result Result data, will be filled with information which the client can examine, contains:
 222                      - errors - An array with errors, each element is an array with \c 'description' containing the text
 223       \param $location The node ID which the new object will be placed or the string \c 'auto' for automatic placement of type.
 224       \param $existingNode Pass a contentobjecttreenode object to let the uploading be done to an existing object,
 225                            if not it will create one from scratch.
 226  
 227       \return \c false if something failed or \c true if succesful.
 228       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 229       the calls within a db transaction; thus within db->begin and db->commit.
 230      */
 231      function handleLocalFile( &$result, $filePath, $location, $existingNode, $nameString = '' )
 232      {
 233          $result = array( 'errors' => array(),
 234                           'notices' => array(),
 235                           'result' => false,
 236                           'redirect_url' => false,
 237                           'status' => false );
 238          $errors =& $result['errors'];
 239          $notices =& $result['notices'];
 240  
 241          if ( !file_exists( $filePath ) )
 242          {
 243              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 244                                                          'The file %filename does not exist, cannot insert file.', null,
 245                                                          array( '%filename' => $filePath ) ) );
 246              return false;
 247          }
 248          include_once ( 'lib/ezutils/classes/ezmimetype.php' );
 249          $mimeData = eZMimeType::findByFileContents( $filePath );
 250          $mime = $mimeData['name'];
 251  
 252          $handler =& $this->findHandler( $result, $mimeData );
 253          if ( $handler === false )
 254          {
 255              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 256                                                          'There was an error trying to instantiate content upload handler.' ) );
 257              return false;
 258          }
 259  
 260          // If this is an object we have a special handler for the file.
 261          // The handler will be responsible for the rest of the execution.
 262          if ( is_object( $handler ) )
 263          {
 264              $originalFilename = $filePath;
 265              return $handler->handleFile( $this, $result,
 266                                           $filePath, $originalFilename, $mimeData,
 267                                           $location, $existingNode );
 268          }
 269  
 270          $object = false;
 271          $class = false;
 272          // Figure out class identifier from an existing node
 273          // if not we will have to detect it from the mimetype
 274          if ( is_object( $existingNode ) )
 275          {
 276              $object =& $existingNode->object();
 277              $class =& $object->contentClass();
 278              $classIdentifier = $class->attribute( 'identifier' );
 279          }
 280          else
 281          {
 282              $classIdentifier = $this->detectClassIdentifier( $mime );
 283          }
 284  
 285          if ( !$classIdentifier )
 286          {
 287              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 288                                                          'No matching class identifier found.' ) );
 289              return false;
 290          }
 291  
 292          if ( !is_object( $class ) )
 293              $class = eZContentClass::fetchByIdentifier( $classIdentifier );
 294  
 295          if ( !$class )
 296          {
 297              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 298                                                          'The class %class_identifier does not exist.', null,
 299                                                          array( '%class_identifier' => $classIdentifier ) ) );
 300              return false;
 301          }
 302  
 303          $parentNodes = false;
 304          $parentMainNode = false;
 305          // If do not have an existing node we need to figure
 306          // out the locations from $location and $classIdentifier
 307          if ( !is_object( $existingNode ) )
 308          {
 309              $locationOK = $this->detectLocations( $classIdentifier, $class, $location, $parentNodes, $parentMainNode );
 310              if ( $locationOK === false )
 311              {
 312                  $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 313                                                              'Was not able to figure out placement of object.' ) );
 314                  return false;
 315              }
 316              elseif ( $locationOK === null )
 317              {
 318                  $result['status'] = EZ_CONTENTUPLOAD_STATUS_PERMISSION_DENIED;
 319                  $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 320                                                              'Permission denied' ) );
 321                  return false;
 322              }
 323          }
 324  
 325          $uploadINI =& eZINI::instance( 'upload.ini' );
 326          $iniGroup = $classIdentifier . '_ClassSettings';
 327          if ( !$uploadINI->hasGroup( $iniGroup ) )
 328          {
 329              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 330                                                          'No configuration group in upload.ini for class identifier %class_identifier.', null,
 331                                                          array( '%class_identifier' => $classIdentifier ) ) );
 332              return false;
 333          }
 334  
 335          $fileAttribute = $uploadINI->variable( $iniGroup, 'FileAttribute' );
 336          $dataMap = $class->dataMap();
 337  
 338          $fileAttribute = $this->findRegularFileAttribute( $dataMap, $fileAttribute );
 339          if ( !$fileAttribute )
 340          {
 341              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 342                                                          'No matching file attribute found, cannot create content object without this.' ) );
 343              return false;
 344          }
 345  
 346          $nameAttribute = $uploadINI->variable( $iniGroup, 'NameAttribute' );
 347          if ( !$nameAttribute )
 348          {
 349              $nameAttribute = $this->findStringAttribute( $dataMap, $nameAttribute );
 350          }
 351          if ( !$nameAttribute )
 352          {
 353              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 354                                                          'No matching name attribute found, cannot create content object without this.' ) );
 355              return false;
 356          }
 357  
 358          $variables = array( 'original_filename' => $mimeData['filename'],
 359                              'mime_type' => $mime );
 360          $variables['original_filename_base'] = $mimeData['basename'];
 361          $variables['original_filename_suffix'] = $mimeData['suffix'];
 362  
 363          if ( !$nameString )
 364          {
 365              $namePattern = $uploadINI->variable( $iniGroup, 'NamePattern' );
 366              $nameString = $this->processNamePattern( $variables, $namePattern );
 367          }
 368          // If we have an existing node we need to create
 369          // a new version in it.
 370          // If we don't we have to make a new object
 371          if ( is_object( $existingNode ) )
 372          {
 373              if ( $existingNode->canEdit( ) != '1' )
 374              {
 375                  $result['status'] = EZ_CONTENTUPLOAD_STATUS_PERMISSION_DENIED;
 376                  $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 377                                                              'Permission denied' ) );
 378                  return false;
 379              }
 380              $version = $object->createNewVersion( false, true );
 381              unset( $dataMap );
 382              $dataMap =& $version->dataMap();
 383              $publishVersion = $version->attribute( 'version' );
 384          }
 385          else
 386          {
 387              $object = $class->instantiate();
 388              unset( $dataMap );
 389              $dataMap =& $object->dataMap();
 390              $publishVersion = $object->attribute( 'current_version' );
 391          }
 392  
 393          $status = $dataMap[$fileAttribute]->insertRegularFile( $object, $publishVersion, eZContentObject::defaultLanguage(),
 394                                                                 $filePath,
 395                                                                 $storeResult );
 396          if ( $status === null )
 397          {
 398              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 399                                                          'The attribute %class_identifier does not support regular file storage.', null,
 400                                                          array( '%class_identifier' => $classIdentifier ) ) );
 401              return false;
 402          }
 403          else if ( !$status )
 404          {
 405              $errors = array_merge( $errors, $storeResult['errors'] );
 406              return false;
 407          }
 408          if ( $storeResult['require_storage'] )
 409              $dataMap[$fileAttribute]->store();
 410  
 411          $status = $dataMap[$nameAttribute]->insertSimpleString( $object, $publishVersion, eZContentObject::defaultLanguage(),
 412                                                                  $nameString,
 413                                                                  $storeResult );
 414          if ( $status === null )
 415          {
 416              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 417                                                          'The attribute %class_identifier does not support simple string storage.', null,
 418                                                          array( '%class_identifier' => $classIdentifier ) ) );
 419              return false;
 420          }
 421          else if ( !$status )
 422          {
 423              $errors = array_merge( $errors, $storeResult['errors'] );
 424              return false;
 425          }
 426          if ( $storeResult['require_storage'] )
 427              $dataMap[$nameAttribute]->store();
 428  
 429          return $this->publishObject( $result, $errors, $notices,
 430                                       $object, $publishVersion, $class, $parentNodes, $parentMainNode );
 431      }
 432  
 433      /*!
 434       Fetches the uploaded file, figures out its MIME-type and creates the proper content object out of it.
 435  
 436       \param $httpFileIdentifier The HTTP identifier of the uploaded file, this must match the \em name of your \em input tag.
 437       \param $result Result data, will be filled with information which the client can examine, contains:
 438                      - errors - An array with errors, each element is an array with \c 'description' containing the text
 439       \param $location The node ID which the new object will be placed or the string \c 'auto' for automatic placement of type.
 440       \param $existingNode Pass a contentobjecttreenode object to let the uploading be done to an existing object,
 441                            if not it will create one from scratch.
 442  
 443       \return \c false if something failed or \c true if succesful.
 444       \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
 445       the calls within a db transaction; thus within db->begin and db->commit.
 446      */
 447      function handleUpload( &$result, $httpFileIdentifier, $location, $existingNode, $nameString = '' )
 448      {
 449          $result = array( 'errors' => array(),
 450                           'notices' => array(),
 451                           'result' => false,
 452                           'redirect_url' => false );
 453          $errors =& $result['errors'];
 454          $notices =& $result['notices'];
 455  
 456          $this->fetchHTTPFile( $httpFileIdentifier, $errors, $file, $mimeData );
 457          if ( !$file )
 458          {
 459              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 460                                                          'No HTTP file found, cannot fetch uploaded file.' ) );
 461              return false;
 462          }
 463          $mime = $mimeData['name'];
 464          if ( $mime == '' )
 465              $mime = $file->attribute( "mime_type" );
 466  
 467          $handler =& $this->findHandler( $result, $mimeData );
 468          if ( $handler === false )
 469          {
 470              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 471                                                          'There was an error trying to instantiate content upload handler.' ) );
 472              return false;
 473          }
 474  
 475          // If this is an object we have a special handler for the file
 476          // The handler will be responsible for the rest of the execution.
 477          if ( is_object( $handler ) )
 478          {
 479              $filePath = $file->attribute( "filename" );
 480              $originalFilename = $file->attribute( "original_filename" );
 481              return $handler->handleFile( $this, $result,
 482                                           $filePath, $originalFilename, $mimeData,
 483                                           $location, $existingNode );
 484          }
 485  
 486          $object = false;
 487          $class = false;
 488          // Figure out class identifier from an existing node
 489          // if not we will have to detect it from the mimetype
 490          if ( is_object( $existingNode ) )
 491          {
 492              $object =& $existingNode->object();
 493              $class =& $object->contentClass();
 494              $classIdentifier = $class->attribute( 'identifier' );
 495          }
 496          else
 497          {
 498              $classIdentifier = $this->detectClassIdentifier( $mime );
 499          }
 500  
 501          if ( !$classIdentifier )
 502          {
 503              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 504                                                          'No matching class identifier found.' ) );
 505              return false;
 506          }
 507  
 508          if ( !is_object( $class ) )
 509              $class = eZContentClass::fetchByIdentifier( $classIdentifier );
 510  
 511          if ( !$class )
 512          {
 513              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 514                                                          'The class %class_identifier does not exist.', null,
 515                                                          array( '%class_identifier' => $classIdentifier ) ) );
 516              return false;
 517          }
 518  
 519  
 520          $parentNodes = false;
 521          $parentMainNode = false;
 522          // If do not have an existing node we need to figure
 523          // out the locations from $location and $classIdentifier
 524          if ( !is_object( $existingNode ) )
 525          {
 526              $locationOK = $this->detectLocations( $classIdentifier, $class, $location, $parentNodes, $parentMainNode );
 527              if ( $locationOK === false )
 528              {
 529                  $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 530                                                              'Was not able to figure out placement of object.' ) );
 531                  return false;
 532              }
 533              elseif ( $locationOK === null )
 534              {
 535                  $result['status'] = EZ_CONTENTUPLOAD_STATUS_PERMISSION_DENIED;
 536                  $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 537                                                              'Permission denied' ) );
 538                  return false;
 539              }
 540          }
 541  
 542          $uploadINI =& eZINI::instance( 'upload.ini' );
 543          $iniGroup = $classIdentifier . '_ClassSettings';
 544          if ( !$uploadINI->hasGroup( $iniGroup ) )
 545          {
 546              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 547                                                          'No configuration group in upload.ini for class identifier %class_identifier.', null,
 548                                                          array( '%class_identifier' => $classIdentifier ) ) );
 549              return false;
 550          }
 551  
 552          $fileAttribute = $uploadINI->variable( $iniGroup, 'FileAttribute' );
 553          $dataMap = $class->dataMap();
 554  
 555          if ( $classIdentifier == 'image' )
 556          {
 557              $classAttribute = $dataMap['image'];
 558              $maxSize = 1024 * 1024 * $classAttribute->attribute( 'data_int1' );
 559              if ( $maxSize != 0 && $file->attribute( 'filesize' ) > $maxSize )
 560              {
 561                  $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 562                                                              'The size of the uploaded file exceeds the limit set for this site: %1 bytes.', null, array( $maxSize ) ) );
 563                  return false;
 564              }
 565          }
 566  
 567  
 568          $fileAttribute = $this->findHTTPFileAttribute( $dataMap, $fileAttribute );
 569          if ( !$fileAttribute )
 570          {
 571              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 572                                                          'No matching file attribute found, cannot create content object without this.' ) );
 573              return false;
 574          }
 575  
 576          $nameAttribute = $uploadINI->variable( $iniGroup, 'NameAttribute' );
 577          if ( !$nameAttribute )
 578          {
 579              $nameAttribute = $this->findStringAttribute( $dataMap, $nameAttribute );
 580          }
 581          if ( !$nameAttribute )
 582          {
 583              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 584                                                          'No matching name attribute found, cannot create content object without this.' ) );
 585              return false;
 586          }
 587  
 588          $variables = array( 'original_filename' => $file->attribute( 'original_filename' ),
 589                              'mime_type' => $mime );
 590          $variables['original_filename_base'] = $mimeData['basename'];
 591          $variables['original_filename_suffix'] = $mimeData['suffix'];
 592  
 593          if ( !$nameString )
 594          {
 595              $namePattern = $uploadINI->variable( $iniGroup, 'NamePattern' );
 596              $nameString = $this->processNamePattern( $variables, $namePattern );
 597          }
 598  
 599          $db =& eZDB::instance();
 600          $db->begin();
 601  
 602          // If we have an existing node we need to create
 603          // a new version in it.
 604          // If we don't we have to make a new object
 605          if ( is_object( $existingNode ) )
 606          {
 607              if ( $existingNode->canEdit( ) != '1' )
 608              {
 609                  $result['status'] = EZ_CONTENTUPLOAD_STATUS_PERMISSION_DENIED;
 610                  $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 611                                                              'Permission denied' ) );
 612  
 613                  $db->commit();
 614                  return false;
 615              }
 616              $version = $object->createNewVersion( false, true );
 617              unset( $dataMap );
 618              $dataMap =& $version->dataMap();
 619              $publishVersion = $version->attribute( 'version' );
 620          }
 621          else
 622          {
 623              $object = $class->instantiate();
 624              unset( $dataMap );
 625              $dataMap =& $object->dataMap();
 626              $publishVersion = $object->attribute( 'current_version' );
 627          }
 628  
 629          unset( $dataMap );
 630          $dataMap =& $object->dataMap();
 631  
 632          $status = $dataMap[$fileAttribute]->insertHTTPFile( $object, $publishVersion, eZContentObject::defaultLanguage(),
 633                                                              $file, $mimeData,
 634                                                              $storeResult );
 635          if ( $status === null )
 636          {
 637              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 638                                                          'The attribute %class_identifier does not support HTTP file storage.', null,
 639                                                          array( '%class_identifier' => $classIdentifier ) ) );
 640              $db->commit();
 641              return false;
 642          }
 643          else if ( !$status )
 644          {
 645              $errors = array_merge( $errors, $storeResult['errors'] );
 646              $db->commit();
 647              return false;
 648          }
 649          if ( $storeResult['require_storage'] )
 650              $dataMap[$fileAttribute]->store();
 651  
 652          $status = $dataMap[$nameAttribute]->insertSimpleString( $object, $publishVersion, eZContentObject::defaultLanguage(),
 653                                                                  $nameString,
 654                                                                  $storeResult );
 655          if ( $status === null )
 656          {
 657              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 658                                                          'The attribute %class_identifier does not support simple string storage.', null,
 659                                                          array( '%class_identifier' => $classIdentifier ) ) );
 660              $db->commit();
 661              return false;
 662          }
 663          else if ( !$status )
 664          {
 665              $errors = array_merge( $errors, $storeResult['errors'] );
 666              $db->commit();
 667              return false;
 668          }
 669          if ( $storeResult['require_storage'] )
 670              $dataMap[$nameAttribute]->store();
 671  
 672          $tmpresult =  $this->publishObject( $result, $errors, $notices,
 673                                       $object, $publishVersion, $class, $parentNodes, $parentMainNode );
 674  
 675          $db->commit();
 676          return $tmpresult;
 677      }
 678  
 679      /*!
 680       \private
 681       Publishes the object to the selected locations.
 682  
 683       \return \c true if everything was OK, \c false if something failed.
 684      */
 685      function publishObject( &$result, &$errors, &$notices,
 686                              &$object, $publishVersion, &$class, $parentNodes, $parentMainNode )
 687      {
 688          if ( is_array( $parentNodes ) )
 689          {
 690              foreach ( $parentNodes as $key => $parentNode )
 691              {
 692                  $object->createNodeAssignment( $parentNode, $parentNode == $parentMainNode );
 693              }
 694          }
 695  
 696          $object->setName( $class->contentObjectName( $object ) );
 697          $object->store();
 698  
 699          include_once ( 'lib/ezutils/classes/ezoperationhandler.php' );
 700  //            $oldObjectName = $object->name();
 701  //             print( "version: " . $object->attribute( 'current_version' ) . "<br/>\n" );
 702          $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $object->attribute( 'id' ),
 703                                                                                       'version' => $publishVersion ) );
 704  
 705          $objectID = $object->attribute( 'id' );
 706          unset( $object );
 707          $object =& eZContentObject::fetch( $objectID );
 708          $result['contentobject'] =& $object;
 709          $result['contentobject_id'] = $object->attribute( 'id' );
 710          $result['contentobject_version'] = $publishVersion;
 711          $result['contentobject_main_node'] = false;
 712          $result['contentobject_main_node_id'] = false;
 713  
 714          $this->setResult( array( 'node_id' => false,
 715                                   'object_id' => $object->attribute( 'id' ),
 716                                   'object_version' => $publishVersion ) );
 717  
 718          switch ( $operationResult['status'] )
 719          {
 720              case EZ_MODULE_OPERATION_HALTED:
 721              {
 722                  if ( isset( $operationResult['redirect_url'] ) )
 723                  {
 724                      $result['redirect_url'] = $operationResult['redirect_url'];
 725                      $notices[] = array( 'description' => ezi18n( 'kernel/content/upload',
 726                                                                   'Publishing of content object was halted.' ) );
 727                      return true;
 728                  }
 729                  else if ( isset( $operationResult['result'] ) )
 730                  {
 731                      $result['result'] = $operationResult['result'];
 732                      return true;
 733                  }
 734              } break;
 735  
 736              case EZ_MODULE_OPERATION_CANCELED:
 737              {
 738                  $result['result'] = ezi18n( 'kernel/content/upload',
 739                                              'Publish process was cancelled.' );
 740                  return true;
 741              } break;
 742  
 743              case EZ_MODULE_OPERATION_CONTINUE:
 744              {
 745              }
 746          }
 747  
 748          $mainNode = $object->mainNode();
 749          $result['contentobject_main_node'] = $mainNode;
 750          $result['contentobject_main_node_id'] = $mainNode->attribute( 'node_id' );
 751          $this->setResult( array( 'node_id' => $mainNode->attribute( 'node_id' ),
 752                                   'object_id' => $object->attribute( 'id' ),
 753                                   'object_version' => $publishVersion ) );
 754  //         $newObjectName = $object->name();
 755          return true;
 756      }
 757  
 758      /*!
 759        Finds the file attribute for object \a $contentObject and tries to extract
 760        file information using eZDataType::storedFileInformation().
 761        \return The information structure or \c false if it fails somehow.
 762      */
 763      function objectFileInfo( &$contentObject )
 764      {
 765          $uploadINI =& eZINI::instance( 'upload.ini' );
 766  
 767          $class =& $contentObject->contentClass();
 768          $classIdentifier = $class->attribute( 'identifier' );
 769          $classDataMap =& $class->dataMap();
 770          $attributeIdentifier = false;
 771          if ( $uploadINI->hasGroup( $classIdentifier . '_ClassSettings' ) )
 772          {
 773              $attributeIdentifier = $uploadINI->variable( $classIdentifier . '_ClassSettings', 'FileAttribute' );
 774          }
 775  
 776          $attributeIdentifier = $this->findRegularFileAttribute( $classDataMap, $attributeIdentifier );
 777          if ( !$attributeIdentifier )
 778          {
 779              // No file information for this object
 780              return false;
 781          }
 782  
 783          $dataMap =& $contentObject->dataMap();
 784          $fileAttribute =& $dataMap[$attributeIdentifier];
 785  
 786          if ( $fileAttribute->hasStoredFileInformation( $contentObject, false, false ) )
 787          {
 788              $info = $fileAttribute->storedFileInformation( $contentObject, false, false );
 789              return $info;
 790          }
 791          return false;
 792      }
 793  
 794      /*!
 795       \private
 796       Fetches the HTTP-File into \a $file and fills in MIME-Type information into \a $mimeData.
 797       \return \c false if something went wrong.
 798      */
 799      function fetchHTTPFile( $httpFileIdentifier, &$errors, &$file, &$mimeData )
 800      {
 801          include_once ( 'lib/ezutils/classes/ezhttpfile.php' );
 802          if ( !eZHTTPFile::canFetch( $httpFileIdentifier ) )
 803          {
 804              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 805                                                          'A file is required for upload, no file were found.' ) );
 806              return false;
 807          }
 808  
 809          $file = eZHTTPFile::fetch( $httpFileIdentifier );
 810          if ( get_class( $file ) != "ezhttpfile" )
 811          {
 812              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
 813                                                          'Expected a eZHTTPFile object but got nothing.' ) );
 814              return false;
 815          }
 816  
 817          include_once ( 'lib/ezutils/classes/ezmimetype.php' );
 818          $mimeData = eZMimeType::findByFileContents( $file->attribute( "original_filename" ) );
 819  
 820          return false;
 821      }
 822  
 823      /*!
 824       \private
 825       \static
 826       Checks if the attribute with the identifier \a $fileAttribute in \a $dataMap
 827       supports HTTP file uploading. If not it will go trough all attributes and
 828       find the first that has this support.
 829  
 830       \return The identifier of the matched attribute or \c false if none were found.
 831       \param $dataMap Associative array with class attributes, the key is attribute identifier
 832       \param $fileAttribute The identifier of the attribute that is expected to have the file datatype.
 833      */
 834      function findHTTPFileAttribute( &$dataMap, $fileAttribute )
 835      {
 836          $fileDatatype = false;
 837          if ( isset( $dataMap[$fileAttribute] ) )
 838              $fileDatatype = $dataMap[$fileAttribute]->dataType();
 839          if ( !$fileDatatype or
 840               !$fileDatatype->isHTTPFileInsertionSupported() )
 841          {
 842              $fileAttribute = false;
 843              foreach ( $dataMap as $identifier => $attribute )
 844              {
 845                  $datatype = $attribute->dataType();
 846                  if ( $datatype->isHTTPFileInsertionSupported() )
 847                  {
 848                      $fileAttribute = $identifier;
 849                      break;
 850                  }
 851              }
 852          }
 853          return $fileAttribute;
 854      }
 855  
 856      /*!
 857       \private
 858       \static
 859       Checks if the attribute with the identifier \a $fileAttribute in \a $dataMap
 860       supports file uploading. If not it will go trough all attributes and
 861       find the first that has this support.
 862  
 863       \return The identifier of the matched attribute or \c false if none were found.
 864       \param $dataMap Associative array with class attributes, the key is attribute identifier
 865       \param $fileAttribute The identifier of the attribute that is expected to have the file datatype.
 866      */
 867      function findRegularFileAttribute( &$dataMap, $fileAttribute )
 868      {
 869          $fileDatatype = false;
 870          if ( isset( $dataMap[$fileAttribute] ) )
 871              $fileDatatype = $dataMap[$fileAttribute]->dataType();
 872          if ( !$fileDatatype or
 873               !$fileDatatype->isRegularFileInsertionSupported() )
 874          {
 875              $fileAttribute = false;
 876              foreach ( $dataMap as $identifier => $attribute )
 877              {
 878                  $datatype = $attribute->dataType();
 879                  if ( $datatype->isRegularFileInsertionSupported() )
 880                  {
 881                      $fileAttribute = $identifier;
 882                      break;
 883                  }
 884              }
 885          }
 886          return $fileAttribute;
 887      }
 888  
 889      /*!
 890       \private
 891       \static
 892       Checks if the attribute with the identifier \a $nameAttribute in \a $dataMap
 893       supports string insertion. If not it will go trough all attributes and
 894       find the first that has this support.
 895  
 896       \return The identifier of the matched attribute or \c false if none were found.
 897       \param $dataMap Associative array with class attributes, the key is attribute identifier
 898       \param $nameAttribute The identifier of the attribute that is expected to have the string datatype.
 899      */
 900      function findStringAttribute( &$dataMap, $nameAttribute )
 901      {
 902          $nameDatatype = false;
 903          if ( isset( $dataMap[$nameAttribute] ) )
 904              $nameDatatype = $dataMap[$nameAttribute]->dataType();
 905          if ( !$nameDatatype or
 906               !$nameDatatype->isSimpleStringInsertionSupported() )
 907          {
 908              $nameAttribute = false;
 909              foreach ( $dataMap as $identifier => $attribute )
 910              {
 911                  $datatype = $attribute->dataType();
 912                  if ( $datatype->isSimpleStringInsertionSupported() )
 913                  {
 914                      $nameAttribute = $identifier;
 915                      break;
 916                  }
 917              }
 918          }
 919          return $nameAttribute;
 920      }
 921  
 922      /*!
 923       \private
 924       \static
 925       Figures out the class which should be used for file with
 926       MIME-Type \a $mime and returns the class identifier.
 927       \param $mime A string defining the MIME-Type, will be used to determine class identifier.
 928      */
 929      function detectClassIdentifier( $mime )
 930      {
 931          $uploadINI =& eZINI::instance( 'upload.ini' );
 932  
 933          $mimeClassMap = $uploadINI->variable( 'CreateSettings', 'MimeClassMap' );
 934          $defaultClass = $uploadINI->variable( 'CreateSettings', 'DefaultClass' );
 935  
 936          list( $group, $type ) = explode( '/', $mime );
 937          if ( isset( $mimeClassMap[$mime] ) )
 938          {
 939              $classIdentifier = $mimeClassMap[$mime];
 940          }
 941          else if ( isset( $mimeClassMap[$group] ) )
 942          {
 943              $classIdentifier = $mimeClassMap[$group];
 944          }
 945          else
 946          {
 947              $classIdentifier = $defaultClass;
 948          }
 949          return $classIdentifier;
 950      }
 951  
 952      /*!
 953       \private
 954       Figures out the location(s) in which the class with
 955       the identifier \a $classIdentifier should be placed.
 956       The returned locations will either be a node ID or an identifier
 957       for a node (e.g. content).
 958  
 959       \return \c true if a location was found or \c false if no location could be determined
 960       \param $classIdentifier Identifier of class, is used to determine location
 961       \param $location The wanted location, either use \c 'auto' for automatic placement
 962                        or number to determine to parent node ID.
 963       \param[out] $parentNodes Will contain an array with node IDs or identifiers if a location could be detected.
 964       \param[out] $parentMainNode Will contain the ID of the main node if a location could be detected.
 965       */
 966      function detectLocations( $classIdentifier, $class, $location,
 967                                &$parentNodes, &$parentMainNode )
 968      {
 969          $isAccessChecked = false;
 970          $parentMainNode = false;
 971          if ( $this->hasAttribute( 'parent_nodes' ) &&
 972               $this->attribute( 'parent_nodes' ) )
 973          {
 974              $parentNodes = $this->attribute( 'parent_nodes' );
 975              foreach( $parentNodes as $key => $parentNode )
 976              {
 977                  $parentNodes[$key] = eZContentUpload::nodeAliasID( $parentNode );
 978                  if ( !eZContentUpload::checkAccess( $parentNodes[$key], $class ) )
 979                  {
 980                      $parentNodes = false;
 981                      return null;
 982                  }
 983              }
 984          }
 985          else
 986          {
 987              if ( $location == 'auto' or !is_numeric( $location ) )
 988              {
 989                  $contentINI =& eZINI::instance( 'content.ini' );
 990  
 991                  $classPlacementMap = $contentINI->variable( 'RelationAssignmentSettings', 'ClassSpecificAssignment' );
 992                  $defaultPlacement = $contentINI->variable( 'RelationAssignmentSettings', 'DefaultAssignment' );
 993  
 994                  // Find location that matches the class and where user is allowed to create objects
 995                  foreach ( $classPlacementMap as $classData )
 996                  {
 997                      $classElements = explode( ';', $classData );
 998                      $classList = explode( ',', $classElements[0] );
 999  
1000                      if ( in_array( $classIdentifier, $classList ) )
1001                      {
1002                          $parentNodes = explode( ',', $classElements[1] );
1003                          if ( count( $parentNodes ) == 0 )
1004                              continue;
1005  
1006                          if ( isset( $classElements[2] ) )
1007                              $parentMainNode = eZContentUpload::nodeAliasID( $classElements[2] );
1008  
1009                          // check access rights and convert to IDs
1010                          foreach ( $parentNodes as $key => $parentNode )
1011                          {
1012                              $parentNodeID = eZContentUpload::nodeAliasID( $parentNode );
1013                              if ( !$parentNodeID )
1014                              {
1015                                  $parentNodes = false;
1016                                  break;
1017                              }
1018  
1019                              $parentNodes[$key] = $parentNodeID;
1020  
1021                              if ( !eZContentUpload::checkAccess( $parentNodeID, $class ) )
1022                              {
1023                                  eZDebug::writeNotice( "Upload assignment setting '$classData' skipped - no permissions", 'eZContentUpload::detectLocations' );
1024                                  $parentNodes = false;
1025                                  break;
1026                              }
1027                          }
1028  
1029                          if ( $parentNodes )
1030                          {
1031                              eZDebug::writeNotice( "Matched assignment for upload :'$classData'", 'eZContentUpload::detectLocations' );
1032                              break;
1033                          }
1034                      }
1035                  }
1036  
1037                  if ( !$parentNodes && isset( $defaultPlacement ) && $defaultPlacement )
1038                  {
1039                      $defaultNodeID = eZContentUpload::nodeAliasID( $defaultPlacement );
1040                      if ( $defaultNodeID )
1041                      {
1042                          if ( eZContentUpload::checkAccess( $defaultNodeID, $class ) )
1043                          {
1044                              $parentNodes = array( $defaultNodeID );
1045                          }
1046                          else
1047                          {
1048                              eZDebug::writeNotice( "No create permission for default upload location: node #$defaultNodeID", 'eZContentUpload::detectLocations' );
1049                              return null;
1050                          }
1051  
1052                      }
1053                  }
1054              }
1055              else
1056              {
1057                  $locationID = eZContentUpload::nodeAliasID( $location );
1058                  if ( $locationID )
1059                  {
1060                      if ( eZContentUpload::checkAccess( $locationID, $class ) )
1061                      {
1062                          $parentNodes = array( $locationID );
1063                      }
1064                      else
1065                      {
1066                          eZDebug::writeNotice( "No create permission for upload location: node #$locationID", 'eZContentUpload::detectLocations' );
1067                          return null;
1068                      }
1069                  }
1070              }
1071          }
1072  
1073          if ( !$parentNodes || count( $parentNodes ) == 0 )
1074          {
1075              return false;
1076          }
1077  
1078          if ( !$parentMainNode )
1079          {
1080              $parentMainNode = $parentNodes[0];
1081          }
1082  
1083          return true;
1084      }
1085  
1086      /*!
1087       \private
1088       \static
1089      */
1090  
1091      function checkAccess( $nodeID, $class )
1092      {
1093          $parentNodeObj = eZContentObjectTreeNode::fetch( $nodeID );
1094          $parentObject =  $parentNodeObj->attribute( 'object' );
1095  
1096          if ( $parentNodeObj->checkAccess( 'create',
1097                                            $class->attribute( 'id' ),
1098                                            $parentObject->attribute( 'contentclass_id' ) ) != '1' )
1099          {
1100              return false;
1101          }
1102          return true;
1103      }
1104  
1105      /*!
1106       \private
1107       \static
1108       Parses the name pattern \a $namePattern and replaces any
1109       variables found in \a $variables with the variable value.
1110  
1111       \return The resulting string with all \e tags replaced.
1112       \param $variables An associative array where the key is variable name and element the variable value.
1113       \param $namePattern A string containing of plain text or \e tags, each tag is enclosed in < and > and
1114                           defines name of the variable to lookup.
1115  
1116       \code
1117       $vars = array( 'name' => 'A name',
1118                      'filename' => 'myfile.txt' );
1119       $name = $this->parseNamePattern( $vars, '<name> - <filename>' );
1120       print( $name ); // Will output 'A name - myfile.txt'
1121       \endcode
1122      */
1123      function processNamePattern( $variables, $namePattern )
1124      {
1125          $tags = array();
1126          $pos = 0;
1127          $lastPos = false;
1128          $len = strlen( $namePattern );
1129          while ( $pos < $len )
1130          {
1131              $markerPos = strpos( $namePattern, '<', $pos );
1132              if ( $markerPos !== false )
1133              {
1134                  $markerEndPos = strpos( $namePattern, '>', $markerPos + 1 );
1135                  if ( $markerEndPos === false )
1136                  {
1137                      $markerEndPos = $len;
1138                      $pos = $len;
1139                  }
1140                  else
1141                  {
1142                      $pos = $markerEndPos + 1;
1143                  }
1144                  $tag = substr( $namePattern, $markerPos + 1, $markerEndPos - $markerPos - 1 );
1145                  $tags[] = array( 'name' => $tag );
1146              }
1147              if ( $lastPos !== false and
1148                   $lastPos < $pos )
1149              {
1150                  $tags[] = substr( $namePattern, $lastPos, $pos - $lastPos );
1151              }
1152              $lastPos = $pos;
1153          }
1154          $nameString = '';
1155          foreach ( $tags as $tag )
1156          {
1157              if ( is_string( $tag ) )
1158              {
1159                  $nameString .= $tag;
1160              }
1161              else
1162              {
1163                  if ( isset( $variables[$tag['name']] ) )
1164                      $nameString .= $variables[$tag['name']];
1165              }
1166          }
1167          return $nameString;
1168      }
1169  
1170      /*!
1171       \static
1172       \return the node ID for the node alias \a $nodeName or \c false if no ID could be found.
1173      */
1174      function nodeAliasID( $nodeName )
1175      {
1176          if ( is_numeric( $nodeName ) )
1177          {
1178              $node = eZContentObjectTreeNode::fetch( $nodeName );
1179              if ( is_object( $node ) )
1180              {
1181                  $result['status'] = EZ_CONTENTUPLOAD_STATUS_PERMISSION_DENIED;
1182                  $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
1183                                                              'Permission denied' ) );
1184  
1185                  return $nodeName;
1186              }
1187          }
1188  
1189          $uploadINI =& eZINI::instance( 'upload.ini' );
1190          $aliasList = $uploadINI->variable( 'UploadSettings', 'AliasList' );
1191          if ( isset( $aliasList[$nodeName] ) )
1192              return $aliasList[$nodeName];
1193          $contentINI =& eZINI::instance( 'content.ini' );
1194          if ( $nodeName == 'content' or $nodeName == 'root' )
1195              return $contentINI->variable( 'NodeSettings', 'RootNode' );
1196          else if ( $nodeName == 'users' )
1197              return $contentINI->variable( 'NodeSettings', 'UserRootNode' );
1198          else if ( $nodeName == 'media' )
1199              return $contentINI->variable( 'NodeSettings', 'MediaRootNode' );
1200          else if ( $nodeName == 'setup' )
1201              return $contentINI->variable( 'NodeSettings', 'SetupRootNode' );
1202  
1203          // Check for node path element
1204          $pathPos = strpos( $nodeName, '/' );
1205          if ( $pathPos !== false )
1206          {
1207              $node = eZContentObjectTreeNode::fetchByURLPath( $nodeName );
1208              if ( is_object( $node ) )
1209              {
1210                  return $node->attribute( 'node_id' );
1211              }
1212          }
1213          return false;
1214      }
1215  
1216      /*!
1217       Sets the result array to \a $result and stores the session variable.
1218      */
1219      function setResult( $result )
1220      {
1221          $this->Parameters['result'] = $result;
1222          $http =& eZHTTPTool::instance();
1223          $http->setSessionVariable( 'ContentUploadParameters', $this->Parameters );
1224      }
1225  
1226      /*!
1227       \static
1228       \return the result of the previous upload operation or \c false if no result was found.
1229               It uses the action name \a $actionName to determine which result to look for.
1230       \param $cleanup If \c true it the persisten data is cleaned up by calling cleanup().
1231      */
1232      function result( $actionName, $cleanup = true )
1233      {
1234          if ( isset( $this ) and
1235               get_class( $this) == 'ezcontentupload' )
1236              $upload =& $this;
1237          else
1238              $upload = new eZContentUpload();
1239  
1240          $isNodeSelection = $upload->attribute( 'return_type' ) == 'NodeID';
1241          $resultData = $upload->attribute( 'result' );
1242          $result = false;
1243          if ( $isNodeSelection )
1244          {
1245              $result = $resultData['node_id'];
1246          }
1247          else
1248          {
1249              $result = $resultData['object_id'];
1250          }
1251          if ( $cleanup )
1252              eZContentUpload::cleanup( $actionName );
1253          return $result;
1254      }
1255  
1256      /*!
1257       \static
1258       Cleans up the persistent data and result for action named \a $actionName
1259      */
1260      function cleanup( $actionName )
1261      {
1262          $http =& eZHTTPTool::instance();
1263          $http->removeSessionVariable( 'ContentUploadParameters' );
1264      }
1265  
1266      /*!
1267       \static
1268       Similar to cleanup() but removes persistent data from all actions.
1269      */
1270      function cleanupAll()
1271      {
1272          $http =& eZHTTPTool::instance();
1273          $http->removeSessionVariable( 'ContentUploadParameters' );
1274      }
1275  
1276      /*!
1277       Finds the correct upload handler for the file specified in \a $mimeInfo.
1278       If no handler is found it will return the default attribute based handler eZContentUpload,
1279       this means that the file is passed to one suitable attribute and handled from there.
1280       \return An object with the interface eZContentUploadHandler or \c false if an error occured.
1281               Will return \c true if there is no handler configured for this type.
1282      */
1283      function &findHandler( &$result, $mimeInfo )
1284      {
1285          $errors =& $result['errors'];
1286          $notices =& $result['notices'];
1287  
1288          // Check for specific mime handler plugin
1289          $uploadINI =& eZINI::instance( 'upload.ini' );
1290          $uploadSettings = $uploadINI->variable( 'CreateSettings', 'MimeUploadHandlerMap' );
1291  
1292          $mime = $mimeInfo['name'];
1293          $elements = explode( '/', $mime );
1294          $mimeGroup = $elements[0];
1295  
1296          $handlerName = false;
1297          // Check first for MIME-Type group, this allows a handler to work
1298          // with an entire group, e.g. image
1299          if ( isset( $uploadSettings[$mimeGroup] ) )
1300          {
1301              $handlerName = $uploadSettings[$mimeGroup];
1302          }
1303          else if ( isset( $uploadSettings[$mime] ) )
1304          {
1305              $handlerName = $uploadSettings[$mime];
1306          }
1307  
1308          if ( $handlerName !== false )
1309          {
1310              include_once ( 'lib/ezutils/classes/ezextension.php' );
1311              $baseDirectory = eZExtension::baseDirectory();
1312              $extensionDirectories = eZExtension::activeExtensions();
1313  
1314              // Check all extension directories for an upload handler for this mimetype
1315              foreach ( $extensionDirectories as $extensionDirectory )
1316              {
1317                  $handlerPath = $baseDirectory . '/' . $extensionDirectory . '/uploadhandlers/' . $handlerName . ".php";
1318                  if ( !file_exists( $handlerPath ) )
1319                      continue;
1320  
1321                  include_once( $handlerPath );
1322                  $handlerClass = $handlerName;
1323                  $handler = new $handlerClass();
1324                  if ( !is_subclass_of( $handler, 'ezcontentuploadhandler' ) )
1325                  {
1326                      eZDebug::writeError( "Content upload handler '$handlerName' is not inherited from eZContentUploadHandler. All upload handlers must do this.", 'eZContentUpload::findHandler' );
1327                      $retValue = false;
1328                      return $retValue;
1329                  }
1330                  return $handler;
1331              }
1332  
1333              $errors[] = array( 'description' => ezi18n( 'kernel/content/upload',
1334                                                          "Could not find content upload handler '%handler_name'",
1335                                                          null, array( '%handler_name' => $handlerName ) ) );
1336  //             eZDebug::writeError( "Could not find content upload handler '$handlerName'", 'eZContentUpload::findHandler' );
1337              $retValue = false;
1338              return $retValue;
1339          }
1340          $retValue = true;
1341          return $retValue;
1342      }
1343  
1344      /// \privatesection
1345      /// The upload parameters.
1346      var $Parameters = false;
1347  }
1348  
1349  ?>


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