Permalink
Browse files

feature(groups): group avatars now use serve-file handler

Group avatars are now served with elgg_get_inline_url()
  • Loading branch information...
hypeJunction committed Mar 9, 2016
1 parent c2b2f7f commit ac57e99002a1c1490b7dd2f348845cbf7653ed8b
Showing with 42 additions and 53 deletions.
  1. +16 −43 mod/groups/icon.php
  2. +26 −10 mod/groups/start.php
View
@@ -1,57 +1,30 @@
<?php
/**
* Icon display
*
* @package ElggGroups
* @deprecated 2.2
*/
elgg_deprecated_notice('icon.php has been depreated and should not be included. Use elgg_get_inline_url() instead.', '2.2');
if (!isset($page)) {
die('This file cannot be called directly.');
}
$group_guid = get_input('group_guid');
/* @var ElggGroup $group */
$group = get_entity($group_guid);
if (!($group instanceof ElggGroup)) {
header("HTTP/1.1 404 Not Found");
exit;
$guid = get_input('group_guid');
$size = get_input('size');
if (!isset($size) || $size === '') {
$size = 'medium';
}
// If is the same ETag, content didn't changed.
$etag = $group->icontime . $group_guid;
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") {
header("HTTP/1.1 304 Not Modified");
exit;
}
$size = strtolower(get_input('size'));
if (!in_array($size, array('large', 'medium', 'small', 'tiny', 'master', 'topbar')))
$size = "medium";
elgg_entity_gatekeeper($guid, 'group');
$success = false;
$group = get_entity($guid);
$filehandler = new ElggFile();
$filehandler->owner_guid = $group->owner_guid;
$filehandler->setFilename("groups/" . $group->guid . $size . ".jpg");
$success = false;
if ($filehandler->open("read")) {
if ($contents = $filehandler->read($filehandler->getSize())) {
$success = true;
}
}
$icon = new ElggFile();
$icon->owner_guid = $group->owner_guid;
$icon->setFilename("groups/{$group->guid}{$size}.jpg");
if (!$success) {
$contents = elgg_view("groups/default{$size}.gif");
header("Content-type: image/gif");
} else {
header("Content-type: image/jpeg");
$url = elgg_get_inline_url($icon, true);
if (!$url) {
$url = elgg_get_simplecache_url("groups/default{$size}.gif");
}
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
header("Pragma: public");
header("Cache-Control: public");
header("Content-Length: " . strlen($contents));
header("ETag: \"$etag\"");
echo $contents;
forward($url);
View
@@ -299,19 +299,29 @@ function groups_page_handler($page) {
*
* @param array $page
* @return bool
* @deprecated 2.2
*/
function groups_icon_handler($page) {
// The username should be the file we're getting
if (isset($page[0])) {
set_input('group_guid', $page[0]);
}
if (isset($page[1])) {
set_input('size', $page[1]);
elgg_deprecated_notice('/groupicon page handler has been deprecated. Use elgg_get_inline_url() instead.', '2.2');
$guid = array_shift($page);
elgg_entity_gatekeeper($guid, 'group');
$size = array_shift($page) ? : 'medium';
$group = get_entity($guid);
$icon = new ElggFile();
$icon->owner_guid = $group->owner_guid;
$icon->setFilename("groups/{$group->guid}{$size}.jpg");
$url = elgg_get_inline_url($icon, true);
if (!$url) {
$url = elgg_get_simplecache_url("groups/default{$size}.gif");
}
// Include the standard profile index
include __DIR__ . "/icon.php";
return true;
forward($url);
}
/**
@@ -354,7 +364,13 @@ function groups_set_icon_url($hook, $type, $url, $params) {
}
if ($icontime) {
// return thumbnail
return "groupicon/$group->guid/$size/$icontime.jpg";
$icon = new ElggFile();
$icon->owner_guid = $group->owner_guid;
$icon->setFilename("groups/{$group->guid}{$size}.jpg");
$url = elgg_get_inline_url($icon, true); // binding to session due to complexity in group access controls
if ($url) {
return $url;
}
}
return elgg_get_simplecache_url("groups/default{$size}.gif");

0 comments on commit ac57e99

Please sign in to comment.