public function getMessage()
{
$type = t($_GET['type']);
if (!in_array($type, array('msg', 'at', 'com', 'pmsg'))) {
$this->ajaxReturn(null, '信息获取失败', 0);
}
$limit = 10;
$html = '';
switch ($type) {
case 'msg':
$map['uid'] = $this->mid;
$notifyList = D('notify_message')->where($map)->order('ctime DESC')->findPage($limit);
foreach ($notifyList['data'] as $item) {
$content = str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($item['body']));
if ($item['node'] == 'user_follow') {
$html .= '<li onclick="location.href=\'' . U('public/Index/follower') . '\'">' . $content . '</li>';
} elseif ($item['node'] == 'digg') {
preg_match_all('%<a[\\s\\S]*?href="([^"]+)[^>]+>([\\s\\S]*?)</a>%', $content, $match, PREG_PATTERN_ORDER);
$url = $match[1][count($match[0]) - 1];
$html .= '<li onclick="location.href=\'' . $url . '\'">' . $content . '</li>';
} else {
$html .= '<li>' . $content . '</li>';
}
}
model('Notify')->setRead($this->mid);
break;
case 'at':
// $map['uid'] = $this->mid;
// $atList = model('Atme')->where($map)->order('atme_id DESC')->findPage($limit);
$table = "( SELECT a.`atme_id`, a.`app`, a.`table`, CASE a.`table` WHEN 'comment' THEN b.`row_id` ELSE a.`row_id` END AS `row_id`, a.`uid`, a.`row_id` AS `old_row_id` FROM " . C('DB_PREFIX') . 'atme AS a LEFT JOIN ' . C('DB_PREFIX') . 'comment AS b ON a.row_id = b.comment_id WHERE a.uid = ' . $this->mid . ' ORDER BY a.`atme_id` DESC) AS NEW ';
$atList = D()->table($table)->group('`app`, `table`, `row_id`, `uid`')->order('`atme_id` DESC')->findPage($limit);
if (!empty($atList)) {
$space = $content = '';
foreach ($atList['data'] as $item) {
$item['row_id'] = $item['old_row_id'];
switch (strtolower($item['table'])) {
case 'feed':
$data = model('Feed')->getFeedInfo($item['row_id']);
$space = '<a href="' . U('public/Profile/index', array('uid' => $data['uid'])) . '">' . getUserName($data['uid']) . '</a>';
if ($data['is_audit'] == 0) {
$content = '内容正在审核';
} else {
$data['content'] = explode('//', $data['content']);
$data['content'] = $data['content'][0];
$content = str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($data['content']));
}
$html .= '<li source-id="' . $item['atme_id'] . '">' . $space . '在分享中@我:' . $content . '</li>';
break;
case 'comment':
$data = model('Comment')->getCommentInfo($item['row_id']);
$space = '<a href="' . U('public/Profile/index', array('uid' => $data['uid'])) . '">' . getUserName($data['uid']) . '</a>';
if ($data['is_audit'] == 0) {
$content = '内容正在审核';
} else {
$data['content'] = explode('//', $data['content']);
$data['content'] = $data['content'][0];
if (preg_match("/^<a\\s+href=[^h]*http:\$/", $data['content'])) {
$data['content'] .= $data['content'][1];
}
$content = str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($data['content']));
}
$html .= '<li source-id="' . $item['atme_id'] . '">' . $space . '在评论中@我:' . $content . '</li>';
break;
}
}
}
model('UserCount')->resetUserCount($this->mid, 'unread_atme', 0);
break;
case 'com':
// 收到的
// $map['_string'] = " (to_uid = '{$this->mid}' OR app_uid = '{$this->mid}') AND is_del = 0 AND uid !=".$this->mid;
$tab = model('Comment')->getTab($map);
$tabHash = array();
foreach ($tab as $key => $val) {
if ($key === 'feed') {
$tabHash['feed'] = '分享';
} elseif ($key === 'webpage') {
$tabHash['webpage'] = '评论箱';
} else {
strtolower($key) === 'weiba_post' && ($key = 'weiba');
$langKey = 'PUBLIC_APPNAME_' . strtoupper($key);
$lang = L($langKey);
if ($lang == $langKey) {
$tabHash[$key] = ucfirst($key);
} else {
$tabHash[$key] = $lang;
}
}
}
$table = '(SELECT * FROM `' . C('DB_PREFIX') . "comment` WHERE ((`to_uid` = '" . $this->mid . "' OR `app_uid` = '" . $this->mid . "') AND `is_del` = 0 AND `uid` != '" . $this->mid . "') AND `table` != 'webpage' ORDER BY `ctime` DESC) AS NEW ";
$commentList = D()->table($table)->group('`app` , `table` , `row_id` , `app_uid` , `uid`')->order('`ctime` DESC')->findPage($limit);
foreach ($commentList['data'] as $item) {
$space = '<a href="' . U('public/Profile/index', array('uid' => $item['uid'])) . '">' . getUserName($item['uid']) . '</a>';
$feed = model('Feed')->get($item['row_id']);
if ($feed['is_audit'] == 0) {
$content = '内容正在审核';
} else {
if ($item['table'] === 'feed' && $item['app'] === 'public' || $feed['is_repost'] == 1) {
$content = unserialize($feed['feed_data']);
$content = str_replace('__THEME__', THEME_PUBLIC_URL, parse_html(getShort($content['content'], 20, '...')));
} else {
$source = model('Source')->getSourceInfo($item['table'], $item['row_id']);
$title = empty($source['api_source']['title']) ? '内容已被删除' : $source['api_source']['title'];
$content = str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($title));
}
}
$html .= '<li source-id="' . $item['comment_id'] . '">' . $space . '评论了' . $tabHash[$item['table']] . ':' . $content . '</li>';
}
model('UserCount')->resetUserCount($this->mid, 'unread_comment', 0);
break;
case 'pmsg':
$messageList = model('Message')->getMessageListByUid($this->mid, array(MessageModel::ONE_ON_ONE_CHAT, MessageModel::MULTIPLAYER_CHAT), $limit);
foreach ($messageList['data'] as $item) {
if ($item['last_message']['from_uid'] == $this->mid) {
$to = model('User')->getUserInfoByUids($item['last_message']['to_uid']);
$to = getSubByKey($to, 'space_link_no');
$space = implode('、', $to);
$content = str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($item['last_message']['content']));
$html .= '<li source-id="' . $item['list_id'] . '">我发送给' . $space . ':' . $content . '</li>';
} else {
$space = $item['last_message']['user_info']['space_link_no'];
$content = str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($item['last_message']['content']));
$html .= '<li source-id="' . $item['list_id'] . '">' . $space . '说:' . $content . '</li>';
}
}
model('Message')->setAllIsRead($this->mid);
break;
}
if (!empty($html)) {
$data['html'] = $html;
$this->ajaxReturn($data, '获取内容成功', 1);
} else {
$this->ajaxReturn(null, '<p class="no-info">暂无此信息</p>', 0);
}
}