Skip to content
Browse files

Merge branch 'MDL-29348-22' of git://github.com/FMCorz/moodle into MO…

…ODLE_22_STABLE
  • Loading branch information...
2 parents b818dfc + b04ba37 commit 0f43c243859fc8a465d859fe66be39f1cd77d820 @stronk7 stronk7 committed Sep 11, 2012
Showing with 27 additions and 7 deletions.
  1. +27 −7 repository/webdav/lib.php
View
34 repository/webdav/lib.php
@@ -92,12 +92,14 @@ public function get_listing($path='', $page = '') {
if (!$this->dav->open()) {
return $ret;
}
+
+ $webdavroot = '/' . trim($this->options['webdav_path'], './@#$ ');
+ if ($webdavroot != '/') {
+ $webdavroot .= '/';
+ }
+
if (empty($path)) {
- if ($this->options['webdav_path'] == '/') {
- $path = '/';
- } else {
- $path = '/' . trim($this->options['webdav_path'], './@#$ ') . '/';
- }
+ $path = $webdavroot;
$dir = $this->dav->ls($path);
} else {
$path = urldecode($path);
@@ -110,9 +112,24 @@ public function get_listing($path='', $page = '') {
$dir = $this->dav->ls($path);
}
+ // Building breadcrumb
+ $pathrel = preg_replace('|^' . preg_quote($webdavroot) . '|', '', $path);
+ if (!empty($pathrel)) {
+ $chunks = preg_split('|/|', trim($pathrel, '/'));
+ for ($i = 0; $i < count($chunks); $i++) {
+ $ret['path'][] = array(
+ 'name' => urldecode($chunks[$i]),
+ 'path' => $webdavroot . join('/', array_slice($chunks, 0, $i+1)). '/'
+ );
+ }
+ }
+
if (!is_array($dir)) {
return $ret;
}
+
+ $files = array();
+ $folders = array();
foreach ($dir as $v) {
if (!empty($v['creationdate'])) {
$ts = $this->dav->iso8601totime($v['creationdate']);
@@ -131,7 +148,7 @@ public function get_listing($path='', $page = '') {
} else {
$title = urldecode($v['href']);
}
- $ret['list'][] = array(
+ $folders[strtoupper($title)] = array(
'title'=>urldecode(basename($title)),
'thumbnail'=>$OUTPUT->pix_url('f/folder-32')->out(false),
'children'=>array(),
@@ -146,7 +163,7 @@ public function get_listing($path='', $page = '') {
$title = urldecode(substr($v['href'], strpos($v['href'], $path)+strlen($path)));
$title = basename($title);
$size = !empty($v['getcontentlength'])? $v['getcontentlength']:'';
- $ret['list'][] = array(
+ $files[strtoupper($title)] = array(
'title'=>$title,
'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 32))->out(false),
'size'=>$size,
@@ -155,6 +172,9 @@ public function get_listing($path='', $page = '') {
);
}
}
+ ksort($files);
+ ksort($folders);
+ $ret['list'] = array_merge($folders, $files);
return $ret;
}
public static function get_instance_option_names() {

0 comments on commit 0f43c24

Please sign in to comment.
Something went wrong with that request. Please try again.