1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
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.
|
|
|
8 |
//
|
|
|
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Class repository_areafiles
|
|
|
19 |
*
|
|
|
20 |
* @package repository_areafiles
|
|
|
21 |
* @copyright 2013 Marina Glancy
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
require_once($CFG->dirroot . '/repository/lib.php');
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Main class responsible for files listing in repostiory_areafiles
|
|
|
31 |
*
|
|
|
32 |
* @package repository_areafiles
|
|
|
33 |
* @copyright 2013 Marina Glancy
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class repository_areafiles extends repository {
|
|
|
37 |
/**
|
|
|
38 |
* Areafiles plugin doesn't require login, so list all files
|
|
|
39 |
*
|
|
|
40 |
* @return mixed
|
|
|
41 |
*/
|
|
|
42 |
public function print_login() {
|
|
|
43 |
return $this->get_listing();
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Get file listing
|
|
|
48 |
*
|
|
|
49 |
* @param string $path
|
|
|
50 |
* @param string $path not used by this plugin
|
|
|
51 |
* @return mixed
|
|
|
52 |
*/
|
|
|
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);
|
|
|
57 |
$ret = array(
|
|
|
58 |
'dynload' => true,
|
|
|
59 |
'nosearch' => true,
|
|
|
60 |
'nologin' => true,
|
|
|
61 |
'list' => array(),
|
|
|
62 |
);
|
|
|
63 |
if (empty($itemid) || $env !== 'editor') {
|
|
|
64 |
return $ret;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
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' => ''));
|
|
|
69 |
if (!empty($path)) {
|
|
|
70 |
$pathchunks = preg_split('|/|', trim($path, '/'));
|
|
|
71 |
foreach ($pathchunks as $i => $chunk) {
|
|
|
72 |
$retpath[] = array(
|
|
|
73 |
'name' => $chunk,
|
|
|
74 |
'path' => '/'. join('/', array_slice($pathchunks, 0, $i + 1)). '/'
|
|
|
75 |
);
|
|
|
76 |
}
|
|
|
77 |
$ret['path'] = $retpath; // Show path if already inside subfolder.
|
|
|
78 |
}
|
|
|
79 |
|
|
|
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()) {
|
|
|
86 |
$node = array(
|
|
|
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->image_url(file_folder_icon())->out(false),
|
|
|
93 |
'thumbnail' => $OUTPUT->image_url(file_folder_icon())->out(false)
|
|
|
94 |
);
|
|
|
95 |
$ret['list'][] = $node;
|
|
|
96 |
$ret['path'] = $retpath; // Show path if subfolders exist.
|
|
|
97 |
continue;
|
|
|
98 |
}
|
|
|
99 |
$fileurl = moodle_url::make_draftfile_url($itemid, $file->get_filepath(), $file->get_filename());
|
|
|
100 |
$node = array(
|
|
|
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 |
'iscontrolledlink' => $file->is_controlled_link(),
|
|
|
110 |
'icon' => $OUTPUT->image_url(file_file_icon($file))->out(false),
|
|
|
111 |
'thumbnail' => $OUTPUT->image_url(file_file_icon($file))->out(false)
|
|
|
112 |
);
|
|
|
113 |
if ($file->get_status() == 666) {
|
|
|
114 |
$node['originalmissing'] = true;
|
|
|
115 |
}
|
|
|
116 |
if ($imageinfo = $file->get_imageinfo()) {
|
|
|
117 |
$node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified()));
|
|
|
118 |
$node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
|
|
|
119 |
$node['image_width'] = $imageinfo['width'];
|
|
|
120 |
$node['image_height'] = $imageinfo['height'];
|
|
|
121 |
}
|
|
|
122 |
$ret['list'][] = $node;
|
|
|
123 |
}
|
|
|
124 |
$ret['list'] = array_filter($ret['list'], array($this, 'filter'));
|
|
|
125 |
return $ret;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* This plugin only can return link
|
|
|
130 |
*
|
|
|
131 |
* @return int
|
|
|
132 |
*/
|
|
|
133 |
public function supported_returntypes() {
|
|
|
134 |
return FILE_EXTERNAL;
|
|
|
135 |
}
|
|
|
136 |
}
|