]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Bookmark:addNew did not add a proper rel=related
authorMikael Nordfeldth <mmn@hethane.se>
Tue, 13 Oct 2015 10:31:35 +0000 (12:31 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Tue, 13 Oct 2015 10:31:35 +0000 (12:31 +0200)
plugins/ActivityVerbPost/ActivityVerbPostPlugin.php
plugins/Bookmark/classes/Bookmark.php

index 32b1ba2e7cfffab427f4f7e195614ce29d9f5f11..6dd182bc924740b8d266d4b8d30a3ec8b27f49d0 100644 (file)
@@ -114,7 +114,7 @@ class ActivityVerbPostPlugin extends ActivityVerbHandlerPlugin
 
     protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
     {
-        // handle repeat POST
+        // handle POST
     }
 
     protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
index 11c37fefa906f2dab27c7a3c05a761847193dd59..d260eeaaaf65ec16f5c24845d7964381c1d14207 100644 (file)
@@ -159,15 +159,26 @@ class Bookmark extends Managed_DataObject
      */
     static function saveActivityObject(ActivityObject $actobj, Notice $stored)
     {
-        $relLinkEls = ActivityUtils::getLinks($actobj->element, 'related');
-
-        if (count($relLinkEls) !== 1) {
+        common_debug('saving bookmark activity object: '.var_export($actobj,true));
+        $url = null;
+        // each extra element is array('tagname', array('attr'=>'val', ...), 'content')
+        foreach ($actobj->extra as $extra) {
+            common_debug('bookmark extra: '.var_export($extra,true));
+            if ($extra[1]['rel'] !== 'related') {
+                continue;
+            }
+            if ($url===null && strlen($extra[1]['href'])>0) {
+                $url = $extra[1]['href'];
+            } elseif ($url !== null) {
+                // TRANS: Client exception thrown when a bookmark is formatted incorrectly.
+                throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got %1$d.'), count($relLinkEls)));
+            }
+        }
+        if (is_null($url)) {
             // TRANS: Client exception thrown when a bookmark is formatted incorrectly.
             throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got %1$d.'), count($relLinkEls)));
         }
 
-        $url = $relLinkEls[0]->getAttribute('href');
-
         if (!strlen($actobj->title)) {
             throw new ClientException(_m('You must provide a non-empty title.'));
         }
@@ -279,7 +290,7 @@ class Bookmark extends Managed_DataObject
         $actobj->type = ActivityObject::BOOKMARK;
         $actobj->title = $title;
         $actobj->summary = $description;
-        $actobj->extra[] = array('link', $attrs, null);
+        $actobj->extra[] = array('link', array('rel'=>'related', 'href'=>$url), null);
         $act->objects[] = $actobj;
 
         $act->enclosures[] = $url;