1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_ROOT_PATH . "/core/XCube_LanguageManager.class.php";
14:
15: class Legacy_LanguageManager extends XCube_LanguageManager
16: {
17: function prepare()
18: {
19: parent::prepare();
20:
21: $this->_setupDatabase();
22: $this->loadGlobalMessageCatalog();
23:
24: $this->_setupMbstring();
25: }
26:
27: 28: 29:
30: function _setupDatabase()
31: {
32: $filename = XOOPS_MODULE_PATH . '/legacy/language/' . $this->mLanguageName . '/charset_' . XOOPS_DB_TYPE . '.php';
33: if (file_exists($filename)) {
34: require_once($filename);
35: }
36: }
37:
38: function _setupMbstring()
39: {
40:
41: if (defined('_MBSTRING_LANGUAGE') && function_exists("mb_language")) {
42: if (@mb_language(_MBSTRING_LANGUAGE) != false && @mb_internal_encoding(_CHARSET) != false) {
43: define('MBSTRING', true);
44: }
45: else {
46: mb_language("neutral");
47: mb_internal_encoding("ISO-8859-1");
48: if (!defined('MBSTRING')) {
49: define('MBSTRING', false);
50: }
51: }
52:
53: if (function_exists('mb_regex_encoding')) {
54: @mb_regex_encoding(_CHARSET);
55: }
56:
57: ini_set( 'mbstring.http_input', 'pass');
58: ini_set( 'mbstring.http_output', 'pass');
59: ini_set( 'mbstring.substitute_character', 'none');
60: }
61:
62:
63: if (!defined( "MBSTRING")) {
64: define( "MBSTRING", FALSE);
65: }
66: }
67:
68: function loadGlobalMessageCatalog()
69: {
70: $lpath = XOOPS_ROOT_PATH . '/modules/legacy/language/' . $this->mLanguageName;
71: if (!$this->_loadFile($lpath . '/global.php')) {
72: $this->_loadFile(XOOPS_ROOT_PATH . '/modules/legacy/language/' . $this->getFallbackLanguage() . '/global.php');
73: }
74: if (!$this->_loadFile($lpath . '/setting.php')) {
75: $this->_loadFile(XOOPS_ROOT_PATH . '/modules/legacy/language/' . $this->getFallbackLanguage() . '/setting.php');
76: }
77:
78:
79:
80:
81: if (!defined("XOOPS_USE_MULTIBYTES")) {
82: define("XOOPS_USE_MULTIBYTES", 0);
83: }
84: }
85:
86: 87: 88: 89: 90: 91: 92:
93: function loadPageTypeMessageCatalog($type)
94: {
95: if (strpos($type, '.') === false) {
96: if (!$this->_loadFile(XOOPS_ROOT_PATH . '/language/' . $this->mLanguageName . '/' . $type . '.php')) {
97: $this->_loadFile(XOOPS_ROOT_PATH . '/language/' . $this->getFallbackLanguage() . '/' . $type . '.php');
98: }
99: }
100: }
101:
102: 103: 104: 105: 106: 107:
108: function loadModuleMessageCatalog($moduleName)
109: {
110: $this->_loadLanguage($moduleName, 'main');
111: }
112:
113: 114: 115: 116: 117: 118:
119: function loadModuleAdminMessageCatalog($dirname)
120: {
121: $this->_loadLanguage($dirname, 'admin');
122: }
123:
124: 125: 126: 127: 128: 129:
130: function loadBlockMessageCatalog($dirname)
131: {
132: $this->_loadLanguage($dirname, 'blocks');
133: }
134:
135: 136: 137: 138: 139: 140:
141: function loadModinfoMessageCatalog($dirname)
142: {
143: $this->_loadLanguage($dirname, 'modinfo');
144: }
145:
146: 147: 148: 149: 150:
151: function _loadLanguage($dirname, $fileBodyName)
152: {
153: if (!$this->_loadFile(XOOPS_MODULE_PATH . '/' . $dirname . '/language/' . $this->mLanguageName . '/' . $fileBodyName . '.php')) {
154: $this->_loadFile(XOOPS_MODULE_PATH . '/' . $dirname . '/language/' . $this->getFallbackLanguage() . '/' . $fileBodyName . '.php');
155: }
156: }
157:
158:
159: 160: 161:
162: function _loadFile($filename)
163: {
164: if (file_exists($filename)) {
165: require_once $filename;
166: return true;
167: }
168:
169: return false;
170: }
171:
172: 173: 174: 175: 176: 177: 178: 179:
180: function existFile($section, $filename)
181: {
182: return file_exists(XOOPS_ROOT_PATH . '/languages/' . $this->mLanguageName . ($section?"/$section/$filename":"/$filename"));
183: }
184:
185: 186: 187: 188: 189: 190: 191: 192:
193: function getFilepath($section, $filename)
194: {
195: $filepath = XOOPS_ROOT_PATH . '/languages/' . $this->mLanguageName . ($section?"/${section}/${filename}":"/${filename}");
196:
197: if (file_exists($filepath)) {
198: return $filepath;
199: }
200: else {
201: return XOOPS_ROOT_PATH . '/languages/' . $this->getFallbackLanguage() . ($section?"/${section}/${filename}":"/${filename}");
202: }
203: }
204:
205: 206: 207: 208: 209: 210: 211: 212:
213: function loadTextFile($section, $filename)
214: {
215: $filepath = $this->getFilepath($section, $filename);
216: return file_get_contents($filepath);
217: }
218:
219: function getFallbackLanguage()
220: {
221: return 'english';
222: }
223:
224: function encodeUTF8($text)
225: {
226: if (XOOPS_USE_MULTIBYTES == 1) {
227: if (function_exists('mb_convert_encoding')) {
228: return mb_convert_encoding($text, 'UTF-8', _CHARSET);
229: }
230: }
231:
232: return utf8_encode($text);
233: }
234:
235: function decodeUTF8($text)
236: {
237: if (XOOPS_USE_MULTIBYTES == 1) {
238: if (function_exists('mb_convert_encoding')) {
239: return mb_convert_encoding($text, _CHARSET, 'UTF-8');
240: }
241: }
242:
243: return utf8_decode($text);
244: }
245: }
246:
247: ?>
248: