Example #1
0
 public function actionIndex()
 {
     $this->checkCookieEnabled();
     $this->htmlPageId = 'index';
     $page = Menu::model()->findByPk(InfoPages::MAIN_PAGE_ID);
     if (issetModule('seo')) {
         $seo = SeoFriendlyUrl::model()->findByAttributes(array('model_name' => 'InfoPages', 'model_id' => InfoPages::MAIN_PAGE_ID));
         if ($seo) {
             $this->setSeo($seo);
         }
     }
     $langs = Lang::getActiveLangs();
     $countLangs = count($langs);
     if (!isFree() && !isset($_GET['lang']) && ($countLangs > 1 || $countLangs == 1 && param('useLangPrefixIfOneLang'))) {
         $canonicalUrl = Yii::app()->getBaseUrl(true);
         $canonicalUrl .= '/' . Yii::app()->language;
         Yii::app()->clientScript->registerLinkTag('canonical', null, $canonicalUrl);
     }
     Yii::app()->user->setState('searchUrl', NULL);
     $lastNews = News::getLastNews();
     if (Yii::app()->request->isAjaxRequest) {
         //			$modeListShow = User::getModeListShow();
         //			if ($modeListShow == 'table') {
         //				# нужны скрипты и стили, поэтому processOutput установлен в true только для table
         //				$this->renderPartial('index', array('page' => $page, 'newsIndex' => $lastNews), false, true);
         //			}
         //			else {
         $this->renderPartial('index', array('page' => $page, 'newsIndex' => $lastNews));
         //			}
     } else {
         $this->render('index', array('page' => $page, 'newsIndex' => $lastNews));
     }
 }
Example #2
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);
 }
Example #3
0
 public function actionRegenSeo()
 {
     $modelsAll = SeoFriendlyUrl::model()->findAll();
     $activeLangs = Lang::getActiveLangs();
     foreach ($modelsAll as $model) {
         foreach ($activeLangs as $lang) {
             $field = 'url_' . $lang;
             $model->{$field} = translit($model->{$field});
         }
         $model->save();
     }
     echo 'end';
 }
Example #4
0
 public function actionAjaxSave()
 {
     if (isset($_POST['SeoFriendlyUrl'])) {
         $this->canUseDirectUrl = (int) Yii::app()->request->getPost('canUseDirectUrl');
         $friendlyUrl = SeoFriendlyUrl::model()->findByPk($_POST['SeoFriendlyUrl']['id']);
         if (!$friendlyUrl) {
             $friendlyUrl = new SeoFriendlyUrl();
         }
         $friendlyUrl->attributes = $_POST['SeoFriendlyUrl'];
         if ($friendlyUrl->save()) {
             echo CJSON::encode(array('status' => 'ok', 'html' => $this->renderPartial('//modules/seo/views/_form', array('friendlyUrl' => $friendlyUrl), true)));
             Yii::app()->end();
         } else {
             echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('//modules/seo/views/_form', array('friendlyUrl' => $friendlyUrl), true)));
             Yii::app()->end();
         }
     }
     throw404();
 }
Example #5
0
 public static function getAndCreateForModel($model)
 {
     if (!param('genFirendlyUrl')) {
         return false;
     }
     // костылек
     $modelName = get_class($model) == 'UserAds' ? 'Apartment' : get_class($model);
     $friendlyUrl = SeoFriendlyUrl::model()->findByAttributes(array('model_name' => $modelName, 'model_id' => $model->id));
     // Если еще нет, создаем
     if (!$friendlyUrl) {
         $friendlyUrl = new SeoFriendlyUrl();
         if ($model->id > 0 && $friendlyUrl->setDefault($model)) {
             $friendlyUrl->save();
         } else {
             $friendlyUrl->model_name = $modelName;
             $friendlyUrl->model_id = $model->id;
         }
     }
     return $friendlyUrl;
 }