2
// This file is part of Moodle - http://moodle.org/
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18
* Class repository_areafiles
20
* @package repository_areafiles
21
* @copyright 2013 Marina Glancy
22
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
defined('MOODLE_INTERNAL') || die();
27
require_once($CFG->dirroot . '/repository/lib.php');
30
* Main class responsible for files listing in repostiory_areafiles
32
* @package repository_areafiles
33
* @copyright 2013 Marina Glancy
34
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
class repository_areafiles extends repository {
38
* Areafiles plugin doesn't require login, so list all files
42
public function print_login() {
43
return $this->get_listing();
50
* @param string $path not used by this plugin
53
public function get_listing($path = '', $page = '') {
54
global $USER, $OUTPUT;
55
$itemid = optional_param('itemid', 0, PARAM_INT);
56
$env = optional_param('env', 'filepicker', PARAM_ALPHA);
63
if (empty($itemid) || $env !== 'editor') {
67
// In the most cases files embedded in textarea do not have subfolders. Do not show path by default.
68
$retpath = array(array('name' => get_string('files'), 'path' => ''));
70
$pathchunks = preg_split('|/|', trim($path, '/'));
71
foreach ($pathchunks as $i => $chunk) {
74
'path' => '/'. join('/', array_slice($pathchunks, 0, $i + 1)). '/'
77
$ret['path'] = $retpath; // Show path if already inside subfolder.
80
$context = context_user::instance($USER->id);
81
$fs = get_file_storage();
82
$files = $fs->get_directory_files($context->id, 'user', 'draft', $itemid,
83
empty($path) ? '/' : $path, false, true);
84
foreach ($files as $file) {
85
if ($file->is_directory()) {
87
'title' => basename($file->get_filepath()),
88
'path' => $file->get_filepath(),
89
'children' => array(),
90
'datemodified' => $file->get_timemodified(),
91
'datecreated' => $file->get_timecreated(),
92
'icon' => $OUTPUT->pix_url(file_folder_icon(24))->out(false),
93
'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false)
95
$ret['list'][] = $node;
96
$ret['path'] = $retpath; // Show path if subfolders exist.
99
$fileurl = moodle_url::make_draftfile_url($itemid, $file->get_filepath(), $file->get_filename());
101
'title' => $file->get_filename(),
102
'size' => $file->get_filesize(),
103
'source' => $fileurl->out(),
104
'datemodified' => $file->get_timemodified(),
105
'datecreated' => $file->get_timecreated(),
106
'author' => $file->get_author(),
107
'license' => $file->get_license(),
108
'isref' => $file->is_external_file(),
109
'icon' => $OUTPUT->pix_url(file_file_icon($file, 24))->out(false),
110
'thumbnail' => $OUTPUT->pix_url(file_file_icon($file, 90))->out(false)
112
if ($file->get_status() == 666) {
113
$node['originalmissing'] = true;
115
if ($imageinfo = $file->get_imageinfo()) {
116
$node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified()));
117
$node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
118
$node['image_width'] = $imageinfo['width'];
119
$node['image_height'] = $imageinfo['height'];
121
$ret['list'][] = $node;
123
$ret['list'] = array_filter($ret['list'], array($this, 'filter'));
128
* This plugin only can return link
132
public function supported_returntypes() {
133
return FILE_EXTERNAL;
b'\\ No newline at end of file'