Lexer->addSpecialPattern('----+ *approve table *-+\n.*?----+', $mode,'plugin_approve_table'); } function handle($match, $state, $pos, Doku_Handler $handler){ $lines = explode("\n", $match); array_shift($lines); array_pop($lines); $params = [ 'namespace' => '', 'filter' => false, 'states' => $this->states, 'summarize' => true, 'approver' => '' ]; foreach ($lines as $line) { $pair = explode(':', $line, 2); if (count($pair) < 2) { continue; } $key = trim($pair[0]); $value = trim($pair[1]); if ($key == 'states') { $value = array_map('trim', explode(',', $value)); //normalize $value = array_map('strtolower', $value); foreach ($value as $state) { if (!in_array($state, $this->states)) { msg('approve plugin: unknown state "'.$state.'" should be: ' . implode(', ', $this->states), -1); return false; } } } elseif($key == 'filter') { $value = trim($value, '/'); if (preg_match('/' . $value . '/', null) === false) { msg('approve plugin: invalid filter regex', -1); return false; } } elseif ($key == 'summarize') { $value = $value == '0' ? false : true; } elseif ($key == 'namespace') { $value = trim(cleanID($value), ':'); } $params[$key] = $value; } return $params; } /** * Render xhtml output or metadata * * @param string $mode Renderer mode (supported modes: xhtml) * @param Doku_Renderer $renderer The renderer * @param array $data The data from the handler() function * * @return bool If rendering was successful. */ public function render($mode, Doku_Renderer $renderer, $data) { $method = 'render' . ucfirst($mode); if (method_exists($this, $method)) { call_user_func([$this, $method], $renderer, $data); return true; } return false; } /** * Render metadata * * @param Doku_Renderer $renderer The renderer * @param array $data The data from the handler() function */ public function renderMetadata(Doku_Renderer $renderer, $params) { $plugin_name = $this->getPluginName(); $renderer->meta['plugin'][$plugin_name] = []; $renderer->meta['plugin'][$plugin_name]['dynamic_approver'] = $params['approver'] == '$USER$'; $renderer->meta['plugin'][$plugin_name]['approve_table'] = true; } protected function array_equal($a, $b) { return ( is_array($a) && is_array($b) && count($a) == count($b) && array_diff($a, $b) === array_diff($b, $a) ); } public function renderXhtml(Doku_Renderer $renderer, $params) { global $INFO; global $conf; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; if ($params['approver'] == '$USER$') { $params['approver'] = $INFO['client']; } // Output Table $renderer->doc .= '
' . $this->getLang('hdr_page') . ' | '; $renderer->doc .= '' . $this->getLang('hdr_state') . ' | '; $renderer->doc .= '' . $this->getLang('hdr_updated') . ' | '; $renderer->doc .= '' . $this->getLang('hdr_approver') . ' | '; $renderer->doc .= '
---|---|---|---|
'; $renderer->doc .= $curNS; $renderer->doc .= ' '; $renderer->doc .= ' | |||
'; if ($conf['useheading'] == '1') { $heading = p_get_first_heading($id); if ($heading != '') { $renderer->doc .= $heading; } else { $renderer->doc .= $id; } } else { $renderer->doc .= $id; } $renderer->doc .= ' | '; $renderer->doc .= ''.$state. ' '; $user = $auth->getUserData($by); if ($user) { $renderer->doc .= $this->getLang('by'). ' ' . $user['name']; } $renderer->doc .= ' | '; $renderer->doc .= '' . dformat($date) . '';; $renderer->doc .= ' | '; if ($approver) { $user = $auth->getUserData($approver); if ($user) { $renderer->doc .= $user['name']; } else { $renderer->doc .= $approver; } } else { $renderer->doc .= '---'; } $renderer->doc .= ' |
'; $renderer->doc .= $this->getLang('all_approved_ready'); $renderer->doc .= ' | '; $renderer->doc .= ''; $percent = 0; if($all > 0) { $percent = $all_approved_ready * 100 / $all; } $renderer->doc .= $all_approved_ready . ' / ' . $all . sprintf(" (%.0f%%)", $percent); $renderer->doc .= ' | ||
'; $renderer->doc .= $this->getLang('all_approved'); $renderer->doc .= ' | '; $renderer->doc .= ''; $percent = 0; if($all > 0) { $percent = $all_approved * 100 / $all; } $renderer->doc .= $all_approved . ' / ' . $all . sprintf(" (%.0f%%)", $percent); $renderer->doc .= ' |