function PclZip::add in Quiz 6.5
Same name and namespace in other branches
- 6.6 includes/moodle/lib/pclzip/pclzip.lib.php \PclZip::add()
File
- includes/moodle/lib/pclzip/pclzip.lib.php, line 430
Class
- PclZip
Code
function add($p_filelist) {
$v_result = 1;
$this
->privErrorReset();
$v_options = array();
$v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
$v_size = func_num_args();
if ($v_size > 1) {
$v_arg_list = func_get_args();
array_shift($v_arg_list);
$v_size--;
if (is_integer($v_arg_list[0]) && $v_arg_list[0] > 77000) {
$v_result = $this
->privParseOptions($v_arg_list, $v_size, $v_options, array(
PCLZIP_OPT_REMOVE_PATH => 'optional',
PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
PCLZIP_OPT_ADD_PATH => 'optional',
PCLZIP_CB_PRE_ADD => 'optional',
PCLZIP_CB_POST_ADD => 'optional',
PCLZIP_OPT_NO_COMPRESSION => 'optional',
PCLZIP_OPT_COMMENT => 'optional',
PCLZIP_OPT_ADD_COMMENT => 'optional',
PCLZIP_OPT_PREPEND_COMMENT => 'optional',
));
if ($v_result != 1) {
return 0;
}
}
else {
$v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
if ($v_size == 2) {
$v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
}
else {
if ($v_size > 2) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
return 0;
}
}
}
}
$v_string_list = array();
$v_att_list = array();
$v_filedescr_list = array();
$p_result_list = array();
if (is_array($p_filelist)) {
if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
$v_att_list = $p_filelist;
}
else {
$v_string_list = $p_filelist;
}
}
else {
if (is_string($p_filelist)) {
$v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
}
else {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '" . gettype($p_filelist) . "' for p_filelist");
return 0;
}
}
if (sizeof($v_string_list) != 0) {
foreach ($v_string_list as $v_string) {
$v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
}
}
$v_supported_attributes = array(
PCLZIP_ATT_FILE_NAME => 'mandatory',
PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional',
PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional',
);
foreach ($v_att_list as $v_entry) {
$v_result = $this
->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes);
if ($v_result != 1) {
return 0;
}
}
$v_result = $this
->privFileDescrExpand($v_filedescr_list, $v_options);
if ($v_result != 1) {
return 0;
}
$v_result = $this
->privAdd($v_filedescr_list, $p_result_list, $v_options);
if ($v_result != 1) {
return 0;
}
return $p_result_list;
}