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 public function getType() { return 'substition'; } 23 public function getPType() { return 'block'; } 24 public function getSort() { return 300; } 25 26 public 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 public function handle($match, $state, $pos, Doku_Handler $handler) { 32 33 $options = explode(' ', trim(substr($match, 2, -2)?:"")); 34 35 return $options; 36 } 37 38 public function render($mode, Doku_Renderer $renderer, $data) { 39 global $ID, $conf; 40 41 // $isAggregator = (array_shift($data) == 'siteexportAGGREGATOR'); 42 $isAggregator = true; 43 $namespace = array(); 44 foreach( $data as $option ) { 45 46 list($key, $value) = explode('=', $option); 47 if ($key == "namespace") { 48 $ns = $value; 49 if ( substr($value, -1) != ':' ) { 50 $ns .= ':'; 51 } 52 53 // The following function wants an page but we only have an NS at this moment 54 $ns .= 'index'; 55 $namespace[] = $ns; 56 } 57 } 58 59 if ( empty($namespace) ) { 60 $namespace[] = $ID; 61 } 62 63 if ($mode == 'xhtml'){ 64 65 $renderer->info['toc'] = false; 66 $renderer->nocache(); 67 68 $formParams = array( 'id' => sectionID('siteexport_site_aggregator', $this->headers), 'action' => wl($ID), 'class' => 'siteexport aggregator' ); 69 $form = new Doku_Form($formParams); 70 $functions=& plugin_load('helper', 'siteexport'); 71 72 $form->addHidden('ns', $ID); 73 $form->addHidden('site', $ID); 74 75 if ( $isAggregator ) { 76 $form->addHidden('siteexport_aggregate', '1'); 77 } 78 79 $submitLabel = $this->getLang('AggregateSubmitLabel'); 80 $introduction = $this->getLang('AggragateExportPages'); 81 foreach( $data as $option ) { 82 83 list($key, $value) = explode('=', $option); 84 switch ($key) { 85 case "namespace": 86 // Done at the top. 87 break; 88 case "buttonTitle": 89 $submitLabel = urldecode($value); 90 break; 91 case "introduction": 92 $introduction = urldecode($value); 93 break; 94 default: 95 $form->addHidden($key, $value); 96 break; 97 } 98 } 99 100 $values = array(); 101 $allNamespaces = $functions->__getOrderedListOfPagesForID($namespace); 102 foreach( $allNamespaces as $ns ) { 103 if ( !array_key_exists('_'.$ns[2], $values) ) { 104 $values['_'.$ns[2]] = $ns; 105 } else if ( !in_array($ns[0], $values['_'.$ns[2]][4]) ) { 106 $values['_'.$ns[2]][0] .= '|' . $ns[0]; 107 } 108 $values['_'.$ns[2]][4][] = $ns[0]; 109 } 110 111 $values = array_values($values); 112 $renderer->doc .= '<div class="siteaggregator">'; 113 114 if ( empty($values) ) { 115 $renderer->doc .= '<span style="color: #a00">'.$this->getLang('NoEntriesFoundHint').'</span>'; 116 } else { 117 $form->addElement(form_makeMenuField('baseID', $values, isset($_REQUEST['baseID']) ? $_REQUEST['baseID'] : $values[0], $introduction)); 118 $form->addElement(form_makeButton('submit', 'siteexport', $submitLabel, array('class' => 'button download'))); 119 120 ob_start(); 121 $form->printForm(); 122 $renderer->doc .= ob_get_contents(); 123 ob_end_clean(); 124 } 125 126 $renderer->doc .= '</div>'; 127 return true; 128 } else if ($mode == 'metadata') { 129 $renderer->meta['siteexport']['hasaggregator'] = $isAggregator; 130 $renderer->meta['siteexport']['baseID'] = implode('|', $namespace); 131 } 132 133 return false; 134 } 135} 136 137//Setup VIM: ex: et ts=4 enc=utf-8 : 138