-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc_language.php
105 lines (92 loc) · 4.18 KB
/
sc_language.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
<?php
/*
##########################################################################
# #
# Version 4 / / / #
# -----------__---/__---__------__----__---/---/- #
# | /| / /___) / ) (_ ` / ) /___) / / #
# _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___ #
# Free Content / Management System #
# / #
# #
# #
# Copyright 2005-2015 by webspell.org #
# #
# visit webSPELL.org, webspell.info to get webSPELL for free #
# - Script runs under the GNU GENERAL PUBLIC LICENSE #
# - It's NOT allowed to remove this copyright-tag #
# -- http://www.fsf.org/licensing/licenses/gpl.html #
# #
# Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at), #
# Far Development by Development Team - webspell.org #
# #
# visit webspell.org #
# #
##########################################################################
*/
if (basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
$new_language = (isset($_GET[ 'new_lang' ]) && !empty($_GET[ 'new_lang' ])) ? getinput($_GET[ 'new_lang' ]) : null;
if (!is_null($new_language) && file_exists('languages/' . $new_language)) {
include("_mysql.php");
include("_settings.php");
include("_functions.php");
$lang = preg_replace("[^a-z]", "", $new_language);
$_SESSION[ 'language' ] = $lang;
if ($userID) {
safe_query("UPDATE " . PREFIX . "user SET language='" . $lang . "' WHERE userID='" . $userID . "'");
}
}
if (isset($_GET[ 'query' ])) {
$query = rawurldecode($_GET[ 'query' ]);
header("Location: ./" . $query);
} else {
header("Location: index.php");
}
} else {
$_language->readModule('sc_language');
$filepath = "languages/";
$langs = array();
// Select all possible languages
$mysql_langs = array();
$query = safe_query("SELECT lang, language FROM " . PREFIX . "news_languages");
while ($ds = mysqli_fetch_assoc($query)) {
$mysql_langs[ $ds[ 'lang' ] ] = $ds[ 'language' ];
}
if ($dh = opendir($filepath)) {
while ($file = mb_substr(readdir($dh), 0, 2)) {
if ($file != "." && $file != ".." && is_dir($filepath . $file)) {
if (isset($mysql_langs[ $file ])) {
$name = $mysql_langs[ $file ];
$name = ucfirst($name);
$langs[ $name ] = $file;
} else {
$langs[ $file ] = $file;
}
}
}
closedir($dh);
}
if (defined("SORT_NATURAL")) {
$sortMode = SORT_NATURAL;
} else {
$sortMode = SORT_LOCALE_STRING;
}
ksort($langs, $sortMode);
$querystring = '';
if ($modRewrite === true) {
$path = rawurlencode(str_replace($GLOBALS[ 'rewriteBase' ], '', $_SERVER[ getConstNameRequestUri() ]));
} else {
$path = rawurlencode($_SERVER[ 'QUERY_STRING' ]);
if (!empty($path)) {
$path = "?".$path;
}
}
if (!empty($path)) {
$querystring = "&query=" . $path;
}
foreach ($langs as $lang => $flag) {
echo '<a href="sc_language.php?new_lang=' . $flag . $querystring . '" title="' . $lang . '" class="flag' .
($_language->language == $flag ? ' active' : '') . '"><img src="images/languages/' . $flag . '.gif" alt="' .
$lang . '"></a>';
}
}