diff --git a/.htaccess b/.htaccess deleted file mode 100644 index 38ce6bcd1c4545438df88395637f4bd6dc09254d..0000000000000000000000000000000000000000 --- a/.htaccess +++ /dev/null @@ -1,21 +0,0 @@ - -<IfModule mod_rewrite.c> -RewriteEngine On -RewriteBase /www/cesium-website/ - -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule .*\.php - [L] - -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^([^/]+)/(.*)$ index.php?lang=$1&page=/$2 [L] - - -# Redirections pour gérer l'ancienne structure de liens sans perdre en SEO -# (ex : /telechargement au lieu de /fr/telechargement) -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^([^/]+)$ fr/$1 [R=301] -</IfModule> - diff --git a/config.php b/config.php index 90951edaf92da93c71ef0b8f1dca646e86d76c68..efe6d801a60e9b4def4816ef8229ccd9ea8517c1 100644 --- a/config.php +++ b/config.php @@ -14,16 +14,69 @@ $legalNotice = +// Trouver une façon de définir $rootURL sans faire ça : + +if ($_SERVER['SERVER_NAME'] == 'localhost') { + + $rootURL = '/www/cesium-website'; + +} else { + + $rootURL = ''; + +} + /* ====== i18n ====== */ +function checkAvailableLanguages ($langList) { + + foreach ($langList as $isoCode => $l) { + + $loc = setlocale(LC_ALL, $l['folder'], ($l['folder'] . '.utf8')); + + if ($loc === false) { + + unset($langList[$isoCode]); + + } else { + + $langList[$isoCode]['localeCode'] = $loc; + } + } + + return $langList; +} + $availableLanguages = [ - 'fr', - 'en', - 'es', - 'va' + 'fr' => [ + 'name' => 'français', + 'folder' => 'fr_FR' + ], + 'en' => [ + 'name' => 'english', + 'folder' => 'en_GB' + ], + 'es' => [ + 'name' => 'español', + 'folder' => 'es_ES' + ], + 'va' => [ + 'name' => 'valyrio', + 'folder' => 'en_US' + ], + /* + 'it' => [ + 'name' => 'italiano', + 'folder' => 'it_IT' + ], + */ ]; +$availableLanguages = checkAvailableLanguages($availableLanguages); + +//echo '<pre>'; print_r($availableLanguages); echo '</pre>'; + define('DEFAULT_LANG', 'fr'); include('inc/lang.php'); @@ -44,18 +97,6 @@ bindTextDomains($textDomains); -// Trouver une façon de définir $rootURL sans faire ça : - -if ($_SERVER['SERVER_NAME'] == 'localhost') { - - $rootURL = '/www/cesium-website'; - -} else { - - $rootURL = '/cesium/cesium.app'; - -} - include('inc/functions.php'); include('inc/display.php'); diff --git a/foot.php b/foot.php index 0fe69d96756bb4203238b2a325a4adfe152427a3..4b50e4410d70dfb20597609ccb2f6057aa8bd41c 100644 --- a/foot.php +++ b/foot.php @@ -91,35 +91,36 @@ textdomain('menu'); textdomain('menu'); - foreach ($availableLanguages as $l) + foreach ($availableLanguages as $thisLangIsoCode => $thisLang) { + /* To have links translated */ + putenv('LC_ALL='. $thisLang['localeCode']); + setlocale(LC_ALL, $thisLang['localeCode']); + echo ' <li>'; - if ($l == LANG) { + if ($thisLangIsoCode == LANG) { echo ' <strong> <span> - ' . $l . ' + ' . $thisLangIsoCode . ' </span> <span> - ' . getLangName($l) . ' + ' . $thisLang['name'] . ' </span> </strong>'; } else { - - putenv('LC_ALL='. getGetTextFolder($l)); - setlocale(LC_ALL, getGetTextFolder($l) . '.utf8'); echo ' - <a href="'. $rootURL .'/'. $l . _($pagePermalink) .'"> + <a href="'. $rootURL .'/'. $thisLangIsoCode . _($pagePermalink) .'"> <span> - ' . $l . ' + ' . $thisLangIsoCode . ' </span> <span> - ' . getLangName($l) . ' + ' . $thisLang['name'] . ' </span> </a>'; @@ -128,9 +129,9 @@ textdomain('menu'); echo ' </li>'; } - - putenv('LC_ALL='. L10N_FOLDER); - setlocale(LC_ALL, L10N_FOLDER . '.utf8'); + + putenv('LC_ALL='. LANG_FOLDER); + setlocale(LC_ALL, LOCALE_CODE); ?> </ul> </nav> diff --git a/head.php b/head.php index bda221cf8c97307034ae3355be98bba2eeb99661..4b5b2a334fd15f4795bf413b287cf13bf696767c 100644 --- a/head.php +++ b/head.php @@ -27,20 +27,22 @@ $bodyIds = !isset($bodyIds) ? '' : $bodyIds; <meta property="og:description" content="<?php echo $pageDescription; ?>" /> <meta property="og:url" content="http://cesium.app/" /> <meta property="og:site_name" content="Cesium Ğ1" /> - <meta property="og:image" content="<?php echo $rootURL . '/i18n/' . L10N_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" /> + + <meta property="og:image" content="<?php echo $rootURL . '/i18n/' . LANG_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" /> <meta property="og:type" content="website" /> <meta name="twitter:description" content="<?php echo $pageDescription; ?>" /> <meta name="twitter:title" content="<?php echo $pageTitle; ?>" /> - <meta name="twitter:image" content="<?php echo $rootURL . '/i18n/' . L10N_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" /> + + <meta name="twitter:image" content="<?php echo $rootURL . '/i18n/' . LANG_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" /> <meta name="twitter:card" content="summary_large_image" /> <script type="text/javascript" src="<?php echo $rootURL; ?>/lib/lazyImg.min.js"></script> <?php - foreach ($availableLanguages as $l) + foreach ($availableLanguages as $isoCode => $v) { - echo '<link rel="alternate" hreflang="'. $l .'" href="'. $rootURL .'/'. $l .'/" />'; + echo '<link rel="alternate" hreflang="'. $isoCode .'" href="'. $rootURL .'/'. $isoCode .'/" />'; } ?> diff --git a/inc/functions.php b/inc/functions.php index d468b7a30b95db22f6201c170adb47d232deb32c..4df84cc687f1b306a530ef7ac1bb383c6055edab 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -30,7 +30,8 @@ function getUserIpAddress () } else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { - return array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])); + $a = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + return array_pop($a); } else { diff --git a/inc/lang.php b/inc/lang.php index b892d43b38427956ac639f4f52dd23461578a053..cffea41edbfcd69da644f9ad3112198c6a2e8b56 100644 --- a/inc/lang.php +++ b/inc/lang.php @@ -1,66 +1,59 @@ <?php -function getLangName ($code) +function getLangName ($isoCode) { - switch ($code) - { - case 'fr' : - return 'français'; - case 'en' : - return 'english' ; - case 'es' : - return 'español'; - case 'va' : - return 'valyrio'; - case 'it' : - return 'italiano'; - default : - return ''; // Supposedly cannot happen - } + global $availableLanguages; + + return $availableLanguages[$isoCode]['name']; } -function getGetTextFolder ($code) +function getLocaleCode ($isoCode) { - switch ($code) - { - case 'fr' : - return 'fr_FR'; - case 'en' : - return 'en_GB'; - case 'es' : - return 'es_ES'; - case 'va' : - return 'en_US'; - case 'it' : - return 'it_IT'; - } + global $availableLanguages; + + return $availableLanguages[$isoCode]['localeCode']; +} + +function getLangFolder ($isoCode) +{ + global $availableLanguages; + + return $availableLanguages[$isoCode]['folder']; } function defineLang () { global $availableLanguages; + global $rootURL; - if (isset($_GET['lang'])) { + if (isset($_GET['lang'])) { /* From URL */ $lang = $_GET['lang']; + + + if (!in_array($lang, array_keys($availableLanguages))) { + + header('Location: '. $rootURL . '/'. DEFAULT_LANG . '/'); + } - } else { + } else { /* From browser (if visiting root page /) */ $lang = preg_replace('/^([^,-]+).*$/', '$1', $_SERVER['HTTP_ACCEPT_LANGUAGE']); } - - if (!in_array($lang, $availableLanguages)) { + + if (!in_array($lang, array_keys($availableLanguages))) { define('LANG', DEFAULT_LANG); } else { - + define('LANG', $lang); } - define('L10N_FOLDER', getGetTextFolder(LANG)); + define('LOCALE_CODE', getLocaleCode(LANG)); + define('LANG_FOLDER', getLangFolder(LANG)); } function bindTextDomains ($textDomains) diff --git a/index.php b/index.php index e718d4ffb9e69ab3a752f8cd2418542505eb28fc..ff3a9247c881b4d75fc45c0eb8ae177beb877654 100644 --- a/index.php +++ b/index.php @@ -3,12 +3,8 @@ include('config.php'); defineLang(); -putenv('LC_ALL='. L10N_FOLDER); - - -if (false === setlocale(LC_ALL, L10N_FOLDER . '.utf8')) { - exit (sprintf('La langue "%s" n\'est pas installée sur ce système.', L10N_FOLDER)); -} +putenv('LC_ALL='. LANG_FOLDER); +setlocale(LC_ALL, LOCALE_CODE); textdomain("menu"); diff --git a/lib/style.css b/lib/style.css index 99c7b45bfc4e9ed4b6e4543f92d4e6d16418316b..e947cc519ff3376e6d1b0b2f92caa004e34fde5e 100644 --- a/lib/style.css +++ b/lib/style.css @@ -315,6 +315,7 @@ body header:first-child > h2 order: 2; flex-grow: 1; text-align: left; + font-size: 2.25rem; } body header:first-child > :first-child a, @@ -322,7 +323,7 @@ body header:first-child > :first-child a:hover { color: white; text-decoration: none; - padding-left: 0.5em; + padding-left: 0.25em; } @@ -683,6 +684,11 @@ body#home #showcase h2#USP text-align: center; } +body#home #showcase :not(figure) { + + z-index: 666; +} + body#home #showcase h2#USP + p { margin-top: 0rem; @@ -775,7 +781,7 @@ body#home #showcase h2#USP + p body#home #showcase div { flex-direction: column; - height: calc(100vh - 120px - 1rem); + height: calc(90vh - 120px - 1rem); box-sizing: border-box; } @@ -797,7 +803,9 @@ body#home #showcase h2#USP + p body#home #showcase figure img { align-self: center; - width: 112.5%; + height: calc(90vh - 120px); + width: auto; + transform: translateY(1rem) translateX(-2vw); } } @@ -811,7 +819,8 @@ body#home #showcase h2#USP + p body#home #showcase figure img { align-self: center; - width: 125%; + height: calc(90vh - 120px); + width: auto; transform: translateY(1rem) translateX(-2vw); } } diff --git a/tpl/features.php b/tpl/features.php index d96559ab695d483186d3c62cb449ce8959b16d85..33f65747b975321b82592398124e6dd4856146a7 100644 --- a/tpl/features.php +++ b/tpl/features.php @@ -23,7 +23,7 @@ textdomain('features'); $reader = new Reader('vendor/GeoLite2-Country/GeoLite2-Country.mmdb'); $record = $reader->country(getUserIpAddress()); - $path = './i18n/' . L10N_FOLDER . '/contents' . _('/fonctionnalites'); + $path = './i18n/' . LANG_FOLDER . '/contents' . _('/fonctionnalites'); $mapFileName = _('/carte-des-utilisateurs') . _('/pays') . sprintf('/%s.png', $record->country->isoCode); if (!file_exists($path . $mapFileName)) { @@ -134,7 +134,7 @@ textdomain('features'); { echo ' <figure> - <img src="'. $rootURL .'/i18n/' . L10N_FOLDER . '/contents' . _('/fonctionnalites') . $f['img'] .'" /> + <img src="'. $rootURL .'/i18n/' . LANG_FOLDER . '/contents' . _('/fonctionnalites') . $f['img'] .'" /> <figcaption> <h2>'. $f['name'] .'</h2>'; diff --git a/tpl/home.php b/tpl/home.php index 20669fcac2933a9686bfbd9dd7649713f027bd9f..21a0863b73955cc0d5e688c617eaad7f15191849 100644 --- a/tpl/home.php +++ b/tpl/home.php @@ -13,7 +13,7 @@ textdomain('home'); <section id="showcase"> <div> <figure id="home-app-screenshot"> - <img src="<?php echo $rootURL . '/i18n/' . L10N_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" + <img src="<?php echo $rootURL . '/i18n/' . LANG_FOLDER . '/contents' . _('/accueil') . _('/Cesium-G1-maquette.png'); ?>" alt="capture d'écran de Cesium" /> </figure> @@ -143,7 +143,7 @@ textdomain('home'); <?php -$reviewsPath = './i18n/' . L10N_FOLDER . '/contents' . _('/accueil') . _('/avis') . '/'; +$reviewsPath = './i18n/' . LANG_FOLDER . '/contents' . _('/accueil') . _('/avis') . '/'; if (file_exists($reviewsPath) AND ($reviewsFiles = scandir($reviewsPath)) AND count($reviewsFiles)-2 > 0) { diff --git a/tpl/tuto.php b/tpl/tuto.php index 66b127745537980cc53a25da1773cdd1269bedb9..8e7e582f0663ab80962c1ff898ad6d9abc062448 100644 --- a/tpl/tuto.php +++ b/tpl/tuto.php @@ -10,7 +10,7 @@ if (empty($subpage)) -$tutoContentsPath = './i18n/' . L10N_FOLDER . '/contents/tuto'; +$tutoContentsPath = './i18n/' . LANG_FOLDER . '/contents/tuto'; if (file_exists($tutoContentsPath . $subpage) and !is_dir($tutoContentsPath . $subpage) ) @@ -75,7 +75,7 @@ if (file_exists($tutoContentsPath . $subpage) and !is_dir($tutoContentsPath . $s { /* === Menu === */ - $menu = './i18n/' . L10N_FOLDER . '/contents/tuto/menu.html'; + $menu = './i18n/' . LANG_FOLDER . '/contents/tuto/menu.html'; if (file_exists($menu)) { $toc = file_get_contents($menu, FILE_USE_INCLUDE_PATH);