1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Andreas Gohr <gohr@cosmocode.de> 5 */ 6// must be run within Dokuwiki 7if(!defined('DOKU_INC')) die(); 8 9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 10require_once(DOKU_PLUGIN.'syntax.php'); 11 12/** 13 * All DokuWiki plugins to extend the parser/rendering mechanism 14 * need to inherit from this class 15 */ 16class syntax_plugin_cryptsign extends DokuWiki_Syntax_Plugin { 17 18 /** 19 * What kind of syntax are we? 20 */ 21 function getType(){ 22 return 'substition'; 23 } 24 25 /** 26 * What about paragraphs? 27 */ 28 function getPType(){ 29 return 'normal'; 30 } 31 32 /** 33 * Where to sort in? 34 */ 35 function getSort(){ 36 return 155; 37 } 38 39 40 /** 41 * Connect pattern to lexer 42 */ 43 function connectTo($mode) { 44 $this->Lexer->addSpecialPattern('\{\{[^{]+\$\$[a-f0-9]{32}--.+?\$\$\}\}',$mode,'plugin_cryptsign'); 45 } 46 47 48 /** 49 * Handle the match 50 */ 51 function handle($match, $state, $pos, Doku_Handler $handler){ 52 global $ID; 53 54 $match = substr($match,2,-4); 55 $pos = strrpos($match,'$$'); 56 $text = trim(substr($match,0,$pos)); 57 $sig = substr($match,$pos+2,32); 58 $user = substr($match,$pos+36); 59 $check = md5($ID.$user.trim($text).auth_cookiesalt()); 60 return array( 61 'text' => $text, 62 'user' => $user, 63 'valid' => ($sig == $check) 64 ); 65 } 66 67 /** 68 * Create output 69 */ 70 function render($format, Doku_Renderer $R, $data) { 71 if($format != 'xhtml') return false; 72 73 $user = strip_tags(editorinfo($data['user'])); 74 75 if($data['valid']){ 76 $msg = sprintf($this->getLang('valid'),$user); 77 $R->doc .= '<span class="sig_valid" title="'.$msg.'">'; 78 }else{ 79 $msg = sprintf($this->getLang('invalid'),$user); 80 $R->doc .= '<span class="sig_invalid" title="'.$msg.'">'; 81 } 82 83 $R->cdata($data['text']); 84 $R->doc .= '</span>'; 85 86 return true; 87 } 88 89} 90 91//Setup VIM: ex: et ts=4 enc=utf-8 : 92