xref: /plugin/siteexport/action/startup.php (revision fd3853649937bf44ced6193f1cf7e968ddbb52d8)
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	}
38
39	/**
40	* Check for Template changes
41	**/
42	function siteexport_check_template()
43	{
44		global $conf, $INFO;
45
46		if ( !defined('SITEEXPORT_TPL') ) { return; }
47		$conf['template'] = SITEEXPORT_TPL;
48	}
49
50	function siteexport_check_export(&$event)
51	{
52	    global $conf;
53	    $command = is_array($event->data) ? array_keys($event->data)[0] : $event->data;
54	    if ( $command == 'export_siteexport_pdf')
55	    {
56	        $event->data = 'show';
57	        $conf['renderer_xhtml'] = 'siteexport_pdf';
58	    }
59
60	    if ( $command == 'siteexport_addpage' && ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager() ) )
61	    {
62			$event->preventDefault();
63	    }
64	}
65
66	function siteexport_addpage(&$event)
67	{
68		if ( $event->data != 'siteexport_addpage' || ! ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) { return; }
69        if ( ! $functions=& plugin_load('helper', 'siteexport') ) {
70            msg("Can't initialize");
71            return false;
72        }
73
74        $functions->__siteexport_addpage();
75	    $event->preventDefault();
76	}
77
78	function siteexport_add_page_export(&$event)
79	{
80		global $ID;
81
82		if ( ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) {
83			$event->data['items'][] = '<li>' . tpl_link(wl($ID, array('do' => 'siteexport_addpage')), '<span>Export Page</span>',
84												'class="action siteexport_addpage" title="Add page"', 1) . '</li>';
85		}
86	}
87}