Пример #1
0
 /**
  * 验证用户具体发帖权限,并不影响其他权限
  * @param type $uid 验证的用户
  * @param type $type 验证的类型
  * @param type $field 是否检查总数
  * @return type
  */
 public static function check($type, $field = false, $uid = '')
 {
     if (!$uid) {
         $uid = Yii::app()->user->id;
     }
     if (!$uid) {
         if (zmf::config('officalUid')) {
             return array('status' => 1, 'msg' => '');
         }
         return array('status' => 0, 'msg' => '用户不存在');
     }
     $uinfo = Users::getUserInfo($uid);
     if (!$uinfo) {
         return array('status' => 0, 'msg' => '用户不存在');
     }
     if (!$uinfo['groupid']) {
         return array('status' => 0, 'msg' => '无组织用户');
     }
     $groupInfo = UserPower::model()->find('groupid=:gid', array(':gid' => $uinfo['groupid']));
     if (!$groupInfo) {
         return array('status' => 0, 'msg' => '无组织用户');
     }
     $num = $groupInfo->getAttribute($type);
     if ($num === null) {
         return array('status' => 0, 'msg' => '无法完成验证的type:' . $type);
     } elseif ($num === 0) {
         return array('status' => 0, 'msg' => '不允许');
     } elseif ($field) {
         switch ($field) {
             case 'addPost':
                 $totalNum = $groupInfo['postNum'];
                 $hasNum = Posts::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addQuestion':
                 $totalNum = $groupInfo['questionNum'];
                 $hasNum = Question::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addAnswer':
                 $totalNum = $groupInfo['answerNum'];
                 $hasNum = Answer::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addPoiPost':
                 $totalNum = $groupInfo['poiPostNum'];
                 $hasNum = PoiPost::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addPoiTips':
                 $totalNum = $groupInfo['poiTipsNum'];
                 $hasNum = PoiTips::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addImage':
                 $totalNum = $groupInfo['imageNum'];
                 $hasNum = Attachments::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addComment':
                 $totalNum = $groupInfo['commentNum'];
                 $hasNum = Comments::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addPlan':
                 $totalNum = $groupInfo['planNum'];
                 $hasNum = Plans::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'yueban':
                 $totalNum = $groupInfo['yuebanNum'];
                 $hasNum = Posts::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
         }
         if (!$totalNum) {
             return array('status' => 1, 'msg' => '无限制');
         } else {
             if ($hasNum >= $totalNum) {
                 return array('status' => 0, 'msg' => '已超出限制:' . $totalNum);
             } else {
                 return array('status' => 1, 'msg' => '');
             }
         }
     } else {
         return array('status' => 1, 'msg' => '');
     }
 }
Пример #2
0
 public function actionView($id)
 {
     $id = zmf::filterInput($id);
     $info = $this->loadModel($id);
     if ($info['redirect'] > 0) {
         $this->redirect(array('position/view', 'id' => $info['redirect']));
     }
     $_title = '';
     if ($info['title_cn'] != '') {
         $_title = $info['title_cn'];
     }
     if ($info['title_en'] != '' && $_title != '') {
         $_title .= '(' . $info['title_en'] . ')';
     } elseif ($info['title_local'] && $_title != '') {
         $_title .= '(' . $info['title_local'] . ')';
     } elseif ($info['title_en'] != '') {
         $_title .= $info['title_en'];
     } else {
         $_title .= $info['title_local'];
     }
     $_address = '';
     if ($info['address_cn'] != '') {
         $_address = $info['address_cn'];
     } elseif ($info['address_en'] != '') {
         $_address = $info['address_en'];
     } else {
         $_address = $info['address_local'];
     }
     if (!Yii::app()->user->isGuest) {
         if (Favorites::checkFavored($id, 'poi')) {
             $this->favorited = true;
         }
         $tipinfo = PoiPost::model()->findByAttributes(array('logid' => $id, 'uid' => Yii::app()->user->id), 'status=' . Posts::STATUS_PASSED);
         if ($tipinfo) {
             $this->tiped = $tipinfo;
         }
     }
     $info->faceimg = Attachments::faceImg($info, 600);
     //获取图片
     $images = Attachments::model()->findAll(array('condition' => "logid=:id AND " . ($info['faceimg'] > 0 ? "id!=" . $info['faceimg'] . ' AND ' : '') . " classify='poi' AND status=" . Posts::STATUS_PASSED, 'select' => 'id,filePath,classify,cTime', 'limit' => 6, 'order' => 'favor DESC', 'params' => array(':id' => $id)));
     $breads = array();
     $breads[] = CHtml::link('目的地', array('position/index'));
     if ($info['areaid']) {
         $areaInfo = Area::model()->findByPk($info['areaid']);
         if ($areaInfo) {
             $breads[] = CHtml::link($areaInfo['title'], array('position/index', 'areaid' => $areaInfo['id']));
         }
     }
     //获取购买地址
     $buylinks = array();
     if ($info['classify'] == Position::HOTEL) {
         $buylinks = Buylink::getAll('poi', $info->id);
     }
     //更新访问统计
     Posts::updateCount($id, 'Position');
     $breads[] = $_title;
     $this->pageTitle = $_title . ' - ' . zmf::config('sitename');
     $this->pageDescription = '【' . $_title . '】位于' . $_address . ',' . zmf::subStr($info['content'], 200);
     $this->render('view', array('info' => $info, 'type' => $type, 'breads' => $breads, 'buylinks' => $buylinks, 'images' => $images));
 }
Пример #3
0
 /**
  * 统计用户的内容数
  */
 public static function getCounts($uid, $info = '')
 {
     if (!$uid) {
         return array();
     }
     if ($info) {
         if (zmf::now() - $info['last_update'] <= 3600) {
             $data = array('posts' => $info['posts'], 'answers' => $info['answers'], 'tips' => $info['tips']);
             return $data;
         }
     }
     $data = array('posts' => Posts::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'answers' => Answer::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'tips' => PoiPost::model()->count('uid=:uid AND status=' . Posts::STATUS_PASSED, array(':uid' => $uid)), 'favors' => Favorites::model()->count('uid=:uid AND classify="user"', array(':uid' => $uid)), 'fans' => Favorites::model()->count('logid=:uid AND classify="user"', array(':uid' => $uid)));
     //将统计数据更新到用户统计表
     $data['last_update'] = zmf::now();
     Users::model()->updateByPk($uid, $data);
     return $data;
 }
Пример #4
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, '新增评论失败');
     }
 }