xref: /plugin/siteexport/action/startup.php (revision 0cd3f1b43aa8213eaf4461040ca62aafbb931533)
1<?php
2/**
3 * Site Export 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')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'action.php');
14
15class action_plugin_siteexport_startup extends DokuWiki_Action_Plugin {
16
17    /**
18	* Register Plugin in DW
19	**/
20	function register(&$controller) {
21		$controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'siteexport_check_template');
22		$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'siteexport_check_template');
23		$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'siteexport_check_export');
24		$controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'siteexport_add_page_export');
25		$controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE',  $this, 'siteexport_addpage');
26        	$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'siteexport_metaheaders');
27	        $controller->register_hook('JS_CACHE_USE', 'BEFORE', $this, 'siteexport_check_js_cache');
28	}
29
30	/**
31	* Check for Template changes
32	**/
33	function siteexport_check_template()
34	{
35		global $conf, $INFO;
36
37        $headers = getallheaders();
38        if ( array_key_exists('X-Site-Exporter', $headers) && $headers['X-Site-Exporter'] = getSecurityToken() ) {
39            // This is a request via the HTTPProxy of the SiteExporter ... set config to what we need here.
40    		$conf['useslash'] = 1;
41        }
42
43		if ( !defined('SITEEXPORT_TPL') ) { return; }
44		$conf['template'] = SITEEXPORT_TPL;
45	}
46
47	/**
48	* Check for Template changes in JS
49	**/
50	function siteexport_check_js_cache(&$event)
51	{
52		global $conf, $INFO;
53
54		if ( !defined('SITEEXPORT_TPL') ) { return; }
55		$event->data->key .= SITEEXPORT_TPL;
56		$event->data->cache = getCacheName($event->data->key,$event->data->ext);
57	}
58
59	function siteexport_check_export(&$event)
60	{
61	    global $conf;
62	    $command = is_array($event->data) ? array_shift(array_keys($event->data)) : $event->data;
63	    if ( $command == 'export_siteexport_pdf')
64	    {
65	        $event->data = 'show';
66	        $conf['renderer_xhtml'] = 'siteexport_pdf';
67	    }
68
69	    if ( $command == 'siteexport_addpage' && ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager() ) )
70	    {
71			$event->preventDefault();
72	    }
73	}
74
75	function siteexport_addpage(&$event)
76	{
77		if ( $event->data != 'siteexport_addpage' || ! ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) { return; }
78        if ( ! $functions=& plugin_load('helper', 'siteexport') ) {
79            msg("Can't initialize");
80            return false;
81        }
82
83        $functions->__siteexport_addpage();
84	    $event->preventDefault();
85	}
86
87	function siteexport_add_page_export(&$event)
88	{
89		global $ID;
90
91		if ( ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) {
92			$event->data['items'][] = '<li>' . tpl_link(wl($ID, array('do' => 'siteexport_addpage')), '<span>Export Page</span>',
93												'class="action siteexport_addpage" title="Add page"', 1) . '</li>';
94		}
95	}
96
97	function siteexport_metaheaders(&$event)
98	{
99		global $conf;
100		$template = defined('SITEEXPORT_TPL') ? SITEEXPORT_TPL : $conf['template'];
101
102		$head =& $event->data;
103
104		foreach( $head['script'] as &$script ) {
105			if ( !empty($script['src']) && strstr($script['src'], 'js.php') ) {
106				$script['src'] .= '&template=' . $template;
107			}
108		}
109
110		return true;
111	}
112}
113