PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/groups/icon.php

https://github.com/fragilbert/Elgg
PHP | 54 lines | 37 code | 10 blank | 7 comment | 8 complexity | a2feb4c1a8165ea85f64876f6881b799 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Icon display
  4. *
  5. * @package ElggGroups
  6. */
  7. require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
  8. $group_guid = get_input('group_guid');
  9. /* @var ElggGroup $group */
  10. $group = get_entity($group_guid);
  11. if (!($group instanceof ElggGroup)) {
  12. header("HTTP/1.1 404 Not Found");
  13. exit;
  14. }
  15. // If is the same ETag, content didn't changed.
  16. $etag = $group->icontime . $group_guid;
  17. if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") {
  18. header("HTTP/1.1 304 Not Modified");
  19. exit;
  20. }
  21. $size = strtolower(get_input('size'));
  22. if (!in_array($size, array('large', 'medium', 'small', 'tiny', 'master', 'topbar')))
  23. $size = "medium";
  24. $success = false;
  25. $filehandler = new ElggFile();
  26. $filehandler->owner_guid = $group->owner_guid;
  27. $filehandler->setFilename("groups/" . $group->guid . $size . ".jpg");
  28. $success = false;
  29. if ($filehandler->open("read")) {
  30. if ($contents = $filehandler->read($filehandler->getSize())) {
  31. $success = true;
  32. }
  33. }
  34. if (!$success) {
  35. $location = elgg_get_plugins_path() . "groups/graphics/default{$size}.gif";
  36. $contents = @file_get_contents($location);
  37. }
  38. header("Content-type: image/jpeg");
  39. header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
  40. header("Pragma: public");
  41. header("Cache-Control: public");
  42. header("Content-Length: " . strlen($contents));
  43. header("ETag: \"$etag\"");
  44. echo $contents;