public function comment()
 {
     if (!CheckPermission('core_normal', 'feed_comment')) {
         return -1;
     }
     $feedInfo = model('Feed')->getFeedInfo($this->data['row_id']);
     $ifShareFeed = isset($this->data['ifShareFeed']) ? $this->data['ifShareFeed'] : '0';
     if (isset($this->data['app_name'])) {
         $data['app'] = $this->data['app_name'];
     } elseif (in_array($feedInfo['app'], array('weiba'))) {
         $data['app'] = 'weiba';
     } else {
         $data['app'] = 'public';
     }
     $data['table'] = isset($this->data['table_name']) ? $this->data['table_name'] : 'feed';
     $data['app_row_id'] = isset($this->data['app_row_id']) ? $this->data['app_row_id'] : '0';
     $data['app_row_table'] = isset($this->data['app_row_table']) ? $this->data['app_row_table'] : 'feed';
     $data['app_uid'] = isset($this->data['app_uid']) ? $this->data['app_uid'] : '0';
     $data['comment_old'] = isset($this->data['comment_old']) ? $this->data['comment_old'] : '0';
     $data['content'] = isset($this->data['content']) ? $this->data['content'] : '';
     //评论内容
     $data['row_id'] = isset($this->data['row_id']) ? $this->data['row_id'] : '0';
     $data['to_comment_id'] = isset($this->data['to_comment_id']) ? $this->data['to_comment_id'] : '0';
     $data['to_uid'] = isset($this->data['to_uid']) ? $this->data['to_uid'] : '0';
     $data['at'] = $this->data['at'];
     if ($data['comment_id'] = model('Comment')->addComment($data, true)) {
         //转发到我的分享
         if ($ifShareFeed == 1) {
             //根据评论的对象获取原来的内容
             $s['sid'] = $data['row_id'];
             $s['app_name'] = $data['app'];
             // w3g版本用到
             if (APP_NAME == 'w3g' && $data['comment_old'] != '') {
                 $s['body'] = $data['content'] . '//@' . $data['at'] . ':' . $data['comment_old'];
             } else {
                 // Android IOS
                 $commentInfo = model('Source')->getSourceInfo($data['table'], $data['row_id'], false, $data['app']);
                 $oldInfo = isset($commentInfo['sourceInfo']) ? $commentInfo['sourceInfo'] : $commentInfo;
                 // 根据评论的对象获取原来的内容
                 $arr = array('post', 'postimage', 'postfile', 'weiba_post', 'postvideo');
                 $scream = '';
                 if (!in_array($feedInfo['type'], $arr)) {
                     $scream = '//@' . $commentInfo['source_user_info']['uname'] . ':' . $commentInfo['source_content'];
                 }
                 if (!empty($data['to_comment_id'])) {
                     $replyInfo = model('Comment')->init($data['app'], $data['table'])->getCommentInfo($data['to_comment_id'], false);
                     $replyScream = '//@' . $replyInfo['user_info']['uname'] . ' :';
                     $data['content'] .= $replyScream . $replyInfo['content'];
                 }
                 $s['body'] = $data['content'] . $scream;
             }
             $s['type'] = 'feed';
             $s['comment'] = $data['comment_old'];
             $s['comment_touid'] = $data['app_uid'];
             $s['from'] = $this->data['from'];
             // 如果为原创分享,不给原创用户发送@信息
             if ($feedInfo['type'] == 'post' && empty($data['to_uid'])) {
                 $lessUids[] = $this->mid;
             }
             //接触转发到我的分享的时间限制
             unlockSubmit();
             model('Share')->shareFeed($s, 'comment', $lessUids);
         }
         if (in_array($feedInfo['app'], array('weiba'))) {
             $wdata['row_id'] = $data['row_id'];
             $wdata['to_comment_id'] = $data['to_comment_id'];
             $wdata['to_uid'] = $data['to_uid'];
             $wdata['content'] = $data['content'];
             $wdata['comment_id'] = $data['comment_id'];
             $this->_upateToweiba($wdata);
         }
         return array('status' => 1, 'info' => '评论成功');
     } else {
         return array('status' => 0, 'info' => '评论失败');
     }
 }
 /**
  * 添加评论的操作
  *
  * @return array 评论添加状态和提示信息
  */
 public function addcomment()
 {
     // 返回结果集默认值
     $return = array('status' => 0, 'data' => L('PUBLIC_CONCENT_IS_ERROR'));
     // 获取接收数据
     $data = $_POST;
     // 安全过滤
     foreach ($data as $key => $val) {
         $data[$key] = t($data[$key]);
     }
     // 评论所属与评论内容
     $data['app'] = $data['app_name'];
     $data['table'] = $data['table_name'];
     $data['content'] = h($data['content']);
     // 判断资源是否被删除
     $dao = M($data['table']);
     $idField = $dao->getPk();
     $map[$idField] = $data['row_id'];
     $sourceInfo = $dao->where($map)->find();
     if (!$sourceInfo) {
         $return['status'] = 0;
         $return['data'] = '内容已被删除,评论失败';
         exit(json_encode($return));
     }
     //兼容旧方法
     if (empty($data['app_detail_summary'])) {
         $source = model('Source')->getSourceInfo($data['table'], $data['row_id'], false, $data['app']);
         $data['app_detail_summary'] = $source['source_body'];
         $data['app_detail_url'] = $source['source_url'];
         $data['app_uid'] = $source['source_user_info']['uid'];
     } else {
         $data['app_detail_summary'] = $data['app_detail_summary'] . '<a class="ico-details" href="' . $data['app_detail_url'] . '"></a>';
     }
     // 添加评论操作
     $data['comment_id'] = model('Comment')->addComment($data);
     if ($data['comment_id']) {
         $return['status'] = 1;
         $return['data'] = $this->parseComment($data);
         // 同步到微吧
         if ($data['app'] == 'weiba') {
             $this->_upateToweiba($data);
         }
         // 去掉回复用户@
         $lessUids = array();
         if (!empty($data['to_uid'])) {
             $lessUids[] = $data['to_uid'];
         }
         if ($_POST['ifShareFeed'] == 1) {
             // 转发到我的微博
             //解锁内容发布
             unlockSubmit();
             $this->_updateToweibo($data, $sourceInfo, $lessUids);
         } else {
             if ($data['comment_old'] != 0) {
                 // 是否评论给原来作者
                 unlockSubmit();
                 $this->_updateToComment($data, $sourceInfo, $lessUids);
             }
         }
     }
     !$data['comment_id'] && ($return['data'] = model('Comment')->getError());
     exit(json_encode($return));
 }
 /**
  * 添加评论的操作
  *
  * @return array 评论添加状态和提示信息
  */
 public function addcomment()
 {
     // 返回结果集默认值
     $return = array('status' => 0, 'data' => L('PUBLIC_CONCENT_IS_ERROR'));
     // 获取接收数据
     $data['app'] = t($_POST['app_name']);
     $data['table'] = t($_POST['table_name']);
     //model ( 'Comment' )->addComment已针对$data['content']转义,请勿重复操作
     //$data ['content'] = h ( $_POST ['content'] );
     $data['content'] = $_POST['content'];
     $data['app_uid'] = intval($_POST['app_uid']);
     $data['app_row_id'] = intval($_POST['app_row_id']);
     $data['app_row_table'] = t($_POST['app_row_table']);
     $data['row_id'] = intval($_POST['row_id']);
     $data['to_comment_id'] = intval($_POST['to_comment_id']);
     $data['to_uid'] = intval($_POST['to_uid']);
     $data['ifShareFeed'] = intval($_POST['ifShareFeed']);
     $data['comment_old'] = intval($_POST['comment_old']);
     $data['app_detail_summary'] = t($_POST['app_detail_summary']);
     $source = model('Source')->getSourceInfo($data['table'], $data['row_id'], false, $data['app']);
     $uid = $source['uid'];
     if ($this->mid != $uid) {
         $userPrivacy = model('UserPrivacy')->getPrivacy($this->mid, $uid);
         if ($userPrivacy['comment_weibo'] == 1) {
             exit(json_encode(array('status' => 0, 'data' => L('PUBLIC_CONCENT_TIPES'))));
         }
     }
     $filterContentStatus = filter_words($data['content']);
     if (!$filterContentStatus['status']) {
         exit(json_encode(array('status' => 0, 'data' => $filterContentStatus['data'])));
     }
     $data['content'] = $filterContentStatus['data'];
     // 判断资源是否被删除
     $dao = M($data['table']);
     $idField = $dao->getPk();
     $map[$idField] = intval($data['row_id']);
     $sourceInfo = $dao->where($map)->find();
     if (!$sourceInfo) {
         $return['status'] = 0;
         $return['data'] = '内容已被删除,评论失败';
         exit(json_encode($return));
     }
     //兼容旧方法
     if (empty($data['app_detail_summary'])) {
         $source = model('Source')->getSourceInfo($data['table'], $data['row_id'], false, $data['app']);
         $data['app_detail_summary'] = $source['source_body'];
         $data['app_detail_url'] = $source['source_url'];
         $data['app_uid'] = $source['source_user_info']['uid'];
     } else {
         $data['app_detail_summary'] = $data['app_detail_summary'] . '<a class="ico-details" href="' . $data['app_detail_url'] . '"></a>';
     }
     // 添加评论操作
     $data['comment_id'] = model('Comment')->addComment($data);
     $return['sql'] = D()->getLastSql();
     if ($data['comment_id']) {
         $talkbox = intval($_POST['talkbox']);
         $return['status'] = 1;
         $return['data'] = $this->parseComment($data, $talkbox);
         // 同步到微吧
         if ($data['app'] == 'weiba') {
             $this->_upateToweiba($data);
         }
         // 去掉回复用户@
         $lessUids = array();
         if (!empty($data['to_uid'])) {
             $lessUids[] = $data['to_uid'];
         }
         if ($_POST['ifShareFeed'] == 1) {
             // 转发到我的分享
             //解锁内容发布
             unlockSubmit();
             $this->_updateToweibo($data, $sourceInfo, $lessUids);
         } else {
             if ($data['comment_old'] != 0) {
                 // 是否评论给原来作者
                 unlockSubmit();
                 $this->_updateToComment($data, $sourceInfo, $lessUids);
             }
         }
     }
     !$data['comment_id'] && ($return['data'] = model('Comment')->getError());
     exit(json_encode($return));
 }
