xref: /plugin/siteexport/action/sendfile.php (revision 6792d0cf58db367e1e6f5b779f1b1efd0e27751f)
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 register(&$controller) {
22        // Download of a file
23
24        $controller->register_hook('MEDIA_SENDFILE', 'BEFORE', $this, 'siteexport_sendfile');
25        $controller->register_hook('FETCH_MEDIA_STATUS', 'BEFORE', $this, 'siteexport_sendfile_not_found');
26    }
27
28    /*
29     * Redirect File to real File
30     */
31    function siteexport_sendfile(&$event, $args) {
32        global $conf;
33
34        if ( empty($_REQUEST['siteexport']) /* || $event->data['orig'] != $this->getConf('zipfilename') */ ) {
35            return;
36        }
37
38        $functions = new siteexport_functions();
39        $functions->debug->message("Starting to send a file from siteexporter", null, 2);
40        $filewriter = new siteexport_zipfilewriter($functions);
41        $functions->settings->pattern = $_REQUEST['siteexport'];
42
43        // Try injecting another name ... can't do, because sendFile sets this right after me and right before sending the actual data.
44        // header('Content-Disposition: attachment; filename="'. basename($functions->settings->zipFile) .'";');
45
46        // Try getting the cached file ...
47        $event->data['file'] = $functions->getCacheFileNameForPattern();
48
49        $functions->debug->message("fetching cached file from pattern '{$functions->settings->pattern}' with name '{$event->data['file']}'", null, 2);
50        $functions->debug->message("Event Data Before:", $event->data, 3);
51
52        $functions->checkIfCacheFileExistsForFileWithPattern($event->data['file'], $_REQUEST['siteexport']);
53
54        $filewriter->getOnlyFileInZip($event->data);
55        $functions->debug->message("Event Data After:", $event->data, 3);
56    }
57
58    function siteexport_sendfile_not_found(&$event, $args)
59    {
60        if ( empty($_REQUEST['siteexport']) /*|| $event->data['orig'] != $this->getConf('zipfilename')*/ || $event->data['status'] != 404 ) { return true; }
61        $event->data['status'] = 200;
62        return true;
63    }
64}
65