REPOSITORY MDL-24205, added more check of path and files
authorDongsheng Cai <unoter@gmail.com>
Mon, 20 Sep 2010 04:00:57 +0000 (04:00 +0000)
committerDongsheng Cai <unoter@gmail.com>
Mon, 20 Sep 2010 04:00:57 +0000 (04:00 +0000)
repository/coursefiles/lib.php
repository/dropbox/lang/en/repository_dropbox.php
repository/dropbox/lib.php

index 9429378..7242f6e 100755 (executable)
@@ -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() {
index dd7acae..ec2341a 100755 (executable)
@@ -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 <a href="http://www.dropbox.com/developers/apps">Dropbox developers</a>';
 $string['dropbox:view'] = 'View a Dropbox folder';
index 69fdc5c..8f5aa6a 100644 (file)
@@ -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(