function handleFile(&$upload, &$result, $filePath, $originalFilename, $mimeinfo, $location, $existingNode) { $tmpDir = getcwd() . "/" . eZSys::cacheDirectory(); $originalFilename = basename($originalFilename); $tmpFile = $tmpDir . "/" . $originalFilename; copy($filePath, $tmpFile); $import = new eZOOImport(); $tmpResult = $import->import($tmpFile, $location, $originalFilename, 'import', $upload); $result['contentobject'] = $tmpResult['Object']; $result['contentobject_main_node'] = $tmpResult['MainNode']; unlink($tmpFile); return true; }
/** * Import object. * * @param Array getParameters. * @param Array getOptions. * @param Array postParameters. * @param Array postOptions. * @param string Import type. * * @return DOMElement DOMElement containing OO document. */ protected function importOODocument($getParams, $getOptions, $postParams, $postOptions, $importType = 'import') { $nodeID = $postParams['nodeID']; $data = $postParams['data']; // Alex 2008/04/22 - Added format argument: 'odt' (default), 'doc' $format = $postOptions['format']; $languageCode = $postOptions['languageCode']; $base64Encoded = $postOptions['base64Encoded']; $node = eZContentObjectTreeNode::fetch($nodeID, $languageCode); if (!$node) { throw new Exception('Could not fetch node: ' . $nodeID); } // Decode data. if ($base64Encoded) { // Alex 2008/04/16 - Added str_replace() $data = base64_decode(str_replace(' ', '+', $data)); } // Store data to temporary file. // Alex 2008/04/22 - Added format argument: 'odt' (default), 'doc' $filename = substr(md5(mt_rand()), 0, 8) . ".{$format}"; $tmpFilePath = eZSys::cacheDirectory() . '/ezodf/' . substr(md5(mt_rand()), 0, 8); $tmpFilename = $tmpFilePath . '/' . $filename; if (!eZFile::create($filename, $tmpFilePath, $data)) { throw new Exception('Could not create file: ' . $tmpFilename); } $import = new eZOOImport(); $result = $import->import($tmpFilename, $nodeID, $filename, $importType); eZDir::recursiveDelete($tmpFilePath); if (!$result) { throw new Exception('OO import failed: ' . $import->getErrorNumber() . ' - ' . $import->getErrorMessage()); } $domDocument = new DOMDocument('1.0', 'utf-8'); $importElement = $domDocument->createElement('OOImport'); // Add node info about imported document. $importElement->appendChild($this->createTreeNodeDOMElement($domDocument, $result['MainNode'])); return $importElement; }
if ( $file ) { if ( $file->store() ) { $fileName = $file->attribute( 'filename' ); $originalFileName = $file->attribute( 'original_filename' ); // If we have the NodeID do the import/replace directly if ( $http->sessionVariable( 'oo_direct_import_node' ) ) { $nodeID = $http->sessionVariable( 'oo_direct_import_node' ); $importType = $http->sessionVariable( 'oo_import_type' ); if ( $importType != "replace" ) $importType = "import"; $import = new eZOOImport(); $result = $import->import( $fileName, $nodeID, $originalFileName, $importType ); // Cleanup of uploaded file unlink( $fileName ); if ( $result ) { $tpl->setVariable( 'class_identifier', $result['ClassIdentifier'] ); $tpl->setVariable( 'url_alias', $result['URLAlias'] ); $tpl->setVariable( 'node_name', $result['NodeName'] ); $tpl->setVariable( 'published', $result['Published'] ); $tpl->setVariable( 'oo_mode', 'imported' ); } else { if( $import->getErrorNumber() != 0 )
eZExecution::cleanExit(); } $file = eZHTTPFile::fetch('File'); $fileName = $file->attribute( 'filename' ); $originalFilename = $file->attribute('original_filename'); $content = base64_decode( file_get_contents( $fileName ) ); $fd = fopen( $fileName, 'w' ); fwrite( $fd, $content ); fclose( $fd ); // Conversion of the stored file $import = new eZOOImport(); $importResult = $import->import( $fileName, $nodeID, $originalFilename, $importType ); // Verification : conversion OK ? if ( $import->getErrorNumber( ) != 0 ) { print( 'problem:Import : ' . $import->getErrorMessage( ) ); eZExecution::cleanExit(); } // End : print return string print( 'done:File successfully exported with nodeID ' . $importResult['MainNode']->attribute('node_id') ); // Don't display eZ Publish page structure eZExecution::cleanExit();
} else { $tpl->setVariable('oo_mode', 'browse'); if (eZHTTPFile::canFetch("oo_file")) { $file = eZHTTPFile::fetch("oo_file"); if ($file) { if ($file->store()) { $fileName = $file->attribute('filename'); $originalFileName = $file->attribute('original_filename'); // If we have the NodeID do the import/replace directly if ($http->sessionVariable('oo_direct_import_node')) { $nodeID = $http->sessionVariable('oo_direct_import_node'); $importType = $http->sessionVariable('oo_import_type'); if ($importType != "replace") { $importType = "import"; } $import = new eZOOImport(); $result = $import->import($fileName, $nodeID, $originalFileName, $importType, null, $http->sessionVariable('oo_import_locale')); // Cleanup of uploaded file unlink($fileName); if ($result) { $tpl->setVariable('class_identifier', $result['ClassIdentifier']); $tpl->setVariable('url_alias', $result['URLAlias']); $tpl->setVariable('node_name', $result['NodeName']); $tpl->setVariable('published', $result['Published']); $tpl->setVariable('oo_mode', 'imported'); } else { if ($import->getErrorNumber() != 0) { $tpl->setVariable('error', makeErrorArray($import->getErrorNumber(), $import->getErrorMessage())); } else { $tpl->setVariable('error', makeErrorArray(eZOOImport::ERROR_DOCNOTSUPPORTED, ezpI18n::tr('extension/ezodf/import/error', "Document is not supported."))); }