From d68c527f68b5436c4c4c169be93d76737b841de6 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Mon, 15 Sep 2008 09:31:41 +0000 Subject: [PATCH] MDL-13766 1. create logout() and check_login() function 2. Remove the code use global varibal --- repository/boxnet/repository.class.php | 161 ++++++++---------- repository/flickr/repository.class.php | 104 +++++------ repository/flickr_public/repository.class.php | 56 +++--- repository/lib.php | 19 +++ repository/ws.php | 40 +++-- 5 files changed, 177 insertions(+), 203 deletions(-) diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index 6bfe7e2914..e5bea87c42 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -13,37 +13,8 @@ require_once($CFG->libdir.'/boxlib.php'); class repository_boxnet extends repository{ private $box; - public function set_option($options = array()){ - if (!empty($options['api_key'])) { - set_config('api_key', trim($options['api_key']), 'boxnet'); - } - unset($options['api_key']); - $ret = parent::set_option($options); - return $ret; - } - - public function get_option($config = ''){ - if($config==='api_key'){ - return trim(get_config('boxnet', 'api_key')); - } else { - $options['api_key'] = trim(get_config('boxnet', 'api_key')); - } - $options = parent::get_option($config); - return $options; - } - - public function global_search(){ - global $SESSION; - $sess_name = 'box_token'.$this->id; - if (empty($SESSION->$sess_name)) { - return false; - } else { - return true; - } - } - public function __construct($repositoryid, $context = SITEID, $options = array()){ - global $SESSION, $action; + global $SESSION; $options['username'] = optional_param('boxusername', '', PARAM_RAW); $options['password'] = optional_param('boxpassword', '', PARAM_RAW); $options['ticket'] = optional_param('ticket', '', PARAM_RAW); @@ -53,10 +24,7 @@ class repository_boxnet extends repository{ if (empty($this->api_key)) { } $sess_name = 'box_token'.$this->id; - // reset session - if(!empty($reset)) { - unset($SESSION->$sess_name); - } + $this->sess_name = 'box_token'.$this->id; // do login if(!empty($options['username']) && !empty($options['password']) @@ -69,11 +37,6 @@ class repository_boxnet extends repository{ } catch (repository_exception $e) { throw $e; } - if ($SESSION->$sess_name) { - $action = 'list'; - } else { - $action = 'login'; - } } // already logged if(!empty($SESSION->$sess_name)) { @@ -81,13 +44,48 @@ class repository_boxnet extends repository{ $this->box = new boxclient($this->api_key, $SESSION->$sess_name); } $this->auth_token = $SESSION->$sess_name; - if(empty($action)) { - $action = 'list'; - } } else { $this->box = new boxclient($this->api_key); - // print login - $action = 'login'; + } + } + + public function check_login(){ + global $SESSION; + return !empty($SESSION->{$this->sess_name}); + } + + public function logout(){ + global $SESSION; + unset($SESSION->{$this->sess_name}); + return $this->print_login(); + } + + public function set_option($options = array()){ + if (!empty($options['api_key'])) { + set_config('api_key', trim($options['api_key']), 'boxnet'); + } + unset($options['api_key']); + $ret = parent::set_option($options); + return $ret; + } + + public function get_option($config = ''){ + if($config==='api_key'){ + return trim(get_config('boxnet', 'api_key')); + } else { + $options['api_key'] = trim(get_config('boxnet', 'api_key')); + } + $options = parent::get_option($config); + return $options; + } + + public function global_search(){ + global $SESSION; + $sess_name = 'box_token'.$this->id; + if (empty($SESSION->$sess_name)) { + return false; + } else { + return true; } } @@ -143,56 +141,31 @@ class repository_boxnet extends repository{ } public function print_login(){ - if(!empty($this->options['auth_token'])) { - if($this->options['ajax']){ - return $this->get_listing(); - } else { - // format file list and - // print list - } - } else { - $t = $this->box->getTicket(); - if(empty($this->options['auth_token'])) { - $ret = $this->get_login(); - $str = ''; - $str .= '
'; - $str .= ''; - $str .= ''; - $str .= '