14 $this->oTPL=
dbx()->get_system_obj(
'dbxTPL');
18 private function user_has_access($groups) {
19 $groups = trim((
string)$groups);
20 if ($groups ===
'') $groups =
'*';
21 return dbx()->can($groups);
24 private function resolve_folder_rights(
$db, $folder_id, array $visited = array()) {
25 $folder_id = (int)$folder_id;
26 if ($folder_id <= 0)
return '*';
27 if (isset($visited[$folder_id]))
return '*';
28 $visited[$folder_id] = 1;
30 $row =
$db->select1(dbxContentLng::ddFolder(), $folder_id,
'*', 0);
31 if (!is_array($row))
return '*';
33 $raw = trim((
string)($row[
'group_read'] ??
''));
34 if ($raw ===
'')
return '*';
36 $parent_id = (int)($row[
'parent_id'] ?? 0);
37 $parts = preg_split(
'/\s*,\s*/', $raw, -1, PREG_SPLIT_NO_EMPTY);
41 foreach ($parts as $part) {
42 $part = trim((
string)$part);
43 if ($part ===
'')
continue;
44 if (strtolower($part) ===
'parent') {
52 $parent_rights = $this->resolve_folder_rights(
$db, $parent_id, $visited);
53 foreach (preg_split(
'/\s*,\s*/', $parent_rights, -1, PREG_SPLIT_NO_EMPTY) as $part) {
54 $part = trim((
string)$part);
55 if ($part !==
'' && strtolower($part) !==
'parent') $out[$part] = 1;
59 return count($out) ? implode(
',', array_keys($out)) :
'*';
62 private function folder_allowed(
$db, $folder_id) {
63 return $this->user_has_access($this->resolve_folder_rights(
$db, $folder_id));
66 private function content_href(array $page) {
67 $permalink = trim((
string)($page[
'permalink'] ??
''));
68 if ($permalink !==
'') {
69 if (preg_match(
'/^(https?:\/\/|\/|\?)/i', $permalink))
return $permalink;
70 return dbx()->get_base_url() . ltrim($permalink,
'/');
72 return '?dbx_modul=dbxContent&dbx_run1=show&dbx_cid=' . (int)($page[
'id'] ?? 0);
75 private function cms_pages(
$db, $folder_id) {
76 $rows =
$db->select(dbxContentLng::ddContent(),
'folder = ' . (
int)$folder_id .
' AND activ = 1',
'id,title,permalink,sorter,folder',
'sorter,title,id',
'ASC',
'', 0, 0, 0);
77 return is_array($rows) ? $rows : array();
80 private function cms_folders(
$db, $parent_id) {
81 $rows =
$db->select(dbxContentLng::ddFolder(),
'parent_id = ' . (
int)$parent_id,
'id,name,parent_id,group_read,sorter',
'sorter,name,id',
'ASC',
'', 0, 0, 0);
82 return is_array($rows) ? $rows : array();
85 private function render_page_li(array $page) {
86 $title = trim((
string)($page[
'title'] ??
''));
87 if ($title ===
'') $title =
'Seite ' . (int)($page[
'id'] ?? 0);
88 return '<li class="dbx-cms-menu-page"><a href="' . dbx()->esc($this->content_href($page)) .
'">' . dbx()->esc($title) .
'</a></li>';
91 private function render_pages(
$db, $folder_id) {
93 foreach ($this->cms_pages(
$db, $folder_id) as $page) {
94 $html .= $this->render_page_li($page);
99 private function render_folder_li(
$db, array $folder) {
100 $id = (int)($folder[
'id'] ?? 0);
101 if ($id <= 0 || !$this->folder_allowed(
$db, $id))
return '';
103 $inner = $this->render_children(
$db, $id);
104 if (trim($inner) ===
'')
return '';
106 $name = trim((
string)($folder[
'name'] ??
''));
107 if ($name ===
'') $name =
'Ordner ' . $id;
109 return '<li class="dbx-cms-menu-folder"><a>' . dbx()->esc($name) .
'</a><ul>' . $inner .
'</ul></li>';
112 private function render_children(
$db, $folder_id, $include_pages =
true) {
113 $folder_id = (int)$folder_id;
114 if (!$this->folder_allowed(
$db, $folder_id))
return '';
117 foreach ($this->cms_folders(
$db, $folder_id) as $folder) {
118 $html .= $this->render_folder_li(
$db, $folder);
120 if ($include_pages) {
121 $html .= $this->render_pages(
$db, $folder_id);
130 if ($flat !== 1)
return '';
132 $db =
dbx()->get_system_obj(
'dbxDB');
133 if (!$this->folder_allowed(
$db,
$root))
return '';
135 return $this->render_pages(
$db,
$root);
141 $split_flat = $split_flat && $flat === 1;
142 $lng = dbxContentPageCache::currentLng();
143 $variant = dbxContentPageCache::menuVariantFlat($flat);
145 $variant .=
'-split';
148 if (dbxContentPageCache::isEnabled()) {
149 $cached = dbxContentPageCache::readMenu(
$root, $variant, $lng);
150 if ($cached !==
null) {
155 $db =
dbx()->get_system_obj(
'dbxDB');
159 $inner = $this->render_children(
$db, 0, !$split_flat);
162 } elseif (trim($inner) !==
'') {
163 $html =
'<li class="dbx-cms-menu-root"><a>Content</a><ul>' . $inner .
'</ul></li>';
166 if ($this->folder_allowed(
$db,
$root)) {
168 $html = $this->render_children(
$db,
$root, !$split_flat);
170 $folder =
$db->select1(dbxContentLng::ddFolder(),
$root,
'*', 0);
171 if (is_array($folder)) {
172 $html = $this->render_folder_li(
$db, $folder);
178 if (dbxContentPageCache::isEnabled()) {
179 dbxContentPageCache::writeMenu($html,
$root, $variant, $lng);
186 private function has_entrys(
$root,$tab_folder,$tab_content,
$count,$deepr=0) {
188 $deep=
dbx()->get_modul_var(
'deep',9,
'int');
193 if ($deepr <= $deep) {
195 $where =
"parent_id = $root";
196 $db =
dbx()->get_system_obj(
'dbxDB');
197 $folder=
$db->select($tab_folder,$where,
'id,name,group_read,sorter',
'sorter,name,id');
199 if (is_array($folder)) {
200 foreach ($folder as $no => $record) {
201 $access=$this->folder_allowed(
$db, (
int)$record[
'id']);
203 $root = $record[
'id'];
204 $name = $record[
'name'];
215 private function has_files(
$root,$tab_content) {
218 $where =
"folder = $root";
220 $db = dbx()->get_system_obj(
'dbxDB');
221 if (!$this->folder_allowed(
$db, (
int)
$root))
return 0;
222 $files =
$db->select($tab_content,$where,
'id,title');
223 if (is_array($files)) {
231 private function content_files(
$root,$tab_content,$content) {
233 $where =
"folder = $root";
234 $db = dbx()->get_system_obj(
'dbxDB');
235 if (!$this->folder_allowed(
$db, (
int)
$root)) {
236 return str_replace(
'{obj:files}',
'', $content);
238 $files =
$db->select($tab_content,$where,
'id,title,permalink,sorter',
'sorter,title,id');
239 if (is_array($files)) {
240 foreach ($files as $no => $record) {
242 $title=$record[
'title'];
243 $tpl=$this->oTPL->get_tpl(
'modul',
'menu-content-file');
244 if ($record[
'permalink']) {
245 $href=$record[
'permalink'];
247 $href=
'?dbx_Modul=dbxContent&dbx_run1=show&cid='.$id;
249 $tpl = (str_replace(
'{href}' ,$href ,$tpl));
250 $tpl = (str_replace(
'{title}',$title,$tpl));
254 $content = (str_replace(
'{obj:files}',$obj_files,$content));
259 private function content_folder(
$root,$tab_folder,$tab_content,$content,$deepr=0) {
261 $where =
"parent_id = $root";
262 $db = dbx()->get_system_obj(
'dbxDB');
263 $folder=
$db->select($tab_folder,$where,
'id,name,group_read,sorter',
'sorter,name,id');
264 if (is_array($folder)) {
265 $deep = dbx()->get_modul_var(
'deep',9,
'int');
266 $deepr = ($deepr + 1);
268 if ($deepr <= $deep) {
269 foreach ($folder as $no => $record) {
270 $access=$this->folder_allowed(
$db, (
int)$record[
'id']);
272 $root = $record[
'id'];
273 $name = $record[
'name'];
274 $count = $this->has_entrys(
$root,$tab_folder,$tab_content,0,$deepr);
276 $tpl = $this->oTPL->get_tpl(
'modul',
'menu-content-sub');
277 $tpl = (str_replace(
'{folder}',$name ,$tpl));
278 $tpl = (str_replace(
'{count}' ,
$count,$tpl));
279 $tpl = (str_replace(
'{deep}' ,$deepr,$tpl));
281 $tpl=$this->content_files(
$root,$tab_content,$tpl);
282 if ($deepr < $deep) {
283 $tpl=$this->content_folder(
$root,$tab_folder,$tab_content,$tpl,$deepr);
293 $content = (str_replace(
'{obj:folders}',$obj_folder,$content));
299 private function content_menu_load() {
301 $root = dbx()->get_modul_var(
'root',0,
'int');
302 $deep = dbx()->get_modul_var(
'deep',9,
'int');
303 $label = dbx()->get_modul_var(
'label');
304 $mode = dbx()->get_modul_var(
'mode');
305 $lng = dbx()->get_modul_var(
'lng');
306 $tpl =
'menu-content';
307 if ($mode) $tpl=$tpl.
'-'.$mode;
309 $tab_content = dbxContentLng::ddContent($lng);
310 $tab_folder = dbxContentLng::ddFolder($lng);
311 dbx()->set_modul_var(
'deep_run',0);
312 $entrys= $this->has_entrys(
$root,$tab_folder,$tab_content,0);
313 $files = $this->has_files(
$root,$tab_content);
315 $content=$this->oTPL->get_tpl(
'modul',$tpl);
316 $content=str_replace(
'{label}',$label,$content);
318 $content=$this->content_files(
$root,$tab_content,$content);
319 $content=$this->content_folder(
$root,$tab_folder,$tab_content,$content);
331 $root =
dbx()->get_modul_var(
'root', 0);
333 #todo $root = folder name select get root
336 $lng = trim((
string)
dbx()->get_modul_var(
'lng',
''));
338 $lng =
dbx()->get_system_var(
'dbx_lng',
'de');
340 dbx()->set_modul_var(
'lng', $lng);
342 $deep = (int)
dbx()->get_modul_var(
'deep', 9,
'int');
343 $mode = trim((
string)
dbx()->get_modul_var(
'mode',
''));
344 $label = trim((
string)
dbx()->get_modul_var(
'label',
''));
345 $variant = dbxContentPageCache::menuVariantLoad($deep, $mode, $label);
347 if (dbxContentPageCache::isEnabled()) {
348 $cached = dbxContentPageCache::readMenu((
int)
$root, $variant, $lng);
349 if ($cached !==
null) {
354 $content = $this->content_menu_load();
356 if (dbxContentPageCache::isEnabled()) {
357 dbxContentPageCache::writeMenu($content, (
int)
$root, $variant, $lng);