dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxContentPermalinkIndex.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxContent;
3
4require_once __DIR__ . '/dbxContentLng.class.php';
5require_once __DIR__ . '/dbxContentPageCache.class.php';
6require_once __DIR__ . '/dbxContentRenderer.class.php';
7require_once __DIR__ . '/dbxContent_permalink.class.php';
8
18
20 public static function indexPath(string $lng = ''): string {
21 $lng = self::safeLng($lng);
22 return dbxContentPageCache::baseDir() . 'meta/permalinks_' . $lng . '.json';
23 }
24
26 public static function homePath(string $lng = ''): string {
27 $lng = self::safeLng($lng);
28 return dbxContentPageCache::baseDir() . 'meta/home_' . $lng . '.json';
29 }
30
31 private static function safeLng(string $lng = ''): string {
32 if ($lng === '') {
33 $lng = trim((string) dbx()->get_system_var('dbx_lng', 'de'));
34 }
35 $lng = strtolower(trim($lng));
36 return preg_match('/^[a-z]{2,3}$/', $lng) ? $lng : 'de';
37 }
38
39 public static function normalizePermalink(string $permalink): string {
40 return dbxContent_permalink::normalize($permalink);
41 }
42
43 private static function pageRights(array $row, dbxContentRenderer $renderer): string {
44 $folderRights = trim($renderer->getPublicFolderRights((int)($row['folder'] ?? 0)));
45 return $folderRights !== '' ? $folderRights : '*';
46 }
47
48 private static function routeFromRow(array $row, dbxContentRenderer $renderer): ?array {
49 $cid = (int)($row['id'] ?? 0);
50 $storedPermalink = trim((string)($row['permalink'] ?? ''));
51 if ($cid <= 0 || !dbxContent_permalink::isValid($storedPermalink)) {
52 return null;
53 }
54 $permalink = self::normalizePermalink($storedPermalink);
55
56 return array(
57 'cid' => $cid,
58 'rights' => self::pageRights($row, $renderer),
59 'activ' => (int)($row['activ'] ?? 1),
60 'permalink' => $permalink,
61 'meta_robots' => trim((string)($row['meta_robots'] ?? '')),
62 );
63 }
64
65 private static function withLanguage(string $lng, callable $callback) {
66 $lng = self::safeLng($lng);
67 $previous = trim((string) dbx()->get_system_var('dbx_lng', 'de'));
68 $changed = $previous !== $lng;
69 if ($changed) {
70 dbx()->set_system_var('dbx_lng', $lng);
71 }
72
73 try {
74 return $callback($lng);
75 } finally {
76 if ($changed) {
77 dbx()->set_system_var('dbx_lng', $previous !== '' ? $previous : 'de');
78 }
79 }
80 }
81
83 public static function load(string $lng = ''): array {
84 return (array) self::withLanguage($lng, static function(string $activeLng): array {
85 $db = dbx()->get_system_obj('dbxDB');
86 if (!is_object($db)) {
87 return array();
88 }
89
90 $rows = $db->select(
91 dbxContentLng::ddContent($activeLng),
92 '1=1',
93 'id,permalink,folder,activ,meta_robots',
94 'id',
95 'ASC',
96 '',
97 0,
98 0,
99 0
100 );
101 if (!is_array($rows)) {
102 return array();
103 }
104
105 $renderer = new dbxContentRenderer();
106 $result = array();
107 foreach ($rows as $row) {
108 if (!is_array($row)) {
109 continue;
110 }
111 $route = self::routeFromRow($row, $renderer);
112 if (is_array($route)) {
113 $result[$route['permalink']] = $route;
114 }
115 }
116 return $result;
117 });
118 }
119
121 public static function save(array $data, string $lng = ''): bool {
122 return true;
123 }
124
125 public static function upsertPage(int $cid, string $permalink, string $rights, int $activ = 1, string $lng = ''): void {
126 // Die Content-Speicherroutine hat den Datensatz bereits aktualisiert.
127 }
128
129 public static function removeByCid(int $cid, string $lng = ''): void {
130 // Kein separater Permalink-Index vorhanden.
131 }
132
133 public static function removeByPermalink(string $permalink, string $lng = ''): void {
134 // Kein separater Permalink-Index vorhanden.
135 }
136
138 public static function resolve(string $permalink, string $lng = ''): ?array {
139 $permalink = trim($permalink);
140 if (!dbxContent_permalink::isValid($permalink)) {
141 $permalink = dbxContent_permalink::canonicalFromLegacy($permalink);
142 if (!dbxContent_permalink::isValid($permalink)) {
143 return null;
144 }
145 }
146 $permalink = self::normalizePermalink($permalink);
147
148 return self::withLanguage($lng, static function(string $activeLng) use ($permalink): ?array {
149 $db = dbx()->get_system_obj('dbxDB');
150 if (!is_object($db)) {
151 return null;
152 }
153
154 $row = $db->select1(
155 dbxContentLng::ddContent($activeLng),
156 array('permalink' => $permalink),
157 'id,permalink,folder,activ,meta_robots',
158 0
159 );
160 if (!is_array($row) || (int)($row['id'] ?? 0) <= 0) {
161 return null;
162 }
163
164 return self::routeFromRow($row, new dbxContentRenderer());
165 });
166 }
167
168 public static function writeHomeCid(int $cid, string $lng = ''): void {
169 // Die sprachabhaengige Startseite wird bei Bedarf live aufgeloest.
170 }
171
172 public static function readHomeCid(string $lng = ''): int {
173 return 0;
174 }
175}
static ddContent(string $lng='')
if(!defined( 'IMG_WEBP')) define( 'IMG_WEBP'
DBX schema administration.