xref: /plugin/siteexport/action/startup.php (revision a8c17ab5b37308343f86651acb8c4a1b3f36f0ae)
17d101cc1SGerry Weißbach<?php
27d101cc1SGerry Weißbach/**
37d101cc1SGerry Weißbach * Site Export Plugin
47d101cc1SGerry Weißbach *
57d101cc1SGerry Weißbach * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
67d101cc1SGerry Weißbach * @author     i-net software <tools@inetsoftware.de>
77d101cc1SGerry Weißbach * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
87d101cc1SGerry Weißbach */
97d101cc1SGerry Weißbach
107d101cc1SGerry Weißbach// must be run within Dokuwiki
11*a8c17ab5Si-net /// softwareif (!defined('DOKU_INC')) define('DOKU_INC', /** @scrutinizer ignore-type */ realpath(dirname(__FILE__) . '/../../') . '/');
127d101cc1SGerry Weißbachif (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
137d101cc1SGerry Weißbachrequire_once(DOKU_PLUGIN . 'action.php');
147d101cc1SGerry Weißbach
157d101cc1SGerry Weißbachclass action_plugin_siteexport_startup extends DokuWiki_Action_Plugin {
167d101cc1SGerry Weißbach
177d101cc1SGerry Weißbach    /**
187d101cc1SGerry Weißbach     * Register Plugin in DW
197d101cc1SGerry Weißbach     **/
203f2e6413SGerry Weißbach    public function register(Doku_Event_Handler $controller) {
2116c5261cSGerry Weißbach        $controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'siteexport_check_template');
227d101cc1SGerry Weißbach        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'siteexport_check_template');
237d101cc1SGerry Weißbach        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'siteexport_check_export');
2495c3174fSGerry Weißbach        $controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'siteexport_add_page_export');
2595c3174fSGerry Weißbach        $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE',  $this, 'siteexport_addpage');
26b26434b0SGerry Weißbach        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'siteexport_metaheaders');
27bbafe1f0SGerry Weißbach        $controller->register_hook('JS_CACHE_USE', 'BEFORE', $this, 'siteexport_check_js_cache');
28c7c6980aSGerry Weißbach        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'siteexport_toolbar_define');
29c7c6980aSGerry Weißbach    }
30c7c6980aSGerry Weißbach
31c7c6980aSGerry Weißbach    private function hasSiteexportHeaders() {
32c7c6980aSGerry Weißbach        $headers = function_exists('getallheaders') ? getallheaders() : null;
33*a8c17ab5Si-net /// software        return is_array($headers) && array_key_exists('X-Site-Exporter', $headers);
347d101cc1SGerry Weißbach    }
357d101cc1SGerry Weißbach
367d101cc1SGerry Weißbach    /**
377d101cc1SGerry Weißbach     * Check for Template changes
387d101cc1SGerry Weißbach     **/
39*a8c17ab5Si-net /// software    public function siteexport_check_template()
407d101cc1SGerry Weißbach    {
417d101cc1SGerry Weißbach        global $conf, $INFO;
420cd3f1b4SGerry Weißbach
43c7c6980aSGerry Weißbach        if ( $this->hasSiteexportHeaders() || defined('SITEEXPORT_TPL') ) {
440cd3f1b4SGerry Weißbach            // This is a request via the HTTPProxy of the SiteExporter ... set config to what we need here.
450cd3f1b4SGerry Weißbach            $conf['useslash'] = 1;
460cd3f1b4SGerry Weißbach        }
477d101cc1SGerry Weißbach
487d101cc1SGerry Weißbach        if ( !defined('SITEEXPORT_TPL') ) { return; }
497d101cc1SGerry Weißbach        $conf['template'] = SITEEXPORT_TPL;
507d101cc1SGerry Weißbach    }
517d101cc1SGerry Weißbach
52bbafe1f0SGerry Weißbach    /**
53bbafe1f0SGerry Weißbach     * Check for Template changes in JS
54bbafe1f0SGerry Weißbach     **/
55*a8c17ab5Si-net /// software    public function siteexport_check_js_cache(Doku_Event &$event)
56bbafe1f0SGerry Weißbach    {
57bbafe1f0SGerry Weißbach        global $conf, $INFO;
58bbafe1f0SGerry Weißbach
59bbafe1f0SGerry Weißbach        if ( !defined('SITEEXPORT_TPL') ) { return; }
60bbafe1f0SGerry Weißbach        $event->data->key .= SITEEXPORT_TPL;
61bbafe1f0SGerry Weißbach        $event->data->cache = getCacheName($event->data->key,$event->data->ext);
62bbafe1f0SGerry Weißbach    }
63bbafe1f0SGerry Weißbach
64*a8c17ab5Si-net /// software    public function siteexport_check_export(Doku_Event &$event)
657d101cc1SGerry Weißbach    {
667d101cc1SGerry Weißbach        global $conf;
67*a8c17ab5Si-net /// software        $keys = is_array($event->data) ? array_keys($event->data) : null;
68*a8c17ab5Si-net /// software        $command = is_array($keys) ? array_shift($keys) : $event->data;
69fd385364SGerry Weißbach        if ( $command == 'export_siteexport_pdf')
707d101cc1SGerry Weißbach        {
717d101cc1SGerry Weißbach            $event->data = 'show';
727d101cc1SGerry Weißbach            $conf['renderer_xhtml'] = 'siteexport_pdf';
73fd385364SGerry Weißbach        }
74fd385364SGerry Weißbach
75*a8c17ab5Si-net /// software        if ( $command == 'siteexport_addpage' && $this->__executeCommand() )
76fd385364SGerry Weißbach        {
7795c3174fSGerry Weißbach            $event->preventDefault();
7895c3174fSGerry Weißbach        }
7995c3174fSGerry Weißbach    }
8095c3174fSGerry Weißbach
81*a8c17ab5Si-net /// software    public function siteexport_addpage(Doku_Event &$event)
8295c3174fSGerry Weißbach    {
83*a8c17ab5Si-net /// software        if ( $event->data != 'siteexport_addpage' || ! $this->__executeCommand() ) { return; }
8495c3174fSGerry Weißbach        if ( ! $functions=& plugin_load('helper', 'siteexport') ) {
8595c3174fSGerry Weißbach            msg("Can't initialize");
8695c3174fSGerry Weißbach            return false;
8795c3174fSGerry Weißbach        }
8895c3174fSGerry Weißbach
8995c3174fSGerry Weißbach        $functions->__siteexport_addpage();
9095c3174fSGerry Weißbach        $event->preventDefault();
9195c3174fSGerry Weißbach    }
9295c3174fSGerry Weißbach
93*a8c17ab5Si-net /// software    public function siteexport_add_page_export(Doku_Event &$event)
9495c3174fSGerry Weißbach    {
9595c3174fSGerry Weißbach        global $ID;
9695c3174fSGerry Weißbach
97*a8c17ab5Si-net /// software        if ( $this->__executeCommand() ) {
9895c3174fSGerry Weißbach            $event->data['items'][] = '<li>' . tpl_link(wl($ID, array('do' => 'siteexport_addpage')), '<span>Export Page</span>',
99259f68e8SGerry Weißbach                                                'class="action siteexport_addpage" title="Export Page (Siteexport)"', 1) . '</li>';
100259f68e8SGerry Weißbach
101259f68e8SGerry Weißbach            require_once(DOKU_PLUGIN . 'siteexport/inc/functions.php');
102259f68e8SGerry Weißbach            $functions = new siteexport_functions();
103259f68e8SGerry Weißbach
104259f68e8SGerry Weißbach            $check = array();
10585b8228eSGerry Weißbach            $mapIDs = $functions->getMapID($ID, null, $check);
10685b8228eSGerry Weißbach            $mapID = array_shift($mapIDs);
107259f68e8SGerry Weißbach            if ( !empty($mapID) ) {
108259f68e8SGerry Weißbach                $event->data['items'][] = '<li>' . tpl_link('', '<span>Copy Map-ID: <span class="mapID" data-done="Done.">'.$mapID.'</span></span>',
109259f68e8SGerry Weißbach                                                   'class="action siteexport_mapid" title="Show Map-ID"" data-mapid="'.$mapID.'" onclick="copyMapIDToClipBoard.call(this); return false;"', 1) . '</li>';
110259f68e8SGerry Weißbach            }
1117d101cc1SGerry Weißbach        }
1127d101cc1SGerry Weißbach    }
113b26434b0SGerry Weißbach
114*a8c17ab5Si-net /// software    public function siteexport_metaheaders(Doku_Event &$event)
115b26434b0SGerry Weißbach    {
116fc3c50fbSGerry Weißbach        global $conf;
117fc3c50fbSGerry Weißbach        $template = defined('SITEEXPORT_TPL') ? SITEEXPORT_TPL : $conf['template'];
118b26434b0SGerry Weißbach
119b26434b0SGerry Weißbach        $head =& $event->data;
120b26434b0SGerry Weißbach
121b26434b0SGerry Weißbach        foreach( $head['script'] as &$script ) {
122b26434b0SGerry Weißbach            if ( !empty($script['src']) && strstr($script['src'], 'js.php') ) {
123fc3c50fbSGerry Weißbach                $script['src'] .= '&template=' . $template;
124b26434b0SGerry Weißbach            }
125b26434b0SGerry Weißbach        }
126b26434b0SGerry Weißbach
127b26434b0SGerry Weißbach        return true;
128b26434b0SGerry Weißbach    }
129c7c6980aSGerry Weißbach
130*a8c17ab5Si-net /// software    public function siteexport_toolbar_define(Doku_Event &$event) {
131c7c6980aSGerry Weißbach
132c7c6980aSGerry Weißbach        if ( $this->hasSiteexportHeaders() ) {
133c7c6980aSGerry Weißbach            // Remove Toolbar
134bf4927b7SGerry Weißbach            // This is pr 5.4 syntax.
135bf4927b7SGerry Weißbach            $event->data = array();
136c7c6980aSGerry Weißbach        }
137c7c6980aSGerry Weißbach    }
138*a8c17ab5Si-net /// software
139*a8c17ab5Si-net /// software    private function __executeCommand() {
140*a8c17ab5Si-net /// software        return ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager());
141*a8c17ab5Si-net /// software    }
1427d101cc1SGerry Weißbach}
143