-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneric.php
More file actions
124 lines (107 loc) · 2.24 KB
/
generic.php
File metadata and controls
124 lines (107 loc) · 2.24 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
//note that this function is unrelated to any library you can find outside of this project
//gives the right text depending on the language
function I18($text)
{
global $textArray;
if ($textArray)
{
return htmlspecialchars(chooseText($textArray, htmlspecialchars($text)));
}
else
{
return htmlspecialchars($text);
}
}
//taken from the first comment of php.net/manual/en/class.simplexmliterator.php
//credits to ratfactor at gmail dot com
function xmlToArray($fileName)
{
$sxi = new SimpleXmlIterator($fileName, null, true);
return sxiToArray($sxi);
}
//taken from the first comment of php.net/manual/en/class.simplexmliterator.php
//credits to: ratfactor at gmail dot com
function sxiToArray($sxi)
{
$a = array();
for ($sxi->rewind();$sxi->valid();$sxi->next())
{
if (!array_key_exists($sxi->key(), $a))
{
$a[$sxi->key()] = array();
}
if ($sxi->hasChildren())
{
$a[$sxi->key()][] = sxiToArray($sxi->current());
}
else
{
$a[$sxi->key()][] = strval($sxi->current());
}
}
return $a;
}
//returns the text in the right language
//takes default if language not available
function chooseText($textArray, $text)
{
$singleText;
foreach ($textArray['text'] as $elem)
{
if (strcmp($elem['default'][0], $text)===0) //if same strings
{
//this variable now contains an array of the right text in all languages
$singleText = $elem;
break;
}
}
if (isset($singleText))
{
if (isset($singleText[$_SESSION['lang']]))
{
return $singleText[$_SESSION['lang']][0];
}
elseif (isset($singleText['en']))
{
return $singleText['en'][0];
}
elseif (isset($singleText['fr']))
{
return $singleText['fr'][0];
}
else
{
return $singleText['default'][0]; //usually french
}
}
else
{
return $text;
}
}
//creates a string with a nice time stamp and everything
function logmsg($message, $user = false)
{
if ($user===true)
{
if (isset ($_SESSION['user']))
$user = $_SESSION['user'];
else
$user = "";
}
elseif ($user===false)
{
$user = "";
}
return "[" . date('D M d H:i:s Y') . "] [$user] " . $message;
}
//adds the string at the end of the log file.
function addLog($string)
{
if (!$file = fopen (USRLOG, "a"))
return false;
fprintf($file, $string . PHP_EOL);
fclose($file);
}
?>