17d101cc1SGerry Weißbach<?php 27d101cc1SGerry Weißbach/** 37d101cc1SGerry Weißbach * Site Export Plugin 47d101cc1SGerry Weißbach * 57d101cc1SGerry Weißbach * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 67d101cc1SGerry Weißbach * @author i-net software <tools@inetsoftware.de> 77d101cc1SGerry Weißbach * @author Gerry Weissbach <gweissbach@inetsoftware.de> 87d101cc1SGerry Weißbach */ 97d101cc1SGerry Weißbach 107d101cc1SGerry Weißbach// must be run within Dokuwiki 11a8c17ab5Si-net /// softwareif (!defined('DOKU_INC')) define('DOKU_INC', /** @scrutinizer ignore-type */ realpath(dirname(__FILE__) . '/../../') . '/'); 127d101cc1SGerry Weißbachif (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 137d101cc1SGerry Weißbach 147d101cc1SGerry Weißbachclass action_plugin_siteexport_startup extends DokuWiki_Action_Plugin { 157d101cc1SGerry Weißbach 167d101cc1SGerry Weißbach /** 177d101cc1SGerry Weißbach * Register Plugin in DW 187d101cc1SGerry Weißbach **/ 193f2e6413SGerry Weißbach public function register(Doku_Event_Handler $controller) { 2016c5261cSGerry Weißbach $controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'siteexport_check_template'); 217d101cc1SGerry Weißbach $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'siteexport_check_template'); 227d101cc1SGerry Weißbach $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'siteexport_check_export'); 2395c3174fSGerry Weißbach $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'siteexport_addpage'); 24b26434b0SGerry Weißbach $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'siteexport_metaheaders'); 25bbafe1f0SGerry Weißbach $controller->register_hook('JS_CACHE_USE', 'BEFORE', $this, 'siteexport_check_js_cache'); 26*992a6e22Si-net /// software 27c7c6980aSGerry Weißbach $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'siteexport_toolbar_define'); 28*992a6e22Si-net /// software 29*992a6e22Si-net /// software $controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'siteexport_add_page_export'); 30*992a6e22Si-net /// software $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'siteexport_add_svg_page_export', array()); 31c7c6980aSGerry Weißbach } 32c7c6980aSGerry Weißbach 33c7c6980aSGerry Weißbach private function hasSiteexportHeaders() { 34c7c6980aSGerry Weißbach $headers = function_exists('getallheaders') ? getallheaders() : null; 35a8c17ab5Si-net /// software return is_array($headers) && array_key_exists('X-Site-Exporter', $headers); 367d101cc1SGerry Weißbach } 377d101cc1SGerry Weißbach 387d101cc1SGerry Weißbach /** 397d101cc1SGerry Weißbach * Check for Template changes 407d101cc1SGerry Weißbach **/ 41a8c17ab5Si-net /// software public function siteexport_check_template() 427d101cc1SGerry Weißbach { 437d101cc1SGerry Weißbach global $conf, $INFO; 440cd3f1b4SGerry Weißbach 45c7c6980aSGerry Weißbach if ( $this->hasSiteexportHeaders() || defined('SITEEXPORT_TPL') ) { 460cd3f1b4SGerry Weißbach // This is a request via the HTTPProxy of the SiteExporter ... set config to what we need here. 470cd3f1b4SGerry Weißbach $conf['useslash'] = 1; 480cd3f1b4SGerry Weißbach } 497d101cc1SGerry Weißbach 507d101cc1SGerry Weißbach if ( !defined('SITEEXPORT_TPL') ) { return; } 517d101cc1SGerry Weißbach $conf['template'] = SITEEXPORT_TPL; 527d101cc1SGerry Weißbach } 537d101cc1SGerry Weißbach 54bbafe1f0SGerry Weißbach /** 55bbafe1f0SGerry Weißbach * Check for Template changes in JS 56bbafe1f0SGerry Weißbach **/ 57a8c17ab5Si-net /// software public function siteexport_check_js_cache(Doku_Event &$event) 58bbafe1f0SGerry Weißbach { 59bbafe1f0SGerry Weißbach global $conf, $INFO; 60bbafe1f0SGerry Weißbach 61bbafe1f0SGerry Weißbach if ( !defined('SITEEXPORT_TPL') ) { return; } 62bbafe1f0SGerry Weißbach $event->data->key .= SITEEXPORT_TPL; 63bbafe1f0SGerry Weißbach $event->data->cache = getCacheName($event->data->key,$event->data->ext); 64bbafe1f0SGerry Weißbach } 65bbafe1f0SGerry Weißbach 66a8c17ab5Si-net /// software public function siteexport_check_export(Doku_Event &$event) 677d101cc1SGerry Weißbach { 687d101cc1SGerry Weißbach global $conf; 69a8c17ab5Si-net /// software $keys = is_array($event->data) ? array_keys($event->data) : null; 70a8c17ab5Si-net /// software $command = is_array($keys) ? array_shift($keys) : $event->data; 71fd385364SGerry Weißbach if ( $command == 'export_siteexport_pdf') 727d101cc1SGerry Weißbach { 737d101cc1SGerry Weißbach $event->data = 'show'; 747d101cc1SGerry Weißbach $conf['renderer_xhtml'] = 'siteexport_pdf'; 75fd385364SGerry Weißbach } 76fd385364SGerry Weißbach 77a8c17ab5Si-net /// software if ( $command == 'siteexport_addpage' && $this->__executeCommand() ) 78fd385364SGerry Weißbach { 7995c3174fSGerry Weißbach $event->preventDefault(); 8095c3174fSGerry Weißbach } 8195c3174fSGerry Weißbach } 8295c3174fSGerry Weißbach 83a8c17ab5Si-net /// software public function siteexport_addpage(Doku_Event &$event) 8495c3174fSGerry Weißbach { 85a8c17ab5Si-net /// software if ( $event->data != 'siteexport_addpage' || ! $this->__executeCommand() ) { return; } 8695c3174fSGerry Weißbach if ( ! $functions=& plugin_load('helper', 'siteexport') ) { 8795c3174fSGerry Weißbach msg("Can't initialize"); 8895c3174fSGerry Weißbach return false; 8995c3174fSGerry Weißbach } 9095c3174fSGerry Weißbach 9195c3174fSGerry Weißbach $functions->__siteexport_addpage(); 9295c3174fSGerry Weißbach $event->preventDefault(); 9395c3174fSGerry Weißbach } 9495c3174fSGerry Weißbach 95a8c17ab5Si-net /// software public function siteexport_add_page_export(Doku_Event &$event) 9695c3174fSGerry Weißbach { 9795c3174fSGerry Weißbach global $ID; 9895c3174fSGerry Weißbach 99a8c17ab5Si-net /// software if ( $this->__executeCommand() ) { 10095c3174fSGerry Weißbach $event->data['items'][] = '<li>' . tpl_link(wl($ID, array('do' => 'siteexport_addpage')), '<span>Export Page</span>', 101259f68e8SGerry Weißbach 'class="action siteexport_addpage" title="Export Page (Siteexport)"', 1) . '</li>'; 102259f68e8SGerry Weißbach 103259f68e8SGerry Weißbach require_once(DOKU_PLUGIN . 'siteexport/inc/functions.php'); 104259f68e8SGerry Weißbach $functions = new siteexport_functions(); 105259f68e8SGerry Weißbach 106259f68e8SGerry Weißbach $check = array(); 10785b8228eSGerry Weißbach $mapIDs = $functions->getMapID($ID, null, $check); 10885b8228eSGerry Weißbach $mapID = array_shift($mapIDs); 109259f68e8SGerry Weißbach if ( !empty($mapID) ) { 110259f68e8SGerry Weißbach $event->data['items'][] = '<li>' . tpl_link('', '<span>Copy Map-ID: <span class="mapID" data-done="Done.">'.$mapID.'</span></span>', 111259f68e8SGerry Weißbach 'class="action siteexport_mapid" title="Show Map-ID"" data-mapid="'.$mapID.'" onclick="copyMapIDToClipBoard.call(this); return false;"', 1) . '</li>'; 112259f68e8SGerry Weißbach } 1137d101cc1SGerry Weißbach } 1147d101cc1SGerry Weißbach } 115b26434b0SGerry Weißbach 116*992a6e22Si-net /// software public function siteexport_add_svg_page_export(Doku_Event $event) { 117*992a6e22Si-net /// software /* if this is not a page OR ckgedit/ckgedoku is not active -> return */ 118*992a6e22Si-net /// software if($event->data['view'] != 'page') return; 119*992a6e22Si-net /// software array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\siteexport\MenuItem()]); 120*992a6e22Si-net /// software } 121*992a6e22Si-net /// software 122a8c17ab5Si-net /// software public function siteexport_metaheaders(Doku_Event &$event) 123b26434b0SGerry Weißbach { 124fc3c50fbSGerry Weißbach global $conf; 125fc3c50fbSGerry Weißbach $template = defined('SITEEXPORT_TPL') ? SITEEXPORT_TPL : $conf['template']; 126b26434b0SGerry Weißbach 127b26434b0SGerry Weißbach $head =& $event->data; 128b26434b0SGerry Weißbach 129b26434b0SGerry Weißbach foreach( $head['script'] as &$script ) { 130b26434b0SGerry Weißbach if ( !empty($script['src']) && strstr($script['src'], 'js.php') ) { 131fc3c50fbSGerry Weißbach $script['src'] .= '&template=' . $template; 132b26434b0SGerry Weißbach } 133b26434b0SGerry Weißbach } 134b26434b0SGerry Weißbach 135b26434b0SGerry Weißbach return true; 136b26434b0SGerry Weißbach } 137c7c6980aSGerry Weißbach 138a8c17ab5Si-net /// software public function siteexport_toolbar_define(Doku_Event &$event) { 139c7c6980aSGerry Weißbach 140c7c6980aSGerry Weißbach if ( $this->hasSiteexportHeaders() ) { 141c7c6980aSGerry Weißbach // Remove Toolbar 142bf4927b7SGerry Weißbach // This is pr 5.4 syntax. 143bf4927b7SGerry Weißbach $event->data = array(); 144c7c6980aSGerry Weißbach } 145c7c6980aSGerry Weißbach } 146a8c17ab5Si-net /// software 147a8c17ab5Si-net /// software private function __executeCommand() { 148a8c17ab5Si-net /// software return ($this->getConf('allowallusers') || auth_isadmin() || auth_ismanager()); 149a8c17ab5Si-net /// software } 1507d101cc1SGerry Weißbach} 151