Esempio n. 4
0
    public function addComment()
    {
        // 返回结果集默认值
        $return = array('status' => 0, 'data' => L('PUBLIC_CONCENT_IS_ERROR'));
        // 获取接收数据
        $data = $_POST;
        // 安全过滤
        foreach ($data as $key => $val) {
            $data[$key] = t($data[$key]);
        }
        // 评论所属与评论内容
        $data['app'] = $data['app_name'];
        $data['table'] = $data['table_name'];
        $data['content'] = h($data['content']);
        // 判断资源是否被删除
        $dao = M($data['table']);
        $idField = $dao->getPk();
        $map[$idField] = $data['row_id'];
        $sourceInfo = $dao->where($map)->find();
        if (!$sourceInfo) {
            $return['status'] = 0;
            $return['data'] = '内容已被删除,评论失败';
            exit(json_encode($return));
        }
        //兼容旧方法
        if (empty($data['app_detail_summary'])) {
            $source = model('Source')->getSourceInfo($data['table'], $data['row_id'], false, $data['app']);
            $data['app_detail_summary'] = $source['source_body'];
            $data['app_detail_url'] = $source['source_url'];
            $data['app_uid'] = $source['source_user_info']['uid'];
        } else {
            $data['app_detail_summary'] = $data['app_detail_summary'] . '<a class="ico-details" href="' . $data['app_detail_url'] . '"></a>';
        }
        // 添加评论操作
        $data['comment_id'] = model('Comment')->addComment($data);
        if ($data['comment_id']) {
            $return['status'] = 1;
            $commentInfo = model('Comment')->getCommentInfo($data['comment_id']);
            $html = '<dl class="comment_list" id="comment_list_' . $commentInfo['comment_id'] . '">
				<dt><a href="' . $commentInfo['user_info']['space_url'] . '"><img src="' . $commentInfo['user_info']['avatar_tiny'] . '" width="30" height="30"/></a></dt>
				<dd>
				<p class="cont">' . $commentInfo['user_info']['space_link'] . ':<em>' . str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($commentInfo['content'])) . '<span class="time">(' . friendlyDate($commentInfo['ctime']) . ')</span></em></p>
				<p class="right mt5"><span><a href="javascript:;" onclick="deleteComment(' . $commentInfo['comment_id'] . ');">删除</a><i class="vline">|</i><a href="javascript:;" onclick="replyComment(\'' . $commentInfo['user_info']['uname'] . '\', ' . $commentInfo['user_info']['uid'] . ', ' . $commentInfo['comment_id'] . ');">回复</a></span></p>
				</dd>
				<!-- <span class="floor">' . $commentInfo['storey'] . '楼</span> -->
				</dl>';
            $return['data'] = $html;
            // 去掉回复用户@
            $lessUids = array();
            if (!empty($data['to_uid'])) {
                $lessUids[] = $data['to_uid'];
            }
            if ($_POST['ifShareFeed'] == 1) {
                // 转发到我的微博
                unlockSubmit();
                $this->_updateToweibo($data, $sourceInfo, $lessUids);
            } else {
                if ($data['comment_old'] != 0) {
                    // 是否评论给原来作者
                    unlockSubmit();
                    $this->_updateToComment($data, $sourceInfo, $lessUids);
                }
            }
        }
        exit(json_encode($return));
    }
 /**
  * 添加帖子回复的操作
  * @return array 评论添加状态和提示信息
  */
 public function addReply()
 {
     //   echo $_POST['post_id'];exit;
     if (!$this->mid || !CheckPermission('weiba_normal', 'weiba_reply')) {
         return;
     }
     $return = array('status' => 0, 'data' => L('PUBLIC_CONCENT_IS_ERROR'));
     $type = intval($_POST['type']);
     $data['weiba_id'] = intval($_POST['weiba_id']);
     $data['post_id'] = intval($_POST['post_id']);
     $data['post_uid'] = intval($_POST['post_uid']);
     $data['to_reply_id'] = intval($_POST['to_reply_id']);
     $data['to_uid'] = intval($_POST['to_uid']);
     $data['uid'] = $this->mid;
     $data['ctime'] = time();
     $data['content'] = h($_POST['content']);
     if (isSubmitLocked()) {
         $return['status'] = 0;
         $return['data'] = '发布内容过于频繁,请稍后再试!';
         exit(json_encode($return));
     }
     if ($data['reply_id'] = D('weiba_reply')->add($data)) {
         // 锁定发布
         lockSubmit();
         //添加积分
         model('Credit')->setUserCredit(intval($_POST['post_uid']), 'comment_topic');
         model('Credit')->setUserCredit($data['to_uid'], 'commented_topic');
         $map['last_reply_uid'] = $this->mid;
         $map['last_reply_time'] = $data['ctime'];
         if ($data['to_reply_id'] == 0) {
             $map['reply_count'] = array('exp', "reply_count+1");
         }
         $map['reply_all_count'] = array('exp', "reply_all_count+1");
         D('weiba_post')->where('post_id=' . $data['post_id'])->save($map);
         //同步到微博评论
         //$feed_id = intval($_POST['feed_id']);
         $datas['app'] = 'weiba';
         $datas['table'] = 'feed';
         $datas['content'] = h($data['content']);
         $datas['app_uid'] = intval($_POST['post_uid']);
         $datas['row_id'] = intval($_POST['feed_id']);
         $datas['to_comment_id'] = $data['to_reply_id'] ? D('weiba_reply')->where('reply_id=' . $data['to_reply_id'])->getField('comment_id') : 0;
         $datas['to_uid'] = intval($_POST['to_uid']);
         $datas['uid'] = $this->mid;
         $datas['ctime'] = time();
         $datas['client_type'] = getVisitorClient();
         // 解锁
         unlockSubmit();
         if ($comment_id = model('Comment')->addComment($datas)) {
             $data1['comment_id'] = $comment_id;
             // $data1['storey'] = model('Comment')->where('comment_id='.$comment_id)->getField('storey');
             D('weiba_reply')->where('reply_id=' . $data['reply_id'])->save($data1);
             // 给应用UID添加一个未读的评论数
             if ($GLOBALS['ts']['mid'] != $datas['app_uid'] && $datas['app_uid'] != '') {
                 !$notCount && model('UserData')->updateKey('unread_comment', 1, true, $datas['app_uid']);
             }
             model('Feed')->cleanCache($datas['row_id']);
         }
         //转发到我的微博
         if ($_POST['ifShareFeed'] == 1) {
             $commentInfo = model('Source')->getSourceInfo($datas['table'], $datas['row_id'], false, $datas['app']);
             $oldInfo = isset($commentInfo['sourceInfo']) ? $commentInfo['sourceInfo'] : $commentInfo;
             // 根据评论的对象获取原来的内容
             $s['sid'] = $data['post_id'];
             $s['app_name'] = 'weiba';
             if (!empty($data['to_comment_id'])) {
                 $replyInfo = model('Comment')->init($data['app'], $data['table'])->getCommentInfo($data['to_comment_id'], false);
                 $data['content'] .= $replyInfo['content'];
             }
             $s['body'] = $data['content'];
             $s['type'] = 'weiba_post';
             $s['comment'] = $data['comment_old'];
             // 去掉回复用户@
             $lessUids = array();
             if (!empty($data['to_uid'])) {
                 $lessUids[] = $data['to_uid'];
             }
             // 如果为原创微博,不给原创用户发送@信息
             if ($oldInfo['feedtype'] == 'post' && empty($data['to_uid'])) {
                 $lessUids[] = $oldInfo['uid'];
             }
             unlockSubmit();
             model('Share')->shareFeed($s, 'comment', $lessUids);
         }
         $data['feed_id'] = $datas['row_id'];
         $data['comment_id'] = $comment_id;
         $data['storey'] = $data1['storey'];
         $return['status'] = 1;
         if ($type == 2) {
             $return['data'] = $this->parseRightReply($data);
         } else {
             $return['data'] = $this->parseReply($data);
         }
     }
     echo json_encode($return);
     exit;
 }
