]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13766, use one api_key for all boxnet instances
authordongsheng <dongsheng>
Wed, 20 Aug 2008 07:26:10 +0000 (07:26 +0000)
committerdongsheng <dongsheng>
Wed, 20 Aug 2008 07:26:10 +0000 (07:26 +0000)
lang/en_utf8/repository.php
repository/boxnet/repository.class.php
repository/flickr/repository.class.php
repository/lib.php

index cd301f76229cea29e3139efb4dc6dce4e021a413..c03e365fd9cc3d6b2ade4e3e5aede252306bb180 100644 (file)
@@ -23,6 +23,7 @@ $string['listview'] = 'List View';
 $string['logout'] = 'Logout';
 $string['loading'] = 'Loading...';
 $string['manage'] = 'Manage repositories';
+$string['manageurl'] = 'Manage';
 $string['manageuserrepository'] = 'Manage individual repository';
 $string['noenter'] = 'Nothing entered';
 $string['operation'] = 'Operation';
index 57182258f0375a5e1337c1f2d48da0282c647943..9a2a36ebc880e7fe2fcdd53310b09a702657fe81 100755 (executable)
@@ -13,6 +13,24 @@ require_once($CFG->dirroot.'/repository/boxnet/'.'boxlibphp5.php');
 class repository_boxnet extends repository{
     private $box;
 
+    public function set_option($options = array()){
+        $ret = parent::set_option($options);
+        if (!empty($options['api_key'])) {
+            set_config('api_key', $options['api_key'], 'boxnet');
+        }
+        return $ret;
+    }
+
+    public function get_option($config = ''){
+        $options = parent::get_option($config);
+        if($config==='api_key'){
+            return get_config('boxnet', 'api_key');
+        } else {
+            $options['api_key'] = get_config('boxnet', 'api_key');
+        }
+        return $options;
+    }
+
     public function __construct($repositoryid, $context = SITEID, $options = array()){
         global $SESSION, $action;
         $options['username']   = optional_param('boxusername', '', PARAM_RAW);
@@ -22,7 +40,6 @@ class repository_boxnet extends repository{
         parent::__construct($repositoryid, $context, $options);
         $this->api_key = $this->get_option('api_key');
         if (empty($this->api_key)) {
-            throw new repository_exception('invalidapikey', 'repository_boxnet');
         }
         $sess_name = 'box_token'.$this->id;
         // reset session
@@ -175,8 +192,12 @@ class repository_boxnet extends repository{
         return true;
     }
     public function admin_config_form(&$mform) {
+        $api_key = get_config('boxnet', 'api_key');
+        if (empty($api_key)) {
+            $api_key = '';
+        }
         $strrequired = get_string('required');
-        $mform->addElement('text', 'api_key', get_string('apikey', 'repository_boxnet'));
+        $mform->addElement('text', 'api_key', get_string('apikey', 'repository_boxnet'), array('value'=>$api_key));
         $mform->addRule('api_key', $strrequired, 'required', null, 'client');
     }
     public static function get_option_names(){
index 289535ad131b3da0ff80428ba3adfe6d12bb5919..f8ec9cc1fa23fb28edeab8d0e94b8fb71db1e97c 100755 (executable)
@@ -20,7 +20,6 @@ class repository_flickr extends repository{
         parent::__construct($repositoryid, $context, $options);
         $this->api_key = $this->get_option('api_key');
         if (empty($this->api_key)) {
-            throw new repository_exception('invalidapikey', 'repository_flickr');
         }
         $this->flickr = new phpFlickr($this->api_key);
 
index 9c5dff60a452d0bbd2da14c6d9f55cbe6548cd67..76eec575193b61b16d221c82e0b3f215debba5c4 100644 (file)
@@ -1016,6 +1016,7 @@ _client.dynload = function (node, fnLoadComplete){
                     }
                     var oDiv = document.getElementById('repo-opt-$suffix-'
                         +_client.repositoryid);
+                    oDiv.innerHTML = '';
                     var search = null;
                     var logout = null;
                     var mgr = null;