/** * Handles data storage on the content tree level. * * It will try to find the parent node of the wanted placement and * create a new object with data from $tempFile. * * @param string $currentSite Eg. 'plain_site_user' * @param string $virtualFolder Eg. 'Content' * @param string $target Eg. 'Folder1/file1.txt' * @param string $tempFile The temporary file holding the contents * @return bool * @todo remove/replace eZContentUpload */ protected function putContentData($currentSite, $virtualFolder, $target, $tempFile) { $nodePath = $this->internalNodePath($virtualFolder, $target); $parentNode = $this->fetchParentNodeByTranslation($nodePath); if ($parentNode === null) { // The node does not exist, so we cannot put the file return false; // @as self::FAILED_CONFLICT; } // Can we put content in the parent node if (!$parentNode->canRead()) { return false; // @as self::FAILED_FORBIDDEN; } $parentNodeID = $parentNode->attribute('node_id'); $existingNode = $this->fetchNodeByTranslation($nodePath); $upload = new eZContentUpload(); if (!$upload->handleLocalFile($result, $tempFile, $parentNodeID, $existingNode)) { if ($result['status'] === eZContentUpload::STATUS_PERMISSION_DENIED) { return false; // @as self::FAILED_FORBIDDEN; } else { return false; // @as self::FAILED_UNSUPPORTED; } } return true; // @as self::OK_CREATED; }
function putContentData( $currentSite, $virtualFolder, $target, $tempFile, $fullPath ) { $nodePath = $this->internalNodePath( $virtualFolder, $target ); $this->appendLogEntry( "Inside virtual content folder", 'CS:put' ); $parentNode = $this->fetchParentNodeByTranslation( $nodePath ); if ( $parentNode == null ) { // The node does not exist, so we cannot put the file $this->appendLogEntry( "Cannot put file $nodePath, not parent found", 'CS:put' ); return eZWebDAVServer::FAILED_CONFLICT; } // Can we put content in the parent node if ( !$parentNode->canRead() ) { $this->appendLogEntry( "No access to put '$nodePath' in site '$currentSite'", 'CS:put' ); return eZWebDAVServer::FAILED_FORBIDDEN; } $parentNodeID = $parentNode->attribute( 'node_id' ); // We need the MIME-Type to figure out which content-class we will use $mimeInfo = eZMimeType::findByURL( $nodePath ); $mime = $mimeInfo['name']; $webdavINI = eZINI::instance( eZWebDAVContentServer::WEBDAV_INI_FILE ); $defaultObjectType = $webdavINI->variable( 'PutSettings', 'DefaultClass' ); $existingNode = $this->fetchNodeByTranslation( $nodePath ); $upload = new eZContentUpload(); if ( !$upload->handleLocalFile( $result, $tempFile, $parentNodeID, $existingNode ) ) { foreach ( $result['errors'] as $error ) { $this->appendLogEntry( "Error: " . $error['description'], 'CS: put' ); } foreach ( $result['notices'] as $notice ) { $this->appendLogEntry( "Notice: " . $notice['description'], 'CS: put' ); } if ( $result['status'] == eZContentUpload::STATUS_PERMISSION_DENIED ) { return eZWebDAVServer::FAILED_FORBIDDEN; } else return eZWebDAVServer::FAILED_UNSUPPORTED; } return eZWebDAVServer::OK_CREATED; }
/** * Crea un oggetto a partire da un fieldArray di tipo ezimage, ezbinaryfile * @see eZContentUpload * @params array $fieldArray * @return int content object id */ protected function createMedia($fieldArray) { $filePath = SQLIContentUtils::getRemoteFile($fieldArray['value']); $upload = new eZContentUpload(); $result = array(); if ($upload->handleLocalFile($result, $filePath, 'auto', false) == true) { return $result['contentobject_id']; } eZDebug::writeNotice(var_export($result['notices']), __METHOD__); eZDebug::writeError(var_export($result['errors']), __METHOD__); return ''; }
/** * Creates the eZContentObject from the uploaded file * * @param eZHTTPFile $file * @param eZContentObjectTreeNode $location * @param string $name * @return eZContentObject * @throw InvalidArgumentException if the parent location does not exists * @throw RuntimeException if the object can not be created */ public function createObject($file, $parentNodeId, $name = '') { $result = array(); $parentNode = eZContentObjectTreeNode::fetch($parentNodeId); if (!$parentNode instanceof eZContentObjectTreeNode) { throw new InvalidArgumentException(ezpI18n::tr('extension/ezjscore/ajaxuploader', 'Location not found.')); } $upload = new eZContentUpload(); $r = $upload->handleLocalFile($result, $file, $parentNodeId, null, $name, $this->attribute->attribute('language_code')); if (!$r || !$result['contentobject'] instanceof eZContentObject) { throw new RuntimeException(ezpI18n::tr('extension/ezjscore/ajaxuploader', 'Unable to create the content object to add to the relation: %detail', null, array('%detail', $result['errors'][0]['description']))); } return $result['contentobject']; }
$canUpload = $parentNode instanceof eZContentObjectTreeNode && $parentNode->canCreate(); } $response = array(); if ($canUpload) { $siteaccess = eZSiteAccess::current(); $options['upload_dir'] = eZSys::cacheDirectory() . '/fileupload/'; $options['download_via_php'] = true; $options['param_name'] = "files"; $options['image_versions'] = array(); $options['max_file_size'] = $http->variable("upload_max_file_size", null); $uploadHandler = new UploadHandler($options, false); $data = $uploadHandler->post(false); foreach ($data[$options['param_name']] as $file) { $filePath = $options['upload_dir'] . $file->name; $behaviour = new ezpContentPublishingBehaviour(); $behaviour->isTemporary = true; $behaviour->disableAsynchronousPublishing = false; ezpContentPublishingBehaviour::setBehaviour($behaviour); $upload = new eZContentUpload(); $upload->handleLocalFile($response, $filePath, $parentNodeID, false); } $file = eZClusterFileHandler::instance($filePath); if ($file->exists()) { $file->delete(); } } else { $response = array('errors' => array('Not Allowed')); } header('Content-Type: application/json'); echo json_encode($response); eZExecution::cleanExit();