diff options
author | Michael Meer <michael@meer.name> | 2014-01-28 09:49:09 +0100 |
---|---|---|
committer | Michael Meer <michael@meer.name> | 2014-01-28 09:49:09 +0100 |
commit | 8ddee71c2b0f384470965dd46a2e594a4f98f8e0 (patch) | |
tree | 84bcf6e0f94365b186b4613b43d7a72f5f22f525 /library/ajaxchat/chat/lib/class/AJAXChatLanguage.php | |
parent | 904db593df914d2932d9c2f018b00987052461d7 (diff) | |
parent | f104b4dc275891785ec03abd779d8aafe5163815 (diff) | |
download | volse-hubzilla-8ddee71c2b0f384470965dd46a2e594a4f98f8e0.tar.gz volse-hubzilla-8ddee71c2b0f384470965dd46a2e594a4f98f8e0.tar.bz2 volse-hubzilla-8ddee71c2b0f384470965dd46a2e594a4f98f8e0.zip |
Merge branch 'master' of https://github.com/friendica/red
to be in sync with main repro
Diffstat (limited to 'library/ajaxchat/chat/lib/class/AJAXChatLanguage.php')
-rw-r--r-- | library/ajaxchat/chat/lib/class/AJAXChatLanguage.php | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/library/ajaxchat/chat/lib/class/AJAXChatLanguage.php b/library/ajaxchat/chat/lib/class/AJAXChatLanguage.php deleted file mode 100644 index b19724710..000000000 --- a/library/ajaxchat/chat/lib/class/AJAXChatLanguage.php +++ /dev/null @@ -1,102 +0,0 @@ -<?php -/* - * @package AJAX_Chat - * @author Sebastian Tschan - * @copyright (c) Sebastian Tschan - * @license Modified MIT License - * @link https://blueimp.net/ajax/ - */ - -class AJAXChatLanguage { - - var $_regExpAcceptLangCode; - var $_availableLangCodes; - var $_defaultLangCode; - var $_strictMode; - var $_langCode; - - function __construct($availableLangCodes, $defaultLangCode, $langCode=null, $strictMode=false) { - $this->_regExpAcceptLangCode = '/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i'; - $this->_availableLangCodes = $availableLangCodes; - $this->_defaultLangCode = $defaultLangCode; - if($langCode && in_array($langCode, $availableLangCodes)) { - $this->_langCode = $langCode; - } - $this->_strictMode = $strictMode; - } - - // Method to detect the language code from the HTTP_ACCEPT_LANGUAGE header: - function detectLangCode() { - // If HTTP_ACCEPT_LANGUAGE is empty use defaultLangCode: - if(empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - $this->_langCode = $this->_defaultLangCode; - return; - } - - // Split up the HTTP_ACCEPT_LANGUAGE header: - $acceptedLanguages = preg_split('/,\s*/', $_SERVER['HTTP_ACCEPT_LANGUAGE']); - - $currentLangCode = $this->_defaultLangCode; - $currentLangQuality = 0.0; - - foreach($acceptedLanguages as $acceptedLanguage) { - // Parse the language string: - $match = preg_match($this->_regExpAcceptLangCode, $acceptedLanguage, $matches); - // Check if the syntax is valid: - if(!$match) { - continue; - } - - // Get and split the language code: - $langCodeParts = explode ('-', $matches[1]); - - // Get the language quality given as float value: - if(isset($matches[2])) { - $langQuality = (float)$matches[2]; - } else { - // Missing language quality value is maximum quality: - $langQuality = 1.0; - } - - // Go through it until the language code is empty: - while(count($langCodeParts)) { - // Join the current langCodeParts: - $langCode = strtolower(join('-', $langCodeParts)); - // Check if the langCode is in the available list: - if(in_array($langCode, $this->_availableLangCodes)) { - // Check the quality setting: - if ($langQuality > $currentLangQuality) { - $currentLangCode = $langCode; - $currentLangQuality = $langQuality; - break; - } - } - // If strict mode is set, don't minimalize the language code: - if($this->_strictMode) { - break; - } - // else chop off the right part: - array_pop($langCodeParts); - } - } - - $this->_langCode = $currentLangCode; - } - - function getLangCode() { - if(!$this->_langCode) { - $this->detectLangCode(); - } - return $this->_langCode; - } - - function setLangCode($langCode) { - $this->_langCode = $langCode; - } - - function getLangCodes() { - return $this->_availableLangCodes; - } - -} -?>
\ No newline at end of file |