PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/repository/dropbox/thumbnail.php

http://github.com/moodle/moodle
PHP | 48 lines | 16 code | 6 blank | 26 comment | 5 complexity | cf5f2f1eb343c8922d424c2af694147f MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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. * This script displays one thumbnail of the image in current user's dropbox.
  18. * If {@link repository_dropbox::send_thumbnail()} can not display image
  19. * the default 64x64 filetype icon is returned
  20. *
  21. * @package repository_dropbox
  22. * @copyright 2012 Marina Glancy
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24. */
  25. require(__DIR__.'/../../config.php');
  26. require_once(__DIR__.'/lib.php');
  27. $repoid = optional_param('repo_id', 0, PARAM_INT); // Repository ID
  28. $contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // Context ID
  29. $source = optional_param('source', '', PARAM_TEXT); // File path in current user's dropbox
  30. $thumbnailavailable = isloggedin();
  31. $thumbnailavailable = $thumbnailavailable && $repoid;
  32. $thumbnailavailable = $thumbnailavailable && $source;
  33. $thumbnailavailable = $thumbnailavailable && ($repo = repository::get_repository_by_id($repoid, $contextid));
  34. $thumbnailavailable = $thumbnailavailable && method_exists($repo, 'send_thumbnail');
  35. if ($thumbnailavailable) {
  36. // Try requesting thumbnail and outputting it.
  37. // This function exits if thumbnail was retrieved.
  38. $repo->send_thumbnail($source);
  39. }
  40. // Send default icon for the file type.
  41. $fileicon = file_extension_icon($source, 64);
  42. send_file($CFG->dirroot . '/pix/' . $fileicon . '.png', basename($fileicon) . '.png');