/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to classes/stream/zipfilter.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
class ZIPFilter extends FILTER implements STREAMObjectInterface {
 
3
 var $zip;
 
4
 
 
5
 var $block_title;
 
6
 var $list;
 
7
 
 
8
 function __construct(&$info = NULL, STREAMWriterInterface $output = NULL) {
 
9
    $this->filereader = true;
 
10
    $this->filewriter = true;
 
11
    $this->joiner = true;
 
12
    
 
13
    $this->content_type = "application/x-zip-compressed";
 
14
    $this->extension = "zip";
 
15
 
 
16
    parent::__construct($info, $output);
 
17
 }
 
18
 
 
19
 function Open(&$args = NULL) {
 
20
    parent::Open($args);
 
21
    
 
22
    $this->zip = new ZipArchive();
 
23
/*
 
24
    Unfortunately, to avoid problems it is neccessary to open and close ZIP 
 
25
    archive on each operation.
 
26
    
 
27
    if ($this->zip->open($this->tmpfile, ZIPARCHIVE::CREATE) !== true)
 
28
        throw new ADEIException(translate("Can't create ZIP archive"));
 
29
*/
 
30
    
 
31
    $this->list = array();
 
32
 }
 
33
 
 
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", "");
 
39
        $this->zip->close();
 
40
    }
 
41
 
 
42
/*
 
43
    $this->zip->close();
 
44
*/    
 
45
 
 
46
    parent::Close($h);
 
47
 }
 
48
 
 
49
 function BlockStart(&$args = NULL) {
 
50
    $this->block_title = preg_replace("/[^\w\d_]/", "_", $args['block_title']);
 
51
 }
 
52
 
 
53
 function WriteData(&$data) {
 
54
    $this->count++;
 
55
 
 
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);
 
60
    
 
61
    if (in_array($title, $this->list)) {
 
62
        if (preg_match("/^(.*)(\.[^/\\\\]+)\s*$/",$title,$m)) {
 
63
            $base = $m[1];
 
64
            $ext = $m[2];
 
65
        } else {
 
66
            $base = $title;
 
67
            $ext = "";
 
68
        }
 
69
        
 
70
        $i = 0;
 
71
        do {
 
72
            $title = $base . (++$i) . $ext;
 
73
        } while (in_array($title, $this->list));
 
74
    }
 
75
    
 
76
    array_push($this->list, $title);
 
77
 
 
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);
 
81
    $this->zip->close();
 
82
 }
 
83
 
 
84
 function RequestFilemode() {
 
85
    return false;
 
86
 }
 
87
}
 
88
 
 
89
?>
 
 
b'\\ No newline at end of file'