1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xmf; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Language |
16
|
|
|
* |
17
|
|
|
* @category Xmf\Language |
18
|
|
|
* @package Xmf |
19
|
|
|
* @author trabis <[email protected]> |
20
|
|
|
* @copyright 2011-2016 XOOPS Project (http://xoops.org) |
21
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
22
|
|
|
* @version Release: 1.0 |
23
|
|
|
* @link http://xoops.org |
24
|
|
|
* @since 1.0 |
25
|
|
|
*/ |
26
|
|
|
class Language |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Attempt a translation of a simple string |
30
|
|
|
* |
31
|
|
|
* @param string $string string to translate |
32
|
|
|
* @param string $domain language domain |
33
|
|
|
* |
34
|
|
|
* @return string translated string |
35
|
|
|
* |
36
|
|
|
* @todo do something useful |
37
|
|
|
*/ |
38
|
1 |
|
public static function translate($string, $domain = null) |
|
|
|
|
39
|
|
|
{ |
40
|
1 |
|
return $string; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* load - load a language file |
45
|
|
|
* |
46
|
|
|
* @param string $name name of the language file |
47
|
|
|
* @param string $domain domain or module supplying language file |
48
|
|
|
* @param string $language language folder name |
49
|
|
|
* |
50
|
|
|
* @return bool true if loaded, otherwise false |
51
|
|
|
*/ |
52
|
1 |
|
public static function load($name, $domain = '', $language = null) |
|
|
|
|
53
|
|
|
{ |
54
|
1 |
|
if (empty($language)) { |
55
|
1 |
|
if (!empty($GLOBALS['xoopsConfig']['language'])) { |
56
|
|
|
$language = $GLOBALS['xoopsConfig']['language']; |
57
|
|
|
} else { |
58
|
1 |
|
$language = 'english'; |
59
|
|
|
} |
60
|
|
|
} |
61
|
1 |
|
$path = \XoopsBaseConfig::get('root-path') . '/' . ((empty($domain) || 'global' === $domain) ? '' |
62
|
1 |
|
: "modules/{$domain}/") . 'language'; |
63
|
1 |
|
if (!$ret = static::loadFile("{$path}/{$language}/{$name}.php")) { |
64
|
|
|
$ret = static::loadFile("{$path}/english/{$name}.php"); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
return $ret; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Load a file |
72
|
|
|
* |
73
|
|
|
* @param string $filename filename to load |
74
|
|
|
* |
75
|
|
|
* @return bool true if file exists and was loaded |
76
|
|
|
* |
77
|
|
|
* @throws \InvalidArgumentException |
78
|
|
|
*/ |
79
|
|
|
protected static function loadFile($filename) |
80
|
|
|
{ |
81
|
|
|
if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) { |
82
|
|
|
throw new \InvalidArgumentException('Security check: Illegal character in filename'); |
83
|
|
|
} |
84
|
|
|
if (file_exists($filename)) { |
85
|
|
|
include_once $filename; |
86
|
|
|
return true; |
87
|
|
|
} |
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.