Ejemplo n.º 1
0
 /**
  * Extract an archive directly inside the dest directory.
  *
  * @param string $destDir
  * @param UserSelection $selection
  * @param array $error
  * @param array $success
  */
 public function extractArchive($destDir, $selection, &$error, &$success)
 {
     require_once AJXP_BIN_FOLDER . "/pclzip.lib.php";
     $zipPath = $selection->getZipPath(true);
     $zipLocalPath = $selection->getZipLocalPath(true);
     if (strlen($zipLocalPath) > 1 && $zipLocalPath[0] == "/") {
         $zipLocalPath = substr($zipLocalPath, 1) . "/";
     }
     $files = $selection->getFiles();
     $realZipFile = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $this->urlBase . $zipPath);
     $archive = new PclZip($realZipFile);
     $content = $archive->listContent();
     foreach ($files as $key => $item) {
         // Remove path
         $item = substr($item, strlen($zipPath));
         if ($item[0] == "/") {
             $item = substr($item, 1);
         }
         foreach ($content as $zipItem) {
             if ($zipItem["stored_filename"] == $item || $zipItem["stored_filename"] == $item . "/") {
                 $files[$key] = $zipItem["stored_filename"];
                 break;
             } else {
                 unset($files[$key]);
             }
         }
     }
     $this->logDebug("Archive", $this->addSlugToPath($files));
     $realDestination = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $this->urlBase . $destDir);
     $this->logDebug("Extract", array($realDestination, $realZipFile, $this->addSlugToPath($files), $zipLocalPath));
     self::$currentZipOperationHandler =& $this;
     $result = $archive->extract(PCLZIP_OPT_BY_NAME, $files, PCLZIP_OPT_PATH, $realDestination, PCLZIP_OPT_REMOVE_PATH, $zipLocalPath, PCLZIP_CB_PRE_EXTRACT, "staticExtractArchiveItemPreCallback", PCLZIP_CB_POST_EXTRACT, "staticExtractArchiveItemPostCallback", PCLZIP_OPT_STOP_ON_ERROR);
     self::$currentZipOperationHandler = null;
     if ($result <= 0) {
         $error[] = $archive->errorInfo(true);
     } else {
         $mess = ConfService::getMessages();
         $success[] = sprintf($mess[368], basename($zipPath), $destDir);
     }
 }
 /**
  * Extract an archive directly inside the dest directory.
  *
  * @param string $destDir
  * @param UserSelection $selection
  * @param array $error
  * @param array $success
  */
 function extractArchive($destDir, $selection, &$error, &$success)
 {
     require_once "server/classes/pclzip.lib.php";
     $zipPath = $selection->getZipPath(true);
     $zipLocalPath = $selection->getZipLocalPath(true);
     if (strlen($zipLocalPath) > 1 && $zipLocalPath[0] == "/") {
         $zipLocalPath = substr($zipLocalPath, 1) . "/";
     }
     $files = $selection->getFiles();
     $realZipFile = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $this->urlBase . $zipPath);
     $archive = new PclZip($realZipFile);
     $content = $archive->listContent();
     foreach ($files as $key => $item) {
         // Remove path
         $item = substr($item, strlen($zipPath));
         if ($item[0] == "/") {
             $item = substr($item, 1);
         }
         foreach ($content as $zipItem) {
             if ($zipItem["stored_filename"] == $item || $zipItem["stored_filename"] == $item . "/") {
                 $files[$key] = $zipItem["stored_filename"];
                 break;
             } else {
                 unset($files[$key]);
             }
         }
     }
     AJXP_Logger::debug("Archive", $files);
     $realDestination = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $this->urlBase . $destDir);
     AJXP_Logger::debug("Extract", array($realDestination, $realZipFile, $files, $zipLocalPath));
     $result = $archive->extract(PCLZIP_OPT_BY_NAME, $files, PCLZIP_OPT_PATH, $realDestination, PCLZIP_OPT_REMOVE_PATH, $zipLocalPath);
     if ($result <= 0) {
         $error[] = $archive->errorInfo(true);
     } else {
         $mess = ConfService::getMessages();
         $success[] = sprintf($mess[368], basename($zipPath), $destDir);
     }
 }