*/ final class syntax_plugin_today extends SyntaxPlugin { /** * @return string Syntax mode type */ public function getType(): string { return 'substition'; } /** * @return string Paragraph type */ public function getPType(): string { return 'normal'; } /** * @return int Sort order - Low numbers go before high numbers */ public function getSort(): int { return 1000; } /** * Connect lookup pattern to lexer. * * @param string $mode Parser mode */ public function connectTo($mode): void { $this->Lexer->addSpecialPattern('\{today.*?\}', $mode, 'plugin_today'); } /** * Handle matches of the today syntax * * @param string $match The match of the syntax * @param int $state The state of the handler * @param int $pos The position in the document * @param Doku_Handler $handler The handler * * @return array Data for the renderer */ public function handle($match, $state, $pos, Doku_Handler $handler): array { $data = []; $namespace = trim(substr($match, strlen('{today'), -1)); $data['namespace'] = $namespace; return $data; } /** * 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): bool { if ($mode !== 'xhtml') { return false; } $today = date('Y-m-d'); $pageId = $data['namespace'] . ':' . $today; $renderer->internallink($pageId, 'today'); return true; } }