city($ip);
}
catch (Exception $e) {
$record = $reader->city("212.198.253.35");
}
$country = $record->country->isoCode;
$region = $record->mostSpecificSubdivision->isoCode;
$continent = $record->continent->code;
$csv = csv_to_array('php/lib/config_country.csv', ';');
foreach($csv as $item) {
if($item["code"]==$country) {
$language = $item["lang_code"];
$devise = $item["devise"];
break;
}
}
// END RECUPERATION DU PAYS + LANGUE + DEVISE
$lang = NULL;
$locked = false;
$defaultEnv = "restaurant";
$skybox = "restaurant";
$base = dirname($_SERVER['PHP_SELF']) . '/';
if($base == '//') $base = '/';
$domainURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'];
// That version is better than just test modules are enabled via `apache_get_modules()` (see `.htaccess`)
$rewriteURL = isset($_SERVER['HTACCESS_REWRITE']) && $_SERVER['HTACCESS_REWRITE'] == 'on';
$requestParts = explode('?', $_SERVER["REQUEST_URI"]);
$baseFullPath = array_shift($requestParts);
// Remove base
$fullPath = substr($baseFullPath, strlen($base));
$pathSlices = explode('/', $fullPath, 2);
$direct = "";
$langDefined = 0;
if(count($pathSlices) > 0){
//echo "LANG : ".$pathSlices[0];
$lang = $pathSlices[0];
if(count($pathSlices) > 1){
//echo "DIRECT -> : ".$pathSlices[1];
$direct = $pathSlices[1];
}
if(!empty($lang)) $langDefined = 1;
}
// BEGIN ON FORCE LA LANGUE SI NON SELECTIONNE DANS L'URL
if($lang=="") {
if($continent=="AF") {
$language = "fr";
}
if($continent=="SA" && $country !="BR") {
$language = "es";
}
// attention sur My Deejo on a pas d'espagnol. fallback vers l'anglais.
if($language=="es") $language = "en";
$lang = $language;
}
// END ON FORCE LA LANGUE SI NON SELECTIONNE DANS L'URL
// DEBUG START
/*
echo $continent . "
";
echo $country . "
";
echo $region;
die();
*/
/*
echo $lang . "
";
echo $devise . "
";
die();
*/
// DEBUG END
$forcecss = "0";
$preview = "0";
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
if(isset($_GET['css']) || $isiPad) $forcecss = "1";
if(isset($_GET['preview'])) $preview = "1";
$prodMode = false;
if(strpos($_SERVER['SERVER_NAME'], 'deejo') !== false) $prodMode = true;
if(isset($_GET["lang"])) $lang = $_GET["lang"];
if(empty($lang) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
$lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
else if(empty($lang))
$lang = "en";
if($lang != "fr" && $lang != "en" && $lang != "de") $lang = "en";
// **************************************** init ******************************************
$folder = "";
if( $_SERVER['HTTP_HOST'] == "127.0.0.1" ) $folder = "deejo/";
$baseurl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] .'/'.$folder;
$baseurlang = $baseurl.$lang."/";
$baseurlangshare = $baseurl."?lang=".$lang;
// JSON LANG ::
$dirname = $_SERVER['DOCUMENT_ROOT']."/".$folder;
if( $_SERVER['DOCUMENT_ROOT'] == "127.0.0.1" ) $dirname = "127.0.0.1/deejo/";
$jsonFolderPath = $dirname.'lib/';
$jsonFile = 'assets/data/'.'data_'.$lang.'.json';
if (file_exists($jsonFile)) $jsoncontent = file_get_contents($jsonFile);
else $jsoncontent = file_get_contents('assets/data/data_'.$lang.'.json');
// data **********************************
$app_id = "";
$data = json_decode($jsoncontent);
$labels = $data->labels;
$share = $data->share;
// fix Manu
$json_good = true;
// data products ************************
// GET FROM CS CARD
$jsonProductFile = $dirname.'lib/listing_'.$lang.'.json';
$jsonProductFileSafe = $dirname.'lib/listing_'.$lang.'.json.safe';
// ONLINE JSON !
function loadJSON($jsonFolderPath, $lang, $env) {
$jsonProductApiFile = 'http://deejo.twin-solutions.fr/curl_products.php?lang='.$lang.'&safe=true';
if(isset($_GET["univers_id"])) $jsonProductApiFile.= '&univers_id='.$_GET["univers_id"];
$jsonProductFile = $jsonFolderPath.$env.'_'.$lang.'.json';
if (file_exists($jsonProductFile)){
$jsonProductsContent = file_get_contents($jsonProductFile);
}
else{
// ONLINE JSON FROM BACKOFFICE
//$jsonProductsContent = file_get_contents($jsonProductApiFile);
$jsonProductsContent = file_get_contents($jsonProductFile.".safe");
}
/*if(isset($_GET['static']) )
{
// LOCAL JSON !
$jsonProductFile = $jsonFolderPath.$env.'_'.$lang.'.json';
if (file_exists($jsonProductFile))
$jsonProductsContent = file_get_contents($jsonProductFile);
else if (file_exists($jsonFolderPath.$env.'_en.json'))
$jsonProductsContent = file_get_contents($jsonFolderPath.$env.'_en.json');
else if (file_exists('assets/data/products_'.$lang.'.json'))
$jsonProductsContent = file_get_contents('assets/data/'.$env .'_'.$lang . '.json');
else
$jsonProductsContent = file_get_contents('assets/data/' . $env .'_en.json');
}else{
// ONLINE JSON FROM BACKOFFICE
$jsonProductsContent = file_get_contents($jsonProductFile);
}*/
return $jsonProductsContent;
}
$jsonProductsContent = loadJSON($jsonFolderPath, $lang, "listing");
if($jsonProductsContent){
$univers = json_decode($jsonProductsContent)->univers;
$products = json_decode($jsonProductsContent)->products;
if($products){
$json_good = true;
}
}
else {
$fichier=$dirname.'lib/error_file_json.txt';
$handle=fopen($fichier, "a");
fwrite($handle, "\nouverture impossible du fichier json ".$jsonProductFile." - ".date('l jS \of F Y h:i:s A'));
fclose($handle);
////// ICI VOIR AVEC LUC POUR AFFICHER PLUTOT UN MESSAGE D'ERREUR AU VISITEUR PLUTOT QUE DE RENVOYER SUR LE SERVEUR
//header('Location: http://betc.twin-solutions.fr/');
}
$currentEnv = $defaultEnv;
$fullpathSlices = explode('/', $fullPath);
if(count($fullpathSlices)>=2) {
foreach($univers as $item=>$key) {
$item = get_object_vars($key);
if($item["id"]==$fullpathSlices[1]) {
$currentEnv = $fullpathSlices[1];
}
}
}
$current_univers = Array();
if($currentEnv!=$defaultEnv) {
$modelsUnivers = Array();
$jsonProductsContent = loadJSON($jsonFolderPath, $lang, strtoupper($currentEnv));
if($jsonProductsContent){
$products = json_decode($jsonProductsContent)->products;
$current_univers = get_object_vars(get_object_vars(json_decode($jsonProductsContent))["current_univers"]);
if($products){
$json_good = true;
}
} else {
$fichier=$dirname.'lib/error_file_json.txt';
$handle=fopen($fichier, "a");
fwrite($handle, "\nouverture impossible du fichier ".$jsonProductFileSafe." - ".date('l jS \of F Y h:i:s A'));
fclose($handle);
////// ICI VOIR AVEC LUC POUR AFFICHER PLUTOT UN MESSAGE D'ERREUR AU VISITEUR PLUTOT QUE DE RENVOYER SUR LE SERVEUR
//header('Location: http://betc.twin-solutions.fr/');
}
$is_open = @$current_univers["menu_open"];
if($is_open=="0") {
$is_open = "is_open";
}
else {
$is_open = "";
}
$pos = explode("/", $direct);
if(count($pos)>5) {
$direct = $pos[1] . "/" . $pos[2] . "/" . $pos[3] . "/" . $pos[4] . "/" . $pos[5] . "/" . $pos[6];
}
else {
$direct = "";
}
$dataSky = $current_univers;
$skybox = $dataSky["skybox"];
$models = get_object_vars($dataSky["models"]);
foreach($models as $item) {
/* BASE */
$baseData = get_object_vars($item);
$base = get_object_vars($baseData["base"]);
$build = $base["weight"] . $base["id_ux"];
/* BASE */
/* HANDLES */
$handles = get_object_vars($baseData["handles"]);
$textstyles = get_object_vars($baseData["textstyles"]);
$handlesOptions = get_object_vars($handles["options"]);
if($handlesOptions["id_ux"]=="naked" || $base["weight"]=="15") {
$punched = 0;
}
else {
$punched = 1;
}
$build = $build . $punched;
$build = $build . "_".$handlesOptions["id_ux"]."_";
/* HANDLES */
/* TATTOOS */
$tattoos = get_object_vars($baseData["tattoos"]);
$build = $build . $tattoos["id_ux"];
/* TATTOOS */
array_push($modelsUnivers, Array(
"img" => @$baseData["preconf_image"],
"url" => $base["weight"] . "/" . $base["id_ux"] . "/" . $handlesOptions["id_ux"] . "/".$textstyles["id_ux"]."/none/" . $tattoos["id_ux"]
));
}
if($direct=="") {
$direct = $modelsUnivers[0]["url"];
$locked = true;
}
}
$fullpathSlicesEnd = explode('/', $direct);
if($fullpathSlicesEnd[2]=="none") {
header("Status: 301 Moved Permanently", false, 301);
header("Location: /");
exit();
}
if($direct=="") {
$direct = "37/mirror/genevrier/none/none/none";
}
$devisesList = array("eur" => "€", "usd" => "$");
//var_dump($products);
// process products datas
if($json_good){
// DISPLAY TEMPLATE
// Mobile -- ??
require_once("php/class/Mobile_Detect.php");
$detectMobile = new Mobile_Detect();
$mobile = true;
$tablet = $detectMobile->isTablet();
$androidVersion = $detectMobile->version('Android');
if(!$detectMobile->isMobile()) {
include('php/template_mobile.php');
}
else {
include('php/template_mobile.php');
}
} else {
$fichier=$dirname.'lib/error_file_json.txt';
$handle=fopen($fichier, "a");
fwrite($handle, "\nfichier json transmis corrompu - ".date('l jS \of F Y h:i:s A'));
fclose($handle);
////// ICI VOIR AVEC LUC POUR AFFICHER PLUTOT UN MESSAGE D'ERREUR AU VISITEUR PLUTOT QUE DE RENVOYER SUR LE SERVEUR
//header('Location: http://betc.twin-solutions.fr/');
}
?>