Esempio n. 6
0
 /**
  * 评论帖子 --using
  *
  * @param
  *        	integer post_id 帖子ID
  * @param
  *        	integer to_comment_id 评论ID
  * @param
  *        	string content 评论内容
  * @param
  *        	integer from 来源(2-android 3-iPhone)
  * @return array 状态+提示
  */
 public function comment_post()
 {
     $return['status'] = 0;
     $return['msg'] = '发布失败';
     //检测用户是否被禁言
     if ($isDisabled = model('DisableUser')->isDisableUser($this->mid, 'post')) {
         return array('status' => 0, 'msg' => '您已经被禁言了');
     }
     if (!t($this->data['content'])) {
         $return['msg'] = '评论内容不能为空';
         return $return;
     }
     if (!intval($this->data['post_id'])) {
         $return['msg'] = '参数非法';
         return $return;
     }
     if (!$this->mid || !CheckPermission('weiba_normal', 'weiba_reply')) {
         $return['msg'] = '你无权发布';
         return $return;
     }
     $feed_detail = M('weiba_post')->where('post_id=' . intval($this->data['post_id']))->find();
     $data['weiba_id'] = intval($feed_detail['weiba_id']);
     $data['post_id'] = intval($this->data['post_id']);
     $data['post_uid'] = intval($feed_detail['post_uid']);
     if (!empty($this->data['to_comment_id'])) {
         $data['to_reply_id'] = intval($this->data['to_comment_id']);
         $data['to_uid'] = model('Comment')->where('comment_id=' . intval($this->data['to_comment_id']))->getField('uid');
     }
     $data['uid'] = $this->mid;
     $data['ctime'] = time();
     $data['content'] = preg_html(h($this->data['content']));
     /* # 格式化emoji */
     $data['content'] = formatEmoji(true, $data['content']);
     $data['attach_id'] = intval($this->data['attach_id']);
     $filterContentStatus = filter_words($data['content']);
     if (!$filterContentStatus['status']) {
         return array('status' => 0, 'msg' => $filterContentStatus['data']);
     }
     $data['content'] = $filterContentStatus['data'];
     if (isSubmitLocked()) {
         $return['msg'] = '发布内容过于频繁,请稍后再试!';
         return $return;
     }
     if ($data['reply_id'] = D('weiba_reply')->add($data)) {
         // 锁定发布
         lockSubmit();
         // 添加积分
         model('Credit')->setUserCredit(intval($data['post_uid']), 'comment_topic');
         model('Credit')->setUserCredit($data['to_uid'], 'commented_topic');
         $map['last_reply_uid'] = $this->mid;
         $map['last_reply_time'] = $data['ctime'];
         $map['reply_count'] = array('exp', 'reply_count+1');
         $map['reply_all_count'] = array('exp', 'reply_all_count+1');
         D('weiba_post')->where('post_id=' . $data['post_id'])->save($map);
         // 同步到微博评论
         $datas['app'] = 'weiba';
         $datas['table'] = 'feed';
         $datas['content'] = preg_html($data['content']);
         $datas['app_uid'] = intval($feed_detail['post_uid']);
         $datas['row_id'] = intval($feed_detail['feed_id']);
         $datas['to_comment_id'] = $data['to_reply_id'] ? D('weiba_reply')->where('reply_id=' . $data['to_reply_id'])->getField('comment_id') : 0;
         $datas['to_uid'] = intval($data['to_uid']);
         $datas['uid'] = $this->mid;
         $datas['ctime'] = time();
         $datas['client_type'] = getVisitorClient();
         // $datas ['from'] = 'weiba';
         $data['cancomment'] = 1;
         // 解锁
         unlockSubmit();
         if ($comment_id = model('Comment')->addComment($datas)) {
             $data1['comment_id'] = $comment_id;
             // $data1['storey'] = model('Comment')->where('comment_id='.$comment_id)->getField('storey');
             D('weiba_reply')->where('reply_id=' . $data['reply_id'])->save($data1);
             // 给应用UID添加一个未读的评论数
             // if ($GLOBALS ['ts'] ['mid'] != $datas ['app_uid'] && $datas ['app_uid'] != '') {
             //     ! $notCount && model('UserData')->updateKey('unread_comment_weiba', 1, true, $datas ['app_uid']);
             // }
             model('Feed')->cleanCache($datas['row_id']);
         }
         // 转发到我的微博
         if ($this->data['ifShareFeed'] == 1) {
             $commentInfo = model('Source')->getSourceInfo($datas['table'], $datas['row_id'], false, $datas['app']);
             $oldInfo = isset($commentInfo['sourceInfo']) ? $commentInfo['sourceInfo'] : $commentInfo;
             // 根据评论的对象获取原来的内容
             $s['sid'] = $data['post_id'];
             $s['app_name'] = 'weiba';
             if (!empty($data['to_comment_id'])) {
                 $replyInfo = model('Comment')->init($data['app'], $data['table'])->getCommentInfo($data['to_comment_id'], false);
                 $data['content'] .= $replyInfo['content'];
             }
             $s['body'] = $data['content'];
             $s['type'] = 'weiba_post';
             $s['comment'] = $data['comment_old'];
             // 去掉回复用户@
             $lessUids = array();
             if (!empty($data['to_uid'])) {
                 $lessUids[] = $data['to_uid'];
             }
             // 如果为原创微博,不给原创用户发送@信息
             if ($oldInfo['feedtype'] == 'post' && empty($data['to_uid'])) {
                 $lessUids[] = $oldInfo['uid'];
             }
             unlockSubmit();
             model('Share')->shareFeed($s, 'comment', $lessUids);
         }
         $data['feed_id'] = $datas['row_id'];
         $data['comment_id'] = $comment_id;
         $data['storey'] = $data1['storey'];
         $data['attach_info'] = model('Attach')->getAttachById($data['attach_id']);
         if ($data['attach_info']['attach_type'] == 'weiba_comment_image' || $data['attach_info']['attach_type'] == 'feed_image') {
             $data['attach_info']['attach_url'] = getImageUrl($data['attach_info']['save_path'] . $data['attach_info']['save_name'], 200, 200);
         }
         $return['status'] = 1;
         $return['msg'] = '发布成功';
     }
     return $return;
 }
