/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionAjaxManage($id) { $model = AlbumPhoto::getPhoto($id); $setting = AlbumSetting::model()->findByPk(1, array('select' => 'photo_limit')); $data = ''; if ($model != null) { foreach ($model as $key => $val) { $image = Yii::app()->request->baseUrl . '/public/album/' . $val->album_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(24012, 1) . '">' . Phrase::trans(24012, 1) . '</a>'; $data .= '<img src="' . Utility::getTimThumb($image, 320, 250, 1) . '" alt="' . $val->album->title . '" />'; $data .= '</li>'; } } if (isset($_GET['replace'])) { // begin.Upload Button $class = count($model) == $setting->photo_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/album/album_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 (AlbumSetting::getInfo('permission') == 1) { $arrThemes = Utility::getCurrentTemplate('public'); Yii::app()->theme = $arrThemes['folder']; $this->layout = $arrThemes['layout']; } else { $this->redirect(Yii::app()->createUrl('site/index')); } }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $setting = AlbumSetting::model()->findByPk(1, array('select' => 'meta_keyword')); $model = $this->loadModel($id); Albums::model()->updateByPk($id, array('view' => $model->view + 1)); $photo = AlbumPhoto::model()->findAll(array('condition' => 'album_id = :id', 'params' => array(':id' => $model->album_id), 'order' => 'media_id DESC')); $this->pageTitleShow = true; $this->pageTitle = $model->title; $this->pageDescription = Utility::shortText(Utility::hardDecode($model->body), 300); $this->pageMeta = $setting->meta_keyword; $this->render('front_view', array('model' => $model, 'photo' => $photo)); }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $setting = AlbumSetting::model()->findByPk(1, array('select' => 'meta_keyword')); $model = $this->loadModel($id); Albums::model()->updateByPk($id, array('view' => $model->view + 1)); $photo = AlbumPhoto::model()->findAll(array('condition' => 'album_id = :id', 'params' => array(':id' => $model->album_id), 'order' => 'media_id DESC')); //Random Article $criteria = new CDbCriteria(); $criteria->condition = 'publish = :publish AND album_id <> :id'; $criteria->params = array(':publish' => 1, ':id' => $id); $criteria->order = 'RAND()'; $criteria->limit = 4; $random = Albums::model()->findAll($criteria); $this->pageTitleShow = true; $this->pageTitle = $model->title; $this->pageDescription = Utility::shortText(Utility::hardDecode($model->body), 300); $this->pageMeta = $setting->meta_keyword; if ($model->media_id != 0 && $model->cover->media != '') { $media = Yii::app()->request->baseUrl . '/public/album/' . $id . '/' . $model->cover->media; $this->pageImage = $media; } $this->render('front_view', array('model' => $model, 'photo' => $photo, 'random' => $random)); }
/** * 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 = AlbumSetting::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('phrase', 'The requested page does not exist.')); } return $model; }
/** * After save attributes */ protected function afterSave() { parent::afterSave(); if ($this->isNewRecord) { // Add album directory $album_path = "public/album/" . $this->album_id; if (!file_exists($album_path)) { @mkdir($album_path, 0777, true); // Add file in album directory (index.php) $newFile = $album_path . '/index.php'; $FileHandle = fopen($newFile, 'w'); } $this->media = CUploadedFile::getInstance($this, 'media'); if ($this->media instanceof CUploadedFile) { $fileName = time() . '_' . $this->album_id . '_' . Utility::getUrlTitle($this->title) . '.' . strtolower($this->media->extensionName); if ($this->media->saveAs($album_path . '/' . $fileName)) { $images = new AlbumPhoto(); $images->album_id = $this->album_id; $images->cover = '1'; $images->media = $fileName; $images->save(); } } } else { // Add Tags 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 AlbumTag(); $tag->album_id = $this->album_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(); } } if (AlbumSetting::getInfo('headline') == 1) { if ($this->headline == 1) { self::model()->updateAll(array('headline' => 0), array('condition' => 'album_id != :id AND cat_id = :cat', 'params' => array(':id' => $this->album_id, ':cat' => $this->cat_id))); } } }
/** * 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 = AlbumSetting::model()->findByPk(1, array('select' => 'photo_limit, meta_keyword')); $tag = AlbumTag::model()->findAll(array('condition' => 'album_id = :id', 'params' => array(':id' => $model->album_id))); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Albums'])) { $model->attributes = $_POST['Albums']; $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', 'Album success updated.') . '</strong></div>')); } else { print_r($model->getErrors()); } } } Yii::app()->end(); } else { $this->pageTitle = Yii::t('phrase', 'Update Album') . ': ' . $model->title; $this->pageDescription = ''; $this->pageMeta = ''; $this->render('admin_edit', array('model' => $model, 'setting' => $setting, 'tag' => $tag)); } }
/** * After save attributes */ protected function afterSave() { parent::afterSave(); //set flex cover in album //if($this->cover == 1 || count(self::getPhoto($this->album_id)) == 1) { if ($this->cover == 1) { $cover = Albums::model()->findByPk($this->album_id); $cover->media_id = $this->media_id; $cover->update(); } $setting = AlbumSetting::getInfo('photo_limit, photo_resize, photo_resize_size', 'many'); $photo_limit = $setting->photo_limit; $photo_resize = $setting->photo_resize; $photo_resize_size = $setting->photo_resize_size; if ($this->album->cat->default_setting == 0) { $photo_limit = $this->album->cat->photo_limit; $photo_resize = $this->album->cat->photo_resize; $photo_resize_size = $this->album->cat->photo_resize_size; } //create thumb image if ($photo_resize == 1) { Yii::import('ext.phpthumb.PhpThumbFactory'); $album_path = 'public/album/' . $this->album_id; $albumImg = PhpThumbFactory::create($album_path . '/' . $this->media, array('jpegQuality' => 90, 'correctPermissions' => true)); $resizeSize = unserialize($photo_resize_size); if ($resizeSize['height'] == 0) { $albumImg->resize($resizeSize['width']); } else { $albumImg->adaptiveResize($resizeSize['width'], $resizeSize['height']); } $albumImg->save($album_path . '/' . $this->media); } //delete other photo (if photo_limit = 1) if ($photo_limit == 1) { self::model()->deleteAll(array('condition' => 'album_id = :id AND cover = :cover', 'params' => array(':id' => $this->album_id, ':cover' => 0))); } }