-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbase.php
More file actions
87 lines (78 loc) · 2.77 KB
/
base.php
File metadata and controls
87 lines (78 loc) · 2.77 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
<?php
require_once 'vendor/autoload.php';
require_once 'texts.generic.php';
/**
* Initialize the translation system by returning the appropriate text file to include.
* @param $browserLanguage string Language of the web browser
* @param $requestLanguage string Language of the web request, or null if not supplied
* @return string Text file to include for getting translations.
*/
function getTextFileToInclude($browserLanguage, $requestLanguage = null) {
if ($requestLanguage != null) {
// Returns the name of the to-be-loaded translations file based on the request param language.
if ($requestLanguage == 'nl') {
return 'texts.nl.php';
} else if ($requestLanguage == 'fr') {
return 'texts.fr.php';
} else {
return 'texts.en.php';
}
} else {
// Returns the name of the to-be-loaded translations file based on the web browser language.
if ($browserLanguage == 'nl' || $browserLanguage =='be') {
return 'texts.nl.php';
} else if ($browserLanguage == 'fr') {
return 'texts.fr.php';
} else {
return 'texts.en.php';
}
}
}
/**
* Prints a text value from the translations table.
* @param $key string to lookup the texts in the translations table.
*/
function text($key) {
echo retrieveText($key);
}
/**
* Returns a text value from the translations table.
* @param $key string to lookup the texts in the translations table.
* @return string Text if found, or error text if not found.
*/
function retrieveText($key) {
global $contents;
if(isset($contents[$key])) {
return $contents[$key];
} else {
return "<i style='color:red; text-decoration: line-through;'>" . $key . "</i>";
}
}
/**Initialize HTML Purifier to prevent XSS.
* @return HTMLPurifier Initialized HTML Purifier
*/
function initHtmlPurifier() {
// Html Purifier to prevent XSS.
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Allowed', 'a[href],i,b,p[class],span[class]');
return new HTMLPurifier($config);
}
/**Connect to the Oxygen Updater database.
* @return PDO Database connection
*/
function connectToDatabase()
{
try {
$databaseUsername = getenv('DATABASE_USER');
$databasePassword = getenv('DATABASE_PASS');
$databaseHost = getenv('DATABASE_HOST');
$databaseName = getenv('DATABASE_NAME');
$databasePort = getenv('DATABASE_PORT');
$database = new PDO('mysql:host=' . $databaseHost . ';port=' . $databasePort . ';dbname=' . $databaseName . '', $databaseUsername, $databasePassword);
$database->query('SET CHARACTER SET utf8');
return $database;
} catch (Exception $e) {
error_log($e->getTraceAsString());
return null;
}
}