Esempio n. 7
0
 /**
  * 分享到微博
  * @example
  * 需要传入的$data值
  * sid:转发的微博/资源ID
  * app_name:app名称
  * content:转发时的内容信息,有时候会有某些标题的资源
  * body:转发时,自定义写入的内容
  * type:微博类型
  * comment:是否给原作者评论
  * @param array $data 分享的相关数据
  * @param string $from 是否发@给资源作者,默认为share
  * @param array $lessUids 去掉@用户,默认为null
  * @return array 分享操作后,相关反馈信息数据
  */
 public function shareFeed($data, $from = 'share', $lessUids = null)
 {
     // 返回的数据结果集
     $return = array('status' => 0, 'data' => L('PUBLIC_SHARE_FAILED'));
     // 分享失败
     // 验证数据正确性
     if (empty($data['sid'])) {
         return $return;
     }
     // type是资源所在的表名
     $type = t($data['type']);
     // 当前产生微博所属的应用
     $app = isset($data['app_name']) ? $data['app_name'] : APP_NAME;
     // 是否为接口形式
     $forApi = $data['forApi'] ? true : false;
     if (!($oldInfo = model('Source')->getSourceInfo($type, $data['sid'], $forApi, $data['app_name']))) {
         $return['data'] = L('PUBLIC_INFO_SHARE_FORBIDDEN');
         // 此信息不可以被分享
         return $return;
     }
     // 内容数据
     $d['content'] = isset($data['content']) ? str_replace(SITE_URL, '[SITE_URL]', $data['content']) : '';
     $d['body'] = str_replace(SITE_URL, '[SITE_URL]', $data['body']);
     $feedType = 'repost';
     // 默认为普通的转发格式
     if (!empty($oldInfo['feedtype']) && !in_array($oldInfo['feedtype'], array('post', 'postimage', 'postfile'))) {
         $feedType = $oldInfo['feedtype'];
     }
     if ($app == 'weiba') {
         $feedType = 'weiba_repost';
         $oldInfo['uid'] = $oldInfo['post_uid'];
         $oldInfo['sourceInfo']['source_id'] = $oldInfo['feed_id'];
     }
     if ($app == 'tipoff') {
         $feedType = 'tipoff_repost';
     }
     $d['sourceInfo'] = !empty($oldInfo['sourceInfo']) ? $oldInfo['sourceInfo'] : $oldInfo;
     // 是否发送@上级节点
     $isOther = $from == 'comment' ? false : true;
     // 获取上个节点资源ID
     $d['curid'] = $data['curid'];
     // 获取转发原微博信息
     if ($oldInfo['app_row_id'] == 0) {
         $appId = $oldInfo['source_id'];
         $appTable = $oldInfo['source_table'];
     } else {
         $appId = $oldInfo['app_row_id'];
         $appTable = $oldInfo['app_row_table'];
     }
     $d['from'] = isset($data['from']) ? intval($data['from']) : 0;
     if ($res = model('Feed')->put($GLOBALS['ts']['mid'], $app, $feedType, $d, $appId, $appTable, null, $lessUids, $isOther, 1)) {
         if ($data['comment'] != 0 && $oldInfo['uid'] != $data['comment_touid']) {
             // 发表评论
             $c['app'] = $app;
             // $c['table'] = $appTable;
             $c['table'] = 'feed';
             $c['app_uid'] = $oldInfo['uid'];
             $c['content'] = !empty($d['body']) ? $d['body'] : $d['content'];
             $c['row_id'] = !empty($oldInfo['sourceInfo']) ? $oldInfo['sourceInfo']['source_id'] : $appId;
             $c['client_type'] = getVisitorClient();
             $notCount = $from == "share" ? $data['comment'] == 1 ? false : true : false;
             unlockSubmit();
             $comment_id = model('Comment')->addComment($c, false, $notCount, $lessUids);
             // 同步到微吧
             if ($app == 'weiba') {
                 $postDetail = D('weiba_post')->where('feed_id=' . $c['row_id'])->find();
                 if ($postDetail) {
                     $datas['weiba_id'] = $postDetail['weiba_id'];
                     $datas['post_id'] = $postDetail['post_id'];
                     $datas['post_uid'] = $postDetail['post_uid'];
                     // $datas['to_reply_id'] = $data['to_comment_id']?D('weiba_reply')->where('comment_id='.$data['to_comment_id'])->getField('reply_id'):0;
                     // $datas['to_uid'] = $data['to_uid'];
                     $datas['uid'] = $GLOBALS['ts']['mid'];
                     $datas['ctime'] = time();
                     $datas['content'] = $c['content'];
                     $datas['comment_id'] = $comment_id;
                     if (D('weiba_reply')->add($datas)) {
                         $map['last_reply_uid'] = $this->mid;
                         $map['last_reply_time'] = $datas['ctime'];
                         D('weiba_post')->where('post_id=' . $datas['post_id'])->save($map);
                         // 回复统计数加1
                         D('weiba_post')->where('post_id=' . $datas['post_id'])->setInc('reply_count');
                     }
                 }
             }
         }
         //添加话题
         model('FeedTopic')->addTopic(html_entity_decode($d['body'], ENT_QUOTES), $res['feed_id'], $feedType);
         // 渲染数据
         $rdata = $res;
         // 渲染完后的结果
         $rdata['feed_id'] = $res['feed_id'];
         $rdata['app_row_id'] = $data['sid'];
         $rdata['app_row_table'] = $data['type'];
         $rdata['app'] = $app;
         $rdata['is_repost'] = 1;
         switch ($app) {
             case 'weiba':
                 $rdata['from'] = getFromClient(0, $app, '微吧');
                 break;
             default:
                 $rdata['from'] = getFromClient($from, $app);
                 break;
         }
         $return['data'] = $rdata;
         $return['status'] = 1;
         // 被分享内容“分享统计”数+1,同时可检测出app,table,row_id 的有效性
         if (!($pk = D($data['type'], $data['app_name'])->getPk())) {
             $pk = $data['type'] . '_id';
         }
         D($data['type'], $data['app_name'])->setInc('repost_count', "`{$pk}`={$data['sid']}", 1);
         if ($data['curid'] != $data['sid'] && !empty($data['curid'])) {
             if (!($pk = D($data['curtable'])->getPk())) {
                 $pk = $data['curtable'] . '_id';
             }
             D($data['curtable'])->setInc('repost_count', "`{$pk}`={$data['curid']}", 1);
             D($data['curtable'])->cleanCache($data['curid']);
         }
         D($data['type'], $data['app_name'])->cleanCache($data['sid']);
     } else {
         $return['data'] = model('Feed')->getError();
     }
     return $return;
 }
 /**
  * 添加帖子回复的操作
  * @return array 评论添加状态和提示信息
  */
 public function addReply()
 {
     //   echo $_POST['post_id'];exit;
     if (!$this->mid || !CheckPermission('weiba_normal', 'weiba_reply')) {
         return;
     }
     $is_lock = M('weiba_blacklist')->where('weiba_id=' . intval($_POST['weiba_id']) . ' and uid=' . intval($_POST['post_uid']))->find();
     if ($is_lock) {
         $return['status'] = 0;
         $return['data'] = '您是黑名单用户没有发帖权限!';
         exit(json_encode($return));
     }
     $return = array('status' => 0, 'data' => L('PUBLIC_CONCENT_IS_ERROR'));
     $data['weiba_id'] = intval($_POST['weiba_id']);
     $data['post_id'] = intval($_POST['post_id']);
     $data['post_uid'] = intval($_POST['post_uid']);
     $data['to_reply_id'] = intval($_POST['to_reply_id']);
     $data['to_uid'] = intval($_POST['to_uid']);
     $data['uid'] = $this->mid;
     $data['ctime'] = time();
     $data['content'] = preg_html(h($_POST['content']));
     $data['attach_id'] = intval($_POST['attach_id']);
     $filterContentStatus = filter_words($data['content']);
     if (!$filterContentStatus['status']) {
         exit(json_encode(array('status' => 0, 'data' => $filterContentStatus['data'])));
     }
     $data['content'] = $filterContentStatus['data'];
     if (isSubmitLocked()) {
         $return['status'] = 0;
         $return['data'] = '发布内容过于频繁,请稍后再试!';
         exit(json_encode($return));
     }
     if ($data['reply_id'] = D('weiba_reply')->add($data)) {
         // 锁定发布
         lockSubmit();
         // 更新微吧今日新帖
         D('Weiba')->setNewcount($data['weiba_id']);
         //添加积分
         model('Credit')->setUserCredit(intval($_POST['post_uid']), 'comment_topic');
         model('Credit')->setUserCredit($data['to_uid'], 'commented_topic');
         $map['last_reply_uid'] = $this->mid;
         $map['last_reply_time'] = $data['ctime'];
         $map['reply_count'] = array('exp', "reply_count+1");
         $map['reply_all_count'] = array('exp', "reply_all_count+1");
         D('weiba_post', 'weiba')->where('post_id=' . $data['post_id'])->save($map);
         //同步到分享评论
         //$feed_id = intval($_POST['feed_id']);
         $datas['app'] = 'weiba';
         $datas['table'] = 'feed';
         $datas['content'] = preg_html($data['content']);
         $datas['app_uid'] = intval($_POST['post_uid']);
         $datas['row_id'] = intval($_POST['feed_id']);
         $datas['to_comment_id'] = $data['to_reply_id'] ? D('weiba_reply', 'weiba')->where('reply_id=' . $data['to_reply_id'])->getField('comment_id') : 0;
         $datas['to_uid'] = intval($_POST['to_uid']);
         $datas['uid'] = $this->mid;
         $datas['ctime'] = time();
         $datas['client_type'] = getVisitorClient();
         $data['cancomment'] = 1;
         $data['list_count'] = intval($_POST['list_count']);
         // 解锁
         unlockSubmit();
         if ($comment_id = model('Comment')->addComment($datas)) {
             $data1['comment_id'] = $comment_id;
             // $data1['storey'] = model('Comment')->where('comment_id='.$comment_id)->getField('storey');
             D('weiba_reply', 'weiba')->where('reply_id=' . $data['reply_id'])->save($data1);
             // 给应用UID添加一个未读的评论数
             if ($GLOBALS['ts']['mid'] != $datas['app_uid'] && $datas['app_uid'] != '') {
                 !$notCount && model('UserData')->updateKey('unread_comment', 1, true, $datas['app_uid']);
             }
             model('Feed')->cleanCache($datas['row_id']);
         }
         //转发到我的分享
         if ($_POST['ifShareFeed'] == 1) {
             $commentInfo = model('Source')->getSourceInfo($datas['table'], $datas['row_id'], false, $datas['app']);
             $oldInfo = isset($commentInfo['sourceInfo']) ? $commentInfo['sourceInfo'] : $commentInfo;
             // 根据评论的对象获取原来的内容
             $s['sid'] = $data['post_id'];
             $s['app_name'] = 'weiba';
             if (!empty($data['to_comment_id'])) {
                 $replyInfo = model('Comment')->init($data['app'], $data['table'])->getCommentInfo($data['to_comment_id'], false);
                 $data['content'] .= $replyInfo['content'];
             }
             $s['body'] = $data['content'];
             $s['type'] = 'weiba_post';
             $s['comment'] = $data['comment_old'];
             // 去掉回复用户@
             $lessUids = array();
             if (!empty($data['to_uid'])) {
                 $lessUids[] = $data['to_uid'];
             }
             // 如果为原创分享,不给原创用户发送@信息
             if ($oldInfo['feedtype'] == 'post' && empty($data['to_uid'])) {
                 $lessUids[] = $oldInfo['uid'];
             }
             unlockSubmit();
             model('Share')->shareFeed($s, 'comment', $lessUids);
         }
         $data['feed_id'] = $datas['row_id'];
         $data['comment_id'] = $comment_id;
         $data['storey'] = $data1['storey'];
         $data['attach_info'] = model('Attach')->getAttachById($data['attach_id']);
         if ($data['attach_info']['attach_type'] == 'weiba_comment_image' || $data['attach_info']['attach_type'] == 'feed_image') {
             $data['attach_info']['attach_url'] = getImageUrl($data['attach_info']['save_path'] . $data['attach_info']['save_name'], 590);
         }
         $return['status'] = 1;
         $return['data'] = $this->parseReply($data);
     }
     echo json_encode($return);
     exit;
 }
