weekly release 3.3.7+
[moodle.git] / repository / dropbox / thumbnail.php
blobdb1bd7bb6a25ff6ce67ed10d1a86770f604c928b
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This script displays one thumbnail of the image in current user's dropbox.
20 * If {@link repository_dropbox::send_thumbnail()} can not display image
21 * the default 64x64 filetype icon is returned
23 * @package repository_dropbox
24 * @copyright 2012 Marina Glancy
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require(__DIR__.'/../../config.php');
29 require_once(__DIR__.'/lib.php');
31 $repoid = optional_param('repo_id', 0, PARAM_INT); // Repository ID
32 $contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // Context ID
33 $source = optional_param('source', '', PARAM_TEXT); // File path in current user's dropbox
35 $thumbnailavailable = isloggedin();
36 $thumbnailavailable = $thumbnailavailable && $repoid;
37 $thumbnailavailable = $thumbnailavailable && $source;
38 $thumbnailavailable = $thumbnailavailable && ($repo = repository::get_repository_by_id($repoid, $contextid));
39 $thumbnailavailable = $thumbnailavailable && method_exists($repo, 'send_thumbnail');
40 if ($thumbnailavailable) {
41 // Try requesting thumbnail and outputting it.
42 // This function exits if thumbnail was retrieved.
43 $repo->send_thumbnail($source);
46 // Send default icon for the file type.
47 $fileicon = file_extension_icon($source, 64);
48 send_file($CFG->dirroot . '/pix/' . $fileicon . '.png', basename($fileicon) . '.png');