xref: /plugin/siteexport/action/startup.php (revision b26434b04ff9a417472fe22beb3a791e0e2c8fcf)
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	 * for backward compatability
19	 * @see inc/DokuWiki_Plugin#getInfo()
20	 */
21    function getInfo(){
22        if ( method_exists(parent, 'getInfo')) {
23            $info = parent::getInfo();
24        }
25        return is_array($info) ? $info : confToHash(dirname(__FILE__).'/../plugin.info.txt');
26    }
27
28    /**
29	* Register Plugin in DW
30	**/
31	function register(&$controller) {
32		$controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'siteexport_check_template');
33		$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'siteexport_check_template');
34		$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'siteexport_check_export');
35		$controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'siteexport_add_page_export');
36		$controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE',  $this, 'siteexport_addpage');
37	        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'siteexport_metaheaders');
38	}
39
40	/**
41	* Check for Template changes
42	**/
43	function siteexport_check_template()
44	{
45		global $conf, $INFO;
46
47		if ( !defined('SITEEXPORT_TPL') ) { return; }
48		$conf['template'] = SITEEXPORT_TPL;
49	}
50
51	function siteexport_check_export(&$event)
52	{
53	    global $conf;
54	    $command = $event->data;
55	    if ($tmp = array_keys($event->data)) { $command = $tmp[0]; }
56	    if ( $command == 'export_siteexport_pdf')
57	    {
58	        $event->data = 'show';
59	        $conf['renderer_xhtml'] = 'siteexport_pdf';
60	    }
61
62	    if ( $command == 'siteexport_addpage' && ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager() ) )
63	    {
64			$event->preventDefault();
65	    }
66	}
67
68	function siteexport_addpage(&$event)
69	{
70		if ( $event->data != 'siteexport_addpage' || ! ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) { return; }
71        if ( ! $functions=& plugin_load('helper', 'siteexport') ) {
72            msg("Can't initialize");
73            return false;
74        }
75
76        $functions->__siteexport_addpage();
77	    $event->preventDefault();
78	}
79
80	function siteexport_add_page_export(&$event)
81	{
82		global $ID;
83
84		if ( ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) {
85			$event->data['items'][] = '<li>' . tpl_link(wl($ID, array('do' => 'siteexport_addpage')), '<span>Export Page</span>',
86												'class="action siteexport_addpage" title="Add page"', 1) . '</li>';
87		}
88	}
89
90	function siteexport_metaheaders(&$event)
91	{
92		if ( defined('SITEEXPORT_TPL') ) {
93
94			$head =& $event->data;
95
96			foreach( $head['script'] as &$script ) {
97				if ( !empty($script['src']) && strstr($script['src'], 'js.php') ) {
98					$script['src'] .= '&template=' . SITEEXPORT_TPL;
99				}
100			}
101		}
102
103		return true;
104	}
105}
106