Elgg
Version 6.1
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
Elgg
Controllers
ServeIcon.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Elgg\Controllers
;
4
5
use
Elgg\Exceptions\Http\EntityNotFoundException
;
6
use
Elgg\Http\OkResponse
;
7
use
Elgg\Http\ResponseBuilder
;
8
use
Elgg\Request
;
9
use
Elgg\Traits\TimeUsing
;
10
use
Symfony\Component\HttpFoundation\Response
;
11
use
Symfony\Component\HttpFoundation\BinaryFileResponse
;
12
19
class
ServeIcon
{
20
21
use
TimeUsing
;
22
31
public
function
__invoke
(
Request
$request
) {
32
33
// clear cache-boosting headers set by PHP session
34
if
(!isset($request->
getHttpRequest
()->_integration_testing)) {
35
header_remove(
'Cache-Control'
);
36
header_remove(
'Pragma'
);
37
header_remove(
'Expires'
);
38
}
39
40
$guid
= (int) $request->
getParam
(
'guid'
);
41
$size
= (string) $request->
getParam
(
'size'
);
42
43
$entity
=
get_entity
(
$guid
);
44
if
(!
$entity
instanceof \
ElggEntity
) {
45
throw
new
EntityNotFoundException
();
46
}
47
48
$thumbnail =
$entity
->getIcon(
$size
);
49
if
(!$thumbnail->exists()) {
50
throw
new
EntityNotFoundException
(
'Icon does not exist'
);
51
}
52
53
$if_none_match = $request->
getHttpRequest
()->headers->get(
'if_none_match'
);
54
if
(!empty($if_none_match)) {
55
// strip mod_deflate suffixes
56
$request->
getHttpRequest
()->headers->set(
'if_none_match'
,
str_replace
(
'-gzip'
,
''
, $if_none_match));
57
}
58
59
$etag =
'"'
. $thumbnail->getModifiedTime().
'"'
;
60
61
$response
=
new
Response();
62
$response
->setExpires($this->
getCurrentTime
(
'-1 day'
))
63
->prepare($request->
getHttpRequest
())
64
->setPrivate()
65
->setEtag($etag)
66
->setExpires($this->
getCurrentTime
(
'+1 day'
))
67
->setMaxAge(86400);
68
69
if
(
$response
->isNotModified($request->
getHttpRequest
())) {
70
return
new
OkResponse
(
''
,
ELGG_HTTP_NOT_MODIFIED
);
71
}
72
73
$headers
= [
74
'Content-Type'
=> $thumbnail->getMimeType(),
75
'X-Content-Type-Options'
=>
'nosniff'
,
76
];
77
$response
=
new
BinaryFileResponse($thumbnail->getFilenameOnFilestore(),
ELGG_HTTP_OK
,
$headers
,
false
,
'inline'
);
78
$response
->prepare($request->
getHttpRequest
());
79
80
$response
->setPrivate()
81
->setEtag($etag)
82
->setExpires($this->
getCurrentTime
(
'+1 day'
))
83
->setMaxAge(86400);
84
85
if
(!
$response
->headers->hasCacheControlDirective(
'no-cache'
)) {
86
$response
->headers->addCacheControlDirective(
'no-cache'
,
'Set-Cookie'
);
87
}
88
89
$response
->send();
90
91
return
elgg_ok_response
();
92
}
93
}
Elgg\Request\getHttpRequest
getHttpRequest()
Get the HttpRequest for this request.
Definition:
Request.php:166
ResponseBuilder
OkResponse
elgg_ok_response
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
Definition:
pagehandler.php:224
$response
$response
Definition:
content.php:10
str_replace
ELGG_HTTP_OK
const ELGG_HTTP_OK
Definition:
constants.php:45
$request
$request
Definition:
livesearch.php:12
Response
Elgg\Controllers\ServeIcon
Controller to handle /serve-icon requests.
Definition:
ServeIcon.php:19
Request
Elgg\Traits\TimeUsing
trait TimeUsing
Adds methods for setting the current time (for testing)
Definition:
TimeUsing.php:10
Elgg\Request\getParam
getParam($key, $default=null, $filter=true)
Get an element of the params array.
Definition:
Request.php:67
Elgg\Traits\getCurrentTime
getCurrentTime($modifier= '')
Get the (cloned) time.
Definition:
TimeUsing.php:25
$headers
$headers
Definition:
section.php:21
Elgg\Controllers
Definition:
CommentEntityRedirector.php:3
$entity
$entity
Definition:
reset.php:8
get_entity
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition:
entities.php:70
Elgg\Controllers\ServeIcon\__invoke
__invoke(Request $request)
Respond to a request.
Definition:
ServeIcon.php:31
$size
$size
Definition:
thumb.php:23
ELGG_HTTP_NOT_MODIFIED
const ELGG_HTTP_NOT_MODIFIED
Definition:
constants.php:59
ElggEntity
Definition:
ElggEntity.php:52
Elgg\Request
Request container.
Definition:
Request.php:12
EntityNotFoundException
Aggregate action for saving settings.
BinaryFileResponse
Elgg\Exceptions\Http\EntityNotFoundException
Thrown when entity can not be found.
Definition:
EntityNotFoundException.php:12
Elgg\Http\OkResponse
OK response builder.
Definition:
OkResponse.php:8
$guid
$guid
Reset an ElggUpgrade.
Definition:
reset.php:6
Generated on Wed Dec 4 2024 00:00:20 for Elgg by
1.8.11