public function actionIndex() { if (Yii::app()->user->checkAccess('viewInternalLinkKeyword') == false) { throw new CHttpException(403); } $pageSize = Yii::app()->request->getQuery('pagesize', 10); $keyword = trim(Yii::app()->request->getQuery('keyword')); $lang = Yii::app()->request->getQuery('lang'); if (empty($lang)) { $lang = I18nHelper::getFrontendSourceLanguage(); } $criteria = new CDbCriteria(); $criteria->compare('lang', $lang); if (empty($keyword) == false) { if (preg_match('/^#\\d+$/', $keyword)) { $criteria->compare('internal_link_keyword_id', substr($keyword, 1)); } else { $criteria->addSearchCondition('t.keyword', $keyword); } } $dataProvider = new CActiveDataProvider(InternalLinkKeyword::model(), array('criteria' => $criteria, 'sort' => array('defaultOrder' => 't.keyword ASC, t.internal_link_keyword_id ASC'), 'pagination' => array('pageSize' => $pageSize))); $langOptions = array(); foreach (I18nHelper::getFrontendLanguages(false) as $curLang => $attr) { $langOptions[$curLang] = $attr['label']; } $this->breadcrumbs = array('内链关键词'); $this->render('index', array('dataProvider' => $dataProvider, 'keyword' => $keyword, 'lang' => $lang, 'langOptions' => $langOptions)); }
public function actionUpdateIsReleased() { $id = Yii::app()->request->getPost('id'); $language = Yii::app()->request->getPost('language'); $isReleased = Yii::app()->request->getPost('is_released'); if ($language == I18nHelper::getFrontendSourceLanguage()) { echo Banner::model()->updateByPk($id, array('is_released' => $isReleased)); } else { echo BannerI18n::model()->updateAll(array('is_released' => $isReleased), 'owner_id = :owner_id AND lang = :lang', array(':owner_id' => $id, ':lang' => $language)); } }
public function actionUpdateIsReleased() { if (Yii::app()->user->checkAccess('updateServer') == false) { throw new CHttpException(403); } $id = Yii::app()->request->getPost('id'); $language = Yii::app()->request->getPost('language'); $isReleased = Yii::app()->request->getPost('is_released'); if ($language == I18nHelper::getFrontendSourceLanguage()) { echo Server::model()->updateByPk($id, array('is_released' => $isReleased)); } else { echo ServerI18n::model()->updateAll(array('is_released' => $isReleased), 'owner_id = :owner_id AND lang = :lang', array(':owner_id' => $id, ':lang' => $language)); } }
public function sourceLanguage() { return I18nHelper::getFrontendSourceLanguage(); }
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())); }
protected function afterSave() { parent::afterSave(); require_once 'Image.php'; // 保存背景图片 if ($this->bgImageFile instanceof CUploadedFile && $this->hasErrors('bgImageFile') == false) { // 保存原文件 $file = $this->bgImageFile; $fileName = md5($file->tempName . uniqid()) . '.' . $file->extensionName; $filePath = Helper::mediaPath(self::UPLOAD_BG_IMAGE_PATH . $fileName, FRONTEND); $file->saveAs($filePath); // 更新数据 $this->updateByPk($this->primaryKey, array('bg_image_path' => $fileName)); } else { if ($this->deleteBgImageFile) { // 删除图片 @unlink(Helper::mediaPath(self::UPLOAD_BG_IMAGE_PATH . $this->bg_image_path, FRONTEND)); // 更新数据 $this->updateByPk($this->primaryKey, array('bg_image_path' => '')); } } // 内链关键词 foreach (I18nHelper::getFrontendLanguages(false) as $lang => $attr) { if ($lang == I18nHelper::getFrontendSourceLanguage()) { InternalLinkKeyword::model()->insertOrUpdate('page', $this->page_id, $lang, $this->internal_link_keywords); } else { InternalLinkKeyword::model()->insertOrUpdate('page', $this->page_id, $lang, $this->i18nFormData['internal_link_keywords_' . $lang]); } } }