11 $this->oTPL =
dbx()->get_system_obj(
'dbxTPL');
18 private function get_content_tpl_from_folder($folder=0) {
24 if ($rec[
'template']) {
25 $tpl=$rec[
'template'];
29 if ($rec[
'template']) {
30 $tpl=$rec[
'template'];
39 private function get_cols_content($cols,$content,$split) {
41 $content_cols=array();
42 for ($c = 0; $c < $cols; $c++) { $content_cols[$c]=
''; }
47 $content_tmp = explode($split, $content);
48 if (is_array($content_tmp)) {
49 $count_tmp = count($content_tmp);
51 if ($count_tmp >= $cols) {
53 $per_col= (int) ($count_tmp / $cols +1);
55 for ($c = 0; $c < $cols; $c++) {
57 for ($p = $a; $p < ($per_col * ($c+1)) ; $p++) {
59 if (isset($content_tmp[$p])) {
60 $content_cols[$c].=$content_tmp[$p].$split;
62 if (strpos($content_tmp[$p],
'</ul>')) $p=($p +3);
63 if (strpos($content_tmp[$p],
'<img')) $p=($p +3);
73 private function check_cols($content_cols,$cols) {
75 if (is_array($content_cols)) {
76 if (isset($content_cols[$cols-1])) {
77 if (trim($content_cols[$cols-1]) >
'') $ok=1;
84 private function get_col_content($cols,$content) {
86 $content = preg_replace(
'/<hr\b[^>]*class="[^"]*\bdbx_split\b[^"]*"[^>]*>/i',
'<hr class="dbx_split">', (
string)$content);
87 $content_cols = explode(
'<hr class="dbx_split">', $content);
88 if ($cols == count($content_cols))
return $content_cols;
90 $content = trim($content);
91 $content = (str_replace(
'<hr class="dbx_split">',
'<br>',$content));
92 $content = (str_replace(
'<br />',
'<br>',$content));
93 $content = (str_replace(
'<br/>' ,
'<br>',$content));
94 $length = strlen($content);
96 if (!$length)
return '';
97 $content_cols=array();
98 if (!$this->check_cols($content_cols,$cols)) $content_cols=$this->get_cols_content($cols,$content,
'</p>');
99 if (!$this->check_cols($content_cols,$cols)) $content_cols=$this->get_cols_content($cols,$content,
'<br>');
100 if (!$this->check_cols($content_cols,$cols)) $content_cols=$this->get_cols_content($cols,$content,
'.');
101 if (!$this->check_cols($content_cols,$cols)) $content_cols=$this->get_cols_content($cols,$content,
' ');
103 return $content_cols;
106 private function split_content_sections($content) {
107 $content = (string)$content;
115 $tokens = array(
'hero',
'main',
'thesar',
'footer');
116 $pattern =
'/(?:<!--\s*dbx:(hero|main|thesar|footer)\s*-->|<span[^>]*class="[^"]*dbx-cms-marker[^"]*"[^>]*>\s*dbx:(hero|main|thesar|footer)\s*<\/span>)/i';
118 if (!preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE)) {
123 foreach ($matches[0] as $idx => $match) {
124 $name = strtolower($matches[1][$idx][0] ?: $matches[2][$idx][0]);
125 if (!in_array($name, $tokens,
true))
continue;
126 $parts[] = array(
'name' => $name,
'pos' => $match[1],
'len' => strlen($match[0]));
129 if (!$parts)
return $sections;
131 for ($i = 0; $i < count($parts); $i++) {
132 $start = $parts[$i][
'pos'] + $parts[$i][
'len'];
133 $end = isset($parts[$i + 1]) ? $parts[$i + 1][
'pos'] : strlen($content);
134 $sections[$parts[$i][
'name']] = trim(substr($content, $start, max(0, $end - $start)));
137 if (trim($sections[
'main']) === $content) {
138 $first = $parts[0][
'pos'];
139 $sections[
'main'] = trim(substr($content, 0, $first));
145 private function adminEditorBarHtml($cid = 0) {
146 if (!dbx()->can(
'admin')) {
150 $url = $this->appUrl() .
'?dbx_modul=dbxContent_admin&dbx_run1=cms&cid=' . (int)$cid;
151 return $this->oTPL->get_tpl(
'dbxContent|content-view-bar-admin-win', array(
152 'admin_url' => dbx()->esc($url),
156 private function appUrl() {
157 $script = str_replace(
'\\',
'/', (
string)(
$_SERVER[
'SCRIPT_NAME'] ??
''));
158 if ($script ===
'')
return '';
159 $dir = str_replace(
'\\',
'/', dirname($script));
160 if (
$dir ===
'.' ||
$dir ===
'/' ||
$dir ===
'\\')
return '/';
161 return rtrim(
$dir,
'/') .
'/';
164 private function wrapContentPage($pageContent, $cid) {
165 $i = dbx()->next_id();
166 $title = trim((
string)dbx()->get_system_var(
'dbx_title',
''));
168 $db = dbx()->get_system_obj(
'dbxDB');
170 if (is_array($row)) {
171 $title = trim((
string)($row[
'title'] ??
''));
175 $title =
'Seite #' . (int)$cid;
178 return $this->oTPL->get_tpl(
'dbxContent|content-page-frontend', array(
179 'frame_id' =>
'dbx_content_page_' . $i,
180 'cid' => (
string)(
int)$cid,
181 'frontend_head' => $this->oTPL->get_tpl(
'dbxContent|content-frontend-head', array(
182 'bar_title' => $title,
183 'bar_title_pre' => $this->adminEditorBarHtml((
int)$cid),
184 'bar_title_heading_attrs' =>
' data-cms-page-title',
186 'page_content' => $pageContent,
190 private function get_media_merge($cid) {
191 $merge = array(
'media_hero' =>
'',
'media_gallery' =>
'',
'media_teaser' =>
'',
'media_footer' =>
'');
193 if ($cid <= 0)
return $merge;
195 $db = dbx()->get_system_obj(
'dbxDB');
196 $usage_rows =
$db->select(
'dbxMediaUsage',
'content_id = ' . $cid .
' AND active = 1',
'*',
'slot,sorter,id',
'ASC',
'', 0, 0, 0);
198 if (is_array($usage_rows) && !empty($usage_rows)) {
199 foreach ($usage_rows as $usage) {
200 if (!is_array($usage))
continue;
201 $row =
$db->select1(
'dbxMedia', (
int)($usage[
'media_id'] ?? 0));
202 if (!is_array($row) || (
int)($row[
'active'] ?? 0) !== 1)
continue;
203 $row[
'slot'] = (string)($usage[
'slot'] ??
'gallery');
207 $rows =
$db->select(
'dbxMedia',
'content_id = ' . $cid .
' AND active = 1',
'*',
'slot,title',
'ASC',
'', 0, 0, 0);
209 if (!is_array($rows))
return $merge;
213 foreach ($rows as $row) {
214 if (!is_array($row))
continue;
215 $slot = trim((
string)($row[
'slot'] ??
'gallery')) ?:
'gallery';
216 $url =
'index.php?dbx_modul=dbxContent&dbx_run1=media&dbx_mid=' . (int)($row[
'id'] ?? 0);
217 $alt = htmlspecialchars((
string)($row[
'alt'] ?? $row[
'title'] ??
''), ENT_QUOTES,
'UTF-8');
218 $img =
'<img class="dbx-content-media dbx-content-media-' . htmlspecialchars($slot, ENT_QUOTES,
'UTF-8') .
'" src="' . htmlspecialchars($url, ENT_QUOTES,
'UTF-8') .
'" alt="' . $alt .
'">';
220 if ($slot ===
'hero' && !$merge[
'media_hero']) $merge[
'media_hero'] = $img;
221 if ($slot ===
'teaser' && !$merge[
'media_teaser']) $merge[
'media_teaser'] = $img;
222 if ($slot ===
'footer' && !$merge[
'media_footer']) $merge[
'media_footer'] = $img;
223 if ($slot ===
'gallery') $gallery .= $img;
226 $merge[
'media_gallery'] = $gallery ?
'<div class="dbx-content-gallery">' . $gallery .
'</div>' :
'';
231 public function renderPage(
int $cid, array $options = array()): string {
237 require_once __DIR__ .
'/dbxContent_bootstrap.php';
238 $renderer =
dbx()->get_include_obj(
'dbxContentRenderer',
'dbxContent');
240 $renderOptions = array(
241 'skip_hits' => !empty($options[
'skip_hits']),
242 'admin_help' => !empty($options[
'admin_help']),
244 $static = $renderer->renderStatic($cid, $renderOptions);
245 return $this->wrapContentPage($static, $cid);
249 $cid = (int)
dbx()->get_modul_var(
'dbx_cid', 0,
'int');
251 $cid = (int)
dbx()->get_modul_var(
'cid', 0,
'int');
254 $cid = (int)
dbx()->get_system_var(
'dbx_cid', 0,
'int');
257 require_once __DIR__ .
'/dbxContent_bootstrap.php';
261 return "show cid=($cid) nicht gefunden! ";
static resolveCid(string $lng='')
Startseiten-CID fuer die aktive (oder uebergebene) Sprache.