You are here

function PclZip::extract in Quiz 6.6

Same name and namespace in other branches
  1. 6.5 includes/moodle/lib/pclzip/pclzip.lib.php \PclZip::extract()

File

includes/moodle/lib/pclzip/pclzip.lib.php, line 682

Class

PclZip

Code

function extract() {

  //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");
  $v_result = 1;

  // ----- Reset the error handler
  $this
    ->privErrorReset();

  // ----- Check archive
  if (!$this
    ->privCheckFormat()) {

    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
    return 0;
  }

  // ----- Set default values
  $v_options = array();

  //    $v_path = "./";
  $v_path = '';
  $v_remove_path = "";
  $v_remove_all_path = false;

  // ----- Look for variable options arguments
  $v_size = func_num_args();

  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");

  // ----- Default values for option
  $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;

  // ----- Look for arguments
  if ($v_size > 0) {

    // ----- Get the arguments
    $v_arg_list = func_get_args();

    // ----- Look for first arg
    if (is_integer($v_arg_list[0]) && $v_arg_list[0] > 77000) {

      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");

      // ----- Parse the options
      $v_result = $this
        ->privParseOptions($v_arg_list, $v_size, $v_options, array(
        PCLZIP_OPT_PATH => 'optional',
        PCLZIP_OPT_REMOVE_PATH => 'optional',
        PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
        PCLZIP_OPT_ADD_PATH => 'optional',
        PCLZIP_CB_PRE_EXTRACT => 'optional',
        PCLZIP_CB_POST_EXTRACT => 'optional',
        PCLZIP_OPT_SET_CHMOD => 'optional',
        PCLZIP_OPT_BY_NAME => 'optional',
        PCLZIP_OPT_BY_EREG => 'optional',
        PCLZIP_OPT_BY_PREG => 'optional',
        PCLZIP_OPT_BY_INDEX => 'optional',
        PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
        PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
        PCLZIP_OPT_REPLACE_NEWER => 'optional',
        PCLZIP_OPT_STOP_ON_ERROR => 'optional',
        PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
      ));
      if ($v_result != 1) {

        //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
        return 0;
      }

      // ----- Set the arguments
      if (isset($v_options[PCLZIP_OPT_PATH])) {
        $v_path = $v_options[PCLZIP_OPT_PATH];
      }
      if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
        $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
      }
      if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
        $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
      }
      if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {

        // ----- Check for '/' in last path char
        if (strlen($v_path) > 0 && substr($v_path, -1) != '/') {
          $v_path .= '/';
        }
        $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
      }
    }
    else {

      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");

      // ----- Get the first argument
      $v_path = $v_arg_list[0];

      // ----- Look for the optional second argument
      if ($v_size == 2) {
        $v_remove_path = $v_arg_list[1];
      }
      else {
        if ($v_size > 2) {

          // ----- Error log
          PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");

          // ----- Return

          //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
          return 0;
        }
      }
    }
  }

  // ----- Trace

  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");

  // ----- Call the extracting fct
  $p_list = array();
  $v_result = $this
    ->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options);
  if ($v_result < 1) {
    unset($p_list);

    //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
    return 0;
  }

  // ----- Return

  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  return $p_list;
}