2017-08-11 11:10:27 -04:00
|
|
|
<?php
|
|
|
|
|
/*--------------------------------------------------
|
|
|
|
|
* TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.1
|
|
|
|
|
* By Devin Doucette
|
|
|
|
|
* Copyright (c) 2005 Devin Doucette
|
|
|
|
|
* Email: darksnoopy@shaw.ca
|
|
|
|
|
*--------------------------------------------------
|
|
|
|
|
* Email bugs/suggestions to darksnoopy@shaw.ca
|
|
|
|
|
*--------------------------------------------------
|
|
|
|
|
* This script has been created and released under
|
|
|
|
|
* the GNU GPL and is free to use and redistribute
|
|
|
|
|
* only if this copyright statement is not removed
|
|
|
|
|
*--------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class is derived from the class archive, is imployed to use files .
|
|
|
|
|
* zip
|
|
|
|
|
*
|
|
|
|
|
* @package workflow.engine.classes
|
2017-08-11 12:33:30 -04:00
|
|
|
*/
|
|
|
|
|
class zip_file extends Archive
|
2017-08-11 11:10:27 -04:00
|
|
|
{
|
|
|
|
|
|
2017-08-11 12:33:30 -04:00
|
|
|
public function zip_file($name)
|
2017-08-11 11:10:27 -04:00
|
|
|
{
|
2017-08-11 12:33:30 -04:00
|
|
|
$this->archive($name);
|
2017-08-11 11:10:27 -04:00
|
|
|
$this->options['type'] = "zip";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function is used to create archives .
|
|
|
|
|
* zip
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2017-08-11 12:33:30 -04:00
|
|
|
public function create_zip()
|
2017-08-11 11:10:27 -04:00
|
|
|
{
|
|
|
|
|
$files = 0;
|
|
|
|
|
$offset = 0;
|
|
|
|
|
$central = "";
|
2017-08-11 12:33:30 -04:00
|
|
|
if (!empty($this->options['sfx'])) {
|
|
|
|
|
if ($fp = @fopen($this->options['sfx'], "rb")) {
|
|
|
|
|
$temp = fread($fp, filesize($this->options['sfx']));
|
|
|
|
|
fclose($fp);
|
|
|
|
|
$this->add_data($temp);
|
|
|
|
|
$offset += strlen($temp);
|
|
|
|
|
unset($temp);
|
2017-08-11 11:10:27 -04:00
|
|
|
} else {
|
|
|
|
|
$this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$pwd = getcwd();
|
2017-08-11 12:33:30 -04:00
|
|
|
chdir($this->options['basedir']);
|
2017-08-11 11:10:27 -04:00
|
|
|
foreach ($this->files as $current) {
|
|
|
|
|
if ($current['name'] == $this->options['name']) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-08-11 12:33:30 -04:00
|
|
|
$timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
|
2017-08-11 11:10:27 -04:00
|
|
|
$timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) | ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
|
2017-08-11 12:33:30 -04:00
|
|
|
$block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
|
2017-08-11 11:10:27 -04:00
|
|
|
if ($current['stat'][7] == 0 && $current['type'] == 5) {
|
2017-08-11 12:33:30 -04:00
|
|
|
$block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
|
2017-08-11 11:10:27 -04:00
|
|
|
$block .= $current['name2'] . "/";
|
2017-08-11 12:33:30 -04:00
|
|
|
$this->add_data($block);
|
|
|
|
|
$central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate, 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
|
2017-08-11 11:10:27 -04:00
|
|
|
$central .= $current['name2'] . "/";
|
2017-08-11 12:33:30 -04:00
|
|
|
$files++;
|
|
|
|
|
$offset += (31 + strlen($current['name2']));
|
2017-08-11 11:10:27 -04:00
|
|
|
} elseif ($current['stat'][7] == 0) {
|
2017-08-11 12:33:30 -04:00
|
|
|
$block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
|
2017-08-11 11:10:27 -04:00
|
|
|
$block .= $current['name2'];
|
2017-08-11 12:33:30 -04:00
|
|
|
$this->add_data($block);
|
|
|
|
|
$central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate, 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
|
2017-08-11 11:10:27 -04:00
|
|
|
$central .= $current['name2'];
|
2017-08-11 12:33:30 -04:00
|
|
|
$files++;
|
|
|
|
|
$offset += (30 + strlen($current['name2']));
|
|
|
|
|
} elseif ($fp = @fopen($current['name'], "rb")) {
|
|
|
|
|
$temp = fread($fp, $current['stat'][7]);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
$crc32 = G::encryptCrc32($temp);
|
|
|
|
|
if (!isset($current['method']) && $this->options['method'] == 1) {
|
|
|
|
|
$temp = gzcompress($temp, $this->options['level']);
|
|
|
|
|
$size = strlen($temp) - 6;
|
|
|
|
|
$temp = substr($temp, 2, $size);
|
2017-08-11 11:10:27 -04:00
|
|
|
} else {
|
2017-08-11 12:33:30 -04:00
|
|
|
$size = strlen($temp);
|
2017-08-11 11:10:27 -04:00
|
|
|
}
|
2017-08-11 12:33:30 -04:00
|
|
|
$block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
|
2017-08-11 11:10:27 -04:00
|
|
|
$block .= $current['name2'];
|
2017-08-11 12:33:30 -04:00
|
|
|
$this->add_data($block);
|
|
|
|
|
$this->add_data($temp);
|
|
|
|
|
unset($temp);
|
|
|
|
|
$central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate, $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
|
2017-08-11 11:10:27 -04:00
|
|
|
$central .= $current['name2'];
|
2017-08-11 12:33:30 -04:00
|
|
|
$files++;
|
|
|
|
|
$offset += (30 + strlen($current['name2']) + $size);
|
2017-08-11 11:10:27 -04:00
|
|
|
} else {
|
|
|
|
|
$this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-11 12:33:30 -04:00
|
|
|
$this->add_data($central);
|
|
|
|
|
$this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset, !empty($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
|
|
|
|
|
if (!empty($this->options['comment'])) {
|
|
|
|
|
$this->add_data($this->options['comment']);
|
2017-08-11 11:10:27 -04:00
|
|
|
}
|
2017-08-11 12:33:30 -04:00
|
|
|
chdir($pwd);
|
2017-08-11 11:10:27 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|