Ejemplo n.º 1
0
 /**
  * 删除微吧帖子
  * 直接把PC删除的Action代码copy
  *
  * @request int post_id 帖子ID
  * @return bool
  * @author Seven Du <*****@*****.**>
  **/
 public function deletePost()
 {
     //$weiba = D('weiba_post')->where('post_id='.intval($_POST['post_id']))->field('weiba_id,post_uid')->find();
     $post_id = intval($this->data['post_id']);
     $info = D('weiba_post')->where(array('post_id' => array('eq', $post_id)))->find();
     if (!$info || !isset($info['weiba_id'])) {
         return array('status' => 0, 'message' => '帖子不存在或者已经被删除!');
     }
     $post_uid = $info['post_uid'];
     $weiba_id = $info['weiba_id'];
     if (CheckPermission('weiba_normal', 'weiba_del') || $post_uid == $this->mid || CheckWeibaPermission('', $weiba_id)) {
         if ($post_uid != $this->mid && CheckWeibaPermission('', $weiba_id)) {
             return array('status' => 0, 'message' => '你没有权限操作!');
         }
     } else {
         return array('status' => 0, 'message' => '你没有权限操作!');
     }
     if (!CheckWeibaPermission('', $weiba['weiba_id'])) {
         if (!CheckPermission('weiba_normal', 'weiba_del') || $post_uid != $this->mid) {
             return array('status' => 0, 'message' => '你没有权限操作!');
         }
     }
     // D('weiba_post')->where('post_id='.$post_id)->setField('is_del',1)
     $status = D('weiba_post')->where(array('post_id' => array('eq', $post_id)))->setField('is_del', 1);
     if ($status) {
         D('log')->writeLog($info['weiba_id'], $this->mid, '删除了帖子“' . $info['title'] . '”', 'posts');
         // D('weiba')->where('weiba_id='.intval($_POST['weiba_id']))->setDec('thread_count');
         D('weiba')->where(array('weiba_id' => array('eq', $weiba_id)))->setDec('thread_count');
         //添加积分
         model('Credit')->setUserCredit($this->mid, 'delete_topic');
         // 删除相应的分享信息
         model('Feed')->doEditFeed($info['feed_id'], 'delFeed', '', $this->mid);
         /* 删除收藏 */
         D('WeibaPost')->where(array('post_id' => $post_id))->delete();
         return array('status' => 1, 'message' => '删除成功!');
     }
     return array('status' => 0, 'message' => '删除失败!');
 }
 public function postDetail()
 {
     $post_id = intval($_GET['post_id']);
     $post_detail = D('weiba_post')->where('is_del=0 and post_id=' . $post_id)->find();
     $weiba_detail = $this->_top_link($post_detail['weiba_id'], true);
     if (!$post_detail || $weiba_detail['is_del']) {
         $this->error('帖子不存在或已被删除');
     }
     if (D('weiba_favorite')->where('uid=' . $this->mid . ' AND post_id=' . $post_id)->find()) {
         $post_detail['favorite'] = 1;
     }
     if ($post_detail['attach']) {
         $attachids = unserialize($post_detail['attach']);
         $attachinfo = model('Attach')->getAttachByIds($attachids);
         foreach ($attachinfo as $ak => $av) {
             $_attach = array('attach_id' => $av['attach_id'], 'attach_name' => $av['name'], 'attach_url' => getImageUrl($av['save_path'] . $av['save_name']), 'extension' => $av['extension'], 'size' => $av['size']);
             $post_detail['attachInfo'][$ak] = $_attach;
         }
     }
     $post_detail['content'] = html_entity_decode($post_detail['content'], ENT_QUOTES, 'UTF-8');
     $this->assign('post_detail', $post_detail);
     // dump($post_detail);
     D('weiba_post')->where('post_id=' . $post_id)->setInc('read_count');
     $weiba_name = $weiba_detail['weiba_name'];
     $this->assign('weiba_id', $post_detail['weiba_id']);
     $this->assign('weiba_name', $weiba_name);
     // 获得圈主uid
     $map['weiba_id'] = $post_detail['weiba_id'];
     $map['level'] = array('in', '2,3');
     $weiba_admin = getSubByKey(D('weiba_follow')->where($map)->order('level desc')->field('follower_uid')->findAll(), 'follower_uid');
     $weiba_manage = false;
     if (CheckWeibaPermission($weiba_admin, 0, 'weiba_global_top') || CheckWeibaPermission($weiba_admin, 0, 'weiba_top') || CheckWeibaPermission($weiba_admin, 0, 'weiba_recommend') || CheckWeibaPermission($weiba_admin, 0, 'weiba_edit') || CheckWeibaPermission($weiba_admin, 0, 'weiba_del')) {
         $weiba_manage = true;
     }
     $this->assign('weiba_manage', $weiba_manage);
     $this->assign('weiba_admin', $weiba_admin);
     $this->assign('nav', 'weibadetail');
     // $this->user_group ( $post_detail ['post_uid'] );
     // 帖子点评
     unset($map);
     $map['tid'] = $post_id;
     $postcomment = M('weiba_postcomment')->where($map)->order('id desc')->findPage(5);
     $this->assign('postcomment', $postcomment);
     // $this->_assignFollowUidState ( array (
     // $post_detail ['post_uid']
     // ) );
     $this->setTitle($post_detail['title'] . ' - ' . $this->site['site_name']);
     $this->setDescription(getShort(t(bbcode($post_detail['content'])), 200));
     $this->assign('type', $_GET['type'] == 'digg' ? 'digg' : 'time');
     $this->display();
 }
