]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activityutils.php
Merge branch 'nightly' into 'nightly'
[quix0rs-gnu-social.git] / lib / activityutils.php
index c8e580825173693aa617a010ab35c27ff1914c95..b83bc0a238045e2acc6959127fba521e199d4fcd 100644 (file)
@@ -65,11 +65,16 @@ class ActivityUtils
      *
      * @return string related link, if any
      */
-    static function getPermalink($element)
+    static function getPermalink(DOMNode $element)
     {
         return self::getLink($element, 'alternate', 'text/html');
     }
 
+    static function getSelfLink(DOMNode $element)
+    {
+        return self::getLink($element, 'self', 'application/atom+xml');
+    }
+
     /**
      * Get the permalink for an Activity object
      *
@@ -90,8 +95,9 @@ class ActivityUtils
                 $linkRel = $link->getAttribute(self::REL);
                 $linkType = $link->getAttribute(self::TYPE);
 
+                // XXX: Am I allowed to do this according to specs? (matching using common_bare_mime)
                 if ($linkRel == $rel &&
-                    (is_null($type) || $linkType == $type)) {
+                    (is_null($type) || common_bare_mime($linkType) == common_bare_mime($type))) {
                     return $link->getAttribute(self::HREF);
                 }
             }
@@ -294,14 +300,14 @@ class ActivityUtils
         // Possibly an upstream bug; tag: URIs aren't validated properly
         // unless you explicitly ask for them. All other schemes are accepted
         // for basic URI validation without asking.
-        if ($validate->uri($uri, array('allowed_scheme' => array('tag')))) {
+        if ($validate->uri($uri, array('allowed_schemes' => array('tag')))) {
             return true;
         }
 
         return false;
     }
 
-    static function getFeedAuthor($feedEl)
+    static function getFeedAuthor(DOMElement $feedEl)
     {
         // Try old and deprecated activity:subject
 
@@ -350,7 +356,7 @@ class ActivityUtils
 
     static function compareTypes($type, $objects)
     {
-        $type = self::resolveUri($type);
+        $type = self::resolveUri($type, false);
         foreach ((array)$objects as $object) {
             if ($type === self::resolveUri($object)) {
                 return true;
@@ -380,23 +386,24 @@ class ActivityUtils
     }
 
     static function findLocalObject(array $uris, $type=ActivityObject::NOTE) {
-        $object = null;
-        // TODO: Extend this in plugins etc.
-        if (Event::handle('StartFindLocalActivityObject', array($uris, $type, &$object))) {
+        $obj_class = null;
+        // TODO: Extend this in plugins etc. and describe in EVENTS.txt
+        if (Event::handle('StartFindLocalActivityObject', array($uris, $type, &$obj_class))) {
             switch (self::resolveUri($type)) {
             case ActivityObject::PERSON:
                 // GROUP will also be here in due time...
-                $object = new Profile();
+                $obj_class = 'Profile';
                 break;
             default:
-                $object = new Notice();
+                $obj_class = 'Notice';
             }
         }
+        $object = null;
         $uris = array_unique($uris);
         foreach ($uris as $uri) {
             try {
                 // the exception thrown will cancel before reaching $object
-                $object = call_user_func(array($object, 'fromUri'), $uri);
+                $object = call_user_func("{$obj_class}::fromUri", $uri);
                 break;
             } catch (UnknownUriException $e) {
                 common_debug('Could not find local activity object from uri: '.$e->object_uri);