1<?php 2/** 3 * DokuWiki Plugin acknowledge (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de> 7 */ 8 9class syntax_plugin_acknowledge_listing extends DokuWiki_Syntax_Plugin 10{ 11 /** @inheritDoc */ 12 public function getType() 13 { 14 return 'substition'; 15 } 16 17 /** @inheritDoc */ 18 public function getPType() 19 { 20 return 'block'; 21 } 22 23 /** @inheritDoc */ 24 public function getSort() 25 { 26 return 155; 27 } 28 29 /** @inheritDoc */ 30 public function connectTo($mode) 31 { 32 $this->Lexer->addSpecialPattern('~~ACKNOWLEDGE.*?~~', $mode, 'plugin_acknowledge_listing'); 33 } 34 35 /** @inheritDoc */ 36 public function handle($match, $state, $pos, Doku_Handler $handler) 37 { 38 // check for 'all' parameter 39 $includeDone = strtolower(substr($match, strlen('~~ACKNOWLEDGE '), -2)) === 'all'; 40 return ['includeDone' => $includeDone]; 41 } 42 43 /** @inheritDoc */ 44 public function render($mode, Doku_Renderer $renderer, $data) 45 { 46 if ($mode !== 'xhtml') { 47 return false; 48 } 49 50 $renderer->info['cache'] = false; 51 52 $renderer->doc .= '<div class="plugin-acknowledge-listing">'; 53 $renderer->doc .= $this->getListing($data['includeDone']); 54 $renderer->doc .= '</div>'; 55 return true; 56 } 57 58 /** 59 * Returns the list of pages to be acknowledged by the user, 60 * optionally including past acknowledgments. 61 * 62 * @param bool $includeDone 63 * 64 * @return string 65 */ 66 protected function getListing($includeDone) 67 { 68 global $INPUT; 69 global $USERINFO; 70 71 $user = $INPUT->server->str('REMOTE_USER'); 72 if ($user === '') return ''; 73 74 $groups = $USERINFO['grps']; 75 76 /** @var helper_plugin_acknowledge $helper */ 77 $helper = plugin_load('helper', 'acknowledge'); 78 $items = $helper->getUserAssignments($user, $groups, $includeDone); 79 80 $html = $this->getLang('ackNotFound'); 81 82 if (!empty($items)) { 83 $html = '<ul>'; 84 foreach ($items as $item) { 85 $done = $item['ack'] ? 86 ' <span title="' . sprintf($this->getLang('ackGranted'), dformat($item['ack'])) . '">✔</span>' 87 : ''; 88 $html .= '<li>' . html_wikilink(':' . $item['page']) . $done . '</li>'; 89 } 90 $html .= '</ul>'; 91 } 92 93 return $html; 94 } 95} 96 97