From: dongsheng Date: Mon, 30 Jun 2008 07:10:13 +0000 (+0000) Subject: "MDL-15350, boxnet plug-in worked now" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0f59046fa2af046ef27f7f110d72638580421a87;p=moodle.git "MDL-15350, boxnet plug-in worked now" --- diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index d66c1f8daf..e88a5425fe 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -12,12 +12,20 @@ require_once($CFG->dirroot.'/repository/boxnet/'.'boxlibphp5.php'); class repository_boxnet extends repository{ - var $api_key = 'dmls97d8j3i9tn7av8y71m9eb55vrtj4'; var $box; var $ticket; public function __construct($repositoryid, $context = SITEID, $options = array()){ - $repositoryid = -1; + global $SESSION; + $op = repository_get_option($repositoryid, 1); + $options['api_key'] = $op['api_key']; + $options['auth_token'] = optional_param('auth_token', '', PARAM_RAW); + if(!empty($options['auth_token'])) { + $SESSION->box_token = $options['auth_token']; + } else { + $options['auth_token'] = $SESSION->box_token; + } + $options['api_key'] = 'dmls97d8j3i9tn7av8y71m9eb55vrtj4'; parent::__construct($repositoryid, $context, $options); if(!empty($options['api_key'])){ $this->api_key = $options['api_key']; @@ -40,6 +48,7 @@ class repository_boxnet extends repository{ $ret[] = array('name'=>$v, 'size'=>0, 'date'=>'', 'url'=>'http://box.net/api/1.0/download/'.$this->options['auth_token'].'/'.$fileids[$n]); } + $this->listing = $ret; return $ret; } else { return null; @@ -48,7 +57,10 @@ class repository_boxnet extends repository{ } public function print_login(){ - if($this->box){ + if(!empty($this->box) && !empty($this->options['auth_token'])) { + echo 'View File list'; + return true; + } else if(!empty($this->box)){ // get a ticket from box.net $ticket_return = $this->box->getTicket(); if($this->box->isError()) { @@ -73,9 +85,6 @@ class repository_boxnet extends repository{ if($this->ticket && ($this->options['auth_token'] == '')){ $this->box->getAuthToken($this->ticket); return false; - } else { - echo 'Logged'; - return true; } } else { return false; diff --git a/repository/lib.php b/repository/lib.php index 96d4bb5f11..109f386ead 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -57,6 +57,7 @@ abstract class repository { public $name; public $context; public $repositoryid; + public $listing; /** * Take an array as a parameter, which contains necessary information @@ -127,6 +128,9 @@ abstract class repository { * */ public function print_listing($listing = array(), $print=true) { + if(empty($listing)){ + $listing = $this->get_listing(); + } if (empty($listing)) { $str = ''; } else { diff --git a/repository/picker.php b/repository/picker.php index e5ef9eb503..3b137fbe4e 100644 --- a/repository/picker.php +++ b/repository/picker.php @@ -1,36 +1,28 @@ get_record('course', array('id'=>$courseid))) { - print_error('invalidcourseid'); -} -*/ +$action = optional_param('action', 'check', PARAM_RAW); if(!$repository = $DB->get_record('repository', array('id'=>$id))) { print_error('invalidrepostoryid'); } -require_once($CFG->dirroot.'/repository/'.$repository->repositorytype.'/repository.class.php'); -$classname = 'repository_'.$repository->repositorytype; -$repo = new $classname($id, SITEID, $options); + +if(is_file($CFG->dirroot.'/repository/'.$repository->repositorytype.'/repository.class.php')) { + require_once($CFG->dirroot.'/repository/'.$repository->repositorytype.'/repository.class.php'); + $classname = 'repository_' . $repository->repositorytype; + $repo = new $classname($id, SITEID); +} else { + print_error('invalidplugin', 'repository'); +} + ?> - -File Picker - + + File Picker + @@ -69,7 +61,11 @@ $repo = new $classname($id, SITEID, $options);
print_login(); + if(!empty($action)) { + $repo->print_listing(); + } else { + $repo->print_login(); + } ?>