summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorMichael Hamann <michael@content-space.de>2013-02-16 18:06:47 +0100
committerMichael Hamann <michael@content-space.de>2013-02-16 18:29:32 +0100
commitdd90013a5a9ce204250f4d94072e089f617e09db (patch)
treec5810130dac5b91f917294cc1190d608aad4818d /inc
parent71f791fff9c3912682e5e0c8866e695a0749aa82 (diff)
downloadrpg-dd90013a5a9ce204250f4d94072e089f617e09db.tar.gz
rpg-dd90013a5a9ce204250f4d94072e089f617e09db.tar.bz2
Media manager: don't create empty namespaces FS#2642
Previously the media manager created an empty namespace whenever you opened a non-existing namespace with upload permissions. Now the current namespace is only displayed in the tree but not actually created.
Diffstat (limited to 'inc')
-rw-r--r--inc/media.php26
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');
}