From ed2408e14c89a7e6d08b34341db03028c4c09065 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Wed, 20 Aug 2008 07:26:10 +0000 Subject: [PATCH] MDL-13766, use one api_key for all boxnet instances --- lang/en_utf8/repository.php | 1 + repository/boxnet/repository.class.php | 25 +++++++++++++++++++++++-- repository/flickr/repository.class.php | 1 - repository/lib.php | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index cd301f7622..c03e365fd9 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -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'; diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index 57182258f0..9a2a36ebc8 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -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(){ diff --git a/repository/flickr/repository.class.php b/repository/flickr/repository.class.php index 289535ad13..f8ec9cc1fa 100755 --- a/repository/flickr/repository.class.php +++ b/repository/flickr/repository.class.php @@ -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); diff --git a/repository/lib.php b/repository/lib.php index 9c5dff60a4..76eec57519 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -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; -- 2.39.5