-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.php
352 lines (308 loc) · 13.6 KB
/
index.php
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
/**
* This is the main web entry point for HuMo-genealogy.
*
* If you are reading this in your web browser, your server is probably
* not configured correctly to run PHP applications!
*
* See the manual for basic setup instructions
*
* https://humo-gen.com
*
* Copyright (C) 2008-2024 Huub Mons,
* Klaas de Winkel, Jan Maat, Jeroen Beemster, Louis Ywema, Theo Huitema,
* Reni Janssen, Yossi Beck
* and others.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// *** Disabled 18-01-2023 ***
//ini_set('url_rewriter.tags','');
//session_cache_limiter('private, must-revalidate'); //tb edit
session_start();
// *** Regenerate session id regularly to prevent session hacking ***
//session_regenerate_id();
/**
* Dec. 2024: Added autoload.
* Name of class = SomethingClass
* Name of script: somethingClass.php ***
*/
// TODO add autoload in gendex.php, sitemap.php, editor_ajax.php, namesearch.php, layout_pdf.php.
function custom_autoload($class_name)
{
// Examples of autoload files:
// app/model/ All scripts are autoloading.
// app/model/adresModel.php
// controller/ All scripts are autoloading.
// controller/addressController.php
// include/dbFunctions.php
// include/marriage_cls
// include/personCls.php
// include/calculateDates.php
// include/processLinks.php
// include/validateDate.php
// languages/languageCls.php
// *** At this moment only a few classes are autoloaded. Under construction ***
$classes = array(
'CalculateDates', 'DbFunctions', 'MarriageCls', 'PersonCls', 'ProcessLinks', 'ValidateDate', 'LanguageCls'
);
// If all classes are autoloading, array check of classes will be removed.
if (in_array($class_name, $classes) || substr($class_name, -10) == 'Controller' || substr($class_name, -5) == 'Model') {
$dirs = array('app/controller', 'app/model', 'include', 'languages');
foreach ($dirs as $dir) {
$file = __DIR__ . '/' . $dir . '/' . lcfirst($class_name) . '.php';
if (file_exists($file)) {
require $file;
break;
}
}
}
}
spl_autoload_register('custom_autoload');
// TODO move to model script (should be processed before setttings_user. Probably first build a general settings class).
if (isset($_GET['log_off'])) {
unset($_SESSION['user_name']);
unset($_SESSION['user_id']);
unset($_SESSION['user_group_id']);
unset($_SESSION['tree_prefix']);
session_destroy();
}
// TODO refactor/ check scripts for autoload.
include_once(__DIR__ . "/include/db_login.php"); // Connect to database
include_once(__DIR__ . "/include/show_tree_text.php");
include_once(__DIR__ . "/include/safe.php");
include_once(__DIR__ . "/include/settings_global.php"); // System variables
include_once(__DIR__ . "/include/settings_user.php"); // User variables
include_once(__DIR__ . "/include/get_visitor_ip.php"); // Statistics and option to block certain IP addresses.
include_once(__DIR__ . "/include/timezone.php");
//include(__DIR__ . "/languages/languageCls.php");
include_once(__DIR__ . '/app/routing/router.php'); // Page routing.
// *** Added dec. 2024 ***
$controllerObj = new IndexController();
$index = $controllerObj->detail($dbh, $humo_option, $user);
// TODO dec. 2024 for now: use old variable names.
$db_functions = $index['db_functions'];
$visitor_ip = $index['visitor_ip'];
$person_cls = $index['person_cls'];
$bot_visit = $index['bot_visit'];
$language_file = $index['language_file']; // Array including all languages files.
$language = $index['language']; // $language = array.
$selected_language = $index['selected_language'];
// *** Process LTR and RTL variables ***
$dirmark1 = $index['dirmark1']; //ltr marker
$dirmark2 = $index['dirmark2']; //rtl marker
$rtlmarker = $index['rtlmarker'];
$alignmarker = $index['alignmarker'];
// *** New routing script sept. 2023. Search route, return match or not found ***
$page = $index['page'];
if (isset($index['last_name'])) {
$last_name = $index['last_name'];
}
if (isset($index['id'])) {
$id = $index['id'];
}
$tree_id = $index['tree_id'];
$tree_prefix_quoted = $index['tree_prefix_quoted'];
// TODO check variable. Just use $tree_id?
$db_functions->set_tree_id($_SESSION['tree_id']);
// *** If an HuMo-gen upgrade is done, automatically update language files ***
if ($humo_option['death_char'] == "y") { // user wants infinity instead of cross -> check if the language files comply
$str = file_get_contents("languages/en/en.po");
if (strpos($str, 'msgstr "†"') || strpos($str, 'msgstr "†"')) { // the cross is used (probably new upgrade) so this has to be changed to infinity
include(__DIR__ . "/languages/change_all.php");
}
}
// *** Backwards compatibility only ***
// *** Example: gezin.php?database=humo_&id=F1&hoofdpersoon=I2 ***
// *** Allready moved most variables to routing script ***
if (isset($_GET["hoofdpersoon"])) {
$_GET['main_person'] = $_GET["hoofdpersoon"];
}
if (isset($_POST["hoofdpersoon"])) {
$_POST['main_person'] = $_POST["hoofdpersoon"];
}
// *** Generate BASE HREF for use in url_rewrite ***
// SERVER_NAME 127.0.0.1
// PHP_SELF: /url_test/index/1abcd2345/
// OF: PHP_SELF: /url_test/index.php
// REQUEST_URI: /url_test/index/1abcd2345/
// REQUEST_URI: /url_test/index.php?variabele=1
$base_href = '';
if ($humo_option["url_rewrite"] == "j" && $index['tmp_path']) {
// *** url_rewrite. 26 jan. 2024 Ron: Added proxy check ***
//if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) {
$uri_path = 'https://' . $_SERVER['SERVER_NAME'] . $index['tmp_path'];
} else {
$uri_path = 'http://' . $_SERVER['SERVER_NAME'] . $index['tmp_path'];
}
$base_href = $uri_path;
} else {
// *** Use standard uri ***
$position = strrpos($_SERVER['PHP_SELF'], '/');
$uri_path = substr($_SERVER['PHP_SELF'], 0, $position) . '/';
}
// *** To be used to show links in several pages ***
$link_cls = new ProcessLinks($uri_path);
// *** Base controller (at this moment only in use with sourcecontroller (using extend) ***
//$controllerObj = new BaseController($dbh, $db_functions);
if ($page == 'address') {
// TODO refactor
include_once(__DIR__ . "/include/show_sources.php");
include_once(__DIR__ . "/include/show_picture.php");
$controllerObj = new AddressController($db_functions, $user);
$data = $controllerObj->detail();
} elseif ($page == 'addresses') {
$controllerObj = new AddressesController($dbh, $user, $tree_id);
$data = $controllerObj->list();
} elseif ($page == 'ancestor_report') {
$controllerObj = new AncestorReportController($dbh);
$data = $controllerObj->list($tree_id);
} elseif ($page == 'ancestor_report_rtf') {
$controllerObj = new AncestorReportController($dbh);
$data = $controllerObj->list($tree_id);
} elseif ($page == 'ancestor_chart') {
$controllerObj = new AncestorChartController($dbh, $db_functions);
$data = $controllerObj->list($tree_id);
} elseif ($page == 'ancestor_sheet') {
$controllerObj = new AncestorSheetController($dbh, $db_functions);
$data = $controllerObj->list($tree_id);
} elseif ($page == 'anniversary') {
//TODO refactor
include_once(__DIR__ . "/include/language_date.php");
$controllerObj = new AnniversaryController();
$data = $controllerObj->anniversary();
} elseif ($page == 'cms_pages') {
$controllerObj = new CmsPagesController($dbh, $user);
$data = $controllerObj->list();
} elseif ($page == 'cookies') {
//
} elseif ($page == 'descendant_chart') {
$controllerObj = new DescendantChartController();
$data = $controllerObj->getFamily($dbh, $tree_id);
} elseif ($page == 'family_rtf') {
//
} elseif ($page == 'family') {
$controllerObj = new FamilyController();
$data = $controllerObj->getFamily($dbh, $tree_id);
} elseif ($page == 'fanchart') {
// TODO refactor
require_once(__DIR__ . "/include/fanchart/persian_log2vis.php");
$controllerObj = new FanchartController();
$data = $controllerObj->detail($dbh, $tree_id);
} elseif ($page == 'help') {
//
} elseif ($page == 'hourglass') {
$controllerObj = new HourglassController();
$data = $controllerObj->getHourglass($dbh, $tree_id);
} elseif ($page == 'latest_changes') {
// TODO refactor
include_once(__DIR__ . "/include/language_date.php");
$controllerObj = new LatestChangesController($dbh);
$data = $controllerObj->list($dbh, $tree_id);
} elseif ($page == 'list') {
// TODO refactor
include_once(__DIR__ . "/include/language_date.php");
include_once(__DIR__ . "/include/date_place.php");
$controllerObj = new ListController();
$list = $controllerObj->list_names($dbh, $tree_id, $user, $humo_option);
} elseif ($page == 'list_places_families') {
// TODO refactor
include_once(__DIR__ . "/include/language_date.php");
include_once(__DIR__ . "/include/date_place.php");
$controllerObj = new ListPlacesFamiliesController();
$data = $controllerObj->list_places_names($tree_id);
} elseif ($page == 'list_names') {
$controllerObj = new ListNamesController();
$data = $controllerObj->list_names($dbh, $tree_id, $user);
} elseif ($page == 'login') {
//
} elseif ($page == 'mailform') {
$controllerObj = new MailformController($db_functions);
$mail_data = $controllerObj->get_mail_data($humo_option, $dataDb, $selected_language);
} elseif ($page == 'maps') {
// TODO refactor
include_once(__DIR__ . "/include/language_date.php");
include_once(__DIR__ . "/include/date_place.php");
include_once(__DIR__ . "/include/ancestors_descendants.php");
$controllerObj = new MapsController($db_functions);
$maps = $controllerObj->detail($humo_option, $dbh, $tree_id, $tree_prefix_quoted);
} elseif ($page == 'photoalbum') {
// TODO refactor
include_once(__DIR__ . "/include/language_date.php");
include_once(__DIR__ . "/include/date_place.php");
include_once(__DIR__ . "/include/show_picture.php");
$controllerObj = new PhotoalbumController();
$photoalbum = $controllerObj->detail($dbh, $tree_id, $db_functions);
} elseif ($page == 'register') {
$controllerObj = new RegisterController($db_functions);
$register = $controllerObj->get_register_data($dbh, $dataDb, $humo_option);
} elseif ($page == 'relations') {
// TODO refactor
include_once(__DIR__ . "/include/language_date.php");
include_once(__DIR__ . "/include/date_place.php");
$controllerObj = new RelationsController($dbh);
$relation = $controllerObj->getRelations($db_functions, $person_cls);
} elseif ($page == 'reset_password') {
$controllerObj = new ResetpasswordController();
$resetpassword = $controllerObj->detail($dbh, $humo_option);
} elseif ($page == 'outline_report') {
$controllerObj = new OutlineReportController();
$data = $controllerObj->getOutlineReport($dbh, $tree_id, $humo_option);
} elseif ($page == 'user_settings') {
// TODO refactor
include_once(__DIR__ . "/include/2fa_authentication/authenticator.php");
//if (isset($_POST['update_settings'])) include_once(__DIR__ . '/include/mail.php');
$controllerObj = new UserSettingsController();
$data = $controllerObj->user_settings($dbh, $dataDb, $humo_option, $user);
} elseif ($page == 'statistics') {
// TODO refactor
include_once(__DIR__ . "/include/language_date.php");
include_once(__DIR__ . "/include/date_place.php");
$controllerObj = new StatisticsController();
$statistics = $controllerObj->detail($dbh, $tree_id);
} elseif ($page == 'sources') {
// TODO refactor
include_once(__DIR__ . "/include/language_date.php");
include_once(__DIR__ . "/include/date_place.php");
$controllerObj = new SourcesController($dbh);
$data = $controllerObj->list($dbh, $tree_id, $user, $humo_option, $link_cls, $uri_path);
} elseif ($page == 'source') {
// TODO refactor
include_once(__DIR__ . "/include/date_place.php");
include_once(__DIR__ . "/include/process_text.php");
include_once(__DIR__ . "/include/show_picture.php");
//include_once(__DIR__ . "/include/show_sources.php");
include_once(__DIR__ . "/include/language_date.php");
$controllerObj = new SourceController($dbh, $db_functions, $tree_id); // Using Controller.
// *** url_rewrite is disabled ***
if (isset($_GET["id"])) {
$id = $_GET["id"];
}
$data = $controllerObj->source($id);
} elseif ($page == 'timeline') {
// TODO refactor
require_once(__DIR__ . "/include/language_date.php");
$controllerObj = new TimelineController();
// *** url_rewrite is disabled ***
if (isset($_GET["id"])) {
$id = $_GET["id"];
}
$data = $controllerObj->getTimeline($db_functions, $id, $user, $dirmark1);
} elseif ($page == 'tree_index') {
// *** TODO: first improve difference between tree_index and mainindex ***
//$controllerObj = new TreeIndexController();
//$tree_index["items"] = $controllerObj->get_items($dbh);
}
include_once(__DIR__ . "/views/layout.php");