/** * @param $field * @param $value * @param FrontendPage $parentPage * @param bool $includeHidden * @return bool|FrontendPage */ public static function findByField($field, $value, FrontendPage $parentPage = null, $includeHidden = true) { $pageCacheId = static::getCacheId([$field, $value, $includeHidden ? 'TRUE' : 'FALSE'], $parentPage); if (isset(static::$pagesCache[$pageCacheId])) { return static::$pagesCache[$pageCacheId]; } $pageClass = get_called_class(); $query = DB::table('pages')->where('pages.' . $field, $value)->whereIn('status', static::getStatuses($includeHidden)); if (config('pages::checkDate') === true) { $query->where('published_at', '<=', DB::raw('NOW()')); } if (!is_null($parentPage)) { $query->where('parent_id', $parentPage->id); } // TODO: добавить кеширование на основе тегов $foundPage = Cache::remember($pageCacheId, Carbon::now()->addMinutes(10), function () use($query) { return $query->take(1)->first(); }); if (is_null($foundPage)) { return null; } $foundPageObject = new FrontendPage($foundPage); if (is_null($parentPage) and !is_null($foundPageObject->getParentId())) { $parentPage = static::findById($foundPageObject->getParentId()); } $foundPageObject->setParentPage($parentPage); static::$pagesCache[$pageCacheId] = $foundPageObject; return $foundPageObject; }
/** * @param FrontendPage|int $page * @param string $part * * @return string */ public static function get($page, $part) { $html = null; $pageId = $page instanceof FrontendPage ? $page->getId() : (int) $page; $parts = static::loadPartsByPageId($pageId); if (empty($parts[$pageId][$part])) { return; } return array_get($parts, implode('.', [$pageId, $part, 'content_html'])); }
/** * @param FrontendPage|integer $page * @param string $part * @return string */ public static function get($page, $part) { $html = null; $pageId = $page instanceof FrontendPage ? $page->getId() : (int) $page; static::loadPartsbyPageId($pageId); if (empty(static::$cached[$pageId][$part])) { return null; } if (($part = static::$cached[$pageId][$part]) instanceof PagePartModel) { $html = $part->content_html; } else { if (($view = static::$cached[$pageId][$part]) instanceof View) { $html = (string) $view; } } return $html; }
/** * @param int $id * * @return bool|FrontendPage */ protected function getPage($id) { try { return FrontendPage::findById($id, [FrontendPage::STATUS_HIDDEN, FrontendPage::STATUS_DRAFT]); } catch (ModelNotFoundException $e) { $this->throwFailException($this->smartRedirect()->withErrors(trans('pages::core.messages.not_found'))); } }
/** * @param string $value * * @return void */ private function execute($value) { if (empty($value)) { return; } // Производим поиск страницы которая укзана в настройках типа страницы if (!empty($itemPageId = $this->getSettings()->getSetting('item_page_id'))) { $this->page = FrontendPage::findById($itemPageId); return; } }
/** * @param string $message * @param int $code * @param Exception|null $previous */ public function __construct($message = '', $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); if (config('app.debug')) { return; } $ext = pathinfo(Request::getUri(), PATHINFO_EXTENSION); $mimeType = null; if (empty($ext) or $ext and !($mimeType = Mime::byExt($ext))) { $mimeType = 'text/html'; } if ($mimeType and $mimeType != 'text/html') { $response = new Response(); $this->sendResponse($response, $mimeType); } elseif (!is_null($page = FrontendPage::findByField('behavior', 'page.not.found'))) { /** @var FrontendController $controller */ $controller = app()->make(FrontendController::class); $response = app()->call([$controller, 'run'], [$page->getUri()]); $this->sendResponse($response, $mimeType); } }
/** * 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; }
/** * @return bool|FrontendPage */ public function toFrontendPage() { return FrontendPage::findById($this->id); }
/** * @param string $uri * * @return string */ public function executeRoute($uri) { if (empty($uri)) { return; } if (is_null($method = $this->getRouter()->findRouteByUri($uri))) { $this->page = FrontendPage::findByUri($uri, $this->page); return; } if (strpos($method, '::') !== false) { Callback::invoke($method, [$this]); } else { $this->{$method}(); } return $method; }
public function onLoad() { $this->currentPage = FrontendPage::findById($this->getPageId()); }