xref: /plugin/siteexport/action/startup.php (revision 7793901e160da6f92c016cb88713575a75e2af66)
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 = is_array($event->data) ? array_shift(array_keys($event->data)) : $event->data;
55	    if ( $command == 'export_siteexport_pdf')
56	    {
57	        $event->data = 'show';
58	        $conf['renderer_xhtml'] = 'siteexport_pdf';
59	    }
60
61	    if ( $command == 'siteexport_addpage' && ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager() ) )
62	    {
63			$event->preventDefault();
64	    }
65	}
66
67	function siteexport_addpage(&$event)
68	{
69		if ( $event->data != 'siteexport_addpage' || ! ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) { return; }
70        if ( ! $functions=& plugin_load('helper', 'siteexport') ) {
71            msg("Can't initialize");
72            return false;
73        }
74
75        $functions->__siteexport_addpage();
76	    $event->preventDefault();
77	}
78
79	function siteexport_add_page_export(&$event)
80	{
81		global $ID;
82
83		if ( ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) {
84			$event->data['items'][] = '<li>' . tpl_link(wl($ID, array('do' => 'siteexport_addpage')), '<span>Export Page</span>',
85												'class="action siteexport_addpage" title="Add page"', 1) . '</li>';
86		}
87	}
88
89	function siteexport_metaheaders(&$event)
90	{
91		if ( defined('SITEEXPORT_TPL') ) {
92
93			$head =& $event->data;
94
95			foreach( $head['script'] as &$script ) {
96				if ( !empty($script['src']) && strstr($script['src'], 'js.php') ) {
97					$script['src'] .= '&template=' . SITEEXPORT_TPL;
98				}
99			}
100		}
101
102		return true;
103	}
104}
105