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 public function register(Doku_Event_Handler $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 $controller->register_hook('JS_CACHE_USE', 'BEFORE', $this, 'siteexport_check_js_cache'); 28 } 29 30 /** 31 * Check for Template changes 32 **/ 33 function siteexport_check_template() 34 { 35 global $conf, $INFO; 36 37 $headers = function_exists('getallheaders') ? getallheaders() : null; 38 39 if ( is_array($headers) && array_key_exists('X-Site-Exporter', $headers) && $headers['X-Site-Exporter'] = getSecurityToken() || defined('SITEEXPORT_TPL') ) { 40 // This is a request via the HTTPProxy of the SiteExporter ... set config to what we need here. 41 $conf['useslash'] = 1; 42 } 43 44 if ( !defined('SITEEXPORT_TPL') ) { return; } 45 $conf['template'] = SITEEXPORT_TPL; 46 } 47 48 /** 49 * Check for Template changes in JS 50 **/ 51 function siteexport_check_js_cache(&$event) 52 { 53 global $conf, $INFO; 54 55 if ( !defined('SITEEXPORT_TPL') ) { return; } 56 $event->data->key .= SITEEXPORT_TPL; 57 $event->data->cache = getCacheName($event->data->key,$event->data->ext); 58 } 59 60 function siteexport_check_export(&$event) 61 { 62 global $conf; 63 $command = is_array($event->data) ? array_shift(array_keys($event->data)) : $event->data; 64 if ( $command == 'export_siteexport_pdf') 65 { 66 $event->data = 'show'; 67 $conf['renderer_xhtml'] = 'siteexport_pdf'; 68 } 69 70 if ( $command == 'siteexport_addpage' && ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager() ) ) 71 { 72 $event->preventDefault(); 73 } 74 } 75 76 function siteexport_addpage(&$event) 77 { 78 if ( $event->data != 'siteexport_addpage' || ! ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) { return; } 79 if ( ! $functions=& plugin_load('helper', 'siteexport') ) { 80 msg("Can't initialize"); 81 return false; 82 } 83 84 $functions->__siteexport_addpage(); 85 $event->preventDefault(); 86 } 87 88 function siteexport_add_page_export(&$event) 89 { 90 global $ID; 91 92 if ( ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()) ) { 93 $event->data['items'][] = '<li>' . tpl_link(wl($ID, array('do' => 'siteexport_addpage')), '<span>Export Page</span>', 94 'class="action siteexport_addpage" title="Add page"', 1) . '</li>'; 95 } 96 } 97 98 function siteexport_metaheaders(&$event) 99 { 100 global $conf; 101 $template = defined('SITEEXPORT_TPL') ? SITEEXPORT_TPL : $conf['template']; 102 103 $head =& $event->data; 104 105 foreach( $head['script'] as &$script ) { 106 if ( !empty($script['src']) && strstr($script['src'], 'js.php') ) { 107 $script['src'] .= '&template=' . $template; 108 } 109 } 110 111 return true; 112 } 113} 114