public function actionCheck()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $relatedType = Yii::app()->request->getPost('related_type');
         $relatedId = Yii::app()->request->getPost('related_id');
         $lang = Yii::app()->request->getPost('lang');
         $keywords = Yii::app()->request->getPost('keywords');
         $keywordList = InternalLinkKeyword::getExistedKeywords($relatedType, $relatedId, $lang, $keywords);
         if (count($keywordList) > 0) {
             echo CJSON::encode(array('result' => false, 'message' => strtr('关键词 {keywords} 已存在', array('{keywords}' => implode(', ', $keywordList)))));
         } else {
             echo CJSON::encode(array('result' => true));
         }
         Yii::app()->end();
     }
 }
Ejemplo n.º 2
0
 public function actionSetting()
 {
     if (Yii::app()->user->checkAccess('updateSetting') == false) {
         throw new CHttpException(403);
     }
     $normalCodes = array('system_maintaining', 'footer_js', 'google_analytics_account', 'google_analytics_password', 'google_analytics_report_id');
     $multilangCodes = array('home_title', 'home_internal_link_keywords', 'inside_title', 'magazine_footer', 'copyright', 'address', 'email', 'meta_keywords', 'meta_description');
     $models = array();
     foreach ($normalCodes as $code) {
         $models[$code] = Setting::model()->findByAttributes(array('code' => $code));
     }
     foreach ($multilangCodes as $code) {
         $models[$code] = Setting::model()->multilingual()->findByAttributes(array('code' => $code));
     }
     // robots.txt
     $robotsFilePath = Helper::mediaPath('robots.txt', FRONTEND);
     if (file_exists($robotsFilePath)) {
         $robots = file_get_contents($robotsFilePath);
     } else {
         if (is_writable($robotsFilePath)) {
             $handle = fopen($robotsFilePath, 'a');
             if ($handle != false) {
                 $fp = fopen($robotsFilePath, 'w');
                 fclose($fp);
             }
             $robots = '';
         } else {
             $robots = '';
         }
     }
     if ($_POST) {
         foreach (array_merge($normalCodes, $multilangCodes) as $code) {
             if (isset($_POST[$code])) {
                 $models[$code]->setAttributes($_POST[$code]);
             } else {
                 $models[$code]->setAttributes(array('value' => ''));
             }
         }
         if (isset($models['home_internal_link_keywords'])) {
             $models['home_internal_link_keywords']['value'] = Helper::arrangeKeywords($_POST['home_internal_link_keywords']['value']);
         }
         foreach ($models as $model) {
             $model->save();
         }
         // 首页内链关键词
         if (isset($models['home_internal_link_keywords'])) {
             foreach (I18nHelper::getFrontendLanguages(false) as $lang => $attr) {
                 if ($lang == I18nHelper::getFrontendSourceLanguage()) {
                     InternalLinkKeyword::model()->insertOrUpdate('home', 0, $lang, $models['home_internal_link_keywords']['value']);
                 } else {
                     InternalLinkKeyword::model()->insertOrUpdate('home', 0, $lang, $models['home_internal_link_keywords']->i18nFormData['value_' . $lang]);
                 }
             }
         }
         // robots.txt
         if (is_writable($robotsFilePath)) {
             $robots = Yii::app()->request->getPost('robots');
             $handle = fopen($robotsFilePath, 'a');
             if ($handle != false) {
                 $fp = fopen($robotsFilePath, 'w');
                 fwrite($handle, $robots);
                 fclose($fp);
             }
         }
         $this->setFlashMessage('系统设置已保存');
         $this->redirect($this->getReturnUrl());
     }
     $this->breadcrumbs = array('系统设置');
     $this->render('setting', array('models' => $models, 'robots' => $robots, 'returnUrl' => $this->getReturnUrl()));
 }
Ejemplo n.º 3
0
 protected function afterDelete()
 {
     // 删除内链关键词
     InternalLinkKeyword::model()->deleteAllByAttributes(array('related_type' => 'page', 'related_id' => $this->page_id));
     parent::afterDelete();
 }