} $http = eZHTTPTool::instance(); $http->removeSessionVariable( 'ContentUploadParameters' ); return $module->redirectTo( $url ); } if ( $module->isCurrentAction( 'UploadFile' ) ) { $location = false; if ( $module->hasActionParameter( 'UploadLocation' ) ) $location = $module->actionParameter( 'UploadLocation' ); if ( $module->hasActionParameter( 'ObjectName' ) ) $objectName = $module->actionParameter( 'ObjectName' ); if ( $upload->handleUpload( $result, 'UploadFile', $location, false, $objectName ) ) { $object = $result['contentobject']; $mainNode = $result['contentobject_main_node']; if ( $result['redirect_url'] ) { return $module->redirectTo( $result['redirect_url'] ); } if ( $result['result'] ) { $resultData = $result['result']; $resultContent = false; if ( is_array( $resultData ) ) { if ( isset( $resultData['content'] ) ) $resultContent = $resultData['content'];
<?php $http = eZHTTPTool::instance(); $tpl = eZTemplate::factory(); $module = $Params['Module']; $parentNodeID = $Params['ParentNodeID']; $message = json_encode("error"); if ($module->isCurrentAction('Upload')) { $result = array('errors' => array()); // Exec multiupload handlers preUpload method eZMultiuploadHandler::exec('preUpload', $result); // Handle file upload only if there was no errors if (empty($result['errors'])) { // Handle file upload. All checkes are performed by eZContentUpload::handleUpload() // and available in $result array $upload = new eZContentUpload(); $upload->handleUpload($result, 'Filedata', $parentNodeID, false); } // Exec multiupload handlers postUpload method eZMultiuploadHandler::exec('postUpload', $result); unset($result['contentobject_main_node']); unset($result['contentobject']); $id = md5((string) mt_rand() . (string) microtime()); $response = array('id' => $id, 'result' => $result); $message = json_encode($response); } header('Content-Type: application/json'); echo $message; eZExecution::cleanExit();
function checkRelationActions($module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage) { $http = eZHTTPTool::instance(); if ($module->isCurrentAction('BrowseForObjects')) { $objectID = $object->attribute('id'); $assignedNodes = $object->attribute('assigned_nodes'); $assignedNodesIDs = array(); foreach ($assignedNodes as $node) { $assignedNodesIDs = $node->attribute('node_id'); } unset($assignedNodes); eZContentBrowse::browse(array('action_name' => 'AddRelatedObject', 'description_template' => 'design:content/browse_related.tpl', 'content' => array('object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage), 'keys' => array('class' => $class->attribute('id'), 'class_id' => $class->attribute('identifier'), 'classgroup' => $class->attribute('ingroup_id_list'), 'section' => $object->attribute('section_id')), 'ignore_nodes_select' => $assignedNodesIDs, 'from_page' => $module->redirectionURI('content', 'edit', array($objectID, $editVersion, $editLanguage, $fromLanguage))), $module); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ($module->isCurrentAction('UploadFileRelation')) { $objectID = $object->attribute('id'); $section = eZSection::fetch($object->attribute('section_id')); $navigationPart = false; if ($section) { $navigationPart = $section->attribute('navigation_part_identifier'); } $location = false; if ($module->hasActionParameter('UploadRelationLocation')) { $location = $module->actionParameter('UploadRelationLocation'); } // We only do direct uploading if we have the uploaded HTTP file // if not we need to go to the content/upload page. if (eZHTTPFile::canFetch('UploadRelationFile')) { $upload = new eZContentUpload(); if ($upload->handleUpload($result, 'UploadRelationFile', $location, false)) { $relatedObjectID = $result['contentobject_id']; if ($relatedObjectID) { $db = eZDB::instance(); $db->begin(); $object->addContentObjectRelation($relatedObjectID, $editVersion); $db->commit(); } } } else { eZContentUpload::upload(array('action_name' => 'RelatedObjectUpload', 'description_template' => 'design:content/upload_related.tpl', 'navigation_part_identifier' => $navigationPart, 'content' => array('object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage), 'keys' => array('class' => $class->attribute('id'), 'class_id' => $class->attribute('identifier'), 'classgroup' => $class->attribute('ingroup_id_list'), 'section' => $object->attribute('section_id')), 'result_action_name' => 'UploadedFileRelation', 'ui_context' => 'edit', 'result_module' => array('content', 'edit', array($objectID, $editVersion, $editLanguage, $fromLanguage))), $module); return eZModule::HOOK_STATUS_CANCEL_RUN; } } if ($module->isCurrentAction('DeleteRelation')) { $objectID = $object->attribute('id'); if ($http->hasPostVariable('DeleteRelationIDArray')) { $relationObjectIDs = $http->postVariable('DeleteRelationIDArray'); } else { $relationObjectIDs = array(); } $db = eZDB::instance(); $db->begin(); foreach ($relationObjectIDs as $relationObjectID) { $object->removeContentObjectRelation($relationObjectID, $editVersion); } $db->commit(); } if ($module->isCurrentAction('NewObject')) { if ($http->hasPostVariable('ClassID')) { if ($http->hasPostVariable('SectionID')) { $sectionID = $http->postVariable('SectionID'); } else { $sectionID = 0; /* Will be changed later */ } $contentClassID = $http->postVariable('ClassID'); $class = eZContentClass::fetch($contentClassID); $db = eZDB::instance(); $db->begin(); $relatedContentObject = $class->instantiate(false, $sectionID); $db->commit(); $newObjectID = $relatedContentObject->attribute('id'); $relatedContentVersion = $relatedContentObject->attribute('current'); if ($relatedContentObject->attribute('can_edit')) { $db = eZDB::instance(); $db->begin(); $assignmentHandler = new eZContentObjectAssignmentHandler($relatedContentObject, $relatedContentVersion); $sectionID = (int) $assignmentHandler->setupAssignments(array('group-name' => 'RelationAssignmentSettings', 'default-variable-name' => 'DefaultAssignment', 'specific-variable-name' => 'ClassSpecificAssignment', 'section-id-wanted' => true, 'fallback-node-id' => $object->attribute('main_node_id'))); $http->setSessionVariable('ParentObject', array($object->attribute('id'), $editVersion, $editLanguage)); $http->setSessionVariable('NewObjectID', $newObjectID); /* Change section ID to the same one as the main node placement */ $db->query("UPDATE ezcontentobject SET section_id = {$sectionID} WHERE id = {$newObjectID}"); $db->commit(); $module->redirectToView('edit', array($relatedContentObject->attribute('id'), $relatedContentObject->attribute('current_version'), false)); } else { $db = eZDB::instance(); $db->begin(); $relatedContentObject->purge(); $db->commit(); } return; } } }
eZExecution::cleanExit(); } $upload = new eZContentUpload(); $location = false; if ($http->hasPostVariable('location')) { $location = $http->postVariable('location'); if ($location === 'auto' || trim($location) === '') { $location = false; } } $objectName = ''; if ($http->hasPostVariable('objectName')) { $objectName = trim($http->postVariable('objectName')); } try { $uploadedOk = $upload->handleUpload($result, 'fileName', $location, false, $objectName, $version->attribute('initial_language')->attribute('locale'), false); if (!$uploadedOk) { throw new RuntimeException("Upload failed"); } $uploadVersion = $uploadedOk['contentobject']->currentVersion(); $newObjectID = (int) $uploadedOk['contentobject']->attribute('id'); foreach ($uploadVersion->dataMap() as $key => $attr) { //post pattern: ContentObjectAttribute_attribute-identifier $base = 'ContentObjectAttribute_' . $key; $postVar = trim($http->postVariable($base, '')); if ($postVar !== '') { switch ($attr->attribute('data_type_string')) { case 'ezstring': $classAttr = $attr->attribute('contentclass_attribute'); $dataType = $classAttr->attribute('data_type'); if ($dataType->validateStringHTTPInput($postVar, $attr, $classAttr) !== eZInputValidator::STATE_ACCEPTED) {
<?php $parentNodeId = (int) $_REQUEST['parent_node_id']; if ($parentNodeId && !empty($_FILES)) { $return = array(); $upload = new eZContentUpload(); foreach ($_FILES as $key => $values) { if (substr($key, 0, 5) == 'files') { $upload->handleUpload($result, $key, $parentNodeId, false); $return[] = array('name' => $values['name'], 'errors' => implode(', ', $result['errors']), 'contentobject_id' => $result['contentobject_id']); } } } else { die('missing input parameters'); } header('Content-type: application/json'); echo json_encode($return); eZExecution::cleanExit();
/** * Handles image upload operation * * @static */ public static function uploadImage() { $contentINI = eZINI::instance('ezstyleeditor.ini'); $rep = $contentINI->variable('StyleEditor', 'ImageRepository'); if (is_numeric($rep)) { $contentNode = eZContentObjectTreeNode::fetch($rep); } else { $nodeID = eZURLAliasML::fetchNodeIDByPath($rep); $contentNode = eZContentObjectTreeNode::fetch($nodeID); } $upload = new eZContentUpload(); $location = false; if (is_object($contentNode)) { $location = $contentNode->attribute('node_id'); } $http = eZHTTPTool::instance(); $fileName = ''; if ($http->hasPostVariable('FileName')) { $fileName = $http->postVariable('FileName'); } $success = $upload->handleUpload($result, 'File', $location, false, $fileName); }