From bddcd933182e4898d59b8ad0ab2406d7a088cac1 Mon Sep 17 00:00:00 2001 From: jerome Date: Tue, 16 Sep 2008 02:09:35 +0000 Subject: [PATCH] MDL-15350: format code (mostly white spaces) + skeleton for documentation --- repository/boxnet/repository.class.php | 139 ++++++++++++++++++++----- 1 file changed, 113 insertions(+), 26 deletions(-) diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index 0948d0222b..f229614f71 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -10,11 +10,22 @@ require_once($CFG->libdir.'/boxlib.php'); -class repository_boxnet extends repository{ +/** + * + */ +class repository_boxnet extends repository { private $box; - public function __construct($repositoryid, $context = SITEID, $options = array()){ + /** + * + * @global $SESSION + * @param $repositoryid + * @param $context + * @param $options + */ + public function __construct($repositoryid, $context = SITEID, $options = array()) { global $SESSION; + $options['username'] = optional_param('boxusername', '', PARAM_RAW); $options['password'] = optional_param('boxpassword', '', PARAM_RAW); $options['ticket'] = optional_param('ticket', '', PARAM_RAW); @@ -26,21 +37,18 @@ class repository_boxnet extends repository{ $sess_name = 'box_token'.$this->id; $this->sess_name = 'box_token'.$this->id; // do login - if(!empty($options['username']) - && !empty($options['password']) - && !empty($options['ticket']) ) - { + if (!empty($options['username']) && !empty($options['password']) && !empty($options['ticket']) ) { $this->box = new boxclient($this->api_key); - try{ + try { $SESSION->$sess_name = $this->box->getAuthToken($options['ticket'], - $options['username'], $options['password']); + $options['username'], $options['password']); } catch (repository_exception $e) { throw $e; } } // already logged - if(!empty($SESSION->$sess_name)) { - if(empty($this->box)) { + if (!empty($SESSION->$sess_name)) { + if (empty($this->box)) { $this->box = new boxclient($this->api_key, $SESSION->$sess_name); } $this->auth_token = $SESSION->$sess_name; @@ -49,18 +57,35 @@ class repository_boxnet extends repository{ } } - public function check_login(){ + /** + * + * @global $SESSION + * @return + */ + public function check_login() { global $SESSION; + return !empty($SESSION->{$this->sess_name}); } - public function logout(){ + /** + * + * @global $SESSION + * @return + */ + public function logout() { global $SESSION; + unset($SESSION->{$this->sess_name}); return $this->print_login(); } - public function set_option($options = array()){ + /** + * + * @param $options + * @return + */ + public function set_option($options = array()) { if (!empty($options['api_key'])) { set_config('api_key', trim($options['api_key']), 'boxnet'); } @@ -69,8 +94,13 @@ class repository_boxnet extends repository{ return $ret; } - public function get_option($config = ''){ - if($config==='api_key'){ + /** + * + * @param $config + * @return + */ + 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')); @@ -79,7 +109,12 @@ class repository_boxnet extends repository{ return $options; } - public function global_search(){ + /** + * + * @global $SESSION + * @return + */ + public function global_search() { global $SESSION; $sess_name = 'box_token'.$this->id; if (empty($SESSION->$sess_name)) { @@ -89,8 +124,14 @@ class repository_boxnet extends repository{ } } - public function get_login(){ + /** + * + * @global $DB + * @return + */ + public function get_login() { global $DB; + if ($entry = $DB->get_record('repository_instances', array('id'=>$this->id))) { $ret->username = $entry->username; $ret->password = $entry->password; @@ -100,8 +141,18 @@ class repository_boxnet extends repository{ } return $ret; } - public function get_listing($path = '/', $search = ''){ + + /** + * + * @global $CFG + * @global $SESSION + * @param $path + * @param $search + * @return + */ + public function get_listing($path = '/', $search = '') { global $CFG, $SESSION; + $list = array(); $ret = array(); if (!empty($search)) { @@ -112,8 +163,8 @@ class repository_boxnet extends repository{ $filesizes = $tree['file_size']; $filedates = $tree['file_date']; $fileicon = $tree['thumbnail']; - foreach ($filenames as $n=>$v){ - if(strstr($v, $search) !== false) { + foreach ($filenames as $n=>$v) { + if (strstr($v, $search) !== false) { $list[] = array('title'=>$v, 'size'=>$filesizes[$n], 'date'=>$filedates[$n], @@ -127,7 +178,7 @@ class repository_boxnet extends repository{ return $ret; } $tree = $this->box->getfiletree($path); - if(!empty($tree)) { + if (!empty($tree)) { $ret['list'] = $tree; $ret['manage'] = 'http://www.box.net/files'; $ret['path'] = array(array('name'=>'Root', 'path'=>0)); @@ -140,7 +191,11 @@ class repository_boxnet extends repository{ } } - public function print_login(){ + /** + * + * @return + */ + public function print_login() { $t = $this->box->getTicket(); $ret = $this->get_login(); if ($this->options['ajax']) { @@ -165,30 +220,58 @@ class repository_boxnet extends repository{ } } - public function print_search(){ + /** + * + * @return + */ + public function print_search() { return false; } + /** + * + * @return + */ public static function has_admin_config() { return true; } + /** + * + * @return + */ public static function has_instance_config() { return false; } - public static function has_multiple_instances(){ + /** + * + * @return + */ + public static function has_multiple_instances() { return false; } - public static function get_admin_option_names(){ + /** + * + * @return + */ + public static function get_admin_option_names() { return array('api_key'); } - public static function get_instance_option_names(){ + /** + * + * @return + */ + public static function get_instance_option_names() { return array('share_url'); } + /** + * + * @param $ + */ public function admin_config_form(&$mform) { $public_account = get_config('boxnet', 'public_account'); $api_key = get_config('boxnet', 'api_key'); @@ -200,6 +283,10 @@ class repository_boxnet extends repository{ $mform->addRule('api_key', $strrequired, 'required', null, 'client'); } + /** + * + * @param $ + */ public function instance_config_form(&$mform) { //$share_url = get_config('boxnet', 'share_url'); $mform->addElement('text', 'share_url', get_string('shareurl', 'repository_boxnet')); -- 2.39.5