Mageia Bugzilla – Attachment 557 Details for
Bug 860
German forums need to be setup
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
PHP redirection script for forums.mageia.org
redirect.php (text/php), 5.45 KB, created by
Romain d'Alverny
on 2011-06-13 16:09:17 CEST
(
hide
)
Description:
PHP redirection script for forums.mageia.org
Filename:
MIME Type:
Creator:
Romain d'Alverny
Created:
2011-06-13 16:09:17 CEST
Size:
5.45 KB
patch
obsolete
><?php >/** > * Language/locale redirection script for forum[s].mageia.org root. > * > * http://forum.mageia.org/ > * redirects to the forum best matching the browser language preferences > * (as sent through the Accept-Language HTTP header). > * > * http://forum.mageia.org/?langs > * lists all available forums. > * > * http://forum.mageia.org/{language}/ > * either is the forum, or redirects to the forum URL (if this forum is > * handled outside of mageia.org domain). > * > * All Mageia links to forums are supposed to be one of those 3 above. > * > * TODO have a single list to manage existing forums and outside forums to redirect to. > * Currently, we have a list in phpbb, a Apache redirection set of rules and this file. > * > * TODO each forum should host a top list of all other official forums for users to switch to > * if they want (and, referring at the same map of forums, please!) > * > * PHP version 5 > * > * @category Mageia_Web_Sites > * @package Forums.mageia.org > * @author Romain d'Alverny <rda@mageia.org> > * @copyright 2011 Romain d'Alverny > * @license GPL-2 > * >*/ > >/** > * @var $forumsMap >*/ >$forumsMap = array( > 'de' => 'Deutsch', > 'el' => 'Îλληνικά', > 'en' => 'English', > 'es' => 'Español', > 'fr' => 'Français', > 'it' => 'Italiano', > 'zh-cn' => 'ç®ä½ä¸æ', > 'pt-br' => 'Português do Brasil', > 'tr' => 'Türkçe', > >// 'cs' => 'ÄeÅ¡tina', >// 'et' => 'Eesti', >// 'fi' => 'Suomeksi', >// 'lv' => 'LatvieÅ¡u', >// 'nb' => 'BokmÃ¥l', >// 'nl' => 'Nederlands', >// 'pl' => 'Polski', >// 'pt' => 'Português', >// 'ro' => 'RomânÄ', >// 'ru' => 'Ð ÑÑÑкий', >// 'sl' => 'SlovenÅ¡Äina', >// 'uk' => 'ÑкÑаÑÌнÑÑка моÌва', >// 'zh-tw' => 'æ£é«ä¸æ' > >); > >if (isset($_GET['langs'])) { > die(show_langs($forumsMap)); > >} > >if ($_SERVER['REQUEST_URI'] === '/') { > $locale = new ChooseLocale(array_keys($forumsMap)); > $locale->setDefaultLocale('en'); > > header(sprintf('Location: /%s/%s', > $locale->getCompatibleLocale(), > $page > )); > die; > >} > >/** >*/ >function show_langs($langs) >{ > header('Content-Type: text/html; charset=utf-8'); > $count = count($langs); > $s = <<<S ><!DOCTYPE html> ><html lang="en"> ><head> > <charset="utf-8"> > <meta name="robots" content="noindex,nosnippet"> > <title>Mageia Forums</title> ></head> ><body> ><p>Mageia Forums are currently available in {$count} languages:</p> ><ul> >S; > foreach ($langs as $k => $v) { > $s .= sprintf('<li><a href="/%s/" hreflang="%s">%s</a></li>', > $k, $k, $v); > } > echo $s, '</ul><hr /></body></html>'; >} > > > >/* ChooseLocale > * > * Licence: MPL 2/GPL 2.0/LGPL 2.1 > * Author: Pascal Chevrel, Mozilla > * Date : 2010-07-17 > * > * Description: > * Class to choose the locale which locale we will show to the visitor > * based on http acceptlang headers and our list of supported locales. > * > * >*/ >class ChooseLocale >{ > public $HTTPAcceptLang; > public $supportedLocales; > protected $detectedLocale; > protected $defaultLocale; > public $mapLonglocales; > > > public function __construct($list=array('en-US')) > { > $this -> HTTPAcceptLang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; > $this -> supportedLocales = array_unique($list); > $this -> setDefaultLocale('en-US'); > $this -> setCompatibleLocale(); > $this -> mapLonglocales = true; > > } > > public function getAcceptLangArray() > { > if (empty($this->HTTPAcceptLang)) return null; > > return explode(',', $this->HTTPAcceptLang); > } > > public function getCompatibleLocale() > { > $l = $this -> defaultLocale; > $acclang = $this -> getAcceptLangArray(); > > if(!is_array($acclang)) { > return $this -> defaultLocale; > } > > foreach ($acclang as $var) { > $locale = $this -> _cleanHTTPlocaleCode($var); > $shortLocale = array_shift(explode('-', $locale)); > > if (in_array($locale, $this -> supportedLocales)) { > $l = $locale; > break; > } > > if (in_array($shortLocale, $this -> supportedLocales)) { > $l = $shortLocale; > break; > } > > // check if we map visitors short locales to site long locales > // like en -> en-GB > if ($this -> mapLonglocales == true) { > foreach ($this -> supportedLocales as $var) { > $shortSupportedLocale = array_shift(explode('-', $var)); > if ($shortLocale == $shortSupportedLocale) { > $l = $var; > break; > } > } > } > > } > > return $l; > } > > public function getDefaultLocale() { > return $this -> defaultLocale; > } > > public function setCompatibleLocale() { > $this -> detectedLocale = $this -> getCompatibleLocale(); > } > > public function setDefaultLocale($locale) { > > // the default locale should always be among the site locales > // if not, the first locale in the supportedLocales array is default > if (!in_array($locale, $this -> supportedLocales)) { > $this -> defaultLocale = $this -> supportedLocales[0]; > > } else { > $this -> defaultLocale = $locale; > } > return; > } > > private function _cleanHTTPlocaleCode($str) > { > $locale = explode(';', $str); > $locale = trim($locale[0]); > > return $locale; > } > >}
<?php /** * Language/locale redirection script for forum[s].mageia.org root. * * http://forum.mageia.org/ * redirects to the forum best matching the browser language preferences * (as sent through the Accept-Language HTTP header). * * http://forum.mageia.org/?langs * lists all available forums. * * http://forum.mageia.org/{language}/ * either is the forum, or redirects to the forum URL (if this forum is * handled outside of mageia.org domain). * * All Mageia links to forums are supposed to be one of those 3 above. * * TODO have a single list to manage existing forums and outside forums to redirect to. * Currently, we have a list in phpbb, a Apache redirection set of rules and this file. * * TODO each forum should host a top list of all other official forums for users to switch to * if they want (and, referring at the same map of forums, please!) * * PHP version 5 * * @category Mageia_Web_Sites * @package Forums.mageia.org * @author Romain d'Alverny <rda@mageia.org> * @copyright 2011 Romain d'Alverny * @license GPL-2 * */ /** * @var $forumsMap */ $forumsMap = array( 'de' => 'Deutsch', 'el' => 'Îλληνικά', 'en' => 'English', 'es' => 'Español', 'fr' => 'Français', 'it' => 'Italiano', 'zh-cn' => 'ç®ä½ä¸æ', 'pt-br' => 'Português do Brasil', 'tr' => 'Türkçe', // 'cs' => 'ÄeÅ¡tina', // 'et' => 'Eesti', // 'fi' => 'Suomeksi', // 'lv' => 'LatvieÅ¡u', // 'nb' => 'BokmÃ¥l', // 'nl' => 'Nederlands', // 'pl' => 'Polski', // 'pt' => 'Português', // 'ro' => 'RomânÄ', // 'ru' => 'Ð ÑÑÑкий', // 'sl' => 'SlovenÅ¡Äina', // 'uk' => 'ÑкÑаÑÌнÑÑка моÌва', // 'zh-tw' => 'æ£é«ä¸æ' ); if (isset($_GET['langs'])) { die(show_langs($forumsMap)); } if ($_SERVER['REQUEST_URI'] === '/') { $locale = new ChooseLocale(array_keys($forumsMap)); $locale->setDefaultLocale('en'); header(sprintf('Location: /%s/%s', $locale->getCompatibleLocale(), $page )); die; } /** */ function show_langs($langs) { header('Content-Type: text/html; charset=utf-8'); $count = count($langs); $s = <<<S <!DOCTYPE html> <html lang="en"> <head> <charset="utf-8"> <meta name="robots" content="noindex,nosnippet"> <title>Mageia Forums</title> </head> <body> <p>Mageia Forums are currently available in {$count} languages:</p> <ul> S; foreach ($langs as $k => $v) { $s .= sprintf('<li><a href="/%s/" hreflang="%s">%s</a></li>', $k, $k, $v); } echo $s, '</ul><hr /></body></html>'; } /* ChooseLocale * * Licence: MPL 2/GPL 2.0/LGPL 2.1 * Author: Pascal Chevrel, Mozilla * Date : 2010-07-17 * * Description: * Class to choose the locale which locale we will show to the visitor * based on http acceptlang headers and our list of supported locales. * * */ class ChooseLocale { public $HTTPAcceptLang; public $supportedLocales; protected $detectedLocale; protected $defaultLocale; public $mapLonglocales; public function __construct($list=array('en-US')) { $this -> HTTPAcceptLang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; $this -> supportedLocales = array_unique($list); $this -> setDefaultLocale('en-US'); $this -> setCompatibleLocale(); $this -> mapLonglocales = true; } public function getAcceptLangArray() { if (empty($this->HTTPAcceptLang)) return null; return explode(',', $this->HTTPAcceptLang); } public function getCompatibleLocale() { $l = $this -> defaultLocale; $acclang = $this -> getAcceptLangArray(); if(!is_array($acclang)) { return $this -> defaultLocale; } foreach ($acclang as $var) { $locale = $this -> _cleanHTTPlocaleCode($var); $shortLocale = array_shift(explode('-', $locale)); if (in_array($locale, $this -> supportedLocales)) { $l = $locale; break; } if (in_array($shortLocale, $this -> supportedLocales)) { $l = $shortLocale; break; } // check if we map visitors short locales to site long locales // like en -> en-GB if ($this -> mapLonglocales == true) { foreach ($this -> supportedLocales as $var) { $shortSupportedLocale = array_shift(explode('-', $var)); if ($shortLocale == $shortSupportedLocale) { $l = $var; break; } } } } return $l; } public function getDefaultLocale() { return $this -> defaultLocale; } public function setCompatibleLocale() { $this -> detectedLocale = $this -> getCompatibleLocale(); } public function setDefaultLocale($locale) { // the default locale should always be among the site locales // if not, the first locale in the supportedLocales array is default if (!in_array($locale, $this -> supportedLocales)) { $this -> defaultLocale = $this -> supportedLocales[0]; } else { $this -> defaultLocale = $locale; } return; } private function _cleanHTTPlocaleCode($str) { $locale = explode(';', $str); $locale = trim($locale[0]); return $locale; } }
View Attachment As Raw
Actions:
View
Attachments on
bug 860
:
503
| 557