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 getI18nColumn($columnName, $withSwitch = false) { $languages = I18nHelper::getFrontendLanguages(false); $sourceLanguageKey = current(array_keys($languages)); $sourceLanguage = array_shift($languages); $id = $this->getPrimaryKey(); $ret = $this->i18nLanguages() ? '[' . $sourceLanguage['short_label'] . '] <span style="height: 16px; overflow-y: hidden;" title="' . $this->{$columnName} . '">' . $this->{$columnName} . '</span>' : '<span style="height: 16px; overflow-y: hidden;" title="' . $this->{$columnName} . '">' . $this->{$columnName} . '</span>'; if ($withSwitch) { $ret = '<a href="#' . $id . $sourceLanguageKey . '" class="is-released-' . $this->is_released . '"></a>' . $ret; } foreach ($languages as $lang => $prop) { $ret .= '<br />'; $model = $this->localized($lang, false)->findByPk($this->primaryKey); if ($withSwitch) { $ret .= '<a href="#' . $id . $lang . '" class="is-released-' . intval($model->{'is_released'}) . '"></a>'; } $ret .= '[' . $prop['short_label'] . '] ' . $model->{$columnName}; } return $ret; }
public function actionUpdate($id) { if (Yii::app()->user->checkAccess('updateServer') == false) { throw new CHttpException(403); } $server = Server::model()->multilingual()->findByPk($id); if (is_null($server)) { throw new CHttpException(404); } if (isset($_POST['Server'])) { $server->attributes = Yii::app()->request->getPost('Server'); $server->serverFile = CUploadedFile::getInstance($server, 'serverFile'); foreach (I18nHelper::getFrontendLanguages() as $lang => $attr) { $server->i18nFormData['serverFile_' . $lang] = CUploadedFile::getInstance($server, 'i18nFormData[serverFile_' . $lang . ']'); } if ($server->validate() && $server->save()) { $this->setFlashMessage(strtr('<strong>{link}</strong> 服务修改成功', array('{link}' => CHtml::link($server->name, array('view', 'id' => $server->primaryKey))))); $this->redirect($this->getReturnUrl()); } } $this->breadcrumbs = array('服务' => array('index'), '修改'); $this->render('create', array('server' => $server, 'returnUrl' => $this->getReturnUrl())); }
public function actionUpdate($id) { if (Yii::app()->user->checkAccess('updateBrand') == false) { throw new CHttpException(403); } $brand = Brand::model()->multilingual()->findByPk($id); if (is_null($brand)) { throw new CHttpException(404); } if (isset($_POST['Brand'])) { $brand->attributes = Yii::app()->request->getPost('Brand'); $brand->brandFile = CUploadedFile::getInstance($brand, 'brandFile'); foreach (I18nHelper::getFrontendLanguages() as $lang => $attr) { $brand->i18nFormData['brandFile_' . $lang] = CUploadedFile::getInstance($brand, 'i18nFormData[brandFile_' . $lang . ']'); } if ($brand->save()) { $this->setFlashMessage(strtr('<strong>{link}</strong> 品牌修改成功', array('{link}' => CHtml::link(CHtml::encode($brand->title), array('view', 'id' => $brand->primaryKey))))); $this->redirect($this->getReturnUrl()); } } $regionOptions = Region::model()->getOptions(); $this->breadcrumbs = array('品牌' => array('index'), '修改'); $this->render('create', array('brand' => $brand, 'regionOptions' => $regionOptions, 'returnUrl' => $this->getReturnUrl())); }
public function actionUpdate() { $id = Yii::app()->request->getQuery('id'); $model = Banner::model()->multilingual()->findByPk($id); if (empty($model)) { throw new CHttpException(404); } if (isset($_POST['Banner'])) { $model->attributes = Yii::app()->request->getPost('Banner'); $model->bannerFile = CUploadedFile::getInstance($model, 'bannerFile'); foreach (I18nHelper::getFrontendLanguages() as $lang => $attr) { $model->i18nFormData['bannerFile_' . $lang] = CUploadedFile::getInstance($model, 'i18nFormData[bannerFile_' . $lang . ']'); } if ($model->save()) { $this->setFlashMessage(strtr('<strong>{link}</strong> Banner修改成功', array('{link}' => CHtml::link(htmlspecialchars($model->title), array('view', 'id' => $model->primaryKey))))); $this->redirect(array('index')); } } else { $model->i18nFormData = $model->getI18nAttributes(); } $bannerPositionOptions = BannerPosition::model()->getOptions(); $this->breadcrumbs = array('Banner' => array('index'), '修改'); $this->render('create', array('model' => $model, 'bannerPositionOptions' => $bannerPositionOptions)); }
?> </th> <td><?php echo CHtml::activeCheckBox($product, 'is_recommend'); ?> </td> </tr> <tr> <th><?php echo CHtml::activeLabelEx($product, 'is_released'); ?> </th> <td><?php echo CHtml::activeCheckBox($product, 'is_released'); ?> </td> </tr> </table> <?php $basicContent = ob_get_clean(); $i18nTabs = array(); $tabs = array(); foreach (I18nHelper::getFrontendLanguages() as $lang => $prop) { $i18nTabs[$prop['label']] = $this->renderPartial('createI18n', array('product' => $product, 'lang' => $lang, 'prop' => $prop), true); } $this->widget('zii.widgets.jui.CJuiTabs', array('tabs' => array('基本资料' => $basicContent) + $i18nTabs)); ?> <?php echo CHtml::endForm(); ?> </div>
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())); }
public function actionUpdate($id) { if (Yii::app()->user->checkAccess('updateProduct') == false) { throw new CHttpException(403); } $product = Product::model()->multilingual()->findByPk($id); if (is_null($product)) { throw new CHttpException(404); } $imageList = array(); if (isset($_POST['Product'])) { $product->attributes = Yii::app()->request->getPost('Product'); $product->productFile = CUploadedFile::getInstance($product, 'productFile'); foreach (I18nHelper::getFrontendLanguages() as $lang => $attr) { $product->i18nFormData['productFile_' . $lang] = CUploadedFile::getInstance($product, 'i18nFormData[productFile_' . $lang . ']'); } $imageList = Yii::app()->request->getPost('imageList'); $product->category_id = $product->series->category->category_id; $product->brand_id = $product->series->brand_id; $product->update_time = time(); if ($product->validate() && $product->save()) { // 保存图片数据 // if (count($imageList) > 0) { // foreach ($imageList as $productImageId => $imageInfo) { // $productImage = ProductImage::model() // ->findByPk($productImageId); // $productImage->sort_order = $imageInfo['sort_order']; // $productImage->file_name = $imageInfo['file_name']; // if (isset($imageInfo['is_released'])) { // $productImage->is_released = $imageInfo['is_released']; // } else { // $productImage->is_released = 0; // } // $productImage // ->save(true, // array('label', 'file_name','sort_order', // 'is_released')); // } // } $this->setFlashMessage(strtr('<strong>{link}</strong> 产品修改成功', array('{link}' => CHtml::link($product->name, array('view', 'id' => $product->primaryKey))))); $this->redirect($this->getReturnUrl()); } } else { $product->i18nFormData = $product->getI18nAttributes(); // foreach ($product->images as $productImage) { // $imageList[$productImage->primaryKey] = array( // 'product_id' => $productImage->product_id, // 'file_name' => $productImage->file_name, // 'thumbnail_image_url' => $productImage // ->getThumbnailImageUrl(), // 'sort_order' => $productImage->sort_order, // 'is_released' => $productImage->is_released); // } } $this->breadcrumbs = array('产品' => array('index'), '修改'); // $productCategoryOptions = ProductCategory::model()->getLeaveOptions(); $productSeriesOptions = ProductSeries::model()->getOptions(); $this->render('create', array('product' => $product, 'imageList' => $imageList, 'productSeriesOptions' => $productSeriesOptions, '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]); } } }