function PclZip::privDeleteByRule in Loft Data Grids 6.2
Same name and namespace in other branches
- 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php \PclZip::privDeleteByRule()
1 call to PclZip::privDeleteByRule()
- PclZip::delete in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php
File
- vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/PCLZip/pclzip.lib.php, line 4682
Class
- PclZip
Code
function privDeleteByRule(&$p_result_list, &$p_options) {
$v_result = 1;
$v_list_detail = array();
if (($v_result = $this
->privOpenFd('rb')) != 1) {
return $v_result;
}
$v_central_dir = array();
if (($v_result = $this
->privReadEndCentralDir($v_central_dir)) != 1) {
$this
->privCloseFd();
return $v_result;
}
@rewind($this->zip_fd);
$v_pos_entry = $v_central_dir['offset'];
@rewind($this->zip_fd);
if (@fseek($this->zip_fd, $v_pos_entry)) {
$this
->privCloseFd();
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
return PclZip::errorCode();
}
$v_header_list = array();
$j_start = 0;
for ($i = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) {
$v_header_list[$v_nb_extracted] = array();
if (($v_result = $this
->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) {
$this
->privCloseFd();
return $v_result;
}
$v_header_list[$v_nb_extracted]['index'] = $i;
$v_found = false;
if (isset($p_options[PCLZIP_OPT_BY_NAME]) && $p_options[PCLZIP_OPT_BY_NAME] != 0) {
for ($j = 0; $j < sizeof($p_options[PCLZIP_OPT_BY_NAME]) && !$v_found; $j++) {
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
if (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]) && substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_found = true;
}
elseif (($v_header_list[$v_nb_extracted]['external'] & 0x10) == 0x10 && $v_header_list[$v_nb_extracted]['stored_filename'] . '/' == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_found = true;
}
}
elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_found = true;
}
}
}
else {
if (isset($p_options[PCLZIP_OPT_BY_PREG]) && $p_options[PCLZIP_OPT_BY_PREG] != "") {
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
$v_found = true;
}
}
else {
if (isset($p_options[PCLZIP_OPT_BY_INDEX]) && $p_options[PCLZIP_OPT_BY_INDEX] != 0) {
for ($j = $j_start; $j < sizeof($p_options[PCLZIP_OPT_BY_INDEX]) && !$v_found; $j++) {
if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] && $i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
$v_found = true;
}
if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
$j_start = $j + 1;
}
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] > $i) {
break;
}
}
}
else {
$v_found = true;
}
}
}
if ($v_found) {
unset($v_header_list[$v_nb_extracted]);
}
else {
$v_nb_extracted++;
}
}
if ($v_nb_extracted > 0) {
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR . uniqid('pclzip-') . '.tmp';
$v_temp_zip = new PclZip($v_zip_temp_name);
if (($v_result = $v_temp_zip
->privOpenFd('wb')) != 1) {
$this
->privCloseFd();
return $v_result;
}
for ($i = 0; $i < sizeof($v_header_list); $i++) {
@rewind($this->zip_fd);
if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
$this
->privCloseFd();
$v_temp_zip
->privCloseFd();
@unlink($v_zip_temp_name);
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
return PclZip::errorCode();
}
$v_local_header = array();
if (($v_result = $this
->privReadFileHeader($v_local_header)) != 1) {
$this
->privCloseFd();
$v_temp_zip
->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
if ($this
->privCheckFileHeaders($v_local_header, $v_header_list[$i]) != 1) {
}
unset($v_local_header);
if (($v_result = $v_temp_zip
->privWriteFileHeader($v_header_list[$i])) != 1) {
$this
->privCloseFd();
$v_temp_zip
->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
$this
->privCloseFd();
$v_temp_zip
->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
}
$v_offset = @ftell($v_temp_zip->zip_fd);
for ($i = 0; $i < sizeof($v_header_list); $i++) {
if (($v_result = $v_temp_zip
->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
$v_temp_zip
->privCloseFd();
$this
->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
$v_temp_zip
->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
}
$v_comment = '';
if (isset($p_options[PCLZIP_OPT_COMMENT])) {
$v_comment = $p_options[PCLZIP_OPT_COMMENT];
}
$v_size = @ftell($v_temp_zip->zip_fd) - $v_offset;
if (($v_result = $v_temp_zip
->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
unset($v_header_list);
$v_temp_zip
->privCloseFd();
$this
->privCloseFd();
@unlink($v_zip_temp_name);
return $v_result;
}
$v_temp_zip
->privCloseFd();
$this
->privCloseFd();
@unlink($this->zipname);
PclZipUtilRename($v_zip_temp_name, $this->zipname);
unset($v_temp_zip);
}
else {
if ($v_central_dir['entries'] != 0) {
$this
->privCloseFd();
if (($v_result = $this
->privOpenFd('wb')) != 1) {
return $v_result;
}
if (($v_result = $this
->privWriteCentralHeader(0, 0, 0, '')) != 1) {
return $v_result;
}
$this
->privCloseFd();
}
}
return $v_result;
}