PclZipUtilPathReduction

The WordPress Core PclZipUtilPathReduction function.

Description

PclZipUtilPathReduction( $p_dir ); 

Parameters (1)

0. $p_dir
The dir.

Usage

  1. if ( !function_exists( 'PclZipUtilPathReduction' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/class-pclzip.php'; 
  3.  
  4. // The dir. 
  5. $p_dir = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = PclZipUtilPathReduction($p_dir); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/class-pclzip.php  
  1. function PclZipUtilPathReduction($p_dir) 
  2. $v_result = ""; 
  3.  
  4. // ----- Look for not empty path 
  5. if ($p_dir != "") { 
  6. // ----- Explode path by directory names 
  7. $v_list = explode("/", $p_dir); 
  8.  
  9. // ----- Study directories from last to first 
  10. $v_skip = 0; 
  11. for ($i=sizeof($v_list)-1; $i>=0; $i--) { 
  12. // ----- Look for current path 
  13. if ($v_list[$i] == ".") { 
  14. // ----- Ignore this directory 
  15. // Should be the first $i=0, but no check is done 
  16. else if ($v_list[$i] == "..") { 
  17. $v_skip++; 
  18. else if ($v_list[$i] == "") { 
  19. // ----- First '/' i.e. root slash 
  20. if ($i == 0) { 
  21. $v_result = "/".$v_result; 
  22. if ($v_skip > 0) { 
  23. // ----- It is an invalid path, so the path is not modified 
  24. // TBC 
  25. $v_result = $p_dir; 
  26. $v_skip = 0; 
  27. // ----- Last '/' i.e. indicates a directory 
  28. else if ($i == (sizeof($v_list)-1)) { 
  29. $v_result = $v_list[$i]; 
  30. // ----- Double '/' inside the path 
  31. else { 
  32. // ----- Ignore only the double '//' in path,  
  33. // but not the first and last '/' 
  34. else { 
  35. // ----- Look for item to skip 
  36. if ($v_skip > 0) { 
  37. $v_skip--; 
  38. else { 
  39. $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); 
  40.  
  41. // ----- Look for skip 
  42. if ($v_skip > 0) { 
  43. while ($v_skip > 0) { 
  44. $v_result = '../'.$v_result; 
  45. $v_skip--; 
  46.  
  47. // ----- Return 
  48. return $v_result;