21 'html' =>
"text/html",
22 'ico' =>
"image/x-icon",
23 'jpeg' =>
"image/jpeg",
24 'jpg' =>
"image/jpeg",
25 'js' =>
"application/javascript",
27 'svg' =>
"image/svg+xml",
28 'swf' =>
"application/x-shockwave-flash",
29 'tiff' =>
"image/tiff",
30 'webp' =>
"image/webp",
32 'eot' =>
"application/vnd.ms-fontobject",
33 'ttf' =>
"application/font-ttf",
34 'woff' =>
"application/font-woff",
35 'woff2' =>
"application/font-woff2",
36 'otf' =>
"application/font-otf",
42 "application/javascript",
64 $this->application = $app;
65 $this->config = $config;
66 $this->server_vars = $server_vars;
76 $config = $this->config;
84 $view = $request[
'view'];
85 $viewtype = $request[
'viewtype'];
88 if (empty($content_type)) {
89 $this->
send403(
"Asset must have a valid file extension");
92 if (in_array($content_type, self::$utf8_content_types)) {
93 header(
"Content-Type: $content_type;charset=utf-8");
95 header(
"Content-Type: $content_type");
102 if (!$config->getVolatile(
'simplecache_enabled')) {
104 $this->application->bootCore();
107 $this->
send403(
"Requested view is not an asset");
123 $filename = $config->getVolatile(
'cacheroot') .
"views_simplecache/$ts/$viewtype/$view";
131 $this->application->bootCore();
135 $this->
send403(
"Requested view is not an asset");
138 $lastcache = (int)$config->get(
'lastcache');
140 $filename = $config->getVolatile(
'cacheroot') .
"views_simplecache/$lastcache/$viewtype/$view";
142 if ($lastcache ==
$ts) {
148 if (!is_dir($dir_name)) {
151 mkdir($dir_name, 0775,
true);
173 if (
false !== strpos(
$path,
'..')) {
177 if (preg_match(
'#[^a-zA-Z0-9/\.\-_]#',
$path)) {
184 if (!preg_match(
'#^/cache/([0-9]+)/([^/]+)/(.+)$#',
$path, $matches)) {
190 'viewtype' => $matches[2],
191 'view' => $matches[3],
203 if (preg_match(
'~^languages/(.*)\.js$~',
$view,
$m)) {
204 return in_array(
$m[1],
_elgg_services()->translator->getAllLanguageCodes());
216 $config = $this->config;
217 $config->loadSettingsFile();
219 if ($config->getVolatile(
'cacheroot') && $config->getVolatile(
'simplecache_enabled') !== null) {
224 $db = $this->application->getDb();
227 $rows = $db->getData(
" 228 SELECT `name`, `value` 229 FROM {$db->prefix}datalists 230 WHERE `name` IN ('dataroot', 'simplecache_enabled') 233 $this->
send403(
'Cache error: unable to get the data root');
236 if (0 === strpos($e->getMessage(),
"Elgg couldn't connect")) {
237 $this->
send403(
'Cache error: unable to connect to database server');
239 $this->
send403(
'Cache error: unable to connect to Elgg database');
245 $config->set($row->name, $row->value);
248 if (!$config->getVolatile(
'cacheroot')) {
249 $dataroot = $config->getVolatile(
'dataroot');
251 $this->
send403(
'Cache error: unable to get the cache root');
264 header(
'Expires: ' . gmdate(
'D, d M Y H:i:s \G\M\T', strtotime(
"+6 months")),
true);
265 header(
"Pragma: public",
true);
266 header(
"Cache-Control: public",
true);
277 header_remove(
'Expires');
278 header(
"Pragma: public",
true);
279 header(
"Cache-Control: public, max-age=0, must-revalidate",
true);
290 if (!isset($this->server_vars[
'HTTP_IF_NONE_MATCH'])) {
295 $if_none_match = str_replace(
'-gzip',
'', trim($this->server_vars[
'HTTP_IF_NONE_MATCH']));
296 if ($if_none_match === $etag) {
297 header(
"HTTP/1.1 304 Not Modified");
330 private function getViewFileType(
$view) {
334 if ($hasValidExtension) {
338 if (preg_match(
'~(?:^|/)(css|js)(?:$|/)~',
$view,
$m)) {
356 $hook_type = $this->getViewFileType(
$view);
357 $hook_params = array(
359 'viewtype' => $viewtype,
375 if ($viewtype ===
'default' && preg_match(
"#^languages/(.*?)\\.js$#",
$view, $matches)) {
376 $view =
"languages.js";
377 $vars = [
'language' => $matches[1]];
387 $this->config->set(
'debug', null);
395 $GLOBALS[
'_ELGG']->pagesetupdone =
true;
406 protected function send403($msg =
'Cache error: bad request') {
407 header(
'HTTP/1.1 403 Forbidden');
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
parsePath($path)
Parse a request.
send403($msg= 'Cache error:bad request')
Send an error message to requestor.
sendRevalidateHeaders($etag)
Send revalidate cache headers.
static static $utf8_content_types
sendCacheHeaders($etag)
Send cache headers.
Access to configuration values.
getContentType($view)
Get the content type.
__construct(Application $app, Config $config, $server_vars)
Constructor.
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
elgg echo
Translates a string.
renderView($view, $viewtype)
Render a view for caching.
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
clearfix elgg elgg elgg elgg page header
handle304($etag)
Send a 304 and exit() if the ETag matches the request.
isCacheableView($view)
Is the view cacheable.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
$content
Set robots.txt action.
handleRequest($path)
Handle a request for a cached view.
getProcessedView($view, $viewtype)
Get the contents of a view for caching.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
setupSimplecache()
Do a minimal engine load.