From c8a907c828b1783e40a20696b06e5d6c9b3c8990 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 13 Oct 2015 12:31:35 +0200 Subject: [PATCH] Bookmark:addNew did not add a proper rel=related --- .../ActivityVerbPostPlugin.php | 2 +- plugins/Bookmark/classes/Bookmark.php | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/plugins/ActivityVerbPost/ActivityVerbPostPlugin.php b/plugins/ActivityVerbPost/ActivityVerbPostPlugin.php index 32b1ba2e7c..6dd182bc92 100644 --- a/plugins/ActivityVerbPost/ActivityVerbPostPlugin.php +++ b/plugins/ActivityVerbPost/ActivityVerbPostPlugin.php @@ -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) diff --git a/plugins/Bookmark/classes/Bookmark.php b/plugins/Bookmark/classes/Bookmark.php index 11c37fefa9..d260eeaaaf 100644 --- a/plugins/Bookmark/classes/Bookmark.php +++ b/plugins/Bookmark/classes/Bookmark.php @@ -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; -- 2.39.5