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; }
preg_match_all( '/<a href[^>]+/is', $html, $hrefs ); foreach( $hrefs[0] as $href ) { if ( stristr( $href, 'class="external' ) ) { preg_match( '/href="([^"]+)"/is', $href, $bits ); $urls[] = $bits[1]; } } */ // Let's just work on a random slice of the URLs $urls = array( 'http://dentedreality.com.au/contact/' ); // Now go through each URL and throw against Plaxo to convert to JSON foreach( $urls as $url ) { // Get the URL and parse for hCards $hKit = new hKit(); $hKit->tidy_mode = 'exec'; $hKit->tmp_dir = '/tmp/'; $hCards = $hKit->getByURL( 'hcard', $url ); // Loop through hCards found and stick them in LDAP foreach( $hCards as $hCard ) { if ( empty( $hCard['fn'] ) && empty( $hCard['n']['given-name'] ) && empty( $hCard['n']['family-name'] ) ) continue; // Can't do anything without a name of some sort // Compile details from card read to create LDAP entry $dn = 'cn=' . $hCard['fn'] . ', o=SuperMegaScrapingAddressBook, c=US'; $entry = array(); $entry['cn'] = array( '' ); // Common Name $entry['sn'] = array( '' ); // Surname/Family Name $entry['gn'] = array( '' ); // Given Name
/** * Fetch hCard for the specified URL. * * @param string $url URL to get hCard from * @return array array containing the hCard object (key: 'hcard') as well as the raw XML (key: 'xml') */ function ext_profile_hcard_from_url($url) { global $hkit; require_once dirname(__FILE__) . '/hkit.class.php'; if (function_exists('tidy_clean_repair')) { $page = wp_remote_fopen($url); } else { $page = wp_remote_fopen('http://cgi.w3.org/cgi-bin/tidy?forceXML=on&docAddr=' . urlencode($url)); } //if(function_exists('tidy_clean_repair')) // $page = tidy_clean_repair($page); $page = str_replace(' ', ' ', $page); if (!$hkit) { $hkit = new hKit(); } @($hcard = $hkit->getByString('hcard', $page)); if (count($hcard['preferred'])) { $phcard = $hcard['preferred'][0]; } else { if ($hcard['all']) { foreach ($hcard['all'] as $card) { if ($card['uid'] == $url) { $phcard = $card; break; } if (!is_array($card['url']) && $card['url'] == $url) { $phcard = $card; break; } if (is_array($card['url']) && in_array($url, $card['url'])) { $phcard = $card; break; } } //end foreach all if (!$phcard) { $phcard = $hcard['all'][0]; } } //end if hcard all } //end if-else preferred return array('hcard' => $phcard, 'xml' => $hcard['xml']); }
} if (!empty($reload)) { $data = array(); $calUser = $nid; $overwrite = true; $type = 'remoteics'; // We will check ics first. $data = parse_ical($nurl, $type); // TODO it may be a vcs file. // if ( count ( $data ) == 0 ) { // $data = parse_vcal ( $nurl ); // } // We may be processing an hCalendar. // $data sometimes has a count of 1 but is not a valid array. if ((count($data) == 0 || !isset($data[0])) && function_exists('simplexml_load_string')) { $h = new hKit(); $h->tidy_mode = 'proxy'; $result = $h->getByURL('hcal', $nurl); $type = 'hcal'; $data = parse_hcal($result, $type); } $errorStr = '<br /><br /> <b>' . translate('Error') . ':</b> '; print_header('', '', '', true, false, true); if (count($data) && empty($errormsg)) { // Delete existing events. delete_events($nid); // Import new events. import_data($data, $overwrite, $type); echo ' <p>' . translate('Import Results') . '</p><br /><br />
private function _get_data_from_url($url) { //We have to hang on to the hKit object, because its configuration is done by require_once //and will thus only work for the first instantiation... static $hkit; if (is_null($hkit)) { require_once MIDCOM_ROOT . '/external/hkit.php'; $hkit = new hKit(); } $data = array(); // TODO: Error handling $client = new org_openpsa_httplib(); $html = $client->get($url); // Check for ICBM coordinate information $icbm = org_openpsa_httplib_helpers::get_meta_value($html, 'icbm'); if ($icbm) { $data['icbm'] = $icbm; } // Check for RSS feed $rss_url = org_openpsa_httplib_helpers::get_link_values($html, 'alternate'); if ($rss_url && count($rss_url) > 0) { $data['rss_url'] = $rss_url[0]['href']; // We have a feed URL, but we should check if it is GeoRSS as well midcom::get('componentloader')->load_library('net.nemein.rss'); $rss_content = net_nemein_rss_fetch::raw_fetch($data['rss_url']); if (isset($rss_content->items) && count($rss_content->items) > 0) { if (array_key_exists('georss', $rss_content->items[0]) || array_key_exists('geo', $rss_content->items[0])) { // This is a GeoRSS feed $data['georss_url'] = $data['rss_url']; } } } $hcards = @$hkit->getByURL('hcard', $url); if (is_array($hcards) && count($hcards) > 0) { // We have found hCard data here $data['hcards'] = $hcards; } return $data; }
while ($row = dbi_fetch_row($res)) { $data = array(); $cnt++; $calUser = $row[0]; $cal_url = $row[1]; $login = $row[2]; $overwrite = true; $type = 'remoteics'; $data = parse_ical($cal_url, $type); // TODO it may be a vcs file // if ( count ( $data ) == 0 ) { // $data = parse_vcal ( $cal_url ); // } // we may be processing an hCalendar if (count($data) == 0 && function_exists('simplexml_load_string')) { $h = new hKit(); $h->tidy_mode = 'proxy'; $result = $h->getByURL('hcal', $cal_url); $type = 'hcal'; $data = parse_hcal($result, $type); } if (count($data) && empty($errormsg)) { // delete existing events if ($debug) { echo "<br />\n" . translate('Deleting events for') . ": {$calUser}<br />\n"; } delete_events($calUser); // import new events if ($debug) { echo translate('Importing events for') . ": {$calUser}<br />\n" . translate('From') . ": {$cal_url}<br />\n"; }
function hcard_import($userid, $url) { global $db; //GET HCARD $ch = curl_init($url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $page = curl_exec($ch); curl_close($ch); if (function_exists('tidy_clean_repair')) { $page = tidy_clear_repair($page); } $page = str_replace(' ', ' ', $page); $h = new hKit(); @($hcard = $h->getByString('hcard', $page)); if (count($hcard['preferred'])) { $phcard = $hcard['preferred'][0]; } else { if ($hcard['all']) { foreach ($hcard['all'] as $card) { if ($card['uid'] == $userdata->user_url) { $phcard = $card; break; } if (!is_array($card['url']) && $card['url'] == $url) { $phcard = $card; break; } if (is_array($card['url']) && in_array($url, $card['url'])) { $phcard = $card; break; } } //end foreach all if (!$phcard) { $phcard = $hcard['all'][0]; } } //end if hcard all } //end if-else preferred $domain = explode('/', $url); $domain = $domain[2]; if (substr($phcard['photo'], 0, 3) == '://') { $photo = explode('/', $phcard['photo']); array_shift($photo); array_shift($photo); array_shift($photo); $phcard['photo'] = 'http://' . $domain . '/' . implode('/', $photo); } //end busted photo url //IMPORT INTO PROFILE if ($phcard['nickname']) { mysql_query("UPDATE users SET nickname='" . mysql_real_escape_string($phcard['nickname'], $db) . "' WHERE user_id={$userid}") or die(mysql_error()); } if ($phcard['email']) { mysql_query("UPDATE users SET email='" . mysql_real_escape_string($phcard['email'], $db) . "' WHERE user_id={$userid}") or die(mysql_error()); } if ($phcard['photo']) { mysql_query("UPDATE users SET photo='" . mysql_real_escape_string($phcard['photo'], $db) . "' WHERE user_id={$userid}") or die(mysql_error()); } }