"MDL-15350, boxnet plug-in worked now"

This commit is contained in:
dongsheng 2008-06-30 07:10:13 +00:00
parent 8231ba1932
commit 0f59046fa2
3 changed files with 37 additions and 28 deletions

View File

@ -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 '<a href="picker.php?id='.$this->repositoryid.'&action=list">View File list</a>';
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;

View File

@ -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 {

View File

@ -1,36 +1,28 @@
<?php
require_once('../config.php');
require_once('lib.php');
// Obtain parameters
$id = required_param('id', PARAM_INT);
$options = repository_get_option($id, 1);
if(!empty($options['required'])) {
foreach($options['required'] as $param){
$options[$param] = optional_param($param, 0, PARAM_RAW);
}
}
$courseid = optional_param('course', 0, PARAM_INT);
$contextid = SITEID;
/*
if (!$course = $DB->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');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
<title>File Picker</title>
<link href="style.css" rel="stylesheet" type="text/css"/>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
<title>File Picker</title>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<table border="0" cellspacing="10" cellpadding="10">
@ -69,7 +61,11 @@ $repo = new $classname($id, SITEID, $options);
</table>
<div>
<?php
$repo->print_login();
if(!empty($action)) {
$repo->print_listing();
} else {
$repo->print_login();
}
?>
</div>
<!--