public function PostFeed()
{
// 返回数据格式
$return = array('status' => 1, 'data' => '');
// 用户发送内容
$d['content'] = isset($_POST['content']) ? h($_POST['content']) : '';
$filterContentStatus = filter_words($d['content']);
if (!$filterContentStatus['status']) {
exit(json_encode(array('status' => 0, 'data' => $filterContentStatus['data'])));
}
$d['content'] = $filterContentStatus['data'];
///
if ($_POST['channel_id'] == '' && $_POST['channel'] == 'channel') {
$return = array('status' => 0, 'data' => '请选择频道');
exit(json_encode($return));
}
// 原始数据内容
$filterBodyStatus = filter_words($_POST['body']);
if (!$filterBodyStatus['status']) {
$return = array('status' => 0, 'data' => $filterBodyStatus['data']);
exit(json_encode($return));
}
$d['body'] = $filterBodyStatus['data'];
// 安全过滤
foreach ($_POST as $key => $val) {
$_POST[$key] = t($_POST[$key]);
}
$d['source_url'] = urldecode($_POST['source_url']);
// 应用分享到分享,原资源链接
// 滤掉话题两端的空白
$d['body'] = preg_replace("/#[\\s]*([^#^\\s][^#]*[^#^\\s])[\\s]*#/is", '#' . trim('${1}') . '#', $d['body']);
// $numbers = array(41624,41625,41626,41627,41628,41629);
// shuffle($numbers);
// // 附件信息
// if($_POST ['attach_id']==''&&$_POST ['channel_id']!=''){
// $_POST ['attach_id'] = '|'.$numbers[0].'|'.$numbers[1].'|'.$numbers[2].'|';
// $_POST ['type'] = 'postimage';
// }
$d['attach_id'] = trim(t($_POST['attach_id']), '|');
if (!empty($d['attach_id'])) {
$d['attach_id'] = explode('|', $d['attach_id']);
if (count($d['attach_id']) == 1 && $_POST['channel_id'] != '' && false) {
$d['attach_id'][1] = $d['attach_id'][0];
$d['attach_id'][0] = $numbers[0];
$_POST['type'] = 'postimage';
}
array_map('intval', $d['attach_id']);
}
if ($_POST['video_id']) {
$d['video_id'] = intval($_POST['video_id']);
}
// 发送分享的类型
$type = t($_POST['type']);
// 附件信息
// 所属应用名称
$app = isset($_POST['app_name']) ? t($_POST['app_name']) : APP_NAME;
// 当前动态产生所属的应用
if (!($data = model('Feed')->put($this->uid, $app, $type, $d))) {
$return = array('status' => 0, 'data' => model('Feed')->getError());
exit(json_encode($return));
}
// 发布邮件之后添加积分
model('Credit')->setUserCredit($this->uid, 'add_weibo');
// 分享来源设置
$data['from'] = getFromClient($data['from'], $data['app']);
$this->assign($data);
// 分享配置
$weiboSet = model('Xdata')->get('admin_Config:feed');
$this->assign('weibo_premission', $weiboSet['weibo_premission']);
$return['data'] = $this->fetch();
// 分享ID
$return['feedId'] = $data['feed_id'];
$return['is_audit'] = $data['is_audit'];
// 添加话题
model('FeedTopic')->addTopic(html_entity_decode($d['body'], ENT_QUOTES, 'UTF-8'), $data['feed_id'], $type);
// 更新用户最后发表的分享
$last['last_feed_id'] = $data['feed_id'];
$last['last_post_time'] = $_SERVER['REQUEST_TIME'];
model('User')->where('uid=' . $this->uid)->save($last);
$isOpenChannel = model('App')->isAppNameOpen('channel');
if (!$isOpenChannel) {
exit(json_encode($return));
}
// 添加分享到投稿数据中
$channelId = t($_POST['channel_id']);
// 绑定用户
$bindUserChannel = D('Channel', 'channel')->getCategoryByUserBind($this->mid);
if (!empty($bindUserChannel)) {
$channelId = array_merge($bindUserChannel, explode(',', $channelId));
$channelId = array_filter($channelId);
$channelId = array_unique($channelId);
$channelId = implode(',', $channelId);
}
// 绑定话题
$content = html_entity_decode($d['body'], ENT_QUOTES, 'UTF-8');
$content = str_replace('#', '#', $content);
preg_match_all("/#([^#]*[^#^\\s][^#]*)#/is", $content, $topics);
$topics = array_unique($topics[1]);
foreach ($topics as &$topic) {
$topic = trim(preg_replace('/#/', '', t($topic)));
}
$bindTopicChannel = D('Channel', 'channel')->getCategoryByTopicBind($topics);
if (!empty($bindTopicChannel)) {
$channelId = array_merge($bindTopicChannel, explode(',', $channelId));
$channelId = array_filter($channelId);
$channelId = array_unique($channelId);
$channelId = implode(',', $channelId);
}
if (!empty($channelId)) {
// 获取后台配置数据
$channelConf = model('Xdata')->get('channel_Admin:index');
$return['is_audit_channel'] = $channelConf['is_audit'];
// 添加频道数据
D('Channel', 'channel')->setChannel($data['feed_id'], $channelId, false);
}
exit(json_encode($return));
}