/** * 批量操作 * @throws CHttpException */ public function actionBatch() { if ($this->method() == 'GET') { $command = trim($this->_request->getParam('command')); $ids = intval($this->_request->getParam('id')); } elseif ($this->method() == 'POST') { $command = $this->_request->getPost('command'); $ids = $this->_request->getPost('id'); } else { throw new CHttpException(404, Yii::t('admin', 'Only POST Or GET')); } empty($ids) && $this->message('error', Yii::t('admin', 'No Select')); switch ($command) { case 'attachDelete': foreach ((array) $ids as $id) { $uploadModel = Upload::model()->findByPk($id); if ($uploadModel) { Uploader::deleteFile($uploadModel->file_name); $uploadModel->delete(); } } break; default: throw new CHttpException(404, Yii::t('admin', 'Error Operation')); break; } $this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index')); }
public function testDelete() { $file = $this->uploads('upload1'); $upload_id = $file->id; $this->assertTrue($file->delete()); $deleted_file = Upload::model()->findByPk($upload_id); $this->assertEquals(NULL, $deleted_file); }
/** * 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 = Upload::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function afterSave(Post $post) { $key = param('sess_post_create_token'); if (app()->session->contains($key) && ($token = app()->session[$key])) { if (!$post->hasErrors()) { $attributes = array('post_id' => $post->id, 'token' => ''); Upload::model()->updateAll($attributes, 'token = :token', array(':token' => $token)); app()->session->remove($key); } } }
/** * 插入用户女神相片 * * @param string $user_id * @param string $token * */ public function actionInsertUserGoddess() { $qq = trim(Yii::app()->request->getParam('qq')); $name = trim(Yii::app()->request->getParam('name')); $nick_name = trim(Yii::app()->request->getParam('nickname')); $img = trim(Yii::app()->request->getParam('img')); // 参数检查 if (!isset($_REQUEST['qq']) || !isset($_REQUEST['name']) || !isset($_REQUEST['nickname']) || !isset($_REQUEST['img'])) { $this->_return('MSG_ERR_LESS_PARAM'); } $param = array('qq' => $qq, 'name' => $name, 'nick_name' => $nick_name); $user_goddess_id = Upload::model()->insertUserGoddess($param); $param = array('url' => $img, 'user_goddess_id' => $user_goddess_id); $res = Upload::model()->insertUpload($param); if ($res == false) { $this->_return('MSG_ERR_UNKOWN'); } $this->_return('MSG_SUCCESS'); }
/** * 删除附件 * @return [type] [description] */ public function actionRemove() { $imageId = intval($this->_gets->getParam('imageId')); try { $imageModel = Upload::model()->findByPk($imageId); if ($imageModel == false) { throw new Exception("附件已经被删除"); } @unlink($imageModel->file_name); @unlink($imageModel->thumb_name); if (!$imageModel->delete()) { throw new Exception("数据删除失败"); } $var['state'] = 'success'; $var['message'] = '删除完成'; } catch (Exception $e) { $var['state'] = 'errro'; $var['message'] = '失败:' . $e->getMessage(); } exit(CJSON::encode($var)); }
public function actionCreate($id = 0) { $id = (int) $id; if ($id === 0) { $model = new AdminPost(); $model->homeshow = user()->checkAccess('create_post_in_home') ? BETA_YES : BETA_NO; $model->state = user()->checkAccess('editor') ? POST_STATE_ENABLED : POST_STATE_NOT_VERIFY; $this->adminTitle = t('create_post'); } elseif ($id > 0) { $model = AdminPost::model()->findByPk($id); $this->adminTitle = t('edit_post'); } else { throw new CHttpException(500); } if (request()->getIsPostRequest() && isset($_POST['AdminPost'])) { $model->attributes = $_POST['AdminPost']; // 此处如果以后有多种文章模型了,这一句可以去掉。 if ($model->getIsNewRecord()) { $model->user_id = user()->id; $model->user_name = user()->name; $model->post_type = POST_TYPE_POST; } if ($model->save()) { $this->afterPostSave($model); user()->setFlash('save_post_result', t('save_post_success', 'admin', array('{title}' => $model->title, '{url}' => $model->url))); $this->redirect(request()->getUrl()); } } else { $key = param('sess_post_create_token'); if (!app()->session->contains($key) || empty(app()->session[$key])) { $token = $model->getIsNewRecord() ? uniqid('beta', true) : $model->id; app()->session->add($key, $token); } else { $token = app()->session[$key]; $tempPictures = Upload::model()->findAllByAttributes(array('token' => $token)); } } $this->render('create', array('model' => $model, 'tempPictures' => $tempPictures)); }
/** * 批量操作 * */ public function actionBatch() { if ($this->method() == 'GET') { $command = trim($_GET['command']); $ids = intval($_GET['id']); } elseif ($this->method() == 'POST') { $command = trim($_POST['command']); $ids = $_POST['id']; } else { $this->message('errorBack', Yii::t('admin', 'Only POST Or GET')); } empty($ids) && $this->message('error', Yii::t('admin', 'No Select')); switch ($command) { case 'delete': //删除文章 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $image_list = $postModel->image_list; $image_list && ($image_list = unserialize($image_list)); if ($image_list) { foreach ($image_list as $image) { Uploader::deleteFile($image['file']); $file = Upload::model()->findByPk($image['fileId']); if ($file) { $file->delete(); } } } Uploader::deleteFile($postModel->attach_file); Uploader::deleteFile($postModel->attach_thumb); $postModel->delete(); //删除关联的标签 TagData::model()->deleteAll('content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post'])); } } break; case 'show': //文章显示 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->status = 'Y'; $postModel->save(); //更新关联的标签 $tagData = TagData::model()->updateAll(array('status' => 'Y'), 'content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post'])); } } break; case 'hidden': //文章隐藏 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->status = 'N'; $postModel->save(); //更新关联的标签 $tagData = TagData::model()->updateAll(array('status' => 'N'), 'content_id =:id AND type =:type', array(':id' => $id, ':type' => $this->_type_ids['post'])); } } break; case 'commend': //文章推荐 foreach ((array) $ids as $id) { $recom_id = intval($_POST['recom_id']); if ($recom_id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->commend = 'Y'; $postModel->save(); $recom_post = new RecommendPost(); $recom_post->id = $recom_id; $recom_post->post_id = $id; $recom_post->save(); } } else { $this->message('error', Yii::t('admin', 'RecommendPosition is Required')); } } break; case 'stick': //文章置顶 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->top_line = 'Y'; $postModel->save(); } } break; case 'cancelStick': //文章取消置顶 foreach ((array) $ids as $id) { $postModel = Post::model()->findByPk($id); if ($postModel) { $postModel->top_line = 'N'; $postModel->save(); } } break; default: throw new CHttpException(404, Yii::t('admin', 'Error Operation')); break; } $this->message('success', Yii::t('admin', 'Batch Operate Success')); }
<td colspan="2" > <form> <input id="uploadFile" name="uploadFile" type="file" multiple="true"> <ul id="fileList"> <?php if ($model->fileid) { ?> <?php $arr = explode(',', $model->fileid); ?> <?php foreach ((array) $arr as $value) { ?> <?php $file = Upload::model()->findByPk($value); ?> <?php if ($file) { ?> <li id="file_<?php echo $file->id; ?> "> <a href="/<?php echo $file->file_name; ?> "><?php echo $file->real_name; ?> </a><br/>
protected function afterDelete() { $counters = array('post_nums' => -1); Category::model()->updateCounters($counters, 'id = :cid', array(':cid' => $this->category_id)); Topic::model()->updateCounters($counters, 'id = :tid', array(':tid' => $this->topic_id)); $comments = Comment::model()->findAllByAttributes(array('post_id' => $this->id)); foreach ($comments as $c) { $c->delete(); } app()->db->createCommand()->delete(TABLE_POST_TAG, 'post_id = :pid', array(':pid' => $this->id)); app()->db->createCommand()->delete(TABLE_SPECIAL_POST, 'post_id = :pid', array(':pid' => $this->id)); $files = Upload::model()->findAllByAttributes(array('post_id' => $this->id)); foreach ($files as $file) { $file->delete(); } }
/** * * 视频下载 * */ public function actionDownload($id) { $video = Video::model()->findByPk($id); if ($video) { $file = Upload::model()->findByPk($video->fileid); if ($file && file_exists($file->file_name)) { //更新下载次数 $video->updateCounters(array('down_count' => 1), 'id=:id', array('id' => $id)); //开始下载 Yii::app()->request->sendFile($soft->title . '.' . $file->file_ext, file_get_contents($file->file_name)); exit; } else { $this->message('error', Yii::t('common', 'Source Is Not Found'), $this->createUrl('video/view', array('id' => $id))); } } else { $this->message('error', Yii::t('common', 'Source Is Not Found'), $this->createUrl('video/view', array('id' => $id))); } }
/** * Returns the static model of the specified AR class. * @return AdminUpload the static model class */ public static function model($className = __CLASS__) { return parent::model($className); }
/** * * 软件下载 */ public function actionDownload($id) { //限制下载频率 $cookie = Yii::app()->request->getCookies(); $cookie_key = 'DL' . $id . 'TIMES'; $down_cookie = $cookie[$cookie_key]->value; if ($down_cookie) { throw new CHttpException(404, Yii::t('common', 'Access frequency too fast')); } $soft = Soft::model()->findByPk($id); if ($soft) { $file = Upload::model()->findByPk($soft->fileid); if ($file && file_exists($file->file_name)) { //更新下载次数 $soft->updateCounters(array('down_count' => 1), 'id=:id', array('id' => $id)); //存储下载cookie次数 unset($cookie[$cookie_key]); $down = 1; $cookie = new CHttpCookie($cookie_key, $down); $cookie->expire = time() + 20; //20秒之后可以再次下载 Yii::app()->request->cookies[$cookie_key] = $cookie; //开始下载 Yii::app()->request->sendFile($soft->title . '.' . $file->file_ext, file_get_contents($file->file_name), $file->file_mime); exit; } else { throw new CHttpException(404, Yii::t('common', 'Source Is Not Found')); } } else { throw new CHttpException(404, Yii::t('common', 'Source Is Not Found')); } }
public function actionGetImageListXML() { if (Yii::app()->user->isGuest) { return; } $pageNo = 1; if (isset($_REQUEST['pageNo']) && $_REQUEST['pageNo'] > 0) { $pageNo = (int) $_REQUEST['pageNo']; } $offset = ($pageNo - 1) * Yii::app()->params->itemCountInDataListPage; $out = ''; $dataFetchedTimeKey = "ImageController.dataFetchedTime"; if (isset($_REQUEST['list'])) { if ($_REQUEST['list'] == "onlyUpdated") { $time = Yii::app()->session[$dataFetchedTimeKey]; if ($time !== false && $time != "") { $friendList = AuxiliaryFriendsOperator::getFriendIdList(); $sqlCount = 'SELECT ceil(count(*)/' . Yii::app()->params->itemCountInDataListPage . ') FROM ' . Upload::model()->tableName() . ' u WHERE (userId in (' . $friendList . ') OR userId = ' . Yii::app()->user->id . ' OR publicData = 1) AND unix_timestamp(u.uploadTime) >= ' . $time; $pageCount = Yii::app()->db->createCommand($sqlCount)->queryScalar(); $sql = 'SELECT u.Id as id, u.description, s.realname, s.Id as userId, date_format(u.uploadTime,"%d %b %Y %T") as uploadTime, u.altitude, u.latitude, u.longitude FROM ' . Upload::model()->tableName() . ' u LEFT JOIN ' . Users::model()->tableName() . ' s ON s.Id = u.userId WHERE (userId in (' . $friendList . ') OR userId = ' . Yii::app()->user->id . ' OR publicData = 1) AND unix_timestamp(u.uploadTime) >= ' . $time . ' ORDER BY u.Id DESC LIMIT ' . $offset . ' , ' . Yii::app()->params->itemCountInDataListPage; $out = $this->prepareXML($sql, $pageNo, $pageCount, "userList"); } } } else { $friendList = AuxiliaryFriendsOperator::getFriendIdList(); $sqlCount = 'SELECT ceil(count(*)/' . Yii::app()->params->itemCountInDataListPage . ') FROM ' . Upload::model()->tableName() . ' u WHERE userId in (' . $friendList . ') OR userId = ' . Yii::app()->user->id . ' OR publicData = 1'; $pageCount = Yii::app()->db->createCommand($sqlCount)->queryScalar(); $sql = 'SELECT u.Id as id, u.description, s.realname, s.Id as userId, date_format(u.uploadTime,"%d %b %Y %T") as uploadTime, u.altitude, u.latitude, u.longitude FROM ' . Upload::model()->tableName() . ' u LEFT JOIN ' . Users::model()->tableName() . ' s ON s.Id = u.userId WHERE userId in (' . $friendList . ') OR userId = ' . Yii::app()->user->id . ' OR publicData = 1 ORDER BY u.Id DESC LIMIT ' . $offset . ' , ' . Yii::app()->params->itemCountInDataListPage; $out = $this->prepareXML($sql, $pageNo, $pageCount, "imageList"); } echo $out; Yii::app()->session[$dataFetchedTimeKey] = time(); Yii::app()->end(); }
public function actionCreate() { $this->channel = 'contribute'; $form = new PostForm(); if (request()->getIsPostRequest() && isset($_POST['PostForm'])) { $form->attributes = $_POST['PostForm']; if ($form->validate()) { $post = $form->save(); if (!$post->hasErrors()) { user()->setFlash('success_post_id', $post->id); $this->redirect(url('post/success')); exit(0); } } } else { $key = param('sess_post_create_token'); if (!app()->session->contains($key) || empty(app()->session[$key])) { app()->session->add($key, uniqid('beta', true)); } else { $token = app()->session[$key]; $tempPictures = Upload::model()->findAllByAttributes(array('token' => $token)); } } $captchaWidget = $form->hasErrors('captcha') ? $this->widget('BetaCaptcha', array(), true) : $this->widget('BetaCaptcha', array('skin' => 'defaultLazy'), true); $captchaClass = $form->hasErrors('captcha') ? 'error' : 'hide'; $this->setSiteTitle(t('contribute_post')); cs()->registerMetaTag('noindex, follow', 'robots'); $this->render('create', array('form' => $form, 'captchaClass' => $captchaClass, 'captchaWidget' => $captchaWidget, 'tempPictures' => $tempPictures)); }
/** * 批量操作 * */ public function actionBatch() { if ($this->method() == 'GET') { $command = trim($_GET['command']); $ids = intval($_GET['id']); } elseif ($this->method() == 'POST') { $command = trim($_POST['command']); $ids = $_POST['id']; } else { $this->message('errorBack', Yii::t('admin', 'Only POST Or GET')); } empty($ids) && $this->message('error', Yii::t('admin', 'No Select')); switch ($command) { case 'delete': //删除商品 foreach ((array) $ids as $id) { $goodsModel = Goods::model()->findByPk($id); if ($goodsModel) { $image_list = $goodsModel->image_list; $image_list && ($image_list = unserialize($image_list)); if ($image_list) { foreach ($image_list as $image) { Uploader::deleteFile($image['file']); $file = Upload::model()->findByPk($image['fileId']); if ($file) { $file->delete(); } } } Uploader::deleteFile($goodsModel->default_image); Uploader::deleteFile($goodsModel->default_thumb); $goodsModel->delete(); } } break; case 'show': //商品显示 foreach ((array) $ids as $id) { $goodsModel = Goods::model()->findByPk($id); if ($goodsModel) { $goodsModel->status = 'Y'; $goodsModel->save(); } } break; case 'hidden': //商品隐藏 foreach ((array) $ids as $id) { $goodsModel = Goods::model()->findByPk($id); if ($goodsModel) { $goodsModel->status = 'N'; $goodsModel->save(); } } break; case 'commend': //商品推荐 foreach ((array) $ids as $id) { $recom_id = intval($_POST['recom_id']); if ($recom_id) { $goodsModel = Goods::model()->findByPk($id); if ($goodsModel) { $goodsModel->recommend = 'Y'; $goodsModel->save(); } } else { $this->message('error', Yii::t('admin', 'RecommendPosition is Required')); } } break; case 'unCommend': //商品取消推荐 foreach ((array) $ids as $id) { $goodsModel = Goods::model()->findByPk($id); if ($goodsModel) { $goodsModel->commend = 'N'; $goodsModel->save(); } } break; default: throw new CHttpException(404, Yii::t('admin', 'Error Operation')); break; } $this->message('success', Yii::t('admin', 'Batch Operate Success')); }