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