You are here

function PclZip::privCalculateStoredFilename 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::privCalculateStoredFilename()
1 call to PclZip::privCalculateStoredFilename()
PclZip::privFileDescrExpand in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php

File

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

Class

PclZip

Code

function privCalculateStoredFilename(&$p_filedescr, &$p_options) {
  $v_result = 1;

  // ----- Working variables
  $p_filename = $p_filedescr['filename'];
  if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
    $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
  }
  else {
    $p_add_dir = '';
  }
  if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
    $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
  }
  else {
    $p_remove_dir = '';
  }
  if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
    $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  }
  else {
    $p_remove_all_dir = 0;
  }

  // ----- Look for full name change
  if (isset($p_filedescr['new_full_name'])) {

    // ----- Remove drive letter if any
    $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
  }
  else {

    // ----- Look for short name change
    // Its when we cahnge just the filename but not the path
    if (isset($p_filedescr['new_short_name'])) {
      $v_path_info = pathinfo($p_filename);
      $v_dir = '';
      if ($v_path_info['dirname'] != '') {
        $v_dir = $v_path_info['dirname'] . '/';
      }
      $v_stored_filename = $v_dir . $p_filedescr['new_short_name'];
    }
    else {

      // ----- Calculate the stored filename
      $v_stored_filename = $p_filename;
    }

    // ----- Look for all path to remove
    if ($p_remove_all_dir) {
      $v_stored_filename = basename($p_filename);
    }
    else {
      if ($p_remove_dir != "") {
        if (substr($p_remove_dir, -1) != '/') {
          $p_remove_dir .= "/";
        }
        if (substr($p_filename, 0, 2) == "./" || substr($p_remove_dir, 0, 2) == "./") {
          if (substr($p_filename, 0, 2) == "./" && substr($p_remove_dir, 0, 2) != "./") {
            $p_remove_dir = "./" . $p_remove_dir;
          }
          if (substr($p_filename, 0, 2) != "./" && substr($p_remove_dir, 0, 2) == "./") {
            $p_remove_dir = substr($p_remove_dir, 2);
          }
        }
        $v_compare = PclZipUtilPathInclusion($p_remove_dir, $v_stored_filename);
        if ($v_compare > 0) {
          if ($v_compare == 2) {
            $v_stored_filename = "";
          }
          else {
            $v_stored_filename = substr($v_stored_filename, strlen($p_remove_dir));
          }
        }
      }
    }

    // ----- Remove drive letter if any
    $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);

    // ----- Look for path to add
    if ($p_add_dir != "") {
      if (substr($p_add_dir, -1) == "/") {
        $v_stored_filename = $p_add_dir . $v_stored_filename;
      }
      else {
        $v_stored_filename = $p_add_dir . "/" . $v_stored_filename;
      }
    }
  }

  // ----- Filename (reduce the path of stored name)
  $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
  $p_filedescr['stored_filename'] = $v_stored_filename;

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