]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'testing' of gitorious.org:statusnet/mainline into testing
authorZach Copley <zach@status.net>
Thu, 25 Feb 2010 00:52:16 +0000 (16:52 -0800)
committerZach Copley <zach@status.net>
Thu, 25 Feb 2010 00:52:16 +0000 (16:52 -0800)
* 'testing' of gitorious.org:statusnet/mainline:
  Merge StatusNet core localization updates from 0.9.x branch
  Fix update_po_templates.php to support the plural and context variants of _m() in plugins
  Drop HTMLPurifier; we don't need its extra capabilities and we're already using htmLawed which is lighter-weight.
  OStatus: handle update-profile Salmon pings
  Revert "Updated jQuery Form Plugin from v2.17 to v2.36"
  OStatus: disable HTMLPurify cache unless we've configured a writable path for it.

lib/activity.php
plugins/OStatus/classes/Ostatus_profile.php
tests/ActivityParseTests.php

index 25727bf2b55314c806b39d390876e183be8d3bbe..3de5f62c7caf4a4d95c88cbd6a6f47c94cb4efd5 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;
     }
@@ -215,6 +223,15 @@ class PoCo
         return $poco;
     }
 
+    function getPrimaryURL()
+    {
+        foreach ($this->urls as $url) {
+            if ($url->primary) {
+                return $url;
+            }
+        }
+    }
+
     function asString()
     {
         $xs = new XMLStringer(true);
@@ -496,6 +513,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?
@@ -761,22 +784,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 a366c1c2cf4b96fe5d7eea042c1358bedc774ca2..4f73fd65be9dcc6cb04792ec105bc2ab44a1afc3 100644 (file)
@@ -1117,11 +1117,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));
@@ -1153,6 +1162,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');
+
     }
 
 }