1<?php 2/** 3 * @license GPL (http://www.gnu.org/licenses/gpl.html) 4 * @author Hans-Juergen Schuemmer 5 * 6 */ 7 8if(!defined('DOKU_INC')) die(); 9 10//if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 11//if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 14require_once DOKU_PLUGIN.'syntax.php'; 15 16class syntax_plugin_instructions extends DokuWiki_Syntax_Plugin { 17 18 function getType() { 19 return 'substition'; 20 } 21 22 function getSort() { 23 return 16; 24 } 25 26 function connectTo($mode) { 27 $this->Lexer->addSpecialPattern('~~INSTR~~.*?~~END~~',$mode,'plugin_instructions'); // Syntax funktioniert zusammen mit Plugin CKGEdit 28 $this->Lexer->addSpecialPattern('{{INSTR<.*?}}',$mode,'plugin_instructions'); // veraltet wegen CKGEdit 29 } 30 31 function handle($match, $state, $pos, Doku_Handler $handler){ 32 33 // aktuelle Seite "@ID@" und "@PAGE@": 34 global $ID, $INFO; 35 $urldoku = DOKU_URL; 36 $urlpage = DOKU_URL."doku.php?id=".$ID; 37 38 $pg_curr = $INFO['id']; 39 if (strrpos($pg_curr,":") > 0) { 40 $pg_curr = substr(strrchr($INFO['id'], ":"), 1); 41 }; 42 $id_curr = $ID; 43 if (strrpos($id_curr,":") > 0) { 44 $id_curr = substr(strrchr($ID, ":"), 1); 45 }; 46 $ns_long = substr(strrchr($urlpage, "="), 1); 47 $ns_long = substr($ns_long,0,strrpos($ns_long,":")); 48 $ns_curr = $ns_long; 49 if (strrpos($ns_long,":") > 0) { 50 $ns_curr = substr(strrchr($ns_long, ":"), 1); 51 }; 52 $ns_main = $INFO['namespace']; // Namespce bei Verwendung in der Sidebar 53 54// echo "ID :", $ID, "<br />"; 55// echo "INFO['id'] :", $INFO['id'], "<br />"; 56// echo "INFO['namespace'] :", $INFO['namespace'], "<br />"; 57// echo "ns_long :", $ns_long, "<br />"; 58// echo "ns_curr :", $ns_curr, "<br />"; 59// echo "ns_main :", $ns_main, "<br />"; 60 61 // Eingabe-Wert verarbeiten 62 $match = str_replace("{{INSTR<", '', $match); 63 $match = str_replace("}}", '', $match); 64 $match = str_replace("~~INSTR~~", '', $match); 65 $match = str_replace("~~END~~", '', $match); 66 67 // Typ des Templates auslesen 68 if (substr_count($match,"~~") > 0) { 69 list($typ) = explode('~~',$match); 70 } else { 71 list($typ) = explode('>',$match); 72 } 73 $typ = strtolower($typ); 74 75 // Zeilenumbruch verarbeiten: 76 $match = str_replace(array("|+"), '<br>', $match); 77 78 // Steuerzeichen im Wiki-Code verarbeiten: 79 //zwei hintereinanderfolgende Leerzeichen sollen als Einrückung ausgegeben werden: 80 $match = str_replace(array(" "), ' ', $match); 81 // Kursivschrift: 82 while (strpos($match, '//') !== false) { 83 $match = preg_replace('/\/\//', '<i>', $match, 1); 84 $match = preg_replace('/\/\//', '</i>', $match, 1); 85 }; 86 // Fettschrift: 87 while (strpos($match, '**') !== false) { 88 $match = preg_replace('/\*\*/', '<b>', $match, 1); 89 $match = preg_replace('/\*\*/', '</b>', $match, 1); 90 }; 91 // Codetext: 92 while (strpos($match, "''") !== false) { 93 $match = preg_replace("/''/", '<code>', $match, 1); 94 $match = preg_replace("/''/", '</code>', $match, 1); 95 }; 96 // Verarbeitung Wiki-Links: 97 while (strpos($match, '[[') !== false) { 98 $s1 = strpos($match, '[[') + 2; 99 $s2 = strpos($match, ']]'); 100 $title = substr($match, $s1, $s2-$s1); 101 $s3 = strpos($title, '|') + 1; 102 $l3 = strlen($title); 103 $title = substr($title, $s3, $l3); 104 $content = substr($match, $s1, $s3-1); 105 $match = str_replace("|".$title, "", $match); 106 $match = preg_replace('/\[\[/', '<a href="'.DOKU_BASE.'/doku.php?id=', $match, 1); 107 $match = preg_replace('/\]\]/', '">'.$title.'</a>', $match, 1); 108 }; 109 110 // Platzhalter für Namensraum und aktuelle Seite: 111 while (strpos($match, '@PAGE@') !== false) { 112 $match = preg_replace('/@PAGE@/', $pg_curr, $match, 1); 113 } 114 while (strpos($match, '@ID@') !== false) { 115 $match = preg_replace('/@ID@/', $id_curr, $match, 1); 116 } 117 while (strpos($match, '@NS@') !== false) { 118 $match = preg_replace('/@NS@/', $ns_long, $match, 1); 119 } 120 while (strpos($match, '@NSMAIN@') !== false) { 121 $match = preg_replace('/@NSMAIN@/', $ns_main, $match, 1); 122 } 123 while (strpos($match, '@CURNS@') !== false) { 124 $match = preg_replace('/@CURNS@/', $ns_curr, $match, 1); 125 } 126 while (strpos($match, '@URL_DOKU@') !== false) { 127 $match = preg_replace('/@URL_DOKU@/', $urldoku, $match, 1); 128 } 129 while (strpos($match, '@URL_PAGE@') !== false) { 130 $match = preg_replace('/@URL_PAGE@/', $urlpage, $match, 1); 131 } 132 133 // Parameter aufspalten: 134 $param = explode('|-',$match); 135 136 $datei='tpl/'.$typ.'/html.txt'; 137 $zeilen = file($datei,true); 138 139 for($i=1; $i<count($zeilen); $i++) { 140 list($p, $z) = explode('-',$zeilen[$i]); 141 $z = (int)$z; 142 if ($p == "param") { 143 // HTML-Zeile enthält Platzhalter für Parameter 144 $tpz = trim($param[$z]); 145 $var = $var.$tpz; 146 } 147 else { 148 // HTML-Zeile enthält Code 149 $z_trim = trim($zeilen[$i]); 150 if ((($z_trim == "<br>") or ($z_trim == "<br />")) and ($tpz == "")) { 151 // falls zuvor kein Parameter übergeben wurde, den ersten nachfolgenden Zeilenumbruch unterdrücken 152 $tpz = "leer"; 153 } 154 else { 155 $var = $var.$z_trim; 156 } 157 } 158 } 159 160 // Übergabe-Wert für Renderer: 161 return $var; 162 } 163 164 function render($mode, Doku_Renderer $renderer, $data) { 165 if($mode == 'xhtml'){ 166 $renderer->doc .= $data; 167 return true; 168 } 169 return false; 170 } 171} 172?> 173