You are here

function PclZip::privExtractFileAsString in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php \PclZip::privExtractFileAsString()
1 call to PclZip::privExtractFileAsString()
PclZip::privExtractByRule in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php, line 4154

Class

PclZip

Code

function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) {
  $v_result = 1;

  // ----- Read the file header
  $v_header = array();
  if (($v_result = $this
    ->privReadFileHeader($v_header)) != 1) {

    // ----- Return
    return $v_result;
  }

  // ----- Check that the file header is coherent with $p_entry info
  if ($this
    ->privCheckFileHeaders($v_header, $p_entry) != 1) {

    // TBC
  }

  // ----- Look for pre-extract callback
  if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {

    // ----- Generate a local information
    $v_local_header = array();
    $this
      ->privConvertHeader2FileInfo($p_entry, $v_local_header);

    // ----- Call the callback
    // Here I do not use call_user_func() because I need to send a reference to the
    // header.
    //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
    $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
    if ($v_result == 0) {

      // ----- Change the file status
      $p_entry['status'] = "skipped";
      $v_result = 1;
    }

    // ----- Look for abort result
    if ($v_result == 2) {

      // ----- This status is internal and will be changed in 'skipped'
      $p_entry['status'] = "aborted";
      $v_result = PCLZIP_ERR_USER_ABORTED;
    }

    // ----- Update the informations
    // Only some fields can be modified
    $p_entry['filename'] = $v_local_header['filename'];
  }

  // ----- Look if extraction should be done
  if ($p_entry['status'] == 'ok') {

    // ----- Do the extraction (if not a folder)
    if (!(($p_entry['external'] & 0x10) == 0x10)) {

      // ----- Look for not compressed file
      //      if ($p_entry['compressed_size'] == $p_entry['size'])
      if ($p_entry['compression'] == 0) {

        // ----- Reading the file
        $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
      }
      else {

        // ----- Reading the file
        $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);

        // ----- Decompress the file
        if (($p_string = @gzinflate($v_data)) === FALSE) {

          // TBC
        }
      }

      // ----- Trace
    }
    else {

      // TBC : error : can not extract a folder in a string
    }
  }

  // ----- Change abort status
  if ($p_entry['status'] == "aborted") {
    $p_entry['status'] = "skipped";
  }
  elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {

    // ----- Generate a local information
    $v_local_header = array();
    $this
      ->privConvertHeader2FileInfo($p_entry, $v_local_header);

    // ----- Swap the content to header
    $v_local_header['content'] = $p_string;
    $p_string = '';

    // ----- Call the callback
    // Here I do not use call_user_func() because I need to send a reference to the
    // header.
    //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
    $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);

    // ----- Swap back the content to header
    $p_string = $v_local_header['content'];
    unset($v_local_header['content']);

    // ----- Look for abort result
    if ($v_result == 2) {
      $v_result = PCLZIP_ERR_USER_ABORTED;
    }
  }

  // ----- Return
  return $v_result;
}