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) this page really has an aggregator and we did submit a request to do so 36 // (2) this page really has an aggregator and we export as PDF 37 if ( !( (!empty($INFO['meta']['siteexport']) && $INFO['meta']['siteexport']['hasaggregator'] == true) && ( isset($_REQUEST['siteexport_aggregate']) || $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 no base given, take the first one from the ordered list. 46 if ( empty($exportBase) ) { 47 // Reset to latest element 48 list($exportBase) = reset( $values ); 49 } 50 51 // If only the one file should be exported, strip it down. 52 if ( !empty($_REQUEST['exportSelectedVersionOnly']) ) { 53 // Strip down values 54 $lookupNS = noNS($namespace) == $conf['start'] ? $namespace : $namespace . ':' . $conf['start']; 55 56 if ( !empty( $_REQUEST['mergecompare_start'] ) && !empty( $_REQUEST['mergecompare_end'] ) ) { 57 $values = $functions->__getOrderedListOfPagesForStartEnd($lookupNS, $_REQUEST['mergecompare_start'], $_REQUEST['mergecompare_end']); 58 } else { 59 $values = $functions->__getOrderedListOfPagesForID($lookupNS, $exportBase); 60 $values = array(end( $values )); // the list above has the $exportBase element at the very end 61 } 62 } 63 64 $this->originalID = (string) $ID; 65 66 // Generate a TOC that can be exported 67 $TOC = "~~NOCACHE~~\n<toc merge mergeheader>\n"; 68 $thema = array(); 69 foreach( $values as $value ) { 70 list($id, $title, $sort) = $value; 71 72 $thema[] = p_get_metadata($id, 'thema', METADATA_RENDER_USING_SIMPLE_CACHE); 73 $TOC .= " * [[{$id}|{$title}]]\n"; 74 } 75 76 $TOC .= "</toc>"; 77 78 // Only get first and last element 79 $thema = array_unique(array(reset($thema), end($thema))); 80 81 $meta = p_read_metadata($ID); 82 $ID = (string) cleanID($ID . '-toc-' . implode('-', array_filter($thema))); 83 84 $meta['current']['thema'] = implode(' - ', array_filter($thema)); 85 p_save_metadata($ID, $meta); 86 87 $this->instructions = $TOC; 88 } 89 90 function siteexport_aggregate(&$event) 91 { 92 global $ID, $INFO; 93 94 if ( empty($this->instructions) ) { return true; } 95 $event->preventDefault(); 96 97 $html = p_render('xhtml', p_get_instructions($this->instructions),$INFO); 98 $html = html_secedit($html,false); 99 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 100 101 @unlink(metaFN($ID, '.meta')); 102 103 $ID = (string) $this->originalID; 104 105 echo $html; 106 return false; 107 } 108 109 /** 110 * Inserts a toolbar button 111 */ 112 function siteexport_aggregate_button(& $event, $param) { 113 $event->data[] = array ( 114 'type' => 'mediapopup', 115 'title' => $this->getLang('toolbarButton'), 116 'icon' => '../../plugins/siteexport/images/toolbar.png', 117 'url' => 'lib/plugins/siteexport/exe/siteexportmanager.php?ns=', 118 'options' => 'width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes', 119 'block' => false, 120 ); 121 } 122}