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_aggregate extends DokuWiki_Action_Plugin { 16 17 18 private $instructions = null; 19 private $originalID = null; 20 21 /** 22 * Register Plugin in DW 23 **/ 24 public function register(Doku_Event_Handler $controller) { 25 $controller->register_hook('ACTION_HEADERS_SEND', 'BEFORE', $this, 'siteexport_aggregate_prepare'); 26 $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'siteexport_aggregate'); 27 $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'siteexport_aggregate_button', array ()); 28 } 29 30 function siteexport_aggregate_prepare(&$event) 31 { 32 global $ID, $INFO, $conf; 33 34 // Aggregate only if 35 // (1) we did submit a request to do so 36 // (2) this page really has an aggregator and we export as PDF 37 if ( !( isset($_REQUEST['siteexport_aggregate']) || ($INFO['meta']['siteexport']['hasaggregator'] == true && $conf['renderer_xhtml'] == 'siteexport_pdf') ) ) { return true; } 38 39 $exportBase = cleanID($_REQUEST['baseID']); 40 $namespace = empty($exportBase) ? $INFO['meta']['siteexport']['baseID'] : getNs($exportBase); 41 42 $functions = plugin_load('helper', 'siteexport'); 43 $values = $functions->__getOrderedListOfPagesForID($namespace, $exportBase); 44 45 if ( empty($exportBase) ) { 46 list($exportBase) = end( $values ); 47 } 48 49 $this->originalID = (string) $ID; 50 51 // Generate a TOC that can be exported 52 $TOC = "~~NOCACHE~~\n<toc merge mergeheader>\n"; 53 $thema = array(); 54 foreach( $values as $value ) { 55 list($id, $title, $sort) = $value; 56 57 $thema[] = p_get_metadata($id, 'thema', METADATA_RENDER_USING_SIMPLE_CACHE); 58 $TOC .= " * [[{$id}|{$title}]]\n"; 59 } 60 61 $TOC .= "</toc>"; 62 63 // Only get first and last element 64 $thema = array_unique(array(reset($thema), end($thema))); 65 66 $meta = p_read_metadata($ID); 67 $ID = (string) cleanID($ID . '-toc-' . implode('-', array_filter($thema))); 68 69 $meta['current']['thema'] = implode(' - ', array_filter($thema)); 70 p_save_metadata($ID, $meta); 71 72 $this->instructions = $TOC; 73 } 74 75 function siteexport_aggregate(&$event) 76 { 77 global $ID, $INFO; 78 79 if ( empty($this->instructions) ) { return true; } 80 $event->preventDefault(); 81 82 $html = p_render('xhtml', p_get_instructions($this->instructions),$INFO); 83 $html = html_secedit($html,false); 84 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 85 86 @unlink(metaFN($ID, '.meta')); 87 88 $ID = (string) $this->originalID; 89 90 echo $html; 91 return false; 92 } 93 94 /** 95 * Inserts a toolbar button 96 */ 97 function siteexport_aggregate_button(& $event, $param) { 98 $event->data[] = array ( 99 'type' => 'mediapopup', 100 'title' => $this->getLang('toolbarButton'), 101 'icon' => '../../plugins/siteexport/images/toolbar.png', 102 'url' => 'lib/plugins/siteexport/exe/siteexportmanager.php?ns=', 103 'options' => 'width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes', 104 'block' => false, 105 ); 106 } 107}