function friend_add($touid, $gid = 0, $note = '')
{
    global $_G;
    if ($touid == $_G['uid']) {
        return -2;
    }
    if (friend_check($touid)) {
        return -2;
    }
    include_once libfile('function/stat');
    $freind_request = DB::fetch_first("SELECT * FROM " . DB::table('home_friend_request') . " WHERE uid='{$_G['uid']}' AND fuid='{$touid}'");
    if ($freind_request) {
        $setarr = array('uid' => $_G['uid'], 'fuid' => $freind_request['fuid'], 'fusername' => addslashes($freind_request['fusername']), 'gid' => $gid, 'dateline' => $_G['timestamp']);
        DB::insert('home_friend', $setarr);
        friend_request_delete($touid);
        friend_cache($_G['uid']);
        $setarr = array('uid' => $touid, 'fuid' => $_G['uid'], 'fusername' => $_G['username'], 'gid' => $freind_request['gid'], 'dateline' => $_G['timestamp']);
        DB::insert('home_friend', $setarr);
        addfriendlog($_G['uid'], $touid);
        friend_cache($touid);
        updatestat('friend');
    } else {
        $to_freind_request = DB::fetch_first("SELECT * FROM " . DB::table('home_friend_request') . " WHERE uid='{$touid}' AND fuid='{$_G['uid']}'");
        if ($to_freind_request) {
            return -1;
        }
        $setarr = array('uid' => $touid, 'fuid' => $_G['uid'], 'fusername' => $_G['username'], 'gid' => $gid, 'note' => $note, 'dateline' => $_G['timestamp']);
        DB::insert('home_friend_request', $setarr);
        updatestat('addfriend');
    }
    return 1;
}
function friend_add($touid, $gid = 0, $note = '')
{
    global $_G;
    if ($touid == $_G['uid']) {
        return -2;
    }
    if (friend_check($touid)) {
        return -2;
    }
    include_once libfile('function/stat');
    $freind_request = C::t('home_friend_request')->fetch_by_uid_fuid($_G['uid'], $touid);
    if ($freind_request) {
        $setarr = array('uid' => $_G['uid'], 'fuid' => $freind_request['fuid'], 'fusername' => addslashes($freind_request['fusername']), 'gid' => $gid, 'dateline' => $_G['timestamp']);
        C::t('home_friend')->insert($setarr);
        friend_request_delete($touid);
        friend_cache($_G['uid']);
        $setarr = array('uid' => $touid, 'fuid' => $_G['uid'], 'fusername' => $_G['username'], 'gid' => $freind_request['gid'], 'dateline' => $_G['timestamp']);
        C::t('home_friend')->insert($setarr);
        addfriendlog($_G['uid'], $touid);
        friend_cache($touid);
        updatestat('friend');
    } else {
        $to_freind_request = C::t('home_friend_request')->fetch_by_uid_fuid($touid, $_G['uid']);
        if ($to_freind_request) {
            return -1;
        }
        $setarr = array('uid' => $touid, 'fuid' => $_G['uid'], 'fusername' => $_G['username'], 'gid' => $gid, 'note' => $note, 'dateline' => $_G['timestamp']);
        C::t('home_friend_request')->insert($setarr);
        updatestat('addfriend');
    }
    return 1;
}
Example #3
0
            require_once libfile('function/mail');
            $values = array('username' => $tospace['username'], 'url' => getsiteurl() . 'home.php?mod=spacecp&ac=friend&op=request');
            sendmail_touser($uid, lang('spacecp', 'friend_subject', $values), '', 'friend_add');
            showmessage('request_has_been_sent', dreferer(), array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
        } else {
            include_once template('home/spacecp_friend');
            exit;
        }
    }
} elseif ($op == 'ignore') {
    if ($uid) {
        if (submitcheck('friendsubmit')) {
            if (friend_check($uid)) {
                friend_delete($uid);
            } else {
                friend_request_delete($uid);
            }
            showmessage('do_success', 'home.php?mod=spacecp&ac=friend&op=request', array('uid' => $uid, 'from' => $_G['gp_from']), array('showdialog' => 1, 'showmsg' => true, 'closetime' => 0));
        }
    } elseif ($_GET['key'] == $space['key']) {
        $count = DB::result(DB::query("SELECT COUNT(*) FROM " . DB::table('home_friend_request') . " WHERE uid='{$_G['uid']}'"), 0);
        if ($count) {
            DB::delete('home_friend_request', array('uid' => $_G['uid']));
            space_merge($space, 'count');
            $space['newprompt'] = intval($space['newprompt'] - $count);
            if ($space['newprompt'] < 0) {
                $space['newprompt'] = 0;
            }
            DB::query("UPDATE " . DB::table('common_member_status') . " SET pendingfriends='0' WHERE uid='{$_G['uid']}'");
            DB::query("UPDATE " . DB::table('common_member') . " SET newprompt='{$space['newprompt']}' WHERE uid='{$_G['uid']}'");
            dsetcookie('promptstate_' . $_G['uid'], $space['newprompt'], 31536000);
Example #4
0
function friend_add($touid, $gid = 0, $note = '')
{
    global $_G;
    if ($touid == $_G['uid']) {
        return -2;
    }
    if (friend_check($touid)) {
        return -2;
    }
    $freind_request = DB::fetch_first("SELECT * FROM " . DB::table('home_friend_request') . " WHERE uid='{$_G['uid']}' AND fuid='{$touid}'");
    if ($freind_request) {
        $setarr = array('uid' => $_G['uid'], 'fuid' => $freind_request['fuid'], 'fusername' => addslashes($freind_request['fusername']), 'gid' => $gid, 'dateline' => $_G['timestamp']);
        DB::insert('home_friend', $setarr);
        friend_request_delete($touid);
        friend_cache($_G['uid']);
        $setarr = array('uid' => $touid, 'fuid' => $_G['uid'], 'fusername' => $_G['username'], 'gid' => $freind_request['gid'], 'dateline' => $_G['timestamp']);
        DB::insert('home_friend', $setarr);
        addfriendlog($_G['uid'], $touid);
        friend_cache($touid);
    } else {
        $to_freind_request = DB::fetch_first("SELECT * FROM " . DB::table('home_friend_request') . " WHERE uid='{$touid}' AND fuid='{$_G['uid']}'");
        if ($to_freind_request) {
            return -1;
        }
        $setarr = array('uid' => $touid, 'fuid' => $_G['uid'], 'fusername' => $_G['username'], 'gid' => $gid, 'note' => $note, 'dateline' => $_G['timestamp']);
        DB::insert('home_friend_request', $setarr);
        DB::query("UPDATE " . DB::table('common_member_status') . " SET pendingfriends=pendingfriends+1 WHERE uid='{$touid}'");
        DB::query("UPDATE " . DB::table('common_member') . " SET newprompt=newprompt+1 WHERE uid='{$touid}'");
    }
    return 1;
}