icon.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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;