This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
common.php
159 lines (128 loc) · 3.91 KB
/
common.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
<?
/*****************************************************************************
**
** grr >:(
** https://github.com/pokebyte/grr
** Copyright (C) 2013 Akop Karapetyan
**
** 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 2 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, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
******************************************************************************
*/
define('ERROR_UNAUTHENTICATED', 100);
define('ERROR_UNAUTHORIZED', 101);
define('ERROR_REAUTHENTICATE', 102);
// Magic quotes should be turned off
// To turn them off via .htaccess, add the following line to the .htaccess file:
// php_flag magic_quotes_gpc Off
if (get_magic_quotes_gpc())
die("Turn off magic quotes");
if (TIMEZONE === null ||
MYSQL_HOSTNAME === null ||
MYSQL_USERNAME === null ||
MYSQL_PASSWORD === null ||
MYSQL_DATABASE === null ||
HOSTNAME === null ||
SALT_VHASH === null ||
SALT_VOPENID === null ||
SALT_SESSION === null)
{
die("Configuration is incomplete");
}
// Locale information
// Order here is unimportant - client controls order of preference
$GRR_SUPPORTED_LOCALES = array(
"en",
"en-us",
);
// This should be 'en'.
// It reflects the language in the 'default' string maps
$GRR_DEFAULT_LOCALE = "en";
function l()
{
// Localization stub
$args = func_get_args();
if (count($args) < 1)
return "";
global $grrStrings;
if (isset($grrStrings[$args[0]]))
$args[0] = $grrStrings[$args[0]];
if (count($args) == 1)
return $args[0];
return call_user_func_array('sprintf', $args);
}
function h($string)
{
return htmlspecialchars($string, ENT_QUOTES, "UTF-8");
}
function compareLocales($a, $b)
{
$q1 = (int)($a["q"] * 100);
$q2 = (int)($b["q"] * 100);
if ($q1 == $q2)
{
$index1 = $a["index"];
$index2 = $b["index"];
// Q-values are the same - compare by index
if ($index1 == $index2)
return 0;
return $index1 > $index2 ? -1 : 1;
}
// Compare by Q-value
return $q1 > $q2 ? -1 : 1;
}
function getAcceptedLocales()
{
$acceptedLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (!$acceptedLocales)
return array();
$localeSpecs = explode(",", $acceptedLocales);
$locales = array();
$index = 0;
foreach ($localeSpecs as $localeSpec)
{
$specParts = explode(";", $localeSpec);
$locale = array("name" => strtolower($specParts[0]), "index" => $index++, "q" => 1.0);
if (count($specParts) == 2 && strncmp($specParts[1], "q=", 2) == 0)
$locale["q"] = substr($specParts[1], 2); // Explicit Q-value
$locales[] = $locale;
}
// Sort the locales
uasort($locales, 'compareLocales');
// Collect the names, keep only uniques
$localeNames = array_unique(array_map('current', $locales));
$localeNames = array_values($localeNames); // Reset indices
return $localeNames;
}
// Get a sorted list of accepted locales
$acceptedLocales = getAcceptedLocales();
$grrCurrentLocale = null; // Default locale
foreach ($acceptedLocales as $acceptedLocale)
{
if (in_array($acceptedLocale, $GRR_SUPPORTED_LOCALES))
{
if ($acceptedLocale != $GRR_DEFAULT_LOCALE)
$grrCurrentLocale = $acceptedLocale; // Explicit locale
break;
}
}
require('include/locales/default.php');
if ($grrCurrentLocale != null)
{
$localeFile = "include/locales/{$grrCurrentLocale}.php";
if (file_exists($localeFile))
include($localeFile);
}
?>