This repository was archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrooter.php
More file actions
161 lines (127 loc) · 2.69 KB
/
rooter.php
File metadata and controls
161 lines (127 loc) · 2.69 KB
1
<?phpsession_start();if(!isset($_GET['f'])){ _404();}else{ if($_GET['f'] === '') { $_filename = 'index.php'; } else if(file_exists($_GET['f'])) { $_filename = $_GET['f']; } else { _404(); }}// Get lang from Session or geolocalisation$lang = get_lang();$hasChanges = false;function get_lang(){ $lang = 'en'; // Define language for countries $country['fr'] = array('FR', 'BE', 'LU', 'MC', 'MU', 'YT', 'MF'); $country['en'] = array('US', 'UK', 'GB', 'AU'); $country['de'] = array('DE'); $country['jp'] = array('JP'); $country['sv'] = array('SE'); /*$country['it'] = array('IT'); */ if(isset($_SESSION['lang'])) { $lang = $_SESSION['lang']; } elseif(isset($_SERVER['REMOTE_ADDR'])) { $url = 'http://api.ipinfodb.com/v3/ip-country/?key=2088fec6a9b33e2851bd9b69f2bae8536708288e136cff7a7e61c52974e2b482&ip=' . $_SERVER['REMOTE_ADDR'] . '&format=json'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $content = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $ipData = json_decode($content); if($httpCode === 200 && $ipData->statusCode == 'OK') { foreach($country as $isoLang => $countryList) { if(in_array($ipData->countryCode, $countryList)) { $lang = $isoLang; } } } $_SESSION['lang'] = $lang; } return $lang;}function translate($id, $text){ global $hasChanges, $translation; // If translation exists if(isset($translation[$id])) { /* If it's not a new translation, we can translate it * Else, we use default text */ if(strpos($translation[$id], '#new# ') === false) { return $translation[$id]; } else { return substr($translation[$id], 6); } } else { $hasChanges = true; $translation[$id] = addcslashes('#new# ' . $text , '"'); } return $text;}$langfile = 'lang/' . $lang . '.txt';$initTranslation = true;$translation = array();if(!file_exists($langfile)){ mkdir($langfile);}else{ if(false === ($translation = parse_ini_file($langfile))) { $initTranslation = false; }}ob_start();include($_filename);$sContent = ob_get_contents();ob_end_clean();//$mtimeStart = microtime();$sContent = preg_replace_callback('#{tr id=([0-9a-z_]+)}(.*){/tr}#sUi', create_function('$matches', '$id = $matches[1]; $text = $matches[2]; return translate($id, $text);'), $sContent);echo $sContent;if($hasChanges && $initTranslation === true){ include 'r/php/write_ini.php'; ksort($translation); write_ini_file($translation, $langfile);}/*$mtimeEnd = microtime();echo 'preg time : ' . ($mtimeEnd - $mtimeStart);*/function _404(){ require '/r/404.html'; die;}