From 520de3434b72ec6eafbf7914dce5df98ab580f2e Mon Sep 17 00:00:00 2001 From: dongsheng Date: Fri, 13 Mar 2009 02:54:28 +0000 Subject: [PATCH] "REPOSITORY/MDL-18520, file system plugin added" --- lang/en_utf8/repository_filesystem.php | 7 ++ repository/filesystem/icon.png | Bin 0 -> 603 bytes repository/filesystem/repository.class.php | 139 +++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 lang/en_utf8/repository_filesystem.php create mode 100644 repository/filesystem/icon.png create mode 100644 repository/filesystem/repository.class.php diff --git a/lang/en_utf8/repository_filesystem.php b/lang/en_utf8/repository_filesystem.php new file mode 100644 index 0000000000..2f41524758 --- /dev/null +++ b/lang/en_utf8/repository_filesystem.php @@ -0,0 +1,7 @@ +A@P?#{r#7~tvR7-DgH>15x$Lk0q^`xiJYQ8;~4ElcHFfw{^N-dp!3h^jm2+;Geh z_&M{X(gTgRi$Z6%zLh**U1z-Qp=-CMr~fm{!;^oC=m$ zWxMghYF@68lb?Gozx=ZNTxz7-^->0(d5+IzTm%1b>2)>jTGuQ;>&0GvPKN8Rr>|vUM5mRlnNxtZet+01@UlW!AHnN#<_J z^_DrF`1kH78~N`Ga-+ZfwmtrM;;K~vp&?UMJS}ASB$5xknRD3ETwsNk(xIApMsxiR zD>G)yVw*b8$Mx5p-aBP9<&+m^GH8yM#dp00i_>zopr0C4;6C;$Ke literal 0 HcmV?d00001 diff --git a/repository/filesystem/repository.class.php b/repository/filesystem/repository.class.php new file mode 100644 index 0000000000..fa0bad3a2a --- /dev/null +++ b/repository/filesystem/repository.class.php @@ -0,0 +1,139 @@ +root_path = trim($this->root_path); + if ($options['ajax']) { + // if created from filepicker + if (empty($this->root_path)) { + $ret = array(); + $ret['msg'] = get_string('invalidpath', 'repository_filesystem'); + $ret['nosearch'] = true; + echo json_encode($ret); + exit; + } else { + if (!is_dir($this->root_path)) { + $ret = array(); + $ret['msg'] = get_string('invalidpath', 'repository_filesystem'); + $ret['nosearch'] = true; + if ($options['ajax']) { + echo json_encode($ret); + exit; + } + } + } + if ($this->root_path{strlen($this->root_path)-1} !== '/') { + $this->root_path .= '/'; + } + } + } + public function get_listing($path = '', $page = '') { + global $CFG; + $list = array(); + $list['list'] = array(); + // process breacrumb trail + $list['path'] = array( + array('name'=>'Root','path'=>'') + ); + $trail = ''; + if (!empty($path)) { + $parts = explode('/', $path); + if (count($parts) > 1) { + foreach ($parts as $part) { + $trail .= ('/'.$part); + $list['path'][] = array('name'=>$part, 'path'=>$trail); + } + } else { + $list['path'][] = array('name'=>$path, 'path'=>$path); + } + $this->root_path .= ($path.'/'); + } + // set options + $list['manage'] = false; + // dynamically loading + $list['dynload'] = true; + // the current path of this list. + // set to true, the login link will be removed + $list['nologin'] = true; + // set to true, the search button will be removed + $list['nosearch'] = true; + if ($dh = opendir($this->root_path)) { + while (($file = readdir($dh)) != false) { + if ( $file != '.' and $file !='..') { + if (filetype($this->root_path.$file) == 'file') { + $list['list'][] = array( + 'title' => $file, + 'source' => $path.'/'.$file, + 'size' => filesize($this->root_path.$file), + 'date' => time(), + 'thumbnail' => $CFG->pixpath .'/f/'. mimeinfo('icon32', $this->root_path.$file) + ); + } else { + if (!empty($path)) { + $current_path = $path . '/'. $file; + } else { + $current_path = $file; + } + $list['list'][] = array( + 'title' => $file, + 'children' => array(), + 'thumbnail' => $CFG->pixpath .'/f/folder-32.png', + 'path' => $current_path + ); + } + } + } + } + return $list; + } + // login + public function check_login() { + return true; + } + // if check_login returns false, + // this function will be called to print a login form. + public function print_login() { + return true; + } + //search + // if this plugin support global search, if this function return + // true, search function will be called when global searching working + public function global_search() { + return false; + } + public function search($text) { + $search_result = array(); + $search_result['list'] = array(); + return $search_result; + } + // move file to local moodle + public function get_file($file, $title = '') { + global $CFG; + if ($file{0} == '/') { + $file = $this->root_path.substr($file, 1, strlen($file)-1); + } + // this is a hack to prevent move_to_file deleteing files + // in local repository + $CFG->repository_no_delete = true; + return $file; + } + + public function logout() { + return true; + } + + public static function get_instance_option_names() { + return array('root_path'); + } + + public function instance_config_form(&$mform) { + $mform->addElement('text', 'root_path', get_string('path', 'repository_filesystem'), array('value'=>'','size' => '40')); + } + + public static function get_type_option_names() { + return array(); + } + public function type_config_form(&$mform) { + } +} -- 2.39.5