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);
 }
Exemple #2
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));
     }
 }
Exemple #3
0
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     if (!$model->active) {
         throw404();
     }
     if ($model->id == 4) {
         //User Agreement
         $field = 'body_' . Yii::app()->language;
         $model->{$field} = str_replace('{site_domain}', IdnaConvert::checkDecode(Yii::app()->getBaseUrl(true)), $model->{$field});
         $model->{$field} = str_replace('{site_title}', CHtml::encode(Yii::app()->name), $model->{$field});
     }
     $this->showSearchForm = $model->widget && $model->widget == 'apartments' ? true : false;
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('view', array('model' => $model));
     } else {
         $this->render('view', array('model' => $model));
     }
 }
Exemple #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();
 }
Exemple #5
0
 public function run()
 {
     if (!param('genFirendlyUrl')) {
         return '';
     }
     if (!$this->model) {
         return NULL;
     }
     $friendlyUrl = SeoFriendlyUrl::getAndCreateForModel($this->model);
     $this->render('seoWidget', array('model' => $this->model, 'friendlyUrl' => $friendlyUrl));
 }
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     $this->render('view', array('model' => $model));
 }
Exemple #7
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';
 }
 public function actionView($id = 0, $url = '')
 {
     //		if(Yii::app()->user->getState('isAdmin')){
     //			$this->redirect(array('backend/main/view', 'id' => $id));
     //		}
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     $this->render('view', array('model' => $model));
 }
Exemple #9
0
 public function actionView($id = 0, $url = '')
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'sorter';
     $criteria->condition = 'active=1';
     $articles = Article::model()->cache(param('cachingTime', 1209600), Article::getCacheDependency())->findAll($criteria);
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $this->render('view', array('model' => $this->loadModel($id), 'articles' => $articles));
 }
Exemple #10
0
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     if (!$model->active) {
         throw404();
     }
     if (isset($_GET['is_ajax'])) {
         $this->renderPartial('view', array('model' => $model));
     } else {
         $this->render('view', array('model' => $model));
     }
 }
Exemple #11
0
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id);
     if ($model) {
         if (Yii::app()->request->getParam('is_ajax')) {
             $this->renderPartial('view', array('model' => $model), false, true);
         } else {
             $this->render('view', array('model' => $model));
         }
     } else {
         Yii::app()->user->setFlash('error', tc('Page not found.'));
         $this->redirect(array('/site/index'));
     }
 }
Exemple #12
0
 public function afterSave()
 {
     if (issetModule('seo') && param('genFirendlyUrl')) {
         SeoFriendlyUrl::getAndCreateForModel($this);
     }
     return parent::afterSave();
 }
Exemple #13
0
 public function getUrl()
 {
     if (issetModule('seo') && param('genFirendlyUrl')) {
         $seo = SeoFriendlyUrl::getForUrl($this->id, 'Article');
         if ($seo) {
             $field = 'url_' . Yii::app()->language;
             if ($seo->{$field}) {
                 return Yii::app()->createAbsoluteUrl('/articles/main/view', array('url' => $seo->{$field} . (param('urlExtension') ? '.html' : '')));
             }
         }
     }
     return Yii::app()->createAbsoluteUrl('/articles/main/view', array('id' => $this->id));
 }
