/** * 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 Twitter information * * @param string $token Twitter access token * @param string $email the users email address * * @return bool|ElggUser */ function socialink_twitter_create_user($token, $email) { $result = false; if (!empty($token) && is_array($token) && !empty($email)) { if (!get_user_by_email($email) && is_email_address($email)) { $keys = socialink_twitter_available(); $keys["oauth_token"] = $token["oauth_token"]; $keys["oauth_secret"] = $token["oauth_token_secret"]; if ($api = socialink_twitter_get_api_object($keys)) { try { $url = "users/show"; $params = array("screen_name" => $token["screen_name"]); $api_result = $api->get($url, $params); } catch (Exception $e) { } if (!empty($api_result)) { $name = $api_result->name; $pwd = generate_random_cleartext_password(); $username = socialink_create_username_from_email($email); try { // register user if ($user_guid = register_user($username, $pwd, $name, $email)) { // show hidden entities $access = access_get_show_hidden_status(); access_show_hidden_entities(TRUE); if ($user = get_user($user_guid)) { // save user tokens elgg_set_plugin_user_setting('twitter_user_id', $token['user_id'], $user_guid, "socialink"); elgg_set_plugin_user_setting('twitter_screen_name', $token['screen_name'], $user_guid, "socialink"); elgg_set_plugin_user_setting('twitter_oauth_token', $token['oauth_token'], $user_guid, "socialink"); elgg_set_plugin_user_setting('twitter_oauth_secret', $token['oauth_token_secret'], $user_guid, "socialink"); // sync user data socialink_twitter_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) { // return the user $result = $user; } } // restore hidden entities access_show_hidden_entities($access); } } catch (Exception $e) { } } } } else { register_error(elgg_echo("socialink:networks:create_user:error:email")); } } return $result; }