23 'eot' =>
'application/vnd.ms-fontobject',
25 'html' =>
'text/html',
26 'ico' =>
'image/x-icon',
27 'jpeg' =>
'image/jpeg',
28 'jpg' =>
'image/jpeg',
29 'js' =>
'application/javascript',
30 'json' =>
'application/json',
31 'map' =>
'application/json',
32 'otf' =>
'application/font-otf',
34 'svg' =>
'image/svg+xml',
35 'swf' =>
'application/x-shockwave-flash',
36 'tiff' =>
'image/tiff',
37 'ttf' =>
'application/font-ttf',
38 'webp' =>
'image/webp',
39 'woff' =>
'application/font-woff',
40 'woff2' =>
'application/font-woff2',
47 'application/javascript',
86 $this->simplecache_enabled = $config->simplecache_enabled;
87 if (!$this->config->hasInitialValue(
'simplecache_enabled')) {
88 $db_value = $config_table->
get(
'simplecache_enabled');
89 if (isset($db_value)) {
90 $this->simplecache_enabled = (bool) $db_value;
110 $view = $parsed[
'view'];
114 if (empty($content_type)) {
115 return $this->
send403(
'Asset must have a valid file extension');
119 if (in_array($content_type, self::$utf8_content_types)) {
120 $response->headers->set(
'Content-Type',
"{$content_type};charset=utf-8",
true);
122 $response->headers->set(
'Content-Type', $content_type,
true);
125 $response->headers->set(
'X-Content-Type-Options',
'nosniff',
true);
127 if (!$this->simplecache_enabled) {
129 if (!headers_sent()) {
130 header_remove(
'Cache-Control');
131 header_remove(
'Pragma');
132 header_remove(
'Expires');
136 return $this->
send403(
"Requested view ({$view}) is not an asset");
146 if ($this->
is304($etag)) {
157 if ($this->
is304($etag)) {
174 header_remove(
'Cache-Control');
175 header_remove(
'Pragma');
176 header_remove(
'Expires');
180 return $this->
send403(
'Requested view is not an asset');
183 if ((
int) $this->config->lastcache ===
$ts) {
210 if (str_contains(
$path,
'..')) {
223 if (!
preg_match(
'#^/cache/([0-9]+)/([^/]+)/(.+)$#',
$path, $matches)) {
228 'ts' => (int) $matches[1],
229 'viewtype' => $matches[2],
230 'view' => $matches[3],
244 return in_array($matches[1],
_elgg_services()->locale->getLanguageCodes());
259 $response->setSharedMaxAge(86400 * 30 * 6);
260 $response->setMaxAge(86400 * 30 * 6);
261 $response->headers->set(
'ETag', $etag);
273 $response->headers->set(
'Cache-Control',
'public, max-age=0, must-revalidate',
true);
274 $response->headers->set(
'ETag', $etag);
285 $if_none_match = $this->request->headers->get(
'If-None-Match');
286 if ($if_none_match === null) {
291 $if_none_match =
trim($if_none_match);
292 if (str_starts_with($if_none_match,
'W/')) {
293 $if_none_match =
substr($if_none_match, 2);
297 $if_none_match =
str_replace(
'-gzip',
'', $if_none_match);
299 return ($if_none_match === $etag);
356 $name = $this->simplecache_enabled ?
'simplecache:generate' :
'cache:generate';
379 $view =
'languages.js';
380 $vars = [
'language' => $matches[1]];
390 $this->config->debug = null;
402 protected function send403($msg =
'Cache error: bad request') {
getElggPath()
Get the Request URI minus querystring.
__construct(Config $config, Request $request, SimpleCache $simplecache, ConfigTable $config_table)
Constructor.
const ELGG_HTTP_FORBIDDEN
$params
Saves global plugin settings.
parsePath($path)
Parse a request.
send403($msg= 'Cache error:bad request')
Send an error message to requestor.
if(!$user||!$user->canDelete()) $name
static static $utf8_content_types
get(string $name)
Gets a configuration value.
getViewFileType($view)
Returns the type of output expected from the view.
getContentType($view)
Get the content type.
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
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
is304($etag)
Send a 304 and exit() if the ETag matches the request.
renderView($view, $viewtype)
Render a view for caching.
elgg_set_viewtype(string $viewtype= '')
Manually set the viewtype.
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.
getProcessedView($view, $viewtype)
Get the contents of a view for caching.
Manipulates values in the dbprefix_config table.
elgg_view_exists(string $view, string $viewtype= '', bool $recurse=true)
Returns whether the specified view exists.
handleRequest(Request $request, Application $app)
Handle a request for a cached view.