Add PoCo to Activity Streams JSON

This commit is contained in:
Zach Copley 2011-02-17 22:36:14 -08:00
parent 97af5e1954
commit 11f77b2fca
5 changed files with 75 additions and 1 deletions

View File

@ -726,6 +726,10 @@ class ActivityObject
); );
} }
if (!empty($this->poco)) {
$object['contact'] = $this->poco->asArray();
}
return array_filter($object); return array_filter($object);
} }
} }

View File

@ -115,7 +115,6 @@ class ActivityStreamJSONDocument
$act = $notice->asActivity($cur); $act = $notice->asActivity($cur);
$act->extra[] = $notice->noticeInfo($cur); $act->extra[] = $notice->noticeInfo($cur);
array_push($this->doc['items'], $act->asArray()); array_push($this->doc['items'], $act->asArray());
} }

View File

@ -241,4 +241,42 @@ class PoCo
$url->outputTo($xo); $url->outputTo($xo);
} }
} }
/**
* Output a Portable Contact as an array suitable for serializing
* as JSON
*
* @return $array the PoCo array
*/
function asArray()
{
$poco = array();
$poco['preferredUsername'] = $this->preferredUsername;
$poco['displayName'] = $this->displayName;
if (!empty($this->note)) {
$poco['note'] = $this->note;
}
if (!empty($this->address)) {
$poco['addresses'] = $this->address->asArray();
}
if (!empty($this->urls)) {
$urls = array();
foreach ($this->urls as $url) {
$urls[] = $url->asArray();
}
$poco['urls'] = $urls;
}
return $poco;
}
} }

View File

@ -56,4 +56,17 @@ class PoCoAddress
$xo->elementEnd('poco:address'); $xo->elementEnd('poco:address');
} }
} }
/**
* Return this PoCo address as an array suitable for serializing in JSON
*
* @return array the address
*/
function asArray()
{
if (!empty($this->formatted)) {
return array('formatted' => $this->formatted);
}
}
} }

View File

@ -67,4 +67,24 @@ class PoCoURL
} }
$xo->elementEnd('poco:urls'); $xo->elementEnd('poco:urls');
} }
/**
* Return this PoCo URL as an array suitable for serializing in JSON
*
* @array $url the url
*/
function asArray()
{
$url = array();
$url['type'] = $this->type;
$url['value'] = $this->value;
if (!empty($this->primary)) {
$url['primary'] = 'true';
}
return $url;
}
} }