+function fbsync_fetchuser($a, $uid, $id) {
+ $access_token = get_pconfig($uid,'facebook','access_token');
+ $self_id = get_pconfig($uid,'fbsync','self_id');
+
+ $user = array();
+
+ $contact = q("SELECT `id`, `name`, `url`, `photo` FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
+ intval($uid), dbesc("facebook::".$id));
+
+ if (count($contact)) {
+ $user["contact-id"] = $contact[0]["id"];
+ $user["name"] = $contact[0]["name"];
+ $user["link"] = $contact[0]["url"];
+ $user["avatar"] = $contact[0]["photo"];
+
+ return($user);
+ }
+
+ $own_contact = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
+ intval($uid), dbesc("facebook::".$self_id));
+
+ if (!count($own_contact))
+ return($user);
+
+ $fql = "SELECT name, url, pic_square FROM profile WHERE id = ".$id;
+
+ $url = "https://graph.facebook.com/fql?q=".urlencode($fql)."&access_token=".$access_token;
+
+ $feed = fetch_url($url);
+ $data = json_decode($feed);
+
+ if (is_array($data->data)) {
+ $user["contact-id"] = $own_contact[0]["id"];
+ $user["name"] = $data->data[0]->name;
+ $user["link"] = $data->data[0]->url;
+ $user["avatar"] = $data->data[0]->pic_square;
+ }
+ return($user);
+}
+