]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13766, boxnet files show as a tree now!
authordongsheng <dongsheng>
Thu, 21 Aug 2008 09:27:39 +0000 (09:27 +0000)
committerdongsheng <dongsheng>
Thu, 21 Aug 2008 09:27:39 +0000 (09:27 +0000)
repository/boxnet/boxlibphp5.php
repository/boxnet/repository.class.php

index f4c24d1135320b9b5f57175b598beeb4ccaeb2ce..1b485e8ac61994c94a2a5f459cbf7ded07d4a61e 100755 (executable)
@@ -124,7 +124,65 @@ class boxclient {
             throw new repository_exception('invalidtoken', 'repository_boxnet');
         }
     }
+    //
+    function getfiletree($params = array()) {
+        $this->_clearErrors();
+        $params['auth_token'] = $this->auth_token;
+        $params['folder_id']  = 0;
+        $params['api_key']    = $this->api_key;
+        $params['action']     = 'get_account_tree';
+        $params['onelevel']   = 1;
+        $params['params[]']   = 'nozip';
+        if($this->debug){
+            $c = new curl(array('debug'=>true, 'cache'=>true));
+        } else {
+            $c = new curl(array('debug'=>false, 'cache'=>true));
+        }
+        try {
+            $args = array();
+            $xml = $c->get($this->_box_api_url, $params);
+        } catch (Exception $e){
+        }
+        $ret = array();
+        $o = simplexml_load_string($xml);
+        if($o->status == 'listing_ok') {
+            $tree = $o->tree->folder;
+            $this->buildtree($tree, $ret);
+        }
+        return $ret;
+    }
 
+    function buildtree($sax, &$tree){
+        $sax = (array)$sax;
+        foreach($sax as $k=>$v){
+            if($k == 'folders'){
+                $o = $sax[$k];
+                foreach($o->folder as $z){
+                    $tmp = array('title'=>(string)$z->attributes()->name,
+                        'size'=>0, 'date'=>userdate(time()),
+                        'thumbnail'=>'http://www.box.net/img/small_folder_icon.gif');
+                    $tmp['children'] = array();
+                    $this->buildtree($z, $tmp['children']);
+                    $tree[] = $tmp;
+                }
+            } elseif ($k == 'files') {
+                $val = $sax[$k]->file;
+                foreach($val as $file){
+                    $thumbnail = (string)$file->attributes()->thumbnail;
+                    if (!preg_match('#^(?:http://)?([^/]+)#i', $thumbnail)) {
+                        $thumbnail =  'http://www.box.net'.$thumbnail;
+                    }
+                    $tmp = array('title'=>(string)$file->attributes()->file_name,
+                        'size'=>display_size((int)$file->attributes()->size),
+                        'thumbnail'=>$thumbnail,
+                        'date'=>userdate((int)$file->attributes()->updated), 
+                        'source'=>'http://box.net/api/1.0/download/'
+                            .$this->auth_token.'/'.(string)$file->attributes()->id);
+                    $tree[] = $tmp;
+                }
+            }
+        }
+    }
     // Get the file list
     function getAccountTree($params = array()) {
         $params['auth_token'] = $this->auth_token;
index ff20cb5ac8d47fcc074e030e6a74fb8f71b5e4dd..50685416d372d3cee40e08c71cc21f2970201129 100755 (executable)
@@ -95,37 +95,12 @@ class repository_boxnet extends repository{
         global $CFG, $SESSION;
         $list = array();
         $ret  = array();
-        $tree = $this->box->getAccountTree();
+        $tree = $this->box->getfiletree();
         if(!empty($tree)) {
-            $filenames = $tree['file_name'];
-            $fileids   = $tree['file_id'];
-            $filesizes = $tree['file_size'];
-            $filedates = $tree['file_date'];
-            $fileicon  = $tree['thumbnail'];
-            foreach ($filenames as $n=>$v){
-                // do search
-                if(!empty($search)) {
-                    if(strstr($v, $search) !== false) {
-                        $list[] = array('title'=>$v, 
-                                'size'=>$filesizes[$n],
-                                'date'=>$filedates[$n],
-                                'source'=>'http://box.net/api/1.0/download/'
-                                    .$this->options['auth_token'].'/'.$fileids[$n],
-                                'thumbnail'=>$CFG->pixpath.'/f/'.mimeinfo('icon', $v));
-                    }
-                } else {
-                    $list[] = array('title'=>$v, 
-                            'size'=>$filesizes[$n],
-                            'date'=>$filedates[$n],
-                            'source'=>'http://box.net/api/1.0/download/'
-                                .$this->options['auth_token'].'/'.$fileids[$n],
-                            'thumbnail'=>$fileicon[$n]);
-                }
-            }
-
-            $ret['list']   = $list;
+            // TODO: think about how to search
+            $ret['list']   = $tree;
             $ret['manage'] = 'http://www.box.net/files';
-            $this->listing = $list;
+            $this->listing = $tree;
             return $ret;
         } else {
             $sess_name = 'box_token'.$this->id;