예제 #1
0
 public function parseUrl($request)
 {
     if (issetModule('seo') && $this->parseReady === false && oreInstall::isInstalled()) {
         if (preg_match('#^([\\w-]+)#i', $request->pathInfo, $matches)) {
             $activeLangs = Lang::getActiveLangs();
             $arr = array();
             foreach ($activeLangs as $lang) {
                 $arr[] = 'url_' . $lang . ' = :alias';
             }
             $condition = '(' . implode(' OR ', $arr) . ')';
             $seo = SeoFriendlyUrl::model()->find(array('condition' => 'direct_url = 1 AND ' . $condition, 'params' => array('alias' => $matches[1])));
             if ($seo !== null) {
                 foreach ($activeLangs as $lang) {
                     $field = 'url_' . $lang;
                     if ($seo->{$field} == $matches[1]) {
                         setLangCookie($lang);
                         Yii::app()->setLanguage($lang);
                         //$_GET['lang'] = $lang;
                     }
                 }
                 $_GET['url'] = $matches[1];
                 //$_GET['id'] = $seo->model_id;
                 //Yii::app()->controller->seo = $seo;
                 return 'infopages/main/view';
             }
         }
         $this->parseReady = true;
     }
     return parent::parseUrl($request);
 }
예제 #2
0
파일: common.php 프로젝트: barricade86/raui
function setLang($lang = null)
{
    if (isFree()) {
        return;
    }
    $app = Yii::app();
    $lang = $lang ? $lang : Lang::getDefaultLang();
    $app->setLanguage($lang);
    $activeLangs = Lang::getActiveLangs();
    if (isset($_GET['lang'])) {
        $tmplang = $_GET['lang'];
        //deb($tmplang);
        if (isset($activeLangs[$tmplang])) {
            $lang = $tmplang;
            $app->setLanguage($lang);
        }
        setLangCookie($lang);
        /*
         * другой код, например обновление кеша некоторых компонентов, которые изменяются при смене языка
         */
    } else {
        $user = $app->user;
        if ($user->hasState('_lang')) {
            $tmplang = $user->getState('_lang');
            if (isset($activeLangs[$tmplang])) {
                $lang = $tmplang;
                $app->setLanguage($lang);
            } else {
                setLangCookie($lang);
            }
        } else {
            if (isset($app->request->cookies['_lang'])) {
                $tmplang = $app->request->cookies['_lang']->value;
                if (isset($activeLangs[$tmplang])) {
                    $lang = $tmplang;
                    $app->setLanguage($lang);
                } else {
                    setLangCookie($lang);
                }
            }
        }
    }
    Lang::getActiveLangs(false, true);
}
예제 #3
0
function tryToGetLang($sLangs, $bSetCookie = false)
{
    $sLangs = trim($sLangs);
    if (!$sLangs) {
        return '';
    }
    $sLangs = preg_replace('/[^a-zA-Z0-9,;-]/m', '', $sLangs);
    // we do not need 'q=0.3'. we are using live queue :)
    $sLangs = strtolower($sLangs);
    if (!$sLangs) {
        return '';
    }
    $aLangs = explode(',', $sLangs);
    // ru,en-us;q=0.7,en;q=0.3 => array( 'ru' , 'en-us;q=0.7' , 'en;q=0.3' );
    foreach ($aLangs as $sLang) {
        if (!$sLang) {
            continue;
        }
        list($sLang) = explode(';', $sLang, 2);
        // en-us;q=0.7 => en-us
        if (!$sLang) {
            continue;
        }
        // check with country
        if (checkLangExists($sLang)) {
            if ($bSetCookie && $_COOKIE['lang'] != $sLang && $GLOBALS['glLangSet'] != $sLang) {
                setLangCookie($sLang);
                $GLOBALS['glLangSet'] = $sLang;
            }
            return $sLang;
        }
        //drop country
        list($sLang, $sCntr) = explode('-', $sLang, 2);
        // en-us => en
        if (!$sLang or !$sCntr) {
            continue;
        }
        //no lang or nothing changed
        //check again. without country
        if (checkLangExists($sLang)) {
            if ($bSetCookie) {
                setLangCookie($sLang);
            }
            return $sLang;
        }
    }
    return '';
}