Exemple #14
0
 public function actionView($id = 0, $url = '', $printable = 0)
 {
     // если админ - делаем редирект на просмотр в админку
     //		if(Yii::app()->user->getState('isAdmin')){
     //			$this->redirect(array('backend/main/view', 'id' => $id));
     //		}
     $apartment = NULL;
     if (($id || $url) && issetModule('seo')) {
         $url = $url ? $url : $id;
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if ($seo) {
             $this->setSeo($seo);
             $id = $seo->model_id;
         }
     }
     if ($id) {
         $apartment = Apartment::model()->with(array('windowTo', 'objType', 'city'))->findByPk($id);
     }
     if (!$apartment) {
         throw404();
     }
     if (!in_array($apartment->type, Apartment::availableApTypesIds())) {
         throw404();
     }
     // "Толстый" запрос из-за JOIN'ов. Кешируем его.
     // Зависимость кеша - выбираем дату последней модификации из 4 таблиц
     //		$apartment = Apartment::model()
     //			->cache(param('cachingTime', 1209600), Apartment::getFullDependency($id))
     //			->with('windowTo', 'comments', 'images', 'objType', 'city')
     //			->findByPk($id);
     //
     //        if (!$apartment)
     //            throw404();
     if ($apartment->owner_id != 1 && $apartment->owner_active == Apartment::STATUS_INACTIVE) {
         if (!(isset(Yii::app()->user->id) && Yii::app()->user->id == $apartment->owner_id) && !Yii::app()->user->getState('isAdmin')) {
             Yii::app()->user->setFlash('notice', tt('apartments_main_index_propertyNotAvailable', 'apartments'));
             throw404();
         }
     }
     if (($apartment->active == Apartment::STATUS_INACTIVE || $apartment->active == Apartment::STATUS_MODERATION) && !Yii::app()->user->getState('isAdmin') && !(isset(Yii::app()->user->id) && Yii::app()->user->id == $apartment->owner_id)) {
         Yii::app()->user->setFlash('notice', tt('apartments_main_index_propertyNotAvailable', 'apartments'));
         //$this->redirect(Yii::app()->homeUrl);
         throw404();
     }
     if ($apartment->active == Apartment::STATUS_MODERATION && $apartment->owner_active == Apartment::STATUS_ACTIVE && $apartment->owner_id == Yii::app()->user->id) {
         Yii::app()->user->setFlash('error', tc('Awaiting moderation'));
     }
     $dateFree = CDateTimeParser::parse($apartment->is_free_to, 'yyyy-MM-dd');
     if ($dateFree && $dateFree < time() - 60 * 60 * 24) {
         $apartment->is_special_offer = 0;
         $apartment->update(array('is_special_offer'));
     }
     if (!Yii::app()->request->isAjaxRequest) {
         $ipAddress = Yii::app()->request->userHostAddress;
         $userAgent = Yii::app()->request->userAgent;
         Apartment::setApartmentVisitCount($apartment, $ipAddress, $userAgent);
     }
     if ($printable) {
         $this->layout = '//layouts/print';
         $this->render('view_print', array('model' => $apartment));
     } else {
         Apartment::model()->setLastVisitedObjectsCookies($apartment->id);
         $this->render('view', array('model' => $apartment, 'statistics' => Apartment::getApartmentVisitCount($apartment)));
     }
 }
Exemple #15
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;
 }
Exemple #16
0
 public function afterSave()
 {
     if ($this->scenario == 'savecat') {
         $this->saveCategories();
         if ($this->metroStations) {
             $this->setMetroStations($this->metroStations);
         }
     }
     if ($this->panoramaFile) {
         $panorama = new ApartmentPanorama();
         $panorama->fileInstance = $this->panoramaFile;
         $panorama->apartment_id = $this->id;
         $panorama->save();
     }
     if (issetModule('seo') && param('genFirendlyUrl')) {
         SeoFriendlyUrl::getAndCreateForModel($this);
     }
     if (issetModule('socialposting') && $this->active == self::STATUS_ACTIVE && ($this->owner_active = self::STATUS_ACTIVE)) {
         SocialpostingModel::preparePosting($this);
     }
     $sql = 'DELETE FROM {{apartment}} WHERE active=:draft AND date_created<DATE_SUB(NOW(),INTERVAL 1 DAY)';
     Yii::app()->db->createCommand($sql)->execute(array(':draft' => self::STATUS_DRAFT));
     return parent::afterSave();
 }
