From e13514d25c3a266f257803b0c35f65252e533852 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Wed, 7 Jun 2023 23:28:45 +0900 Subject: [PATCH 1/6] Add parameter support Add mediawiki-like parameter support --- helper.php | 78 +++++++++++++++++++++++++++++++++++++++++- syntax/placeholder.php | 61 +++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 syntax/placeholder.php diff --git a/helper.php b/helper.php index ebde44f..95681e2 100644 --- a/helper.php +++ b/helper.php @@ -65,6 +65,7 @@ function getMethods() { * Overrides standard values for showfooter and firstseconly settings */ function get_flags($setflags) { + // load defaults $flags = $this->defaults; foreach ($setflags as $flag) { @@ -220,6 +221,9 @@ function get_flags($setflags) { case 'exclude': $flags['exclude'] = $value; break; + case 'parameters': + $flags['parameters'] = $this->_parse_parameter_string($value); + break; } } // the include_content URL parameter overrides flags @@ -228,6 +232,38 @@ function get_flags($setflags) { return $flags; } + /** + * Parse parameter flag value into array, to create 'dictionary' of replace values. + */ + function _parse_parameter_string($value) { + + $param_array = array(); + + $count = 0; + $value = preg_split('/(?_escape_value($value); + } else { + // There's no '=' character: This is unnamed parameter. + $count += 1; + $param_array[strval($count)] = $this->_escape_value($param); + } + } + + return $param_array; + } + + /** + * Escapes '\|', '\&', '\=', '\}' in parameter value. + */ + function _escape_value($value) { + return preg_replace('/\\\\([|&=}])/', '\1', $value); + } + + /** * Returns the converted instructions of a give page/section * @@ -314,7 +350,7 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc $this->adapt_links($ins, $page, $included_pages); - for($i=0; $i<$num; $i++) { + for ($i=0; $i<$num; $i++) { switch($ins[$i][0]) { case 'document_start': case 'document_end': @@ -369,6 +405,44 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc if (!$flags['inline'] && $flags['indent']) $ins[$i][1][1][4] += $lvl; break; + case 'include_placeholder': + if (array_key_exists($ins[$i][1][1][0], $flags['parameters'])) { + + // Call dokuwiki parser to get instructions of included text. + $included_ins = p_get_instructions($flags['parameters'][$ins[$i][1][1][0]]); + + // Get starting and ending position + for ($start=0; $startLexer->addSpecialPattern("{{{.+?}}}", $mode, 'plugin_include_placeholder'); + } + + /** + * Handle syntax matches + * + * @param string $match The current match + * @param int $state The match state + * @param int $pos The position of the match + * @param Doku_Handler $handler The hanlder object + * @return array The instructions of the plugin + */ + function handle($match, $state, $pos, Doku_handler $handler) { + $name = substr($match, 3, -3); // strip markup + return array($name, $pos); + } + + /** + * Skip rendering of template field. + */ + function render($format, Doku_Renderer $renderer, $data) { + return true; + } + +} \ No newline at end of file From d60f957c15567b3fe7ff79b4d503ee57878f4101 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Wed, 7 Jun 2023 23:38:55 +0900 Subject: [PATCH 2/6] Bug fix --- helper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helper.php b/helper.php index 95681e2..a3f22ff 100644 --- a/helper.php +++ b/helper.php @@ -406,6 +406,9 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc $ins[$i][1][1][4] += $lvl; break; case 'include_placeholder': + if (!isset($flags['parameters'])) + break; + if (array_key_exists($ins[$i][1][1][0], $flags['parameters'])) { // Call dokuwiki parser to get instructions of included text. From d341c23bc0c609c785a7bfaa97189a093a44f429 Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Thu, 8 Jun 2023 20:03:20 +0900 Subject: [PATCH 3/6] Update include.php Fix escaping "&" symbol --- syntax/include.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/include.php b/syntax/include.php index 44b803a..d587de9 100644 --- a/syntax/include.php +++ b/syntax/include.php @@ -75,7 +75,7 @@ function handle($match, $state, $pos, Doku_Handler $handler) { $check = false; if (isset($sect)) $sect = sectionID($sect, $check); $level = NULL; - return array($mode, $page, $sect, explode('&', $flags), $level, $pos); + return array($mode, $page, $sect, explode('(? Date: Thu, 8 Jun 2023 20:06:36 +0900 Subject: [PATCH 4/6] Update helper.php Add alias flag to 'parameters' --- helper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/helper.php b/helper.php index a3f22ff..74251e3 100644 --- a/helper.php +++ b/helper.php @@ -222,6 +222,7 @@ function get_flags($setflags) { $flags['exclude'] = $value; break; case 'parameters': + case 'params': $flags['parameters'] = $this->_parse_parameter_string($value); break; } From dff58b4ac0c8db1e778e60bbfa70af9c9387150f Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Mon, 21 Apr 2025 20:17:52 +0900 Subject: [PATCH 5/6] PHP 8.2 fix --- helper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helper.php b/helper.php index 74251e3..d78c898 100644 --- a/helper.php +++ b/helper.php @@ -352,6 +352,9 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc $this->adapt_links($ins, $page, $included_pages); for ($i=0; $i<$num; $i++) { + if (!isset($ins[$i][0])) { + continue; + } switch($ins[$i][0]) { case 'document_start': case 'document_end': From 1d20b075da627973437ac13f29f5e49ea6a261fe Mon Sep 17 00:00:00 2001 From: alexdraconian <78018187+alexdraconian@users.noreply.github.com> Date: Tue, 22 Apr 2025 00:05:37 +0900 Subject: [PATCH 6/6] PHP 8.2 fix Add missing parameters. --- syntax/footer.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syntax/footer.php b/syntax/footer.php index 4be5ac4..fed70aa 100644 --- a/syntax/footer.php +++ b/syntax/footer.php @@ -64,6 +64,8 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) 'target' => $conf['target']['wiki'], 'class' => $class . ' permalink', 'more' => 'rel="bookmark"', + 'pre' => '', + 'suf' => '' ); $xhtml[] = $renderer->_formatLink($link); }