diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/media.php | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/inc/media.php b/inc/media.php index bd80db577..db1ca0d57 100644 --- a/inc/media.php +++ b/inc/media.php @@ -1686,18 +1686,36 @@ function media_nstree($ns){ $ns = cleanID($ns); if(empty($ns)){ global $ID; - $ns = dirname(str_replace(':','/',$ID)); - if($ns == '.') $ns =''; + $ns = (string)getNS($ID); } - $ns = utf8_encodeFN(str_replace(':','/',$ns)); + + $ns_dir = utf8_encodeFN(str_replace(':','/',$ns)); $data = array(); - search($data,$conf['mediadir'],'search_index',array('ns' => $ns, 'nofiles' => true)); + search($data,$conf['mediadir'],'search_index',array('ns' => $ns_dir, 'nofiles' => true)); // wrap a list with the root level around the other namespaces array_unshift($data, array('level' => 0, 'id' => '', 'open' =>'true', 'label' => '['.$lang['mediaroot'].']')); + // insert the current ns into the hierarchy if it isn't already part of it + $ns_parts = explode(':', $ns); + $tmp_ns = ''; + $pos = 0; + foreach ($ns_parts as $level => $part) { + if ($tmp_ns) $tmp_ns .= ':'.$part; + else $tmp_ns = $part; + + // find the namespace parts or insert them + while ($data[$pos]['id'] != $tmp_ns) { + if ($pos >= count($data) || ($data[$pos]['level'] <= $level+1 && strnatcmp(utf8_encodeFN($data[$pos]['id']), utf8_encodeFN($tmp_ns)) > 0)) { + array_splice($data, $pos, 0, array(array('level' => $level+1, 'id' => $tmp_ns, 'open' => 'true'))); + break; + } + ++$pos; + } + } + echo html_buildlist($data,'idx','media_nstree_item','media_nstree_li'); } |