1<?php 2/** 3 * DokuWiki Plugin unblink (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 15 16require_once DOKU_PLUGIN.'syntax.php'; 17 18class syntax_plugin_unblink extends DokuWiki_Syntax_Plugin { 19 function getType() { 20 return 'substition'; 21 } 22 23 function getPType() { 24 return 'normal'; 25 } 26 27 function getSort() { 28 return 150; 29 } 30 31 32 function connectTo($mode) { 33 $this->Lexer->addSpecialPattern('\[\[user>.+?\]\]',$mode,'plugin_unblink'); 34 } 35 36 function handle($match, $state, $pos, Doku_Handler $handler){ 37 $match = trim(substr($match,7,-2)); 38 39 40 list($login,$title) = explode('|',$match,2); 41 42 return compact('login','title'); 43 } 44 45 function render($mode, Doku_Renderer $R, $data) { 46 global $auth; 47 global $conf; 48 extract($data); 49 50 if($mode != 'xhtml' || is_null($auth)){ 51 $R->cdata($title?$title:$login); 52 return true; 53 } 54 55 // fetch userinfo 56 $uinfo = $auth->getUserData($login); 57 58 // nothing found? render as text 59 if(!$uinfo){ 60 $R->cdata($title?$title:$login); 61 return true; 62 } 63 64 if(!$title){ 65 if($this->getConf('usefullname')){ 66 $title = $uinfo['name']; 67 }else{ 68 $title = $login; 69 } 70 } 71 if(!$title) $title = $login; 72 73 if($uinfo['avatar'] && $uinfo['avatar'] != 'gravatar'){ 74 $img = $this->getConf('avatarurl').$uinfo['avatar']; 75 }else{ 76 $img = $this->getConf('gravatar').md5($uinfo['mail']); 77 } 78 79 $R->doc .= '<a href="'.$this->getConf('profileurl').$uinfo['uid'].'" class="unblink_plugin">'; 80 $R->doc .= hsc($title); 81 82 $R->doc .= '<span class="unblink_popup" title="Visit Profile">'; 83 $R->doc .= '<img src="'.hsc($img).'" class="medialeft" width="64" height="64" alt="" />'; 84 $R->doc .= '<b>'.hsc($uinfo['name']).'</b><br />'; 85 if($uinfo['name'] != $login) $R->doc .= '<i>'.hsc($login).'</i><br />'; 86 $R->doc .= '<br />'; 87 $R->doc .= hsc($uinfo['location']); 88 $R->doc .= '</span>'; 89 90 $R->doc .= '</a>'; 91 92 return true; 93 } 94} 95 96// vim:ts=4:sw=4:et:enc=utf-8: 97