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;
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) {
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]));
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)));
138 $first = $parts[0][
'pos'];
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(
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(
198 dbxContentMediaUsageScope::withLanguage(
'content_id = ' . $cid .
' AND active = 1'),
208 if (is_array($usage_rows) && !empty($usage_rows)) {
209 foreach ($usage_rows as $usage) {
210 if (!is_array($usage))
continue;
211 $row =
$db->select1(
'dbxMedia', (
int)($usage[
'media_id'] ?? 0));
212 if (!is_array($row) || (
int)($row[
'active'] ?? 0) !== 1)
continue;
213 $row[
'slot'] = (string)($usage[
'slot'] ??
'gallery');
217 $rows =
$db->select(
'dbxMedia',
'content_id = ' . $cid .
' AND active = 1',
'*',
'slot,title',
'ASC',
'', 0, 0, 0);
223 foreach (
$rows as $row) {
224 if (!is_array($row))
continue;
225 $slot = trim((
string)($row[
'slot'] ??
'gallery')) ?:
'gallery';
226 $url =
'index.php?dbx_modul=dbxContent&dbx_run1=media&dbx_mid=' . (int)($row[
'id'] ?? 0);
227 $alt = htmlspecialchars((
string)($row[
'alt'] ?? $row[
'title'] ??
''), ENT_QUOTES,
'UTF-8');
228 $img =
'<img class="dbx-content-media dbx-content-media-' . htmlspecialchars($slot, ENT_QUOTES,
'UTF-8') .
'" src="' . htmlspecialchars(
$url, ENT_QUOTES,
'UTF-8') .
'" alt="' . $alt .
'">';
230 if ($slot ===
'hero' && !
$merge[
'media_hero'])
$merge[
'media_hero'] = $img;
231 if ($slot ===
'teaser' && !
$merge[
'media_teaser'])
$merge[
'media_teaser'] = $img;
232 if ($slot ===
'footer' && !
$merge[
'media_footer'])
$merge[
'media_footer'] = $img;
233 if ($slot ===
'gallery') $gallery .= $img;
236 $merge[
'media_gallery'] = $gallery ?
'<div class="dbx-content-gallery">' . $gallery .
'</div>' :
'';
247 require_once __DIR__ .
'/dbxContent_bootstrap.php';
248 $renderer =
dbx()->get_include_obj(
'dbxContentRenderer',
'dbxContent');
250 $renderOptions = array(
251 'skip_hits' => !empty(
$options[
'skip_hits']),
252 'admin_help' => !empty(
$options[
'admin_help']),
254 $forcedTemplate = trim((
string)(
$options[
'template'] ??
''));
255 if ($forcedTemplate !==
'') {
256 $renderOptions[
'template'] = $forcedTemplate;
258 $static =
$renderer->renderStatic($cid, $renderOptions);
262 return $this->wrapContentPage($static, $cid);
266 $cid = (int)
dbx()->get_modul_var(
'dbx_cid', 0,
'int');
268 $cid = (int)
dbx()->get_modul_var(
'cid', 0,
'int');
271 $cid = (int)
dbx()->get_system_var(
'dbx_cid', 0,
'int');
274 require_once __DIR__ .
'/dbxContent_bootstrap.php';
278 $renderer =
dbx()->get_include_obj(
'dbxContentRenderer',
'dbxContent');
renderPage(int $cid, array $options=array())
static resolveCid(string $lng='')
Startseiten-CID fuer die aktive (oder uebergebene) Sprache.
static ddFolder(string $lng='')
static ddContent(string $lng='')
foreach($heroTemplates as $templateFile) $sections