1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Code optimization and cleanup.

This commit is contained in:
Cameron
2020-12-10 15:52:48 -08:00
parent bd3a181e27
commit f605ddc552
39 changed files with 364 additions and 371 deletions

View File

@@ -293,7 +293,7 @@ class PclZip
$v_size--;
// ----- Look for first arg
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
if ((is_int($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
// ----- Parse the options
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array(
@@ -367,7 +367,7 @@ class PclZip
}
// ----- Reformat the string list
if (sizeof($v_string_list) != 0) {
if (count($v_string_list) != 0) {
foreach ($v_string_list as $v_string) {
if ($v_string != '') {
$v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
@@ -468,7 +468,7 @@ class PclZip
$v_size--;
// ----- Look for first arg
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
if ((is_int($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
// ----- Parse the options
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array(
@@ -546,7 +546,7 @@ class PclZip
}
// ----- Reformat the string list
if (sizeof($v_string_list) != 0) {
if (count($v_string_list) != 0) {
foreach ($v_string_list as $v_string) {
$v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
}
@@ -714,7 +714,7 @@ class PclZip
$v_arg_list = func_get_args();
// ----- Look for first arg
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
if ((is_int($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
// ----- Parse the options
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array(
@@ -873,7 +873,7 @@ class PclZip
$v_size--;
// ----- Look for first arg
if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
if ((is_int($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
// ----- Parse the options
$v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array(
@@ -949,7 +949,7 @@ class PclZip
$p_index
);
$v_options_trick = array();
$v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, array(
$v_result = $this->privParseOptions($v_arg_trick, count($v_arg_trick), $v_options_trick, array(
PCLZIP_OPT_BY_INDEX => 'optional'
));
if ($v_result != 1) {
@@ -1445,7 +1445,7 @@ class PclZip
// ----- Check the value
$v_value = $p_options_list[$i + 1];
if ((!is_integer($v_value)) || ($v_value < 0)) {
if ((!is_int($v_value)) || ($v_value < 0)) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '" . PclZipUtilOptionText($p_options_list[$i]) . "'");
return PclZip::errorCode();
@@ -1603,7 +1603,7 @@ class PclZip
// ----- Parse items
$v_work_list = explode(",", $p_options_list[$i + 1]);
} elseif (is_integer($p_options_list[$i + 1])) {
} elseif (is_int($p_options_list[$i + 1])) {
$v_work_list[0] = $p_options_list[$i + 1] . '-' . $p_options_list[$i + 1];
} elseif (is_array($p_options_list[$i + 1])) {
$v_work_list = $p_options_list[$i + 1];
@@ -1621,10 +1621,10 @@ class PclZip
// ----- Check the format of each item
$v_sort_flag = false;
$v_sort_value = 0;
for ($j = 0; $j < sizeof($v_work_list); $j++) {
for ($j = 0; $j < count($v_work_list); $j++) {
// ----- Explode the item
$v_item_list = explode("-", $v_work_list[$j]);
$v_size_item_list = sizeof($v_item_list);
$v_size_item_list = count($v_item_list);
// ----- TBC : Here we might check that each item is a
// real integer ...
@@ -1902,7 +1902,7 @@ class PclZip
break;
case PCLZIP_ATT_FILE_MTIME:
if (!is_integer($v_value)) {
if (!is_int($v_value)) {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type " . gettype($v_value) . ". Integer expected for attribute '" . PclZipUtilOptionText($v_key) . "'");
return PclZip::errorCode();
@@ -1968,7 +1968,7 @@ class PclZip
$v_result_list = array();
// ----- Look each entry
for ($i = 0; $i < sizeof($p_filedescr_list); $i++) {
for ($i = 0; $i < count($p_filedescr_list); $i++) {
// ----- Get filedescr
$v_descr = $p_filedescr_list[$i];
@@ -2008,7 +2008,7 @@ class PclZip
$this->privCalculateStoredFilename($v_descr, $p_options);
// ----- Add the descriptor in result list
$v_result_list[sizeof($v_result_list)] = $v_descr;
$v_result_list[count($v_result_list)] = $v_descr;
// ----- Look for folder
if ($v_descr['type'] == 'folder') {
@@ -2204,7 +2204,7 @@ class PclZip
}
// ----- Create the Central Dir files header
for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) {
for ($i = 0, $v_count = 0; $i < count($v_header_list); $i++) {
// ----- Create the file header
if ($v_header_list[$i]['status'] == 'ok') {
if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
@@ -2356,7 +2356,7 @@ class PclZip
$v_offset = @ftell($this->zip_fd);
// ----- Create the Central Dir files header
for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) {
for ($i = 0, $v_count = 0; $i < count($v_header_list); $i++) {
// ----- Create the file header
if ($v_header_list[$i]['status'] == 'ok') {
if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
@@ -2408,10 +2408,10 @@ class PclZip
$v_header = array();
// ----- Recuperate the current number of elt in list
$v_nb = sizeof($p_result_list);
$v_nb = count($p_result_list);
// ----- Loop on the files
for ($j = 0; ($j < sizeof($p_filedescr_list)) && ($v_result == 1); $j++) {
for ($j = 0; ($j < count($p_filedescr_list)) && ($v_result == 1); $j++) {
// ----- Format the filename
$p_filedescr_list[$j]['filename'] = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
@@ -2947,14 +2947,14 @@ class PclZip
$v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len']);
// ----- Write the first 148 bytes of the header in the archive
fputs($this->zip_fd, $v_binary_data, 30);
fwrite($this->zip_fd, $v_binary_data, 30);
// ----- Write the variable fields
if (strlen($p_header['stored_filename']) != 0) {
fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
fwrite($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
}
if ($p_header['extra_len'] != 0) {
fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
fwrite($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
}
// ----- Return
@@ -2985,17 +2985,17 @@ class PclZip
$v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, $p_header['version'], $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len'], $p_header['comment_len'], $p_header['disk'], $p_header['internal'], $p_header['external'], $p_header['offset']);
// ----- Write the 42 bytes of the header in the zip file
fputs($this->zip_fd, $v_binary_data, 46);
fwrite($this->zip_fd, $v_binary_data, 46);
// ----- Write the variable fields
if (strlen($p_header['stored_filename']) != 0) {
fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
fwrite($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
}
if ($p_header['extra_len'] != 0) {
fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
fwrite($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
}
if ($p_header['comment_len'] != 0) {
fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
fwrite($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
}
// ----- Return
@@ -3017,11 +3017,11 @@ class PclZip
$v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, $p_nb_entries, $p_size, $p_offset, strlen($p_comment));
// ----- Write the 22 bytes of the header in the zip file
fputs($this->zip_fd, $v_binary_data, 22);
fwrite($this->zip_fd, $v_binary_data, 22);
// ----- Write the variable fields
if (strlen($p_comment) != 0) {
fputs($this->zip_fd, $p_comment, strlen($p_comment));
fwrite($this->zip_fd, $p_comment, strlen($p_comment));
}
// ----- Return
@@ -3245,7 +3245,7 @@ class PclZip
if ((isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
// ----- Look if the filename is in the list
for ($j = 0; ($j < sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
for ($j = 0; ($j < count($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
// ----- Look for a directory
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
@@ -3283,7 +3283,7 @@ class PclZip
} elseif ((isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
// ----- Look if the index is in the list
for ($j = $j_start; ($j < sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
for ($j = $j_start; ($j < count($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
if (($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
$v_extract = true;
@@ -3584,7 +3584,7 @@ class PclZip
}
// ----- Look if file is write protected
} elseif (!is_writeable($p_entry['filename'])) {
} elseif (!is_writable($p_entry['filename'])) {
// ----- Change the file status
$p_entry['status'] = "write_protected";
@@ -4529,7 +4529,7 @@ class PclZip
if ((isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
// ----- Look if the filename is in the list
for ($j = 0; ($j < sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
for ($j = 0; ($j < count($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
// ----- Look for a directory
if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
@@ -4570,7 +4570,7 @@ class PclZip
} elseif ((isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
// ----- Look if the index is in the list
for ($j = $j_start; ($j < sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
for ($j = $j_start; ($j < count($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;
@@ -4613,7 +4613,7 @@ class PclZip
}
// ----- Look which file need to be kept
for ($i = 0; $i < sizeof($v_header_list); $i++) {
for ($i = 0; $i < count($v_header_list); $i++) {
// ----- Calculate the position of the header
@rewind($this->zip_fd);
@@ -4675,7 +4675,7 @@ class PclZip
$v_offset = @ftell($v_temp_zip->zip_fd);
// ----- Re-Create the Central Dir files header
for ($i = 0; $i < sizeof($v_header_list); $i++) {
for ($i = 0; $i < count($v_header_list); $i++) {
// ----- Create the file header
if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
$v_temp_zip->privCloseFd();
@@ -4700,7 +4700,7 @@ class PclZip
$v_size = @ftell($v_temp_zip->zip_fd) - $v_offset;
// ----- Create the central dir footer
if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
if (($v_result = $v_temp_zip->privWriteCentralHeader(count($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
// ----- Reset the file list
unset($v_header_list);
$v_temp_zip->privCloseFd();
@@ -5147,7 +5147,7 @@ function PclZipUtilPathReduction($p_dir)
// ----- Study directories from last to first
$v_skip = 0;
for ($i = sizeof($v_list) - 1; $i >= 0; $i--) {
for ($i = count($v_list) - 1; $i >= 0; $i--) {
// ----- Look for current path
if ($v_list[$i] == ".") {
// ----- Ignore this directory
@@ -5166,7 +5166,7 @@ function PclZipUtilPathReduction($p_dir)
}
// ----- Last '/' i.e. indicates a directory
} elseif ($i == (sizeof($v_list) - 1)) {
} elseif ($i == (count($v_list) - 1)) {
$v_result = $v_list[$i];
// ----- Double '/' inside the path
@@ -5179,7 +5179,7 @@ function PclZipUtilPathReduction($p_dir)
if ($v_skip > 0) {
$v_skip--;
} else {
$v_result = $v_list[$i] . ($i != (sizeof($v_list) - 1) ? "/" . $v_result : "");
$v_result = $v_list[$i] . ($i != (count($v_list) - 1) ? "/" . $v_result : "");
}
}
}
@@ -5227,9 +5227,9 @@ function PclZipUtilPathInclusion($p_dir, $p_path)
// ----- Explode dir and path by directory separator
$v_list_dir = explode("/", $p_dir);
$v_list_dir_size = sizeof($v_list_dir);
$v_list_dir_size = count($v_list_dir);
$v_list_path = explode("/", $p_path);
$v_list_path_size = sizeof($v_list_path);
$v_list_path_size = count($v_list_path);
// ----- Study directories paths
$i = 0;