-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminimal_init.php
125 lines (113 loc) · 3.01 KB
/
minimal_init.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
<?php
// Load userspice DB class
if (!class_exists('DB')) {
$GLOBALS['config']['mysql'] = [];
$file = fopen("users/init.php", "r");
if ($file) {
$config_line_found = false;
while (!feof($file) && count($GLOBALS['config']['mysql'])<4) {
$line = trim(fgets($file,512));
if (!$config_line_found) {
if (strpos($line,"\$GLOBALS['config']") !== false)
$config_line_found = true;
} else {
foreach(["host", "username", "password", "db"] as $find)
if (strpos($line,$find) !== false) {
$tokens = explode("=>", str_replace(["'",","],"",$line));
if (count($tokens) >= 2)
$GLOBALS['config']['mysql'][trim($tokens[0])] = trim($tokens[1]);
}
}
}
fclose($file);
}
require_once "users/classes/Config.php";
require_once "users/classes/DB.php";
require_once "users/classes/Parsedown.php";
DB::getDB([]);
}
// Load userspice lang
if(!function_exists('lang')) {
$lang = [
"THIS_LANGUAGE" =>"English",
"THIS_CODE" =>"en-US",
"MISSING_TEXT" =>"Missing Text",
];
include("usersc/lang/en-US.php");
function lang($key,$markers = NULL){
global $lang, $us_url_root, $abs_us_root;
if($markers == NULL){
if(isset($lang[$key])){
$str = $lang[$key];
}else{
$str = "";
}
}else{
//Replace any dyamic markers
if(isset($lang[$key])){
$str = $lang[$key];
$iteration = 1;
foreach($markers as $marker){
$str = str_replace("%m".$iteration."%",$marker,$str);
$iteration++;
}
}else{
$str = "";
}
}
//Ensure we have something to return
// dump($key);
if($str == ""){
if(isset($lang["MISSING_TEXT"])){
$missing = $lang["MISSING_TEXT"];
}else{
$missing = "Missing Text";
}
//if nothing is found, let's check to see if the language is English.
if(isset($lang['THIS_CODE']) && $lang['THIS_CODE'] != "en-US"){
$save = $lang['THIS_CODE'];
if($save == ''){
$save = 'en-US';
}
//if it is NOT English, we are going to try to grab the key from the English translation
include($abs_us_root.$us_url_root."users/lang/en-US.php");
if($markers == NULL){
if(isset($lang[$key])){
$str = $lang[$key];
}else{
$str = "";
}
}else{
//Replace any dyamic markers
if(isset($lang[$key])){
$str = $lang[$key];
$iteration = 1;
foreach($markers as $marker){
$str = str_replace("%m".$iteration."%",$marker,$str);
$iteration++;
}
}else{
$str = "";
}
}
$lang = [];
include($abs_us_root.$us_url_root."users/lang/$save.php");
if($str == ""){
//This means that we went to the English file and STILL did not find the language key, so...
$str = "{ $missing }";
return $str;
}else{
//falling back to English
return $str;
}
}else{
//the language is already English but the code is not found so...
$str = "{ $missing }";
return $str;
}
}else{
return $str;
}
}
}
?>