2016-06-24 11:35:09 +02:00
|
|
|
<?php
|
|
|
|
$current_dir= basename (getcwd ());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Language registration
|
|
|
|
*/
|
|
|
|
|
|
|
|
$registered_languages= array();
|
|
|
|
|
|
|
|
function register_lang ( $code, $lang ) {
|
|
|
|
global $registered_languages;
|
|
|
|
$registered_languages[$code]= $lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($current_dir == "htdocs")
|
|
|
|
include ("languages.php");
|
|
|
|
else
|
|
|
|
include ("../languages.php");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prefered language detection
|
|
|
|
*/
|
|
|
|
|
|
|
|
function prefered_language () {
|
|
|
|
global $registered_languages;
|
|
|
|
$locale= locale_accept_from_http ($_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
|
|
return locale_lookup (array_keys ($registered_languages), $locale, true, 'fr');
|
|
|
|
}
|
|
|
|
|
2016-09-13 17:24:43 +02:00
|
|
|
/*
|
|
|
|
* URL translation
|
|
|
|
*/
|
|
|
|
|
|
|
|
function url_translate ($url, $to) {
|
|
|
|
global $registered_languages;
|
|
|
|
|
|
|
|
$current_dir= basename (getcwd ());
|
|
|
|
if ($current_dir == "htdocs")
|
|
|
|
$from= 'fr';
|
|
|
|
else
|
|
|
|
$from= $current_dir;
|
|
|
|
|
|
|
|
$name= basename ($url);
|
|
|
|
$index= array_search ($name, $registered_languages[$from]['pages']);
|
2016-11-11 22:17:50 +01:00
|
|
|
if ($index === false)
|
2016-09-13 17:31:59 +02:00
|
|
|
return $registered_languages[$to]['loc'];
|
2016-09-13 17:24:43 +02:00
|
|
|
return $registered_languages[$to]['loc'] . $registered_languages[$to]['pages'][$index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-24 11:35:09 +02:00
|
|
|
/*
|
|
|
|
* Redirect to prefered language, if needed, when referer is none or ourself
|
|
|
|
*/
|
2016-11-11 22:10:53 +01:00
|
|
|
$server_names= array('expolibre.org', 'www.expolibre.org', 'libreexpo.org', 'www.libreexpo.org');
|
|
|
|
if (!isset ($_SERVER['HTTP_REFERER']) or (
|
|
|
|
strrpos ($_SERVER['HTTP_REFERER'], 'expolibre.org') === false and
|
|
|
|
strrpos ($_SERVER['HTTP_REFERER'], 'libreexpo.org') === false)) {
|
2016-06-24 11:35:09 +02:00
|
|
|
if ($current_dir == "htdocs")
|
|
|
|
$current_dir= $registered_languages['fr']['loc'];
|
|
|
|
$prefered_dir= $registered_languages[prefered_language ()]['loc'];
|
|
|
|
if (basename($current_dir) != basename ($prefered_dir)) {
|
2016-11-11 22:11:22 +01:00
|
|
|
header ("Location: " . url_translate ($_SERVER['REQUEST_URI'], prefered_language ()));
|
2016-06-24 11:35:09 +02:00
|
|
|
exit ();
|
|
|
|
}
|
|
|
|
}
|
2016-09-13 17:24:43 +02:00
|
|
|
|
2016-06-24 11:35:09 +02:00
|
|
|
?>
|