1<?php 2/** 3 * SHA3SUM Plugin 4 * 5 * @license GPL 3 (http://www.gnu.org/licenses/gpl.html) 6 * @author Georg Schmidt 7 */ 8 9class syntax_plugin_sha3sum extends DokuWiki_Syntax_Plugin { 10 11 // Kind of syntax 12 function getType(){ 13 return 'substition'; 14 } 15 16 // Paragraph type 17 function getPType(){ 18 return 'block'; 19 } 20 21 // sorting order 22 function getSort(){ 23 return -1; 24 } 25 26 // SHA3-Pattern 27 function connectTo($mode) { 28 $this->Lexer->addSpecialPattern('\[\[SHA3:[^]]*\]\]',$mode,'plugin_sha3sum'); 29 } 30 31 // Trim Match 32 function handle($match, $state, $pos, Doku_Handler $handler){ 33 $ret = urlencode(substr($match,7,-2)); // trim {{SHA3> from start and }} from end 34 return $ret; 35 } 36 37 // Render output 38 public function render($mode, Doku_Renderer $renderer, $data) { 39 40 // $data is the result of handle 41 if($mode == 'xhtml'){ 42 43 if (version_compare(phpversion(), '7.2.0', 'ge')) { 44 $hash = hash('sha3-512' , $data); // SHA3 support in php 7.2 45 } 46 else { 47 require_once(realpath(dirname(__FILE__)).'/Sha3.php'); // extenal lib under MIT license 48 $hash = Sha3::hash($data, 512); 49 } 50 $renderer->doc .= 'SHA3-512:<br><p style="font-family: monospace; font-size: initial;">'.substr($hash,0,64).'<br>'.substr($hash,64).'</p>'; 51 52 return true; 53 } 54 return false; 55 } 56} 57 58//Setup VIM: ex: et ts=4 enc=utf-8 : 59