1<?php
2abstract class plugin_nsexport_packer extends DokuWiki_Plugin {
3
4    public function start_packing($pages) {
5
6        if (!$this->init_packing($pages)) {
7            return;
8        }
9
10        $this->fileid = time().rand(0,99999);
11
12        // return name to the client
13        echo $this->fileid;
14        flush();
15
16        foreach($pages as $ID) {
17            if( auth_quickaclcheck($ID) < AUTH_READ ) continue;
18            @set_time_limit(30);
19            $this->pack_page($ID);
20        }
21
22        $this->finish_packing();
23    }
24
25    public function init_packing($pages) {
26        return true;
27    }
28
29    public function pack_page($ID) {
30
31    }
32
33    public function finish_packing() {
34
35    }
36
37    protected function check_key($key) {
38        return is_numeric($key);
39    }
40
41    protected function result_filename() {
42        global $conf;
43        return $conf['tmpdir'] . '/offline-' . $this->fileid . '.' . $this->ext;
44    }
45
46    public function get_status($key) {
47        if (!$this->check_key($key)) {
48            return;
49        }
50        $this->fileid = $key;
51        return is_file($this->result_filename());
52    }
53
54    public function get_pack($key) {
55        if (!$this->check_key($key)) {
56            return;
57        }
58
59        @ignore_user_abort(true);
60
61        $this->fileid = $key;
62        $filename = $this->result_filename();
63        if (!is_file($filename)) {
64            send_redirect(DOKU_BASE . 'doku.php');
65        }
66
67        // send to browser
68        $mime = mimetype('.' . $this->ext, false);
69        header('Content-Type: ' . $mime[1]);
70        header('Content-Disposition: attachment; filename="export.' . $this->ext . '"');
71        header('Expires: 0');
72        header('Content-Length: ' . filesize($filename));
73        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
74        header('Content-Transfer-Encoding: binary');
75        header('Pragma: public');
76        flush();
77        @set_time_limit(0);
78
79        $fh = @fopen($filename, 'rb');
80        while (!feof($fh)) {
81            echo fread($fh, 1024);
82        }
83        fclose($fh);
84        @unlink($filename);
85    }
86}
87