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

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: