public function extractTo($Path, $Names) { $Indexes = array(); // Convert the name(s) to indexes. foreach ((array) $Names as $Name) { if (!isset($this->_Names[$Name])) { continue; } $Indexes[] = $this->_Names[$Name]['index']; } $IndexesStr = implode(',', $Indexes); $Result = $this->PclZip->extractByIndex($IndexesStr, $Path); return $Result != 0; }
function parse() { $temp_file = new upload($this->_filename, DIR_FS_CACHE); if ($temp_file->exists() && $temp_file->parse() && $temp_file->save()) { $this->_filename = $temp_file; } if ($this->_compression_type == 'zip') { require_once '../ext/zip/pclzip.lib.php'; $archive = new PclZip($this->_filename->destination . $this->_filename->filename); if ($archive->extract(PCLZIP_OPT_PATH, DIR_FS_CACHE) == 0) { return false; } else { $file = $archive->extractByIndex(0); @unlink($this->_filename->destination . $this->_filename->filename); $this->_filename = DIR_FS_CACHE . $file[0]['stored_filename']; } } else { $this->_filename = $this->_filename->destination . $this->_filename->filename; } switch ($this->_file_type) { case 'csv': return $this->parseCsvFile(); case 'xml': return $this->parseXmlFile(); } }
protected function execute() { $this->loadParams(); $archive = new PclZip($this->zipFile->getFileName()); $listContent = $archive->listContent(); $allFilesCount = count($listContent); $processedFiles = -self::UNZIP_STEP; while ($processedFiles < $allFilesCount) { $processedFiles += self::UNZIP_STEP; if ($this->isDone($processedFiles, $this->_('%s%% files unzipped', round($processedFiles / $allFilesCount * 100, 0)))) { continue; } $this->changePermissions($archive->extractByIndex($processedFiles . '-' . ($processedFiles + self::UNZIP_STEP - 1), $this->outputDirectory->getFileName())); $this->setDone($processedFiles); } }
} if ($my_uploader->upload_failed()) { array_push($inserterrors, $my_uploader->get_error()); } if (count($inserterrors) > 0) { error('admin.php?action=db&job=query', $inserterrors); } else { $ext = get_extension($file); if (($ext == 'zip' || $ext == 'sql') && file_exists($file)) { if ($ext == 'zip') { require_once 'classes/class.zip.php'; $archive = new PclZip($file); if (($list = $archive->listContent()) == 0) { error($archive->errorInfo(true)); } $data = $archive->extractByIndex($list[0]['index'], PCLZIP_OPT_EXTRACT_AS_STRING); $lines = $data[0]['content']; unset($data); } elseif ($ext == 'sql') { $lines = file_get_contents($file); } } } } else { $lines = $gpc->get('query', none); } $sql = str_replace('{:=DBPREFIX=:}', $db->pre, $lines); @exec_query_form($lines); $hl = highlight_sql_query($sql); if (!empty($lines)) { ob_start();
/** * @param $galleryId * @param $file * @param $user * @return bool|int */ function process_batch_image_upload($galleryId, $file, $user) { global $prefs; $numimages = 0; include_once 'vendor_extra/pclzip/pclzip.lib.php'; $archive = new PclZip($file); // Read Archive contents $ziplist = $archive->listContent(); if (!$ziplist) { return false; } // Archive invalid foreach ($ziplist as $zipfile) { $file = $zipfile["filename"]; if (!$zipfile["folder"]) { //copied $gal_info = $this->get_gallery($galleryId); $upl = 1; if (!empty($prefs['gal_match_regex'])) { if (!preg_match('/' . $prefs['gal_match_regex'] . '/', $file, $reqs)) { $upl = 0; } } if (!empty($prefs['gal_nmatch_regex'])) { if (preg_match('/' . $prefs['gal_nmatch_regex'] . '/', $file, $reqs)) { $upl = 0; } } //extract file $archive->extractByIndex($zipfile["index"], $prefs['tmpDir'], dirname($file)); //extract and remove (dangerous) pathname $file = basename($file); //unset variables unset($this->filetype); unset($this->xsize); unset($this->ysize); //determine filetype and dimensions $this->getfileinfo($prefs['tmpDir'] . "/" . $file); $foo = explode(".", $file); $exp = end($foo); // read image and delete it after $this->readimagefromfile($prefs['tmpDir'] . "/" . $file); unlink($prefs['tmpDir'] . "/" . $file); if ($this->issupported($exp)) { // convert to handle $this->readimagefromstring(); if ($this->validhandle()) { $this->getimageinfo(); } } //if there is no mimetype, we don't got a image if (isset($this->filetype)) { if (!isset($this->xsize)) { $this->xsize = $this->ysize = 0; } $imageId = $this->insert_image($galleryId, $file, '', $file, $this->filetype, $this->image, $this->filesize, $this->xsize, $this->ysize, $user, '', '', NULL, NULL, $gal_info); $numimages++; } } } return $numimages; }
function upload_zip($imagefile) { if (!mkdir($tmpdir = $this->config->pathto_cache . '/' . uniqid("ps"))) { $this->last_error = "Your cache directory is not writeable, please check the permissions."; return false; } $archive = $imagefile["tmp_name"]; if (!is_uploaded_file($archive)) { $this->last_error = "Could not upload file"; return false; } switch ($this->config->unzip_method) { case 'unzip': //decompress archive to temp $cmd = escapeshellcmd($this->config->pathto_unzip); $cmd .= ' -d "' . escapeshellcmd(realpath($tmpdir)); $cmd .= '" "' . escapeshellcmd(realpath($archive)) . '"'; if (!exec($cmd)) { $this->last_error = "Could not decompress archive"; return false; } break; case 'pclzip': /* This uses the PclZip Library to extract the files of the zip-archive */ $zip = new PclZip(realpath($archive)); $archiveContents = $zip->listContent(); foreach ($archiveContents as $file) { if (preg_match("/\\.(" . $this->config->recognised_extensions . ")\$/i", $file['filename'])) { //if(stristr($file['filename'],'/') === FALSE){ $imageIndex .= $file['index'] . ","; //} } } $imageIndex = substr($imageIndex, 0, strlen($imageIndex) - 1); $zip->extractByIndex($imageIndex, $tmpdir); break; } //start processing archive contents $wd = $tmpdir; $contents = $this->get_listing($wd, "images"); //cope with archives contained within a directory if (empty($contents->files) && count($contents->dirs) == 1) { $contents = $this->get_listing($wd .= '/' . $contents->dirs[0], "images"); } $success = true; //add any images to current gallery foreach ($contents->files as $image) { //make sure file has a recognised extension if (!preg_match("/\\.(" . $this->config->recognised_extensions . ")\$/i", $image)) { $image .= ".jpeg"; } $path = $this->config->pathto_galleries . $this->gallery->id . "/" . $image; $srcImage = $image; if (file_exists($path)) { switch ($this->config->upload_overwrite) { case 1: //overwrite $this->delete_image($image); break; case 2: //generate unique for ($i = 0; file_exists($path); $i++) { $pivot = strrpos($srcImage, "."); $image = substr($srcImage, 0, $pivot) . '-' . $i . substr($srcImage, $pivot, strlen($srcImage) - $pivot); $path = $this->config->pathto_galleries . $this->gallery->id . "/" . $image; } break; case 0: //raise error //raise error default: $this->last_error = "File already exists"; $success = false; continue; } } copy($wd . '/' . $srcImage, $path); @chmod($path, octdec($this->config->chmod_value)); $img = new image(); $img->filename = $image; $img->name = strtr(substr($image, strrpos($image, "/"), strrpos($image, ".") - strlen($image)), "_", " "); list($img->width, $img->height, $img->type) = GetImageSize($path); $this->gallery->images[count($this->gallery->images)] = $img; } //add any directories as subgalleries, if allowed foreach ($contents->dirs as $gallery) { if ($gallery != '__MACOSX') { $path = $this->config->pathto_galleries . $this->gallery->id . "/" . $gallery; if (file_exists($path)) { switch ($this->config->upload_overwrite) { case 1: //overwrite $this->delete_gallery($this->gallery->id . '/' . $gallery); break; case 2: //generate unique for ($i = 0; file_exists($path); $i++) { $path = $this->config->pathto_galleries . $this->gallery->id . "/" . $gallery . '-' . $i; } break; case 0: //raise error //raise error default: $success = false; continue; } } rename($wd . '/' . $gallery, $path); chmod($path, octdec($this->config->chmod_value)); } } //if images were added save metadata if (!empty($contents->files)) { $success &= $this->io->put_gallery($this->gallery); } //if subgalleries were added reload gallery data if (!empty($contents->dirs)) { $this->select_gallery(); } //remove temporary directory $this->rmdir_all($tmpdir); if (!$success) { $this->last_error = "Some archive contents could not be added"; } return $success; }
} if (!$error) { $db = @mysql_select_db($_GET['dbn']); } if (!$db) { $error = C_WRONG_DB . " (" . $_GET['dbn'] . ")"; } } // open the file if (!$error && !isset($firstSession)) { // gzopen can be used for plain text too! // extract zip file if (PMBP_file_info("comp", $_GET["fn"]) == "zip") { include_once "pclzip.lib.php"; $pclzip = new PclZip($_GET["fn"]); $extracted_file = $pclzip->extractByIndex(0, PMBP_EXPORT_DIR, ""); if ($pclzip->error_code != 0) { $error = "plczip: " . $pclzip->error_string . "<br>" . BI_BROKEN_ZIP . "!"; } $_GET["fn"] = substr($_GET["fn"], 0, strlen($_GET["fn"]) - 4); unset($pclzip); } if (!$error && !($file = @gzopen($_GET["fn"], "r"))) { $error = C_OPEN . " " . $_GET["fn"]; } } if (!$error) { // get start time to calculate duration if (function_exists("microtime")) { $microtime = explode(" ", microtime()); $starttime = $microtime[0] + $microtime[1];
function process_zip_pclzip($filename) { require_once dirname(__FILE__) . '/pclzip.lib.php'; $added = array(); $existing = $this->user->images; $zip = new PclZip($filename); if ($zip) { $list = $zip->listContent(); if ($list) { $temp_dir = $this->makeTempDir(); // for each entry foreach ($list as $entry) { if (!$entry['folder']) { // get the name $name = $entry['filename']; // if the name is jpg/gif/png if (preg_match('#([^/\\\\]+)\\.(jpg|gif|png)$#i', $name, $matches)) { $oname = $matches[1] . '.' . $matches[2]; $filesize = $entry['size']; if ($this->filesizeOK($filesize)) { $newname = $temp_dir . $oname; // extract the file to the temp name $result = $zip->extractByIndex($entry['index'], PCLZIP_OPT_PATH, $temp_dir, PCLZIP_OPT_REMOVE_ALL_PATH); if ($result) { /* debugging, hopefully no longer needed if( $this->app->config->debug_imagick ) { echo '<hr />Debug: Extracted file should be: ',$newname,"\n<pre>"; print_r($result); echo '</pre>',"\n"; echo (file_exists($newname) ? ' File Extracted ' : ' File not extracted '); } */ // add the image $iid = $this->images->addimage($oname, $this->user->user_id, $newname, $this->gallery, 0, $this->public); // delete the temp file unlink($newname); if (!$iid) { $this->errors = array_merge($this->errors, $this->images->errors); $this->images->errors = array(); } else { $added[] = $iid; $existing++; } } else { $this->errors[] = $this->app->translate('Unable to read from zip archive'); } } else { $this->errors[] = htmlspecialchars($name) . ': ' . $this->app->translate('file too large.'); } } elseif ($name[strlen($name) - 1] != '/') { $this->errors[] = htmlspecialchars($name) . ': ' . $this->app->translate('Unknown file format'); } } } // rmdir($temp_dir); } else { $this->errors[] = $this->app->translate('Unable to read from zip archive'); } } else { $this->errors[] = $this->app->translate('Unable to read from zip archive'); } return $added; }
/** * use the pclZip lib to list the contents of the file * * the following files can be acquired and used to trace errors if necessary * require_once( MAX_PATH . '/lib/pclzip/pclerror.lib.php' ); * require_once( MAX_PATH . '/lib/pclzip/pcltrace.lib.php' ); * require_once( MAX_PATH . '/lib/pclzip/pcltar.lib.php' ); * * * @param string $pkgFileUploaded * @param string $zipFile * @param boolean $overwrite * @return boolean */ function _checkPackageContents($pkgFileUploaded, $zipFile, $overwrite = false) { //OA::logMem('enter _checkPackageContents'); if (!file_exists($zipFile)) { $this->_logError('File not found ' . $zipFile); return false; } $this->_logMessage('starting _checkPackageContents ' . $pkgFileUploaded); $aExpectedPackage = $this->_parsePackageFilename($pkgFileUploaded); $pkgFile = $aExpectedPackage['name'] . '.xml'; $this->_logMessage('expecting definition ' . $pkgFile); require_once MAX_PATH . '/lib/pclzip/pclzip.lib.php'; $oZip = new PclZip($zipFile); $aContents = $oZip->listContent(); if (!$aContents) { $this->_logError('Failed to read contents of zip file ' . $zipFile); return false; } $aConf = $GLOBALS['_MAX']['CONF']; $pattPluginDefFile = '/' . preg_quote($aConf['pluginPaths']['packages'], '/') . '[\\w\\d]+\\.xml/'; $pattGroupDefFile = '/' . preg_quote($aConf['pluginPaths']['packages'], '/') . '[\\w\\d]+\\/[\\w\\d]+\\.xml/'; // find all of the xml definition files and compile a smiple array of files that are stored in the zipfile (exclude folders) foreach ($aContents as $i => &$aItem) { $aPath = pathinfo($aItem['filename']); $file = '/' . $aItem['filename']; if ($aItem['folder']) { continue; } if (!$aPkgFile && preg_match($pattPluginDefFile, $file, $aMatches)) { $this->_logMessage('detected plugin definition file ' . $file); $aPkgFile['pathinfo'] = $aPath; $aPkgFile['storedinfo'] = $aItem; $aFilesStored[] = $file; continue; } if (preg_match($pattGroupDefFile, $file, $aMatches)) { $this->_logMessage('detected group definition file ' . $file); $aXMLFiles[$aPath['basename']]['pathinfo'] = $aPath; $aXMLFiles[$aPath['basename']]['storedinfo'] = $aItem; $aFilesStored[] = $file; continue; } if (strpos($aPath['dirname'], '/etc/changes') == 0) { $aFilesStored[] = $file; continue; } } // must have a plugin package definition file if (!$aPkgFile) { $this->_logError('Plugin definition ' . $aExpectedPackage['name'] . '.xml not found in uploaded file: ' . $pkgFileUploaded); $this->errcode = OX_PLUGIN_ERROR_PACKAGE_DEFINITION_NOT_FOUND; return false; } // extract the plugin package definition file to var/tmp folder $aResult = $oZip->extractByIndex($aPkgFile['storedinfo']['index'], PCLZIP_OPT_ADD_PATH, $this->basePath . '/var/tmp', PCLZIP_OPT_SET_CHMOD, OX_PLUGIN_DIR_WRITE_MODE, PCLZIP_OPT_REPLACE_NEWER); if (!is_array($aResult) || $aResult[0]['status'] != 'ok') { $this->_logError('Error extracting plugin definition file: ' . $aResult[0]['status'] . ' : ' . $aResult[0]['stored_filename']); $this->errcode = OX_PLUGIN_ERROR_PACKAGE_EXTRACT_FAILED; return false; } // parse the plugin package definition file $pathPackages = '/var/tmp' . $this->pathPackages; if (!$this->_parsePackage($this->basePath . $pathPackages . $pkgFile)) { $this->_logError('Failed to parse the plugin definition ' . $pkgFile); $this->errcode = OX_PLUGIN_ERROR_PACKAGE_PARSE_FAILED; @unlink($this->basePath . $pathPackages . $pkgFile); return false; } $aPackage =& $this->aParse['package']; @unlink($this->basePath . $pathPackages . $pkgFile); // check that plugin is not already installed if (!$overwrite && array_key_exists($aPackage['name'], $GLOBALS['_MAX']['CONF']['plugins'])) { $this->_logError('Plugin with this name is already installed ' . $aPackage['name']); $this->errcode = OX_PLUGIN_ERROR_PACKAGE_NAME_EXISTS; return false; } // ensure the plugin package definition file has a valid version number if (empty($aPackage['version'])) { $this->_logError('Failed to retrieve version from the plugin definition ' . $pkgFile); $this->errcode = OX_PLUGIN_ERROR_PACKAGE_VERSION_NOT_FOUND; return false; } if ($aExpectedPackage['version'] && $aExpectedPackage['version'] != $aPackage['version']) { $this->_logError('Version found ' . $aPackage['version'] . ' is not that expected ' . $aExpectedPackage['version']); $this->errcode = OX_PLUGIN_ERROR_PACKAGE_VERSION_NOT_FOUND; return false; } // ensure that the number of declaration files that were found in the zip file // matches the number of declared component groups if (count($aPackage['install']['contents']) != count($aXMLFiles)) { $this->_logError('Expected ' . count($aPackage['install']['contents']) . ' definitions but found ' . count($aXMLFiles)); $this->errcode = OX_PLUGIN_ERROR_PLUGIN_DEFINITION_MISSING; return false; } // extract each of the component group definitions to var/tmp foreach ($aPackage['install']['contents'] as &$aItem) { if (!array_key_exists($aItem['name'] . '.xml', $aXMLFiles)) { $this->_logError('Group definition missing from plugin ' . $pkgFile . ' -> ' . $aItem['name'] . '.xml'); $this->errcode = OX_PLUGIN_ERROR_PACKAGE_CONTENTS_MISMATCH; return false; } $aResult = $oZip->extractByIndex($aXMLFiles[$aItem['name'] . '.xml']['storedinfo']['index'], PCLZIP_OPT_ADD_PATH, $this->basePath . '/var/tmp', PCLZIP_OPT_SET_CHMOD, OX_PLUGIN_DIR_WRITE_MODE, PCLZIP_OPT_REPLACE_NEWER); if (!is_array($aResult) || $aResult[0]['status'] != 'ok') { $this->_logError('Error extracting group definition file: ' . $aResult[0]['status'] . ' : ' . $aResult[0]['stored_filename']); $this->errcode = OX_PLUGIN_ERROR_PLUGIN_EXTRACT_FAILED; return false; } } // parse each of the component group definitions $pathPackagesOld = $this->pathPackages; $this->pathPackages = '/var/tmp' . $this->pathPackages; if (!$this->_parseComponentGroups($aPackage['install']['contents'])) { foreach ($aXMLFiles as $i => &$aFile) { @unlink($this->basePath . '/var/tmp/' . $aFile['storedinfo']['filename']); @rmdir(dirname($this->basePath . '/var/tmp/' . $aFile['storedinfo']['filename'])); } $this->pathPackages = $pathPackagesOld; $this->_logError('Failed to parse the component groups in package ' . $pkgFile); $this->errcode = OX_PLUGIN_ERROR_PLUGIN_PARSE_FAILED; return false; } foreach ($aXMLFiles as $i => &$aFile) { @unlink($this->basePath . '/var/tmp/' . $aFile['storedinfo']['filename']); @rmdir(dirname($this->basePath . '/var/tmp/' . $aFile['storedinfo']['filename'])); } $this->pathPackages = $pathPackagesOld; $aPlugins =& $this->aParse['plugins']; // the parser compiles and returns an array of files from the plugin declaration foreach ($aPackage['allfiles'] as $i => &$aFileExpected) { // expand the file declaration's path macro to get the path $fileExpected = $this->_expandFilePath($aFileExpected['path'], $aFileExpected['name'], $aPackage['name']); // files must have a valid path macro (see _expandFilePath()) else they are illegal, ie could be unzipped outside legal paths if ($fileExpected == $aFileExpected['path'] . $aFileExpected['name']) { $this->_logError('Illegal file location found :' . $fileExpected); $this->errcode = OX_PLUGIN_ERROR_ILLEGAL_FILE; return false; } $aFilesExpected[] = $fileExpected; } foreach ($aPlugins as $idx => &$aPlugin) { // check that group is not already installed if (!$overwrite && array_key_exists($aPlugin['name'], $GLOBALS['_MAX']['CONF']['pluginGroupComponents'])) { $this->_logError('Component group with this name is already installed ' . $aPlugin['name']); $this->errcode = OX_PLUGIN_ERROR_PLUGIN_NAME_EXISTS; return false; } // the parser compiles and returns an array of files from the group declaration foreach ($aPlugin['allfiles'] as $i => &$aFileExpected) { // expand the file declaration's path macro to get the path $fileExpected = $this->_expandFilePath($aFileExpected['path'], $aFileExpected['name'], $aPlugin['name']); // files must have a valid path macro (see _expandFilePath()) else they are illegal, ie could be unzipped outside legal paths if ($fileExpected == $aFileExpected['path'] . $aFileExpected['name']) { $this->_logError('Illegal file location found :' . $fileExpected); $this->errcode = OX_PLUGIN_ERROR_ILLEGAL_FILE; return false; } $aFilesExpected[] = $fileExpected; } } // are any declared files missing from the zip? $aDiffsExpected = array_diff($aFilesExpected, $aFilesStored); if (count($aDiffsExpected)) { $this->_logError(count($aDiffsExpected) . ' expected files not found'); foreach ($aDiffsExpected as &$file) { $this->_logError($file); } $this->errcode = OX_PLUGIN_ERROR_PLUGIN_DECLARATION_MISMATCH; return false; } // are there any files in the zip that are not declared in the definitions? $aDiffStored = array_diff($aFilesStored, $aFilesExpected); if (count($aDiffStored) > 0) { $this->_logError(count($aDiffStored) . ' unexpected files found'); foreach ($aDiffStored as &$file) { $this->_logError($file); } $this->errcode = OX_PLUGIN_ERROR_FILE_COUNT_MISMATCH; return false; } // package is good, return the parsed definitions $this->errcode = OX_PLUGIN_ERROR_PACKAGE_OK; //OA::logMem('exit _checkPackageContents'); //return array('package'=>$aPackage, 'plugins'=>$aPlugins); return true; }
if (!$listFiles[$i]['folder'] and trim($listFiles[$i]['filename']) == 'config.ini') { $iniIndex = $i; break; } } // Loi khong co file cau hinh if ($iniIndex == -1) { $error = $lang_module['autoinstall_error_missing_cfg']; } else { // Giai nen file config de doc thong tin $temp_extract_dir = NV_TEMP_DIR; // Xoa file config neu ton tai if (file_exists(NV_ROOTDIR . '/' . $temp_extract_dir . '/config.ini')) { @nv_deletefile(NV_ROOTDIR . '/' . $temp_extract_dir . '/config.ini'); } $extract = $zip->extractByIndex($iniIndex, PCLZIP_OPT_PATH, NV_ROOTDIR . '/' . $temp_extract_dir); if (empty($extract) or !isset($extract[0]['status']) or $extract[0]['status'] != 'ok' or !file_exists(NV_ROOTDIR . '/' . $temp_extract_dir . '/config.ini')) { $error = $lang_module['autoinstall_cantunzip']; } else { // Doc, kiem tra thong tin file config.ini $extConfig = nv_parse_ini_file(NV_ROOTDIR . '/' . $temp_extract_dir . '/config.ini', true); $extConfigCheck = nv_check_ext_config_filecontent($extConfig); if (!$extConfigCheck) { $error = $lang_module['autoinstall_error_cfg_content']; } elseif (!in_array($extConfig['extension']['type'], $arraySysOption['allowExtType'])) { $error = $lang_module['autoinstall_error_cfg_type']; } elseif (!preg_match($global_config['check_version'], $extConfig['extension']['version'])) { $error = $lang_module['autoinstall_error_cfg_version']; } elseif (is_array($arraySysOption['checkName'][$extConfig['extension']['type']])) { foreach ($arraySysOption['checkName'][$extConfig['extension']['type']] as $check) { if (!preg_match($check, $extConfig['extension']['name'])) {
function spip_deballe_paquet($paquet, $fichier, $dest, $range) { global $chmod; // le repertoire temporaire est invariant pour permettre la reprise @mkdir($tmp = _DIR_BASE.'zip_'.md5($fichier), $chmod); $ok = is_dir($tmp); $zip = new PclZip($fichier); $content = $zip->listContent(); $max_index = count($content); $start_index = isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0; if ($start_index < $max_index) { if (!$range) { $range = _PCL_ZIP_RANGE; } $end_index = min($start_index + $range, $max_index); $ok &= $zip->extractByIndex( "$start_index-$end_index", PCLZIP_OPT_PATH, $tmp, PCLZIP_OPT_SET_CHMOD, $chmod, PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_REMOVE_PATH, _REMOVE_PATH_ZIP."/", PCLZIP_CB_POST_EXTRACT, 'touchCallBack' ); } if (!$ok or $zip->error_code < 0) { debut_html(); echo _TT('tradloader:donnees_incorrectes', array('erreur' => $zip->errorInfo())); fin_html(); } else { // si l'extraction n'est pas finie, relancer if ($start_index < $max_index) { $url = _DIR_BASE._SPIP_LOADER_SCRIPT . (strpos(_SPIP_LOADER_SCRIPT, '?') ? '&' : '?') . "etape=fichier&chemin=$paquet&dest=$dest&start=$end_index"; $progres = $start_index/$max_index; spip_redirige_boucle($url, $progres); } if ($dest) { @mkdir(_DIR_PLUGINS, $chmod); $dir = _DIR_PLUGINS . $dest; $url = _DIR_BASE._SPIP_LOADER_PLUGIN_RETOUR; } else { $dir = _DIR_BASE; $url = _DIR_BASE._SPIP_LOADER_URL_RETOUR; } move_all($tmp, $dir); rmdir($tmp); nettoyer_racine($fichier); header("Location: $url"); } }
function unzipConversionResults($sourceZipPath, $previewDirectory) { chmod($previewDirectory, 0700); $destinationZipPath = $previewDirectory . DIRECTORY_SEPARATOR . basename($sourceZipPath); $this->destinationZip = $destinationZipPath; if (!moveFile($sourceZipPath, $destinationZipPath)) { webServiceError('&error-webpage-unable-to-move;', 500, array('source' => $sourceZipPath, 'destination' => $destinationZipPath)); } chmod($destinationZipPath, 0666); include_once dirname(__FILE__) . '/lib/pclzip-2-6/pclzip.lib.php'; $archive = new PclZip($destinationZipPath); if (($archivedFiles = $archive->listContent()) == 0) { webServiceError('&error-webpage-unzipping-files;', 500, array('errorMessage' => $archive->errorInfo(true))); } foreach ($archivedFiles as $archivedFile) { $extractedFileMetaData = $archive->extractByIndex($archivedFile['index'], PCLZIP_OPT_PATH, $previewDirectory); $extractedFileMetaData = $extractedFileMetaData[0]; $extractedDestinationPath = substr($extractedFileMetaData['filename'], 2); if (file_exists($extractedDestinationPath) && !chmod($extractedDestinationPath, 0700)) { webServiceError('&error-webpage-unzipping-files;', 500, array('errorMessage' => $extractedDestinationPath)); } } return $this->destinationZip; }
/** * gets the useful stuff from an Oasis OpenDocument archive */ function extractUsefulOasisOpenDocumentFiles($oasisOpenDocumentPath) { if (!trim($oasisOpenDocumentPath)) { webServiceError('&error-oasis-path;'); } ini_set('include_path', ini_get('include_path') . ':' . DOCVERT_DIR . 'core/lib/pclzip-2-6:'); include_once dirname(__FILE__) . '/lib/pclzip-2-6/pclzip.lib.php'; $unknownImageIndex = 1; $documentDirectory = dirname($oasisOpenDocumentPath) . DIRECTORY_SEPARATOR; $archive = new PclZip($oasisOpenDocumentPath); $odfObjects = array(); if (($archivedFiles = $archive->listContent()) == 0) { webServiceError('&error-unzipping-archive; ' . revealXml($archive->errorInfo(true))); } foreach ($archivedFiles as $archivedFile) { if (isAnOasisOpenDocumentFileWeWant($archivedFile['filename'])) { $archive->extractByIndex($archivedFile['index'], PCLZIP_OPT_PATH, $documentDirectory, PCLZIP_OPT_REMOVE_ALL_PATH); //print basename($archivedFile['filename']).'<br />'; if (stringEndsWith($archivedFile['filename'], 'xml') || basename($archivedFile['filename']) == 'thumbnail.png') { $oldPath = $documentDirectory . basename($archivedFile['filename']); $newPath = $documentDirectory . 'docvert-' . basename($archivedFile['filename']); if (!file_exists($oldPath)) { webServiceError('&error-source-path-does-not-exist; "' . revealXml($oldPath) . '"'); } rename($oldPath, $newPath); if (!file_exists(dirname($newPath))) { webServiceError('&error-destination-directory-not-found;"' . revealXml(dirname($newPath)) . '"'); } if (!file_exists($newPath)) { webServiceError('&error-destination-path-not-exist; "' . revealXml($newPath) . '"'); } } elseif (stringStartsWith(strtolower($archivedFile['filename']), 'objectreplacements')) { $oldPath = $documentDirectory . basename($archivedFile['filename']); if (!function_exists('getimagesize')) { $template = '<div class="error"><p>&error-openoffice-objects;</p></div>'; $template = preg_replace_callback('/\\&(.*?)\\;/s', 'replaceLanguagePlaceholder', $template); $testResultsPath = $documentDirectory . 'test.html'; file_put_contents($testResultsPath, $template, FILE_APPEND); } else { $fileExtension = 'wmf'; $imageMetadata = null; $imageSize = getimagesize($oldPath, $imageMetadata); /* * getimagesize returns a number which means a file format * 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, * 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), * 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, * 15 = WBMP, 16 = XBM */ $imageTypes = array("GIF", "JPG", "PNG", "SWF", "PSD", "BMP", "TIFF", "TIFF", "JPC", "JP2", "JPX", "JB2", "SWC", "IFF", "WBMP", "XBM"); if (count($imageMetadata) > 0) { if (trim($imageMetadata[1]) != null && trim($imageMetadata[1]) != "" && $imageMetadata[1] < count($imageTypes)) { $imageTypeIndex = $imageMetadata[1] - 1; $fileExtension = strtolower($imageTypes[$imageTypeIndex]); //die('File extension: "'.$fileExtension.':'.$imageTypes[$imageTypeIndex].'" ['.$imageMetadata[1].']'); } } else { } $newPath = $documentDirectory . 'image' . $unknownImageIndex . '.' . $fileExtension; $unknownImageIndex++; $odfObjects[] = array($archivedFile['filename'], basename($newPath), $fileExtension); } } } } $contentXmlPath = $documentDirectory . 'docvert-content.xml'; if (!file_exists($contentXmlPath)) { webServiceError('&error-no-content-xml-file-found;'); } if (count($odfObjects) >= 1) { // Rename image paths $contentXml = file_get_contents($contentXmlPath); foreach ($odfObjects as $odfObject) { $contentXml = str_replace('./' . $odfObject[0] . '"', $odfObject[1] . '" type="' . $odfObject[2] . '"', $contentXml); $contentXml = str_replace($odfObject[0] . '"', $odfObject[1] . '" type="' . $odfObject[2] . '"', $contentXml); } //displayXmlString($contentXml); file_put_contents($contentXmlPath, $contentXml); } }