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, $INPUT; 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) && ( $INPUT->has( 'siteexport_aggregate' ) || $conf['renderer_xhtml'] == 'siteexport_pdf' ) ) ) { return true; } 33 34 $exportBase = cleanID( $INPUT->str('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 ( $INPUT->bool('exportSelectedVersionOnly' ) ) { 48 // Strip down values 49 $lookupNS = noNS($namespace) == $conf['start'] ? $namespace : $namespace . ':' . $conf['start']; 50 51 if ( $INPUT->has( 'mergecompare_start' ) && $INPUT->has( 'mergecompare_end' ) ) { 52 $values = $functions->__getOrderedListOfPagesForStartEnd($lookupNS, $INPUT->int( 'mergecompare_start' ), $INPUT->int( '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 if( $INPUT->bool('includeSelectedVersion', true, true ) && count( $values ) > 1 ) { 60 array_pop( $values ); // Remove last entry which is the selected version, but only if more than one entry exists 61 } 62 63 $originalID = (string) $ID; 64 65 // Generate a TOC that can be exported 66 $TOC = "<toc merge mergeheader>\n"; 67 $thema = array(); 68 foreach( $values as $value ) { 69 list($id, $title, $sort) = $value; 70 71 $thema[] = p_get_metadata($id, 'thema', METADATA_RENDER_USING_SIMPLE_CACHE); 72 $TOC .= " * [[{$id}|{$title}]]\n"; 73 } 74 75 $TOC .= "</toc>"; 76 77 // Only get first and last element 78 $thema = array_reverse(array_unique(array(reset($thema), end($thema)))); 79 80 $meta = p_read_metadata($originalID); 81 // Temporary ID for rendering a document. 82 $ID = (string) cleanID($originalID . '-toc-' . implode('-', array_filter($thema))); 83 84 $meta['current']['thema'] = implode(' - ', array_filter($thema)); 85 p_save_metadata($originalID, $meta); 86 p_save_metadata($ID, $meta); 87 88 if (empty($TOC)) { return true; } 89 $event->preventDefault(); 90 91 $html = p_render('xhtml', p_get_instructions($TOC), $INFO); 92 // $html = html_secedit($html,false); 93 if ($INFO['prependTOC']) $html = tpl_toc(true) . $html; 94 95 @unlink(metaFN($ID, '.meta')); 96 97 $ID = (string) $originalID; 98 echo $html; 99 return true; 100 } 101 102 /** 103 * Inserts a toolbar button 104 */ 105 function siteexport_aggregate_button(& $event, $param) { 106 $event->data[] = array ( 107 'type' => 'mediapopup', 108 'title' => $this->getLang('toolbarButton'), 109 'icon' => '../../plugins/siteexport/images/toolbar.png', 110 'url' => 'lib/plugins/siteexport/exe/siteexportmanager.php?ns=', 111 'options' => 'width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes', 112 'block' => false, 113 ); 114 } 115} 116