From 32368e99157ae0d4f1a490c663d244c0d3f4180a Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Mon, 20 Sep 2010 04:00:57 +0000 Subject: [PATCH] REPOSITORY MDL-24205, added more check of path and files --- repository/coursefiles/lib.php | 8 ++++-- .../dropbox/lang/en/repository_dropbox.php | 1 + repository/dropbox/lib.php | 27 ++++++++++++------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/repository/coursefiles/lib.php b/repository/coursefiles/lib.php index 94293785d19..7242f6e53c4 100755 --- a/repository/coursefiles/lib.php +++ b/repository/coursefiles/lib.php @@ -202,8 +202,12 @@ class repository_coursefiles extends repository { } public function get_name() { - global $COURSE; //TODO: this is deprecated (skodak) - return $COURSE->fullname; + list($context, $course, $cm) = get_context_info_array($this->context->id); + if (!empty($course)) { + return get_string('courselegacyfiles') . $course->shortname; + } else { + return get_string('courselegacyfiles'); + } } public function supported_returntypes() { diff --git a/repository/dropbox/lang/en/repository_dropbox.php b/repository/dropbox/lang/en/repository_dropbox.php index dd7acaee5a6..ec2341aa8c7 100755 --- a/repository/dropbox/lang/en/repository_dropbox.php +++ b/repository/dropbox/lang/en/repository_dropbox.php @@ -28,6 +28,7 @@ $string['notitle'] = 'notitle'; $string['remember'] = 'Remember me'; $string['pluginname'] = 'Dropbox'; $string['apikey'] = 'Dropbox API Key'; +$string['sandbox'] = 'Dropbox sandbox'; $string['secret'] = 'Dropbox Secret'; $string['instruction'] = 'You can get your API Key and secret from Dropbox developers'; $string['dropbox:view'] = 'View a Dropbox folder'; diff --git a/repository/dropbox/lib.php b/repository/dropbox/lib.php index 69fdc5c3781..8f5aa6ae6a9 100644 --- a/repository/dropbox/lib.php +++ b/repository/dropbox/lib.php @@ -130,18 +130,27 @@ class repository_dropbox extends repository { } else { $path = file_correct_filepath($path); } - $result = $this->dropbox->get_listing($path, $this->access_key, $this->access_secret); - $current_path = file_correct_filepath($result->path); - if (empty($result->path)) { - $current_path = '/'; - } $list = array(); $list['list'] = array(); + $list['manage'] = false; + $list['dynload'] = true; + $list['nosearch'] = true; // process breacrumb trail $list['path'] = array( - array('name'=>'Dropbox Sandbox', 'path'=>'/') + array('name'=>get_string('sandbox', 'repository_dropbox'), 'path'=>'/') ); + + $result = $this->dropbox->get_listing($path, $this->access_key, $this->access_secret); + if (!is_object($result) || empty($result)) { + return $list; + } + if (empty($result->path)) { + $current_path = '/'; + } else { + $current_path = file_correct_filepath($result->path); + } + $trail = ''; if (!empty($path)) { $parts = explode('/', $path); @@ -156,11 +165,11 @@ class repository_dropbox extends repository { $list['path'][] = array('name'=>$path, 'path'=>$path); } } - $list['manage'] = false; - $list['dynload'] = true; - $list['nosearch'] = true; $files = $result->contents; + if (!is_array($files) || empty($files)) { + return $list; + } foreach ($files as $file) { if ($file->is_dir) { $list['list'][] = array( -- 2.43.0