/** * Synchronize social network information to a profile * * @param string $hook_name the name of the hook * @param string $entity_type the type of the hook * @param mixed $return_value current return value * @param array $params supplied params * * @return void */ function socialink_sync_network_hook($hook_name, $entity_type, $return_value, $params) { if (!empty($params) && is_array($params)) { if (isset($params["user"]) && isset($params["network"])) { $user = $params["user"]; $network = $params["network"]; if (socialink_is_available_network($network)) { switch ($network) { case "twitter": socialink_twitter_sync_profile_metadata($user->getGUID()); break; case "linkedin": socialink_linkedin_sync_profile_metadata($user->getGUID()); break; case "facebook": socialink_facebook_sync_profile_metadata($user->getGUID()); break; } } } } }
/** * Create a user based on Facebook information * * @param string $token Facebook access token * * @return bool|ElggUser */ function socialink_facebook_create_user($token) { if (empty($token)) { return false; } if (!socialink_facebook_available()) { return false; } $session = new Facebook\FacebookSession($token); if (empty($session)) { return false; } $request = new FaceBook\FacebookRequest($session, "GET", "/me"); // set correct proxy settings (if needed) $curl_http_client = socialink_facebook_get_curl_http_client(); $request->setHttpClientHandler($curl_http_client); try { $api_result = $request->execute()->getGraphObject(Facebook\GraphUser::className()); } catch (Exception $e) { } if (empty($api_result)) { return false; } // get user information $name = $api_result->getName(); $email = $api_result->getEmail(); if (get_user_by_email($email)) { register_error(elgg_echo("socialink:networks:create_user:error:email")); return false; } $pwd = generate_random_cleartext_password(); $username = socialink_create_username_from_email($email); try { $user_guid = register_user($username, $pwd, $name, $email); if (empty($user_guid)) { return false; } // show hidden entities $access = access_get_show_hidden_status(); access_show_hidden_entities(true); $user = get_user($user_guid); if (empty($user)) { access_show_hidden_entities($access); return false; } // register user's access tokens elgg_set_plugin_user_setting("facebook_access_token", $token, $user_guid, "socialink"); elgg_set_plugin_user_setting("facebook_user_id", $api_result->getId(), $user_guid, "socialink"); // no need for uservalidationbyemail elgg_unregister_plugin_hook_handler("register", "user", "uservalidationbyemail_disable_new_user"); // sync user data socialink_facebook_sync_profile_metadata($user->getGUID()); // trigger hook for registration $params = array("user" => $user, "password" => $pwd, "friend_guid" => 0, "invitecode" => ""); if (elgg_trigger_plugin_hook("register", "user", $params, true) !== false) { access_show_hidden_entities($access); // return the user return $user; } // restore hidden entities access_show_hidden_entities($access); } catch (Exception $e) { } return false; }