]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-15350, boxnet plug-in worked now"
authordongsheng <dongsheng>
Mon, 30 Jun 2008 07:10:13 +0000 (07:10 +0000)
committerdongsheng <dongsheng>
Mon, 30 Jun 2008 07:10:13 +0000 (07:10 +0000)
repository/boxnet/repository.class.php
repository/lib.php
repository/picker.php

index d66c1f8daf787c1704f0004e47dbd19f1cf2bd60..e88a5425fea9e8db82f7e202961fc99a268ce199 100755 (executable)
@@ -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;
index 96d4bb5f1159a043a88aa8c7006f17ad17944466..109f386ead3c31136a286fc0e68d909d8a08f47f 100644 (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 {
index e5ef9eb5037258ffc57173c6be07317686416ed9..3b137fbe4ee43bc1b59c36944338ab0abc4ee01e 100644 (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>
         <!--