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;
}
return $poco;
}
+ function getPrimaryURL()
+ {
+ foreach ($this->urls as $url) {
+ if ($url->primary) {
+ return $url;
+ }
+ }
+ }
+
function asString()
{
$xs = new XMLStringer(true);
$this->element = $element;
+ $this->geopoint = $this->_childContent(
+ $element,
+ ActivityContext::POINT,
+ ActivityContext::GEORSS
+ );
+
if ($element->tagName == 'author') {
$this->type = self::PERSON; // XXX: is this fair?
for ($i = 0; $i < $points->length; $i++) {
$point = $points->item($i)->textContent;
- $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
- $point = preg_replace('/\s+/', ' ', $point);
- $point = trim($point);
- $coords = explode(' ', $point);
- 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");
- return Location::fromLatLon($lat, $lon);
- }
- }
- common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
+ 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);
+ $coords = explode(' ', $point);
+ 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 point");
+ return Location::fromLatLon($lat, $lon);
+ }
+ }
+ common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
+ return null;
+ }
}
/**
$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));
}
}
+ 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) {