/** * 不入数据库的上传 * 不做压缩和缩略图处理 */ public function actionSimpleUpload() { $uptype = zmf::filterInput($_GET['type'], 't', 1); $fileholder = zmf::filterInput($_GET['fileholder'], 't', 1); //上传控件的ID $fileName = zmf::filterInput($_GET['fileName'], 't', 1); //上传后保存名字 $keyid = zmf::filterInput($_GET['keyid']); //所属对象ID if (!isset($uptype) or !in_array($uptype, array('topArea', 'avatar'))) { $this->jsonOutPut(0, '请设置上传所属类型' . $uptype); } if (Yii::app()->request->getParam('PHPSESSID')) { Yii::app()->session->close(); Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID')); Yii::app()->session->open(); } if (Yii::app()->user->isGuest) { $this->jsonOutPut(0, Yii::t('default', 'loginfirst')); } if ($uptype == 'avatar' && !$keyid) { $this->jsonOutPut(0, '缺少参数'); } $checkInfo = UserPower::check('addImage', true); if (!$checkInfo['status']) { $this->jsonOutPut(0, $checkInfo['msg']); } if (!$fileholder) { $fileholder = 'filedata'; } if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) { $this->jsonOutPut(0, '无效上传,请重试'); } $img = CUploadedFile::getInstanceByName($fileholder); $ext = $img->getExtensionName(); $size = $img->getSize(); if ($size > zmf::config('imgMaxSize')) { $this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize'))); } $upExt = zmf::config("imgAllowTypes"); if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) { $this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt); } if (!$fileName) { $fileName = uniqid() . '.' . $ext; } if ($uptype == 'avatar') { $fileName = $keyid . '.jpg'; } if ($uptype == 'topArea') { $todir = zmf::attachBase('app') . '/daodao/'; $returnDir = zmf::attachBase('site') . '/daodao/'; } elseif ($uptype == 'avatar') { $todir = zmf::attachBase('app') . '/avatar/origin/' . $keyid . '/'; $todir2 = zmf::attachBase('app') . '/avatar/big/' . $keyid . '/'; $todir3 = zmf::attachBase('app') . '/avatar/small/' . $keyid . '/'; $returnDir = zmf::attachBase('site') . '/avatar/small/' . $keyid . '/'; } zmf::createUploadDir($todir); if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $todir . $fileName)) { if ($uptype == 'avatar') { $image = Yii::app()->image->load($todir . $fileName); zmf::createUploadDir($todir2); zmf::createUploadDir($todir3); $image->smart_resize(100, 100)->quality(95); $image->save($todir2 . $fileName); $image->smart_resize(50, 50)->quality(95); $image->save($todir3 . $fileName); } $outPutData = array('status' => 1, 'imgsrc' => $returnDir . $fileName, 'attachid' => ''); $json = CJSON::encode($outPutData); echo $json; } else { $this->jsonOutPut(0, '上传失败'); } }
/** * 写评论 */ public function actionComment() { if (!Yii::app()->request->isAjaxRequest) { $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction')); } if (Yii::app()->user->isGuest) { $this->jsonOutPut(2, Yii::t('default', 'loginfirst')); } else { $uid = zmf::uid(); } $checkInfo = UserPower::check('addComment', true); if (!$checkInfo['status']) { $this->jsonOutPut(0, $checkInfo['msg']); } $keyid = zmf::filterInput($_POST['k']); $to = zmf::filterInput($_POST['to']); $type = zmf::filterInput($_POST['t'], 't', 1); $content = zmf::filterInput($_POST['c'], 't', 1); if (!isset($type) or !in_array($type, array('attachments', 'posts', 'poipost', 'poitips', 'question', 'answer', 'yueban', 'goods'))) { $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction')); } if (!isset($keyid) or !is_numeric($keyid)) { $this->jsonOutPut(0, Yii::t('default', 'pagenotexists')); } if (!$content) { $this->jsonOutPut(0, '评论不能为空哦~'); } $status = Posts::STATUS_PASSED; //判断是否应被禁止 // $forbidInfo = Posts::isForbidden($content, 'comment'); // if ($forbidInfo['status'] != Posts::STATUS_PASSED) { // //todo,增加用户非法操作次数 // $status = Posts::STATUS_STAYCHECK; // } //处理文本 $filter = Posts::handleContent($content); $content = $filter['content']; if (Yii::app()->session['checkHasBadword'] == 'yes') { $status = Posts::STATUS_STAYCHECK; } $model = new Comments(); $ainfo = Posts::getSimpleInfo(array('keyid' => $keyid, 'origin' => strtolower($type))); if (!$ainfo) { $this->jsonOutPut(0, Yii::t('default', 'contentnotexists')); } $toNotice = true; if ($ainfo['uid'] == $uid) { $toNotice = false; } //当为商品评论且不是回复某人时,不提醒发布商品的人 if ($type == 'goods' && !$to) { $toNotice = false; } $touid = $ainfo['uid']; if ($to) { $comInfo = Posts::getSimpleInfo(array('keyid' => $to, 'origin' => 'comments')); if (!$comInfo || $comInfo['status'] != Posts::STATUS_PASSED) { $to = ''; } elseif ($comInfo['uid'] == $uid) { $toNotice = false; } else { $touid = $comInfo['uid']; $toNotice = true; } } $intoData = array('logid' => $keyid, 'uid' => $uid, 'content' => $content, 'cTime' => zmf::now(), 'classify' => $type, 'platform' => $this->platform, 'tocommentid' => $to, 'status' => $status); unset(Yii::app()->session['checkHasBadword']); $model->attributes = $intoData; if ($model->validate()) { if ($model->save()) { if ($type == 'answer') { Answer::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid)); $_url = CHtml::link('查看详情', array('question/answer', 'id' => $keyid, '#' => 'pid-' . $model->id)); $_content = '您的回答有了新的评论,' . $_url; } elseif ($type == 'poitips') { PoiTips::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid)); $_url = CHtml::link('查看详情', array('question/answer', 'id' => $keyid, '#' => 'pid-' . $model->id)); $_content = '您的短评有了新的评论,' . $_url; } elseif ($type == 'poipost') { $_url = CHtml::link('查看详情', array('poipost/view', 'id' => $keyid, '#' => 'pid-' . $model->id)); PoiPost::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid)); $_content = '您的点评有了新的评论,' . $_url; } elseif ($type == 'question') { $_url = CHtml::link('查看详情', array('question/view', 'id' => $keyid, '#' => 'pid-' . $model->id)); Question::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid)); $_content = '您的提问有了新的评论,' . $_url; } elseif ($type == 'posts') { $_url = CHtml::link('查看详情', array('posts/index', 'id' => $keyid, '#' => 'pid-' . $model->id)); Posts::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid)); $_content = '您的文章有了新的评论,' . $_url; } elseif ($type == 'attachments') { $_url = CHtml::link('查看详情', array('attachments/view', 'id' => $keyid, '#' => 'pid-' . $model->id)); Attachments::model()->updateCounters(array('comments' => 1), 'id=:id', array(':id' => $keyid)); $_content = '您的图片有了新的评论,' . $_url; } elseif ($type == 'yueban') { $_url = CHtml::link('查看详情', array('yueban/index', 'areaid' => $ainfo['toAreaid'], 'year' => zmf::time($ainfo['startTime'], 'Y'), 'month' => zmf::time($ainfo['startTime'], 'm'), 'day' => zmf::time($ainfo['startTime'], 'd'))); Posts::updateCount($keyid, 'UserYueban', 1, 'comments'); $_content = '您的约伴有了新的评论,' . $_url; } elseif ($type == 'goods') { $_url = CHtml::link('查看详情', array('goods/detail', 'id' => $keyid, '#' => 'pid-' . $model->id)); Posts::updateCount($keyid, 'Goods', 1, 'comments'); $_content = '您的产品有了新的评论,' . $_url; } if ($to && $_url) { $_content = '您的评论有了新的回复,' . $_url; } if ($toNotice) { $_noticedata = array('uid' => $touid, 'authorid' => $uid, 'content' => $_content, 'new' => 1, 'type' => 'comment', 'cTime' => zmf::now(), 'from_id' => $model->id, 'from_num' => 1); Notification::add($_noticedata); } $html = $this->renderPartial('//comments/_comment', array('data' => $model), true); $this->jsonOutPut(1, $html); } else { $this->jsonOutPut(0, '新增评论失败'); } } else { $this->jsonOutPut(0, '新增评论失败'); } }