22 'eot' =>
'application/vnd.ms-fontobject',
24 'html' =>
'text/html',
25 'ico' =>
'image/x-icon',
26 'jpeg' =>
'image/jpeg',
27 'jpg' =>
'image/jpeg',
28 'js' =>
'application/javascript',
29 'json' =>
'application/json',
30 'map' =>
'application/json',
31 'otf' =>
'application/font-otf',
33 'svg' =>
'image/svg+xml',
34 'swf' =>
'application/x-shockwave-flash',
35 'tiff' =>
'image/tiff',
36 'ttf' =>
'application/font-ttf',
37 'webp' =>
'image/webp',
38 'woff' =>
'application/font-woff',
39 'woff2' =>
'application/font-woff2',
46 'application/javascript',
95 $view = $parsed[
'view'];
99 if (empty($content_type)) {
100 return $this->
send403(
'Asset must have a valid file extension');
103 $response =
new Response();
104 if (in_array($content_type, self::$utf8_content_types)) {
105 $response->headers->set(
'Content-Type',
"{$content_type};charset=utf-8",
true);
107 $response->headers->set(
'Content-Type', $content_type,
true);
110 $response->headers->set(
'X-Content-Type-Options',
'nosniff',
true);
112 if (!$this->simplecache->isEnabled()) {
114 if (!headers_sent()) {
115 header_remove(
'Cache-Control');
116 header_remove(
'Pragma');
117 header_remove(
'Expires');
121 return $this->
send403(
"Requested view ({$view}) is not an asset");
131 if ($this->
is304($etag)) {
132 $response =
new Response();
133 $response->setNotModified();
138 return $response->setContent(
$content);
142 if ($this->
is304($etag)) {
143 $response =
new Response();
144 $response->setNotModified();
154 return new BinaryFileResponse(
$filename, 200, $response->headers->all());
159 header_remove(
'Cache-Control');
160 header_remove(
'Pragma');
161 header_remove(
'Expires');
165 return $this->
send403(
'Requested view is not an asset');
168 if ((
int) $this->config->lastcache ===
$ts) {
180 return $response->setContent(
$content);
205 if (!
preg_match(
'#^/cache/([0-9]+)/([^/]+)/(.+)$#',
$path, $matches)) {
210 'ts' => (int) $matches[1],
211 'viewtype' => $matches[2],
212 'view' => $matches[3],
226 return in_array($matches[1],
_elgg_services()->locale->getLanguageCodes());
241 $response->setSharedMaxAge(86400 * 30 * 6);
242 $response->setMaxAge(86400 * 30 * 6);
243 $response->headers->set(
'ETag', $etag);
255 $response->headers->set(
'Cache-Control',
"public, max-age=0, must-revalidate",
true);
256 $response->headers->set(
'ETag', $etag);
267 $if_none_match = $this->request->headers->get(
'If-None-Match');
268 if ($if_none_match === null) {
273 $if_none_match =
trim($if_none_match);
274 if (0 ===
strpos($if_none_match,
'W/')) {
275 $if_none_match =
substr($if_none_match, 2);
277 $if_none_match =
str_replace(
'-gzip',
'', $if_none_match);
279 return ($if_none_match === $etag);
336 $hook_name = $this->simplecache->isEnabled() ?
'simplecache:generate' :
'cache:generate';
359 $view =
'languages.js';
360 $vars = [
'language' => $matches[1]];
370 $this->config->debug = null;
382 protected function send403($msg =
'Cache error: bad request') {
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
getElggPath()
Get the Request URI minus querystring.
const ELGG_HTTP_FORBIDDEN
parsePath($path)
Parse a request.
send403($msg= 'Cache error:bad request')
Send an error message to requestor.
static static $utf8_content_types
getViewFileType($view)
Returns the type of output expected from the view.
getContentType($view)
Get the content type.
bootCore()
Bootstrap the Elgg engine, loads plugins, and calls initial system events.
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
__construct(Config $config, Request $request, SimpleCache $simplecache)
Constructor.
is304($etag)
Send a 304 and exit() if the ETag matches the request.
renderView($view, $viewtype)
Render a view for caching.
setRevalidateHeaders($etag, Response $response)
Set revalidate cache headers.
isCacheableView($view)
Is the view cacheable.
Load, boot, and implement a front controller for an Elgg application.
$ts
CSRF security token view for use with secure forms.
$content
Set robots.txt action.
_elgg_services()
Get the global service provider.
sendCacheHeaders($etag, Response $response)
Sets cache headers.
elgg_set_viewtype($viewtype= '')
Manually set the viewtype.
getProcessedView($view, $viewtype)
Get the contents of a view for caching.
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
handleRequest(Request $request, Application $app)
Handle a request for a cached view.