示例#1
0
function make_userlogin()
{
    if (isset($_GET['page'])) {
        return;
    }
    $facebookData = FacebookClassified::newInstance()->selectFacebookData();
    $api_id = osc_get_preference('facebook_api_id', 'classified');
    $api_secret = osc_get_preference('facebook_api_secret', 'classified');
    if (isset($_GET['code']) and !empty($_GET['code'])) {
        $code = $_GET['code'];
        if (!empty($code)) {
            $get_access_data = facebookall_get_fb_contents("https://graph.facebook.com/v2.3/oauth/access_token?" . 'client_id=' . $api_id . '&redirect_uri=' . urlencode(osc_base_url()) . '&client_secret=' . $api_secret . '&code=' . urlencode($code));
            $access_data = json_decode($get_access_data, true);
        }
        if (empty($access_data['access_token'])) {
            $get_access_data = facebookall_get_fb_contents("https://graph.facebook.com/v2.3/oauth/access_token?" . 'client_id=' . $api_id . '&redirect_uri=' . urlencode(osc_base_url()) . '&client_secret=' . $api_secret . '&code=' . urlencode($code));
            $access_data = json_decode($get_access_data, true);
        }
        if (!empty($access_data['access_token'])) {
            $access_token = $access_data['access_token'];
        } else {
            echo 'Error : Could not get access token please check your app settings for more about this error<br> Or Follow our doc setion <a href="http://sourceaddons.com/documentation">Documentation Section</a>.';
            exit;
        }
        ?>
    <script>
      window.opener.FbAll.parentRedirect({'action' : 'fball', 'fball_access_token' : '<?php 
        echo $access_token;
        ?>
'});
      window.close();
    </script>
    <?php 
    }
    if (!empty($_REQUEST['fball_access_token']) and isset($_REQUEST['fball_redirect'])) {
        $user_info = json_decode(facebookall_get_fb_contents("https://graph.facebook.com/v2.3/me?access_token=" . $_REQUEST['fball_access_token']));
        Session::newInstance()->_set('fb-token', $_REQUEST['fball_access_token']);
        $user_data = get_userprofile_data($user_info);
        if (!empty($user_data['email']) and !empty($user_data['id'])) {
            // Filter username form data.
            if (!empty($user_data['name'])) {
                $username = $user_data['name'];
            } else {
                if (!empty($user_data['first_name']) && !empty($user_data['last_name'])) {
                    $username = $user_data['first_name'] . $user_data['last_name'];
                } else {
                    $user_emailname = explode('@', $user_data['email']);
                    $username = $user_emailname[0];
                }
            }
            $user_login = $username;
            $new_user = false;
            $user_id = get_userid($user_data['id']);
            if (empty($user_id)) {
                //Not Registered As Facebook User
                $u_data = User::newInstance()->findByEmail($user_data['email']);
                if (!empty($u_data)) {
                    //Registered As OSClass but not as Facebook User
                    $user = User::newInstance()->findByEmail($user_data['email']);
                    insert_facebook_user_data($user['pk_i_id'], $user_data['id']);
                } else {
                    //New User Not Registered as Facebook User And OSClass User
                    $new_user = true;
                    register_user($user_data);
                }
            }
            $manager = User::newInstance();
            $oscUser = $manager->findByEmail($user_data['email']);
            $email = $oscUser['pk_i_id'];
            require_once osc_lib_path() . 'osclass/UserActions.php';
            $uActions = new UserActions(false);
            $logged = $uActions->bootstrap_login($oscUser['pk_i_id']);
            // Redirect user.
            osc_redirect_to(osc_user_dashboard_url());
            /*
              if (!empty ($_GET['redirect_to'])) {
                $redirect_to = $_GET['redirect_to'];
                wp_safe_redirect ($redirect_to);
              }
              else {
                $redirect_to = facebookall_redirect_loggedin_user();
                wp_redirect ($redirect_to);
              }
              exit();
            }
            */
        }
    }
}
function facebookall_make_userlogin()
{
    $fball_settings = get_option('fball_settings');
    if (isset($_GET['code']) and !empty($_GET['code'])) {
        $code = $_GET['code'];
        if (!empty($code)) {
            $get_access_data = facebookall_get_fb_contents("https://graph.facebook.com/v2.4/oauth/access_token?" . 'client_id=' . $fball_settings['apikey'] . '&redirect_uri=' . urlencode(site_url()) . '&client_secret=' . $fball_settings['apisecret'] . '&code=' . urlencode($code));
            $access_data = json_decode($get_access_data, true);
        }
        if (empty($access_data['access_token'])) {
            $get_access_data = facebookall_get_fb_contents("https://graph.facebook.com/v2.4/oauth/access_token?" . 'client_id=' . $fball_settings['apikey'] . '&redirect_uri=' . urlencode(site_url() . '/') . '&client_secret=' . $fball_settings['apisecret'] . '&code=' . urlencode($code));
            $access_data = json_decode($get_access_data, true);
        }
        if (!empty($access_data['access_token'])) {
            $access_token = $access_data['access_token'];
        } else {
            echo 'Error : Could not get access token please check your app settings for more about this error<br> Or Follow our doc setion <a href="http://sourceaddons.com/documentation">Documentation Section</a>.';
            exit;
        }
        ?>
		<script>
			window.opener.FbAll.parentRedirect({'action' : 'fball', 'fball_access_token' : '<?php 
        echo $access_token;
        ?>
'});
			window.close();
		</script>
		<?php 
    }
    if (!empty($_REQUEST['fball_access_token']) and isset($_REQUEST['fball_redirect'])) {
        $fbuser_info = json_decode(facebookall_get_fb_contents("https://graph.facebook.com/v2.4/me?fields=id,name,first_name,last_name,email,age_range,link,gender,picture,locale,verified&access_token=" . $_REQUEST['fball_access_token']));
        $fbdata = facebookall_get_fbuserprofile_data($fbuser_info);
        if (!empty($fbdata['email']) and !empty($fbdata['id'])) {
            // Filter username form data.
            if (!empty($fbdata['name'])) {
                $username = $fbdata['name'];
            } else {
                if (!empty($fbdata['first_name']) && !empty($fbdata['last_name'])) {
                    $username = $fbdata['first_name'] . $fbdata['last_name'];
                } else {
                    $user_emailname = explode('@', $fbdata['email']);
                    $username = $user_emailname[0];
                }
            }
            $user_login = sanitize_user($username, true);
            $new_user = false;
            $user_id = facebookall_get_userid($fbdata['id']);
            if (!is_numeric($user_id) and empty($user_id)) {
                if (($user_id_tmp = email_exists($fbdata['email'])) !== false) {
                    $user_data = get_userdata($user_id_tmp);
                    if ($user_data !== false) {
                        $user_id = $user_data->ID;
                        $user_login = $user_data->user_login;
                        if (!isset($fball_settings['linkaccount']) or $fball_settings['linkaccount'] == 'link') {
                            delete_metadata('user', null, 'facebookall_user_id', $fbdata['id'], true);
                            update_user_meta($user_id, 'facebookall_user_id', $fbdata['id']);
                            update_user_meta($user_id, 'facebookall_user_email', $fbdata['email']);
                            if (!empty($fbdata['thumbnail'])) {
                                update_user_meta($user_id, 'facebookall_user_thumbnail', $fbdata['thumbnail']);
                            }
                            wp_cache_delete($user_id, 'users');
                            wp_cache_delete($user_login, 'userlogins');
                        }
                    }
                } else {
                    $new_user = true;
                    $user_login = facebookall_usernameexists($user_login);
                    $user_password = wp_generate_password();
                    $user_role = get_option('default_role');
                    $user_data = array('user_login' => $user_login, 'display_name' => !empty($fbdata['name']) ? $fbdata['name'] : $user_login, 'user_email' => $fbdata['email'], 'first_name' => $fbdata['first_name'], 'last_name' => $fbdata['last_name'], 'user_url' => $fbdata['website'], 'user_pass' => $user_password, 'description' => $fbdata['aboutme'], 'role' => $user_role);
                    $user_id = wp_insert_user($user_data);
                    if (is_numeric($user_id)) {
                        delete_metadata('user', null, 'facebookall_user_id', $fbdata['id'], true);
                        update_user_meta($user_id, 'facebookall_user_id', $fbdata['id']);
                        update_user_meta($user_id, 'facebookall_user_email', $fbdata['email']);
                        if (!empty($fbdata['thumbnail'])) {
                            update_user_meta($user_id, 'facebookall_user_thumbnail', $fbdata['thumbnail']);
                        }
                        wp_cache_delete($user_id, 'users');
                        wp_cache_delete($user_login, 'userlogins');
                        do_action('user_register', $user_id);
                    }
                }
            }
            $user_data = get_userdata($user_id);
            if ($user_data !== false) {
                facebookall_post_user_wall($_REQUEST['fball_access_token'], $fbdata['id'], $new_user);
                wp_clear_auth_cookie();
                wp_set_auth_cookie($user_data->ID, true);
                do_action('wp_login', $user_data->user_login, $user_data);
                // Redirect user.
                if (!empty($_GET['redirect_to'])) {
                    $redirect_to = $_GET['redirect_to'];
                    wp_safe_redirect($redirect_to);
                } else {
                    $redirect_to = facebookall_redirect_loggedin_user();
                    wp_redirect($redirect_to);
                }
                exit;
            }
        }
    }
}