2
class ZIPFilter extends FILTER implements STREAMObjectInterface {
8
function __construct(&$info = NULL, STREAMWriterInterface $output = NULL) {
9
$this->filereader = true;
10
$this->filewriter = true;
13
$this->content_type = "application/x-zip-compressed";
14
$this->extension = "zip";
16
parent::__construct($info, $output);
19
function Open(&$args = NULL) {
22
$this->zip = new ZipArchive();
24
Unfortunately, to avoid problems it is neccessary to open and close ZIP
25
archive on each operation.
27
if ($this->zip->open($this->tmpfile, ZIPARCHIVE::CREATE) !== true)
28
throw new ADEIException(translate("Can't create ZIP archive"));
31
$this->list = array();
34
function Close(STREAMWriterInterface $h = NULL) {
35
if (!sizeof($this->list)) {
36
if ($this->zip->open($this->tmpfile, ZIPARCHIVE::CREATE) !== true)
37
throw new ADEIException(translate("Can't open/create ZIP archive (%s)", $this->tmpfile));
38
$this->zip->addFromString("no_data_available", "");
49
function BlockStart(&$args = NULL) {
50
$this->block_title = preg_replace("/[^\w\d_]/", "_", $args['block_title']);
53
function WriteData(&$data) {
56
if ($this->block_title) {
57
if (preg_match("/(\.[^\/\\\\]+)\s*$/",$data,$m)) $title = $this->block_title . $m[1];
58
else $title = $this->block_title;
59
} else $title = basename($data);
61
if (in_array($title, $this->list)) {
62
if (preg_match("/^(.*)(\.[^/\\\\]+)\s*$/",$title,$m)) {
72
$title = $base . (++$i) . $ext;
73
} while (in_array($title, $this->list));
76
array_push($this->list, $title);
78
if ($this->zip->open($this->tmpfile, ZIPARCHIVE::CREATE) !== true)
79
throw new ADEIException(translate("Can't open/create ZIP archive (%s)", $this->tmpfile));
80
$this->zip->addFile($data, $title);
84
function RequestFilemode() {
b'\\ No newline at end of file'