1<?php
2if(!defined('DOKU_INC')) die();
3
4/**
5 * Namespace export : Action component to send compressed ZIP file.
6 */
7class action_plugin_nsexport_export extends DokuWiki_Action_Plugin {
8
9    public $run = false;
10
11    /**
12     * Registers a callback function for a given event
13     *
14     * @param Doku_Event_Handler $controller
15     */
16    public function register(Doku_Event_Handler $controller) {
17        $controller->register_hook('TPL_ACT_UNKNOWN','BEFORE',  $this, 'nsexport');
18        $controller->register_hook('ACTION_ACT_PREPROCESS','BEFORE',  $this, 'act');
19    }
20
21    public function act(Doku_Event $event , $param) {
22        if ($event->data !== 'nsexport') {
23            return;
24        }
25        $event->preventDefault();
26        $this->run = true;
27    }
28
29    public function nsexport(Doku_Event $event, $param) {
30        if (!$this->run) return;
31
32        // stops default action handler
33        $event->preventDefault();
34
35        if ($this->getConf('autoexport')){
36            $id = ' plugin_nsexport__started';
37            echo $this->locale_xhtml('autointro');
38        }else{
39            $id = '';
40            echo $this->locale_xhtml('intro');
41        }
42        echo '<div class="level1"><p>' .
43             $this->getLang('packer___ziphtml___intro') .
44             '</p></div>';
45        $this->_listPages($id);
46    }
47
48    /**
49     * Create a list of pages about to be exported within a form
50     * to start the export
51     */
52    public function _listPages($id){
53        global $ID;
54
55        $pages = array();
56        $base  = dirname(wikiFN($ID));
57        search($pages,$base,'search_allpages',array());
58        $pages = array_reverse($pages);
59
60        echo '<form class="plugin_nsexport__form' . $id . '"
61                    action="'.DOKU_BASE.'lib/plugins/nsexport/export.php"
62                    method="post">';
63        echo '<p><input type="submit" id="do__export" class="button" value="'.$this->getLang('btn_export').'" />';
64        $ns = getNS($ID);
65        if(!$ns) $ns = '*';
66        printf($this->getLang('inns'), $ns);
67        echo '</p>';
68
69        echo '<ul>';
70        $num = 0;
71        $ns = getNS($ID). ':';
72        foreach($pages as $page){
73            $id = cleanID($ns . $page['id']);
74            echo '<li><div class="li"><input type="checkbox" name="export[]" '
75               . 'id="page__'.++$num.'" value="'.hsc($id).'" '
76               . 'checked="checked" />&nbsp;<label for="page__'.$num.'">'
77               .  hsc($id) . '</label></div></li>';
78        }
79        echo '</ul>';
80        echo '</form>';
81    }
82
83    public function tpl_link($return = false) {
84        global $ID;
85        $caption = hsc($this->getLang('link'));
86        return tpl_link(wl($ID, array('do' => 'nsexport')), $caption,
87                        'class="action nsexport" rel="nofollow" ' .
88                        'title="' . $caption . '"', $return);
89    }
90}
91