Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option collapse_sub #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 dir
author Jacobus Geluk, Matthias Schulte
email [email protected]
date 2014-07-15
date 2016-06-28
name dir
desc Show content of current namespace, including sub namespaces and/or parent/sibling namespaces, in a table or list.
url http://www.dokuwiki.org/plugin:dir
65 changes: 35 additions & 30 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* - Matthias Schulte
* - Geert Janssens
* - Gerry Weißbach
* - Markus Gschwendt
*/

if(!defined('DOKU_INC')) {
Expand Down Expand Up @@ -334,6 +335,7 @@ function _initOpts($flags) {
$this->opts = array();
$this->opts ["noheader"] = false;
$this->opts ["collapse"] = false;
$this->opts ["collapse_sub"] = false;
$this->opts ["ego"] = false;
$this->opts ["namespacename"] = false;

Expand Down Expand Up @@ -368,6 +370,10 @@ function _initOpts($flags) {
$key = "collapse";
$val = true;
break;
case "collapse_sub":
$key = "collapse_sub";
$val = true;
break;
case "ego":
$key = "ego";
$val = true;
Expand Down Expand Up @@ -576,13 +582,16 @@ function _parseSortKeys() {
function _addFoundPage(&$data, $ns, $id, $type, $level) {
global $ID;
$fqid = $ns.$id; // Fully qualified id...
$nsPathSplit = explode(":", trim($ns, ":"));
$curPathSplit = explode(":", trim(getNS($ID), ":"));
$fqidPathSplit = explode(":", trim(getNS($fqid), ":"));

//
// If this file or directory should be skipped, do so
//
switch($type) {
case "f":
if(($fqid == ':'.$ID) && !$this->opts ["ego"]) // If we found ourself, skip it
if($fqid == ':'.$ID && !$this->opts ["ego"] && $nsPathSplit == $curPathSplit) // If we found ourself, skip it
return false;
$pageName = noNS($id);
if($pageName == $this->start)
Expand All @@ -599,13 +608,23 @@ function _addFoundPage(&$data, $ns, $id, $type, $level) {
}
}
}
unset($keep_page);
if($this->opts ["collapse"]) {
$keep_page = false;
// With collapse, only show:
// - pages within the same namespace as the current page
if($this->_getParentNS($fqid) != $this->_getParentNS($ID)) {
return false;
if($this->_getParentNS($fqid) == $ns) {
$keep_page = true;
}
}
if($this->opts ["collapse_sub"]) {
$keep_page = false;
if(($this->_getParentNS($fqid) == $ns && $id == "start") || $this->opts ["collapse"]) {
$keep_page = true;
}
}
if(isset($keep_page) && !$keep_page) { unset($keep_page); return false; }

$linkid = $fqid;
break;
case "d":
Expand All @@ -617,38 +636,24 @@ function _addFoundPage(&$data, $ns, $id, $type, $level) {
}
}

// Don't add startpages the user isn't authorized to read
if(auth_quickaclcheck(substr($linkid, 1)) < AUTH_READ)
return false;

if($this->opts ["collapse"]) {
// With collapse, only show:
// - sibling namespaces of the current namespace and it's ancestors
$curPathSplit = explode(":", trim(getNS($ID), ":"));
$fqidPathSplit = explode(":", trim(getNS($fqid), ":"));

// Find the last parent namespace that matches
// If there is only one more child namespace in the namespace under evaluation,
// Then this is a sibling of one of the parent namespaces of the current page.
// Siblings are ok, grandchild namespaces and below should be skipped (for collapse).
$clevel = 0;
if(count($curPathSplit) > 0) {
while(($clevel < count($fqidPathSplit) - 1) && ($clevel < count($curPathSplit))) {
if($curPathSplit[$clevel] == $fqidPathSplit[$clevel]) {
$clevel++;
} else {
break;
}
}
}
if(count($fqidPathSplit) > $clevel + 1) {
// With collapse_sub, only show:
// - start pages of the first subnamespace
if($this->opts ["collapse"] || $this->opts ["collapse_sub"]) {
if($this->opts ["collapse"]) $collapselevel = 0;
if($this->opts ["collapse_sub"]) $collapselevel = 1;
if($this->opts ["collapse"] && $this->opts ["collapse_sub"]) $collapselevel = 1;
if(count($nsPathSplit) + $collapselevel < count($fqidPathSplit)) {
return false;
}
}

$linkid = $fqid.$this->start;
break;
}
}
// Don't add pages the user isn't authorized to read
if(auth_quickaclcheck(substr($fqid, 1)) < AUTH_READ)
return false;


// $this->_showDebugMsg ("$level $type $ns$id:");

Expand Down Expand Up @@ -690,7 +695,7 @@ function _searchDir(&$data, $base, $file, $type, $level, $opts) {
return false;
//check ACL
$id = pathID($file);
if(auth_quickaclcheck($id) < AUTH_READ)
if(auth_quickaclcheck(substr($ns.$id,1,-1)) < AUTH_READ)
return false;
$this->_addFoundPage($data, $ns, $id, $type, $level);
}
Expand Down