xref: /plugin/siteexport/action/sendfile.php (revision f3359d31bc059608034e7c4c70b3b0a87ac050be)
1<?php
2/**
3 * Siteexport SendFile Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     i-net software <tools@inetsoftware.de>
7 * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
8 */
9
10// must be run within Dokuwiki
11if(!defined('DOKU_INC')) die();
12
13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14
15require_once(DOKU_PLUGIN.'action.php');
16require_once(DOKU_PLUGIN.'siteexport/inc/debug.php');
17require_once(DOKU_PLUGIN.'siteexport/inc/functions.php');
18
19class action_plugin_siteexport_sendfile extends DokuWiki_Action_Plugin {
20
21    function getInfo(){
22        return array_merge(confToHash(dirname(__FILE__).'/../info.txt'), array(
23				'name' => 'i-net Download (Send File Action Component)',
24        ));
25    }
26
27    function register(&$controller) {
28        // Download of a file
29
30        $controller->register_hook('MEDIA_SENDFILE', 'BEFORE', $this, 'siteexport_sendfile');
31        $controller->register_hook('FETCH_MEDIA_STATUS', 'BEFORE', $this, 'siteexport_sendfile_not_found');
32    }
33
34    /*
35     * Redirect File to real File
36     */
37    function siteexport_sendfile(&$event, $args) {
38        global $conf;
39
40        if ( empty($_REQUEST['siteexport']) /* || $event->data['orig'] != $this->getConf('zipfilename') */ ) {
41            return;
42        }
43
44        $functions = new siteexport_functions();
45        $functions->settings->pattern = $_REQUEST['siteexport'];
46        $filewriter = new siteexport_zipfilewriter($functions);
47
48        // Try injecting another name ... can't do, because sendFile sets this right after me and right before sending the actual data.
49        // header('Content-Disposition: attachment; filename="'. basename($functions->settings->zipFile) .'";');
50
51        // Try getting the cached file ...
52        $event->data['file'] = $functions->getCacheFileNameForPattern();
53
54        $functions->debug->message("fetching cached file from pattern '{$functions->settings->pattern}' with name '{$event->data['file']}'", null, 2);
55
56        $functions->checkIfCacheFileExistsForFileWithPattern($event->data['file'], $_REQUEST['siteexport']);
57        $filewriter->getOnlyFileInZip($event->data['file'], $event->data['orig']);
58    }
59
60    function siteexport_sendfile_not_found(&$event, $args)
61    {
62        if ( empty($_REQUEST['siteexport']) /*|| $event->data['orig'] != $this->getConf('zipfilename')*/ || $event->data['status'] != 404 ) { return true; }
63        $event->data['status'] = 200;
64        return true;
65    }
66}
67