dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxContentContextHelp.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxContent;
3
4require_once __DIR__ . '/dbxContent_bootstrap.php';
5require_once __DIR__ . '/dbxContentContextHelpProvision.class.php';
6
8
9 public const HELP_ROOT = 'outside/help';
10
11 public function topicSlug(string $topic): string {
12 $topic = strtolower(trim($topic));
13 $topic = str_replace('_', '-', $topic);
14 $topic = preg_replace('/[^a-z0-9-]+/', '-', $topic);
15 $topic = preg_replace('/-+/', '-', $topic);
16 return trim((string) $topic, '-');
17 }
18
19 public function permalinkForTopic(string $topic): string {
20 $help = dbx()->get_include_obj('dbxAdminHelp', 'dbxAdmin');
21 if (is_object($help) && method_exists($help, 'topicPermalink')) {
22 $permalink = trim((string)$help->topicPermalink($topic));
23 if (dbxContent_permalink::isValid($permalink)) {
24 return $permalink;
25 }
26 }
27
28 $slug = $this->topicSlug($topic);
29 return $slug !== '' ? 'help-' . $slug : '';
30 }
31
32 public function legacyPermalinksForTopic(string $topic): array {
33 $slug = $this->topicSlug($topic);
34 if ($slug === '') {
35 return array();
36 }
37 return array(
38 self::HELP_ROOT . '/' . $slug,
39 'help/' . $slug,
40 );
41 }
42
43 public function resolveCidByPermalink(string $permalink, string $lng = ''): int {
44 $permalink = trim($permalink);
45 if (!dbxContent_permalink::isValid($permalink)) {
46 return 0;
47 }
48
49 if ($lng === '') {
50 $lng = function_exists('dbx_lng_current') ? dbx_lng_current() : 'de';
51 }
52 $lng = strtolower(trim($lng));
53
54 $hit = dbxContentPermalinkIndex::resolve($permalink, $lng);
55 if (is_array($hit) && (int) ($hit['cid'] ?? 0) > 0) {
56 return (int) $hit['cid'];
57 }
58
59 $db = dbx()->get_system_obj('dbxDB');
60 if (!is_object($db)) {
61 return 0;
62 }
63
64 $dd = dbxContentLng::ddContent($lng);
65 $rec = $db->select1($dd, array('permalink' => $permalink), 'id', 0);
66 if (is_array($rec) && (int) ($rec['id'] ?? 0) > 0) {
67 return (int) $rec['id'];
68 }
69
70 $masterLng = strtolower(trim((string) dbx()->get_config('dbx', 'default_lng', 'de')));
71 if ($masterLng !== '' && $masterLng !== $lng) {
72 $ddMaster = dbxContentLng::ddContent($masterLng);
73 $rec = $db->select1($ddMaster, array('permalink' => $permalink), 'id', 0);
74 if (is_array($rec) && (int) ($rec['id'] ?? 0) > 0) {
75 return (int) $rec['id'];
76 }
77 }
78
79 return 0;
80 }
81
82 public function renderTopic(string $topic): string {
83 $permalink = $this->permalinkForTopic($topic);
84 if ($permalink === '') {
85 return '';
86 }
87
88 $cid = $this->resolveCidByPermalink($permalink);
89 if ($cid <= 0) {
90 return dbx()->get_system_obj('dbxTPL')->get_tpl('dbx|alert-info', array(
91 'msg' => 'Hilfe-Seite noch nicht angelegt. Im CMS unter Ordner <code>'
92 . htmlspecialchars(self::HELP_ROOT, ENT_QUOTES, 'UTF-8')
93 . '</code> eine Seite mit Permalink <code>'
94 . htmlspecialchars($permalink, ENT_QUOTES, 'UTF-8')
95 . '</code> anlegen (Thema: <code>'
96 . htmlspecialchars($topic, ENT_QUOTES, 'UTF-8')
97 . '</code>).',
98 ));
99 }
100
101 $contentObj = dbx()->get_include_obj('dbxContent_content');
102 if (!is_object($contentObj) || !method_exists($contentObj, 'renderPage')) {
103 return '';
104 }
105
106 return $contentObj->renderPage($cid, array(
107 'admin_help' => true,
108 'skip_hits' => true,
109 'skip_cache' => true,
110 'template' => 'c-content-help',
111 'wrap' => false,
112 ));
113 }
114
115 public function renderFormHelp(string $modul, string $form, string $title = ''): string {
116 $modul = trim($modul);
117 $form = trim($form);
118 $title = trim($title);
119 if (!preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $modul)
120 || $form === ''
121 || !preg_match('/^[a-zA-Z0-9_.:-]+$/', $form)) {
122 return dbx()->get_system_obj('dbxTPL')->get_tpl('dbx|alert-danger', array(
123 'msg' => 'Der Formular-Kontext ist ungueltig.',
124 ));
125 }
126
127 if ($title === '') {
128 $title = ucwords(str_replace(array('-', '_', '.'), ' ', $form));
129 }
130
131 $registry = dbx()->get_include_obj('dbxModuleRegistry', 'dbxAdmin');
132 $detail = '';
133 if (is_object($registry) && method_exists($registry, 'renderFormHelp')) {
134 $detail = (string)$registry->renderFormHelp($modul, $form, array(
135 'modul' => htmlspecialchars($modul, ENT_QUOTES, 'UTF-8'),
136 'form' => htmlspecialchars($form, ENT_QUOTES, 'UTF-8'),
137 'form_title' => htmlspecialchars($title, ENT_QUOTES, 'UTF-8'),
138 ));
139 }
140 $detail = str_ireplace(
141 array('[modul=', '[/modul]', '[tpl=', '[dbx:'),
142 array('&#91;modul=', '&#91;/modul]', '&#91;tpl=', '&#91;dbx:'),
143 $detail
144 );
145
146 return dbx()->get_system_obj('dbxTPL')->get_tpl('dbxAdmin|admin-help-form', array(
147 'form_title' => htmlspecialchars($title, ENT_QUOTES, 'UTF-8'),
148 'form_id' => htmlspecialchars($form, ENT_QUOTES, 'UTF-8'),
149 'form_modul' => htmlspecialchars($modul, ENT_QUOTES, 'UTF-8'),
150 'form_detail' => $detail,
151 ));
152 }
153
154 public function run(): string {
155 dbx()->set_system_var('dbx_page', '_window');
156
157 $topic = trim((string) dbx()->get_modul_var('topic', '', 'parameter'));
158 if ($topic === '') {
159 $topic = trim((string) dbx()->get_modul_var('dbx_run2', '', 'parameter'));
160 }
161
162 $help = dbx()->get_include_obj('dbxAdminHelp', 'dbxAdmin');
163 $isFormHelp = ($topic === 'form');
164 if (!$isFormHelp) {
166 }
167 $topics = is_object($help) && method_exists($help, 'topics') ? $help->topics() : array();
168 if (!$isFormHelp && ($topic === '' || !isset($topics[$topic]))) {
169 $topic = 'dashboard';
170 }
171
172 $formTitle = '';
173 if ($isFormHelp) {
174 $formModul = trim((string)dbx()->get_modul_var('help_modul', '', 'parameter'));
175 $formId = trim((string)dbx()->get_modul_var('help_form', '', 'parameter'));
176 $formTitle = trim((string)dbx()->get_modul_var('help_title', '', 'varchar'));
177 $content = $this->renderFormHelp($formModul, $formId, $formTitle);
178 } else {
179 $content = $this->renderTopic($topic);
180 }
181 if (trim(strip_tags((string) $content)) === '') {
182 $content = dbx()->get_system_obj('dbxTPL')->get_tpl('dbx|alert-info', array(
183 'msg' => 'Fuer diesen Bereich ist noch keine Hilfe hinterlegt.',
184 ));
185 }
186
187 $bar = array();
188 if ($isFormHelp && is_object($help) && method_exists($help, 'formHelpWindowBarTemplateData')) {
189 $bar = $help->formHelpWindowBarTemplateData($formTitle);
190 } elseif (is_object($help) && method_exists($help, 'helpWindowBarTemplateData')) {
191 $bar = $help->helpWindowBarTemplateData($topic);
192 }
193
194 return dbx()->get_system_obj('dbxTPL')->get_tpl('dbxAdmin|admin-help-shell', array_merge(
195 is_array($bar) ? $bar : array(),
196 array(
197 'frame_id' => 'dbx_context_help_' . preg_replace('/[^a-z0-9_-]+/i', '_', $topic),
198 'frame_panel_class' => 'dbx-admin-help py-3 dbx-context-help-preview',
199 'frame_form_open' => '',
200 'frame_form_close' => '',
201 'frame_subbar' => '',
202 'frame_body_class' => 'dbx-admin-help-body dbx-context-help-body',
203 'frame_body_head' => '',
204 'frame_body_tail' => '',
205 'frame_panel_attrs' => '',
206 'content' => $content,
207 )
208 ));
209 }
210}
resolveCidByPermalink(string $permalink, string $lng='')
renderFormHelp(string $modul, string $form, string $title='')
dbx_lng_current()
Lädt eine Klasse aus dem Cache oder erstellt eine neue Instanz der Klasse.
Definition dbxApi.php:3038
DBX schema administration.