1<?php 2/** 3 * Syntax Plugin: 4 * 5 * This plugin lists all users from the given groups in a tabel. 6 * Syntax: {{groupusers[|nomail]>group1[,group2[,group3...]]}} 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Dominik Eckelmann <eckelmann@cosmocode.de> 10 */ 11 12use dokuwiki\Extension\SyntaxPlugin; 13 14class syntax_plugin_groupusers extends DokuWiki_Syntax_Plugin { 15 16 /** 17 * What kind of syntax are we? 18 */ 19 function getType(){ 20 return 'substition'; 21 } 22 23 /** 24 * What about paragraphs? 25 */ 26 function getPType(){ 27 return 'normal'; 28 } 29 30 /** 31 * Where to sort in? 32 */ 33 function getSort(){ 34 return 160; 35 } 36 37 function connectTo($mode) { 38 $this->Lexer->addSpecialPattern('\{\{groupusers\>[^}]*?\}\}',$mode,'plugin_groupusers'); 39 $this->Lexer->addSpecialPattern('\{\{groupusers\|nomail\>[^}]*?\}\}',$mode,'plugin_groupusers'); 40 } 41 42 function handle($match, $state, $pos, Doku_Handler $handler){ 43 $match = substr($match,13,-2); 44 $data = []; 45 46 if (substr($match, 0, 7) == 'nomail>') { 47 $match = substr($match, 7); 48 $data['nomail'] = true; 49 } 50 51 $data['grps'] = explode(',', $match); 52 return $data; 53 } 54 55 function render($mode, Doku_Renderer $renderer, $data) { 56 global $auth; 57 global $lang; 58 59 if (!method_exists($auth,"retrieveUsers")) return false; 60 61 if($mode != 'xhtml') return false; 62 63 $users = array(); 64 if (empty($data['grps'])) $data['grps'] = $data[0]; // ensures backward compatibility to cached data 65 foreach ($data['grps'] as $grp) { 66 $grp = trim($grp); 67 $getuser = $auth->retrieveUsers(0,-1,array('grps'=>'^'.preg_quote($grp,'/').'$')); 68 $users = array_merge($users,$getuser); 69 } 70 71 $renderer->doc .= '<table class="inline">'; 72 $renderer->doc .= '<tr>'; 73 $renderer->doc .= '<th>'.$lang['user'].'</th>'; 74 $renderer->doc .= '<th>'.$lang['fullname'].'</th>'; 75 76 if (empty($data['nomail'])) { 77 $renderer->doc .= '<th>'.$lang['email'].'</th>'; 78 } 79 80 $renderer->doc .= '</tr>'; 81 foreach ($users as $user => $info) { 82 $renderer->doc .= '<tr>'; 83 $renderer->doc .= '<td>'.htmlspecialchars($user).'</td>'; 84 $renderer->doc .= '<td>'.hsc($info['name']).'</td>'; 85 86 if (empty($data['nomail'])) { 87 $renderer->doc .= '<td>'; 88 $renderer->emaillink($info['mail']); 89 $renderer->doc .= '</td>'; 90 } 91 92 $renderer->doc .= '</tr>'; 93 } 94 $renderer->doc .= '</table>'; 95 return true; 96 } 97} 98