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' =>
'text/javascript',
30 'json' =>
'application/json',
31 'map' =>
'application/json',
32 'mjs' =>
'text/javascript',
33 'otf' =>
'application/font-otf',
35 'svg' =>
'image/svg+xml',
36 'swf' =>
'application/x-shockwave-flash',
37 'tiff' =>
'image/tiff',
38 'ttf' =>
'application/font-ttf',
39 'webp' =>
'image/webp',
40 'woff' =>
'application/font-woff',
41 'woff2' =>
'application/font-woff2',
70 $this->simplecache_enabled = $config->simplecache_enabled;
71 if (!$this->config->hasInitialValue(
'simplecache_enabled')) {
72 $db_value = $config_table->
get(
'simplecache_enabled');
73 if (isset($db_value)) {
74 $this->simplecache_enabled = (bool) $db_value;
94 $view = $parsed[
'view'];
98 if (empty($content_type)) {
99 return $this->
send403(
'Asset must have a valid file extension');
103 if (in_array($content_type, self::$utf8_content_types)) {
104 $response->headers->set(
'Content-Type',
"{$content_type};charset=utf-8",
true);
106 $response->headers->set(
'Content-Type', $content_type,
true);
109 $response->headers->set(
'X-Content-Type-Options',
'nosniff',
true);
111 if (!$this->simplecache_enabled) {
113 if (!headers_sent()) {
114 header_remove(
'Cache-Control');
115 header_remove(
'Pragma');
116 header_remove(
'Expires');
120 return $this->
send403(
"Requested view ({$view}) is not an asset");
130 if ($this->
is304($etag)) {
141 if ($this->
is304($etag)) {
158 header_remove(
'Cache-Control');
159 header_remove(
'Pragma');
160 header_remove(
'Expires');
164 return $this->
send403(
'Requested view is not an asset');
167 if ((
int) $this->config->lastcache ===
$ts) {
194 if (str_contains(
$path,
'..')) {
207 if (!
preg_match(
'#^/cache/([0-9]+)/([^/]+)/(.+)$#',
$path, $matches)) {
212 'ts' => (int) $matches[1],
213 'viewtype' => $matches[2],
214 'view' => $matches[3],
228 return in_array($matches[1],
_elgg_services()->locale->getLanguageCodes());
243 $response->setSharedMaxAge(86400 * 30 * 6);
244 $response->setMaxAge(86400 * 30 * 6);
245 $response->headers->set(
'ETag', $etag);
257 $response->headers->set(
'Cache-Control',
'public, max-age=0, must-revalidate',
true);
258 $response->headers->set(
'ETag', $etag);
269 $if_none_match = $this->request->headers->get(
'If-None-Match');
270 if ($if_none_match === null) {
275 $if_none_match =
trim($if_none_match);
276 if (str_starts_with($if_none_match,
'W/')) {
277 $if_none_match =
substr($if_none_match, 2);
281 $if_none_match =
str_replace(
'-gzip',
'', $if_none_match);
283 return ($if_none_match === $etag);
340 $name = $this->simplecache_enabled ?
'simplecache:generate' :
'cache:generate';
344 if (
$type ===
'mjs') {
369 $view =
'languages.js';
370 $vars = [
'language' => $matches[1]];
380 $this->config->debug = null;
392 protected function send403($msg =
'Cache error: bad request') {
getElggPath()
Get the Request URI minus querystring.
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.
$config
Advanced site settings, debugging section.
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.
__construct(protected Config $config, protected Request $request, protected SimpleCache $simplecache, ConfigTable $config_table)
Constructor.
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.
bool $simplecache_enabled
$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.