| 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 <lusopoemas@gmail.com> | 
| 20: | * @copyright 2011-2018 XOOPS Project (https://xoops.org) | 
| 21: | * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) | 
| 22: | * @link https://xoops.org | 
| 23: | */ | 
| 24: | class Language | 
| 25: | { | 
| 26: | /** | 
| 27: | * Attempt a translation of a simple string | 
| 28: | * | 
| 29: | * @param string $string string to translate | 
| 30: | * @param string $domain language domain | 
| 31: | * | 
| 32: | * @return string translated string | 
| 33: | * | 
| 34: | * @todo do something useful | 
| 35: | */ | 
| 36: | public static function translate($string, $domain = null) | 
| 37: | { | 
| 38: | return $string; | 
| 39: | } | 
| 40: | |
| 41: | /** | 
| 42: | * load - load a language file | 
| 43: | * | 
| 44: | * @param string $name name of the language file | 
| 45: | * @param string $domain domain or module supplying language file | 
| 46: | * @param string $language language folder name | 
| 47: | * | 
| 48: | * @return bool true if loaded, otherwise false | 
| 49: | */ | 
| 50: | public static function load($name, $domain = '', $language = null) | 
| 51: | { | 
| 52: | if (empty($language)) { | 
| 53: | if (!empty($GLOBALS['xoopsConfig']['language'])) { | 
| 54: | $language = $GLOBALS['xoopsConfig']['language']; | 
| 55: | } else { | 
| 56: | $language = 'english'; | 
| 57: | } | 
| 58: | } | 
| 59: | $path = XOOPS_ROOT_PATH . '/' . ((empty($domain) || 'global' === $domain) ? '' | 
| 60: | : "modules/{$domain}/") . 'language'; | 
| 61: | if (!$ret = static::loadFile("{$path}/{$language}/{$name}.php")) { | 
| 62: | $ret = static::loadFile("{$path}/english/{$name}.php"); | 
| 63: | } | 
| 64: | |
| 65: | return $ret; | 
| 66: | } | 
| 67: | |
| 68: | /** | 
| 69: | * Load a file | 
| 70: | * | 
| 71: | * @param string $filename filename to load | 
| 72: | * | 
| 73: | * @return bool true if file exists and was loaded | 
| 74: | * | 
| 75: | * @throws \InvalidArgumentException | 
| 76: | */ | 
| 77: | protected static function loadFile($filename) | 
| 78: | { | 
| 79: | if (preg_match('/[[:cntrl:]]/i', $filename)) { | 
| 80: | throw new \InvalidArgumentException('Security check: Illegal character in filename'); | 
| 81: | } | 
| 82: | if (file_exists($filename)) { | 
| 83: | include_once $filename; | 
| 84: | return true; | 
| 85: | } | 
| 86: | return false; | 
| 87: | } | 
| 88: | } | 
| 89: |