Example #1
0
function iflychat_get_current_guest_name()
{
    global $modSettings;
    if (isset($_SESSION) && isset($_SESSION['iflychat_guest_name'])) {
        //if(!isset($_COOKIE) || !isset($_COOKIE['drupalchat_guest_name'])) {
        setrawcookie('iflychat_guest_name', rawurlencode($_SESSION['iflychat_guest_name']), time() + 60 * 60 * 24 * 365);
        //}
    } else {
        if (isset($_COOKIE) && isset($_COOKIE['iflychat_guest_name']) && isset($_COOKIE['iflychat_guest_session']) && $_COOKIE['iflychat_guest_session'] == iflychat_compute_guest_session(iflychat_get_current_guest_id())) {
            $_SESSION['iflychat_guest_name'] = check_plain($_COOKIE['iflychat_guest_name']);
        } else {
            if ($modSettings['iflychat_anon_use_name'] == 1) {
                $_SESSION['iflychat_guest_name'] = check_plain($modSettings['iflychat_anon_prefix'] . ' ' . iflychat_get_random_name());
            } else {
                $_SESSION['iflychat_guest_name'] = check_plain($modSettings['iflychat_anon_prefix'] . time());
            }
            setrawcookie('iflychat_guest_name', rawurlencode($_SESSION['iflychat_guest_name']), time() + 60 * 60 * 24 * 365);
        }
    }
    return $_SESSION['iflychat_guest_name'];
}
Example #2
0
function iflychat_auth()
{
    global $txt, $scripturl, $context, $settings, $sc, $modSettings, $user_info, $user_profile;
    header("Content-Type: application/json");
    if (empty($modSettings['iflychat_external_api_key'])) {
        return null;
    }
    $_i = $modSettings['iflychat_ext_d_i'];
    if (iflychat_check_chat_admin()) {
        $role = 'admin';
    } else {
        $groups = list_getGroups(0);
        $role = array();
        foreach ($groups as $group) {
            if (in_array($group['id'], $user_info['groups'])) {
                $role[$group['id']] = $group['name'];
            }
        }
    }
    if ($modSettings['iflychat_theme'] == 1) {
        $iflychat_theme = 'light';
    } else {
        $iflychat_theme = 'dark';
    }
    $api_key = $modSettings['iflychat_external_api_key'];
    $data = array('uname' => !$user_info['is_guest'] ? $user_info['username'] : iflychat_get_current_guest_name(), 'uid' => !$user_info['is_guest'] ? $user_info['id'] : iflychat_get_current_guest_id(), 'api_key' => $api_key, 'image_path' => $settings['default_theme_url'] . '/iflychat-static/themes/' . $iflychat_theme . '/images/', 'isLog' => TRUE, 'role' => $role, 'whichTheme' => 'blue', 'enableStatus' => TRUE, 'validState' => array('available', 'offline', 'busy', 'idle'), 'rel' => '0');
    if ($modSettings['iflychat_enable_friends'] == '1') {
        loadMemberData($user_info['buddies']);
        $data['rel'] = '1';
        $final_list = array();
        $final_list['1']['name'] = 'friend';
        $final_list['1']['plural'] = 'friends';
        foreach ($user_info['buddies'] as $uid) {
            loadMemberContext($uid);
            $has = in_array($user_info['id'], explode(",", $user_profile[$uid]['buddy_list']));
            if ($has) {
                $final_list['1']['valid_uids'][] = $uid;
            }
        }
        $data['valid_uids'] = $final_list;
    }
    if ($modSettings['iflychat_user_picture'] == '1') {
        $data['up'] = iflychat_get_user_pic_url();
    }
    $data['upl'] = iflychat_get_user_profile_url();
    $post_data = http_build_query($data, '', '&');
    if (!($modSettings['iflychat_enable_friends'] == '1' && $user_info['is_guest'])) {
        $result = fetch_web_data(SMFCHAT_EXTERNAL_HOST . ':' . SMFCHAT_EXTERNAL_PORT . '/p/', $post_data, false, 3);
    }
    if (empty($result) || !isset($result)) {
        $var = array('uname' => !$user_info['is_guest'] ? $user_info['username'] : iflychat_get_current_guest_name(), 'uid' => !$user_info['is_guest'] ? $user_info['id'] : iflychat_get_current_guest_id());
        exit(json_encode($var));
    }
    $jsonDataObj = json_decode($result);
    //updating value of iflychat_ext_d_i
    if (isset($jsonData->_i) && $jsonData->_i != $_i) {
        $updateSettings = array('iflychat_ext_d_i' => $jsonData->_i);
        updateSettings($updateSettings);
    }
    $jsonDataAssoc = json_decode($result, TRUE);
    $jsonDataAssoc['name'] = !$user_info['is_guest'] ? $user_info['username'] : iflychat_get_current_guest_name();
    $jsonDataAssoc['uid'] = !$user_info['is_guest'] ? $user_info['id'] : iflychat_get_current_guest_id();
    $jsonDataAssoc['up'] = iflychat_get_user_pic_url();
    $jsonDataAssoc['upl'] = iflychat_get_user_profile_url();
    exit(json_encode($jsonDataAssoc));
}