Exemple #17
0
 public function actionView($id = 0, $url = '', $printable = 0)
 {
     //$this->showSearchForm = false;
     $this->htmlPageId = 'viewlisting';
     $apartment = NULL;
     $seo = NULL;
     if (($id || $url) && issetModule('seo')) {
         $url = $url ? $url : $id;
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if ($seo) {
             $this->setSeo($seo);
             $id = $seo->model_id;
         }
     }
     if ($id) {
         $apartment = Apartment::model()->with(array('windowTo', 'objType', 'city'))->findByPk($id);
         // избавляемся от дублей
         $apartmentUrl = $apartment->getUrl(false);
         if (!$printable && issetModule('seo') && $apartment->seo && Yii::app()->request->url != $apartmentUrl) {
             $this->redirect($apartmentUrl, true, 301);
         }
     }
     if (!$apartment) {
         throw404();
     }
     if (!in_array($apartment->type, Apartment::availableApTypesIds()) || !in_array($apartment->price_type, array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true)))) {
         throw404();
     }
     if ($apartment->owner_id != 1 && $apartment->owner_active == Apartment::STATUS_INACTIVE) {
         if (!(isset(Yii::app()->user->id) && Yii::app()->user->id == $apartment->owner_id) && !Yii::app()->user->checkAccess('backend_access')) {
             Yii::app()->user->setFlash('notice', tt('apartments_main_index_propertyNotAvailable', 'apartments'));
             throw404();
         }
     }
     if (($apartment->active == Apartment::STATUS_INACTIVE || $apartment->active == Apartment::STATUS_MODERATION) && !Yii::app()->user->checkAccess('backend_access') && !(isset(Yii::app()->user->id) && Yii::app()->user->id == $apartment->owner_id)) {
         Yii::app()->user->setFlash('notice', tt('apartments_main_index_propertyNotAvailable', 'apartments'));
         //$this->redirect(Yii::app()->homeUrl);
         throw404();
     }
     if ($apartment->active == Apartment::STATUS_MODERATION && $apartment->owner_active == Apartment::STATUS_ACTIVE && $apartment->owner_id == Yii::app()->user->id) {
         Yii::app()->user->setFlash('error', tc('Awaiting moderation'));
     }
     if ($apartment->deleted) {
         Yii::app()->user->setFlash('error', tt('Listing is deleted', 'apartments'));
     }
     $dateFree = CDateTimeParser::parse($apartment->is_free_to, 'yyyy-MM-dd');
     if ($dateFree && $dateFree < time() - 60 * 60 * 24) {
         $apartment->is_special_offer = 0;
         $apartment->update(array('is_special_offer'));
     }
     if (!Yii::app()->request->isAjaxRequest) {
         $ipAddress = Yii::app()->request->userHostAddress;
         $userAgent = Yii::app()->request->userAgent;
         Apartment::setApartmentVisitCount($apartment, $ipAddress, $userAgent);
     }
     $lastNews = News::getLastNews();
     $lastArticles = Article::getLastArticles();
     #######################################################################
     # для соц. кнопок
     if ($apartment->getStrByLang("title")) {
         Yii::app()->clientScript->registerMetaTag($apartment->getStrByLang("title"), null, null, array('property' => 'og:title'));
     }
     if ($apartment->getStrByLang("description")) {
         Yii::app()->clientScript->registerMetaTag($apartment->getStrByLang("description"), null, null, array('property' => 'og:description'));
     }
     Yii::app()->clientScript->registerMetaTag($apartment->getUrl(), null, null, array('property' => 'og:url'));
     if (Yii::app()->theme->name == 'atlas') {
         $res = Images::getMainThumb(640, 400, $apartment->images);
     } else {
         $res = Images::getMainThumb(300, 200, $apartment->images);
     }
     if (isset($res['thumbUrl']) && $res['thumbUrl']) {
         Yii::app()->clientScript->registerMetaTag($res['thumbUrl'], null, null, array('property' => 'og:image'));
         Yii::app()->clientScript->registerLinkTag('image_src', null, $res['thumbUrl']);
     }
     #######################################################################
     if ($printable) {
         $this->layout = '//layouts/print';
         $this->render('view_print', array('model' => $apartment));
     } else {
         $this->render('view', array('model' => $apartment, 'statistics' => Apartment::getApartmentVisitCount($apartment), 'lastNews' => $lastNews, 'lastArticles' => $lastArticles));
     }
 }
Exemple #18
0
 public function setSeo(SeoFriendlyUrl $seo)
 {
     $this->seoTitle = $seo->getStrByLang('title');
     $this->seoDescription = $seo->getStrByLang('description');
     $this->seoKeywords = $seo->getStrByLang('keywords');
 }