~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to repository/areafiles/lib.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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->pix_url(file_folder_icon(24))->out(false),
 
93
                    'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->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
                'icon' => $OUTPUT->pix_url(file_file_icon($file, 24))->out(false),
 
110
                'thumbnail' => $OUTPUT->pix_url(file_file_icon($file, 90))->out(false)
 
111
            );
 
112
            if ($file->get_status() == 666) {
 
113
                $node['originalmissing'] = true;
 
114
            }
 
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'];
 
120
            }
 
121
            $ret['list'][] = $node;
 
122
        }
 
123
        $ret['list'] = array_filter($ret['list'], array($this, 'filter'));
 
124
        return $ret;
 
125
    }
 
126
 
 
127
    /**
 
128
     * This plugin only can return link
 
129
     *
 
130
     * @return int
 
131
     */
 
132
    public function supported_returntypes() {
 
133
        return FILE_EXTERNAL;
 
134
    }
 
135
}
 
 
b'\\ No newline at end of file'