You are here

function PclZip::privReadCentralFileHeader in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php \PclZip::privReadCentralFileHeader()
3 calls to PclZip::privReadCentralFileHeader()
PclZip::privDeleteByRule in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
PclZip::privExtractByRule in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
PclZip::privList in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php

File

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

Class

PclZip

Code

function privReadCentralFileHeader(&$p_header) {
  $v_result = 1;

  // ----- Read the 4 bytes signature
  $v_binary_data = @fread($this->zip_fd, 4);
  $v_data = unpack('Vid', $v_binary_data);

  // ----- Check signature
  if ($v_data['id'] != 0x2014b50) {

    // ----- Error log
    PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');

    // ----- Return
    return PclZip::errorCode();
  }

  // ----- Read the first 42 bytes of the header
  $v_binary_data = fread($this->zip_fd, 42);

  // ----- Look for invalid block size
  if (strlen($v_binary_data) != 42) {
    $p_header['filename'] = "";
    $p_header['status'] = "invalid_header";

    // ----- Error log
    PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : " . strlen($v_binary_data));

    // ----- Return
    return PclZip::errorCode();
  }

  // ----- Extract the values
  $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);

  // ----- Get filename
  if ($p_header['filename_len'] != 0) {
    $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
  }
  else {
    $p_header['filename'] = '';
  }

  // ----- Get extra
  if ($p_header['extra_len'] != 0) {
    $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
  }
  else {
    $p_header['extra'] = '';
  }

  // ----- Get comment
  if ($p_header['comment_len'] != 0) {
    $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
  }
  else {
    $p_header['comment'] = '';
  }

  // ----- Extract properties
  // ----- Recuperate date in UNIX format

  //if ($p_header['mdate'] && $p_header['mtime'])

  // TBC : bug : this was ignoring time with 0/0/0
  if (1) {

    // ----- Extract time
    $v_hour = ($p_header['mtime'] & 0xf800) >> 11;
    $v_minute = ($p_header['mtime'] & 0x7e0) >> 5;
    $v_seconde = ($p_header['mtime'] & 0x1f) * 2;

    // ----- Extract date
    $v_year = (($p_header['mdate'] & 0xfe00) >> 9) + 1980;
    $v_month = ($p_header['mdate'] & 0x1e0) >> 5;
    $v_day = $p_header['mdate'] & 0x1f;

    // ----- Get UNIX date format
    $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
  }
  else {
    $p_header['mtime'] = time();
  }

  // ----- Set the stored filename
  $p_header['stored_filename'] = $p_header['filename'];

  // ----- Set default status to ok
  $p_header['status'] = 'ok';

  // ----- Look if it is a directory
  if (substr($p_header['filename'], -1) == '/') {

    //$p_header['external'] = 0x41FF0010;
    $p_header['external'] = 0x10;
  }

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