|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZContentUpload class 00004 // 00005 // Created on: <28-Apr-2003 11:04:47 sp> 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 /*! \file ezcontentupload.php 00032 */ 00033 00034 /*! 00035 \class eZContentUpload ezcontentupload.php 00036 \brief Handles simple creation of content objects by uploading files 00037 00038 This class makes it easy to use the start a new file upload 00039 and let it be created as a content object. 00040 00041 Using it is simply to call the \link upload \endlink function with some parameters. 00042 00043 \code 00044 eZContentUpload::upload( array( 'action_name' => 'MyActionName' ), $module ); 00045 \endcode 00046 00047 It requires the module objects as the second parameter to redirect and the first 00048 define how the upload page should behave. Normally you just want to set \c action_name 00049 and define the behaviour of that action in settings/upload.ini. 00050 00051 Fetching the result afterwards is done by calling the result() method, it will return 00052 the resulting node ID or object ID depending on the configuration of the upload action. 00053 00054 \code 00055 eZContentUpload::result( 'MyActionName' ); 00056 \endcode 00057 00058 It is also possible to use this class to upload a given file (HTTP or regular) as an object. 00059 The correct class and location can be determined automatically. 00060 00061 Simply create an instance and then call handleUpload() or handleLocalFile(). 00062 00063 \code 00064 $upload = new eZContentUpload(); 00065 $upload->handleUpload( $result, 'UploadFile', 'auto', false ); 00066 00067 $upload->handleLocalFile( $result, 'a_yellow_flower.jpg', 'auto' ); 00068 \endcode 00069 */ 00070 00071 //include_once( 'lib/ezutils/classes/ezhttptool.php' ); 00072 //include_once( 'lib/ezutils/classes/ezini.php' ); 00073 //include_once( 'kernel/classes/ezcontentobject.php' ); 00074 00075 class eZContentUpload 00076 { 00077 00078 const STATUS_PERMISSION_DENIED = 1; 00079 00080 /*! 00081 Initializes the object with the session data if they are found. 00082 If \a $params is supplied it used instead. 00083 */ 00084 function eZContentUpload( $params = false ) 00085 { 00086 $http = eZHTTPTool::instance(); 00087 if ( !$params && $http->hasSessionVariable( 'ContentUploadParameters' ) ) 00088 { 00089 $this->Parameters =& $http->sessionVariable( 'ContentUploadParameters' ); 00090 } 00091 else 00092 { 00093 if ( $params === false ) 00094 $params = array(); 00095 $this->Parameters = $params; 00096 } 00097 } 00098 00099 /*! 00100 \return an array with attribute names. 00101 */ 00102 function attributes() 00103 { 00104 return array_keys( $this->Parameters ); 00105 } 00106 00107 /*! 00108 \return true if the attribute name \a $attributeName is among the upload parameters. 00109 */ 00110 function hasAttribute( $attributeName ) 00111 { 00112 return array_key_exists( $attributeName, $this->Parameters ); 00113 } 00114 00115 /*! 00116 \return the attribute value of the attribute named \a $attributeName or \c null if no such attribute. 00117 */ 00118 function attribute( $attributeName ) 00119 { 00120 if ( isset( $this->Parameters[$attributeName] ) ) 00121 { 00122 return $this->Parameters[$attributeName]; 00123 } 00124 00125 eZDebug::writeError( "Attribute '$attributeName' does not exist", 'eZContentUpload::attribute' ); 00126 return null; 00127 } 00128 00129 /*! 00130 \static 00131 Sets some session data taken from \a $parameters and start the upload module by redirecting to it using \a $module. 00132 Most data will be automatically derived from the \c action_name value taken from settings/upload.ini, other 00133 values will override default values. 00134 */ 00135 static function upload( $parameters = array(), $module ) 00136 { 00137 $ini = eZINI::instance( 'upload.ini' ); 00138 00139 if ( !isset( $parameters['action_name'] ) ) 00140 $parameters['action_name'] = $ini->variable( 'UploadSettings', 'DefaultActionName' ); 00141 00142 if ( !isset( $parameters['result_action_name'] ) ) 00143 $parameters['result_action_name'] = $parameters['action_name']; 00144 00145 if ( !isset( $parameters['navigation_part_identifier'] ) ) 00146 $parameters['navigation_part_identifier'] = false; 00147 if ( !$parameters['navigation_part_identifier'] and 00148 $ini->hasVariable( 'UploadSettings', 'NavigationPartIdentifier' ) ) 00149 $parameters['navigation_part_identifier'] = $ini->variable( 'UploadSettings', 'NavigationPartIdentifier' ); 00150 00151 if ( !isset( $parameters['type'] ) ) 00152 $parameters['type'] = $parameters['action_name']; 00153 00154 if ( !isset( $parameters['return_type'] ) ) 00155 { 00156 if ( $ini->hasVariable( $parameters['type'], 'ReturnType' ) ) 00157 $parameters['return_type'] = $ini->variable( $parameters['type'], 'ReturnType' ); 00158 else 00159 $parameters['return_type'] = $ini->variable( 'UploadSettings', 'DefaultReturnType' ); 00160 } 00161 00162 if ( !isset( $parameters['upload_custom_action'] ) ) 00163 $parameters['upload_custom_action'] = false; 00164 00165 if ( !isset( $parameters['custom_action_data'] ) ) 00166 $parameters['custom_action_data'] = false; 00167 00168 if ( !isset( $parameters['description_template'] ) ) 00169 $parameters['description_template'] = false; 00170 00171 if ( !isset( $parameters['parent_nodes'] ) ) 00172 { 00173 $parameters['parent_nodes'] = false; 00174 if ( $ini->hasVariable( $parameters['type'], 'ParentNodes' ) ) 00175 { 00176 $parameters['parent_nodes'] = $ini->variable( $parameters['type'], 'ParentNodes' ); 00177 } 00178 } 00179 00180 if ( !isset( $parameters['persistent_data'] ) ) 00181 $parameters['persistent_data'] = false; 00182 00183 if ( isset( $parameters['parent_nodes'] ) and 00184 is_array( $parameters['parent_nodes'] ) ) 00185 { 00186 foreach ( $parameters['parent_nodes'] as $key => $parentNode ) 00187 { 00188 if ( !is_numeric( $parentNode ) ) 00189 { 00190 $parameters['parent_nodes'][$key] = eZContentUpload::nodeAliasID( $parentNode ); 00191 } 00192 } 00193 } 00194 00195 if ( !isset( $parameters['result_uri'] ) ) 00196 $parameters['result_uri'] = false; 00197 00198 if ( !isset( $parameters['cancel_uri'] ) ) 00199 $parameters['cancel_uri'] = false; 00200 00201 if ( !isset( $parameters['result_module'] ) ) 00202 $parameters['result_module'] = false; 00203 00204 $parameters['result'] = false; 00205 00206 $http = eZHTTPTool::instance(); 00207 $http->setSessionVariable( 'ContentUploadParameters', $parameters ); 00208 00209 if ( is_null( $module ) ) 00210 { 00211 return "/content/upload/"; 00212 } 00213 else 00214 { 00215 $module->redirectTo( "/content/upload/" ); 00216 return "/content/upload/"; 00217 } 00218 } 00219 00220 /*! 00221 Fetches the local file, figures out its MIME-type and creates the proper content object out of it. 00222 00223 \param $filePath Path to file which should be stored. 00224 \param $result Result data, will be filled with information which the client can examine, contains: 00225 - errors - An array with errors, each element is an array with \c 'description' containing the text 00226 \param $location The node ID which the new object will be placed or the string \c 'auto' for automatic placement of type. 00227 \param $existingNode Pass a contentobjecttreenode object to let the uploading be done to an existing object, 00228 if not it will create one from scratch. 00229 00230 \return \c false if something failed or \c true if succesful. 00231 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00232 the calls within a db transaction; thus within db->begin and db->commit. 00233 */ 00234 function handleLocalFile( &$result, $filePath, $location, $existingNode, $nameString = '' ) 00235 { 00236 $result = array( 'errors' => array(), 00237 'notices' => array(), 00238 'result' => false, 00239 'redirect_url' => false, 00240 'status' => false ); 00241 00242 if ( !file_exists( $filePath ) ) 00243 { 00244 $result['errors'][] = 00245 array( 'description' => ezi18n( 'kernel/content/upload', 00246 'The file %filename does not exist, cannot insert file.', null, 00247 array( '%filename' => $filePath ) ) ); 00248 return false; 00249 } 00250 //include_once( 'lib/ezutils/classes/ezmimetype.php' ); 00251 $mimeData = eZMimeType::findByFileContents( $filePath ); 00252 $mime = $mimeData['name']; 00253 00254 $handler = $this->findHandler( $result, $mimeData ); 00255 if ( $handler === false ) 00256 { 00257 $result['errors'][] = 00258 array( 'description' => ezi18n( 'kernel/content/upload', 00259 'There was an error trying to instantiate content upload handler.' ) ); 00260 return false; 00261 } 00262 00263 // If this is an object we have a special handler for the file. 00264 // The handler will be responsible for the rest of the execution. 00265 if ( is_object( $handler ) ) 00266 { 00267 $originalFilename = $filePath; 00268 return $handler->handleFile( $this, $result, 00269 $filePath, $originalFilename, $mimeData, 00270 $location, $existingNode ); 00271 } 00272 00273 $object = false; 00274 $class = false; 00275 // Figure out class identifier from an existing node 00276 // if not we will have to detect it from the mimetype 00277 if ( is_object( $existingNode ) ) 00278 { 00279 $object = $existingNode->object(); 00280 $class = $object->contentClass(); 00281 $classIdentifier = $class->attribute( 'identifier' ); 00282 } 00283 else 00284 { 00285 $classIdentifier = $this->detectClassIdentifier( $mime ); 00286 } 00287 00288 if ( !$classIdentifier ) 00289 { 00290 $result['errors'][] = 00291 array( 'description' => ezi18n( 'kernel/content/upload', 00292 'No matching class identifier found.' ) ); 00293 return false; 00294 } 00295 00296 if ( !is_object( $class ) ) 00297 $class = eZContentClass::fetchByIdentifier( $classIdentifier ); 00298 00299 if ( !$class ) 00300 { 00301 $result['errors'][] = 00302 array( 'description' => ezi18n( 'kernel/content/upload', 00303 'The class %class_identifier does not exist.', null, 00304 array( '%class_identifier' => $classIdentifier ) ) ); 00305 return false; 00306 } 00307 00308 $parentNodes = false; 00309 $parentMainNode = false; 00310 // If do not have an existing node we need to figure 00311 // out the locations from $location and $classIdentifier 00312 if ( !is_object( $existingNode ) ) 00313 { 00314 $locationOK = $this->detectLocations( $classIdentifier, $class, $location, $parentNodes, $parentMainNode ); 00315 if ( $locationOK === false ) 00316 { 00317 $result['errors'][] = 00318 array( 'description' => ezi18n( 'kernel/content/upload', 00319 'Was not able to figure out placement of object.' ) ); 00320 return false; 00321 } 00322 elseif ( $locationOK === null ) 00323 { 00324 $result['status'] = eZContentUpload::STATUS_PERMISSION_DENIED; 00325 $result['errors'][] = 00326 array( 'description' => ezi18n( 'kernel/content/upload', 00327 'Permission denied' ) ); 00328 return false; 00329 } 00330 } 00331 00332 $uploadINI = eZINI::instance( 'upload.ini' ); 00333 $iniGroup = $classIdentifier . '_ClassSettings'; 00334 if ( !$uploadINI->hasGroup( $iniGroup ) ) 00335 { 00336 $result['errors'][] = 00337 array( 'description' => ezi18n( 'kernel/content/upload', 00338 'No configuration group in upload.ini for class identifier %class_identifier.', null, 00339 array( '%class_identifier' => $classIdentifier ) ) ); 00340 return false; 00341 } 00342 00343 $fileAttribute = $uploadINI->variable( $iniGroup, 'FileAttribute' ); 00344 $dataMap = $class->dataMap(); 00345 00346 $fileAttribute = $this->findRegularFileAttribute( $dataMap, $fileAttribute ); 00347 if ( !$fileAttribute ) 00348 { 00349 $result['errors'][] = 00350 array( 'description' => ezi18n( 'kernel/content/upload', 00351 'No matching file attribute found, cannot create content object without this.' ) ); 00352 return false; 00353 } 00354 00355 $nameAttribute = $uploadINI->variable( $iniGroup, 'NameAttribute' ); 00356 if ( !$nameAttribute ) 00357 { 00358 $nameAttribute = $this->findStringAttribute( $dataMap, $nameAttribute ); 00359 } 00360 if ( !$nameAttribute ) 00361 { 00362 $result['errors'][] = 00363 array( 'description' => ezi18n( 'kernel/content/upload', 00364 'No matching name attribute found, cannot create content object without this.' ) ); 00365 return false; 00366 } 00367 00368 $variables = array( 'original_filename' => $mimeData['filename'], 00369 'mime_type' => $mime ); 00370 $variables['original_filename_base'] = $mimeData['basename']; 00371 $variables['original_filename_suffix'] = $mimeData['suffix']; 00372 00373 if ( !$nameString ) 00374 { 00375 $namePattern = $uploadINI->variable( $iniGroup, 'NamePattern' ); 00376 $nameString = $this->processNamePattern( $variables, $namePattern ); 00377 } 00378 // If we have an existing node we need to create 00379 // a new version in it. 00380 // If we don't we have to make a new object 00381 if ( is_object( $existingNode ) ) 00382 { 00383 if ( $existingNode->canEdit( ) != '1' ) 00384 { 00385 $result['status'] = eZContentUpload::STATUS_PERMISSION_DENIED; 00386 $result['errors'][] = 00387 array( 'description' => ezi18n( 'kernel/content/upload', 00388 'Permission denied' ) ); 00389 return false; 00390 } 00391 $version = $object->createNewVersion( false, true ); 00392 unset( $dataMap ); 00393 $dataMap = $version->dataMap(); 00394 $publishVersion = $version->attribute( 'version' ); 00395 } 00396 else 00397 { 00398 $object = $class->instantiate(); 00399 unset( $dataMap ); 00400 $dataMap = $object->dataMap(); 00401 $publishVersion = $object->attribute( 'current_version' ); 00402 } 00403 00404 $status = $dataMap[$fileAttribute]->insertRegularFile( $object, $publishVersion, eZContentObject::defaultLanguage(), 00405 $filePath, 00406 $storeResult ); 00407 if ( $status === null ) 00408 { 00409 $result['errors'][] = 00410 array( 'description' => ezi18n( 'kernel/content/upload', 00411 'The attribute %class_identifier does not support regular file storage.', null, 00412 array( '%class_identifier' => $classIdentifier ) ) ); 00413 return false; 00414 } 00415 else if ( !$status ) 00416 { 00417 $result['errors'] = array_merge( $result['errors'], $storeResult['errors'] ); 00418 return false; 00419 } 00420 if ( $storeResult['require_storage'] ) 00421 $dataMap[$fileAttribute]->store(); 00422 00423 $status = $dataMap[$nameAttribute]->insertSimpleString( $object, $publishVersion, eZContentObject::defaultLanguage(), 00424 $nameString, 00425 $storeResult ); 00426 if ( $status === null ) 00427 { 00428 $result['errors'][] = 00429 array( 'description' => ezi18n( 'kernel/content/upload', 00430 'The attribute %class_identifier does not support simple string storage.', null, 00431 array( '%class_identifier' => $classIdentifier ) ) ); 00432 return false; 00433 } 00434 else if ( !$status ) 00435 { 00436 $result['errors'] = array_merge( $result['errors'], $storeResult['errors'] ); 00437 return false; 00438 } 00439 if ( $storeResult['require_storage'] ) 00440 $dataMap[$nameAttribute]->store(); 00441 00442 return $this->publishObject( $result, $result['errors'], $result['notices'], 00443 $object, $publishVersion, $class, $parentNodes, $parentMainNode ); 00444 } 00445 00446 /*! 00447 Fetches the uploaded file, figures out its MIME-type and creates the proper content object out of it. 00448 00449 \param $httpFileIdentifier The HTTP identifier of the uploaded file, this must match the \em name of your \em input tag. 00450 \param $result Result data, will be filled with information which the client can examine, contains: 00451 - errors - An array with errors, each element is an array with \c 'description' containing the text 00452 \param $location The node ID which the new object will be placed or the string \c 'auto' for automatic placement of type. 00453 \param $existingNode Pass a contentobjecttreenode object to let the uploading be done to an existing object, 00454 if not it will create one from scratch. 00455 00456 \return \c false if something failed or \c true if succesful. 00457 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00458 the calls within a db transaction; thus within db->begin and db->commit. 00459 */ 00460 function handleUpload( &$result, $httpFileIdentifier, $location, $existingNode, $nameString = '' ) 00461 { 00462 $result = array( 'errors' => array(), 00463 'notices' => array(), 00464 'result' => false, 00465 'redirect_url' => false ); 00466 00467 $this->fetchHTTPFile( $httpFileIdentifier, $result['errors'], $file, $mimeData ); 00468 if ( !$file ) 00469 { 00470 $result['errors'][] = 00471 array( 'description' => ezi18n( 'kernel/content/upload', 00472 'No HTTP file found, cannot fetch uploaded file.' ) ); 00473 return false; 00474 } 00475 $mime = $mimeData['name']; 00476 if ( $mime == '' ) 00477 $mime = $file->attribute( "mime_type" ); 00478 00479 $handler = $this->findHandler( $result, $mimeData ); 00480 if ( $handler === false ) 00481 { 00482 $result['errors'][] = 00483 array( 'description' => ezi18n( 'kernel/content/upload', 00484 'There was an error trying to instantiate content upload handler.' ) ); 00485 return false; 00486 } 00487 00488 // If this is an object we have a special handler for the file 00489 // The handler will be responsible for the rest of the execution. 00490 if ( is_object( $handler ) ) 00491 { 00492 $filePath = $file->attribute( "filename" ); 00493 $originalFilename = $file->attribute( "original_filename" ); 00494 $handlerResult = $handler->handleFile( $this, $result, 00495 $filePath, $originalFilename, $mimeData, 00496 $location, $existingNode ); 00497 if ( is_object( $result['contentobject'] ) ) 00498 return $handlerResult; 00499 } 00500 00501 $object = false; 00502 $class = false; 00503 // Figure out class identifier from an existing node 00504 // if not we will have to detect it from the mimetype 00505 if ( is_object( $existingNode ) ) 00506 { 00507 $object = $existingNode->object(); 00508 $class = $object->contentClass(); 00509 $classIdentifier = $class->attribute( 'identifier' ); 00510 } 00511 else 00512 { 00513 $classIdentifier = $this->detectClassIdentifier( $mime ); 00514 } 00515 00516 if ( !$classIdentifier ) 00517 { 00518 $result['errors'][] = 00519 array( 'description' => ezi18n( 'kernel/content/upload', 00520 'No matching class identifier found.' ) ); 00521 return false; 00522 } 00523 00524 if ( !is_object( $class ) ) 00525 $class = eZContentClass::fetchByIdentifier( $classIdentifier ); 00526 00527 if ( !$class ) 00528 { 00529 $result['errors'][] = 00530 array( 'description' => ezi18n( 'kernel/content/upload', 00531 'The class %class_identifier does not exist.', null, 00532 array( '%class_identifier' => $classIdentifier ) ) ); 00533 return false; 00534 } 00535 00536 00537 $parentNodes = false; 00538 $parentMainNode = false; 00539 // If do not have an existing node we need to figure 00540 // out the locations from $location and $classIdentifier 00541 if ( !is_object( $existingNode ) ) 00542 { 00543 $locationOK = $this->detectLocations( $classIdentifier, $class, $location, $parentNodes, $parentMainNode ); 00544 if ( $locationOK === false ) 00545 { 00546 $result['errors'][] = 00547 array( 'description' => ezi18n( 'kernel/content/upload', 00548 'Was not able to figure out placement of object.' ) ); 00549 return false; 00550 } 00551 elseif ( $locationOK === null ) 00552 { 00553 $result['status'] = eZContentUpload::STATUS_PERMISSION_DENIED; 00554 $result['errors'][] = 00555 array( 'description' => ezi18n( 'kernel/content/upload', 00556 'Permission denied' ) ); 00557 return false; 00558 } 00559 } 00560 00561 $uploadINI = eZINI::instance( 'upload.ini' ); 00562 $iniGroup = $classIdentifier . '_ClassSettings'; 00563 if ( !$uploadINI->hasGroup( $iniGroup ) ) 00564 { 00565 $result['errors'][] = 00566 array( 'description' => ezi18n( 'kernel/content/upload', 00567 'No configuration group in upload.ini for class identifier %class_identifier.', null, 00568 array( '%class_identifier' => $classIdentifier ) ) ); 00569 return false; 00570 } 00571 00572 $fileAttribute = $uploadINI->variable( $iniGroup, 'FileAttribute' ); 00573 $dataMap = $class->dataMap(); 00574 00575 if ( $classIdentifier == 'image' ) 00576 { 00577 $classAttribute = $dataMap['image']; 00578 $maxSize = 1024 * 1024 * $classAttribute->attribute( 'data_int1' ); 00579 if ( $maxSize != 0 && $file->attribute( 'filesize' ) > $maxSize ) 00580 { 00581 $result['errors'][] = 00582 array( 'description' => ezi18n( 'kernel/content/upload', 00583 'The size of the uploaded file exceeds the limit set for this site: %1 bytes.', null, array( $maxSize ) ) ); 00584 return false; 00585 } 00586 } 00587 00588 00589 $fileAttribute = $this->findHTTPFileAttribute( $dataMap, $fileAttribute ); 00590 if ( !$fileAttribute ) 00591 { 00592 $result['errors'][] = 00593 array( 'description' => ezi18n( 'kernel/content/upload', 00594 'No matching file attribute found, cannot create content object without this.' ) ); 00595 return false; 00596 } 00597 00598 $nameAttribute = $uploadINI->variable( $iniGroup, 'NameAttribute' ); 00599 if ( !$nameAttribute ) 00600 { 00601 $nameAttribute = $this->findStringAttribute( $dataMap, $nameAttribute ); 00602 } 00603 if ( !$nameAttribute ) 00604 { 00605 $result['errors'][] = 00606 array( 'description' => ezi18n( 'kernel/content/upload', 00607 'No matching name attribute found, cannot create content object without this.' ) ); 00608 return false; 00609 } 00610 00611 $variables = array( 'original_filename' => $file->attribute( 'original_filename' ), 00612 'mime_type' => $mime ); 00613 $variables['original_filename_base'] = $mimeData['basename']; 00614 $variables['original_filename_suffix'] = $mimeData['suffix']; 00615 00616 if ( !$nameString ) 00617 { 00618 $namePattern = $uploadINI->variable( $iniGroup, 'NamePattern' ); 00619 $nameString = $this->processNamePattern( $variables, $namePattern ); 00620 } 00621 00622 $db = eZDB::instance(); 00623 $db->begin(); 00624 00625 // If we have an existing node we need to create 00626 // a new version in it. 00627 // If we don't we have to make a new object 00628 if ( is_object( $existingNode ) ) 00629 { 00630 if ( $existingNode->canEdit( ) != '1' ) 00631 { 00632 $result['status'] = eZContentUpload::STATUS_PERMISSION_DENIED; 00633 $result['errors'][] = 00634 array( 'description' => ezi18n( 'kernel/content/upload', 00635 'Permission denied' ) ); 00636 00637 $db->commit(); 00638 return false; 00639 } 00640 $version = $object->createNewVersion( false, true ); 00641 unset( $dataMap ); 00642 $dataMap = $version->dataMap(); 00643 $publishVersion = $version->attribute( 'version' ); 00644 } 00645 else 00646 { 00647 $object = $class->instantiate(); 00648 unset( $dataMap ); 00649 $dataMap = $object->dataMap(); 00650 $publishVersion = $object->attribute( 'current_version' ); 00651 } 00652 00653 unset( $dataMap ); 00654 $dataMap = $object->dataMap(); 00655 00656 $status = $dataMap[$fileAttribute]->insertHTTPFile( $object, $publishVersion, eZContentObject::defaultLanguage(), 00657 $file, $mimeData, 00658 $storeResult ); 00659 if ( $status === null ) 00660 { 00661 $result['errors'][] = 00662 array( 'description' => ezi18n( 'kernel/content/upload', 00663 'The attribute %class_identifier does not support HTTP file storage.', null, 00664 array( '%class_identifier' => $classIdentifier ) ) ); 00665 $db->commit(); 00666 return false; 00667 } 00668 else if ( !$status ) 00669 { 00670 $result['errors'] = array_merge( $result['errors'], $storeResult['errors'] ); 00671 $db->commit(); 00672 return false; 00673 } 00674 if ( $storeResult['require_storage'] ) 00675 $dataMap[$fileAttribute]->store(); 00676 00677 $status = $dataMap[$nameAttribute]->insertSimpleString( $object, $publishVersion, eZContentObject::defaultLanguage(), 00678 $nameString, 00679 $storeResult ); 00680 if ( $status === null ) 00681 { 00682 $result['errors'][] = 00683 array( 'description' => ezi18n( 'kernel/content/upload', 00684 'The attribute %class_identifier does not support simple string storage.', null, 00685 array( '%class_identifier' => $classIdentifier ) ) ); 00686 $db->commit(); 00687 return false; 00688 } 00689 else if ( !$status ) 00690 { 00691 $result['errors'] = array_merge( $result['errors'], $storeResult['errors'] ); 00692 $db->commit(); 00693 return false; 00694 } 00695 if ( $storeResult['require_storage'] ) 00696 $dataMap[$nameAttribute]->store(); 00697 00698 $tmpresult = $this->publishObject( $result, $result['errors'], $result['notices'], 00699 $object, $publishVersion, $class, $parentNodes, $parentMainNode ); 00700 00701 $db->commit(); 00702 return $tmpresult; 00703 } 00704 00705 /*! 00706 \private 00707 Publishes the object to the selected locations. 00708 00709 \return \c true if everything was OK, \c false if something failed. 00710 */ 00711 function publishObject( &$result, &$errors, &$notices, 00712 $object, $publishVersion, $class, $parentNodes, $parentMainNode ) 00713 { 00714 if ( is_array( $parentNodes ) ) 00715 { 00716 foreach ( $parentNodes as $key => $parentNode ) 00717 { 00718 $object->createNodeAssignment( $parentNode, $parentNode == $parentMainNode ); 00719 } 00720 } 00721 00722 $object->setName( $class->contentObjectName( $object ) ); 00723 $object->store(); 00724 00725 //include_once( 'lib/ezutils/classes/ezoperationhandler.php' ); 00726 $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $object->attribute( 'id' ), 00727 'version' => $publishVersion ) ); 00728 00729 $objectID = $object->attribute( 'id' ); 00730 unset( $object ); 00731 $object = eZContentObject::fetch( $objectID ); 00732 $result['contentobject'] = $object; 00733 $result['contentobject_id'] = $object->attribute( 'id' ); 00734 $result['contentobject_version'] = $publishVersion; 00735 $result['contentobject_main_node'] = false; 00736 $result['contentobject_main_node_id'] = false; 00737 00738 $this->setResult( array( 'node_id' => false, 00739 'object_id' => $object->attribute( 'id' ), 00740 'object_version' => $publishVersion ) ); 00741 00742 switch ( $operationResult['status'] ) 00743 { 00744 case eZModuleOperationInfo::STATUS_HALTED: 00745 { 00746 if ( isset( $operationResult['redirect_url'] ) ) 00747 { 00748 $result['redirect_url'] = $operationResult['redirect_url']; 00749 $notices[] = array( 'description' => ezi18n( 'kernel/content/upload', 00750 'Publishing of content object was halted.' ) ); 00751 return true; 00752 } 00753 else if ( isset( $operationResult['result'] ) ) 00754 { 00755 $result['result'] = $operationResult['result']; 00756 return true; 00757 } 00758 } break; 00759 00760 case eZModuleOperationInfo::STATUS_CANCELLED: 00761 { 00762 $result['result'] = ezi18n( 'kernel/content/upload', 00763 'Publish process was cancelled.' ); 00764 return true; 00765 } break; 00766 00767 case eZModuleOperationInfo::STATUS_CONTINUE: 00768 { 00769 } 00770 } 00771 00772 $mainNode = $object->mainNode(); 00773 $result['contentobject_main_node'] = $mainNode; 00774 $result['contentobject_main_node_id'] = $mainNode->attribute( 'node_id' ); 00775 $this->setResult( array( 'node_id' => $mainNode->attribute( 'node_id' ), 00776 'object_id' => $object->attribute( 'id' ), 00777 'object_version' => $publishVersion ) ); 00778 00779 return true; 00780 } 00781 00782 /*! 00783 Finds the file attribute for object \a $contentObject and tries to extract 00784 file information using eZDataType::storedFileInformation(). 00785 \return The information structure or \c false if it fails somehow. 00786 */ 00787 function objectFileInfo( $contentObject ) 00788 { 00789 $uploadINI = eZINI::instance( 'upload.ini' ); 00790 00791 $class = $contentObject->contentClass(); 00792 $classIdentifier = $class->attribute( 'identifier' ); 00793 $classDataMap = $class->dataMap(); 00794 $attributeIdentifier = false; 00795 if ( $uploadINI->hasGroup( $classIdentifier . '_ClassSettings' ) ) 00796 { 00797 $attributeIdentifier = $uploadINI->variable( $classIdentifier . '_ClassSettings', 'FileAttribute' ); 00798 } 00799 00800 $attributeIdentifier = $this->findRegularFileAttribute( $classDataMap, $attributeIdentifier ); 00801 if ( !$attributeIdentifier ) 00802 { 00803 // No file information for this object 00804 return false; 00805 } 00806 00807 $dataMap = $contentObject->dataMap(); 00808 $fileAttribute = $dataMap[$attributeIdentifier]; 00809 00810 if ( $fileAttribute->hasStoredFileInformation( $contentObject, false, false ) ) 00811 { 00812 return $fileAttribute->storedFileInformation( $contentObject, false, false ); 00813 } 00814 return false; 00815 } 00816 00817 /*! 00818 \private 00819 Fetches the HTTP-File into \a $file and fills in MIME-Type information into \a $mimeData. 00820 \return \c false if something went wrong. 00821 */ 00822 function fetchHTTPFile( $httpFileIdentifier, &$errors, &$file, &$mimeData ) 00823 { 00824 //include_once( 'lib/ezutils/classes/ezhttpfile.php' ); 00825 if ( !eZHTTPFile::canFetch( $httpFileIdentifier ) ) 00826 { 00827 $errors[] = array( 'description' => ezi18n( 'kernel/content/upload', 00828 'A file is required for upload, no file were found.' ) ); 00829 return false; 00830 } 00831 00832 $file = eZHTTPFile::fetch( $httpFileIdentifier ); 00833 if ( !( $file instanceof eZHTTPFile ) ) 00834 { 00835 $errors[] = array( 'description' => ezi18n( 'kernel/content/upload', 00836 'Expected a eZHTTPFile object but got nothing.' ) ); 00837 return false; 00838 } 00839 00840 //include_once( 'lib/ezutils/classes/ezmimetype.php' ); 00841 $mimeData = eZMimeType::findByFileContents( $file->attribute( "original_filename" ) ); 00842 00843 return false; 00844 } 00845 00846 /*! 00847 \private 00848 \static 00849 Checks if the attribute with the identifier \a $fileAttribute in \a $dataMap 00850 supports HTTP file uploading. If not it will go trough all attributes and 00851 find the first that has this support. 00852 00853 \return The identifier of the matched attribute or \c false if none were found. 00854 \param $dataMap Associative array with class attributes, the key is attribute identifier 00855 \param $fileAttribute The identifier of the attribute that is expected to have the file datatype. 00856 */ 00857 function findHTTPFileAttribute( $dataMap, $fileAttribute ) 00858 { 00859 $fileDatatype = false; 00860 if ( isset( $dataMap[$fileAttribute] ) ) 00861 $fileDatatype = $dataMap[$fileAttribute]->dataType(); 00862 if ( !$fileDatatype or 00863 !$fileDatatype->isHTTPFileInsertionSupported() ) 00864 { 00865 $fileAttribute = false; 00866 foreach ( $dataMap as $identifier => $attribute ) 00867 { 00868 $datatype = $attribute->dataType(); 00869 if ( $datatype->isHTTPFileInsertionSupported() ) 00870 { 00871 $fileAttribute = $identifier; 00872 break; 00873 } 00874 } 00875 } 00876 return $fileAttribute; 00877 } 00878 00879 /*! 00880 \private 00881 \static 00882 Checks if the attribute with the identifier \a $fileAttribute in \a $dataMap 00883 supports file uploading. If not it will go trough all attributes and 00884 find the first that has this support. 00885 00886 \return The identifier of the matched attribute or \c false if none were found. 00887 \param $dataMap Associative array with class attributes, the key is attribute identifier 00888 \param $fileAttribute The identifier of the attribute that is expected to have the file datatype. 00889 */ 00890 function findRegularFileAttribute( $dataMap, $fileAttribute ) 00891 { 00892 $fileDatatype = false; 00893 if ( isset( $dataMap[$fileAttribute] ) ) 00894 $fileDatatype = $dataMap[$fileAttribute]->dataType(); 00895 if ( !$fileDatatype or 00896 !$fileDatatype->isRegularFileInsertionSupported() ) 00897 { 00898 $fileAttribute = false; 00899 foreach ( $dataMap as $identifier => $attribute ) 00900 { 00901 $datatype = $attribute->dataType(); 00902 if ( $datatype->isRegularFileInsertionSupported() ) 00903 { 00904 $fileAttribute = $identifier; 00905 break; 00906 } 00907 } 00908 } 00909 return $fileAttribute; 00910 } 00911 00912 /*! 00913 \private 00914 \static 00915 Checks if the attribute with the identifier \a $nameAttribute in \a $dataMap 00916 supports string insertion. If not it will go trough all attributes and 00917 find the first that has this support. 00918 00919 \return The identifier of the matched attribute or \c false if none were found. 00920 \param $dataMap Associative array with class attributes, the key is attribute identifier 00921 \param $nameAttribute The identifier of the attribute that is expected to have the string datatype. 00922 */ 00923 function findStringAttribute( $dataMap, $nameAttribute ) 00924 { 00925 $nameDatatype = false; 00926 if ( isset( $dataMap[$nameAttribute] ) ) 00927 $nameDatatype = $dataMap[$nameAttribute]->dataType(); 00928 if ( !$nameDatatype or 00929 !$nameDatatype->isSimpleStringInsertionSupported() ) 00930 { 00931 $nameAttribute = false; 00932 foreach ( $dataMap as $identifier => $attribute ) 00933 { 00934 $datatype = $attribute->dataType(); 00935 if ( $datatype->isSimpleStringInsertionSupported() ) 00936 { 00937 $nameAttribute = $identifier; 00938 break; 00939 } 00940 } 00941 } 00942 return $nameAttribute; 00943 } 00944 00945 /*! 00946 \private 00947 \static 00948 Figures out the class which should be used for file with 00949 MIME-Type \a $mime and returns the class identifier. 00950 \param $mime A string defining the MIME-Type, will be used to determine class identifier. 00951 */ 00952 function detectClassIdentifier( $mime ) 00953 { 00954 $uploadINI = eZINI::instance( 'upload.ini' ); 00955 00956 $mimeClassMap = $uploadINI->variable( 'CreateSettings', 'MimeClassMap' ); 00957 $defaultClass = $uploadINI->variable( 'CreateSettings', 'DefaultClass' ); 00958 00959 list( $group, $type ) = explode( '/', $mime ); 00960 if ( isset( $mimeClassMap[$mime] ) ) 00961 { 00962 $classIdentifier = $mimeClassMap[$mime]; 00963 } 00964 else if ( isset( $mimeClassMap[$group] ) ) 00965 { 00966 $classIdentifier = $mimeClassMap[$group]; 00967 } 00968 else 00969 { 00970 $classIdentifier = $defaultClass; 00971 } 00972 return $classIdentifier; 00973 } 00974 00975 /*! 00976 \private 00977 Figures out the location(s) in which the class with 00978 the identifier \a $classIdentifier should be placed. 00979 The returned locations will either be a node ID or an identifier 00980 for a node (e.g. content). 00981 00982 \return \c true if a location was found or \c false if no location could be determined 00983 \param $classIdentifier Identifier of class, is used to determine location 00984 \param $location The wanted location, either use \c 'auto' for automatic placement 00985 or number to determine to parent node ID. 00986 \param[out] $parentNodes Will contain an array with node IDs or identifiers if a location could be detected. 00987 \param[out] $parentMainNode Will contain the ID of the main node if a location could be detected. 00988 */ 00989 function detectLocations( $classIdentifier, $class, $location, 00990 &$parentNodes, &$parentMainNode ) 00991 { 00992 $isAccessChecked = false; 00993 $parentMainNode = false; 00994 if ( $this->hasAttribute( 'parent_nodes' ) && 00995 $this->attribute( 'parent_nodes' ) ) 00996 { 00997 $parentNodes = $this->attribute( 'parent_nodes' ); 00998 foreach( $parentNodes as $key => $parentNode ) 00999 { 01000 $parentNodes[$key] = eZContentUpload::nodeAliasID( $parentNode ); 01001 if ( !eZContentUpload::checkAccess( $parentNodes[$key], $class ) ) 01002 { 01003 $parentNodes = false; 01004 return null; 01005 } 01006 } 01007 } 01008 else 01009 { 01010 if ( $location == 'auto' or !is_numeric( $location ) ) 01011 { 01012 $contentINI = eZINI::instance( 'content.ini' ); 01013 01014 $classPlacementMap = $contentINI->variable( 'RelationAssignmentSettings', 'ClassSpecificAssignment' ); 01015 $defaultPlacement = $contentINI->variable( 'RelationAssignmentSettings', 'DefaultAssignment' ); 01016 01017 // Find location that matches the class and where user is allowed to create objects 01018 foreach ( $classPlacementMap as $classData ) 01019 { 01020 $classElements = explode( ';', $classData ); 01021 $classList = explode( ',', $classElements[0] ); 01022 01023 if ( in_array( $classIdentifier, $classList ) ) 01024 { 01025 $parentNodes = explode( ',', $classElements[1] ); 01026 if ( count( $parentNodes ) == 0 ) 01027 continue; 01028 01029 if ( isset( $classElements[2] ) ) 01030 $parentMainNode = eZContentUpload::nodeAliasID( $classElements[2] ); 01031 01032 // check access rights and convert to IDs 01033 foreach ( $parentNodes as $key => $parentNode ) 01034 { 01035 $parentNodeID = eZContentUpload::nodeAliasID( $parentNode ); 01036 if ( !$parentNodeID ) 01037 { 01038 $parentNodes = false; 01039 break; 01040 } 01041 01042 $parentNodes[$key] = $parentNodeID; 01043 01044 if ( !eZContentUpload::checkAccess( $parentNodeID, $class ) ) 01045 { 01046 eZDebug::writeNotice( "Upload assignment setting '$classData' skipped - no permissions", 'eZContentUpload::detectLocations' ); 01047 $parentNodes = false; 01048 break; 01049 } 01050 } 01051 01052 if ( $parentNodes ) 01053 { 01054 eZDebug::writeNotice( "Matched assignment for upload :'$classData'", 'eZContentUpload::detectLocations' ); 01055 break; 01056 } 01057 } 01058 } 01059 01060 if ( !$parentNodes && isset( $defaultPlacement ) && $defaultPlacement ) 01061 { 01062 $defaultNodeID = eZContentUpload::nodeAliasID( $defaultPlacement ); 01063 if ( $defaultNodeID ) 01064 { 01065 if ( eZContentUpload::checkAccess( $defaultNodeID, $class ) ) 01066 { 01067 $parentNodes = array( $defaultNodeID ); 01068 } 01069 else 01070 { 01071 eZDebug::writeNotice( "No create permission for default upload location: node #$defaultNodeID", 'eZContentUpload::detectLocations' ); 01072 return null; 01073 } 01074 01075 } 01076 } 01077 } 01078 else 01079 { 01080 $locationID = eZContentUpload::nodeAliasID( $location ); 01081 if ( $locationID ) 01082 { 01083 if ( eZContentUpload::checkAccess( $locationID, $class ) ) 01084 { 01085 $parentNodes = array( $locationID ); 01086 } 01087 else 01088 { 01089 eZDebug::writeNotice( "No create permission for upload location: node #$locationID", 'eZContentUpload::detectLocations' ); 01090 return null; 01091 } 01092 } 01093 } 01094 } 01095 01096 if ( !$parentNodes || count( $parentNodes ) == 0 ) 01097 { 01098 return false; 01099 } 01100 01101 if ( !$parentMainNode ) 01102 { 01103 $parentMainNode = $parentNodes[0]; 01104 } 01105 01106 return true; 01107 } 01108 01109 /*! 01110 \private 01111 \static 01112 */ 01113 01114 function checkAccess( $nodeID, $class ) 01115 { 01116 $parentNodeObj = eZContentObjectTreeNode::fetch( $nodeID ); 01117 $parentObject = $parentNodeObj->attribute( 'object' ); 01118 01119 if ( $parentNodeObj->checkAccess( 'create', 01120 $class->attribute( 'id' ), 01121 $parentObject->attribute( 'contentclass_id' ) ) != '1' ) 01122 { 01123 return false; 01124 } 01125 return true; 01126 } 01127 01128 /*! 01129 \private 01130 \static 01131 Parses the name pattern \a $namePattern and replaces any 01132 variables found in \a $variables with the variable value. 01133 01134 \return The resulting string with all \e tags replaced. 01135 \param $variables An associative array where the key is variable name and element the variable value. 01136 \param $namePattern A string containing of plain text or \e tags, each tag is enclosed in < and > and 01137 defines name of the variable to lookup. 01138 01139 \code 01140 $vars = array( 'name' => 'A name', 01141 'filename' => 'myfile.txt' ); 01142 $name = $this->parseNamePattern( $vars, '<name> - <filename>' ); 01143 print( $name ); // Will output 'A name - myfile.txt' 01144 \endcode 01145 */ 01146 function processNamePattern( $variables, $namePattern ) 01147 { 01148 $tags = array(); 01149 $pos = 0; 01150 $lastPos = false; 01151 $len = strlen( $namePattern ); 01152 while ( $pos < $len ) 01153 { 01154 $markerPos = strpos( $namePattern, '<', $pos ); 01155 if ( $markerPos !== false ) 01156 { 01157 $markerEndPos = strpos( $namePattern, '>', $markerPos + 1 ); 01158 if ( $markerEndPos === false ) 01159 { 01160 $markerEndPos = $len; 01161 $pos = $len; 01162 } 01163 else 01164 { 01165 $pos = $markerEndPos + 1; 01166 } 01167 $tag = substr( $namePattern, $markerPos + 1, $markerEndPos - $markerPos - 1 ); 01168 $tags[] = array( 'name' => $tag ); 01169 } 01170 if ( $lastPos !== false and 01171 $lastPos < $pos ) 01172 { 01173 $tags[] = substr( $namePattern, $lastPos, $pos - $lastPos ); 01174 } 01175 $lastPos = $pos; 01176 } 01177 $nameString = ''; 01178 foreach ( $tags as $tag ) 01179 { 01180 if ( is_string( $tag ) ) 01181 { 01182 $nameString .= $tag; 01183 } 01184 else 01185 { 01186 if ( isset( $variables[$tag['name']] ) ) 01187 $nameString .= $variables[$tag['name']]; 01188 } 01189 } 01190 return $nameString; 01191 } 01192 01193 /*! 01194 \static 01195 \return the node ID for the node alias \a $nodeName or \c false if no ID could be found. 01196 */ 01197 function nodeAliasID( $nodeName ) 01198 { 01199 if ( is_numeric( $nodeName ) ) 01200 { 01201 $node = eZContentObjectTreeNode::fetch( $nodeName, false, false ); 01202 if ( is_array( $node ) ) 01203 { 01204 $result['status'] = eZContentUpload::STATUS_PERMISSION_DENIED; 01205 $errors[] = array( 'description' => ezi18n( 'kernel/content/upload', 01206 'Permission denied' ) ); 01207 01208 return $nodeName; 01209 } 01210 } 01211 01212 $uploadINI = eZINI::instance( 'upload.ini' ); 01213 $aliasList = $uploadINI->variable( 'UploadSettings', 'AliasList' ); 01214 if ( isset( $aliasList[$nodeName] ) ) 01215 return $aliasList[$nodeName]; 01216 $contentINI = eZINI::instance( 'content.ini' ); 01217 if ( $nodeName == 'content' or $nodeName == 'root' ) 01218 return $contentINI->variable( 'NodeSettings', 'RootNode' ); 01219 else if ( $nodeName == 'users' ) 01220 return $contentINI->variable( 'NodeSettings', 'UserRootNode' ); 01221 else if ( $nodeName == 'media' ) 01222 return $contentINI->variable( 'NodeSettings', 'MediaRootNode' ); 01223 else if ( $nodeName == 'setup' ) 01224 return $contentINI->variable( 'NodeSettings', 'SetupRootNode' ); 01225 01226 // Check for node path element 01227 $pathPos = strpos( $nodeName, '/' ); 01228 if ( $pathPos !== false ) 01229 { 01230 $node = eZContentObjectTreeNode::fetchByURLPath( $nodeName, false ); 01231 if ( is_array( $node ) ) 01232 { 01233 return $node['node_id']; 01234 } 01235 } 01236 return false; 01237 } 01238 01239 /*! 01240 Sets the result array to \a $result and stores the session variable. 01241 */ 01242 function setResult( $result ) 01243 { 01244 $this->Parameters['result'] = $result; 01245 $http = eZHTTPTool::instance(); 01246 $http->setSessionVariable( 'ContentUploadParameters', $this->Parameters ); 01247 } 01248 01249 /*! 01250 \static 01251 \return the result of the previous upload operation or \c false if no result was found. 01252 It uses the action name \a $actionName to determine which result to look for. 01253 \param $cleanup If \c true it the persisten data is cleaned up by calling cleanup(). 01254 */ 01255 static function result( $actionName, $cleanup = true ) 01256 { 01257 $upload = new eZContentUpload(); 01258 01259 $isNodeSelection = $upload->attribute( 'return_type' ) == 'NodeID'; 01260 $resultData = $upload->attribute( 'result' ); 01261 $result = false; 01262 if ( $isNodeSelection ) 01263 { 01264 $result = $resultData['node_id']; 01265 } 01266 else 01267 { 01268 $result = $resultData['object_id']; 01269 } 01270 if ( $cleanup ) 01271 eZContentUpload::cleanup( $actionName ); 01272 return $result; 01273 } 01274 01275 /*! 01276 \static 01277 Cleans up the persistent data and result for action named \a $actionName 01278 */ 01279 static function cleanup( $actionName ) 01280 { 01281 $http = eZHTTPTool::instance(); 01282 $http->removeSessionVariable( 'ContentUploadParameters' ); 01283 } 01284 01285 /*! 01286 \static 01287 Similar to cleanup() but removes persistent data from all actions. 01288 */ 01289 function cleanupAll() 01290 { 01291 $http = eZHTTPTool::instance(); 01292 $http->removeSessionVariable( 'ContentUploadParameters' ); 01293 } 01294 01295 /*! 01296 Finds the correct upload handler for the file specified in \a $mimeInfo. 01297 If no handler is found it will return the default attribute based handler eZContentUpload, 01298 this means that the file is passed to one suitable attribute and handled from there. 01299 \return An object with the interface eZContentUploadHandler or \c false if an error occured. 01300 Will return \c true if there is no handler configured for this type. 01301 */ 01302 function findHandler( &$result, $mimeInfo ) 01303 { 01304 // Check for specific mime handler plugin 01305 $uploadINI = eZINI::instance( 'upload.ini' ); 01306 $uploadSettings = $uploadINI->variable( 'CreateSettings', 'MimeUploadHandlerMap' ); 01307 01308 $mime = $mimeInfo['name']; 01309 $elements = explode( '/', $mime ); 01310 $mimeGroup = $elements[0]; 01311 01312 $handlerName = false; 01313 // Check first for MIME-Type group, this allows a handler to work 01314 // with an entire group, e.g. image 01315 if ( isset( $uploadSettings[$mimeGroup] ) ) 01316 { 01317 $handlerName = $uploadSettings[$mimeGroup]; 01318 } 01319 else if ( isset( $uploadSettings[$mime] ) ) 01320 { 01321 $handlerName = $uploadSettings[$mime]; 01322 } 01323 01324 if ( $handlerName !== false ) 01325 { 01326 //include_once( 'lib/ezutils/classes/ezextension.php' ); 01327 $baseDirectory = eZExtension::baseDirectory(); 01328 $extensionDirectories = eZExtension::activeExtensions(); 01329 01330 // Check all extension directories for an upload handler for this mimetype 01331 foreach ( $extensionDirectories as $extensionDirectory ) 01332 { 01333 $handlerPath = $baseDirectory . '/' . $extensionDirectory . '/uploadhandlers/' . $handlerName . ".php"; 01334 if ( !file_exists( $handlerPath ) ) 01335 continue; 01336 01337 include_once( $handlerPath ); 01338 $handlerClass = $handlerName; 01339 $handler = new $handlerClass(); 01340 if ( !$handler instanceof eZContentUploadHandler ) 01341 { 01342 eZDebug::writeError( "Content upload handler '$handlerName' is not inherited from eZContentUploadHandler. All upload handlers must do this.", 'eZContentUpload::findHandler' ); 01343 return false; 01344 } 01345 return $handler; 01346 } 01347 01348 $result['errors'][] = 01349 array( 'description' => ezi18n( 'kernel/content/upload', 01350 "Could not find content upload handler '%handler_name'", 01351 null, array( '%handler_name' => $handlerName ) ) ); 01352 01353 return false; 01354 } 01355 return true; 01356 } 01357 01358 /// \privatesection 01359 /// The upload parameters. 01360 public $Parameters = false; 01361 } 01362 01363 ?>