*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); function startswith($haystack, $needle) { return $needle === "" || strpos($haystack, $needle) === 0; } function wf_render_link($ns, $page, $onclick, $text) { $exists = false; resolve_pageid('wf', $page, $exists); $exists = $exists ? '1' : '2'; return "$text"; } function wf_render_criteria($criteria) { $data = ''; foreach ($criteria as $name => $value) { $data .= $name . '=' . $value . ':'; } return trim($data, ':'); } class syntax_plugin_workflow_decision extends DokuWiki_Syntax_Plugin { public function getType() { return 'formatting'; } public function getPType() { return 'block'; } public function getSort() { return 196; } public function connectTo($mode) { $this->Lexer->addEntryPattern('(?=.*?)',$mode,'plugin_workflow_decision'); } public function postConnect() { $this->Lexer->addExitPattern('','plugin_workflow_decision'); } public function handle($match, $state, $pos, &$handler){ $data = array($state, $match); return $data; } public function render($mode, &$renderer, $indata) { if($mode != 'xhtml') return false; if (empty($indata)) return false; list($state, $data) = $indata; global $INFO; include DOKU_INC . 'lib/plugins/workflow/wfversion.php'; $wfns = trim($this->getConf('WorkflowNamespace')); switch ($state) { case DOKU_LEXER_ENTER: // get the attributes $numattrs = preg_match_all('/([\w\d]+)="([\w\d, \/_-]+)"/', $data, $matches); $attrs = array(); for ($i = 0; $i < $numattrs; $i++) { $attrs[$matches[1][$i]] = $matches[2][$i]; } $renderer->doc .= ''; $renderer->doc .= '
'; $renderer->doc .= ''; $renderer->doc .= ' workflow version ' . $workflow_plugin_version . '
'; $renderer->doc .= ''; break; case DOKU_LEXER_UNMATCHED: // foreach decision link $lines = explode("\n *", $data); foreach ($lines as $rawline) { // parse the line $line = trim($rawline); if ($line == '') continue; $tokens = preg_split('/(\|| \+| -| \?)/', $line, NULL, PREG_SPLIT_DELIM_CAPTURE); // get the page name and link text $page = trim($tokens[0]); $text = in_array('|', $tokens) ? trim($tokens[2]) : $page; $options_index = in_array('|', $tokens) ? 3 : 1; // the index of the first option // process new workflow state and criteria for the link $criteria = array(); $onclick = ''; for ($i = $options_index; $i+1 < count($tokens); $i += 2) { list($name, $value) = array_map('trim', explode('=', $tokens[$i+1])); if ($tokens[$i] == ' +' && $name != NULL && $value != NULL) { $onclick .= 'wfRemember(\'' . $name . '\',\'' . $value . '\');'; } else if ($tokens[$i] == ' -' && $name != NULL) { $onclick .= 'wfForget(\'' . $name . '\');'; } else if ($tokens[$i] == ' ?' && $name != NULL && $value != NULL) { $criteria[$name] = $value; } } $renderer->doc .= ""; } break; case DOKU_LEXER_EXIT: $renderer->doc .= '
" . wf_render_link($wfns, $page, $onclick, $text) . "
'; break; default: $renderer->doc .= '!!!Renderer default case!!!'; } return true; } }