Esempio n. 9
0
 /**
  * 分享给同事
  * 
  * @example 需要传入的$data值
  *          uid:同事用户ID
  *          sid:转发的分享/资源ID
  *          app_name:app名称
  *          content:转发时的内容信息,有时候会有某些标题的资源
  *          body:转发时,自定义写入的内容
  *          type:分享类型
  *          comment:是否给原作者评论
  * @param array $data
  *        	分享的相关数据
  * @return array 分享操作后,相关反馈信息数据
  */
 public function shareMessage($data)
 {
     $return = array('status' => 0, 'data' => L('PUBLIC_SHARE_FAILED'));
     // 分享失败
     $app = t($data['app_name']);
     $msg['to'] = trim($data['uids'], ',');
     if (empty($msg['to'])) {
         $return['data'] = L('PUBLIC_SHARE_TOUSE_EMPTY');
         // 分享接受人不能为空
         return $return;
     }
     if (!($oldInfo = model('Source')->getSourceInfo($data['type'], $data['sid'], false, $app))) {
         $return['data'] = L('PUBLIC_INFO_SHARE_FORBIDDEN');
         // 此信息不可以被分享
         return $return;
     }
     $data['content'] = trim($data['content']);
     $content = empty($data['content']) ? "" : "“{$data['content']}”&nbsp;//&nbsp;";
     $content = parse_html($content);
     $message['to'] = $msg['to'];
     $message['content'] = $content . parse_html($oldInfo['source_content']) . '&nbsp;&nbsp;<a href="' . $oldInfo['source_url'] . '" target=\'_blank\'>查看</a>';
     if (model('Message')->postMessage($message, $GLOBALS['ts']['_user']['uid'])) {
         // 发表评论
         $c['type'] = 3;
         $c['app'] = $app;
         $c['table'] = 'feed';
         $c['app_uid'] = $oldInfo['uid'];
         $c['content'] = str_replace(SITE_URL, '[SITE_URL]', $data['content']);
         $c['row_id'] = !empty($oldInfo['sourceInfo']) ? $oldInfo['sourceInfo']['source_id'] : $data['sid'];
         $c['client_type'] = getVisitorClient();
         $notCount = false;
         unlockSubmit();
         $comment_id = model('Comment')->addComment($c, true, $notCount, $lessUids);
         // $config['name'] = $GLOBALS['ts']['_user']['uname'];
         // $config['content'] = $content;
         // //$config['sourceurl'] = $oldInfo['source_url'];
         // $touids = explode(',', $msg['to']);
         // foreach($touids as $v) {
         // model('Notify')->sendNotify($v, 'new_message', $config);
         // }
         $return = array('status' => 1, 'data' => L('PUBLIC_SHARE_SUCCESS'));
         // 分享成功
     }
     return $return;
 }