23 'html' =>
"text/html",
24 'ico' =>
"image/x-icon",
25 'jpeg' =>
"image/jpeg",
26 'jpg' =>
"image/jpeg",
27 'js' =>
"application/javascript",
28 'json' =>
"application/json",
30 'svg' =>
"image/svg+xml",
31 'swf' =>
"application/x-shockwave-flash",
32 'tiff' =>
"image/tiff",
33 'webp' =>
"image/webp",
35 'eot' =>
"application/vnd.ms-fontobject",
36 'ttf' =>
"application/font-ttf",
37 'woff' =>
"application/font-woff",
38 'woff2' =>
"application/font-woff2",
39 'otf' =>
"application/font-otf",
45 "application/javascript",
68 $this->config = $config;
69 $this->request = $request;
81 $config = $this->config;
89 $view = $parsed[
'view'];
93 if (empty($content_type)) {
94 return $this->
send403(
"Asset must have a valid file extension");
97 $response = Response::create();
98 if (in_array($content_type, self::$utf8_content_types)) {
99 $response->headers->set(
'Content-Type',
"$content_type;charset=utf-8",
true);
101 $response->headers->set(
'Content-Type', $content_type,
true);
106 if (!headers_sent()) {
107 header_remove(
'Cache-Control');
108 header_remove(
'Pragma');
109 header_remove(
'Expires');
113 return $this->
send403(
"Requested view ({$view}) is not an asset");
123 if ($this->
is304($etag)) {
124 return Response::create()->setNotModified();
127 return $response->setContent(
$content);
131 if ($this->
is304($etag)) {
132 return Response::create()->setNotModified();
136 $filename = $config->assetroot .
"$ts/$viewtype/$view";
139 return BinaryFileResponse::create(
$filename, 200, $response->headers->all());
144 header_remove(
'Cache-Control');
145 header_remove(
'Pragma');
146 header_remove(
'Expires');
150 return $this->
send403(
"Requested view is not an asset");
153 $lastcache = (int) $config->lastcache;
155 $filename = $config->assetroot .
"$lastcache/$viewtype/$view";
157 if ($lastcache ==
$ts) {
163 if (!is_dir($dir_name)) {
166 mkdir($dir_name, 0775,
true);
176 return $response->setContent(
$content);
187 if (
false !== strpos(
$path,
'..')) {
191 if (preg_match(
'#[^a-zA-Z0-9/\.\-_]#',
$path)) {
198 if (!preg_match(
'#^/cache/([0-9]+)/([^/]+)/(.+)$#',
$path, $matches)) {
204 'viewtype' => $matches[2],
205 'view' => $matches[3],
217 if (preg_match(
'~^languages/(.*)\.js$~',
$view, $m)) {
218 return in_array($m[1],
_elgg_services()->localeService->getLanguageCodes());
232 $response->setSharedMaxAge(86400 * 30 * 6);
233 $response->setMaxAge(86400 * 30 * 6);
234 $response->headers->set(
'ETag', $etag);
246 $response->headers->set(
'Cache-Control',
"public, max-age=0, must-revalidate",
true);
247 $response->headers->set(
'ETag', $etag);
257 $if_none_match = $this->request->headers->get(
'If-None-Match');
258 if ($if_none_match === null) {
263 $if_none_match = trim($if_none_match);
264 if (0 === strpos($if_none_match,
'W/')) {
265 $if_none_match = substr($if_none_match, 2);
267 $if_none_match = str_replace(
'-gzip',
'', $if_none_match);
269 return ($if_none_match === $etag);
304 if ($hasValidExtension) {
308 if (preg_match(
'~(?:^|/)(css|js)(?:$|/)~',
$view, $m)) {
330 $hook_name =
'simplecache:generate';
332 $hook_name =
'cache:generate';
353 if (
$viewtype ===
'default' && preg_match(
"#^languages/(.*?)\\.js$#",
$view, $matches)) {
354 $view =
"languages.js";
355 $vars = [
'language' => $matches[1]];
365 $this->config->debug = null;
376 protected function send403($msg =
'Cache error: bad request') {
377 return Response::create($msg, 403);
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
getElggPath()
Get the Request URI minus querystring.
$CONFIG simplecache_enabled
Is simplecache enabled?
parsePath($path)
Parse a request.
send403($msg= 'Cache error:bad request')
Send an error message to requestor.
static static $utf8_content_types
if(!$enabled) if(PHP_SAPI!== 'cli')
Interates through each element of an array and calls callback a function.
getViewFileType($view)
Returns the type of output expected from the view.
getContentType($view)
Get the content type.
if(!$owner||!$owner->canEdit()) if(!$owner->hasIcon('master')) if(!$owner->saveIconFromElggFile($owner->getIcon('master'), 'icon', $coords)) $view
bootCore()
Bootstrap the Elgg engine, loads plugins, and calls initial system events.
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.
$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.
__construct(Config $config, Request $request, $simplecache_enabled)
Constructor.
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
handleRequest(Request $request, Application $app)
Handle a request for a cached view.