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;
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;