Example #1
0
 public function create($link = '', $lang = '')
 {
     $hideDefaultLanguage = Config::get('options/hide_default_language') ? true : false;
     if (!$link) {
         $url = $this->clean('http://' . $this->_domin . $_SERVER['PHP_SELF']);
         //$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
         if ($hideDefaultLanguage && $lang == defualtLang()) {
             return $url;
         }
         if ($this->_query) {
             return $url . '&lang=' . $lang;
         }
         return $url . '?lang=' . $lang;
     }
     if ($this->validUrl($link)) {
         if (!$lang) {
             $lang = currentLang();
         }
         $link = $this->clean($link);
         if ($hideDefaultLanguage && $lang == defualtLang()) {
             return $link;
         }
         if ($this->_query) {
             return $link . '&lang=' . $lang;
         }
         return $link . '?lang=' . $lang;
     }
     return $link . '?lang=' . $lang;
     //return false;
 }
Example #2
0
 /**
  * Detect::country()
  * detect country language for visitor
  * @return string code language (2 digits)
  */
 public static function country()
 {
     /**
      * @var number $ip this ip for visitor
      */
     $ip = self::getIp();
     // if cant't detect visitor ip then language is defualt language in website
     if ($ip == 'UNKNOWN') {
         return defualtLang();
     } elseif ($ip == '::1') {
         return 'localhost';
     }
     // get country local code (ex: US for USA, JO for Jordan, UK for United Kingdom .. etc)
     if ($countryCode = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip))) {
         $countryCode = $countryCode['geoplugin_countryCode'];
         /*
          * @var  string $countryLangCode convert country local code to country laguage ISO code
          *  get the language from detected country (US = en, UK = en, JO = ar .. etc)
          */
         $countryLangCode = self::getCountryLang($countryCode);
         /*
          * @var array $enabledLanguages all the enabled languages
          */
         $enabledLanguages = enabledLanguagesList();
         // check if visitor vountry language is enable in website ro not
         // if enabled return it
         if (in_array($countryLangCode, $enabledLanguages)) {
             return $countryLangCode;
         }
     }
     // if not return country language code return defualt language
     return defualtLang();
 }
Example #3
0
/**
 * currentLang()
 * get curren language 
 * @return string
 */
function currentLang()
{
    //return isset($_GET['lang']) ? htmlentities($_GET['lang']) : defualtLang();
    if (isset($_GET['lang'])) {
        $currentLang = htmlentities(strtolower($_GET['lang']));
        if (avaliableLanguage($currentLang)) {
            return $currentLang;
        }
    }
    return defualtLang();
}
Example #4
0
 /**
  * DBContent::__construct()
  * initialize variables values
  * @return void
  */
 public function __construct()
 {
     // get languages json files path
     $this->_langFile = Config::get('paths/lang_files');
     // check if file language exist
     if ($this->getLangFile(currentLang())) {
         // set the language = current language
         $this->_theLang = currentLang();
     } else {
         // set defulat language
         $this->_theLang = defualtLang();
     }
     // open language .json file
     $this->getCurrentLanguageFile();
 }
Example #5
0
 /**
  * 
  * @param stirng $link
  * @param stribg $lang
  * @return string
  */
 public function create($link = '', $lang = '')
 {
     // check if hide_default_language option is enabled
     $hideDefaultLanguage = Config::get('options/hide_default_language') ? true : false;
     // check if $link is empty
     if (!$link) {
         // create link (current page)
         $url = $this->clean('http://' . $this->_domin . $_SERVER['PHP_SELF']);
         //$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
         // if hide_default_language option is enabled and $lang is defualte language return same link
         if ($hideDefaultLanguage && $lang == defualtLang()) {
             return $url;
         }
         // check if url have query string
         if ($this->_query) {
             return $url . '&lang=' . $lang;
         }
         return $url . '?lang=' . $lang;
     }
     // check if $link is a valide URL
     if ($this->validUrl($link)) {
         // if $lang is emty set it current language
         if (!$lang) {
             $lang = currentLang();
         }
         // clean link
         $link = $this->clean($link);
         // if $hideDefaultLanguage is true and $lang is default language return same link
         if ($hideDefaultLanguage && $lang == defualtLang()) {
             return $link;
         }
         // if $_query is true
         if ($this->_query) {
             return $link . '&lang=' . $lang;
         }
         return $link . '?lang=' . $lang;
     }
     return $link . '?lang=' . $lang;
     //return false;
 }