function add($p, $delete_if_exists = 0) { $rets = array(); $buddyid = (int) ($p['buddyid'] ? $p['buddyid'] : $p['touid']); $uid = $p['uid'] > 0 ? $p['uid'] : MEMBER_ID; if ($uid < 1 || $buddyid < 1 || $uid == $buddyid) { $rets['error'] = '您不能关注自己'; return $rets; } $query = DB::query("SELECT * FROM `" . TABLE_PREFIX . "members` WHERE `uid` IN ('{$uid}','{$buddyid}')"); $members = array(); while (false != ($row = DB::fetch($query))) { $members[$row['uid']] = $row; } $info = $this->info($buddyid, $uid); if (!$info) { $sys_config = jconf::get(); if (count($members) < 2) { $rets['error'] = '关注失败,TA已经消失不见了'; return $rets; } if ($sys_config['follow_limit'] > 0 && $members[$uid]['follow_count'] >= $sys_config['follow_limit']) { $rets['error'] = '本站限制关注数量为<b>' . $sys_config['follow_limit'] . '</b>人,您不能再关注更多的好友了'; return $rets; } if ($members[$buddyid]['disallow_beiguanzhu']) { $rets['error'] = '关注失败,TA设置了禁止被关注'; return $rets; } if (is_blacklist($uid, $buddyid)) { $rets['error'] = '关注失败,对方已将您拉入了黑名单'; return $rets; } $_tmps = jsg_role_check_allow('follow', $buddyid, $uid); if ($_tmps && $_tmps['error']) { return $_tmps; } jtable('buddy_follow')->add($uid, $buddyid); jtable('buddy_fans')->add($buddyid, $uid); ios_push_msg($buddyid, '你有新消息:1个粉丝'); $this->count($uid); $this->count($buddyid); if ($sys_config['sendmailday'] > 0) { jtable('mailqueue')->add($members[$buddyid], 'notice_fans'); } if ($sys_config['extcredits_enable'] && $uid > 0) { $update_credits = false; if ($members[$buddyid]['nickname']) { $update_credits = update_credits_by_action("_U" . crc32($members[$buddyid]['nickname']), $uid); } if (!$update_credits) { update_credits_by_action('buddy', $uid); } } if ($sys_config['imjiqiren_enable'] && imjiqiren_init($sys_config)) { imjiqiren_send_message($members[$buddyid], 'f'); } if ($sys_config['sms_enable'] && sms_init($sys_config)) { sms_send_message($members[$buddyid], 'f'); } } else { if ($delete_if_exists) { $this->del_info($buddyid, $uid); } } return $info; }
function pmSend($post, $suid = MEMBER_ID, $susername = MEMBER_NAME, $snickname = MEMBER_NICKNAME) { if (jaccess('pm', 'send', $suid) == false) { return 6; } $to_user_list = array(); $f_rets = filter($post['message']); if ($f_rets) { if ($f_rets['error']) { return $f_rets['msg']; } } $post['subject'] = jhtmlspecialchars(trim($post['subject'])); $p_to_user = $post['to_user']; if (empty($p_to_user)) { return 2; } $this->_process_content($post['message']); if ($post['message'] == '') { return 1; } $p_to_user = (array) $p_to_user; $nks = array(); foreach ($p_to_user as $tmps) { $tmps = (string) $tmps; if (false !== strpos($tmps, ',')) { $_tmps = explode(',', $tmps); foreach ($_tmps as $_tmp) { $nk = addslashes($_tmp); $nks[$nk] = $nk; } } else { $nk = addslashes($tmps); $nks[$nk] = $nk; } } $sql = "\r\n\t\tSELECT\r\n\t\t\t`uid`,`username`,`nickname`,`notice_pm`,`email`,`email_checked`,`newpm`,`at_new`,`event_new`,`fans_new`,`vote_new`,`qun_new`,`dig_new`,`channel_new`,`company_new`,`comment_new`,`user_notice_time`,`lastactivity`\r\n\t\tFROM\r\n\t\t\t" . TABLE_PREFIX . 'members' . "\r\n\t\tWHERE `nickname` IN (" . jimplode($nks) . ") ORDER BY `uid` limit 100"; $query = $this->DatabaseHandler->Query($sql); $to_uids = array(); while ($row = $query->GetRow()) { if ($suid == MEMBER_ID) { if (is_blacklist($suid, $row['uid'])) { return '你在' . $row['nickname'] . '的黑名单中,不被允许发私信'; } } $rets = jsg_role_check_allow('sendpm', $row['uid'], $suid); if ($rets && $rets['error']) { return $rets['error']; } else { $to_user_list[$row['uid']] = $row; $to_uids[$row['uid']] = $row['uid']; } } ios_push_msg($to_uids, '你有新消息:1条私信'); if ($to_user_list == false) { return 3; } $time = time(); foreach ($to_user_list as $to_user_id => $to_user_name) { $data = array("msgfrom" => $susername, "msgnickname" => $snickname, "msgfromid" => $suid, "msgto" => $to_user_name['username'], "tonickname" => $to_user_name['nickname'], "msgtoid" => $to_user_id, 'imageids' => $post['imageids'], 'attachids' => $post['attachids'], "subject" => $post['subject'], "message" => $post['message'], "new" => '1', "dateline" => $time); if ($post["save_to_outbox"]) { $data['folder'] = "outbox"; $msg = "消息已经保存草稿箱"; } $uids = ''; if ($suid > $to_user_id) { $uids = $to_user_id . "," . $suid; } else { $uids = $suid . "," . $to_user_id; } $plid = 0; if (!$msg) { $lastmessage = addslashes(serialize($data)); $plid = DB::result_first("select plid from " . TABLE_PREFIX . "pms_index where uids = '{$uids}'"); if ($plid == 0) { DB::query("insert into " . TABLE_PREFIX . "pms_index (uids) values('{$uids}')"); $plid = $this->DatabaseHandler->Insert_ID(); if (0 != $plid) { DB::query("insert into " . TABLE_PREFIX . "pms_list (plid,uid,pmnum,dateline,lastmessage) values('{$plid}','" . $suid . "',1,'{$time}','{$lastmessage}')"); if ($suid != $to_user_id) { DB::query("insert into " . TABLE_PREFIX . "pms_list (plid,uid,pmnum,dateline,lastmessage,is_new) values('{$plid}','{$to_user_id}',1,'{$time}','{$lastmessage}',1)"); } } } else { DB::query("update " . TABLE_PREFIX . "pms_list set pmnum = pmnum + 1,dateline = '{$time}',lastmessage = '{$lastmessage}',is_new = 1 where plid = '{$plid}' and uid = '{$to_user_id}' "); if ($suid != $to_user_id) { DB::query("update " . TABLE_PREFIX . "pms_list set pmnum = pmnum + 1,dateline = '{$time}',lastmessage = '{$lastmessage}',is_new = 0 where plid = '{$plid}' and uid = '{$suid}' "); } } } $data['plid'] = $plid; DB::insert('pms', $data); } #标记音乐和附件,使清缓存的时候不会把附件删除 if ($data['imageids']) { DB::query("update `" . TABLE_PREFIX . "topic_image` set `tid` = -1 where `id` in ({$data['imageids']})"); } if ($data['attachids']) { DB::query("update `" . TABLE_PREFIX . "topic_attach` set `tid` = -1 where `id` in ({$data['attachids']})"); } $num = $post["save_to_outbox"] ? 0 : 1; if ($num > 0) { $_tmps = array_keys($to_user_list); $to_user_id_list = array(); foreach ($_tmps as $_tmp) { $_tmp = (int) $_tmp; if ($_tmp > 0) { $to_user_id_list[$_tmp] = $_tmp; } } $this->UpdateNewMsgCount($num, $to_user_id_list); foreach ($to_user_list as $user_notice) { if ($GLOBALS['_J']['config']['sendmailday'] > 0) { jtable('mailqueue')->add($user_notice, 'notice_pm'); } if ($GLOBALS['_J']['config']['imjiqiren_enable'] && imjiqiren_init()) { imjiqiren_send_message($user_notice, 'm', $GLOBALS['_J']['config']); } if ($GLOBALS['_J']['config']['sms_enable'] && sms_init()) { sms_send_message($user_notice, 'm', $GLOBALS['_J']['config']); } } if ($GLOBALS['_J']['config']['extcredits_enable'] && $suid > 0) { update_credits_by_action('pm', $suid, count($to_user_list)); } } if (!$post['is_pm_to_admin_notice']) { $this->to_admin_notice($to_uids); } return 0; }
private function _process_content($content, $topic_info = array()) { $return = array(); $content .= ' '; $cont_sch = $cont_rpl = $at_uids = $tags = $urls = array(); $tuid = (int) $topic_info['uid']; # @user if (false !== strpos($content, '@')) { if (preg_match_all('~\\@([\\w\\d\\_\\-\\x7f-\\xff]+)(?:[\\r\\n\\t\\s ]+|[\\xa1\\xa1]+|[\\xa3\\xac]|[\\xef\\xbc\\x8c]|[\\,\\.\\;\\[\\#])~', $content, $match)) { if (is_array($match[1]) && count($match[1])) { foreach ($match[1] as $k => $v) { $v = trim($v); if (' ' == substr($v, -2)) { $v = substr($v, 0, -2); } if ($v && strlen($v) < 16) { $match[1][$k] = $v; } } $sql = "select `uid`,`nickname`,`username` from `" . TABLE_PREFIX . "members` where `nickname` in ('" . implode("','", $match[1]) . "') "; $query = DB::query($sql); while (false != ($row = DB::fetch($query))) { if ($row['uid'] > 0 && !is_blacklist($tuid, $row['uid']) && !jsg_role_check_allow('topic_at', $row['uid'], $tuid)) { $_at = "@{$row['nickname']} "; $cont_sch[$_at] = $_at; $cont_rpl[$_at] = "<M {$row['username']}>@{$row['nickname']}</M> "; $at_uids[$row['uid']] = $row['uid']; } } } } } if ($topic_info['roottid'] > 0 && in_array($topic_info['type'], array('forward'))) { $rtopic = $this->Get($topic_info['roottid']); $ruid = (int) $rtopic['uid']; if ($ruid > 0 && $ruid != $tuid && !is_blacklist($tuid, $ruid) && !jsg_role_check_allow('topic_at', $ruid, $tuid)) { $at_uids[$ruid] = $ruid; } } if (false !== strpos($content, '#')) { $tag_num = jconf::get('tag_num', 'topic'); if (preg_match_all('~\\#([^\\/\\@\\#\\[\\$\\{\\}\\(\\)\\;\\<\\>\\\\]+?)\\#~', $content, $match)) { $i = 0; foreach ($match[1] as $v) { $v = trim($v); if (($vl = strlen($v)) < 2 || $vl > 60) { continue; } $tags[$v] = $v; $_tag = "#{$v}#"; $cont_sch[$_tag] = $_tag; $cont_rpl[$_tag] = "<T>#{$v}#</T>"; if (++$i >= $tag_num) { break; } } } } if (false !== strpos($content, ':/' . '/') || false !== strpos($content, 'www.')) { if (preg_match_all('~(?:https?\\:\\/\\/|www\\.)(?:[A-Za-z0-9\\_\\-]+\\.)+[A-Za-z0-9]{1,4}(?:\\:\\d{1,6})?(?:\\/[\\w\\d\\/=\\?%\\-\\&\\;_\\~\\`\\:\\+\\#\\.\\@\\[\\]]*(?:[^\\<\\>\'\\"\\n\\r\\t\\s\\x7f-\\xff])*)?~i', $content, $match)) { foreach ($match[0] as $v) { $v = trim($v); if (($vl = strlen($v)) < 8) { continue; } if (strtolower($GLOBALS['_J']['config']['site_url']) == strtolower(substr($v, 0, strlen($GLOBALS['_J']['config']['site_url'])))) { continue; } if ('.wmv' == substr($v, -4)) { continue; } if (!($arr = jlogic('url')->info($v))) { continue; } $_process_result = array(); if (!isset($urls[$v]) && ($_process_result = $this->_process_url($v))) { $urls[$v] = $_process_result; } $rpl = ($_process_result['content'] ? " {$_process_result['content']} " : "") . "<U {$arr['key']}>{$v}</U>"; if ('image' == $_process_result['type']) { $rpl = ' '; if (strlen(trim($content)) <= strlen($v)) { $rpl = ' 分享图片 '; } } elseif ('music' == $_process_result['type']) { $rpl = ' '; if (strlen(trim($content)) <= strlen($v)) { $rpl = ' 分享音乐 '; } } $cont_sch[$v] = "{$v}"; $cont_rpl[$v] = $rpl; } } } if ($this->replaces) { $cont_sch = array_merge($cont_sch, $this->replaces['search']); $cont_rpl = array_merge($cont_rpl, $this->replaces['replace']); } if ($cont_sch && $cont_rpl) { $content = $this->_str_replace($cont_sch, $cont_rpl, $content); } $content = trim($content); $return['content'] = $content; $return['at_uids'] = $at_uids; $return['tags'] = $tags; $return['urls'] = $urls; return $return; }