diff --git a/repository/remotemoodle/repository.class.php b/repository/remotemoodle/repository.class.php index 6e042d67169..ce5e30654c6 100644 --- a/repository/remotemoodle/repository.class.php +++ b/repository/remotemoodle/repository.class.php @@ -44,32 +44,6 @@ class repository_remotemoodle extends repository { return $this->get_listing(); } - /** - * - * @param $filearea - * @param $path - * @param $visiblename - * @return - */ - private function _encode_path($filearea, $path, $visiblename) { - return array('path'=>serialize(array($filearea, $path)), 'name'=>$visiblename); - } - - /** - * - * @param $path - * @return - */ - private function _decode_path($path) { - $filearea = ''; - $path = ''; - if (($file = unserialize($path)) !== false) { - $filearea = $file[0]; - $path = $file[1]; - } - return array('filearea' => $filearea, 'path' => $path); - } - /** * * @param $search_text @@ -79,7 +53,11 @@ class repository_remotemoodle extends repository { return $this->get_listing('', $search_text); } - private function ensure_environment() { + /** + * + * @global $MNET + */ + private function ensure_environment() { global $MNET; if (empty($MNET)) { @@ -97,24 +75,13 @@ class repository_remotemoodle extends repository { */ public function get_listing($encodedpath = '', $search = '') { global $CFG, $DB, $USER; - $ret = array( - 'path'=>'/var/repo/', - 'manage'=>'http://webmgr.moodle.com', - 'list'=> array( - array('title'=>'filename1', 'date'=>'01/01/2009', 'size'=>'10MB', 'source'=>'http://www.moodle.com/dl.rar'), - array('title'=>'folder2', 'date'=>'01/01/2009', 'size'=>'0', 'children'=>array()) - ) - ); - - $ret['nologin'] = true; require_once($CFG->dirroot . '/mnet/xmlrpc/client.php'); //retrieve the host url $this->ensure_environment(); $host = $DB->get_record('mnet_host',array('id' => $this->options['peer'])); - - + $mnetauth = get_auth_plugin('mnet'); $url = $mnetauth->start_jump_session($host->id, ''); @@ -125,8 +92,7 @@ class repository_remotemoodle extends repository { $client = new mnet_xmlrpc_client(); $client->set_method('system/listFiles'); - $client->add_param($USER->username); - + $client->add_param($USER->username); $client->send($mnet_peer); @@ -135,88 +101,7 @@ class repository_remotemoodle extends repository { return $services; } - /** - * Builds a tree of files, to be used by get_listing(). This function is - * then called recursively. - * - * @param $fileinfo an object returned by file_browser::get_file_info() - * @param $search searched string - * @param $dynamicmode bool no recursive call is done when in dynamic mode - * @param $list - the array containing the files under the passed $fileinfo - * @returns int the number of files found - * - * todo: take $search into account, and respect a threshold for dynamic loading - */ - private function build_tree($fileinfo, $search, $dynamicmode, &$list) { - global $CFG; - - $filecount = 0; - $children = $fileinfo->get_children(); - - foreach ($children as $child) { - $filename = $child->get_visible_name(); - $filesize = $child->get_filesize(); - $filesize = $filesize ? display_size($filesize) : ''; - $filedate = $child->get_timemodified(); - $filedate = $filedate ? userdate($filedate) : ''; - $filetype = $child->get_mimetype(); - - if ($child->is_directory()) { - $path = array(); - $level = $child->get_parent(); - while ($level) { - $params = $level->get_params(); - $path[] = $this->_encode_path($params['filearea'], $params['filepath'], $level->get_visible_name()); - $level = $level->get_parent(); - } - - $tmp = array( - 'title' => $child->get_visible_name(), - 'size' => 0, - 'date' => $filedate, - 'path' => array_reverse($path), - 'thumbnail' => $CFG->pixpath .'/f/folder.gif' - ); - - //if ($dynamicmode && $child->is_writable()) { - // $tmp['children'] = array(); - //} else { - // if folder name matches search, we send back all files contained. - $_search = $search; - if ($search && stristr($tmp['title'], $search) !== false) { - $_search = false; - } - $tmp['children'] = array(); - $_filecount = $this->build_tree($child, $_search, $dynamicmode, $tmp['children']); - if ($search && $_filecount) { - $tmp['expanded'] = 1; - } - - //} - - if (!$search || $_filecount || (stristr($tmp['title'], $search) !== false)) { - $list[] = $tmp; - $filecount += $_filecount; - } - - } else { // not a directory - // skip the file, if we're in search mode and it's not a match - if ($search && (stristr($filename, $search) === false)) { - continue; - } - $list[] = array( - 'title' => $filename, - 'size' => $filesize, - 'date' => $filedate, - 'source' => $child->get_url(), - 'thumbnail' => $CFG->pixpath .'/f/'. mimeinfo_from_type("icon", $filetype) - ); - $filecount++; - } - } - - return $filecount; - } + /** * Download a file