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