/** * TODO: добавить кеширование вывода * * @param FrontendPage $frontPage * @return \Illuminate\View\View|null * @throws LayoutNotFoundException */ protected function render(FrontendPage $frontPage) { event('frontend.found', [$frontPage]); app()->singleton('frontpage', function () use($frontPage) { return $frontPage; }); $layout = $frontPage->getLayoutView(); if (is_null($layout)) { throw new LayoutNotFoundException(); } $widgetCollection = new PageWidgetCollection($frontPage); $html = (string) $frontPage->getLayoutView(); if (auth()->check() and auth()->user()->hasRole(['administrator', 'developer'])) { $injectHTML = (string) view('cms::app.partials.toolbar'); // Insert system HTML before closed tag body $matches = preg_split('/(<\\/body>)/i', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); if (count($matches) > 1) { /* assemble the HTML output back with the iframe code in it */ $html = $matches[0] . $injectHTML . $matches[1] . $matches[2]; } } $response = new Response(); $response->header('Content-Type', $frontPage->getMime()); if (config('cms.show_response_sign', TRUE)) { $response->header('X-Powered-CMS', \CMS::NAME . '/' . \CMS::VERSION); } $response->setContent($html); // Set the ETag header $response->setEtag(sha1($html)); $response->setLastModified($frontPage->getCreatedAt()); // mark the response as either public or private $response->setPublic(); // Check that the Response is not modified for the given Request if ($response->isNotModified($this->request)) { // return the 304 Response immediately return $response; } return $response; }
/** * @param View $layout * @param string $mime * * @return \Illuminate\View\View|null * @throws LayoutNotFoundException */ protected function render(View $layout = null, $mime = 'text\\html') { if (is_null($layout)) { throw new LayoutNotFoundException(trans('pages::core.messages.layout_not_set')); } $html = $layout->render(); $response = new Response(); $response->header('Content-Type', $mime); if (config('cms.show_response_sign', true)) { $response->header('X-Powered-CMS', CMS::getFullName()); } $response->setContent($html); // Set the ETag header $response->setEtag(md5($html)); // mark the response as either public or private $response->setPublic(); // Check that the Response is not modified for the given Request if ($response->isNotModified($this->request)) { // return the 304 Response immediately return $response; } return $response; }
/** * Display an attachment file such as image * * @param Project $project * @param Issue $issue * @param Attachment $attachment * @param Request $request * * @return Response */ public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request) { $issue->setRelation('project', $project); $attachment->setRelation('issue', $issue); $path = config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename; $storage = \Storage::disk('local'); $length = $storage->size($path); $time = $storage->lastModified($path); $type = $storage->getDriver()->getMimetype($path); $response = new Response(); $response->setEtag(md5($time . $path)); $response->setExpires(new \DateTime('@' . ($time + 60))); $response->setLastModified(new \DateTime('@' . $time)); $response->setPublic(); $response->setStatusCode(200); $response->header('Content-Type', $type); $response->header('Content-Length', $length); $response->header('Content-Disposition', 'inline; filename="' . $attachment->filename . '"'); $response->header('Cache-Control', 'must-revalidate'); if ($response->isNotModified($request)) { // Return empty response if not modified return $response; } // Return file if first request / modified $response->setContent($storage->get($path)); return $response; }
/** * Set header containing 'cache' or 'controller' to show source of content * @param Response|null $response */ public function setResponseHeader($response = null) { if ($response === null) { return; } $response->setEtag($this->getETag()); if ($this->option('infoheader') !== false) { $response->header($this->option('infoheader'), $this->isFromCache ? 'cache' : 'controller'); } }