Populate more profile information when doing a remote subscribe
This commit is contained in:
parent
01cfe86cd2
commit
543ff40ef6
|
@ -154,7 +154,15 @@ class PoCo
|
|||
PoCo::NS
|
||||
);
|
||||
|
||||
array_push($urls, new PoCoURL($type, $value, $primary));
|
||||
$isPrimary = false;
|
||||
|
||||
if (isset($primary) && $primary == 'true') {
|
||||
$isPrimary = true;
|
||||
}
|
||||
|
||||
// @todo check to make sure a primary hasn't already been added
|
||||
|
||||
array_push($urls, new PoCoURL($type, $value, $isPrimary));
|
||||
}
|
||||
return $urls;
|
||||
}
|
||||
|
@ -213,6 +221,15 @@ class PoCo
|
|||
return $poco;
|
||||
}
|
||||
|
||||
function getPrimaryURL()
|
||||
{
|
||||
foreach ($this->urls as $url) {
|
||||
if ($url->primary) {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function asString()
|
||||
{
|
||||
$xs = new XMLStringer(true);
|
||||
|
@ -494,6 +511,12 @@ class ActivityObject
|
|||
|
||||
$this->element = $element;
|
||||
|
||||
$this->geopoint = $this->_childContent(
|
||||
$element,
|
||||
ActivityContext::POINT,
|
||||
ActivityContext::GEORSS
|
||||
);
|
||||
|
||||
if ($element->tagName == 'author') {
|
||||
|
||||
$this->type = self::PERSON; // XXX: is this fair?
|
||||
|
@ -759,6 +782,15 @@ class ActivityContext
|
|||
|
||||
for ($i = 0; $i < $points->length; $i++) {
|
||||
$point = $points->item($i)->textContent;
|
||||
return self::locationFromPoint($point);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// XXX: Move to ActivityUtils or Location?
|
||||
static function locationFromPoint($point)
|
||||
{
|
||||
$point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
|
||||
$point = preg_replace('/\s+/', ' ', $point);
|
||||
$point = trim($point);
|
||||
|
@ -766,13 +798,11 @@ class ActivityContext
|
|||
if (count($coords) == 2) {
|
||||
list($lat, $lon) = $coords;
|
||||
if (is_numeric($lat) && is_numeric($lon)) {
|
||||
common_log(LOG_INFO, "Looking up location for $lat $lon from georss");
|
||||
common_log(LOG_INFO, "Looking up location for $lat $lon from georss point");
|
||||
return Location::fromLatLon($lat, $lon);
|
||||
}
|
||||
}
|
||||
common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1118,11 +1118,20 @@ class Ostatus_profile extends Memcached_DataObject
|
|||
$profile->profileurl = $hints['profileurl'];
|
||||
}
|
||||
|
||||
// @fixme bio
|
||||
$profile->bio = self::getActivityObjectBio($object, $hints);
|
||||
$profile->location = self::getActivityObjectLocation($object, $hints);
|
||||
$profile->homepage = self::getActivityObjectHomepage($object, $hints);
|
||||
|
||||
if (!empty($object->geopoint)) {
|
||||
$location = ActivityContext::locationFromPoint($object->geopoint);
|
||||
if (!empty($location)) {
|
||||
$profile->lat = $location->lat;
|
||||
$profile->lon = $location->lon;
|
||||
}
|
||||
}
|
||||
|
||||
// @fixme tags/categories
|
||||
// @fixme location?
|
||||
// @todo tags from categories
|
||||
// @todo lat/lon/location?
|
||||
|
||||
if ($profile->id) {
|
||||
common_log(LOG_DEBUG, "Updating OStatus profile $profile->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
|
||||
|
@ -1154,6 +1163,62 @@ class Ostatus_profile extends Memcached_DataObject
|
|||
}
|
||||
}
|
||||
|
||||
protected static function getActivityObjectHomepage($object, $hints=array())
|
||||
{
|
||||
$homepage = null;
|
||||
$poco = $object->poco;
|
||||
|
||||
if (!empty($poco)) {
|
||||
$url = $poco->getPrimaryURL();
|
||||
if ($url->type == 'homepage') {
|
||||
$homepage = $url->value;
|
||||
}
|
||||
}
|
||||
|
||||
// @todo Try for a another PoCo URL?
|
||||
|
||||
return $homepage;
|
||||
}
|
||||
|
||||
protected static function getActivityObjectLocation($object, $hints=array())
|
||||
{
|
||||
$location = null;
|
||||
|
||||
if (!empty($object->poco)) {
|
||||
if (isset($object->poco->address->formatted)) {
|
||||
$location = $object->poco->address->formatted;
|
||||
if (mb_strlen($location) > 255) {
|
||||
$location = mb_substr($note, 0, 255 - 3) . ' … ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @todo Try to find location some othe way? Via goerss point?
|
||||
|
||||
return $location;
|
||||
}
|
||||
|
||||
protected static function getActivityObjectBio($object, $hints=array())
|
||||
{
|
||||
$bio = null;
|
||||
|
||||
if (!empty($object->poco)) {
|
||||
$note = $object->poco->note;
|
||||
if (!empty($note)) {
|
||||
if (mb_strlen($note) > Profile::maxBio()) {
|
||||
// XXX: truncate ok?
|
||||
$bio = mb_substr($note, 0, Profile::maxBio() - 3) . ' … ';
|
||||
} else {
|
||||
$bio = $note;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @todo Try to get bio info some other way?
|
||||
|
||||
return $bio;
|
||||
}
|
||||
|
||||
protected static function getActivityObjectNickname($object, $hints=array())
|
||||
{
|
||||
if ($object->poco) {
|
||||
|
|
|
@ -133,6 +133,8 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($poco->urls[0]->type, 'homepage');
|
||||
$this->assertEquals($poco->urls[0]->value, 'http://example.com/blog.html');
|
||||
$this->assertEquals($poco->urls[0]->primary, 'true');
|
||||
$this->assertEquals($act->actor->geopoint, '37.7749295 -122.4194155');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user