Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / page / PageCache.class.php
CommitLineData
8aacc17d
AE
1<?php
2namespace wcf\data\page;
3use wcf\system\cache\builder\PageCacheBuilder;
4use wcf\system\SingletonFactory;
ac4ff35d 5use wcf\system\WCF;
8aacc17d
AE
6
7/**
8 * Provides access to the page cache.
9 *
10 * @author Alexander Ebert
c839bd49 11 * @copyright 2001-2018 WoltLab GmbH
8aacc17d 12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
e71525e4
MW
13 * @package WoltLabSuite\Core\Data\Page
14 * @since 3.0
8aacc17d
AE
15 */
16class PageCache extends SingletonFactory {
17 /**
18 * page cache
893aace3 19 * @var array
8aacc17d
AE
20 */
21 protected $cache;
22
23 /**
24 * @inheritDoc
25 */
26 protected function init() {
27 $this->cache = PageCacheBuilder::getInstance()->getData();
28 }
29
b2782e46
MS
30 /**
31 * Returns all available pages.
32 *
33 * @return Page[]
34 */
35 public function getPages() {
36 return $this->cache['pages'];
37 }
38
8aacc17d
AE
39 /**
40 * Returns a page by page id or null.
41 *
893aace3
MS
42 * @param integer $pageID page id
43 * @return Page|null
8aacc17d
AE
44 */
45 public function getPage($pageID) {
46 if (isset($this->cache['pages'][$pageID])) {
47 return $this->cache['pages'][$pageID];
48 }
49
50 return null;
51 }
52
53 /**
54 * Returns a page by controller or null.
55 *
893aace3
MS
56 * @param string $controller controller class name
57 * @return Page|null
8aacc17d
AE
58 */
59 public function getPageByController($controller) {
60 if (isset($this->cache['controller'][$controller])) {
61 return $this->getPage($this->cache['controller'][$controller]);
62 }
63
64 return null;
65 }
66
67 /**
68 * Returns a page by its internal identifier or null.
69 *
893aace3
MS
70 * @param string $identifier internal identifier
71 * @return Page|null
8aacc17d
AE
72 */
73 public function getPageByIdentifier($identifier) {
74 if (isset($this->cache['identifier'][$identifier])) {
75 return $this->getPage($this->cache['identifier'][$identifier]);
76 }
77
78 return null;
79 }
ac4ff35d
AE
80
81 /**
82 * Returns the localized page title by page id, optionally retrieving the title
83 * for given language id if it is a multilingual page.
84 *
8ff2cd79
MS
85 * @param integer $pageID page id
86 * @param integer $languageID specific value by language id
87 * @return string localized page title
ac4ff35d
AE
88 */
89 public function getPageTitle($pageID, $languageID = null) {
90 if (isset($this->cache['pageTitles'][$pageID])) {
91 $page = $this->getPage($pageID);
ff9e3598 92 if ($page->isMultilingual || $page->pageType == 'system') {
ac4ff35d
AE
93 if ($languageID !== null && isset($this->cache['pageTitles'][$pageID][$languageID])) {
94 return $this->cache['pageTitles'][$pageID][$languageID];
95 }
01ce42f0
MS
96 else if (isset($this->cache['pageTitles'][$pageID][WCF::getLanguage()->languageID])) {
97 return $this->cache['pageTitles'][$pageID][WCF::getLanguage()->languageID];
98 }
ac4ff35d
AE
99 }
100 else {
101 return $this->cache['pageTitles'][$pageID][0];
102 }
103 }
104
105 return '';
106 }
107
108 /**
109 * Returns the global landing page.
110 *
8ff2cd79 111 * @return Page
ac4ff35d
AE
112 */
113 public function getLandingPage() {
114 return $this->cache['landingPage'];
115 }
8aacc17d 116}