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 <type> $SESSION
+ * @param <type> $repositoryid
+ * @param <type> $context
+ * @param <type> $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);
$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;
}
}
- public function check_login(){
+ /**
+ *
+ * @global <type> $SESSION
+ * @return <type>
+ */
+ public function check_login() {
global $SESSION;
+
return !empty($SESSION->{$this->sess_name});
}
- public function logout(){
+ /**
+ *
+ * @global <type> $SESSION
+ * @return <type>
+ */
+ public function logout() {
global $SESSION;
+
unset($SESSION->{$this->sess_name});
return $this->print_login();
}
- public function set_option($options = array()){
+ /**
+ *
+ * @param <type> $options
+ * @return <type>
+ */
+ public function set_option($options = array()) {
if (!empty($options['api_key'])) {
set_config('api_key', trim($options['api_key']), 'boxnet');
}
return $ret;
}
- public function get_option($config = ''){
- if($config==='api_key'){
+ /**
+ *
+ * @param <type> $config
+ * @return <type>
+ */
+ 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'));
return $options;
}
- public function global_search(){
+ /**
+ *
+ * @global <type> $SESSION
+ * @return <type>
+ */
+ public function global_search() {
global $SESSION;
$sess_name = 'box_token'.$this->id;
if (empty($SESSION->$sess_name)) {
}
}
- public function get_login(){
+ /**
+ *
+ * @global <type> $DB
+ * @return <type>
+ */
+ 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;
}
return $ret;
}
- public function get_listing($path = '/', $search = ''){
+
+ /**
+ *
+ * @global <type> $CFG
+ * @global <type> $SESSION
+ * @param <type> $path
+ * @param <type> $search
+ * @return <type>
+ */
+ public function get_listing($path = '/', $search = '') {
global $CFG, $SESSION;
+
$list = array();
$ret = array();
if (!empty($search)) {
$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],
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));
}
}
- public function print_login(){
+ /**
+ *
+ * @return <type>
+ */
+ public function print_login() {
$t = $this->box->getTicket();
$ret = $this->get_login();
if ($this->options['ajax']) {
}
}
- public function print_search(){
+ /**
+ *
+ * @return <type>
+ */
+ public function print_search() {
return false;
}
+ /**
+ *
+ * @return <type>
+ */
public static function has_admin_config() {
return true;
}
+ /**
+ *
+ * @return <type>
+ */
public static function has_instance_config() {
return false;
}
- public static function has_multiple_instances(){
+ /**
+ *
+ * @return <type>
+ */
+ public static function has_multiple_instances() {
return false;
}
- public static function get_admin_option_names(){
+ /**
+ *
+ * @return <type>
+ */
+ public static function get_admin_option_names() {
return array('api_key');
}
- public static function get_instance_option_names(){
+ /**
+ *
+ * @return <type>
+ */
+ public static function get_instance_option_names() {
return array('share_url');
}
+ /**
+ *
+ * @param <type> $
+ */
public function admin_config_form(&$mform) {
$public_account = get_config('boxnet', 'public_account');
$api_key = get_config('boxnet', 'api_key');
$mform->addRule('api_key', $strrequired, 'required', null, 'client');
}
+ /**
+ *
+ * @param <type> $
+ */
public function instance_config_form(&$mform) {
//$share_url = get_config('boxnet', 'share_url');
$mform->addElement('text', 'share_url', get_string('shareurl', 'repository_boxnet'));