PclZipUtilTranslateWinPath

Definition:
function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)

Parameters

  • $p_path
  • $p_remove_disk_letter

Source code

  function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)

  {

    if (stristr(php_uname(), 'windows')) {

      // ----- Look for potential disk letter

      if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {

          $p_path = substr($p_path, $v_position+1);

      }

      // ----- Change potential windows directory separator

      if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {

          $p_path = strtr($p_path, '\\', '/');

      }

    }

    return $p_path;

  }

2499

PclZipUtilRename

Definition:
function PclZipUtilRename($p_src, $p_dest)

Parameters

  • $p_src
  • $p_dest

Source code

  function PclZipUtilRename($p_src, $p_dest)

  {

    $v_result = 1;



    // ----- Try to rename the files

    if (!@rename($p_src, $p_dest)) {



      // ----- Try to copy & unlink the src

      if (!@copy($p_src, $p_dest)) {

        $v_result = 0;

      }

      else if (!@unlink($p_src)) {

        $v_result = 0;

      }

    }



    // ----- Return

    return $v_result;

  }

2497

PclZipUtilPathReduction

Definition:
function PclZipUtilPathReduction($p_dir)

Parameters

  • $p_dir

Source code

  function PclZipUtilPathReduction($p_dir)

  {

    $v_result = "";



    // ----- Look for not empty path

    if ($p_dir != "") {

      // ----- Explode path by directory names

      $v_list = explode("/", $p_dir);



      // ----- Study directories from last to first

      $v_skip = 0;

      for ($i=sizeof($v_list)-1; $i>=0; $i--) {

        // ----- Look for current path

        if ($v_list[$i] == ".") {

          // ----- Ignore this directory

          // Should be the first $i=0, but no check is done

        }

        else if ($v_list[$i] == "..") {

		  $v_skip++;

        }

        else if ($v_list[$i] == "") {

		  // ----- First '/' i.e. root slash

		  if ($i == 0) {

            $v_result = "/".$v_result;

		    if ($v_skip > 0) {

		        // ----- It is an invalid path, so the path is not modified

		        // TBC

		        $v_result = $p_dir;

                $v_skip = 0;

		    }

		  }

		  // ----- Last '/' i.e. indicates a directory

		  else if ($i == (sizeof($v_list)-1)) {

            $v_result = $v_list[$i];

		  }

		  // ----- Double '/' inside the path

		  else {

            // ----- Ignore only the double '//' in path,

            // but not the first and last '/'

		  }

        }

        else {

		  // ----- Look for item to skip

		  if ($v_skip > 0) {

		    $v_skip--;

		  }

		  else {

            $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");

		  }

        }

      }



      // ----- Look for skip

      if ($v_skip > 0) {

        while ($v_skip > 0) {

            $v_result = '../'.$v_result;

            $v_skip--;

        }

      }

    }



    // ----- Return

    return $v_result;

  }

2495

PclZipUtilPathInclusion

Definition:
function PclZipUtilPathInclusion($p_dir, $p_path)

Parameters

  • $p_dir
  • $p_path

Source code

  function PclZipUtilPathInclusion($p_dir, $p_path)

  {

    $v_result = 1;



    // ----- Look for path beginning by ./

    if (   ($p_dir == '.')

        || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {

      $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);

    }

    if (   ($p_path == '.')

        || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {

      $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);

    }



    // ----- Explode dir and path by directory separator

    $v_list_dir = explode("/", $p_dir);

    $v_list_dir_size = sizeof($v_list_dir);

    $v_list_path = explode("/", $p_path);

    $v_list_path_size = sizeof($v_list_path);



    // ----- Study directories paths

    $i = 0;

    $j = 0;

    while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {



      // ----- Look for empty dir (path reduction)

      if ($v_list_dir[$i] == '') {

        $i++;

        continue;

      }

      if ($v_list_path[$j] == '') {

        $j++;

        continue;

      }



      // ----- Compare the items

      if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != ''))  {

        $v_result = 0;

      }



      // ----- Next items

      $i++;

      $j++;

    }



    // ----- Look if everything seems to be the same

    if ($v_result) {

      // ----- Skip all the empty items

      while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;

      while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;



      if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {

        // ----- There are exactly the same

        $v_result = 2;

      }

      else if ($i < $v_list_dir_size) {

        // ----- The path is shorter than the dir

        $v_result = 0;

      }

    }



    // ----- Return

    return $v_result;

  }

2493

PclZipUtilOptionText

Definition:
function PclZipUtilOptionText($p_option)

Parameters

  • $p_option

Source code

  function PclZipUtilOptionText($p_option)

  {



    $v_list = get_defined_constants();

    for (reset($v_list); $v_key = key($v_list); next($v_list)) {

	    $v_prefix = substr($v_key, 0, 10);

	    if ((   ($v_prefix == 'PCLZIP_OPT')

           || ($v_prefix == 'PCLZIP_CB_')

           || ($v_prefix == 'PCLZIP_ATT'))

	        && ($v_list[$v_key] == $p_option)) {

        return $v_key;

	    }

    }



    $v_result = 'Unknown';



    return $v_result;

  }

2491