/** * Calls the Google API to get information about the user associated with this * email address. For more details on the call, see * http://code.google.com/apis/socialgraph/docs/ * * @since Unknown * * @param string $email The email address of the user */ function google_find_by_email($email) { $user_info_url = 'http://socialgraph.apis.google.com/lookup'; $user_info_url .= '?q=' . urlencode('mailto:' . $email); $user_info_url .= '&fme=1&edi=1&edo=1&pretty=1&sgn=1&callback='; $user_info_result = http_request($user_info_url); if (!did_http_succeed($user_info_result)) { return null; } // Take the JSON string containing all the user's information and pull it into a PHP array as the final result $user_info_json_string = $user_info_result['body']; $user_info_object = json_decode($user_info_json_string, true); if (!isset($user_info_object['nodes'])) { return null; } $all_nodes = $user_info_object['nodes']; $result = null; foreach ($all_nodes as $current_id => $node) { if (!isset($node['attributes'])) { continue; } $attributes = $node['attributes']; if (!isset($attributes['photo'])) { continue; } $portrait_url = $attributes['photo']; if (isset($attributes['fn'])) { $display_name = $attributes['fn']; } else { $display_name = ''; } $user_name = ''; $user_id = ''; $location = ''; $result = array('google' => array('user_id' => $user_id, 'user_name' => $user_name, 'display_name' => $display_name, 'portrait_url' => $portrait_url, 'location' => $location)); break; } return $result; }
/** * Queries the domain for this email address to see if it supports WebFinger, and * if it does returns the right URL to call to get information on the address * * @param string $email The email address of the user * @return string The URL to call to get information, or null if none found */ function webfinger_query_url_for_email($email) { $domain = get_domain_from_email($email); if (empty($domain)) { return null; } // First, ask the server for a list of the services it supports, so we can // look through that list for WebFinger $endpoint_url = WEBFINGER_ENDPOINT_PREFIX; $endpoint_url .= $domain; $endpoint_url .= WEBFINGER_ENDPOINT_SUFFIX; $endpoint_result = http_request($endpoint_url); if (!did_http_succeed($endpoint_result)) { return null; } $endpoint_xml = $endpoint_result['body']; $endpoint_data = convert_xml_string_to_array($endpoint_xml); if (!isset($endpoint_data['xrd']['link'])) { return null; } $endpoint_links = $endpoint_data['xrd']['link']; // If there was a single link tag, we'll get its contents in $endpoint_links, but // if multiple links were present, the contents will be an numeric array of them all. // To normalize this, put lone tags into their own array. if (!isset($endpoint_links[0])) { $endpoint_links_list = array($endpoint_links); } else { $endpoint_links_list = $endpoint_links; } // Now search for a link with the right service rel tag, and get the URL template $template = null; foreach ($endpoint_links_list as $link) { if (!isset($link['@attributes']['rel'])) { continue; } $rel = $link['@attributes']['rel']; if ($rel !== WEBFINGER_SERVICE_REL_TYPE) { continue; } if (!isset($link['@attributes']['template'])) { continue; } $template = $link['@attributes']['template']; } if (empty($template)) { return null; } if (!strpos($template, '{uri}')) { return null; } // Finally substitute the actual email address into the generic template $result = str_replace('{uri}', urlencode('acct://' . $email), $template); return $result; }
function webfinger_find_by_email($email) { // Obtain the URL to gather user information from $query_url = webfinger_query_url_for_email($email); if (empty($query_url)) { return null; } // Try to grab the information help on this email address $query_result = http_request($query_url); if (!did_http_succeed($query_result)) { return null; } $query_xml = $query_result['body']; $query_data = convert_xml_string_to_array($query_xml); if (!isset($query_data['xrd']['link'])) { return null; } $query_links = $query_data['xrd']['link']; // If there was a single link tag, we'll get its contents in $query_links, but // if multiple links were present, the contents will be an numeric array of them all. // To normalize this, put lone tags into their own array. if (!isset($query_links[0])) { $query_links_list = array($query_links); } else { $query_links_list = $query_links; } // Go through all the links and extract the information from any we recognize $result = array(); foreach ($query_links_list as $link) { if (!isset($link['@attributes']['rel']) || !isset($link['@attributes']['href'])) { continue; } $rel = $link['@attributes']['rel']; $href = $link['@attributes']['href']; // At the moment this only understands hCard formatted pages if ($rel === HCARD_REL_URL) { $hkit = new hKit(); $hcard_result = $hkit->getByURL('hcard', $href); if (empty($hcard_result) || !isset($hcard_result[0])) { continue; } $hcard_info = $hcard_result[0]; $user_id = $href; $user_name = ''; if (isset($hcard_info['fn'])) { $display_name = $hcard_info['fn']; } else { $display_name = ''; } if (isset($hcard_info['photo'])) { $portrait_url = $hcard_info['photo']; } else { $portrait_url = ''; } if (isset($hcard_info['adr'])) { $location = $hcard_info['adr']; } else { $location = ''; } $result = array('webfinger' => array('user_id' => $user_id, 'user_name' => $user_name, 'display_name' => $display_name, 'portrait_url' => $portrait_url, 'location' => $location)); } } if (empty($result)) { return null; } return $result; }
/** * Calls the MySpace API to get information about the user associated with this * email address. For more details on the call, see * http://wiki.developer.myspace.com/index.php?title=Open_Search * * @since Unknown * * @param string $email The email address of the user */ function myspace_find_by_email($email) { $user_info_url = 'http://api.myspace.com/opensearch/people'; $user_info_url .= '?searchBy=email'; $user_info_url .= '&searchTerms=' . urlencode($email); $user_info_result = http_request($user_info_url); if (!did_http_succeed($user_info_result)) { return null; } // Take the JSON string containing all the user's information and pull it into a PHP array as the final result $user_info_json_string = $user_info_result['body']; $user_info_object = json_decode($user_info_json_string, true); if (!isset($user_info_object['entry'][0])) { return null; } $user_data = $user_info_object['entry'][0]; $user_id = str_replace('myspace.com.person.', '', $user_data['id']); $user_name = ''; $display_name = $user_data['displayName']; if (strrpos($user_data['thumbnailUrl'], 'no_pic.gif')) { $portrait_url = ''; } else { $portrait_url = $user_data['thumbnailUrl']; } $location = $user_data['location']; $result = array('myspace' => array('user_id' => $user_id, 'user_name' => $user_name, 'display_name' => $display_name, 'portrait_url' => $portrait_url, 'location' => $location)); return $result; }