Ejemplo n.º 3
0
 /**
  * 设置帖子类型(置顶或精华)
  * @return void
  */
 public function postSet()
 {
     $post_id = intval($_POST['post_id']);
     $type = intval($_POST['type']);
     if ($type == 1) {
         $field = 'top';
     }
     if ($type == 2) {
         $field = 'digest';
     }
     if ($type == 3) {
         $field = 'recommend';
     }
     $currentValue = intval($_POST['currentValue']);
     $targetValue = intval($_POST['targetValue']);
     if ($targetValue == '1' && $type == 1) {
         $action = 'weiba_top';
     } else {
         if ($targetValue == '2' && $type == 1) {
             $action = 'weiba_global_top';
         } else {
             if ($type == 2) {
                 $action = 'weiba_marrow';
             } else {
                 if ($type == 3) {
                     $action = 'weiba_recommend';
                 }
             }
         }
     }
     $weiba_id = D('weiba_post')->where('post_id=' . $post_id)->getField('weiba_id');
     if ($targetValue == '0' && $type == 1) {
         if (!CheckWeibaPermission('', $weiba_id, 'weiba_top') && !CheckWeibaPermission('', $weiba_id, 'weiba_global_top')) {
             $this->error('对不起,您没有权限进行该操作!');
         }
     } else {
         if (!CheckWeibaPermission('', $weiba_id, $action)) {
             $this->error('对不起,您没有权限进行该操作!');
         }
     }
     if (D('weiba_post')->where('post_id=' . $post_id)->setField($field, $targetValue)) {
         $post_detail = D('weiba_post')->where('post_id=' . $post_id)->find();
         $config['post_name'] = $post_detail['title'];
         $config['post_url'] = '<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>';
         if ($type == 1) {
             switch ($targetValue) {
                 case '0':
                     //取消置顶
                     if ($currentValue == 1) {
                         D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”取消了吧内置顶', 'posts');
                     } else {
                         D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”取消了全局置顶', 'posts');
                     }
                     //添加积分
                     model('Credit')->setUserCredit($post_detail['post_uid'], 'untop_topic_all');
                     break;
                 case '1':
                     //设为吧内置顶
                     $config['typename'] = "吧内置顶";
                     model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                     D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”设为了吧内置顶', 'posts');
                     //添加积分
                     model('Credit')->setUserCredit($post_detail['post_uid'], 'top_topic_weiba');
                     break;
                 case '2':
                     //设为全局置顶
                     $config['typename'] = "全局置顶";
                     model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                     D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”设为了全局置顶', 'posts');
                     //添加积分
                     model('Credit')->setUserCredit($post_detail['post_uid'], 'top_topic_all');
                     break;
             }
         }
         if ($type == 2) {
             switch ($targetValue) {
                 case '0':
                     //取消精华
                     D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”取消了精华', 'posts');
                     break;
                 case '1':
                     //设为精华
                     $config['typename'] = "精华";
                     model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                     D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”设为了精华', 'posts');
                     //添加积分
                     model('Credit')->setUserCredit($post_detail['post_uid'], 'dist_topic');
                     break;
             }
         }
         if ($type == 3) {
             switch ($targetValue) {
                 case '0':
                     //取消推荐
                     D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”取消了推荐', 'posts');
                     break;
                 case '1':
                     //设为推荐
                     $config['typename'] = "推荐";
                     model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                     D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”设为了推荐', 'posts');
                     //添加积分
                     model('Credit')->setUserCredit($post_detail['post_uid'], 'recommend_topic');
                     break;
             }
         }
         echo 1;
     } else {
         echo 0;
     }
 }
