protected function getData() { $pageList = new StaticPageList($this->theme); $pages = $pageList->getPageTree(true); $searchTerm = Str::lower($this->getSearchTerm()); if (strlen($searchTerm)) { $words = explode(' ', $searchTerm); $iterator = function ($pages) use(&$iterator, $words) { $result = []; foreach ($pages as $page) { if ($this->textMatchesSearch($words, $this->subtreeToText($page))) { $result[] = (object) ['page' => $page->page, 'subpages' => $iterator($page->subpages)]; } } return $result; }; $pages = $iterator($pages); } return $pages; }
/** * Returns a list of options for the Reference drop-down menu in the * menu item configuration form, when the Static Page item type is selected. * @return array Returns an array */ protected static function listStaticPageMenuOptions() { $theme = Theme::getEditTheme(); $pageList = new PageList($theme); $pageTree = $pageList->getPageTree(true); $iterator = function ($pages) use(&$iterator) { $result = []; foreach ($pages as $pageInfo) { $pageName = $pageInfo->page->getViewBag()->property('title'); $fileName = $pageInfo->page->getBaseFileName(); if (!$pageInfo->subpages) { $result[$fileName] = $pageName; } else { $result[$fileName] = ['title' => $pageName, 'items' => $iterator($pageInfo->subpages)]; } } return $result; }; return $iterator($pageTree); }
/** * Loads the URL map - a list of page file names and corresponding URL patterns. * The URL map can is cached. The clearUrlMap() method resets the cache. By default * the map is updated every time when a page is saved in the back-end, or * when the interval defined with the cms.urlCacheTtl expires. * @return boolean Returns true if the URL map was loaded from the cache. Otherwise returns false. */ protected function loadUrlMap() { $key = $this->getCacheKey('static-page-url-map'); $cacheable = Config::get('cms.enableRoutesCache'); $cached = $cacheable ? Cache::get($key, false) : false; if (!$cached || ($unserialized = @unserialize($cached)) === false) { /* * The item doesn't exist in the cache, create the map */ $pageList = new PageList($this->theme); $pages = $pageList->listPages(); $map = ['urls' => [], 'files' => [], 'titles' => []]; foreach ($pages as $page) { $url = $page->getViewBag()->property('url'); if (!$url) { continue; } $url = Str::lower(RouterHelper::normalizeUrl($url)); $file = $page->getBaseFileName(); $map['urls'][$url] = $file; $map['files'][$file] = $url; $map['titles'][$file] = $page->getViewBag()->property('title'); } self::$urlMap = $map; if ($cacheable) { Cache::put($key, serialize($map), Config::get('cms.urlCacheTtl', 1)); } return false; } self::$urlMap = $unserialized; return true; }