+ if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
+ foreach($fields_ret as $k => $v)
+ $fields_ret[$k] = true;
+ else {
+ $fields_req = explode(',',$_GET['fields']);
+ foreach($fields_req as $f)
+ $fields_ret[trim($f)] = true;
+ }
+
+ if(is_array($r)) {
+ if(count($r)) {
+ foreach($r as $rr) {
+ if (!isset($rr['generation'])) {
+ if ($global)
+ $rr['generation'] = 3;
+ elseif ($system_mode)
+ $rr['generation'] = 1;
+ else
+ $rr['generation'] = 2;
+ }
+
+ if (($rr['about'] == "") AND isset($rr['pabout']))
+ $rr['about'] = $rr['pabout'];
+
+ if ($rr['location'] == "") {
+ if (isset($rr['plocation']))
+ $rr['location'] = $rr['plocation'];
+
+ if (isset($rr['pregion']) AND ($rr['pregion'] != "")) {
+ if ($rr['location'] != "")
+ $rr['location'] .= ", ";
+
+ $rr['location'] .= $rr['pregion'];
+ }
+
+ if (isset($rr['pcountry']) AND ($rr['pcountry'] != "")) {
+ if ($rr['location'] != "")
+ $rr['location'] .= ", ";
+
+ $rr['location'] .= $rr['pcountry'];
+ }
+ }
+
+ if (($rr['gender'] == "") AND isset($rr['pgender']))
+ $rr['gender'] = $rr['pgender'];
+
+ if (($rr['keywords'] == "") AND isset($rr['pub_keywords']))
+ $rr['keywords'] = $rr['pub_keywords'];
+
+ $entry = array();
+ if($fields_ret['id'])
+ $entry['id'] = (int)$rr['id'];
+ if($fields_ret['displayName'])
+ $entry['displayName'] = $rr['name'];
+ if($fields_ret['aboutMe'])
+ $entry['aboutMe'] = bbcode($rr['about'], false, false);
+ if($fields_ret['currentLocation'])
+ $entry['currentLocation'] = $rr['location'];
+ if($fields_ret['gender'])
+ $entry['gender'] = $rr['gender'];
+ if($fields_ret['generation'])
+ $entry['generation'] = (int)$rr['generation'];
+ if($fields_ret['urls']) {
+ $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
+ if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
+ $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
+ }
+ if($fields_ret['preferredUsername'])
+ $entry['preferredUsername'] = $rr['nick'];
+ if($fields_ret['updated']) {
+ if (!$global) {
+ $entry['updated'] = $rr['success_update'];
+
+ if ($rr['name-date'] > $entry['updated'])
+ $entry['updated'] = $rr['name-date'];
+
+ if ($rr['uri-date'] > $entry['updated'])
+ $entry['updated'] = $rr['uri-date'];
+
+ if ($rr['avatar-date'] > $entry['updated'])
+ $entry['updated'] = $rr['avatar-date'];
+ } else
+ $entry['updated'] = $rr['updated'];
+
+ $entry['updated'] = date("c", strtotime($entry['updated']));
+ }
+ if($fields_ret['photos'])
+ $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
+ if($fields_ret['network']) {
+ $entry['network'] = $rr['network'];
+ if ($entry['network'] == NETWORK_STATUSNET)
+ $entry['network'] = NETWORK_OSTATUS;
+ if (($entry['network'] == "") AND ($rr['self']))
+ $entry['network'] = NETWORK_DFRN;
+ }
+ if($fields_ret['tags']) {
+ $tags = str_replace(","," ",$rr['keywords']);
+ $tags = explode(" ", $tags);
+
+ $cleaned = array();
+ foreach ($tags as $tag) {
+ $tag = trim(strtolower($tag));
+ if ($tag != "")
+ $cleaned[] = $tag;
+ }
+
+ $entry['tags'] = array($cleaned);
+ }
+ if($fields_ret['address']) {
+ $entry['address'] = array();
+
+ // Deactivated. It just reveals too much data. (Although its from the default profile)
+ //if (isset($rr['paddress']))
+ // $entry['address']['streetAddress'] = $rr['paddress'];
+
+ if (isset($rr['plocation']))
+ $entry['address']['locality'] = $rr['plocation'];
+
+ if (isset($rr['pregion']))
+ $entry['address']['region'] = $rr['pregion'];
+
+ // See above
+ //if (isset($rr['ppostalcode']))
+ // $entry['address']['postalCode'] = $rr['ppostalcode'];
+
+ if (isset($rr['pcountry']))
+ $entry['address']['country'] = $rr['pcountry'];
+ }
+
+ $ret['entry'][] = $entry;
+ }