From: dongsheng Date: Thu, 21 Aug 2008 09:27:39 +0000 (+0000) Subject: MDL-13766, boxnet files show as a tree now! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=68e374a6c1b598ecdee97a5003c3b1f205f0a6da;p=moodle.git MDL-13766, boxnet files show as a tree now! --- diff --git a/repository/boxnet/boxlibphp5.php b/repository/boxnet/boxlibphp5.php index f4c24d1135..1b485e8ac6 100755 --- a/repository/boxnet/boxlibphp5.php +++ b/repository/boxnet/boxlibphp5.php @@ -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; diff --git a/repository/boxnet/repository.class.php b/repository/boxnet/repository.class.php index ff20cb5ac8..50685416d3 100755 --- a/repository/boxnet/repository.class.php +++ b/repository/boxnet/repository.class.php @@ -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;