Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/repository/user/lib.php
Go to the documentation of this file.
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_user 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                 $filepath = clean_param($params['filepath'], PARAM_PATH);;
00056                 $filename = clean_param($params['filename'], PARAM_FILE);
00057             }
00058         } else {
00059             $itemid   = 0;
00060             $filepath = '/';
00061             $filename = null;
00062         }
00063         $filearea = 'private';
00064         $component = 'user';
00065         $itemid  = 0;
00066         $context = get_context_instance(CONTEXT_USER, $USER->id);
00067 
00068         try {
00069             $browser = get_file_browser();
00070 
00071             if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
00072                 $pathnodes = array();
00073                 $level = $fileinfo;
00074                 $params = $fileinfo->get_params();
00075                 while ($level && $params['component'] == 'user' && $params['filearea'] == 'private') {
00076                     $encodedpath = base64_encode(serialize($level->get_params()));
00077                     $pathnodes[] = array('name'=>$level->get_visible_name(), 'path'=>$encodedpath);
00078                     $level = $level->get_parent();
00079                     $params = $level->get_params();
00080                 }
00081                 $ret['path'] = array_reverse($pathnodes);
00082 
00083                 // build file tree
00084                 $children = $fileinfo->get_children();
00085                 foreach ($children as $child) {
00086                     if ($child->is_directory()) {
00087                         $encodedpath = base64_encode(serialize($child->get_params()));
00088                         $node = array(
00089                             'title' => $child->get_visible_name(),
00090                             'size' => 0,
00091                             'date' => '',
00092                             'path' => $encodedpath,
00093                             'children'=>array(),
00094                             'thumbnail' => $OUTPUT->pix_url('f/folder-32')->out(false)
00095                         );
00096                         $list[] = $node;
00097                     } else {
00098                         $encodedpath = base64_encode(serialize($child->get_params()));
00099                         $node = array(
00100                             'title' => $child->get_visible_name(),
00101                             'size' => 0,
00102                             'date' => '',
00103                             'source'=> $encodedpath,
00104                             'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->get_visible_name(), 32))->out(false)
00105                         );
00106                         $list[] = $node;
00107                     }
00108                 }
00109             }
00110         } catch (Exception $e) {
00111             throw new repository_exception('emptyfilelist', 'repository_user');
00112         }
00113         $ret['list'] = $list;
00114         $ret['list'] = array_filter($list, array($this, 'filter'));
00115         return $ret;
00116     }
00117 
00123     public function supported_returntypes() {
00124         return FILE_INTERNAL;
00125     }
00126 
00132     public function has_moodle_files() {
00133         return true;
00134     }
00135 }
 All Data Structures Namespaces Files Functions Variables Enumerations