14use \phpseclib3\Crypt\AES;
19 return function_exists(
'dbx') ? (int)
dbx()->log_missing($missing) : 0;
43 public array $editor_files = array();
46 private array $owner_stack = array();
49 private bool $sys_msg_running =
false;
52 private array $timer_state = array();
55 private array $admin_bypass_user = array();
58 private bool $admin_bypass_user_loaded =
false;
61 private bool $admin_bypass_user_loading =
false;
72 public function push_owner($owner): void {
73 if (is_object($owner)) {
74 $this->owner_stack[] = $owner;
83 public function pop_owner(): void {
84 if ($this->owner_stack) {
85 array_pop($this->owner_stack);
98 public function set_current_owner($owner): void {
99 if (is_object($owner)) {
100 if ($this->owner_stack) {
101 $this->owner_stack[count($this->owner_stack) - 1] = $owner;
103 $this->owner_stack[] = $owner;
113 public function get_current_owner() {
114 if (!$this->owner_stack) {
118 return $this->owner_stack[count($this->owner_stack) - 1];
135 public function run_owner($owner,
string $method =
'run', ...$args) {
136 if (!is_object($owner) || !is_callable(array($owner, $method))) {
140 $this->push_owner($owner);
143 return $owner->$method(...$args);
167 public function get_system_obj(
string $class,
string $use =
''): ?object {
170 if (!preg_match(
'/^[A-Za-z_][A-Za-z0-9_]*$/', $class)) {
171 throw new Exception(
"Invalid system class name '$class'.");
178 $baseClass =
'\\' . $class;
181 if (file_exists($baseFile)) {
182 require_once $baseFile;
184 $baseClass =
"\\dbxUndefClass";
187 $myClass = $this->get_SysClassOverrideName($class);
188 $myFile = $this->ensure_SysClassOverride($class, $myClass, $baseClass);
190 if ($myFile && file_exists($myFile)) {
191 $this->register_editor_file(
'sysclass', $myFile);
192 require_once $myFile;
195 $myClassFull =
'\\' . $myClass;
196 $createClass = class_exists($myClassFull,
false) ? $myClassFull : $baseClass;
202 if (class_exists($createClass)) {
207 throw new Exception(
"Klasse '$createClass' konnte nicht geladen werden.");
216 public function editor_file_path(
string $file): string {
217 $file = str_replace(
'\\',
'/', $file);
220 if (strpos($file,
$base) === 0) {
221 $file = substr($file, strlen(
$base));
224 return ltrim($file,
'/');
234 public function register_editor_file(
string $kind,
string $file): void {
235 $kind = strtolower(trim($kind));
238 if ($kind ===
'' || $file ===
'') {
242 $path = $this->editor_file_path($file);
243 $key = $kind .
'|' . $path;
244 $this->editor_files[$key] = array(
'kind' => $kind,
'file' => $path);
252 public function get_editor_files(): array {
253 return $this->editor_files;
270 public function editor_marker(
string $kind,
string $file): string {
271 $kind = strtolower(trim($kind));
272 $mode = (int) $this->get_system_var(
'dbx_edit', 0,
'int');
273 $modes = array(
'fd' => 4,
'dd' => 5,
'class' => 6,
'sysclass' => 7,
'config' => 8);
275 if (!isset($modes[$kind]) || ($mode !== 9 && $mode !== $modes[$kind]) || $file ===
'') {
279 $path = $this->editor_file_path($file);
280 $path = str_replace(
'--',
'-', $path);
282 return "\n<!-- DBX-EDITOR|$kind|$path -->\n";
304 public function get_modul_obj(
string $class): object {
306 $namespace_class =
'\dbx\-class-\-class-';
307 $namespace_class = str_replace(
'-class-', $class, $namespace_class);
310 $modul_id = $this->get_system_var(
'dbx_activ_modul_id', 0,
'*');
312 $this->set_system_var(
'dbx_activ_modul_id', $modul_id);
315 $this->set_system_var(
'dbx_activ_modul', $class);
316 $this->set_modul_var(
'dbx_modul_id', $modul_id);
317 $this->set_modul_var(
'dbx_modul', $class);
320 if (stripos($class,
'admin') !==
false) {
329 if (file_exists($modul_class_file)) {
330 $this->register_editor_file(
'class', $modul_class_file);
331 require_once $modul_class_file;
334 $namespace_class =
"\\dbxUndefClass";
338 if (class_exists($namespace_class)) {
339 $object =
new $namespace_class();
340 if (method_exists($object,
'set_editor_class_file')) {
341 $object->set_editor_class_file($modul_class_file);
343 $this->set_current_owner($object);
348 throw new Exception(
"Modul-Klasse '$namespace_class' konnte nicht geladen werden.");
371 public function get_include_obj(
string $class,
string $modul =
'',
string $use =
''): ?object {
374 $modul = $this->get_system_var(
'dbx_activ_modul',
'dbx',
'*');
378 $this->set_system_var(
'dbx_inc', $class);
381 $namespace_class =
'\dbx\-modul-\-class-';
382 $namespace_class = str_replace(
'-modul-', $modul, $namespace_class);
383 $namespace_class = str_replace(
'-class-', $class, $namespace_class);
389 if (file_exists($modul_class_file)) {
390 $this->register_editor_file(
'class', $modul_class_file);
391 require_once $modul_class_file;
394 $namespace_class =
"\\dbxUndefClass";
399 if (class_exists($namespace_class)) {
400 $object =
new $namespace_class();
401 if (method_exists($object,
'set_editor_class_file')) {
402 $object->set_editor_class_file($modul_class_file);
404 $this->set_current_owner($object);
409 throw new Exception(
"Klasse '$namespace_class' konnte nicht geladen werden.");
427 public function use_system_class($class) {
433 if (file_exists($dbx_class_file)) {
434 require_once $dbx_class_file;
455 public function get_system_var(
string $varname, $default =
'',
string $rules =
'*') {
461 if (isset($_SESSION[
'dbx'][
'tmp'][0][
'dbx'][$varname])) {
462 $danger_value = $_SESSION[
'dbx'][
'tmp'][0][
'dbx'][$varname];
465 if (isset($_GET[$varname])) {
466 $danger_value = $_GET[$varname];
468 if (isset($_POST[$varname])) {
469 $danger_value = $_POST[$varname];
474 if (($danger_value !==
'') && ($danger_value !==
null)) {
475 if (dbx_validate_var($danger_value, $rules, $varname)) {
476 $value = $danger_value;
499 public function set_system_var(
string $varname, $value) {
501 $_SESSION[
'dbx'][
'tmp'][0][
'dbx'][$varname] = $value;
520 public function get_modul_var($varname, $default =
'', $rules =
'alphanum') {
525 $modul = $this->get_system_var(
'dbx_activ_modul',
'undef',
'*');
526 $mid = $this->get_system_var(
'dbx_activ_modul_id', 88888,
'*');
529 if (isset($_SESSION[
'dbx'][
'tmp'][$mid][$modul][$varname])) {
530 $danger_value = $_SESSION[
'dbx'][
'tmp'][$mid][$modul][$varname];
535 if (isset($_GET[$varname])) {
536 $danger_value = $_GET[$varname];
539 if (isset($_POST[$varname])) {
540 $danger_value = $_POST[$varname];
545 if ($danger_value !==
'' && $danger_value !==
null && dbx_validate_var($danger_value, $rules, $varname)) {
546 $value = $danger_value;
556 public function get_modul_request_var($varname, $default =
'', $rules =
'*') {
557 return $this->get_modul_var($varname, $default, $rules);
577 public function set_modul_var($varname, $value =
null, $check_protected =
true) {
579 $mid = $this->get_system_var(
'dbx_activ_modul_id', 0,
'int');
580 $modul = $this->get_system_var(
'dbx_activ_modul',
'dbx',
'parameter');
585 if ($check_protected) {
586 $protected = array();
587 if (isset($_SESSION[
'dbx'][
'tmp'][$mid][$modul][
'dbx_protected_modulvars'])) {
588 $protected = $_SESSION[
'dbx'][
'tmp'][$mid][$modul][
'dbx_protected_modulvars'];
590 if (is_array($protected) && array_key_exists($varname, $protected)) {
591 dbx()->debug(
"PROTECTED ($varname)");
597 $_SESSION[
'dbx'][
'tmp'][$mid][$modul][$varname] = $value;
618 public function req(
string $varname, $default =
'',
string $rules =
'parameter') {
624 if (isset($_GET[$varname])) {
625 $danger_value = $_GET[$varname];
627 if (isset($_POST[$varname])) {
628 $danger_value = $_POST[$varname];
632 if (($danger_value !==
'') && ($danger_value !==
null)) {
633 if (dbx_validate_var($danger_value, $rules, $varname)) {
634 $value = $danger_value;
650 public function get(
string $varname, $default =
'',
string $rules =
'parameter') {
655 if (isset($_GET[$varname])) {
656 $danger_value = $_GET[$varname];
659 if (dbx_validate_var($danger_value, $rules, $varname)) {
660 $value = $danger_value;
676 public function post(
string $varname, $default =
'',
string $rules =
'parameter') {
681 if (isset($_POST[$varname])) {
682 $danger_value = $_POST[$varname];
685 if (dbx_validate_var($danger_value, $rules, $varname)) {
686 $value = $danger_value;
697 public function get_request_var(
string $varname, $default =
'',
string $rules =
'parameter') {
698 return $this->req($varname, $default, $rules);
704 public function get_query_var(
string $varname, $default =
'',
string $rules =
'parameter') {
705 return $this->
get($varname, $default, $rules);
711 public function get_post_var(
string $varname, $default =
'',
string $rules =
'parameter') {
712 return $this->post($varname, $default, $rules);
732 public function get_config(
string $modul =
'dbx',
string $key =
'', $default =
null) {
735 if (file_exists($moduleConfigFile)) {
736 $_SESSION[
'dbx'][
'config_file'][$modul] = $moduleConfigFile;
737 $this->register_editor_file(
'config', $moduleConfigFile);
741 if (!isset($_SESSION[
'dbx'][
'config'][$modul])) {
745 $dir_file = $moduleConfigFile;
746 if (file_exists($dir_file)) {
747 $_SESSION[
'dbx'][
'config_file'][$modul] = $dir_file;
748 $this->register_editor_file(
'config', $dir_file);
749 $content = file_get_contents($dir_file);
754 $clean_code = str_replace([
'<?php',
'?>'],
'', $content);
757 set_error_handler(
function ($errno, $errstr, $errfile, $errline) {
758 throw new Exception(
"Fehler in eval() Code: $errstr in Zeile $errline");
763 }
catch (Exception $e) {
764 echo
"Fehler: " . $e->getMessage();
766 restore_error_handler();
771 if (!isset(
$config[
'groups'])) {
773 } elseif (!is_array(
$config[
'groups'])) {
774 $config[
'groups'] = array_filter(explode(
',',
$config[
'groups']));
777 $fileDefaults = $this->read_module_config_defaults($modul);
778 if (is_array($fileDefaults) && count($fileDefaults)) {
783 $_SESSION[
'dbx'][
'config'][$modul] =
$config;
787 $config = $_SESSION[
'dbx'][
'config'][$modul];
789 static $configDefaultsMerged = array();
790 if (!isset($configDefaultsMerged[$modul])) {
791 $fileDefaults = $this->read_module_config_defaults($modul);
792 if (is_array($fileDefaults) && count($fileDefaults)) {
793 $merged = array_merge($fileDefaults,
$config);
796 $_SESSION[
'dbx'][
'config'][$modul] =
$config;
799 $configDefaultsMerged[$modul] = 1;
804 if (!array_key_exists($key,
$config)) {
805 return $default !==
null ? $default :
'undef';
809 if (($val ===
'undef' || $val ===
'' || $val ===
null) && $default !==
null) {
826 private function read_module_config_defaults(
string $modul): array {
827 if ($modul ===
'dbx') {
832 if (!is_file($dir_file) || !is_readable($dir_file)) {
837 $content = file_get_contents($dir_file);
838 if (!is_string($content) || $content ===
'') {
842 $clean_code = str_replace(array(
'<?php',
'?>'),
'', $content);
843 set_error_handler(
function ($errno, $errstr, $errfile, $errline) {
844 throw new \Exception(
"Fehler in config.php: $errstr in Zeile $errline");
849 }
catch (\Exception $e) {
852 restore_error_handler();
870 public function set_config(
string $modul, array
$config): int {
871 $content =
"<?php \n";
873 if (isset(
$config[
'form-config-edit'])) unset(
$config[
'form-config-edit']);
881 $_SESSION[
'dbx'][
'config'][$modul] =
$config;
882 $content .= dbx_convertArrayToPHPCode(
$config,
'$config');
887 mkdir(
$dir, 0700,
true);
891 $ok = file_put_contents($dir_file, $content);
892 dbx()->debug(
"#CFG write ok=($ok) file=($dir_file)");
894 $_SESSION[
'dbx'][
'config_file'][$modul] = $dir_file;
895 $this->register_editor_file(
'config', $dir_file);
926 public function send_mail($from, $to,
string $subject =
'',
string $body =
'',
string $format =
'html', $attachments = array(), array $options = array()): int {
927 $mail = $this->get_system_obj(
'dbxMail');
933 $options[
'from'] = $from;
935 $format = strtolower(trim($format));
936 if ($format ===
'txt') {
940 if ($format ===
'html') {
941 $mail->bodyhtml($body);
942 if (isset($options[
'text'])) {
943 $mail->bodytext((
string) $options[
'text']);
946 $mail->bodytext($body);
949 foreach ($this->normalize_mail_attachments($attachments) as $attachment) {
950 if (is_array($attachment)) {
952 (
string) ($attachment[
'path'] ?? $attachment[
'file'] ??
''),
953 (
string) ($attachment[
'disposition'] ??
'attachment'),
954 (
string) ($attachment[
'content_type'] ?? $attachment[
'type'] ??
''),
955 (
string) ($attachment[
'cid'] ??
'')
958 $mail->attachfile((
string) $attachment);
962 return (
int) $mail->send($to, $subject, $options);
965 private function normalize_mail_attachments($attachments): array {
966 if ($attachments === null || $attachments ===
'') {
970 if (is_string($attachments)) {
971 return array_filter(array_map(
'trim', preg_split(
'/[;,]+/', $attachments)));
974 if (is_array($attachments)) {
975 if (isset($attachments[
'path']) || isset($attachments[
'file'])) {
976 return array($attachments);
1000 public function get_remember_var(
string $varname, $default =
'',
string $modul =
'modul') {
1006 if ($modul ==
'modul') {
1007 $modul = $this->get_system_var(
'dbx_activ_modul',
'dbx',
'*');
1011 if (isset($_SESSION[
'dbx'][
'remember'][$modul][$varname])) {
1012 $value = $_SESSION[
'dbx'][
'remember'][$modul][$varname];
1035 public function set_remember_var(
string $varname, $value,
string $modul =
'modul') {
1037 if ($modul ==
'modul') {
1038 $modul = $this->get_system_var(
'dbx_activ_modul',
'dbx',
'*');
1042 $_SESSION[
'dbx'][
'remember'][$modul][$varname] = $value;
1045 if ($modul ==
'dbx') {
1046 $this->set_system_var($varname, $value);
1064 public function get_session_var($key,$default=
null,$section=
'sys',$modul=
'modul') {
1066 if ($modul==
'modul') $modul =$this->get_system_var(
'dbx_activ_modul' ,
'dbx');
1068 if (isset($_SESSION[
'dbx'][
'session'][$modul][$section][$key])) {
1069 $val=$_SESSION[
'dbx'][
'session'][$modul][$section][$key];
1072 if (isset($_SESSION[
'dbx'][
'session'][$modul][$section])) {
1073 $val=$_SESSION[
'dbx'][
'session'][$modul][$section];
1088 public function set_session_var($key,$val,$section=
'sys',$modul=
'') {
1089 if (!$modul) $modul =$this->get_system_var(
'dbx_activ_modul' ,
'dbx');
1090 if ($key !=
'*') $_SESSION[
'dbx'][
'session'][$modul][$section][$key]=$val;
1091 if ($key ==
'*') $_SESSION[
'dbx'][
'session'][$modul][$section]=$val;
1101 public function delete_session_var($key,$section=
'sys',$modul=
'modul') {
1102 if ($modul==
'modul') $modul =$this->get_system_var(
'dbx_activ_modul' ,
'dbx');
1104 if (isset($_SESSION[
'dbx'][
'session'][$modul][$section][$key])) {
1105 unset($_SESSION[
'dbx'][
'session'][$modul][$section][$key]);
1109 if (isset($_SESSION[
'dbx'][
'session'][$modul][$section])) {
1110 unset($_SESSION[
'dbx'][
'session'][$modul][$section]);
1113 if ($key ==
'*' && $section==
'*') {
1114 if (isset($_SESSION[
'dbx'][
'session'][$modul])) {
1115 unset($_SESSION[
'dbx'][
'session'][$modul]);
1128 public function action_token(
string $scope =
'global'): string {
1129 $scope = preg_replace(
'/[^a-zA-Z0-9_.:-]/',
'', $scope) ?:
'global';
1130 $tokens = $this->get_session_var(
'action_tokens', array(),
'security',
'dbx');
1131 if (!is_array($tokens)) {
1135 if (empty($tokens[$scope]) || !preg_match(
'/^[a-f0-9]{64}$/', (
string)$tokens[$scope])) {
1136 $tokens[$scope] = bin2hex(random_bytes(32));
1137 $this->set_session_var(
'action_tokens', $tokens,
'security',
'dbx');
1140 return (
string)$tokens[$scope];
1150 public function check_action_token(
string $scope =
'global',
string $token =
''): bool {
1151 $scope = preg_replace(
'/[^a-zA-Z0-9_.:-]/',
'', $scope) ?:
'global';
1152 $expected = $this->action_token($scope);
1153 return $token !==
'' && hash_equals($expected, $token);
1168 public function user($key=
'id') {
1169 $current_user = $_SESSION[
'dbx'][
'current_user'] ?? array();
1171 if (defined(
'dbxRunAsAdmin') && (
int) constant(
'dbxRunAsAdmin') === 1) {
1172 $current_user = $this->get_admin_bypass_user($current_user);
1176 return $current_user;
1179 return $current_user[$key] ??
null;
1192 private function get_admin_bypass_user(array $session_user = array()): array {
1193 if ((int)($session_user[
'id'] ?? 0) === 1) {
1194 return $session_user;
1197 if ($this->admin_bypass_user_loaded || $this->admin_bypass_user_loading) {
1198 return $this->admin_bypass_user;
1201 $this->admin_bypass_user = array_merge($session_user, array(
1207 'design' => $session_user[
'design'] ??
'default',
1208 'color' => $session_user[
'color'] ??
'default',
1209 'language' => $session_user[
'language'] ??
'de',
1210 'edit' => $session_user[
'edit'] ?? 0,
1212 $this->admin_bypass_user_loading =
true;
1215 $session = $this->get_system_obj(
'dbxSession');
1216 if (is_object($session) && method_exists($session,
'get_current_user')) {
1217 $admin_user = $session->get_current_user(1);
1218 if (is_array($admin_user) && (
int)($admin_user[
'id'] ?? 0) === 1) {
1219 $this->admin_bypass_user = $admin_user;
1222 }
catch (\Throwable $e) {
1225 $this->admin_bypass_user_loading =
false;
1226 $this->admin_bypass_user_loaded =
true;
1229 return $this->admin_bypass_user;
1244 public function can($access_groups =
'', $user_groups =
'') {
1246 if (defined(
'dbxRunAsAdmin') && (
int) constant(
'dbxRunAsAdmin') === 1)
return 1;
1247 if ($access_groups==
'*')
return 1;
1248 if (!$access_groups)
return 1;
1249 $current_user_groups = !$user_groups;
1250 if ($current_user_groups) $user_groups = $_SESSION[
'dbx'][
'current_user'][
'roles'] ??
'';
1252 if (!is_array($user_groups)) $user_groups = explode(
',', $user_groups);
1253 if (!is_array($access_groups)) $access_groups = explode(
',', $access_groups);
1254 $user_groups = array_map(
'trim', $user_groups);
1255 $access_groups = array_map(
'trim', $access_groups);
1257 if ($current_user_groups && in_array(
'authenticated', $access_groups,
true) && (
int)$this->user() > 0) {
1261 foreach ($user_groups as $role) {
1262 if ($role ===
'admin')
return 1;
1264 foreach ($access_groups as $group) {
1265 if ($group ===
'*' || $group === $role) $access = 1;
1266 if ($access)
break 2;
1273 public function has_group($access_groups =
'', $user_groups =
'') {
1274 return $this->can($access_groups, $user_groups);
1282 public function is_dbx_edit(): bool {
1283 return (int) $this->get_system_var(
'dbx_edit', 0,
'int') > 0;
1293 public function can_modul($modul) {
1297 $current_user= $_SESSION[
'dbx'][
'current_user'] ?? array();
1298 $modul_config= $this->get_config($modul);
1299 $groups =$modul_config[
'groups'] ??
'';
1300 $uid =$current_user[
'id'] ?? 0;
1301 $install=$this->get_system_var(
'dbx_install',0,
'int');
1303 if (defined(
'dbxRunAsAdmin') && (
int) constant(
'dbxRunAsAdmin') === 1) {
1306 if ((
int)$uid === 1) {
1310 $access = $install ? 1 : $this->can($groups);
1312 if ($access==0) $this->set_system_var(
'dbx_noaccess_modul',
"(User=$uid Modul=$modul)");
1328 public function login($uid=0,$remember=0) {
1330 dbx()->debug(
"API dbx_login von ($old) Zu ($uid)");
1332 $oSession=$this->get_system_obj(
'dbxSession');
1333 $oSession->login($uid,$remember);
1335 $page = $this->get_base_url();
1336 $from = $this->user(
'email');
1337 $fromname = $this->user(
'name');
1338 $subject =
'Login ('.$from.
') on ('.$page.
') User=('.$uid.
')';
1352 public function logout($uid=0) {
1353 if (!$uid) $uid=$this->user();
1354 dbx()->debug(
"API dbx_logout uid=($uid)");
1355 $oSession=$this->get_system_obj(
'dbxSession');
1356 $oSession->logout($uid);
1364 public function get_base_url() {
1365 return $this->get_system_var(
'dbx_base_url',
'',
'*');
1373 public function get_self_url() {
1374 return $this->get_system_var(
'dbx_self_url',
'',
'*');
1383 public function get_base_dir(
int $cutData = 0): string {
1392 public function get_file_dir(): string {
1402 public function os_path(
string $path): string {
1413 public function json_response(array $data,
bool $withRuntime =
false): void {
1415 $runtime = number_format($this->current_php_runtime(), 3,
'.',
'');
1416 $data[
'dbx_php_runtime'] = $runtime;
1417 $data[
'_dbx_runtime'] = array(
'php' => $runtime);
1418 $this->send_runtime_headers();
1421 if (!headers_sent()) {
1422 header(
'Content-Type: application/json; charset=utf-8');
1425 echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
1443 public function timer($section,$info=
'') {
1444 global $dbx_run_timer;
1447 $time = microtime(
true);
1448 $memory = memory_get_peak_usage();
1451 if (!isset($dbx_run_timer[$section])) {
1453 $dbx_run_timer[$section][
'start_time'] =$time;
1454 $dbx_run_timer[$section][
'end_time'] =-1;
1455 $dbx_run_timer[$section][
'start_memory']=$memory;
1456 $dbx_run_timer[$section][
'end_memory'] =-1;
1457 $dbx_run_timer[$section][
'time'] =-1;
1458 $dbx_run_timer[$section][
'memory'] =-1;
1459 $dbx_run_timer[$section][
'info'] =$info;
1460 $this->timer_state[$section] = array(
1462 'segment_start_time' => $time,
1463 'segment_start_memory' => $memory,
1467 $state = $this->timer_state[$section] ?? array();
1468 $running = (int) ($state[
'running'] ?? (($dbx_run_timer[$section][
'end_time'] ?? -1) == -1 ? 1 : 0));
1472 $segment_start_time = (float) ($state[
'segment_start_time'] ?? $dbx_run_timer[$section][
'start_time'] ?? $time);
1473 $segment_start_memory = (int) ($state[
'segment_start_memory'] ?? $dbx_run_timer[$section][
'start_memory'] ?? $memory);
1474 $time_sum = max(0, (
float) ($dbx_run_timer[$section][
'time'] ?? 0));
1475 $memory_sum = max(0, (
int) ($dbx_run_timer[$section][
'memory'] ?? 0));
1477 $dbx_run_timer[$section][
'end_time'] = $time;
1478 $dbx_run_timer[$section][
'end_memory']= $memory;
1479 $dbx_run_timer[$section][
'time'] = $time_sum + max(0, $time - $segment_start_time);
1480 $dbx_run_timer[$section][
'memory'] = $memory_sum + max(0, $memory - $segment_start_memory);
1481 $this->timer_state[$section] = array(
1483 'segment_start_time' => $segment_start_time,
1484 'segment_start_memory' => $segment_start_memory,
1485 'segments' => (
int) ($state[
'segments'] ?? 0) + 1,
1487 } elseif ($info !==
'') {
1488 if (($dbx_run_timer[$section][
'info'] ??
'') ===
'') {
1489 $dbx_run_timer[$section][
'info'] = $info;
1492 $dbx_run_timer[$section][
'end_time'] = -1;
1493 $dbx_run_timer[$section][
'end_memory'] = -1;
1494 $this->timer_state[$section] = array(
1496 'segment_start_time' => $time,
1497 'segment_start_memory' => $memory,
1498 'segments' => (
int) ($state[
'segments'] ?? 0),
1511 public function skin_ids(): array {
1512 return array(
'hell',
'gelb',
'rot',
'gruen',
'blau',
'dunkel');
1521 public function normalize_skin(
string $skin =
''): string {
1522 $skin = strtolower(trim($skin));
1532 'black' =>
'dunkel',
1534 'dunkel' =>
'dunkel',
1542 if ($skin !==
'' && isset($map[$skin])) {
1543 $skin = $map[$skin];
1546 if ($skin ===
'' || !in_array($skin, $this->skin_ids(),
true)) {
1547 $cfg = strtolower(trim((
string) $this->get_config(
'dbx',
'default_color',
'blau')));
1551 if (!in_array($skin, $this->skin_ids(),
true)) {
1563 public function get_skin(): string {
1564 return $this->normalize_skin((string) $this->get_system_var(
'dbx_color',
''));
1572 public function get_skin_css(): string {
1573 $skin = $this->get_skin();
1574 $design = (string) $this->get_system_var(
'dbx_activ_design', $this->get_system_var(
'dbx_design',
'dbxapp'));
1576 return 'dbx/design/' . $design .
'/css/skin-' . $skin .
'.css';
1584 public function get_skin_class(): string {
1585 $skin = $this->get_skin();
1586 $cls =
'skin-' . $skin;
1588 if ($skin ===
'dunkel') {
1589 $cls .=
' theme-dark';
1600 public function load_content_cache_classes(): void {
1601 static $loaded = false;
1615 public function get_content_permalink_mode(): string {
1616 $file = $this->os_path($this->get_base_dir() .
'dbx/modules/dbxContent/include/dbxContentLng.class.php');
1617 if (is_file($file)) {
1621 return class_exists(
'\dbx\dbxContent\dbxContentLng')
1632 public function find_executable_path(
string $command): string {
1633 static $cache = array();
1635 $command = trim($command);
1636 if ($command ===
'' || !preg_match(
'/^[a-zA-Z0-9_.-]+$/', $command)) {
1640 if (array_key_exists($command, $cache)) {
1641 return $cache[$command];
1644 $lookup = stripos(PHP_OS_FAMILY,
'Windows') === 0
1645 ?
'where ' . $command .
' 2>NUL'
1646 :
'command -v ' . $command .
' 2>/dev/null';
1648 $result = trim((
string)@shell_exec($lookup));
1650 $cache[$command] = is_string($path) ? trim($path) :
'';
1652 return $cache[$command];
1661 public function log_missing($missing =
'') {
1662 $missing = trim((
string)$missing);
1663 if ($missing ===
'') {
1667 if (strlen($missing) > 250) {
1668 $missing = substr($missing, 0, 250);
1672 $db = $this->get_system_obj(
'dbxDB');
1673 if (!is_object(
$db)) {
1677 $uid = (int)$this->user();
1678 $rec =
$db->select1(
'dbxMissing', array(
'missing' => $missing),
'id,count', 0);
1680 if (is_array($rec) && (
int)($rec[
'id'] ?? 0) > 0) {
1681 $id = (int)$rec[
'id'];
1682 $db->update(
'dbxMissing', array(
1683 'count' => ((
int)($rec[
'count'] ?? 0)) + 1,
1684 ), $id, 0, 1, 1, 0);
1688 $ok =
$db->insert(
'dbxMissing', array(
1689 'missing' => $missing,
1694 return $ok ? (int)
$db->get_insert_id() : 0;
1695 }
catch (\Throwable $e) {
1696 if (function_exists(
'dbx_write_php_error_log')) {
1719 public function sys_msg($status =
'', $about =
'', $rid =
'', $why =
'', $what =
'') {
1720 if ($this->sys_msg_running) {
1724 $this->sys_msg_running =
true;
1727 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
1728 $caller = $trace[1] ??
null;
1729 $file = $caller[
'file'] ??
'';
1730 $line = (int)($caller[
'line'] ?? 0);
1732 $status = strtolower(trim((
string)$status));
1733 if ($status ===
'') {
1749 $level = $level_map[$status] ?? 10;
1750 if ($status ===
'warn') {
1751 $status =
'warning';
1754 $sysMsgLevel = strtolower(trim((
string) $this->get_config(
'dbx',
'sys_msg_level',
'all')));
1755 if ($sysMsgLevel ===
'') {
1756 $sysMsgLevel =
'all';
1760 if ($sysMsgLevel ===
'error') {
1762 } elseif ($sysMsgLevel ===
'warning' || $sysMsgLevel ===
'warn') {
1766 if ($level < $minLevel) {
1770 $modul = $this->get_modul_var(
'dbx_modul', $this->get_system_var(
'dbx_activ_modul' ,
'dbx',
'*'), rules:
'*');
1771 $action = $this->get_modul_var(
'dbx_run1' , $this->get_system_var(
'dbx_activ_action',
'' ,
'*'), rules:
'*');
1772 $work = $this->get_modul_var(
'dbx_run2' ,
'',
'*');
1775 if (is_array($what) || is_object($what)) {
1776 $data_json = json_encode($what, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
1777 $what_text = $data_json ?:
'';
1779 $what_text = (string)$what;
1782 $message_parts = array();
1783 if ((
string)$about !==
'') $message_parts[] = (string)$about;
1784 if ((
string)$why !==
'') $message_parts[] =
'why=' . (string)$why;
1785 if ($what_text !==
'') $message_parts[] =
'what=' . $what_text;
1786 if ((
string)$rid !==
'') $message_parts[] =
'rid=' . (string)$rid;
1787 $message = implode(
' | ', $message_parts);
1790 'xuser' => $this->user(
'id'),
1792 'status' => $status,
1793 'about' => (
string)$about,
1794 'rid' => (
string)$rid,
1795 'why' => (
string)$why,
1796 'what' => $what_text,
1797 'message' => $message,
1798 'modul' => (
string)$modul,
1799 'action' => (
string)$action,
1800 'work' => (
string)$work,
1801 'source_file' => (
string)$file,
1802 'source_line' => $line,
1803 'data_json' => $data_json,
1806 $oDB = $this->get_system_obj(
'dbxDB');
1807 $prevReport = (int)$oDB->_report_error;
1808 $oDB->_report_error = 0;
1809 $ok = $oDB->insert(
'dbxSysMsg', $record, 0, 1, 0, 0);
1810 $oDB->_report_error = $prevReport;
1811 $insertId = $ok ? $oDB->get_insert_id() : 0;
1813 dbx()->debug(
"##SYS-MSG### ok=($ok) id=($insertId) Level=($level) Status=($status) Modul=($modul) Action=($action) Work=($work) About=($about) RID=($rid) Why=($why) What=($what_text)");
1815 return (
int)$insertId;
1817 $this->sys_msg_running =
false;
1832 public function norep($norep,$i=0) {
1833 $norep=str_replace(
"\r",
'',$norep);
1834 $norep_id=
'norep_'.$this->next_id();
1835 $_SESSION[
'dbx'][
'norep'][$norep_id]=$norep;
1836 return '['.$norep_id.
']';
1845 public function next_id(
int $add = 1): int {
1847 $i = $this->get_remember_var(
'dbx_next_i', 0,
'dbx');
1853 $this->set_remember_var(
'dbx_next_i', $i,
'dbx');
1865 public function is_modul($modul) {
1868 $modul_class_file=
dbx_get_base_dir().
"dbx/modules/$modul/".$modul.
".class.php";
1869 if (file_exists($modul_class_file)) $retval=
true;
1881 public function is_design($design,$page=
'default') {
1882 $admin=$this->can(
'admin');
1883 $firstchar=substr($design,0,1);
1884 if (!$admin && $firstchar ==
'_')
return false;
1885 if (!$admin && $firstchar ==
'-')
return false;
1888 if (file_exists($design_tpl))
return true;
1889 if ($page !=
'default') {
1891 if (file_exists($design_tpl))
return true;
1904 public function redirect($redirect, $timer = 0) {
1905 $timer = ($timer * 1000);
1906 $base = $this->get_base_url();
1907 $ajax = $this->get_system_var(
'dbx_ajax', 0,
'int');
1909 dbx()->debug(
"run redirect ($redirect)");
1911 if (!str_contains($redirect,
'://'))
1912 $redir =
$base . $redirect;
1916 dbx()->debug(
"#dbx_redirect Call=($redirect) redir=($redir) Ajax=($ajax) timer=($timer)");
1918 $redir_js = json_encode($redir);
1921 $script =
"<script>window.location.replace($redir_js);</script>";
1923 $script =
"<script>setTimeout(function() { window.location.replace($redir_js); }, $timer);</script>";
1937 public function set_cookie_var($cookie,$key,$val) {
1938 $_SESSION[
'dbx'][
'cookie'][$cookie][$key]=$val;
1948 public function has_text($string,$find) {
1949 return strpos(
'~'.$string,$find);
1958 public function html($html) {
1959 return htmlentities($html, ENT_QUOTES);
1972 public function esc($value): string {
1973 return htmlspecialchars(
1975 ENT_QUOTES | ENT_SUBSTITUTE,
1988 public function search_defaults(array $overrides = array()): array {
1990 'placeholder' =>
'🔍',
1991 'title' =>
'Suchen',
1994 'input_class' =>
'form-control-sm dbx-grid-search',
1995 'data_role' =>
'search',
1998 'extra_attrs' =>
'',
2001 if (array_key_exists(
'placeholder', $overrides) && trim((
string) $overrides[
'placeholder']) ===
'') {
2002 unset($overrides[
'placeholder']);
2005 return array_merge($defaults, $overrides);
2016 public function search_html(array $opts = array()): string {
2017 $opts = $this->search_defaults($opts);
2018 $i = (int) ($opts[
'i'] ?? 0);
2019 $name = (string) ($opts[
'name'] ??
'');
2020 $label = trim((
string) ($opts[
'label'] ??
''));
2021 $tooltip = trim((
string) ($opts[
'tooltip'] ??
'')) !==
''
2022 ? (string) $opts[
'tooltip']
2023 : (string) ($opts[
'title'] ??
'Suchen');
2026 'name' => $this->esc($name),
2027 'value' => $this->esc((
string) ($opts[
'value'] ??
'')),
2028 'placeholder' => $this->esc((
string) ($opts[
'placeholder'] ??
'🔍')),
2029 'title' => $this->esc((
string) ($opts[
'title'] ??
'Suchen')),
2030 'tooltip' => $this->esc($tooltip),
2031 'errormsg' => $this->esc((
string) ($opts[
'errormsg'] ??
'')),
2032 'class' => $this->esc((
string) ($opts[
'class'] ??
'')),
2033 'input_class' => $this->esc((
string) ($opts[
'input_class'] ??
'form-control-sm dbx-grid-search')),
2034 'wrap_class' => $this->esc((
string) ($opts[
'wrap_class'] ??
'')),
2035 'wrap_style' => $this->esc((
string) ($opts[
'wrap_style'] ??
'')),
2036 'data_role' => $this->esc((
string) ($opts[
'data_role'] ??
'search')),
2037 'extra_attrs' => (
string) ($opts[
'extra_attrs'] ??
''),
2040 $html = $this->get_system_obj(
'dbxTPL')->get_tpl(
'dbx|search', $data,
'htm', $i);
2042 if ($label ===
'') {
2046 $fieldId = $this->esc($name !==
'' ? $name .
'_' . $i :
'dbx_search_' . $i);
2047 $style = $this->esc((
string) ($opts[
'style'] ??
''));
2049 return '<div class="fld-frame dbx-search-field" style="' . $style .
'">'
2050 .
'<label for="' . $fieldId .
'" class="control-label">' . $this->esc($label) .
'</label>'
2061 public function timestamp($add_sec=0) {
2062 list($usec, $sec) = explode(
" ",microtime());
2063 $time= ((float) $usec + (float)$sec);
2064 $time= (float) ($time + ($add_sec));
2075 public function time_diff($starttime=0,$endtime=0) {
2076 if (!$starttime) $starttime=$this->timestamp();
2077 if (!$endtime) $endtime =$this->timestamp();
2078 return ($endtime-$starttime);
2089 public function part_select($vor,$nach,$part) {
2090 $leng= strlen($vor);
2091 $pos1= strpos($part, $vor);
2093 if ($pos1 ===
false) {
2097 $part= substr($part, ($pos1+$leng));
2098 $pos2= strpos($part, $nach);
2100 if ($pos2 ===
false) {
2104 $part= substr($part, 0,$pos2);
2115 public function parse_url($data) {
2116 if (!is_array($data)) {
2117 $first=substr($data,0,1);
2118 if ($data && $first !=
'=') {
2119 if (strpos($data,
'=')) {
2120 parse_str($data,$xdata);
2134 public function is_int_value($value) {
2135 if (is_int($value))
return 1;
2136 if (is_string($value) && filter_var($value, FILTER_VALIDATE_INT) !==
false)
return 1;
2147 public function new_password($minlength, $special =
'-_!') {
2149 $syllabels =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' . $special;
2150 $len = strlen($syllabels) - 1;
2153 if ($minlength < 1)
return '';
2157 for ($i = 0; $i < 300; $i++) {
2158 $ch = $syllabels[mt_rand(0, $len)];
2159 if (ctype_lower($ch) && mt_rand(0, 4) == 1) {
2160 $ch = strtoupper($ch);
2166 for ($i = 0; $i < $minlength; $i++) {
2167 $passwort .= $box[mt_rand(0, 299)];
2179 public function debug_timer($max=0) {
2180 Global $dbx_run_timer;
2181 if (isset($dbx_run_timer[
'system'][
'time'])) {
2182 $time=$dbx_run_timer[
'system'][
'time'];
2184 $this->debug(
"#RUN-TIMER",$dbx_run_timer);
2186 $this->debug(
"dbx System run time=($time)");
2196 public function current_php_runtime(): float {
2197 global $dbx_run_timer;
2199 if (isset($dbx_run_timer[
'system'][
'time']) && is_numeric($dbx_run_timer[
'system'][
'time']) && (
float) $dbx_run_timer[
'system'][
'time'] >= 0) {
2200 return (
float) $dbx_run_timer[
'system'][
'time'];
2203 if (isset($dbx_run_timer[
'system'][
'start_time']) && is_numeric($dbx_run_timer[
'system'][
'start_time'])) {
2204 return max(0.0, microtime(
true) - (
float) $dbx_run_timer[
'system'][
'start_time']);
2217 public function current_memory_bytes(): int {
2218 global $dbx_run_timer;
2220 if (isset($dbx_run_timer[
'system'][
'memory']) && is_numeric($dbx_run_timer[
'system'][
'memory']) && (
float) $dbx_run_timer[
'system'][
'memory'] >= 0) {
2221 return (
int) round((
float) $dbx_run_timer[
'system'][
'memory']);
2224 if (isset($dbx_run_timer[
'system'][
'start_memory'], $dbx_run_timer[
'system'][
'end_memory'])
2225 && is_numeric($dbx_run_timer[
'system'][
'start_memory'])
2226 && is_numeric($dbx_run_timer[
'system'][
'end_memory'])) {
2227 return max(0, (
int) round((
float) $dbx_run_timer[
'system'][
'end_memory'] - (
float) $dbx_run_timer[
'system'][
'start_memory']));
2238 public function send_runtime_headers(): void {
2239 if (headers_sent()) {
2243 $runtime = $this->current_php_runtime();
2244 header(
'X-DBX-PHP-Runtime: ' . number_format($runtime, 3,
'.',
''));
2245 header(
'Server-Timing: dbxphp;dur=' . number_format($runtime * 1000, 3,
'.',
'') .
';desc="DBX PHP Runtime"',
false);
2256 public function store_performance_timer(): int {
2259 if (!is_file($file)) {
2264 if (!class_exists(
'dbxPerformanceTimer')) {
2268 $timer = new \dbxPerformanceTimer();
2269 if (!method_exists($timer,
'store')) {
2273 return (
int) $timer->store();
2274 }
catch (\Throwable $e) {
2275 if (function_exists(
'dbx_write_php_error_log')) {
2288 public function debug2($line) {
2291 file_put_contents($file, $line, FILE_APPEND);
2311 public function debug($txt, $data1 =
'', $data2 =
'', $data3 =
'') {
2312 $activ = $this->get_remember_var(
'dbx_debug_activ', -1,
'dbx');
2317 if (file_exists($debugActiv)) {
2320 $this->set_remember_var(
'dbx_debug_activ',
$activ,
'dbx');
2331 foreach (array($data1, $data2, $data3) as $data) {
2332 if (is_array($data)) {
2333 $vars .= print_r($data,
true);
2336 $vars .= $data .
"\n";
2341 $txt .=
"\n" . $vars .
"\n";
2342 file_put_contents($file, $txt, FILE_APPEND);
2353 private function get_SysClassOverrideName(
string $class): string {
2354 if (str_starts_with($class,
'dbx')) {
2355 $suffix = substr($class, 3);
2356 return 'my' . ($suffix ?: $class);
2358 return 'my' . $class;
2373 private function ensure_SysClassOverride(
string $class,
string $myClass,
string $baseClass): string {
2374 if ($baseClass ===
"\\dbxUndefClass" || !class_exists($baseClass, false)) {
2382 if (!is_dir($sysDir)) {
2383 mkdir($sysDir, 0777,
true);
2387 if (!is_dir($cfgDir)) {
2388 mkdir($cfgDir, 0777,
true);
2392 if (!file_exists($cfgFile)) {
2393 file_put_contents($cfgFile,
"<?php\n\$config['version']='1';\n\$config['activ']='1';\n\$config['groups']='*';\n");
2397 if (!file_exists($moduleFile)) {
2398 file_put_contents($moduleFile,
"<?php\nnamespace dbx\\myX;\n\nclass myX {\n public function run() {\n return 'myX system module';\n }\n}\n");
2401 if (!file_exists($file)) {
2402 $content =
"<?php\n";
2403 $content .=
"/**\n";
2404 $content .=
" * Auto-generated DBX system class override.\n";
2405 $content .=
" * Requested class: $class\n";
2406 $content .=
" * Override class: $myClass\n";
2407 $content .=
" */\n";
2408 $content .=
"class $myClass extends $class {\n";
2410 file_put_contents($file, $content);
2430function dbx(): dbxApi {
2432 if ($api ===
null) {
2433 $api =
new dbxApi();
2444function ge_stichtag() {
2445 $heute =
new DateTime();
2446 $grenze =
new DateTime(
'2025-06-01');
2447 return $heute >= $grenze;
2458function dbx_copy_recursive($src, $dst) {
2459 $src = rtrim($src,
'/\\');
2460 $dst = rtrim($dst,
'/\\');
2462 if (!is_dir($src)) {
2463 dbx()->debug(
"dbx_copy_recursive Error DIR");
2467 if (!file_exists($dst)) {
2468 if (!mkdir($dst, 0777,
true)) {
2469 dbx()->debug(
"dbx_copy_recursive mkdir Error($dst)");
2474 $items = scandir($src);
2475 foreach ($items as $item) {
2476 if ($item ===
'.' || $item ===
'..') {
2480 $srcPath = $src . DIRECTORY_SEPARATOR . $item;
2481 $dstPath = $dst . DIRECTORY_SEPARATOR . $item;
2483 if (is_dir($srcPath)) {
2485 if (!dbx_copy_recursive($srcPath, $dstPath)) {
2486 dbx()->debug(
"dbx_copy_recursive Error A");
2491 if (!copy($srcPath, $dstPath)) {
2492 dbx()->debug(
"dbx_copy_recursive Error B");
2519function dbx_DateTime($date_time=
'now',$calc=0,$special=
'') {
2520 $timezone =
'Europe/Berlin';
2523 if ($date_time==
'now') {
2524 $offset = (60*60*$offset);
2525 $calc=($calc + $offset);
2526 $date_time = date(
"Y-m-d H:i:s", (time() + $calc));
2528 $offset = (60*60*$offset);
2529 $calc=($calc + $offset);
2530 $date_time = date(
"Y-m-d H:i:s", (strtotime($date_time) + $calc ));
2534 $time=strtotime($date_time);
2535 $date_time=date(
"Y-m-d H:i:s", strtotime($special, $time));
2539 $week_start = strtotime(
'last Sunday', time());
2540 $week_end = strtotime(
'next Sunday', time());
2542 $month_start = strtotime(
'first day of this month', time());
2543 $month_end = strtotime(
'last day of this month', time());
2545 $year_start = strtotime(
'first day of January', time());
2546 $year_end = strtotime(
'last day of December', time());
2566function dbx_make_dir(
string $path): int {
2568 if (is_dir($path)) return 1;
2571 if (mkdir($path, 0777,
true)) {
2592function dbx_sendMail($from,$fromname,$to,$subject,$text,$type=
'html',$attach=
'',$archiv=0) {
2593 $from = array(
'email' => $from,
'name' => $fromname);
2594 return dbx()->send_mail($from, $to, (
string) $subject, (
string) $text, (
string) $type, $attach);
2606function dbx_is_page($page,$design,$lng=
'') {
2609 if (file_exists($page_tpl)) $retval=
true;
2663function dbx_lng_current(): string {
2664 $lng = strtolower(trim((string)
dbx()->get_system_var(
'dbx_lng',
'de')));
2665 return $lng !==
'' ? $lng :
'de';
2673function dbx_accessible_lngs(): array {
2674 $raw =
dbx()->get_config(
'dbx',
'accessible_lng',
'de');
2675 if ($raw ===
'undef' || $raw ===
'' || $raw ===
null) {
2678 if (is_array($raw)) {
2680 foreach ($raw as $val) {
2681 $val = strtolower(trim((
string) $val));
2682 if ($val !==
'' && $val !==
'undef' && preg_match(
'/^[a-z]{2,3}$/', $val)) {
2686 return count($out) ? $out : array(
'de');
2689 $parts = preg_split(
'/\s*,\s*/', (
string) $raw, -1, PREG_SPLIT_NO_EMPTY);
2691 if (is_array($parts)) {
2692 foreach ($parts as $val) {
2693 $val = strtolower(trim((
string) $val));
2694 if ($val !==
'' && $val !==
'undef' && preg_match(
'/^[a-z]{2,3}$/', $val)) {
2700 return count($out) ? $out : array(
'de');
2710function dbx_lng_name(
string $base,
string $lng =
''): string {
2716 $lng = strtolower(trim($lng !==
'' ? $lng : dbx_lng_current()));
2721 return $base .
'_' . $lng;
2734function dbx_lng_resolve_file(
string $dir,
string $name,
string $ext,
string $lng =
'',
bool $fallback =
true): string {
2735 $dir = str_replace(
'\\',
'/',
$dir);
2736 if (
$dir !==
'' && substr(
$dir, -1) !==
'/') {
2740 $name = strtolower(trim($name));
2741 $ext = ltrim(strtolower(trim($ext)),
'.');
2742 if ($name ===
'' || $ext ===
'') {
2746 $lng = strtolower(trim($lng !==
'' ? $lng : dbx_lng_current()));
2748 $pathLng =
$dir . $name .
'_' . $lng .
'.' . $ext;
2749 if (is_file($pathLng)) {
2750 return function_exists(
'dbx_os_path_file') ?
dbx_os_path_file($pathLng) : $pathLng;
2758 $pathDef =
$dir . $name .
'.' . $ext;
2759 if (is_file($pathDef)) {
2760 return function_exists(
'dbx_os_path_file') ?
dbx_os_path_file($pathDef) : $pathDef;
2779function dbx_modul_translate($content,$modul=
'',$lng=
'') {
2780 if (!$modul) $modul=
dbx()->get_system_var(
'dbx_activ_modul',
'dbx');
2781 if (!$lng) $lng=
dbx()->get_system_var(
'dbx_lng',
'de');
2784 if (file_exists($dir_file)) {
2801function dbx_replace_first($search_str, $replacement_str, $src_str){
2802 return (
false !== ($pos = strpos($src_str, $search_str))) ? substr_replace($src_str, $replacement_str, $pos, strlen($search_str)) : $src_str;
2818function dbx_convertArrayToPHPCode(array $array,
string $prefix): string {
2821 foreach ($array as $key => $value) {
2823 $keyPart = is_numeric($key) ?
"[$key]" :
"['" . addslashes($key) .
"']";
2825 if (is_array($value)) {
2827 $code .= dbx_convertArrayToPHPCode($value, $prefix . $keyPart);
2830 if (is_string($value)) {
2832 $formattedValue =
"'" . addslashes($value) .
"'";
2833 } elseif (is_bool($value)) {
2835 $formattedValue = $value ?
'true' :
'false';
2836 } elseif ($value ===
null) {
2838 $formattedValue =
'null';
2841 $formattedValue = $value;
2845 $code .=
"$prefix$keyPart = $formattedValue;\n";
2895function dbx_convert_charset(
string $in,
string $charset,
string $incharset =
'UTF-8'): string {
2897 if ($charset !== $incharset) {
2900 'ä' => chr(228),
'ö' => chr(246),
'ü' => chr(252),
'ß' => chr(223),
2901 'Ä' => chr(196),
'Ö' => chr(214),
'Ü' => chr(220)
2903 $in = str_replace(array_keys($umlaute), array_values($umlaute), $in);
2906 $in = mb_convert_encoding(
2909 mb_detect_encoding($in,
"UTF-8, $charset, ISO-8859-1, ISO-8859-15",
true)
2930function dbx_add_modul(
string $modul,
string $action,
string $work =
''): string {
2932 $content =
'[modul=' . $modul .
']dbx_run1=' . $action;
2935 if (!empty($work)) {
2936 $content .=
'&dbx_run2=' . $work;
2940 $content .=
'[/modul]';
2959function dbx_validate_var($danger_value, $rules =
'parameter', $varname =
'undef'): bool {
2961 if ($rules ==
'*') return true;
2963 $oValidator =
dbx()->get_system_obj(
'dbxValidator');
2965 return $oValidator->validate($danger_value, $rules, $varname);
3094function dbx_make_seed(){
3095 list($usec, $sec) = explode(
' ', microtime());
3096 return (
float) $sec + ((float) $usec * 100000);
3112function dbx_load_cookie($cookie) {
3114 if (isset($_COOKIE[$cookie])) $data = json_decode($_COOKIE[$cookie],
true);
3115 $_SESSION[
'dbx'][
'cookie'][$cookie]=$data;
3119function dbx_save_cookie($cookie,$hh=12) {
3120 $data=$_SESSION[
'dbx'][
'cookie'][$cookie];
3121 setcookie($cookie, json_encode($data), time()+3600*$hh,
'/');
3124function dbx_delete_cookie($cookie) {
3125 setcookie($cookie,
'', time() - 3600,
'/');
3129function dbx_get_cookie_val($cookie,$key,$default=
'') {
3131 if (isset($_SESSION[
'dbx'][
'cookie'][$cookie][$key])) {
3132 $val=$_SESSION[
'dbx'][
'cookie'][$cookie][$key];
3148function dbx_get_Date($date, $io, $default =
''): string {
3150 if (!$date || $date===null) $date=
'';
3151 $date = trim($date);
3154 if (!preg_match(
'#^[0-9./-]+$#', $date)) {
3155 dbx()->set_system_var(
'dbx_validate_error', 1);
3160 if (strlen($date) !== 10) {
3161 dbx()->set_system_var(
'dbx_validate_error', 1);
3167 if (strpos($date,
'-') !==
false) {
3169 } elseif (strpos($date,
'.') !==
false) {
3171 } elseif (strpos($date,
'/') !==
false) {
3176 dbx()->set_system_var(
'dbx_validate_error', 1);
3180 $parts = explode($delimiter, $date);
3183 if (count($parts) !== 3) {
3184 dbx()->set_system_var(
'dbx_validate_error', 1);
3188 [$first, $second, $third] = $parts;
3191 if ($delimiter ===
'-') {
3192 [$year, $month, $day] = [$first, $second, $third];
3194 [$day, $month, $year] = [$first, $second, $third];
3198 if (!checkdate((
int)$month, (
int)$day, (
int)$year)) {
3199 dbx()->set_system_var(
'dbx_validate_error', 1);
3204 if ($io ===
'web') {
3205 return sprintf(
'%02d.%02d.%04d', $day, $month, $year);
3206 } elseif ($io ===
'php') {
3207 return sprintf(
'%04d-%02d-%02d', $year, $month, $day);
3211 dbx()->set_system_var(
'dbx_validate_error', 1);
3216function dbx_get_webDate($date,$default=
'') {
3217 $date=dbx_get_Date($date,
'web');
3218 if (!$date) $date=$default;
3222function dbx_get_phpDate($date,$default=
'') {
3223 $date=dbx_get_Date($date,
'php');
3224 if (!$date) $date=$default;
3230function dbx_get_webDateTime($date_time,$default=
'') {
3231 $date=substr($date_time, 0, 10);
3232 $time=substr($date_time,11, 8);
3233 $date=dbx_get_Date($date,
'web');
3234 return $date.
' '.$time;
3240function dbx_is_Login() {
3241 return dbx()->user(
'id');
3256function dbx_set_CurrentUser($key,$value) {
3258 $_SESSION[
'dbx'][
'current_user'][$key]=$value;
3260 $_SESSION[
'dbx'][
'current_user']=$value;
3263function dbx_is_decimal($value) {
3264 if (trim($value)==
'')
return FALSE;
3265 $lang = strlen($value);
3266 $okcahr =
'-0123456789.,';
3267 for ($i = 0; $i < $lang; $i++) {
3269 $ok = strrpos($okcahr, $char);
3270 if ($ok === FALSE)
return FALSE;
3281function dbx_get_Today($days=0) {
3283 $date=$today[
'year'].
'-'.$today[
'mon'].
'-'.$today[
'mday'];
3286 $date_t = strtotime($date.
' UTC');
3287 return gmdate(
'Y-m-d',$date_t + ($days*86400));
3292function dbx_get_Microtime() {
3293 list($usec, $sec) = explode(
' ',microtime());
3294 return ((
float)$usec + (
float)$sec);
3299function dbx_upload() {
3300 $oUpload=
dbx()->get_system_obj(
'dbxUpload');
3312function dbx_html2txt($txt) {
3313 $txt = dbx_html2src($txt);
3314 $txt = str_replace(
'<br/>',
"\n", $txt );
3315 $txt = str_replace(
'<br>' ,
"\n", $txt );
3319function dbx_txt2html($txt) {
3320 $txt = str_replace(
"\n",
'<br/>',$txt);
3324function dbx_html2src($html_in) {
3325 $html_in=stripslashes($html_in);
3326 $html_in = str_replace (
' ' ,
' ', $html_in);
3327 $html_in = str_replace (
'&' ,
'&', $html_in);
3328 $html_in = str_replace (
'"' ,
'"', $html_in);
3329 $html_in = str_replace (
''' ,
"'", $html_in);
3330 $html_in = str_replace (
'<' ,
'<', $html_in);
3331 $html_in = str_replace (
'>' ,
'>', $html_in);
3332 $html_in = str_replace (
'%7B' ,
'{', $html_in);
3333 $html_in = str_replace (
'%7D' ,
'}', $html_in);
3335 $html_in = str_replace (
'ü',
'ü', $html_in);
3336 $html_in = str_replace (
'ö',
'ö', $html_in);
3337 $html_in = str_replace (
'ä',
'ä', $html_in);
3338 $html_in = str_replace (
'Ü',
'Ü', $html_in);
3339 $html_in = str_replace (
'Ö',
'Ö', $html_in);
3340 $html_in = str_replace (
'Ä',
'Ä', $html_in);
3350function dbx_interpreter($content) {
3351 $int=
dbx()->get_system_obj(
'dbxInterpreter');
3352 $content=$int->run($content);
3371function dbx_decrypt($content, $xkey =
'', $master =
'') {
3374 $master =
dbx()->get_config(
'dbx',
'crypt');
3376 throw new Exception(
"Master key is not set.");
3381 $xkey =
'jkgj89bz7b789345%$&8t5';
3384 $crypt_key = md5($xkey . $master);
3385 $key = substr($crypt_key, 0, 16);
3386 $iv = substr($crypt_key, -16);
3390 $aes =
new AES(
'cbc');
3394 $decrypt_content = $aes->decrypt($content);
3396 return $decrypt_content;
3397 }
catch (Exception $e) {
3398 dbx()->debug(
"Decryption error: " . $e->getMessage());
3412function dbx_crypt($content, $xkey =
'', $master =
'') {
3416 $master =
dbx()->get_config(
'dbx',
'crypt');
3418 throw new Exception(
"Master key is not set.");
3423 $xkey =
'jkgj89bz7b789345%$&8t5';
3426 $crypt_key = md5($xkey . $master);
3427 $key = substr($crypt_key, 0, 16);
3428 $iv = substr($crypt_key, -16);
3432 $aes =
new AES(
'cbc');
3436 $crypt_content = $aes->encrypt($content);
3438 return $crypt_content;
3439 }
catch (Exception $e) {
3440 dbx()->debug(
"Encryption error: " . $e->getMessage());
dbx_log_missing_entry($missing='')
dbx_normalize_config_for_store(array $config)
dbx_os_path_file($path_file)
dbx_write_php_error_log($type, $message, $file='', $line=0)
dbx_get_base_dir($cut_Data=0)
DBX schema administration.
if(! $db->connect_db_server($server)) $result