Skip to content

Commit

Permalink
feature: add syntax to display files other directories
Browse files Browse the repository at this point in the history
{{filelisting>name:space}}
  • Loading branch information
Szymon Olewniczak committed Nov 30, 2018
1 parent 26f1697 commit 89f508d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
4 changes: 1 addition & 3 deletions helper.php
Expand Up @@ -18,11 +18,9 @@ class helper_plugin_filelisting extends DokuWiki_Plugin {
*
* @return string
*/
public function tpl_filelisting($print = true) {
global $ID;
public function tpl_filelisting($ns, $print = true) {
global $lang;

$ns = getNS($ID);
if ($ns == false) {
$ns_string = '[' . $lang['mediaroot'] . ']';
} else {
Expand Down
27 changes: 23 additions & 4 deletions syntax.php
Expand Up @@ -35,7 +35,7 @@ public function getSort() {
* @param string $mode Parser mode
*/
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('{{filelisting}}',$mode,'plugin_filelisting');
$this->Lexer->addSpecialPattern('{{filelisting>?.*?}}',$mode,'plugin_filelisting');
}

/**
Expand All @@ -48,9 +48,26 @@ public function connectTo($mode) {
* @return array Data for the renderer
*/
public function handle($match, $state, $pos, Doku_Handler $handler){
$data = array();
global $ID;
global $conf;

return $data;
$param = substr($match, strlen('{{filelisting'), -strlen('}}'));
$cur_ns = getNS($ID);
//no namespace provided
if (strlen($param) == 0) {
return array($cur_ns);
}
//remove '>' from the path
$ns = substr($param, 1);
$abs_ns = resolve_id($cur_ns, $ns);
$dir = str_replace(':','/',$abs_ns);
$abs_dir = $conf['mediadir'].'/'.utf8_encodeFN($dir);
if (!file_exists($abs_dir)) {
msg("filelisting: No namespace $ns", -1);
return array($cur_ns);
}

return array($abs_ns);
}

/**
Expand All @@ -64,10 +81,12 @@ public function handle($match, $state, $pos, Doku_Handler $handler){
public function render($mode, Doku_Renderer $renderer, $data) {
if($mode != 'xhtml') return false;

list($ns) = $data;

/** @var helper_plugin_filelisting $hlp */
$hlp = plugin_load('helper', 'filelisting');

$renderer->doc .= $hlp->tpl_filelisting(false);
$renderer->doc .= $hlp->tpl_filelisting($ns,false);
return true;
}
}
Expand Down

0 comments on commit 89f508d

Please sign in to comment.