* @author Adrian Lang * @author Dominik Eckelmann */ class syntax_plugin_do_dolist extends DokuWiki_Syntax_Plugin { /** @inheritDoc */ public function getType() { return 'substition'; } /** @inheritDoc */ public function getPType() { return 'block'; } /** @inheritDoc */ public function getSort() { return 155; } /** @inheritDoc */ public function connectTo($mode) { $this->Lexer->addSpecialPattern('{{dolist>.*?}}', $mode, 'plugin_do_dolist'); } /** * Handler to prepare matched data for the rendering process * * @param string $match The text matched by the patterns * @param int $state The lexer state for the match * @param int $pos The character position of the matched text * @param Doku_Handler $handler Reference to the Doku_Handler object * * @return array Return an array with all data you want to use in render() */ public function handle($match, $state, $pos, Doku_Handler $handler) { // parse the given match $match = substr($match, 9, -2); // usability enhance // // if there is no ? but a & the user has probably forgot the ? befor the first arg. // in this case we'll replace the first & to a ? if (strpos($match, '?') === false) { $pos = strpos($match, '&'); if (is_int($pos)) { $match[$pos] = '?'; } } $url = explode('?', $match, 2); $ns = $url[0]; $args = array(); // check the arguments if (isset($url[1])) { parse_str($url[1], $args); // check for filters $filters = array_keys($args); foreach ($filters as $filter) { if (isset($args[$filter])) { $args[$filter] = explode(',', $args[$filter]); $c = count($args[$filter]); for ($i = 0; $i < $c; $i++) { $args[$filter][$i] = trim($args[$filter][$i]); } } } } $args['ns'] = $ns; return $args; } /** * Create output * * @param string $mode output format being rendered * @param Doku_Renderer $R reference to the current renderer object * @param array $data data created by handler() * * @return bool */ public function render($mode, Doku_Renderer $R, $data) { if ($mode != 'xhtml') { return false; } $R->info['cache'] = false; /** @var helper_plugin_do $hlp */ $hlp = plugin_load('helper', 'do'); $tasks = $hlp->loadTasks($data); if (count($tasks) === 0) { $R->tablerow_open(); $R->tablecell_open(6, 'center'); $R->cdata($this->getLang('none')); $R->tablecell_close(); $R->tablerow_close(); $R->doc .= ''; return true; } $R->doc .= $this->buildTasklistHTML($tasks, isset($data['user']), isset($data['creator'])); return true; } /** * @param array $tasks * @param bool $hideUser * @param bool $hideCreator * * @return string */ public function buildTasklistHTML(array $tasks, $hideUser, $hideCreator) { $userstyle = $hideUser ? ' style="display: none;"' : ''; $creatorstyle = $hideCreator ? ' style="display: none;"' : ''; $table = ''; $table .= ' '; $table .= ' '; $table .= ' ' . $this->getLang('user') . ''; $table .= ' '; $table .= ' '; $table .= ' ' . $this->getLang('creator') . ''; $table .= ' '; $table .= ' '; global $ID; /** @var helper_plugin_do $hlp */ $hlp = plugin_load('helper', 'do'); foreach ($tasks as $row) { $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ' '; } $table .= '
' . $this->getLang('task') . '' . $this->getLang('date') . '' . $this->getLang('status') . '' . $this->lang['js']['popup_msg'] . '
'; $table .= '' . hsc($row['text']) . ''; $table .= ''; foreach ($row['users'] as &$user) { $user = $hlp->getPrettyUser($user); } unset($user); $table .= implode(', ', $row['users']); $table .= '' . hsc($row['date']) . ''; // task status icon... $image = ($row['status']) ? 'done.png' : 'undone.png'; $editor = ($row['closedby']) ? $hlp->getPrettyUser($row['closedby']) : ''; $table .= ''; // outer span // img link $table .= ''; $table .= ''; $table .= ''; $table .= '' . $editor . ''; $table .= ''; // outer span end $table .= ''; $table .= $hlp->getPrettyUser($row['creator']); $table .= ''; $table .= hsc($row['msg']); $table .= '
'; return $table; } }