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