1<?php 2/** 3 * 4 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 5 * @author René Drießel <rene@driessel.de> 6 */ 7 8// must be run within Dokuwiki 9if(!defined('DOKU_INC')) die(); 10 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_crypto extends DokuWiki_Syntax_Plugin { 19 20 function getType() { 21 return 'disabled'; 22 } 23 24 function getPType() { 25 return 'normal'; 26 } 27 28 function getAllowedTypes() { 29 return array(); 30 } 31 32 function getSort() { 33 return 999; 34 } 35 36 function connectTo($mode) { 37 $this->Lexer->addEntryPattern('<decrypt.*?>(?=.*?</decrypt>)', $mode,'plugin_crypto'); 38 } 39 40 function postConnect() { 41 $this->Lexer->addExitPattern('</decrypt>','plugin_crypto'); 42 } 43 44 /** 45 * Handle the match 46 */ 47 function handle($match, $state, $pos, &$handler) { 48 return array($state, trim($match)); 49 } 50 51 function render($mode, &$renderer, $data) { 52 if($mode == 'xhtml') { 53 list($state, $match) = $data; 54 switch ($state) { 55 case DOKU_LEXER_ENTER: 56 if (!is_ssl()) msg($this->getLang("no_ssl"), -1); 57 58 $id = $this->xml_property($match, "id", uniqid("")); 59 $inline = $this->xml_property($match, "inline", "true"); 60 $hint = $this->xml_property($match, "hint", $this->getLang('standard_hint')); 61 $renderer->doc .= '<span>'; 62 $renderer->doc .= '<button class="toolbutton" title="Toogle encryption" onclick="pg_toggle_encryption(this, \''.$id.'\')">'; 63 $renderer->doc .= '<img src="'.DOKU_BASE."lib/plugins/crypto/lock.png".'"/>'; 64 $renderer->doc .= '</button>'; 65 $options = 'id="'.$id.'" class="encrypted" hint="'.$hint.'"'; 66 if ($inline == "true") { 67 $options .= ' inline="true"'; 68 } else { 69 $options .= ' inline="false"'; 70 } 71 72 $renderer->doc .= '<span '.$options.'>'; 73 break; 74 case DOKU_LEXER_UNMATCHED: 75 $renderer->doc .= $match; 76 break; 77 case DOKU_LEXER_EXIT: 78 $renderer->doc .= '</span>'; 79 $renderer->doc .= '</span>'; 80 break; 81 } 82 83 return true; 84 } 85 86 return false; 87 } 88 89 function xml_content($xml) { 90 $pattern = '>(.*)<'; 91 if (ereg($pattern, $xml, $matches)) { 92 return $matches[1]; 93 } 94 95 return ""; 96 } 97 98 function xml_property($xml, $name, $default = "") { 99 // dbglog("xml_property($xml, $name, $default)"); 100 $pattern = $name ."='([^']*)')"; 101 if (ereg($pattern, $xml, $matches)) { 102 return $matches[1]; 103 } 104 105 $pattern = $name .'="([^"]*)"'; 106 if (ereg($pattern, $xml, $matches)) { 107 return $matches[1]; 108 } 109 110 return $default; 111 } 112} 113