]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Populate more profile information when doing a remote subscribe
authorZach Copley <zach@status.net>
Thu, 25 Feb 2010 00:51:24 +0000 (16:51 -0800)
committerZach Copley <zach@status.net>
Thu, 25 Feb 2010 00:51:24 +0000 (16:51 -0800)
lib/activity.php
plugins/OStatus/classes/Ostatus_profile.php
tests/ActivityParseTests.php

index 33932ad0ef9c91e7fbb68ad0ecff50cc1de2b4f2..eace672a5a1605367fdcb6029029e33f8b388b1c 100644 (file)
@@ -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,22 +782,29 @@ class ActivityContext
 
         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;
+    }
 }
 
 /**
index 5e38a523ead9437e320ae6e2d7c12f76c04b2747..144fdfa8b7ad4693e12dbf336a288714cf92ddd8 100644 (file)
@@ -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) {
index 5de97d2e2ed2117e157fdc16ab93fd97381a7ad1..d1d8717343576a9b2c6272f1d426b4415a95c332 100644 (file)
@@ -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');
+
     }
 
 }