You are here

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

File

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

Class

PclZip

Code

function privFileDescrExpand(&$p_filedescr_list, &$p_options) {
  $v_result = 1;

  // ----- Create a result list
  $v_result_list = array();

  // ----- Look each entry
  for ($i = 0; $i < sizeof($p_filedescr_list); $i++) {

    // ----- Get filedescr
    $v_descr = $p_filedescr_list[$i];

    // ----- Reduce the filename
    $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
    $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);

    // ----- Look for real file or folder
    if (file_exists($v_descr['filename'])) {
      if (@is_file($v_descr['filename'])) {
        $v_descr['type'] = 'file';
      }
      else {
        if (@is_dir($v_descr['filename'])) {
          $v_descr['type'] = 'folder';
        }
        else {
          if (@is_link($v_descr['filename'])) {

            // skip
            continue;
          }
          else {

            // skip
            continue;
          }
        }
      }
    }
    else {
      if (isset($v_descr['content'])) {
        $v_descr['type'] = 'virtual_file';
      }
      else {

        // ----- Error log
        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '" . $v_descr['filename'] . "' does not exist");

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

    // ----- Calculate the stored filename
    $this
      ->privCalculateStoredFilename($v_descr, $p_options);

    // ----- Add the descriptor in result list
    $v_result_list[sizeof($v_result_list)] = $v_descr;

    // ----- Look for folder
    if ($v_descr['type'] == 'folder') {

      // ----- List of items in folder
      $v_dirlist_descr = array();
      $v_dirlist_nb = 0;
      if ($v_folder_handler = @opendir($v_descr['filename'])) {
        while (($v_item_handler = @readdir($v_folder_handler)) !== false) {

          // ----- Skip '.' and '..'
          if ($v_item_handler == '.' || $v_item_handler == '..') {
            continue;
          }

          // ----- Compose the full filename
          $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'] . '/' . $v_item_handler;

          // ----- Look for different stored filename
          // Because the name of the folder was changed, the name of the
          // files/sub-folders also change
          if ($v_descr['stored_filename'] != $v_descr['filename'] && !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
            if ($v_descr['stored_filename'] != '') {
              $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'] . '/' . $v_item_handler;
            }
            else {
              $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
            }
          }
          $v_dirlist_nb++;
        }
        @closedir($v_folder_handler);
      }
      else {

        // TBC : unable to open folder in read mode
      }

      // ----- Expand each element of the list
      if ($v_dirlist_nb != 0) {

        // ----- Expand
        if (($v_result = $this
          ->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
          return $v_result;
        }

        // ----- Concat the resulting list
        $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
      }
      else {
      }

      // ----- Free local array
      unset($v_dirlist_descr);
    }
  }

  // ----- Get the result list
  $p_filedescr_list = $v_result_list;

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