|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00028 class repository_local extends repository { 00029 00034 public function print_login() { 00035 return $this->get_listing(); 00036 } 00037 00044 public function get_listing($encodedpath = '') { 00045 global $CFG, $USER, $OUTPUT; 00046 $ret = array(); 00047 $ret['dynload'] = true; 00048 $ret['nosearch'] = true; 00049 $ret['nologin'] = true; 00050 $list = array(); 00051 00052 if (!empty($encodedpath)) { 00053 $params = unserialize(base64_decode($encodedpath)); 00054 if (is_array($params)) { 00055 $component = is_null($params['component']) ? NULL : clean_param($params['component'], PARAM_COMPONENT); 00056 $filearea = is_null($params['filearea']) ? NULL : clean_param($params['filearea'], PARAM_AREA); 00057 $itemid = is_null($params['itemid']) ? NULL : clean_param($params['itemid'], PARAM_INT); 00058 $filepath = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH);; 00059 $filename = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE); 00060 $context = get_context_instance_by_id(clean_param($params['contextid'], PARAM_INT)); 00061 } 00062 } else { 00063 $itemid = null; 00064 $filename = null; 00065 $filearea = null; 00066 $filepath = null; 00067 $component = null; 00068 if (!empty($this->context)) { 00069 list($context, $course, $cm) = get_context_info_array($this->context->id); 00070 $courseid = is_object($course) ? $course->id : SITEID; 00071 $context = get_context_instance(CONTEXT_COURSE, $courseid); 00072 } else { 00073 $context = get_system_context(); 00074 } 00075 } 00076 00077 $browser = get_file_browser(); 00078 00079 if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) { 00080 // build path navigation 00081 $pathnodes = array(); 00082 $encodedpath = base64_encode(serialize($fileinfo->get_params())); 00083 $pathnodes[] = array('name'=>$fileinfo->get_visible_name(), 'path'=>$encodedpath); 00084 $level = $fileinfo->get_parent(); 00085 while ($level) { 00086 $encodedpath = base64_encode(serialize($level->get_params())); 00087 $pathnodes[] = array('name'=>$level->get_visible_name(), 'path'=>$encodedpath); 00088 $level = $level->get_parent(); 00089 } 00090 if (!empty($pathnodes) && is_array($pathnodes)) { 00091 $pathnodes = array_reverse($pathnodes); 00092 $ret['path'] = $pathnodes; 00093 } 00094 // build file tree 00095 $children = $fileinfo->get_children(); 00096 foreach ($children as $child) { 00097 if ($child->is_directory()) { 00098 if ($child->is_empty_area()) { 00099 continue; 00100 } 00101 $params = $child->get_params(); 00102 $encodedpath = base64_encode(serialize($params)); 00103 // hide user_private area from local plugin, user should 00104 // use private file plugin to access private files 00105 //if ($params['filearea'] == 'user_private') { 00106 //continue; 00107 //} 00108 $node = array( 00109 'title' => $child->get_visible_name(), 00110 'size' => 0, 00111 'date' => '', 00112 'path' => $encodedpath, 00113 'children'=>array(), 00114 'thumbnail' => $OUTPUT->pix_url('f/folder-32')->out(false) 00115 ); 00116 $list[] = $node; 00117 } else { 00118 $encodedpath = base64_encode(serialize($child->get_params())); 00119 $node = array( 00120 'title' => $child->get_visible_name(), 00121 'size' => 0, 00122 'date' => '', 00123 'source'=> $encodedpath, 00124 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->get_visible_name(), 32))->out(false) 00125 ); 00126 $list[] = $node; 00127 } 00128 } 00129 } else { 00130 // if file doesn't exist, build path nodes root of current context 00131 $pathnodes = array(); 00132 $fileinfo = $browser->get_file_info($context, null, null, null, null, null); 00133 $encodedpath = base64_encode(serialize($fileinfo->get_params())); 00134 $pathnodes[] = array('name'=>$fileinfo->get_visible_name(), 'path'=>$encodedpath); 00135 $level = $fileinfo->get_parent(); 00136 while ($level) { 00137 $encodedpath = base64_encode(serialize($level->get_params())); 00138 $pathnodes[] = array('name'=>$level->get_visible_name(), 'path'=>$encodedpath); 00139 $level = $level->get_parent(); 00140 } 00141 if (!empty($pathnodes) && is_array($pathnodes)) { 00142 $pathnodes = array_reverse($pathnodes); 00143 $ret['path'] = $pathnodes; 00144 } 00145 $list = array(); 00146 } 00147 $ret['list'] = array_filter($list, array($this, 'filter')); 00148 return $ret; 00149 } 00150 00156 public function supported_returntypes() { 00157 return FILE_INTERNAL; 00158 } 00159 00165 public function has_moodle_files() { 00166 return true; 00167 } 00168 }