-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
108 lines (92 loc) · 4.05 KB
/
bootstrap.php
File metadata and controls
108 lines (92 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* DataForce CMS — vendor entry point.
*
* The host site calls this after `require vendor/autoload.php` and after
* defining $dfConfig (see stubs/config.php for the shape).
*/
if (!isset($dfConfig) || !is_array($dfConfig)) {
throw new RuntimeException('DataForce: $dfConfig must be defined before including bootstrap.php');
}
// Force UTF-8 everywhere. Ukrainian shared hosts often default Apache/nginx
// to Content-Type: text/html; charset=windows-1251 which overrides <meta>.
if (!headers_sent()) {
header('Content-Type: text/html; charset=utf-8');
}
ini_set('default_charset', 'utf-8');
if (function_exists('mb_internal_encoding')) {
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
}
define('DATAFORCE_ROOT', __DIR__);
define('DATAFORCE_SRC', __DIR__ . '/src');
// --- Expose config as legacy globals expected by controllers ---
$DB_HOST = $dfConfig['db']['host'] ?? 'localhost';
$DB_NAME = $dfConfig['db']['name'] ?? '';
$DB_USER = $dfConfig['db']['user'] ?? '';
$DB_PASSWORD = $dfConfig['db']['pass'] ?? '';
$ALANG = $dfConfig['lang'] ?? 'ru';
$PROJECT_NAME = $dfConfig['project_name'] ?? 'DataForce';
$LANGS = $dfConfig['langs'] ?? ['ru' => 'RU', 'ua' => 'Укр', 'en' => 'EN'];
// --- Upload paths (filesystem vs URL) ---
// Two separate prefixes let the CMS run in different layouts:
// * Legacy standalone: admin/ at project root, uploads are siblings of admin/
// fs_root = '../', url_root = '../'
// * Symfony-style: admin served from public/admin/, uploads live in public/
// fs_root = dirname(DATAFORCE_ROOT).'/public/', url_root = '/'
// * Self-hosted vendor: admin in public/admin/, uploads at project root
// fs_root = dirname(DATAFORCE_ROOT).'/', url_root = '/'
$__dfPaths = $dfConfig['paths'] ?? [];
$FOLDER_FILES = $__dfPaths['files'] ?? ($dfConfig['folder_files'] ?? 'files');
$FOLDER_IMAGES = $__dfPaths['images'] ?? 'images';
$FOLDER_USERFILES = $__dfPaths['userfiles'] ?? 'userfiles';
$FOLDER_IMAGES_FRONTEND = $FOLDER_IMAGES;
$pref = rtrim($__dfPaths['fs_root'] ?? '../', '/') . '/';
$pref_url = rtrim($__dfPaths['url_root'] ?? '../', '/') . '/';
// Legacy flag: "we are not running from admin/ CWD, don't prepend '../' yourself"
$NO_ADMIN = 1;
unset($__dfPaths);
$tables = $dfConfig['tables'] ?? [];
$TABLE_DOCS_RUBS = $tables['docs_rubs'] ?? 'tef_drubs';
$TABLE_DOCS = $tables['docs'] ?? 'tef_docs';
$TABLE_MAIL = $tables['mail'] ?? 'emails';
$TABLE_TAGS = $tables['tags'] ?? 'tags';
$TABLE_ADMINS_GROUPS = $tables['admins_groups'] ?? 'admins_groups';
$TABLE_ADMINS = $tables['admins'] ?? 'admins';
$TABLE_ADMINS_MENU = $tables['admins_menu'] ?? 'admins_menu';
$TABLE_ADMINS_MENU_ASSOC = $tables['admins_menu_assoc'] ?? 'admins_menu_assoc';
$TABLE_ADMINS_LOG = $tables['admins_log'] ?? 'admins_log';
// Extra host-provided tables
foreach (($dfConfig['extra_tables'] ?? []) as $key => $name) {
$varName = 'TABLE_' . strtoupper($key);
$$varName = $name;
}
if (!empty($dfConfig['error_display'])) {
ini_set('display_errors', '1');
error_reporting(E_ALL);
} else {
ini_set('display_errors', '0');
}
// Timezone — some hosts ship an outdated tzdata that rejects 'Europe/Kyiv'
// (renamed from 'Europe/Kiev' in tzdata 2022b). Fall back gracefully.
$__dfTz = $dfConfig['timezone'] ?? 'UTC';
if (!in_array($__dfTz, timezone_identifiers_list(), true)) {
if ($__dfTz === 'Europe/Kyiv' && in_array('Europe/Kiev', timezone_identifiers_list(), true)) {
$__dfTz = 'Europe/Kiev';
} else {
$__dfTz = 'UTC';
}
}
date_default_timezone_set($__dfTz);
unset($__dfTz);
// Legacy code uses relative requires (require_once "inc/Connect.php"),
// scandir("models/") etc. — enter the src/ dir so those resolve.
$__dfPrevCwd = getcwd();
chdir(DATAFORCE_SRC);
try {
require DATAFORCE_SRC . '/router.php';
} finally {
if ($__dfPrevCwd !== false) {
chdir($__dfPrevCwd);
}
}