Ejemplo n.º 4
0
 /**
  * 删除帖子
  * @return void
  */
 public function postDel()
 {
     $post_id = intval($this->data['post_id']);
     $user_id = empty($this->user_id) ? $this->mid : $this->user_id;
     $post_id || $this->error('参数异常');
     $user_id || $this->error('请先登录');
     $weiba = D('weiba_post')->where('post_id=' . $post_id)->field('weiba_id,post_uid,feed_id,title')->find();
     if (CheckPermission('weiba_normal', 'weiba_del') || $weiba['post_uid'] == $user_id || CheckWeibaPermission('', $weiba['weiba_id'])) {
         //判断删帖权限
         if ($weiba['post_uid'] != $user_id) {
             //判断是否本人
             if (!CheckWeibaPermission('', $weiba['weiba_id'])) {
                 //判断管理员或圈主
                 $this->error('没有权限删除1');
             }
         }
     } else {
         $this->error('没有权限删除2');
     }
     if (!CheckWeibaPermission('', $weiba['weiba_id'])) {
         //判断管理员或圈主
         if (!CheckPermission('weiba_normal', 'weiba_del') || $weiba['post_uid'] != $user_id) {
             $this->error('没有权限删除3');
         }
     }
     if (D('weiba_post')->where('post_id=' . $post_id)->setField('is_del', 1)) {
         //记录删除操作
         D('log', 'weiba')->writeLog($weiba['weiba_id'], $user_id, '删除了帖子“' . $weiba['title'] . '”', 'posts');
         M('weiba')->where('weiba_id=' . intval($weiba['weiba_id']))->setDec('thread_count');
         M('weiba_favorite')->where(array('post_id' => $post_id))->delete();
         //添加积分
         model('Credit')->setUserCredit($user_id, 'delete_topic');
         // 删除相应的分享信息
         model('Feed')->doEditFeed($weiba['feed_id'], 'delFeed', '', $user_id);
         if (CheckWeibaPermission('', $weiba['weiba_id'])) {
             //判断管理员或圈主
             if (!$weiba['post_uid'] != $user_id) {
                 //判断是否本人
                 $data = array('weiba_id' => $weiba['weiba_id'], 'post_id' => $post_id, 'post_uid' => $weiba['post_uid'], 'uid' => $user_id, 'ctime' => time(), 'content' => '您的帖子已被管理员或圈主删除', 'type' => 2);
                 D('weiba_reply')->add($data);
             }
         }
         $this->success('删除成功');
     } else {
         $this->success('删除失败');
     }
 }