Example #1
0
 /**
  * Sets the current language for phpMyFAQ user session
  *
  * @param bool   $configDetection Configuration detection
  * @param string $configLanguage  Language from configuration
  *
  * @return  string
  */
 public function setLanguage($configDetection, $configLanguage)
 {
     $_lang = [];
     self::_getUserAgentLanguage();
     // Get language from: _POST, _GET, _COOKIE, phpMyFAQ configuration and the automatic language detection
     $_lang['post'] = PMF_Filter::filterInput(INPUT_POST, 'language', FILTER_SANITIZE_STRING);
     if (!is_null($_lang['post']) && !self::isASupportedLanguage($_lang['post'])) {
         $_lang['post'] = null;
     }
     // Get the user language
     $_lang['get'] = PMF_Filter::filterInput(INPUT_GET, 'lang', FILTER_SANITIZE_STRING);
     if (!is_null($_lang['get']) && !self::isASupportedLanguage($_lang['get'])) {
         $_lang['get'] = null;
     }
     // Get the faq record language
     $_lang['artget'] = PMF_Filter::filterInput(INPUT_GET, 'artlang', FILTER_SANITIZE_STRING);
     if (!is_null($_lang['artget']) && !self::isASupportedLanguage($_lang['artget'])) {
         $_lang['artget'] = null;
     }
     // Get the language from the session
     if (isset($_SESSION['pmf_lang']) && self::isASupportedLanguage($_SESSION['pmf_lang'])) {
         $_lang['session'] = trim($_SESSION['pmf_lang']);
     }
     // Get the language from the config
     if (isset($configLanguage)) {
         $confLangCode = str_replace(array("language_", ".php"), "", $configLanguage);
         if (self::isASupportedLanguage($confLangCode)) {
             $_lang['config'] = $confLangCode;
         }
     }
     // Detect the browser's language
     if (true === $configDetection && self::isASupportedLanguage($this->acceptedLanguage)) {
         $_lang['detection'] = strtolower($this->acceptedLanguage);
     }
     // Select the language
     if (isset($_lang['post'])) {
         self::$language = $_lang['post'];
         $_lang = null;
         unset($_lang);
     } elseif (isset($_lang['get'])) {
         self::$language = $_lang['get'];
     } elseif (isset($_lang['session'])) {
         self::$language = $_lang['session'];
         $_lang = null;
         unset($_lang);
     } elseif (isset($_lang['detection'])) {
         self::$language = $_lang['detection'];
         $_lang = null;
         unset($_lang);
     } elseif (isset($_lang['config'])) {
         self::$language = $_lang['config'];
         $_lang = null;
         unset($_lang);
     } else {
         self::$language = 'en';
         // just a fallback
     }
     return $_SESSION['pmf_lang'] = self::$language;
 }