2006-12-02 04:36:16 +00:00
|
|
|
|
<?php
|
|
|
|
|
/*
|
2010-10-26 07:41:20 +00:00
|
|
|
|
* e107 website system
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2008-2010 e107 Inc (e107.org)
|
|
|
|
|
* Released under the terms and conditions of the
|
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
|
|
|
|
*
|
|
|
|
|
* Language handler
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package e107
|
|
|
|
|
* @subpackage e107_handlers
|
|
|
|
|
* @version $Id$
|
|
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
|
|
class language{
|
|
|
|
|
|
2010-09-10 01:01:48 +00:00
|
|
|
|
// http://www.loc.gov/standards/iso639-2/php/code_list.php
|
|
|
|
|
|
|
|
|
|
// Valid Language Pack Names are shown directly below on the right.
|
2011-04-19 11:20:12 +00:00
|
|
|
|
public $detect = FALSE;
|
|
|
|
|
public $e_language = 'English'; // replaced later with $pref
|
|
|
|
|
public $_cookie_domain = '';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cached list of Installed Language Packs
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $lanlist = null; // null is important!!!
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
2011-04-19 11:20:12 +00:00
|
|
|
|
protected $list = array(
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"aa" => "Afar",
|
2007-01-01 15:31:54 +00:00
|
|
|
|
"ab" => "Abkhazian",
|
|
|
|
|
"af" => "Afrikaans",
|
|
|
|
|
"am" => "Amharic",
|
|
|
|
|
"ar" => "Arabic",
|
|
|
|
|
"as" => "Assamese",
|
|
|
|
|
"ae" => "Avestan",
|
|
|
|
|
"ay" => "Aymara",
|
|
|
|
|
"az" => "Azerbaijani",
|
|
|
|
|
"ba" => "Bashkir",
|
|
|
|
|
"be" => "Belarusian",
|
|
|
|
|
"bn" => "Bengali",
|
|
|
|
|
"bh" => "Bihari",
|
|
|
|
|
"bi" => "Bislama",
|
|
|
|
|
"bo" => "Tibetan",
|
|
|
|
|
"bs" => "Bosnian",
|
|
|
|
|
"br" => "Breton",
|
|
|
|
|
"bg" => "Bulgarian",
|
|
|
|
|
"ca" => "Catalan",
|
|
|
|
|
"cs" => "Czech",
|
|
|
|
|
"ch" => "Chamorro",
|
|
|
|
|
"ce" => "Chechen",
|
|
|
|
|
"cn" => "ChineseSimp",
|
|
|
|
|
"cv" => "Chuvash",
|
|
|
|
|
"kw" => "Cornish",
|
|
|
|
|
"co" => "Corsican",
|
|
|
|
|
"cy" => "Welsh",
|
|
|
|
|
"da" => "Danish",
|
|
|
|
|
"de" => "German",
|
|
|
|
|
"dz" => "Dzongkha",
|
|
|
|
|
"el" => "Greek",
|
|
|
|
|
"en" => "English",
|
|
|
|
|
"eo" => "Esperanto",
|
|
|
|
|
"et" => "Estonian",
|
|
|
|
|
"eu" => "Basque",
|
|
|
|
|
"fo" => "Faroese",
|
|
|
|
|
"fa" => "Persian",
|
|
|
|
|
"fj" => "Fijian",
|
|
|
|
|
"fi" => "Finnish",
|
|
|
|
|
"fr" => "French",
|
|
|
|
|
"fy" => "Frisian",
|
|
|
|
|
"gd" => "Gaelic",
|
|
|
|
|
"ga" => "Irish",
|
|
|
|
|
"gl" => "Gallegan",
|
|
|
|
|
"gv" => "Manx",
|
|
|
|
|
"gn" => "Guarani",
|
|
|
|
|
"gu" => "Gujarati",
|
|
|
|
|
"ha" => "Hausa",
|
|
|
|
|
"he" => "Hebrew",
|
|
|
|
|
"hz" => "Herero",
|
|
|
|
|
"hi" => "Hindi",
|
|
|
|
|
"ho" => "Hiri Motu",
|
|
|
|
|
"hr" => "Croatian",
|
|
|
|
|
"hu" => "Hungarian",
|
|
|
|
|
"hy" => "Armenian",
|
|
|
|
|
"iu" => "Inuktitut",
|
|
|
|
|
"ie" => "Interlingue",
|
|
|
|
|
"id" => "Indonesian",
|
|
|
|
|
"ik" => "Inupiaq",
|
|
|
|
|
"is" => "Icelandic",
|
|
|
|
|
"it" => "Italian",
|
|
|
|
|
"jw" => "Javanese",
|
|
|
|
|
"ja" => "Japanese",
|
|
|
|
|
"kl" => "Kalaallisut",
|
|
|
|
|
"kn" => "Kannada",
|
|
|
|
|
"ks" => "Kashmiri",
|
|
|
|
|
"ka" => "Georgian",
|
|
|
|
|
"kk" => "Kazakh",
|
|
|
|
|
"km" => "Khmer",
|
|
|
|
|
"ki" => "Kikuyu",
|
|
|
|
|
"rw" => "Kinyarwanda",
|
|
|
|
|
"ky" => "Kirghiz",
|
|
|
|
|
"kv" => "Komi",
|
|
|
|
|
"ko" => "Korean",
|
|
|
|
|
"ku" => "Kurdish",
|
|
|
|
|
"lo" => "Lao",
|
|
|
|
|
"la" => "Latin",
|
|
|
|
|
"lv" => "Latvian",
|
|
|
|
|
"ln" => "Lingala",
|
|
|
|
|
"lt" => "Lithuanian",
|
|
|
|
|
"lb" => "Letzeburgesch",
|
|
|
|
|
"mh" => "Marshall",
|
|
|
|
|
"ml" => "Malayalam",
|
|
|
|
|
"mr" => "Marathi",
|
|
|
|
|
"mk" => "Macedonian",
|
|
|
|
|
"mg" => "Malagasy",
|
|
|
|
|
"mt" => "Maltese",
|
|
|
|
|
"mo" => "Moldavian",
|
|
|
|
|
"mn" => "Mongolian",
|
|
|
|
|
"mi" => "Maori",
|
|
|
|
|
"ms" => "Malay",
|
|
|
|
|
"my" => "Burmese",
|
|
|
|
|
"na" => "Nauru",
|
|
|
|
|
"nv" => "Navajo",
|
|
|
|
|
|
|
|
|
|
"ng" => "Ndonga",
|
|
|
|
|
"ne" => "Nepali",
|
|
|
|
|
"nl" => "Dutch",
|
2010-09-10 01:01:48 +00:00
|
|
|
|
"no" => "Norwegian",
|
2007-01-01 15:31:54 +00:00
|
|
|
|
|
|
|
|
|
"ny" => "Chichewa",
|
|
|
|
|
"or" => "Oriya",
|
|
|
|
|
"om" => "Oromo",
|
|
|
|
|
"pa" => "Panjabi",
|
|
|
|
|
"pi" => "Pali",
|
|
|
|
|
"pl" => "Polish",
|
|
|
|
|
"pt" => "Portuguese",
|
|
|
|
|
"ps" => "Pushto",
|
|
|
|
|
"qu" => "Quechua",
|
|
|
|
|
"ro" => "Romanian",
|
|
|
|
|
"rn" => "Rundi",
|
|
|
|
|
"ru" => "Russian",
|
|
|
|
|
"sg" => "Sango",
|
|
|
|
|
"sa" => "Sanskrit",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"si" => "Sinhala",
|
2007-01-01 15:31:54 +00:00
|
|
|
|
"sk" => "Slovak",
|
|
|
|
|
"sl" => "Slovenian",
|
|
|
|
|
|
|
|
|
|
"sm" => "Samoan",
|
|
|
|
|
"sn" => "Shona",
|
|
|
|
|
"sd" => "Sindhi",
|
|
|
|
|
"so" => "Somali",
|
|
|
|
|
|
|
|
|
|
"es" => "Spanish",
|
|
|
|
|
"sq" => "Albanian",
|
|
|
|
|
"sc" => "Sardinian",
|
|
|
|
|
"sr" => "Serbian",
|
|
|
|
|
"ss" => "Swati",
|
|
|
|
|
"su" => "Sundanese",
|
|
|
|
|
"sw" => "Swahili",
|
|
|
|
|
"sv" => "Swedish",
|
|
|
|
|
"ty" => "Tahitian",
|
|
|
|
|
"ta" => "Tamil",
|
|
|
|
|
"tt" => "Tatar",
|
|
|
|
|
"te" => "Telugu",
|
|
|
|
|
"tg" => "Tajik",
|
|
|
|
|
"tl" => "Tagalog",
|
|
|
|
|
"th" => "Thai",
|
|
|
|
|
"ti" => "Tigrinya",
|
|
|
|
|
|
|
|
|
|
"tn" => "Tswana",
|
|
|
|
|
"ts" => "Tsonga",
|
|
|
|
|
"tk" => "Turkmen",
|
|
|
|
|
"tr" => "Turkish",
|
|
|
|
|
"tw" => "ChineseTrad",
|
|
|
|
|
"ug" => "Uighur",
|
|
|
|
|
"uk" => "Ukrainian",
|
|
|
|
|
"ur" => "Urdu",
|
|
|
|
|
"uz" => "Uzbek",
|
|
|
|
|
"vi" => "Vietnamese",
|
|
|
|
|
|
|
|
|
|
"wo" => "Wolof",
|
|
|
|
|
"xh" => "Xhosa",
|
|
|
|
|
"yi" => "Yiddish",
|
|
|
|
|
"yo" => "Yoruba",
|
|
|
|
|
"za" => "Zhuang",
|
|
|
|
|
// "zh" => "Chinese",
|
|
|
|
|
"zu" => "Zulu"
|
|
|
|
|
);
|
|
|
|
|
|
2011-04-19 11:20:12 +00:00
|
|
|
|
protected $names = array(
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Arabic" => "العربية",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Bengali" => "বাংলা",
|
2006-12-10 12:47:23 +00:00
|
|
|
|
"Bosnian" => "Bosanski",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Bulgarian" => "Български",
|
|
|
|
|
"Croatian" => "Hrvatski",
|
2006-12-10 12:47:23 +00:00
|
|
|
|
"ChineseTrad" => "繁体中文",
|
|
|
|
|
"ChineseSimp" => "简体中文",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Czech" => "Čeština",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Dutch" => "Nederlands",
|
|
|
|
|
"English" => "English",
|
2011-02-26 19:58:28 +00:00
|
|
|
|
"Estonian" => "Eesti",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"French" => "Français",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Finnish" => "Suomi",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"German" => "Deutsch",
|
|
|
|
|
"Greek" => "Ελληνικά",
|
|
|
|
|
"Hebrew" => "עִבְרִית",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Hindi" => "हिन्दी",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Hungarian" => "Magyar",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Icelandic" => "íslenska",
|
2011-02-26 19:58:28 +00:00
|
|
|
|
"Indonesian" => "Bahasa Indonesia",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Italian" => "Italiano",
|
|
|
|
|
"Japanese" => "日本語",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Khmer" => "ខ្មែរ",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Korean" => "한국어",
|
2006-12-10 12:47:23 +00:00
|
|
|
|
"Lithuanian" => "Lietuvių",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Mongolian" => "Монгол",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Nepali" => "नेपाली",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Norwegian" => "Norsk",
|
2006-12-10 12:47:23 +00:00
|
|
|
|
"Persian" => "فارسي",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Portuguese" => "Português",
|
|
|
|
|
"Polish" => "Polski",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Romanian" => "Română",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Russian" => "Pусский",
|
2013-07-10 02:29:05 -07:00
|
|
|
|
"Serbian" => "Српски",
|
|
|
|
|
"Sinhala" => "සිංහල",
|
2006-12-02 04:36:16 +00:00
|
|
|
|
"Spanish" => "Español",
|
|
|
|
|
"Slovenian" => "Slovensko",
|
|
|
|
|
"Slovakian" => "Slovensky",
|
|
|
|
|
"Slovak" => "Slovensky",
|
|
|
|
|
"Swedish" => "Svenska",
|
2007-01-01 15:31:54 +00:00
|
|
|
|
"Thai" => "ภาษาไทย",
|
2011-02-26 19:58:28 +00:00
|
|
|
|
"Turkish" => "Türkçe",
|
|
|
|
|
"Vietnamese" => "Tiếng Việt"
|
2006-12-02 04:36:16 +00:00
|
|
|
|
);
|
|
|
|
|
|
2010-09-10 01:01:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* Converts iso to language-name and visa-versa.
|
|
|
|
|
* @param object $data
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2007-01-01 15:31:54 +00:00
|
|
|
|
function convert($data){
|
|
|
|
|
|
|
|
|
|
if(strlen($data) > 2)
|
|
|
|
|
{
|
|
|
|
|
$tmp = array_flip($this->list);
|
2010-09-10 01:01:48 +00:00
|
|
|
|
return isset($tmp[$data]) ? $tmp[$data] : FALSE;
|
2007-01-01 15:31:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-09-10 01:01:48 +00:00
|
|
|
|
return (isset($this->list[$data])) ? $this->list[$data] : FALSE;
|
2007-01-01 15:31:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2010-09-10 01:01:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* Check if a Language is installed and valid
|
|
|
|
|
* @param object $lang - Language to check. eg. 'es' or 'Spanish'
|
|
|
|
|
* @return FALSE or the name of the valid Language
|
|
|
|
|
*/
|
|
|
|
|
function isValid($lang='')
|
2015-06-06 02:33:23 -07:00
|
|
|
|
{
|
|
|
|
|
if(empty($lang))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-10 01:01:48 +00:00
|
|
|
|
global $pref;
|
|
|
|
|
|
|
|
|
|
if(!$lang)
|
|
|
|
|
{
|
2013-07-17 03:01:46 -07:00
|
|
|
|
return (ADMIN_AREA && vartrue($pref['adminlanguage'])) ? $pref['adminlanguage'] : $pref['sitelanguage'];
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(strpos($lang,"debug")!==FALSE)
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(strlen($lang)== 2)
|
|
|
|
|
{
|
|
|
|
|
$iso = $lang;
|
|
|
|
|
$lang = $this->convert($lang);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$iso = $this->convert($lang);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($iso==FALSE || $lang==FALSE)
|
|
|
|
|
{
|
|
|
|
|
$diz = ($lang) ? $lang : $iso;
|
|
|
|
|
trigger_error("The selected language (".$diz.") is invalid. See e107_handlers/language_class.php for a list of valid languages. ", E_USER_ERROR);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(is_readable(e_LANGUAGEDIR.$lang.'/'.$lang.'.php'))
|
|
|
|
|
{
|
|
|
|
|
return $lang;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
trigger_error("The selected language (".$lang.") was not found.", E_USER_ERROR);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the specified domain has multi-language subdomains enabled.
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
function isLangDomain($domain='')
|
|
|
|
|
{
|
|
|
|
|
if(!$domain)
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
global $pref;
|
|
|
|
|
$mtmp = explode("\n", $pref['multilanguage_subdomain']);
|
|
|
|
|
foreach($mtmp as $val)
|
|
|
|
|
{
|
|
|
|
|
if($domain == trim($val))
|
|
|
|
|
{
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
}
|
2013-03-08 04:46:02 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generic variable translator for LAN definitions.
|
|
|
|
|
* @example $lng->translate("My name is [x] and I own a [y]", array('x'=>"John", 'y'=>"Cat"));
|
2013-10-29 12:20:23 -07:00
|
|
|
|
* @deprecated Use $tp->lanVars() instead.
|
2013-03-08 04:46:02 -08:00
|
|
|
|
*/
|
|
|
|
|
function translate($lan, $array= array())
|
|
|
|
|
{
|
|
|
|
|
foreach($array as $k=>$v)
|
|
|
|
|
{
|
|
|
|
|
$search[] = "[".$k."]";
|
|
|
|
|
$replace[] = "<b>".$v."</b>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str_replace($search, $replace, $lan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
2010-09-10 01:01:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return a list of Installed Language Packs
|
2011-04-19 11:20:12 +00:00
|
|
|
|
*
|
2010-09-10 01:01:48 +00:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function installed()
|
|
|
|
|
{
|
2011-04-19 11:20:12 +00:00
|
|
|
|
if(null == $this->lanlist)
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
2012-11-29 23:12:20 -08:00
|
|
|
|
$fl = e107::getFile();
|
|
|
|
|
$dirArray = $fl->get_dirs(e_LANGUAGEDIR);
|
|
|
|
|
// $handle = opendir(e_LANGUAGEDIR);
|
2011-04-19 11:20:12 +00:00
|
|
|
|
$lanlist = array();
|
2012-11-29 23:12:20 -08:00
|
|
|
|
// while ($file = readdir($handle))
|
|
|
|
|
foreach($dirArray as $file)
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
2011-04-19 11:20:12 +00:00
|
|
|
|
if ($file != '.' && $file != '..' && is_readable(e_LANGUAGEDIR.$file.'/'.$file.'.php'))
|
|
|
|
|
{
|
|
|
|
|
$lanlist[] = $file;
|
|
|
|
|
}
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
2012-11-29 23:12:20 -08:00
|
|
|
|
// closedir($handle);
|
2011-04-19 11:20:12 +00:00
|
|
|
|
|
|
|
|
|
$this->lanlist = array_intersect($lanlist,$this->list);
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-19 11:20:12 +00:00
|
|
|
|
return $this->lanlist;
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a Language to its Native title. eg. 'Spanish' becomes 'Español'
|
|
|
|
|
* @param string $lang
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-01-01 15:31:54 +00:00
|
|
|
|
function toNative($lang)
|
|
|
|
|
{
|
|
|
|
|
return ($this->names[$lang]) ? $this->names[$lang] : $lang;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-10 01:01:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* Convert the current URL to a multi-lang for the specified language.
|
|
|
|
|
* eg. 'http://www.mydomain.com' becomes 'http://es.mydomain.com'
|
|
|
|
|
* @param string $language eg. 'Spanish'
|
|
|
|
|
* @return URL
|
|
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
|
function subdomainUrl($language)
|
|
|
|
|
{
|
|
|
|
|
global $pref;
|
|
|
|
|
$codelnk = ($language == $pref['sitelanguage']) ? "www" : $this->convert($language);
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
2014-06-02 00:42:41 -07:00
|
|
|
|
if($codelnk == '')
|
|
|
|
|
{
|
|
|
|
|
$codelnk = 'www';
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-10 01:01:48 +00:00
|
|
|
|
// $urlval = str_replace($_SERVER['HTTP_HOST'],$codelnk.".".e_DOMAIN,e_SELF);
|
|
|
|
|
|
|
|
|
|
$urlval = (e_QUERY)
|
|
|
|
|
? str_replace($_SERVER['HTTP_HOST'], $codelnk.'.'.e_DOMAIN, e_SELF).'?'.e_QUERY
|
|
|
|
|
: str_replace($_SERVER['HTTP_HOST'], $codelnk.'.'.e_DOMAIN, e_SELF);
|
|
|
|
|
|
2015-02-15 02:37:36 -08:00
|
|
|
|
return (string) $urlval;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Detect a Language Change
|
|
|
|
|
* 1. Parked (sub)Domain eg. http://es.mydomain.com (Preferred for SEO)
|
|
|
|
|
* 2. e_MENU Query eg. /index.php?[es]
|
|
|
|
|
* 3. $_GET['elan'] eg. /index.php?elan=es
|
|
|
|
|
* 4. $_POST['sitelanguage'] eg. <input type='hidden' name='sitelanguage' value='Spanish' />
|
|
|
|
|
* 5. $GLOBALS['elan'] eg. <?php $GLOBALS['elan']='es' (deprecated)
|
2010-10-26 07:41:20 +00:00
|
|
|
|
*
|
|
|
|
|
* @param boolean $force force detection, don't use cached value
|
2010-09-10 01:01:48 +00:00
|
|
|
|
*/
|
2010-10-26 07:41:20 +00:00
|
|
|
|
function detect($force = false)
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
|
|
|
|
global $pref;
|
2010-10-26 07:41:20 +00:00
|
|
|
|
|
|
|
|
|
|
2011-04-19 11:20:12 +00:00
|
|
|
|
if(false !== $this->detect && !$force) return $this->detect;
|
2010-10-27 11:31:18 +00:00
|
|
|
|
$this->_cookie_domain = '';
|
2015-02-14 23:34:15 -08:00
|
|
|
|
if(vartrue($pref['multilanguage_subdomain']) && $this->isLangDomain(e_DOMAIN) && (defset('MULTILANG_SUBDOMAIN') !== FALSE))
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
|
|
|
|
$detect_language = (e_SUBDOMAIN) ? $this->isValid(e_SUBDOMAIN) : $pref['sitelanguage'];
|
2010-10-26 07:41:20 +00:00
|
|
|
|
// Done in session handler now, based on MULTILANG_SUBDOMAIN value
|
|
|
|
|
//e107_ini_set("session.cookie_domain", ".".e_DOMAIN); // Must be before session_start()
|
2010-10-27 11:31:18 +00:00
|
|
|
|
$this->_cookie_domain = ".".e_DOMAIN;
|
2010-09-10 01:01:48 +00:00
|
|
|
|
define('MULTILANG_SUBDOMAIN',TRUE);
|
|
|
|
|
}
|
|
|
|
|
elseif(e_MENU && ($detect_language = $this->isValid(e_MENU))) //
|
|
|
|
|
{
|
|
|
|
|
define("e_LANCODE",TRUE);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
elseif(isset($_GET['elan']) && ($detect_language = $this->isValid($_GET['elan']))) // eg: /index.php?elan=Spanish
|
|
|
|
|
{
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
elseif(isset($_POST['setlanguage']) && ($detect_language = $this->isValid($_POST['sitelanguage'])))
|
|
|
|
|
{
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elseif(isset($GLOBALS['elan']) && ($detect_language = $this->isValid($GLOBALS['elan'])))
|
|
|
|
|
{
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$detect_language = FALSE; // ie. No Change.
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-26 07:41:20 +00:00
|
|
|
|
// Done in session handler now
|
|
|
|
|
// e107_ini_set("session.cookie_path", e_HTTP);
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
|
|
|
|
$this->detect = $detect_language;
|
|
|
|
|
return $detect_language;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-27 11:31:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get domain to be used in cookeis (e.g. .domain.com), or empty
|
|
|
|
|
* if multi-language subdomain settings not enabled
|
|
|
|
|
* Available after self::detect()
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getCookieDomain()
|
|
|
|
|
{
|
|
|
|
|
return $this->_cookie_domain;
|
|
|
|
|
}
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the Language (Constants, $_SESSION and $_COOKIE) for the current page.
|
2010-11-21 09:08:18 +00:00
|
|
|
|
* @param string $language force set
|
|
|
|
|
* @return void
|
2010-09-10 01:01:48 +00:00
|
|
|
|
*/
|
2010-11-21 09:08:18 +00:00
|
|
|
|
function set($language = null)
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
2010-10-26 07:41:20 +00:00
|
|
|
|
$pref = e107::getPref();
|
|
|
|
|
$session = e107::getSession(); // default core session namespace
|
2010-11-21 09:08:18 +00:00
|
|
|
|
if($language && ($language = $this->isValid($language))) // force set
|
|
|
|
|
{
|
|
|
|
|
$this->detect = $language;
|
|
|
|
|
}
|
2010-09-10 01:01:48 +00:00
|
|
|
|
if($this->detect) // Language-Change Trigger Detected.
|
|
|
|
|
{
|
2010-10-26 07:41:20 +00:00
|
|
|
|
// new - e_language moved to e107 namespace - $_SESSION['e107']['e_language']
|
2013-01-29 16:00:30 +02:00
|
|
|
|
$oldlan = $session->get('e_language');
|
2013-11-11 03:23:07 -08:00
|
|
|
|
|
|
|
|
|
if(!$session->has('e_language') || (($session->get('e_language') != $this->detect) && $this->isValid($this->detect)))
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
2010-10-26 07:41:20 +00:00
|
|
|
|
$session->set('e_language', $this->detect);
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(varset($_COOKIE['e107_language'])!=$this->detect && (defset('MULTILANG_SUBDOMAIN') != TRUE))
|
|
|
|
|
{
|
|
|
|
|
setcookie('e107_language', $this->detect, time() + 86400, e_HTTP);
|
|
|
|
|
$_COOKIE['e107_language'] = $this->detect; // Used only when a user returns to the site. Not used during this session.
|
|
|
|
|
}
|
|
|
|
|
else // Multi-lang SubDomains should ignore cookies and remove old ones if they exist.
|
|
|
|
|
{
|
|
|
|
|
if(isset($_COOKIE['e107_language']))
|
|
|
|
|
{
|
|
|
|
|
unset($_COOKIE['e107_language']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$user_language = $this->detect;
|
2013-01-29 16:00:30 +02:00
|
|
|
|
|
|
|
|
|
// new system trigger 'lanset'
|
|
|
|
|
if($oldlan && $oldlan !== $this->detect)
|
|
|
|
|
{
|
|
|
|
|
e107::getEvent()->trigger('lanset', array('new' => $this->detect, 'old' => $oldlan));
|
|
|
|
|
}
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
else // No Language-change Trigger Detected.
|
2013-11-11 03:23:07 -08:00
|
|
|
|
{
|
|
|
|
|
|
2010-10-26 07:41:20 +00:00
|
|
|
|
if($session->has('e_language'))
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
2010-10-26 07:41:20 +00:00
|
|
|
|
$user_language = $session->get('e_language');
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
elseif(isset($_COOKIE['e107_language']) && ($user_language = $this->isValid($_COOKIE['e107_language'])))
|
|
|
|
|
{
|
2010-10-26 07:41:20 +00:00
|
|
|
|
$session->set('e_language', $user_language);
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2013-07-17 03:01:46 -07:00
|
|
|
|
{
|
2014-02-07 17:57:55 -08:00
|
|
|
|
|
|
|
|
|
$user_language = $pref['sitelanguage'];
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
2010-10-26 07:41:20 +00:00
|
|
|
|
if($session->is('e_language'))
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
2010-10-26 07:41:20 +00:00
|
|
|
|
$session->clear('e_language');
|
2010-09-10 01:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(isset($_COOKIE['e107_language']))
|
|
|
|
|
{
|
|
|
|
|
unset($_COOKIE['e107_language']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->e_language = $user_language;
|
|
|
|
|
$this->setDefs();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set Language-specific Constants
|
2011-04-19 11:20:12 +00:00
|
|
|
|
* FIXME - language detection is a mess - db handler, mysql handler, session handler and language handler + constants invlolved,
|
|
|
|
|
* SIMPLIFY, test, get feedback
|
2010-09-10 01:01:48 +00:00
|
|
|
|
* @param string $language
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
function setDefs()
|
|
|
|
|
{
|
|
|
|
|
global $pref;
|
|
|
|
|
|
|
|
|
|
$language = $this->e_language;
|
2011-04-19 11:20:12 +00:00
|
|
|
|
//$session = e107::getSession();
|
|
|
|
|
|
|
|
|
|
// SecretR - don't register lanlist in session, confusions, save it as class property (lan class is singleton)
|
|
|
|
|
e107::getSession()->set('language-list', null); // cleanup test installs, will be removed soon
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
2011-04-19 11:20:12 +00:00
|
|
|
|
/*if(!$session->is('language-list'))
|
2010-09-10 01:01:48 +00:00
|
|
|
|
{
|
2010-10-26 07:41:20 +00:00
|
|
|
|
$session->set('language-list', implode(',',$this->installed()));
|
2011-04-19 11:20:12 +00:00
|
|
|
|
}*/
|
2010-09-10 01:01:48 +00:00
|
|
|
|
|
2011-04-19 11:20:12 +00:00
|
|
|
|
//define('e_LANLIST', $session->get('language-list'));
|
|
|
|
|
define('e_LANLIST', implode(',', $this->installed()));
|
2010-09-10 01:01:48 +00:00
|
|
|
|
define('e_LANGUAGE', $language);
|
|
|
|
|
define('USERLAN', $language); // Keep USERLAN for backward compatibility
|
|
|
|
|
$iso = $this->convert($language);
|
|
|
|
|
define("e_LAN", $iso);
|
|
|
|
|
|
|
|
|
|
// Below is for BC
|
|
|
|
|
if(defined('e_LANCODE') && varset($pref['multilanguage']) && ($language != $pref['sitelanguage']))
|
|
|
|
|
{
|
|
|
|
|
define("e_LANQRY", "[".$iso."]");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
define("e_LANCODE", '');
|
|
|
|
|
define("e_LANQRY", FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-08 09:20:12 +00:00
|
|
|
|
public function getLanSelectArray($force = false)
|
|
|
|
|
{
|
|
|
|
|
if($force ||null === $this->_select_array)
|
|
|
|
|
{
|
|
|
|
|
$lanlist = explode(',', e_LANLIST);
|
|
|
|
|
$this->_select_array = array();
|
|
|
|
|
foreach ($lanlist as $lan)
|
|
|
|
|
{
|
|
|
|
|
$this->_select_array[$this->convert($lan)] = $this->toNative($lan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $this->_select_array;
|
|
|
|
|
}
|
2014-11-13 19:37:37 -08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return an array of all language types.
|
|
|
|
|
*/
|
|
|
|
|
public function getList()
|
|
|
|
|
{
|
|
|
|
|
return $this->list;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|