Skip to content

Commit

Permalink
Version 0.8.4: rollback removing #ifemp. Not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
nerun committed Dec 15, 2023
1 parent b931152 commit bb587b9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

2023-12-14 v0.8.4:
* Rollback: removed `#ifemp`.

2023-12-09 v0.8.3:
* A better fix for "Uninitialized string offset".

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Plugin for [DokuWiki](https://www.dokuwiki.org), available at [plugin: templater
Maintainer : Daniel Dias Rodrigues
Author : Jonathan Arkell
Current Version : 0.8.3 (2023-12-09)
Current Version : 0.8.4 (2023-12-14)

Want to translate this plugin to your language? Go to [DokuWiki Localization](https://translate.dokuwiki.org/plugin/templater).
2 changes: 1 addition & 1 deletion plugin.info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
base templater
author Daniel Rodrigues ("Nerun") and Jonathan Arkell.
email danieldiasr@gmail.com
date 2023-12-09
date 2023-12-14
name Templater Plugin
desc Displays a wiki page (or a section thereof) within another, with user selectable replacements.
url https://www.dokuwiki.org/plugin:templater
28 changes: 7 additions & 21 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
* Ximin Luo <xl269@cam.ac.uk>
* jack126guy <halfgray7e@gmail.com>
* Turq Whiteside <turq@mage.city>
* @version 0.8.3 (2023-12-09)
* @version 0.8.4 (2023-12-14)
*/

use dokuwiki\File\PageResolver;

define('BEGIN_REPLACE_DELIMITER', '@');
define('END_REPLACE_DELIMITER', '@');
define('CONDITIONAL_CHUNK_DELIMITER', '#ifemp');

require_once('debug.php');

Expand All @@ -45,7 +44,7 @@ function getInfo() {
return array(
'author' => 'Daniel Dias Rodrigues',
'email' => 'danieldiasr@gmail.com',
'date' => '2023-12-09',
'date' => '2023-12-14',
'name' => 'Templater Plugin',
'desc' => 'Displays a wiki page (or a section thereof) within another, with user selectable replacements',
'url' => 'http://www.dokuwiki.org/plugin:templater',
Expand Down Expand Up @@ -164,35 +163,21 @@ function render($mode, Doku_Renderer $renderer, $data) {
// Get the raw file, and parse it into its instructions. This could be cached... maybe.
$rawFile = io_readfile($file);

// Split into chunks
$parts = explode(CONDITIONAL_CHUNK_DELIMITER, $rawFile);

// fill in all known values
if(!empty($data[1]['keys']) && !empty($data[1]['vals'])) {
$parts = str_replace($data[1]['keys'], $data[1]['vals'], $parts);
$rawFile = str_replace($data[1]['keys'], $data[1]['vals'], $rawFile);
}

// replace unmatched substitutions with "" or use DEFAULT_STR from data arguments if exists.
$left_overs = '/'.BEGIN_REPLACE_DELIMITER.'.*'.END_REPLACE_DELIMITER.'/';

if(!empty($data[1]['keys']) && !empty($data[1]['vals'])) {
$def_key = array_search(BEGIN_REPLACE_DELIMITER."DEFAULT_STR".END_REPLACE_DELIMITER, $data[1]['keys']);
if ($def_key) {
// if caller defined a DEFAULT_STR, use that
$DEFAULT_STR = $def_key ? $data[1]['vals'][$def_key] : "";
$parts = preg_replace($left_overs, $DEFAULT_STR, $parts);
}
else {
// otherwise remove any chunk with unmatched @placeholder@s, allowing for conditionally including only populated sections
foreach ($parts as $key => $value) {
if (preg_match($left_overs, $value) != 0) {
unset($parts[$key]);
}
}
}
$DEFAULT_STR = $def_key ? $data[1]['vals'][$def_key] : "";
$rawFile = preg_replace($left_overs, $DEFAULT_STR, $rawFile);
}

$instr = p_get_instructions(implode($parts));
$instr = p_get_instructions($rawFile);

// filter section if given
if ($data[2]) {
Expand Down Expand Up @@ -347,3 +332,4 @@ function _massageReplacers($replacers) {
}
}
?>

0 comments on commit bb587b9

Please sign in to comment.