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