1<?php 2/** 3 * Siteexport 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 10if (!defined('DOKU_INC')) die(); 11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 12require_once(DOKU_PLUGIN . 'syntax.php'); 13 14/** 15 * All DokuWiki plugins to extend the parser/rendering mechanism 16 * need to inherit from this class 17 */ 18class syntax_plugin_siteexport_aggregate extends DokuWiki_Syntax_Plugin { 19 20 private $headers = array(); 21 22 function getType() { return 'substition'; } 23 function getPType() { return 'block'; } 24 function getSort() { return 300; } 25 26 function connectTo($mode) { 27 // $this->Lexer->addSpecialPattern('\{\{(?=siteexport|siteexportAGGREGATOR).*?\}\}', $mode, 'plugin_siteexport_aggregate'); 28 $this->Lexer->addSpecialPattern('\{\{siteexportAGGREGATOR .*?\}\}', $mode, 'plugin_siteexport_aggregate'); 29 } 30 31 function handle($match, $state, $pos, Doku_Handler $handler) { 32 33 $options = explode(' ', trim(substr($match, 2, -2))); 34 return $options; 35 } 36 37 function render($mode, Doku_Renderer $renderer, $data) { 38 global $ID, $conf; 39 40 // $isAggregator = (array_shift($data) == 'siteexportAGGREGATOR'); 41 $isAggregator = true; 42 $namespace = $ID; 43 foreach( $data as $option ) { 44 45 list($key, $value) = explode('=', $option); 46 if ($key == "namespace") { 47 $namespace = $value; 48 if ( substr($value, -1) != ':' ) { 49 $namespace .= ':'; 50 } 51 52 // The following function wants an page but we only have an NS at this moment 53 $namespace .= 'index'; 54 break; 55 } 56 } 57 58 if ($mode == 'xhtml'){ 59 60 $renderer->info['toc'] = false; 61 $renderer->nocache(); 62 63 $formParams = array( 'id' => sectionID('siteexport_site_aggregator', $this->headers), 'action' => wl($ID), 'class' => 'siteexport aggregator' ); 64 $form = new Doku_Form($formParams); 65 $functions=& plugin_load('helper', 'siteexport'); 66 67 $form->addHidden('ns', $ID); 68 $form->addHidden('site', $ID); 69 70 if ( $isAggregator ) { 71 $form->addHidden('siteexport_aggregate', '1'); 72 } 73 74 $submitLabel = $this->getLang('AggregateSubmitLabel'); 75 $introduction = $this->getLang('AggragateExportPages'); 76 foreach( $data as $option ) { 77 78 list($key, $value) = explode('=', $option); 79 switch ($key) { 80 case "namespace": 81 // Done at the top. 82 break; 83 case "buttonTitle": 84 $submitLabel = urldecode($value); 85 break; 86 case "introduction": 87 $introduction = urldecode($value); 88 break; 89 default: 90 $form->addHidden($key, $value); 91 break; 92 } 93 } 94 95 $values = $functions->__getOrderedListOfPagesForID($namespace); 96 $renderer->doc .= '<div class="siteaggregator">'; 97 98 if ( empty($values) ) { 99 $renderer->doc .= '<span style="color: #a00">'.$this->getLang('NoEntriesFoundHint').'</span>'; 100 } else { 101 $form->addElement(form_makeMenuField('baseID', $values, isset($_REQUEST['baseID']) ? $_REQUEST['baseID'] : $values[0], $introduction)); 102 $form->addElement(form_makeButton('submit', 'siteexport', $submitLabel, array('class' => 'button download'))); 103 104 ob_start(); 105 $form->printForm(); 106 $renderer->doc .= ob_get_contents(); 107 ob_end_clean(); 108 } 109 110 $renderer->doc .= '</div>'; 111 return true; 112 } else if ($mode == 'metadata') { 113 $renderer->meta['siteexport']['hasaggregator'] = $isAggregator; 114 $renderer->meta['siteexport']['baseID'] = $namespace; 115 } 116 117 return false; 118 } 119} 120 121//Setup VIM: ex: et ts=4 enc=utf-8 : 122