IndexAction::messageContent PHP Méthode

messageContent() public méthode

消息弹出层内容获取
public messageContent ( $type )
    public function messageContent($type)
    {
        if (!$type) {
            $type = t(empty($_POST['type']) ? $_GET['type'] : $_POST['type']);
        }
        $_POST['type'] = $type;
        switch ($type) {
            //@我的
            case 'at':
                // 获取未读@Me的条数
                $this->assign('unread_atme_count', model('UserData')->where('uid=' . $this->mid . " and `key`='unread_atme'")->getField('value'));
                // 拼装查询条件
                $map['uid'] = $this->mid;
                $d['tab'] = model('Atme')->getTab(null);
                foreach ($d['tab'] as $key => $vo) {
                    if ($key == 'feed') {
                        $d['tabHash']['feed'] = L('PUBLIC_WEIBO');
                    } elseif ($key == 'comment') {
                        $d['tabHash']['comment'] = L('PUBLIC_STREAM_COMMENT');
                    } else {
                        $langKey = 'PUBLIC_APPNAME_' . strtoupper($key);
                        $lang = L($langKey);
                        if ($lang == $langKey) {
                            $d['tabHash'][$key] = ucfirst($key);
                        } else {
                            $d['tabHash'][$key] = $lang;
                        }
                    }
                }
                $this->assign($d);
                !empty($_POST['t']) && ($map['table'] = t($_POST['t']));
                //at类型
                $this->assign('tt', $_POST['t']);
                // 设置应用名称与表名称
                $app_name = isset($_GET['app_name']) ? t($_GET['app_name']) : 'public';
                // $app_table = isset($_GET['app_table']) ? t($_GET['app_table']) : '';
                // 获取@Me分享列表
                $at_list = model('Atme')->setAppName($app_name)->setAppTable($app_table)->getAtmeList($map, $order = 'atme_id DESC', $limit = 20);
                // 赞功能
                $feed_ids = getSubByKey($at_list['data'], 'feed_id');
                $diggArr = model('FeedDigg')->checkIsDigg($feed_ids, $GLOBALS['ts']['mid']);
                $this->assign('diggArr', $diggArr);
                // dump($at_list);exit;
                // 添加Widget参数数据
                foreach ($at_list['data'] as &$val) {
                    if ($val['source_table'] == 'comment') {
                        $val['widget_sid'] = $val['sourceInfo']['source_id'];
                        $val['widget_style'] = $val['sourceInfo']['source_table'];
                        $val['widget_sapp'] = $val['sourceInfo']['app'];
                        $val['widget_suid'] = $val['sourceInfo']['uid'];
                        $val['widget_share_sid'] = $val['sourceInfo']['source_id'];
                    } elseif ($val['is_repost'] == 1) {
                        $val['widget_sid'] = $val['source_id'];
                        $val['widget_stype'] = $val['source_table'];
                        $val['widget_sapp'] = $val['app'];
                        $val['widget_suid'] = $val['uid'];
                        $val['widget_share_sid'] = $val['app_row_id'];
                        $val['widget_curid'] = $val['source_id'];
                        $val['widget_curtable'] = $val['source_table'];
                    } else {
                        $val['widget_sid'] = $val['source_id'];
                        $val['widget_stype'] = $val['source_table'];
                        $val['widget_sapp'] = $val['app'];
                        $val['widget_suid'] = $val['uid'];
                        $val['widget_share_sid'] = $val['source_id'];
                    }
                    // 获取转发与评论数目
                    if ($val['source_table'] != 'comment') {
                        $feedInfo = model('Feed')->get($val['widget_sid']);
                        $val['repost_count'] = $feedInfo['repost_count'];
                        $val['comment_count'] = $feedInfo['comment_count'];
                    }
                    // 解析数据成网页端显示格式(@xxx 加链接)
                    $val['source_content'] = parse_html($val['source_content']);
                    $val['from'] = getFromClient($val['from'], $val['app']);
                }
                // 获取分享设置
                $weiboSet = model('Xdata')->get('admin_Config:feed');
                $this->assign($weiboSet);
                // 用户@Me未读数目重置
                // model('UserCount')->resetUserCount($this->mid, 'unread_atme', 0);
                $userInfo = model('User')->getUserInfo($this->mid);
                // 分页链接重写
                $at_list['html'] = $this->messagePage($at_list['html']);
                $this->assign($at_list);
                //消息类型
                $this->assign('type', $type);
                $html = $this->fetch('at');
                break;
                //我的评论
            //我的评论
            case 'comment':
                $stype = t($_POST['stype']);
                if (empty($_POST['stype'])) {
                    $stype = $_POST['stype'] = 'receive';
                }
                if ($stype == 'send') {
                    $map['uid'] = $this->uid;
                } else {
                    // 分享配置
                    $weiboSet = model('Xdata')->get('admin_Config:feed');
                    $this->assign('weibo_premission', $weiboSet['weibo_premission']);
                    $keyword = '收到';
                    //获取未读评论的条数
                    $this->assign('unread_comment_count', model('UserData')->where('uid=' . $this->mid . " and `key`='unread_comment'")->getField('value'));
                    // 收到的
                    $map['_string'] = " (to_uid = '{$this->uid}' OR app_uid = '{$this->uid}') AND uid !=" . $this->uid;
                }
                //消息类型
                $this->assign('type', $type);
                //发出的或者收到的
                $this->assign('stype', $stype);
                //		$d['tab'] = model('Comment')->getTab($map);
                $d['tab'] = model('Comment')->getTabForApp($map);
                foreach ($d['tab'] as $key => $vo) {
                    if ($key == 'feed') {
                        $d['tabHash']['feed'] = L('PUBLIC_WEIBO');
                    } elseif ($key == 'webpage') {
                        $d['tabHash']['webpage'] = '评论箱';
                    } else {
                        // 微吧
                        strtolower($key) === 'weiba_post' && ($key = 'weiba');
                        $langKey = 'PUBLIC_APPNAME_' . strtoupper($key);
                        $lang = L($langKey);
                        if ($lang == $langKey) {
                            $d['tabHash'][$key] = ucfirst($key);
                        } else {
                            $d['tabHash'][$key] = $lang;
                        }
                    }
                }
                $this->assign($d);
                // 安全过滤
                $t = t($_POST['t']);
                // 	评论类型
                $this->assign('tt', $t);
                !empty($t) && ($map['app'] = $t);
                if ($t == 'feed') {
                    $map['app'] = 'public';
                }
                $list = model('Comment')->setAppName(t($_GET['app_name']))->getCommentList($map, 'comment_id DESC', 20, true);
                foreach ($list['data'] as $k => $v) {
                    if ($v['sourceInfo']['app'] == 'weiba') {
                        $list['data'][$k]['sourceInfo']['source_body'] = str_replace($v['sourceInfo']['row_id'], $v['comment_id'], $v['sourceInfo']['source_body']);
                    }
                    if ($v['table'] === 'webpage') {
                        $list['data'][$k]['hasComment'] = false;
                    } else {
                        $list['data'][$k]['hasComment'] = true;
                    }
                }
                model('UserCount')->resetUserCount($this->mid, 'unread_comment', 0);
                //分页链接重写
                $list['html'] = $this->messagePage($list['html']);
                $this->assign('list', $list);
                $userInfo = model('User')->getUserInfo($this->mid);
                $html = $this->fetch('comment');
                break;
                //我的私信
            //我的私信
            case 'message':
                $dao = model('Message');
                $list = $dao->getMessageListByUid($this->mid, array(MessageModel::ONE_ON_ONE_CHAT, MessageModel::MULTIPLAYER_CHAT), 20);
                // 设置信息已读(在右上角提示去掉),
                model('Message')->setMessageIsRead(t($POST['id']), $this->mid, 1);
                if ($list['nowPage'] <= 1 && is_array($list['data']) && isset($list['data'][0])) {
                    $only = !isset($list['data'][1]) || $list['data'][1]['new'] <= 0;
                    if ($list['data'][0]['new'] > 0 && $only) {
                        $this->redirect('public/Index/messageContent', array('type' => 'message_detail', 'stype' => $list['data'][0]['type'], 'id' => $list['data'][0]['list_id']));
                        exit;
                    }
                }
                //重写分页链接
                $list['html'] = $this->messagePage($list['html']);
                $this->assign($list);
                $this->assign('type', $type);
                $userInfo = model('User')->getUserInfo($this->mid);
                $html = $this->fetch('message');
                break;
            case 'message_detail':
                $_POST['id'] = intval(empty($_POST['id']) ? $_GET['id'] : $_POST['id']);
                $_POST['stype'] = t(empty($_POST['stype']) ? $_GET['stype'] : $_POST['stype']);
                $message = model('Message')->isMember(t($_POST['id']), $this->mid, true);
                // 验证数据
                if (empty($message)) {
                    $this->error(L('PUBLIC_PRI_MESSAGE_NOEXIST'));
                }
                $message['member'] = model('Message')->getMessageMembers(t($_POST['id']), 'member_uid');
                $message['to'] = array();
                // 添加发送用户ID
                foreach ($message['member'] as $v) {
                    $this->mid != $v['member_uid'] && ($message['to'][] = $v);
                }
                // 设置信息已读(私信列表页去掉new标识)
                model('Message')->setMessageIsRead(t($_POST['id']), $this->mid, 0);
                $message['since_id'] = model('Message')->getSinceMessageId($message['list_id'], $message['message_num']);
                $this->assign('message', $message);
                $this->assign('type', intval($_POST['type']));
                $this->setTitle('与' . $message['to'][0]['user_info']['uname'] . '的私信对话');
                $this->setKeywords('与' . $message['to'][0]['user_info']['uname'] . '的私信对话');
                $html = $this->fetch('message_detail');
                break;
            case 'notify':
                $map['uid'] = $this->mid;
                if ($_POST['t'] == 'digg') {
                    $map['node'] = array('eq', 'digg');
                } else {
                    $map['node'] = array('neq', 'digg');
                }
                $list = D('notify_message')->where($map)->order('ctime desc')->findpage(20);
                //重写分页链接
                $list['html'] = $this->messagePage($list['html']);
                foreach ($list['data'] as $k => $v) {
                    $list['data'][$k]['body'] = parse_html($v['body']);
                    if ($appname != 'public') {
                        $list['data'][$k]['app'] = model('App')->getAppByName($v['appname']);
                    }
                    //如果为点赞消息,获取发送人的头像
                    if ($_POST['t'] == 'digg') {
                        $from_user = model('User')->getUserInfo($list['data'][$k]['from_uid']);
                        //头像
                        $list['data'][$k]['from_user_avatar'] = $from_user['avatar_middle'];
                        $list['data'][$k]['from_user'] = $from_user;
                    }
                }
                if ($_POST['t'] == 'digg') {
                    $node = 'digg';
                    model('UserCount')->resetUserCount($this->mid, 'unread_digg', 0);
                } else {
                    $node = array('neq', 'digg');
                }
                model('Notify')->setRead($this->mid, '', $node);
                $this->assign('list', $list);
                $this->assign('type', $type);
                $this->assign('t', $_POST['t']);
                $html = $this->fetch('notify');
                break;
        }
        $data['html'] = $html;
        $this->ajaxReturn($data, '获取内容成功', 1);
    }