/usr/share/php/Horde/Nls.php is in php-horde-nls 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | <?php
/**
* Copyright 1999-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Jon Parise <jon@horde.org>
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Jan Schneider <jan@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Nls
*/
/**
* The Horde_Nls class provides Native Language Support.
*
* This includes common methods for handling language data, timezones, and
* hostname->country lookups.
*
* @author Jon Parise <jon@horde.org>
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Jan Schneider <jan@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Nls
*/
class Horde_Nls
{
/**
* DNS resolver.
*
* @var Net_DNS2_Resolver
*/
public static $dnsResolver;
/**
* Cached values.
*
* @var array
*/
protected static $_cache = array();
/**
* Check to see if character set is valid for htmlspecialchars() calls.
*
* @param string $charset The character set to check.
*
* @return boolean Is charset valid for the current system?
*/
public static function checkCharset($charset)
{
if (is_null($charset) || empty($charset)) {
return false;
}
$valid = true;
ini_set('track_errors', 1);
@htmlspecialchars('', ENT_COMPAT, $charset);
if (isset($php_errormsg)) {
$valid = false;
}
ini_restore('track_errors');
return $valid;
}
/**
* Returns a list of available timezones.
*
* @return array List of timezones.
*/
public static function getTimezones()
{
$timezones = DateTimeZone::listIdentifiers();
return array_combine($timezones, $timezones);
}
/**
* Returns a list of available timezones, including timezone abbreviations.
*
* Contrary to getTimezones() the timezone IDs are values and the timezone
* labels are the keys, to allow multiple labels for the same timezone.
*
* @since 2.2.0
*
* @return array List of timezones.
*/
public static function getTimezonesWithAbbreviations()
{
$timezones = array_flip(self::getTimezones());
foreach (DateTimeZone::listAbbreviations() as $abbreviation => $timezone) {
$abbreviation = Horde_String::upper($abbreviation);
if ($abbreviation == 'UTC' || strlen($abbreviation) < 2) {
continue;
}
$timezones[$abbreviation] = $timezone[0]['timezone_id'];
}
return $timezones;
}
/**
* Get the locale info returned by localeconv(), but cache it, to
* avoid repeated calls.
*
* @return array The results of localeconv().
*/
public static function getLocaleInfo()
{
if (!isset(self::$_cache['lc_info'])) {
self::$_cache['lc_info'] = localeconv();
}
return self::$_cache['lc_info'];
}
/**
* Get the language info returned by nl_langinfo(), but cache it, to
* avoid repeated calls.
*
* @param const $item The langinfo item to return.
*
* @return array The results of nl_langinfo().
*/
public static function getLangInfo($item)
{
if (!function_exists('nl_langinfo')) {
return false;
}
if (!isset(self::$_cache['nl_info'])) {
self::$_cache['nl_info'] = array();
}
if (!isset(self::$_cache['nl_info'][$item])) {
self::$_cache['nl_info'][$item] = nl_langinfo($item);
}
return self::$_cache['nl_info'][$item];
}
/**
* Get country information from a hostname or IP address.
*
* @param string $host The hostname or IP address.
* @param string $datafile The datafile for the GeoIP lookup. If not set,
* will skip this lookup.
*
* @return mixed On success, return an array with the following entries:
* 'code' => Country Code
* 'name' => Country Name
* On failure, return false.
*/
public static function getCountryByHost($host, $datafile = null)
{
/* List of generic domains that we know is not in the country TLD
list. See: http://www.iana.org/gtld/gtld.htm */
$generic = array(
'aero', 'biz', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'mil',
'museum', 'name', 'net', 'org', 'pro'
);
$checkHost = null;
if (preg_match('/^\d+\.\d+\.\d+\.\d+$/', $host)) {
if (isset(self::$dnsResolver)) {
try {
$response = self::$dnsResolver->query($host, 'PTR');
foreach ($response->answer as $val) {
if (isset($val->ptrdname)) {
$checkHost = $val->ptrdname;
break;
}
}
} catch (Net_DNS2_Exception $e) {}
}
if (is_null($checkHost)) {
$checkHost = @gethostbyaddr($host);
}
} else {
$checkHost = $host;
}
/* Get the TLD of the hostname. */
$pos = strrpos($checkHost, '.');
if ($pos === false) {
return false;
}
$domain = Horde_String::lower(substr($checkHost, $pos + 1));
/* Try lookup via TLD first. */
if (!in_array($domain, $generic)) {
$name = self::tldLookup($domain);
if ($name) {
return array(
'code' => $domain,
'name' => $name
);
}
}
/* Try GeoIP lookup next. */
$geoip = new Horde_Nls_Geoip($datafile);
return $geoip->getCountryInfo($checkHost);
}
/**
* Do a top level domain (TLD) lookup.
*
* @param string $code A 2-letter country code.
*
* @return mixed The localized country name, or null if not found.
*/
public static function tldLookup($code)
{
if (!isset(self::$_cache['tld'])) {
include __DIR__ . '/Nls/Tld.php';
self::$_cache['tld'] = $tld;
}
$code = Horde_String::lower($code);
return isset(self::$_cache['tld'][$code])
? self::$_cache['tld'][$code]
: null;
}
/**
* Returns either a specific or all ISO-3166 country names.
*
* @param string $code The ISO 3166 country code.
*
* @return mixed If a country code has been requested will return the
* corresponding country name. If empty will return an
* array of all the country codes and their names.
*/
public static function getCountryISO($code = null)
{
if (!isset(self::$_cache['iso3166'])) {
include __DIR__ . '/Nls/Countries.php';
self::$_cache['iso3166'] = $countries;
}
if (empty($code)) {
return self::$_cache['iso3166'];
}
$code = Horde_String::upper($code);
return isset(self::$_cache['iso3166'][$code])
? self::$_cache['iso3166'][$code]
: null;
}
/**
* Returns either a specific or all ISO-639 language names.
*
* @param string $code The ISO 639 language code.
*
* @return mixed If a language code has been requested will return the
* corresponding language name. If empty will return an
* array of all the language codes (keys) and their names
* (values).
*/
public static function getLanguageISO($code = null)
{
if (!isset(self::$_cache['iso639'])) {
include __DIR__ . '/Nls/Languages.php';
self::$_cache['iso639'] = $languages;
}
if (empty($code)) {
return self::$_cache['iso639'];
}
$code = substr(Horde_String::lower(trim($code)), 0, 2);
return isset(self::$_cache['iso639'][$code])
? self::$_cache['iso639'][$code]
: null;
}
}
|