function if_add_channel($original, $cha_code, $cha_name) { if (strlen($cha_code) > 3 && filter_keyword($cha_code)) { if ($original != '' && $cha_code != '' && $cha_name != '') { $flag = 1; for ($i = 0; $i < strlen($cha_code); $i++) { $val = substr($cha_code, $i, 1); if ($i == 0) { if (ord($val) < ord('a') || ord($val) > ord('z')) { $flag = 0; break; } } else { if ((ord($val) < ord('a') || ord($val) > ord('z')) && (ord($val) < ord('0') || ord($val) > ord('9'))) { $flag = 0; break; } } } if ($flag) { $obj = new channel(); $obj->set_where("cha_code = '{$cha_code}'"); $one = $obj->get_one(); if (count($one) == 0) { return 1; } else { return 4; } } else { return 3; } } else { return 2; } } else { return 4; } }
public function update_profile() { $save = array(); if (isset($this->data['sex'])) { $save['sex'] = 1 == intval($this->data['sex']) ? 1 : 2; } if (isset($this->data['intro'])) { $save['intro'] = t($this->data['intro']); } if (isset($this->data['city_names']) && isset($this->data['city_ids'])) { // 添加地区信息 $save['location'] = t($this->data['city_names']); $cityIds = t($this->data['city_ids']); $cityIds = explode(',', $cityIds); if (!$cityIds[0] || !$cityIds[1] || !$cityIds[2]) { return array('status' => 0, 'info' => '请选择完整地区'); } isset($cityIds[0]) && ($save['province'] = intval($cityIds[0])); isset($cityIds[1]) && ($save['city'] = intval($cityIds[1])); isset($cityIds[2]) && ($save['area'] = intval($cityIds[2])); } if (isset($this->data['uname']) && isset($this->data['old_name'])) { // 修改用户昵称 $uname = t($this->data['uname']); $save['uname'] = filter_keyword($uname); $oldName = t($this->data['old_name']); $res = model('Register')->isValidName($uname, $oldName); if (!$res) { $error = model('Register')->getLastError(); return array('status' => 0, 'info' => $error); } // 如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $save['uname'])) { // 昵称和呢称拼音保存到搜索字段 $save['search_key'] = $save['uname'] . ' ' . model('PinYin')->Pinyin($save['uname']); } else { $save['search_key'] = $save['uname']; } } if (!empty($save)) { $res = model('User')->where('`uid`=' . $this->mid)->save($save); $res && model('User')->cleanCache($this->mid); $user_feeds = model('Feed')->where('uid=' . $this->mid)->field('feed_id')->findAll(); if ($user_feeds) { $feed_ids = getSubByKey($user_feeds, 'feed_id'); model('Feed')->cleanCache($feed_ids, $this->mid); } } if (isset($this->data['user_tags'])) { if (empty($this->data['user_tags'])) { return array('status' => 0, 'info' => L('PUBLIC_TAG_NOEMPTY')); } $nameList = t($this->data['user_tags']); $nameList = explode(',', $nameList); $tagIds = array(); foreach ($nameList as $name) { $tagIds[] = model('Tag')->setAppName('public')->setAppTable('user')->getTagId($name); } $rowId = intval($this->mid); if (!empty($rowId)) { $registerConfig = model('Xdata')->get('admin_Config:register'); if (count($tagIds) > $registerConfig['tag_num']) { return array('status' => 0, 'info' => '最多只能设置' . $registerConfig['tag_num'] . '个标签'); } model('Tag')->setAppName('public')->setAppTable('user')->updateTagData($rowId, $tagIds); } } return array('status' => 1, 'info' => '用户信息修改成功'); }
/** * 验证昵称内容的正确性 * @param string $name 输入昵称的信息 * @param string $old_name 原始昵称的信息 * @return bool 是否验证成功 */ public function isValidName($name, $old_name = null) { // 默认不准使用的昵称 $protected_name = array('name', 'uname', 'admin', 'profile', 'space'); $site_config = model('Xdata')->get('admin_Config:site'); !empty($site_config['sys_nickname']) && ($protected_name = array_merge($protected_name, explode(',', $site_config['sys_nickname']))); if (in_array($name, $protected_name)) { $this->_error = L('PUBLIC_NICKNAME_RESERVED'); // 抱歉,该昵称不允许被使用 return false; } //不能为手机号格式 $phone_reg = preg_match($this->_phone_reg, $name) !== 0; if ($phone_reg) { $this->_error = '用户名不能为手机号格式'; return false; } //其他格式 $res = preg_match($this->_name_reg, $name) !== 0; if ($res) { $length = get_str_length($name); $res = $length >= 2 && $length <= 10; if (!$res) { $this->_error = L('PUBLIC_NICKNAME_LIMIT', array('nums' => '2-10')); // 昵称长度必须在2-10个汉字之间 return false; } } else { $this->_error = '昵称仅支持中英文,数字,下划线'; return false; } $old_user = \Ts\Models\User::existent()->byUserName($old_name)->first(); $user = \Ts\Models\User::existent()->byUserName($name)->first(); if ($name != $old_name && $old_name && $user && $old_user->uid != $user->uid) { $this->_error = '该用户名已经存在。'; return false; } //敏感词 if (filter_keyword($name) !== $name) { $this->_error = '抱歉,该昵称包含敏感词不允许被使用'; return false; } return true; }
/** * 验证昵称内容的正确性 * @param string $name 输入昵称的信息 * @param string $old_name 原始昵称的信息 * @return boolean 是否验证成功 */ public function isValidName($name, $old_name = null) { // 默认不准使用的昵称 $protected_name = array('name', 'uname', 'admin', 'profile', 'space'); $site_config = model('Xdata')->get('admin_Config:site'); !empty($site_config['sys_nickname']) && ($protected_name = array_merge($protected_name, explode(',', $site_config['sys_nickname']))); $res = preg_match($this->_name_reg, $name) !== 0; if ($res) { $length = get_str_length($name); $res = $length >= 2 && $length <= 10; } else { $this->_error = '仅支持中英文,数字,下划线'; $res = false; return $res; } // 预保留昵称 if (in_array($name, $protected_name)) { $this->_error = L('PUBLIC_NICKNAME_RESERVED'); // 抱歉,该昵称不允许被使用 $res = false; return $res; } if (!$res) { $this->_error = L('PUBLIC_NICKNAME_LIMIT', array('nums' => '2-10')); // 昵称长度必须在2-10个汉字之间 return $res; } if ($name != $old_name && $this->_user_model->where('`uname`="' . mysql_escape_string($name) . '"')->find()) { $this->_error = L('PUBLIC_ACCOUNT_USED'); // 该用户名已被使用 $res = false; } // 敏感词 if (filter_keyword($name) !== $name) { $this->_error = '抱歉,该昵称包含敏感词不允许被使用'; return false; } return $res; }
function keyWordFilter($text) { return filter_keyword($text); }
/** * 3.0发布微博操作,用于AJAX * @return json 发布微博后的结果信息JSON数据 */ public function PostFeed() { if (!$this->ismember) { $return = array('status' => 0, 'data' => '抱歉,您不是该群成员'); exit(json_encode($return)); } // 返回数据格式 $return = array('status' => 1, 'data' => ''); //圈子ID $gid = intval($_POST['gid']); // 用户发送内容 $d['content'] = isset($_POST['content']) ? filter_keyword(h($_POST['content'])) : ''; $d['gid'] = $gid; // 原始数据内容 $d['body'] = filter_keyword(h($_POST['body'])); $d['source_url'] = urldecode($_POST['source_url']); //应用分享到微博,原资源链接 // 滤掉话题两端的空白 $d['body'] = preg_replace("/#[\\s]*([^#^\\s][^#]*[^#^\\s])[\\s]*#/is", '#' . trim("\${1}") . '#', $d['body']); // 附件信息 $d['attach_id'] = trim(t($_POST['attach_id']), "|"); !empty($d['attach_id']) && ($d['attach_id'] = explode('|', $d['attach_id'])); // 发送微博的类型 $type = t($_POST['type']); // 所属应用名称 //$app = isset($_POST['app_name']) ? t($_POST['app_name']) : APP_NAME; // 当前动态产生所属的应用 $app = 'group'; if ($data = D('GroupFeed')->put($this->uid, $app, $type, $d)) { // 发布邮件之后添加积分 //model('Credit')->setUserCredit($this->uid,'add_weibo'); // 微博来源设置 $data['from'] = getFromClient($data['from'], 'public'); $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), $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) { // $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); // $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)) { // D('Channel', 'channel')->setChannel($data['feed_id'], $channelId, false); // } // } } else { $return = array('status' => 0, 'data' => model('Feed')->getError()); } exit(json_encode($return)); }
public function addReport() { // 获取传入的值 $post = $_POST; // 安全过滤 foreach ($post as $key => $val) { $post[$key] = t($post[$key]); } // 过滤内容值 $post['body'] = filter_keyword($post['body']); // 判断资源是否删除 if (empty($post['curid'])) { $map['feed_id'] = $post['sid']; } else { $map['feed_id'] = $post['curid']; } $map['is_del'] = 0; $isExist = model('Feed')->where($map)->count(); if ($isExist == 0) { $return['status'] = 0; $return['data'] = '内容已被删除,转发失败'; exit(json_encode($return)); } // 进行分享操作 $return = model('Share')->shareFeed($post, 'share'); if ($return['status'] == 1) { $app_name = $post['app_name']; // 添加积分 if ($app_name == 'public') { model('Credit')->setUserCredit($this->uid, 'forward_weibo'); //微博被转发 $suid = model('Feed')->where($map)->getField('uid'); model('Credit')->setUserCredit($suid, 'forwarded_weibo'); } if ($app_name == 'weiba') { model('Credit')->setUserCredit($this->uid, 'forward_topic'); //微博被转发 $suid = D('Feed')->where('feed_id=' . $map['feed_id'])->getField('uid'); model('Credit')->setUserCredit($suid, 'forwarded_topic'); } $this->assign($return['data']); // 微博配置 $weiboSet = model('Xdata')->get('admin_Config:feed'); $this->assign('weibo_premission', $weiboSet['weibo_premission']); $html = '<dl class="comment_list"> <dt><a href="' . $return['data']['user_info']['space_url'] . '"><img src="' . $return['data']['user_info']['avatar_tiny'] . '" width="30" height="30"/></a></dt> <dd> <p class="cont">' . $return['data']['user_info']['space_link'] . ':<em>' . str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($return['data']['content'])) . '<span class="time">(' . friendlyDate($return['data']['publish_time']) . ')</span></em></p> <p class="right mt5"><span><a href="javascript:;" onclick="shareFeed(' . $return['data']['feed_id'] . ', ' . $return['data']['curid'] . ');">转发</a></span></p> </dd> </dl>'; $return['data'] = $html; } exit(json_encode($return)); }
/** * 修改用户信息 --using * * @param string $uname * 用户名 * @param integer $sex * 性别(1-男,2-女) * @param string $intro * 个人简介 * @param string $city_id * 地区ID * @param string $password * 新密码 * @param string $old_password * 旧密码 * @param string $tags * 标签(多个标签之间用逗号隔开) */ public function save_user_info() { $save = array(); // 修改用户昵称 if (isset($this->data['uname'])) { $uname = t($this->data['uname']); $save['uname'] = filter_keyword($uname); $oldName = t($this->data['old_name']); $res = model('Register')->isValidName($uname); if (!$res) { $error = model('Register')->getLastError(); return array('status' => 0, 'msg' => $error); } $save['first_letter'] = getFirstLetter($uname); // 如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $save['uname'])) { // 昵称和呢称拼音保存到搜索字段 $save['search_key'] = $save['uname'] . ' ' . model('PinYin')->Pinyin($save['uname']); } else { $save['search_key'] = $save['uname']; } } // 修改性别 if (isset($this->data['sex'])) { $save['sex'] = 1 == intval($this->data['sex']) ? 1 : 2; } // 修改用户真实姓名 if (isset($this->data['realname'])) { $save['realname'] = t($this->data['realname']); } // 修改公司 if (isset($this->data['company'])) { $save['company'] = t($this->data['company']); } // 修改职位 if (isset($this->data['position'])) { $save['position'] = t($this->data['position']); } // 修改个人简介 if (isset($this->data['intro'])) { $save['intro'] = t($this->data['intro']); } // // 修改地区 // if ($this->data ['city_id']) { // $area_id = intval ( $this->data ['city_id'] ); // $area = D ( 'area' )->where ( 'area_id=' . $area_id )->find (); // $city = D ( 'area' )->where ( 'area_id=' . $area ['pid'] )->find (); // $province = D ( 'area' )->where ( 'area_id=' . $city ['pid'] )->find (); // $save ['province'] = intval ( $province ['area_id'] ); // $save ['city'] = intval ( $city ['area_id'] ); // $save ['area'] = t ( $area ['area_id'] ); // $save ['location'] = $province ['title'] . ' ' . $city ['title'] . ' ' . $area ['title']; // } // 修改地区 if ($this->data['city_id']) { $id = intval($this->data['city_id']); //$area = D ( 'district' )->where ( 'id=' . $id )->find (); $city = D('district')->where('id=' . $id)->find(); $province = D('district')->where('id=' . $city['upid'])->find(); $save['province'] = intval($province['id']); $save['city'] = intval($city['id']); //$save ['area'] = t ( $area ['id'] ); $save['location'] = $province['name'] . ' ' . $city['name']; } // 修改密码 if ($this->data['password']) { // 验证新密码与旧密码是否一致 if ($this->data['password'] == $this->data['old_password']) { $return = array('status' => 0, 'msg' => L('PUBLIC_PASSWORD_SAME')); return $return; } } // 数据中心修改用户昵称性别地区 if (!empty($save) || $this->data['password'] && $this->data['old_password']) { $sCenter_token = $this->getCenterToken(); $UserData = model('User')->where('`uid`=' . $this->mid)->find(); if (!empty($UserData) && ($save['uname'] || $save['sex'] || $save['company'] || $save['position'] || $save['realname'] || $city['name'])) { $sCtlgurl = C('APIURL') . '/v1/user/modify?_format=json&access_token=' . $sCenter_token; $rCtlg = array('open_id' => $UserData['cyj_id'], 'realname' => '', 'gender' => $save['sex'], 'city' => $city['name'], 'company' => $save['company'], 'position' => $save['position'], 'realname' => $save['realname']); if (!empty($save['uname'])) { $rCtlg['username'] = $save['uname']; } $sCtlgstatus = request_post($sCtlgurl, $rCtlg); $rStatus = json_decode($sCtlgstatus, true); } if ($this->data['password'] && $this->data['old_password']) { $sCtlgurl = C('APIURL') . '/v1/user/reset-pwd?_format=json&access_token=' . $sCenter_token; $rCtlg = array('open_id' => $UserData['cyj_id'], 'password' => $this->data['password'], 'old_password' => $this->data['old_password']); $sCtlgstatus = request_post($sCtlgurl, $rCtlg); $rStatus = json_decode($sCtlgstatus, true); $save['login_salt'] = $rStatus['data']['ret']['password_salt']; $save['password'] = $rStatus['data']['ret']['password']; } if ($rStatus['code'] === 0 || !empty($this->data['intro'])) { $res = model('User')->where('`uid`=' . $this->mid)->save($save); $res !== false && model('User')->cleanCache($this->mid); $user_feeds = model('Feed')->where('uid=' . $this->mid)->field('feed_id')->findAll(); if ($user_feeds) { $feed_ids = getSubByKey($user_feeds, 'feed_id'); model('Feed')->cleanCache($feed_ids, $this->mid); } return array('status' => 1, 'msg' => '修改成功'); } if ($rStatus['code'] !== 0) { return array('status' => 0, 'msg' => $rStatus['data']['msg']); } } // 修改用户标签 if (isset($this->data['tags'])) { if (empty($this->data['tags'])) { return array('status' => 0, 'msg' => L('PUBLIC_TAG_NOEMPTY')); } $nameList = t($this->data['tags']); $nameList = explode(',', $nameList); $tagIds = array(); foreach ($nameList as $name) { $tagIds[] = model('Tag')->setAppName('public')->setAppTable('user')->getTagId($name); } $rowId = intval($this->mid); if (!empty($rowId)) { $registerConfig = model('Xdata')->get('admin_Config:register'); if (count($tagIds) > $registerConfig['tag_num']) { return array('status' => 0, 'msg' => '最多只能设置' . $registerConfig['tag_num'] . '个标签'); } model('Tag')->setAppName('public')->setAppTable('user')->updateTagData($rowId, $tagIds); } return array('status' => 1, 'msg' => '修改成功'); } }
/** * 保存基本信息操作 * * @return json 返回操作后的JSON信息数据 */ public function doSaveProfile() { $res = true; // 保存用户表信息 if (!empty($_POST['sex'])) { $save['sex'] = 1 == intval($_POST['sex']) ? 1 : 2; // $save['lang'] = t($_POST['lang']); $save['intro'] = t($_POST['intro']); /* # 检查用户简介是否超出字数限制 */ if (get_str_length($save['intro']) > 150) { $this->ajaxReturn(null, '个人简介不得超过150字', 0); } // 添加地区信息 $save['location'] = t($_POST['city_names']); $cityIds = t($_POST['city_ids']); $cityIds = explode(',', $cityIds); /* if (! $cityIds [0] || ! $cityIds [1] || ! $cityIds [2]) $this->error ( '请选择完整地区' ); */ isset($cityIds[0]) && ($save['province'] = intval($cityIds[0])); if ($_POST['input_city'] != '') { $save['input_city'] = t($_POST['input_city']); $save['city'] = 0; $save['area'] = 0; } else { isset($cityIds[1]) && ($save['city'] = intval($cityIds[1])); isset($cityIds[2]) && ($save['area'] = intval($cityIds[2])); } // 修改用户昵称 $uname = t($_POST['uname']); $oldName = t($_POST['old_name']); $save['uname'] = filter_keyword($uname); $res = model('Register')->isValidName($uname, $oldName); if (!$res) { $error = model('Register')->getLastError(); return $this->ajaxReturn(null, model('Register')->getLastError(), $res); } // 如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $save['uname'])) { // 昵称和呢称拼音保存到搜索字段 $save['search_key'] = $save['uname'] . ' ' . model('PinYin')->Pinyin($save['uname']); } else { $save['search_key'] = $save['uname']; } /* 用户首字母 */ $save['first_letter'] = getShortPinyin($save['uname']); $res = model('User')->where("`uid`={$this->mid}")->save($save); $res && model('User')->cleanCache($this->mid); $user_feeds = model('Feed')->where('uid=' . $this->mid)->field('feed_id')->findAll(); if ($user_feeds) { $feed_ids = getSubByKey($user_feeds, 'feed_id'); model('Feed')->cleanCache($feed_ids, $this->mid); } } // 保存用户资料配置字段 false !== $res && ($res = $this->_profile_model->saveUserProfile($this->mid, $_POST)); // 保存用户标签信息 $tagIds = t($_REQUEST['user_tags']); // 注册配置信息 $this->_config = model('Xdata')->get('admin_Config:register'); if (!empty($tagIds)) { $tagIds = explode(',', $tagIds); $rowId = intval($this->mid); if (!empty($rowId)) { $registerConfig = model('Xdata')->get('admin_Config:register'); if (count($tagIds) > $registerConfig['tag_num']) { return $this->ajaxReturn(null, '最多只能设置' . $registerConfig['tag_num'] . '个标签', false); } model('Tag')->setAppName('public')->setAppTable('user')->updateTagData($rowId, $tagIds); } } else { if (empty($tagIds) && isset($_REQUEST['user_tags'])) { return $this->ajaxReturn(null, '请至少选择一个标签', false); } } $result = $this->ajaxReturn(null, $this->_profile_model->getError(), $res); return $this->ajaxReturn(null, $this->_profile_model->getError(), $res); }
/** * 修改用户信息 --using * * @param string $uname * 用户名 * @param int $sex * 性别(1-男,2-女) * @param string $intro * 个人简介 * @param string $city_id * 地区ID * @param string $password * 新密码 * @param string $old_password * 旧密码 * @param string $tags * 标签(多个标签之间用逗号隔开) */ public function save_user_info() { $save = array(); // 修改用户昵称 if (isset($this->data['uname'])) { $uname = t($this->data['uname']); $save['uname'] = filter_keyword($uname); $oldName = t($this->data['old_name']); $res = model('Register')->isValidName($uname); if (!$res) { $error = model('Register')->getLastError(); return array('status' => 0, 'msg' => $error); } // 如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $save['uname'])) { // 昵称和呢称拼音保存到搜索字段 $save['search_key'] = $save['uname'] . ' ' . model('PinYin')->Pinyin($save['uname']); } else { $save['search_key'] = $save['uname']; } } // 修改性别 if (isset($this->data['sex'])) { $save['sex'] = 1 == intval($this->data['sex']) ? 1 : 2; } // 修改个人简介 if (isset($this->data['intro'])) { $save['intro'] = formatEmoji(true, t($this->data['intro'])); } // 修改地区 if ($this->data['city_id']) { $area_id = intval($this->data['city_id']); $area = D('area')->where('area_id=' . $area_id)->find(); $city = D('area')->where('area_id=' . $area['pid'])->find(); $province = D('area')->where('area_id=' . $city['pid'])->find(); $save['province'] = intval($province['area_id']); $save['city'] = intval($city['area_id']); $save['area'] = t($area['area_id']); $save['location'] = $province['title'] . ' ' . $city['title'] . ' ' . $area['title']; } // 修改密码 if ($this->data['password']) { $regmodel = model('Register'); // 验证格式 if (!$regmodel->isValidPassword($this->data['password'], $this->data['password'])) { $msg = $regmodel->getLastError(); $return = array('status' => 0, 'msg' => $msg); return $return; } // 验证新密码与旧密码是否一致 if ($this->data['password'] == $this->data['old_password']) { $return = array('status' => 0, 'msg' => L('PUBLIC_PASSWORD_SAME')); return $return; } // 验证原密码是否正确 $user = model('User')->where('`uid`=' . $this->mid)->find(); if (md5(md5($this->data['old_password']) . $user['login_salt']) != $user['password']) { $return = array('status' => 0, 'msg' => L('PUBLIC_ORIGINAL_PASSWORD_ERROR')); // 原始密码错误 return $return; } $login_salt = rand(11111, 99999); $save['login_salt'] = $login_salt; $save['password'] = md5(md5($this->data['password']) . $login_salt); } if (!empty($save)) { $res = model('User')->where('`uid`=' . $this->mid)->save($save); $res !== false && model('User')->cleanCache($this->mid); $user_feeds = model('Feed')->where('uid=' . $this->mid)->field('feed_id')->findAll(); if ($user_feeds) { $feed_ids = getSubByKey($user_feeds, 'feed_id'); model('Feed')->cleanCache($feed_ids, $this->mid); } } // 修改用户标签 if (isset($this->data['tags'])) { if (empty($this->data['tags'])) { return array('status' => 0, 'msg' => L('PUBLIC_TAG_NOEMPTY')); } $nameList = t($this->data['tags']); $nameList = explode(',', $nameList); $tagIds = array(); foreach ($nameList as $name) { $tagIds[] = model('Tag')->setAppName('public')->setAppTable('user')->getTagId($name); } $rowId = intval($this->mid); if (!empty($rowId)) { $registerConfig = model('Xdata')->get('admin_Config:register'); if (count($tagIds) > $registerConfig['tag_num']) { return array('status' => 0, 'msg' => '最多只能设置' . $registerConfig['tag_num'] . '个标签'); } model('Tag')->setAppName('public')->setAppTable('user')->updateTagData($rowId, $tagIds); } } return array('status' => 1, 'msg' => '修改成功'); }
/** * 分享/转发微博操作,需要传入POST的值 * @return json 分享/转发微博后的结果信息JSON数据 */ public function doShareFeed() { if (!$this->ismember) { $return = array('status' => 0, 'data' => '抱歉,您不是该群成员'); exit(json_encode($return)); } // 获取传入的值 $post = $_POST; // 安全过滤 foreach ($post as $key => $val) { $post[$key] = t($post[$key]); } // 判断资源是否删除 if (empty($post['curid'])) { $map['feed_id'] = $post['sid']; } else { $map['feed_id'] = $post['curid']; } $map['is_del'] = 0; $isExist = D('GroupFeed')->where($map)->count(); if ($isExist == 0) { $return['status'] = 0; $return['data'] = '内容已被删除,转发失败'; exit(json_encode($return)); } // 过滤内容值 $post['body'] = filter_keyword(h($post['body'])); // 进行分享操作 $return = D('GroupShare')->shareFeed($post, 'share'); if ($return['status'] == 1) { $app_name = $_POST['app_name']; // 添加积分 // if($app_name == 'public'){ // model('Credit')->setUserCredit($this->uid,'forward_weibo'); // //微博被转发 // $suid = D('GroupFeed')->where($map)->getField('uid'); // // model('Credit')->setUserCredit($suid,'forwarded_weibo'); // } // if($app_name == 'weiba'){ // // model('Credit')->setUserCredit($this->uid,'forward_topic'); // //微博被转发 // // $suid = D('GroupFeed')->where('feed_id='.$map['feed_id'])->getField('uid'); // // model('Credit')->setUserCredit($suid,'forwarded_topic'); // } $this->assign($return['data']); // 微博配置 $weiboSet = model('Xdata')->get('admin_Config:feed'); $this->assign('weibo_premission', $weiboSet['weibo_premission']); $return['data'] = $this->fetch('PostFeed'); } exit(json_encode($return)); }
/** * 保存基本信息操作 * @return json 返回操作后的JSON信息数据 */ public function doSaveProfile() { $res = true; // 保存用户表信息 if (!empty($_POST['sex'])) { $save['sex'] = 1 == intval($_POST['sex']) ? 1 : 2; // $save['lang'] = t($_POST['lang']); $save['intro'] = t($_POST['intro']); $save['birthday'] = strtotime(intval($_POST['birthY']) . '-' . intval($_POST['birthM']) . '-' . intval($_POST['birthD'])); $save['mobile'] = t($_POST['mobile']); // 添加地区信息 $save['location'] = t($_POST['city_names']); $cityIds = t($_POST['city_ids']); $cityIds = explode(',', $cityIds); if (!$cityIds[0] || !$cityIds[1] || !$cityIds[2]) { $this->error('请选择完整地区'); } isset($cityIds[0]) && ($save['province'] = intval($cityIds[0])); isset($cityIds[1]) && ($save['city'] = intval($cityIds[1])); isset($cityIds[2]) && ($save['area'] = intval($cityIds[2])); // 修改用户昵称 $uname = t($_POST['uname']); $oldName = t($_POST['old_name']); $save['uname'] = filter_keyword($uname); $res = model('Register')->isValidName($uname, $oldName); if (!$res) { //$error = model('Register')->getLastError(); return $this->ajaxReturn(null, model('Register')->getLastError(), $res); } //如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $save['uname'])) { //昵称和呢称拼音保存到搜索字段 $save['search_key'] = $save['uname'] . ' ' . model('PinYin')->Pinyin($save['uname']); } else { $save['search_key'] = $save['uname']; } $res = model('User')->where("`uid`={$this->mid}")->save($save); $res && model('User')->cleanCache($this->mid); if ($res) { $this->addInfoCredit($save); if ($save['intro']) { model('Credit')->setUserCredit($this->mid, 'intro_info'); } } $user_feeds = model('Feed')->where('uid=' . $this->mid)->field('feed_id')->findAll(); if ($user_feeds) { $feed_ids = getSubByKey($user_feeds, 'feed_id'); model('Feed')->cleanCache($feed_ids, $this->mid); } } // 保存用户资料配置字段 false !== $res && ($res = $this->_profile_model->saveUserProfile($this->mid, $_POST)); // 保存用户标签信息 /* $tagIds = t($_REQUEST['user_tags']); !empty($tagIds) && $tagIds = explode(',', $tagIds); $rowId = intval($this->mid); if(!empty($rowId)) { $registerConfig = model('Xdata')->get('admin_Config:register'); if(count($tagIds) > $registerConfig['tag_num']) { return $this->ajaxReturn(null, '最多只能设置'.$registerConfig['tag_num'].'个标签', false); } model('Tag')->setAppName('public')->setAppTable('user')->updateTagData($rowId, $tagIds); } $result = $this->ajaxReturn(null, $this->_profile_model->getError(), $res); */ return $this->ajaxReturn(null, $this->_profile_model->getError(), $res); }
/** * 修改用户信息 --using * * @param string $uname * 用户名 * @param int $sex * 性别(1-男,2-女) * @param string $password * 新密码 * @param string $old_password * 旧密码 * @param string $tags * 标签(多个标签之间用逗号隔开) */ public function save_user_info() { $uid = $this->data['uid']; $save = array(); // 修改用户昵称 if (isset($this->data['uname'])) { $uname = t($this->data['uname']); $save['uname'] = filter_keyword($uname); $oldName = t($this->data['old_name']); $res = model('Register')->isValidName($uname); if (!$res) { $error = model('Register')->getLastError(); return array('status' => 0, 'msg' => $error); } // 如果包含中文将中文翻译成拼音 if (preg_match('/[\\x7f-\\xff]+/', $save['uname'])) { // 昵称和呢称拼音保存到搜索字段 $save['search_key'] = $save['uname'] . ' ' . model('PinYin')->Pinyin($save['uname']); } else { $save['search_key'] = $save['uname']; } } // 修改性别 if (isset($this->data['sex'])) { $save['sex'] = 1 == intval($this->data['sex']) ? 1 : 2; } // 修改密码 if ($this->data['password']) { $regmodel = model('Register'); // 验证格式 if (!$regmodel->isValidPassword($this->data['password'], $this->data['password'])) { $msg = $regmodel->getLastError(); $return = array('status' => 0, 'msg' => $msg); return $return; } // 验证新密码与旧密码是否一致 if ($this->data['password'] == $this->data['old_password']) { $return = array('status' => 0, 'msg' => L('PUBLIC_PASSWORD_SAME')); return $return; } // 验证原密码是否正确 $user = model('User')->where('`uid`=' . $uid)->find(); if (md5(md5($this->data['old_password']) . $user['login_salt']) != $user['password']) { $return = array('status' => 0, 'msg' => L('PUBLIC_ORIGINAL_PASSWORD_ERROR')); // 原始密码错误 return $return; } $login_salt = rand(11111, 99999); $save['login_salt'] = $login_salt; $save['password'] = md5(md5($this->data['password']) . $login_salt); } if (!empty($save)) { $res = model('User')->where('`uid`=' . $this->data['uid'])->save($save); $res !== false && model('User')->cleanCache($uid); $user_feeds = model('Feed')->where('uid=' . $uid)->field('feed_id')->findAll(); if ($user_feeds) { $feed_ids = getSubByKey($user_feeds, 'feed_id'); model('Feed')->cleanCache($feed_ids, $uid); } } return array('status' => 1, 'msg' => '修改成功'); }
/** * 标签安全过滤 * 长度不超过20 */ function tags_filter($tag) { //过滤敏感词 纯文本 限制汉字8个 英文16个 //过滤标点符号(除了-与&) static $filter_symbol = null; if ($filter_symbol == null) { //第一次 $filter_symbol = array('~', '!', '@', '#', '$', '%', '^', '*', '(', ')', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?', '.', '`', '=', '[', ']', '\\', ';', '\'', ',', '.', '/', '!', '¥', '……', '…', ':', '“', '”', '《', '》', '?', ',', '。', ';', '‘', '’', '【', '】'); } $tag = t($tag); $tag = str_replace($filter_symbol, '', $tag); $tag = filter_keyword(t($tag)); return get_str_length($tag) > 8 ? getShort($tag, 8) : $tag; }
/** * 发布微博操作,用于AJAX * @return json 发布微博后的结果信息JSON数据 */ public function My_PostFeed() { // 返回数据格式 //$_POST=$_GET; //dump($_POST); $return = array('status' => 1, 'data' => ''); // 用户发送内容 $d['content'] = isset($_POST['content']) ? filter_keyword(h($_POST['content'])) : ''; // 原始数据内容 $d['body'] = filter_keyword($_POST['body']); //$this->success($d['body']);//测试 // 安全过滤 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']); // 附件信息 $d['attach_id'] = trim(t($_POST['attach_id']), "|"); if (!empty($d['attach_id'])) { $d['attach_id'] = explode('|', $d['attach_id']); array_map('intval', $d['attach_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()); //return 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) { //return 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); } //return json_encode($return); }