This method loads the full Elgg engine, checks the installation
state, and triggers a series of events to finish booting Elgg:
- {@elgg_event boot system}
- {@elgg_event init system}
- {@elgg_event ready system}
If Elgg is not fully installed, the browser will be redirected to an installation page.
/** * Handle a request for a cached view * * @param array $path URL path * @return void */ public function handleRequest($path) { $config = $this->config; $request = $this->parsePath($path); if (!$request) { $this->send403(); } $ts = $request['ts']; $view = $request['view']; $viewtype = $request['viewtype']; $contentType = $this->getContentType($view); if (!empty($contentType)) { header("Content-Type: {$contentType}", true); } // this may/may not have to connect to the DB $this->setupSimplecache(); // we can't use $config->get yet. It fails before the core is booted if (!$config->getVolatile('simplecache_enabled')) { $this->application->bootCore(); if (!\_elgg_is_view_cacheable($view)) { $this->send403(); } else { echo $this->renderView($view, $viewtype); } exit; } $etag = "\"{$ts}\""; // If is the same ETag, content didn't change. if (isset($this->server_vars['HTTP_IF_NONE_MATCH']) && trim($this->server_vars['HTTP_IF_NONE_MATCH']) === $etag) { header("HTTP/1.1 304 Not Modified"); exit; } $filename = $config->getVolatile('dataroot') . 'views_simplecache/' . md5("{$viewtype}|{$view}"); if (file_exists($filename)) { $this->sendCacheHeaders($etag); readfile($filename); exit; } $this->application->bootCore(); elgg_set_viewtype($viewtype); if (!\_elgg_is_view_cacheable($view)) { $this->send403(); } $cache_timestamp = (int) $config->get('lastcache'); if ($cache_timestamp == $ts) { $this->sendCacheHeaders($etag); $content = $this->getProcessedView($view, $viewtype); $dir_name = $config->getDataPath() . 'views_simplecache/'; if (!is_dir($dir_name)) { mkdir($dir_name, 0700); } file_put_contents($filename, $content); } else { // if wrong timestamp, don't send HTTP cache $content = $this->renderView($view, $viewtype); } echo $content; exit; }
/** * Handle a request for a file * * @param Request $request HTTP request * @return Response */ public function getResponse($request) { $response = new Response(); $response->prepare($request); $path = implode('/', $request->getUrlSegments()); if (!preg_match('~serve-file/e(\\d+)/l(\\d+)/d([ia])/c([01])/([a-zA-Z0-9\\-_]+)/(.*)$~', $path, $m)) { return $response->setStatusCode(400)->setContent('Malformatted request URL'); } list(, $expires, $last_updated, $disposition, $use_cookie, $mac, $path_from_dataroot) = $m; if ($expires && $expires < time()) { return $response->setStatusCode(403)->setContent('URL has expired'); } $etag = '"' . $last_updated . '"'; $response->setPublic()->setEtag($etag); if ($response->isNotModified($request)) { return $response; } // @todo: change to minimal boot without plugins $this->application->bootCore(); $hmac_data = array('expires' => (int) $expires, 'last_updated' => (int) $last_updated, 'disposition' => $disposition, 'path' => $path_from_dataroot, 'use_cookie' => (int) $use_cookie); if ((bool) $use_cookie) { $hmac_data['cookie'] = _elgg_services()->session->getId(); } ksort($hmac_data); $hmac = elgg_build_hmac($hmac_data); if (!$hmac->matchesToken($mac)) { return $response->setStatusCode(403)->setContent('HMAC mistmatch'); } $dataroot = _elgg_services()->config->getDataPath(); $filenameonfilestore = "{$dataroot}{$path_from_dataroot}"; if (!is_readable($filenameonfilestore)) { return $response->setStatusCode(404)->setContent('File not found'); } $actual_last_updated = filemtime($filenameonfilestore); if ($actual_last_updated != $last_updated) { return $response->setStatusCode(403)->setContent('URL has expired'); } $public = $use_cookie ? false : true; $content_disposition = $disposition == 'i' ? 'inline' : 'attachment'; $response = new BinaryFileResponse($filenameonfilestore, 200, array(), $public, $content_disposition); $response->prepare($request); if (empty($expires)) { $expires = strtotime('+1 year'); } $expires_dt = (new DateTime())->setTimestamp($expires); $response->setExpires($expires_dt); $response->setEtag($etag); return $response; }
/** * Handle a request for a cached view * * @param array $path URL path * @return void */ public function handleRequest($path) { $config = $this->config; $request = $this->parsePath($path); if (!$request) { $this->send403(); } $ts = $request['ts']; $view = $request['view']; $viewtype = $request['viewtype']; $contentType = $this->getContentType($view); if (empty($contentType)) { $this->send403("Asset must have a valid file extension"); } header("Content-Type: {$contentType}", true); // this may/may not have to connect to the DB $this->setupSimplecache(); // we can't use $config->get yet. It fails before the core is booted if (!$config->getVolatile('simplecache_enabled')) { $this->application->bootCore(); if (!$this->isCacheableView($view)) { $this->send403("Requested view is not an asset"); } else { $content = $this->renderView($view, $viewtype); $etag = '"' . md5($content) . '"'; $this->sendRevalidateHeaders($etag); $this->handle304($etag); echo $content; } exit; } $etag = "\"{$ts}\""; $this->handle304($etag); // trust the client but check for an existing cache file $filename = $config->getVolatile('dataroot') . "views_simplecache/{$ts}/{$viewtype}/{$view}"; if (file_exists($filename)) { $this->sendCacheHeaders($etag); readfile($filename); exit; } // the hard way $this->application->bootCore(); elgg_set_viewtype($viewtype); if (!$this->isCacheableView($view)) { $this->send403("Requested view is not an asset"); } $lastcache = (int) $config->get('lastcache'); $filename = $config->getVolatile('dataroot') . "views_simplecache/{$lastcache}/{$viewtype}/{$view}"; if ($lastcache == $ts) { $this->sendCacheHeaders($etag); $content = $this->getProcessedView($view, $viewtype); $dir_name = dirname($filename); if (!is_dir($dir_name)) { mkdir($dir_name, 0700, true); } file_put_contents($filename, $content); } else { // if wrong timestamp, don't send HTTP cache $content = $this->renderView($view, $viewtype); } echo $content; exit; }