/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionAjaxManage($id) { $model = ArticleMedia::getPhoto($id); $setting = ArticleSetting::model()->findByPk(1, array('select' => 'media_limit')); $data = ''; if ($model != null) { foreach ($model as $key => $val) { $image = Yii::app()->request->baseUrl . '/public/article/' . $val->article_id . '/' . $val->media; $url = Yii::app()->controller->createUrl('ajaxdelete', array('id' => $val->media_id)); $urlCover = Yii::app()->controller->createUrl('ajaxcover', array('id' => $val->media_id)); $data .= '<li>'; if ($val->cover == 0) { $data .= '<a id="set-cover" href="' . $urlCover . '" title="' . Phrase::trans(26108, 1) . '">' . Phrase::trans(26108, 1) . '</a>'; } $data .= '<a id="set-delete" href="' . $url . '" title="' . Phrase::trans(26055, 1) . '">' . Phrase::trans(26055, 1) . '</a>'; $data .= '<img src="' . Utility::getTimThumb($image, 320, 250, 1) . '" alt="' . $val->article->title . '" />'; $data .= '</li>'; } } if (isset($_GET['replace'])) { // begin.Upload Button $class = count($model) == $setting->media_limit ? 'class="hide"' : ''; $url = Yii::app()->controller->createUrl('ajaxadd', array('id' => $id)); $data .= '<li id="upload" ' . $class . '>'; $data .= '<a id="upload-gallery" href="' . $url . '" title="' . Phrase::trans(26054, 1) . '">' . Phrase::trans(26054, 1) . '</a>'; $data .= '<img src="' . Utility::getTimThumb(Yii::app()->request->baseUrl . '/public/article/article_default.png', 320, 250, 1) . '" alt="" />'; $data .= '</li>'; // end.Upload Button } $data .= ''; $result['data'] = $data; echo CJSON::encode($result); }
/** * Initialize admin page theme */ public function init() { if (ArticleSetting::getInfo('permission') == 1) { $arrThemes = Utility::getCurrentTemplate('public'); Yii::app()->theme = $arrThemes['folder']; $this->layout = $arrThemes['layout']; } else { $this->redirect(Yii::app()->createUrl('site/index')); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = ArticleSetting::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.')); } return $model; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionEdit($id) { $model = $this->loadModel($id); $setting = ArticleSetting::model()->findByPk(1, array('select' => 'type_active, media_limit, meta_keyword')); $tag = ArticleTag::model()->findAll(array('condition' => 'article_id = :id', 'params' => array(':id' => $model->article_id))); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Articles'])) { $model->attributes = $_POST['Articles']; /* if($model->article_type == 1 && $setting->media_limit != 1) { $jsonError = CActiveForm::validate($model); if(strlen($jsonError) > 2) { $errors = $model->getErrors(); $summary['msg'] = "<div class='errorSummary'><strong>".Yii::t('phrase', 'Please fix the following input errors:')."</strong>"; $summary['msg'] .= "<ul>"; foreach($errors as $key => $value) { $summary['msg'] .= "<li>{$value[0]}</li>"; } $summary['msg'] .= "</ul></div>"; $message = json_decode($jsonError, true); $merge = array_merge_recursive($summary, $message); $encode = json_encode($merge); echo $encode; } else { if(isset($_GET['enablesave']) && $_GET['enablesave'] == 1) { if($model->save()) { echo CJSON::encode(array( 'type' => 0, 'msg' => '<div class="errorSummary success"><strong>'.Yii::t('phrase', 'Article success updated.').'</strong></div>', )); } else { print_r($model->getErrors()); } } } Yii::app()->end(); } else { */ if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('phrase', 'Article success updated.')); $this->redirect(array('edit', 'id' => $model->article_id)); } //} } $this->pageTitle = Phrase::trans(26032, 1) . ': ' . $model->title; $this->pageDescription = ''; $this->pageMeta = ''; $this->render('admin_edit', array('model' => $model, 'setting' => $setting, 'tag' => $tag)); }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $setting = ArticleSetting::model()->findByPk(1, array('select' => 'meta_keyword')); $model = $this->loadModel($id); Articles::model()->updateByPk($id, array('view' => $model->view + 1)); //Random Article $criteria = new CDbCriteria(); $criteria->condition = 'publish = :publish AND published_date <= curdate() AND article_id <> :id'; $criteria->params = array(':publish' => 1, ':id' => $id); $criteria->order = 'RAND()'; $criteria->addInCondition('cat_id', $model->cat_id); $criteria->limit = 4; $random = Articles::model()->findAll($criteria); $this->pageTitle = $model->title; $this->pageDescription = Utility::shortText(Utility::hardDecode($model->body), 300); $this->pageMeta = ArticleTag::getKeyword($setting->meta_keyword, $id); if ($model->media_id != 0 && $model->cover->media != '') { if (in_array($model->article_type, array('1', '3'))) { $media = Yii::app()->request->baseUrl . '/public/article/' . $id . '/' . $model->cover->media; } else { if ($model->article_type == 2) { $media = 'http://www.youtube.com/watch?v=' . $model->cover->media; } } $this->pageImage = $media; } $this->render('front_view', array('model' => $model, 'random' => $random)); }
/** * After save attributes */ protected function afterSave() { parent::afterSave(); $article_path = "public/article/" . $this->article_id; if ($this->isNewRecord && in_array($this->article_type, array(1, 3))) { // Add article directory if (!file_exists($article_path)) { @mkdir($article_path, 0777, true); // Add file in article directory (index.php) $newFile = $article_path . '/index.php'; $FileHandle = fopen($newFile, 'w'); } } if ($this->article_type == 1) { if ($this->isNewRecord || !$this->isNewRecord && ArticleSetting::getInfo('media_limit') == 1) { $this->media = CUploadedFile::getInstance($this, 'media'); if ($this->media instanceof CUploadedFile) { $fileName = time() . '_' . $this->article_id . '_' . Utility::getUrlTitle($this->title) . '.' . strtolower($this->media->extensionName); if ($this->media->saveAs($article_path . '/' . $fileName)) { if ($this->isNewRecord || !$this->isNewRecord && $this->media_id == 0) { $images = new ArticleMedia(); $images->article_id = $this->article_id; $images->cover = 1; $images->media = $fileName; $images->save(); } else { if ($this->old_media != '' && file_exists($article_path . '/' . $this->old_media)) { rename($article_path . '/' . $this->old_media, 'public/article/verwijderen/' . $this->article_id . '_' . $this->old_media); } $images = ArticleMedia::model()->findByPk($this->media_id); $images->media = $fileName; $images->update(); } } } } } else { if ($this->article_type == 2) { if ($this->isNewRecord) { $video = new ArticleMedia(); $video->article_id = $this->article_id; $video->cover = 1; $video->media = $this->video; $video->save(); } else { if ($this->media_id == 0) { $video = new ArticleMedia(); $video->article_id = $this->article_id; $video->cover = 1; $video->media = $this->video; if ($video->save()) { $data = Articles::model()->findByPk($this->article_id); $data->media_id = $video->media_id; $data->update(); } } else { $video = ArticleMedia::model()->findByPk($this->media_id); $video->media = $this->video; $video->update(); } } } } $this->file = CUploadedFile::getInstance($this, 'file'); if ($this->file instanceof CUploadedFile) { $fileName = time() . '_' . $this->article_id . '_' . Utility::getUrlTitle($this->title) . '.' . strtolower($this->file->extensionName); if ($this->file->saveAs($article_path . '/' . $fileName)) { if (!$this->isNewRecord && $this->media_file != '' && file_exists($article_path . '/' . $this->old_file)) { rename($article_path . '/' . $this->old_file, 'public/article/verwijderen/' . $this->article_id . '_' . $this->old_file); } $article = Articles::model()->findByPk($this->article_id); $article->media_file = $fileName; $article->update(); } } // Add Keyword if (!$this->isNewRecord) { if ($this->keyword != '') { $model = OmmuTags::model()->find(array('select' => 'tag_id, body', 'condition' => 'publish = 1 AND body = :body', 'params' => array(':body' => $this->keyword))); $tag = new ArticleTag(); $tag->article_id = $this->article_id; if ($model != null) { $tag->tag_id = $model->tag_id; } else { $data = new OmmuTags(); $data->body = $this->keyword; if ($data->save()) { $tag->tag_id = $data->tag_id; } } $tag->save(); } } // Reset headline if (ArticleSetting::getInfo('headline') == 1) { if ($this->headline == 1) { self::model()->updateAll(array('headline' => 0), array('condition' => 'article_id != :id AND cat_id = :cat', 'params' => array(':id' => $this->article_id, ':cat' => $this->cat_id))); } } else { } }
/** * After save attributes */ protected function afterSave() { parent::afterSave(); //set flex cover in article //if($this->cover == 1 || count(self::getPhoto($this->article_id)) == 1) { if ($this->cover == 1) { $cover = Articles::model()->findByPk($this->article_id); $cover->media_id = $this->media_id; $cover->update(); } if ($this->article->article_type == 1) { $setting = ArticleSetting::getInfo('media_limit, media_resize, media_resize_size', 'many'); //create thumb image if ($setting->media_resize == 1) { Yii::import('ext.phpthumb.PhpThumbFactory'); $article_path = "public/article/" . $this->article_id; $articleImg = PhpThumbFactory::create($article_path . '/' . $this->media, array('jpegQuality' => 90, 'correctPermissions' => true)); $resizeSize = explode(',', $setting->media_resize_size); if ($resizeSize[1] == 0) { $articleImg->resize($resizeSize[0]); } else { $articleImg->adaptiveResize($resizeSize[0], $resizeSize[1]); } $articleImg->save($article_path . '/' . $this->media); } //delete other media (if media_limit = 1) if ($setting->media_limit == 1) { self::model()->deleteAll(array('condition' => 'article_id = :id AND cover = :cover', 'params' => array(':id' => $this->article_id, ':cover' => 0))); } } }