Skip to content

Commit

Permalink
Merge pull request #6 from rolfik/master
Browse files Browse the repository at this point in the history
New variables: NSL, PAGEL, SMONTH, SDAY
  • Loading branch information
lpaulsen93 committed Sep 4, 2020
2 parents 2be9c4a + c48fe43 commit 910e265
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
4 changes: 2 additions & 2 deletions plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# General Plugin Info do not edit
base var
author Gina Häußge, Michael Klier, Esther Brunner, Luis Machuca Bezzaza
author Gina Häußge, Michael Klier, Esther Brunner, Luis Machuca Bezzaza, Marek Ištvánek
email dokuwiki@chimeric.de
date 2017-06-11
date 2020-03-23
name Variable Plugin
desc Insert dynamic variables.
url http://www.dokuwiki.org/plugin:var
39 changes: 36 additions & 3 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
return array($match);
}

function wikiLink($id, $namespace = false)
{
if ($namespace)
$id = getNS($id);
$link = wl($id, '', true);
if ($namespace)
$link .= '/';
return $link;
}

function render($mode, Doku_Renderer $renderer, $data) {
global $ID;
global $INFO;
Expand All @@ -41,6 +51,7 @@ function render($mode, Doku_Renderer $renderer, $data) {
$aliasSep = $meta[$length-1];
$meta = $part;
}
$metadata = $mode == 'metadata';
$nocache = false;
switch ($meta) {
case 'ID':
Expand All @@ -51,10 +62,22 @@ function render($mode, Doku_Renderer $renderer, $data) {
$xhtml = getNS($ID);
$meta = $xhtml;
break;
case 'NSL':
$meta = $this->wikiLink($ID, true);
$nocache = true;
if (!$metadata)
$renderer->externallink($meta);
break;
case 'PAGE':
$xhtml = strtr(noNS($ID),'_',' ');
$meta = $xhtml;
break;
case 'PAGEL':
$meta = $this->wikiLink($ID);
$nocache = true;
if (!$metadata)
$renderer->externallink($meta);
break;
case 'USER':
$xhtml = $_SERVER['REMOTE_USER'];
$nocache = true;
Expand All @@ -80,11 +103,20 @@ function render($mode, Doku_Renderer $renderer, $data) {
break;
case 'MONTH':
$xhtml = date('m');
$nocache = true;
break;
case 'SMONTH':
$xhtml = date('n');
$nocache = true;
break;
case 'DAY':
$xhtml = date('d');
$nocache = true;
break;
case 'SDAY':
$xhtml = date('j');
$nocache = true;
break;
case 'WIKI':
$xhtml = $conf['title'];
break;
Expand Down Expand Up @@ -113,11 +145,12 @@ function render($mode, Doku_Renderer $renderer, $data) {
break;
}

if ($mode == 'metadata') {
if ($metadata) {
$renderer->cdata($meta);
} else {
$renderer->cdata($xhtml);

if ($xhtml != null) {
$renderer->cdata($xhtml);
}
if ($nocache) {
$renderer->nocache();
}
Expand Down

0 comments on commit 910e265

Please sign in to comment.