public function add_log($content, $type = 'login') { if ($this->settings['App_logs']) { $this->add2log($content, $type); } else { $this->db = hg_checkDB(); if ($this->input['id']) { $ids = '(' . $this->input['id'] . ')'; } $ip = hg_getip(); $ipaddr = hg_getIpInfo($ip, 5); if ($ipaddr) { $zone = $ipaddr[0]['zone']; $service = $ipaddr[0]['service']; } $data = array('content' => $content . $ids, 'type' => $type, 'admin_id' => intval($this->user['id']), 'user_name' => $this->user['user_name'], 'group_type' => $this->user['group_type'], 'ip' => $ip, 'ip_info' => $zone . ' ' . $service, 'create_time' => TIMENOW, 'script_name' => SCRIPT_NAME . '::' . REFERRER); hg_fetch_query_sql($data, 'log'); } }
/** * 回复会话消息 * * @param session_id 会话id * @param mesage 回复内容 */ public function reply_session() { if (!$this->user['user_id']) { $this->errorOutput(NO_LOGIN); } if (!$this->input['session_id']) { $this->errorOutput(NO_SESSIONID); } if (!trim($this->input['message']) && (empty($_FILES['imgs']) || $_FILES['imgs']['error'] == 4) && (empty($_FILES['videofile']) || $_FILES['videofile']['error'] == 4) && (empty($_FILES['audiofile']) || $_FILES['audiofile']['error'] == 4)) { $this->errorOutput(NO_MESSAGE); } $session_id = intval($this->input['session_id']); $message = $this->input['message']; $send_uid = $this->user['user_id']; $send_uname = $this->user['user_name']; $send_utype = $this->user['user_type']; $send_device_token = $this->input['user_device_token']; $send_appid = $this->input['user_appid'] ? $this->input['user_appid'] : $this->user['appid']; $send_user = $this->mode->get_member_info($send_uname, $send_uid, $send_utype, $send_device_token, $send_appid); //判断用户是否已经在会话中 /* $session_users = $this->mode->session_users($session_id); $session_users = $session_users[$session_id]; $exists_users = array(); foreach ((array) $session_users as $k => $v) { $exists_users[$v['uid']] = $v; } if ( !array_key_exists($send_uid, $exists_users) || ($send_utype != $exists_users[$send_uid]['utype']) ) { $this->errorOutput('你不在此会话中'); } */ //如果用户不在此会话中 将用户加入此会话 $session_users = $this->mode->session_users($session_id); $session_users = $session_users[$session_id]; $exists_users = array(); foreach ((array) $session_users as $k => $v) { $exists_users[$v['uid']] = $v; } $this->mode->ender_session($session_id, $send_user, $exists_users); $message_info = array('session_id' => $session_id, 'send_uid' => $send_user[0]['user_id'], 'send_uname' => $send_user[0]['user_name'], 'send_uavatar' => $send_user[0]['user_avatar'] ? addslashes(serialize($send_user[0]['user_avatar'])) : '', 'send_utype' => $send_user[0]['user_type'], 'message' => $message, 'send_time' => TIMENOW, 'ip' => hg_getip(), 'location' => $this->input['location'], 'longitude' => $this->input['longitude'], 'latitude' => $this->input['latitude'], 'status' => intval($this->input['status'])); !$message_info['location'] && $message_info['ip'] && ($message_info['location'] = hg_getIpInfo($message_info['ip'])); $imgs = $videos = array(); //图片上传 if ($_FILES['imgs']) { $imgs = $this->mode->upload_imgs($_FILES); if ($imgs['error']) { $this->errorOutput($imgs['error']); } } //视频上传 if ($_FILES['videofile']) { $videos = $this->mode->upload_video($_FILES, $message_info['message']); if ($videos['error']) { $this->errorOutput($videos['error']); } } //音频上传 不提交到转码 if ($_FILES['audiofile']) { $audios = $this->mode->upload_audio($_FILES); if ($audios['error']) { $this->errorOutput($audios['error']); } } $message_info['imgs'] = $imgs ? serialize($imgs) : ''; $message_info['videos'] = $videos ? serialize($videos) : ''; $message_info['audios'] = $audios ? serialize($audios) : ''; $message_info['id'] = $insert_id = $this->db->insert_data($message_info, 'message'); //更新会话最新发消息人信息 $session_info = array('last_message' => $message_info['message'], 'last_time' => TIMENOW, 'last_uid' => $message_info['send_uid'], 'last_uname' => $message_info['send_uname'], 'last_uavatar' => $message_info['send_uavatar']); $this->db->update_data($session_info, 'session', ' id=' . $session_id); //把会话中所有人的信息未读数+1 // $sql = "UPDATE ".DB_PREFIX.'session_user SET unread_counts = unread_counts + 1 WHERE session_id = ' . $session_id . ' AND uid != ' . $this->user['user_id'] . ' AND utype != \''.$this->user['user_type'].'\''; $sql = "UPDATE " . DB_PREFIX . 'session_user SET unread_counts = unread_counts + 1 WHERE session_id = ' . $session_id . ' AND ( uid != ' . $this->user['user_id'] . ' OR utype != \'' . $this->user['user_type'] . '\')'; $this->db->query($sql); //有新会话时把所有用户的删除状态改为0 $sql = "UPDATE " . DB_PREFIX . "session_user SET del_status = 0 WHERE session_id = " . $session_id; $this->db->query($sql); $message_info['send_uavatar'] = $message_info['send_uavatar'] ? unserialize(stripslashes($message_info['send_uavatar'])) : array(); $message_info['imgs'] = $message_info['imgs'] ? unserialize(stripslashes($message_info['imgs'])) : array(); $message_info['videos'] = $message_info['videos'] ? unserialize(stripslashes($message_info['videos'])) : array(); $message_info['audios'] = $message_info['audios'] ? unserialize(stripslashes($message_info['audios'])) : array(); //推送消息 $session_info = $this->mode->session_info($session_id, 'settings'); if ($session_info['settings']['push_notice']) { foreach ((array) $session_users as $k => $v) { $session_users[$k]['user_id'] = $v['uid']; $session_users[$k]['user_type'] = $v['utype']; } $this->mode->push_notice($message_info['message'], $session_users, $send_user); } //推送消息 $this->addItem($message_info); $this->output(); }
public function add_message() { $content = trim($this->input['content']); if (!$content) { $this->errorOutput(NOCONTENT); } if (!get_magic_quotes_gpc()) { $content = addslashes($content); } //根据发布id查询信息 $cmid = intval($this->input['cmid']); if (!$cmid) { //非发布库内容评论要传入应用标识和模块标识 if (!$this->input['app_uniqueid'] || !$this->input['mod_uniqueid']) { $this->errorOutput(NOUNIQUEID); } } //评论设置 $set = $this->comment_set(); $contentid = intval($this->input['contentid']); if (!$contentid) { $this->errorOutput(NOCONTENTID); } $display = $set['display']; //是否审核显示 $max_word = $set['max_word']; //评论最大字数 $login = $set['is_login']; //是否登录评论 $colation = $set['colation']; //是否过滤 $is_open = $set['state']; //评论开启关闭 $rate = $set['rate']; //评论频率限制 $allow_reply = $set['allow_reply']; //回复设置 $verify_mode = $set['verify_mode']; //验证码 $is_credits = $set['is_credits']; //未审核获取积分 $is_credits_extra = $set['is_credits_extra']; //审核获取积分 $is_diy_credits = $set['is_diy_credits']; //自定义积分规则 $same_user_same_record = $set['same_user_same_record']; //评论功能开启/关闭 if (!$is_open) { $this->errorOutput(MESSAGECLOSED); } $fid = intval($this->input['fid']); if ($fid && !$allow_reply) { $this->errorOutput(REPLYCLOSED); } //登陆评论 if ($login) { if ($this->user['user_id'] < 1) { $this->errorOutput(NOTLOGIN); } } if ($max_word) { //评论长度判断 $len = ''; $len = strlen($content); if ($len > $max_word * 3) { $this->errorOutput(MAXNUM); } } //审核显示 $state = $display ? 0 : 1; if ($app_id = $this->input['app_id']) { $appconfig = $this->appconfig->detail($app_id); if ($appconfig['comment_audit'] == 0) { $state = 1; } else { $state = 0; } } //过滤敏感词 if ($colation && $this->settings['App_banword']) { include_once ROOT_PATH . 'lib/class/banword.class.php'; $this->banword = new banword(); $banword = $this->banword->exists($content); if ($banword) { $colation_state = ''; if ($colation == 1) { $this->errorOutput(BANWORD); } elseif ($colation == 2) { $colation_state = 3; } elseif ($colation == 3) { $content = $this->banword->replace($content, '*'); $colation_state = 0; //替换后状态为未审核 } //如果存在敏感词,敏感词的设置高于普通设置 if ($colation_state) { $state = $colation_state; } //记录敏感词 $banwords = array(); foreach ($banword as $v) { $banwords[] = $v['banname']; } $banwords = implode(',', $banwords); } } //验证码开启并且安装验证码 if ($this->settings['App_verifycode'] && $verify_mode) { if (!$this->input['not_need_verifycode']) { include_once ROOT_PATH . 'lib/class/verifycode.class.php'; $this->mVerifyCode = new verifycode(); $verifycode = trim($this->input['verify_code']); $session_id = trim($this->input['session_id']); if (!$verifycode || !$session_id) { $this->errorOutput(VERIFY); } $check_result = $this->mVerifyCode->check_verify_code($verifycode, $session_id); //验证验证码 if ($check_result != 'SUCCESS') { $data['error'] = $check_result; $this->addItem($data); $this->output(); } } } //兼容user_name传递用户昵称 if ($this->input['user_name'] && !$this->input['author']) { $this->input['author'] = $this->input['user_name']; } $data = array('title' => urldecode($this->input['title']), 'username' => $this->user['user_name'], 'author' => trim($this->input['author']), 'member_id' => $this->user['user_id'], 'content' => $content, 'pub_time' => TIMENOW, 'ip' => hg_getip(), 'state' => $state, 'contentid' => $contentid, 'content_title' => $this->input['content_title'], 'content_url' => $this->input['content_url'], 'cmid' => $cmid, 'app_uniqueid' => $this->input['app_uniqueid'], 'mod_uniqueid' => $this->input['mod_uniqueid'], 'site_id' => $this->input['site_id'], 'column_id' => $this->input['column_id'], 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'long' => $this->input['long'], 'lati' => $this->input['lati'], 'banword' => $banwords, 'fid' => $fid, 'member_type' => intval($this->input['member_type']), 'groupid' => intval($this->input['groupid']), 'baidu_longitude' => $this->input['baidu_longitude'], 'baidu_latitude' => $this->input['baidu_latitude'], 'address' => $this->input['address']); //获取ip的地域信息 if (function_exists('hg_getIpInfo')) { $data['ip_info'] = hg_getIpInfo($data['ip']); } //入库 $mes = new Message(); $res = $mes->add_message($data, $rate); if (!$res) { $this->errorOutput(RATE); } $res['pub_time'] = date('Y-m-d H:i:s', $res['pub_time']); /***********************调用积分规则,给已审核评论增加积分START*****************/ if ($this->input['iscreditsrule']) { include ROOT_PATH . 'lib/class/members.class.php'; $Members = new members(); if ($this->settings['App_members']) { if ($res['member_id'] && $same_user_same_record) { $res_total = $mes->return_count(" AND contentid=" . $res['contentid'] . " AND cmid = " . $res['cmid'] . " AND app_uniqueid = '" . $res['app_uniqueid'] . "' AND mod_uniqueid = '" . $res['mod_uniqueid'] . "' AND member_id=" . $res['member_id'], $tableName); } if ($res_total['total'] - 1 < $same_user_same_record || empty($same_user_same_record)) { $Members->Initoperation(); //初始化 $Members->Setoperation(APP_UNIQUEID); /***未审核增加积分**/ if ($is_credits && $this->user['user_id']) { $credit_rules = $Members->get_credit_rules($this->user['user_id'], $data['app_uniqueid'], $data['mod_uniqueid'], $data['column_id'], $data['contentid']); } /***审核增加积分**/ if ($is_credits_extra && $res['state'] == 1 && $this->user['user_id']) { $Members->Initoperation(); //初始化 $Members->Setoperation(APP_UNIQUEID, '', '', 'extra'); $credit_rules_extra = $Members->get_credit_rules($this->user['user_id'], $data['app_uniqueid'], $data['mod_uniqueid'], $data['column_id'], $data['contentid']); $field = 'is_credits=0'; //已经增加积分 } elseif (empty($is_credits_extra)) { $field = 'is_credits=-1'; //禁止增加积分,因为未开启审核增加积分,所以即使审核也不增加 } } else { $field = 'is_credits=-1'; //禁止增加积分,此会员此条记录评论超过限制次数 } } /**积分文案处理**/ $credit_copy = array(); if ($credit_rules['updatecredit']) { $credit_copy[] = $credit_rules; } if ($credit_rules_extra['updatecredit']) { $credit_copy[] = $credit_rules_extra; } $res['copywriting_credit'] = $Members->copywriting_credit($credit_copy); /**积分文案处理结束**/ } else { $field = 'is_credits=-1'; //禁止增加积分,非新会员 } /**更新获得积分字段**/ if ($field) { $this->db->query("UPDATE " . DB_PREFIX . "{$res['tableame']} SET " . $field . " WHERE id=" . $res['id']); } /***********************调用积分规则,给已审核评论增加积分END*****************/ //已审核状态 if ($res['state'] == 1) { /***********************即时更新内容评论计数****************************/ if ($this->settings['App_' . $data['app_uniqueid']]) { $path['host'] = $this->settings['App_' . $data['app_uniqueid']]['host']; $path['dir'] = $this->settings['App_' . $data['app_uniqueid']]['dir'] . 'admin/'; if ($path) { $host = $path['host']; $dir = $path['dir']; $filename = $data['app_uniqueid']; if ($filename == 'livmedia') { $filename = 'vod'; } else { if ($filename == 'cheapbuy') { $filename = 'product'; } } include_once ROOT_PATH . 'lib/class/curl.class.php'; $curl = new curl($host, $dir); $curl->setSubmitType('post'); $curl->initPostData(); $curl->addRequestData('a', 'update_comment_count'); $curl->addRequestData('id', $data['contentid']); $curl->addRequestData('type', 'audit'); $curl->request($filename . '_update.php'); } } /***********************即时更新内容评论计数****************************/ /***********************更新会员我的评论计数****************************/ if ($this->settings['App_members']) { $path['host'] = $this->settings['App_members']['host']; $path['dir'] = $this->settings['App_members']['dir']; if ($path) { include_once ROOT_PATH . 'lib/class/curl.class.php'; $curl = new curl($path['host'], $path['dir']); $curl->setSubmitType('post'); $curl->initPostData(); $curl->addRequestData('a', 'create'); $curl->addRequestData('mark', 'mymessage'); $curl->addRequestData('totalsum', 1); $curl->addRequestData('summath', 1); $curl->addRequestData('access_token', $this->user['token']); $curl->request('member_my_update.php'); } } /***********************更新会员我的评论计数****************************/ } //统计app下面的评论计数 if ($data['appid']) { $sql = "SELECT appid FROM " . DB_PREFIX . "message_appinfo WHERE appid = " . $data['appid']; if ($this->db->query_first($sql)) { $sql = "UPDATE " . DB_PREFIX . "message_appinfo SET appname='" . $data['appname'] . "',comment_num = comment_num+1 WHERE appid=" . $data['appid']; } else { $sql = "INSERT INTO " . DB_PREFIX . "message_appinfo SET appid=" . $data['appid'] . ",appname='" . $data['appname'] . "',comment_num=comment_num+1"; } $this->db->query($sql); } $res['copywriting'] = '评论成功'; $this->addItem($res); $this->output(); }
public function create() { if (empty($this->input)) { return false; } $info = array(); $operation = array(); $user_name = ''; //获取应用标识 $info['bundle_id'] = $operation['bundle_id'] = urldecode($this->input['bundle_id']); //获取模板标识 $info['moudle_id'] = $operation['moudle_id'] = urldecode($this->input['moudle_id']); //获取操作人id $info['user_id'] = $this->user['user_id']; //获取操作人 $info['user_name'] = $user_name = urldecode($this->user['user_name']); //获取操作类型 //$info['operation'] = urldecode($this->input['operation']); $operation['op_name'] = urldecode($this->input['operation']); //获取操作标识 $operation['action'] = trim($this->input['action']); //获取ip $info['ip'] = hg_getip(); if (function_exists('hg_getIpInfo')) { $info['ip_info'] = hg_getIpInfo($info['ip']); } //获取操作时间 $info['create_time'] = TIMENOW; //获取来源 $info['source'] = urldecode($this->user['display_name']); //获取经度 $info['longtitude'] = $this->user['lon']; //获取纬度 $info['latitude'] = $this->user['lat']; //获取内容id $info['content_id'] = intval($this->input['content_id']); //获取内容id $info['sort_id'] = intval($this->input['sort_id']); //获取标题 $info['title'] = urldecode($this->input['title']); $info['org_id'] = intval($this->user['org_id']); $sq_ = "SELECT id,action FROM " . DB_PREFIX . "system_log_operation WHERE bundle_id = '" . $operation['bundle_id'] . "'" . " AND moudle_id = '" . $operation['moudle_id'] . "'" . " AND op_name = '" . $operation['op_name'] . "'"; $q_ = $this->db->query_first($sq_); $op_id = $q_['id']; if (!$op_id) { $sql = 'INSERT INTO ' . DB_PREFIX . 'system_log_operation SET '; foreach ($operation as $key => $val) { $sql .= $key . '="' . $val . '",'; } $sql = rtrim($sql, ','); $this->db->query($sql); $op_id = $this->db->insert_id(); } elseif (!$q_['action'] || $q_['action'] != $action) { $sql = 'UPDATE ' . DB_PREFIX . 'system_log_operation SET action = "' . $operation['action'] . '" WHERE id = ' . $op_id; $this->db->query($sql); } //获取操作id $info['operation'] = $op_id; $sq = "SELECT id FROM " . DB_PREFIX . "systerm_log_user WHERE user_name = '" . $user_name . "'"; $q = $this->db->query_first($sq); if (!$q['id']) { $sql_ = "INSERT INTO " . DB_PREFIX . "systerm_log_user SET user_name = '" . $user_name . "'"; $this->db->query($sql_); } $ret = $this->obj->addLogs($info); $this->addItem($ret); $this->output(); }