From: Mikael Nordfeldth Date: Fri, 24 Jun 2016 11:51:40 +0000 (+0200) Subject: Properly parse incoming bookmarks X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=39e8c13afbc460f28a309a71dcb5f548f477c775;p=quix0rs-gnu-social.git Properly parse incoming bookmarks --- diff --git a/lib/activityobject.php b/lib/activityobject.php index ca6390b725..d211136d3c 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -28,9 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } require_once(INSTALLDIR.'/lib/activitystreamjsondocument.php'); @@ -269,6 +267,22 @@ class ActivityObject if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID $this->id = $this->link; } + + $els = $element->childNodes; + $out = array(); + + for ($i = 0; $i < $els->length; $i++) { + $link = $els->item($i); + if ($link->localName == ActivityUtils::LINK && $link->namespaceURI == ActivityUtils::ATOM) { + $attrs = array(); + foreach ($link->attributes as $attrName=>$attrNode) { + $attrs[$attrName] = $attrNode->nodeValue; + } + $this->extra[] = [$link->localName, + $attrs, + $link->nodeValue]; + } + } } // @todo FIXME: rationalize with Activity::_fromRssItem() diff --git a/plugins/Bookmark/classes/Bookmark.php b/plugins/Bookmark/classes/Bookmark.php index b593bc1909..02b4d3d2e3 100644 --- a/plugins/Bookmark/classes/Bookmark.php +++ b/plugins/Bookmark/classes/Bookmark.php @@ -162,19 +162,19 @@ class Bookmark extends Managed_DataObject $url = null; // each extra element is array('tagname', array('attr'=>'val', ...), 'content') foreach ($actobj->extra as $extra) { - if ($extra[1]['rel'] !== 'related') { + if ($extra[0] !== ActivityUtils::LINK || $extra[1][ActivityUtils::REL] !== 'related') { continue; } - if ($url===null && strlen($extra[1]['href'])>0) { - $url = $extra[1]['href']; + if ($url===null && strlen($extra[1][ActivityUtils::HREF])>0) { + $url = $extra[1][ActivityUtils::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))); + throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got more than that.'))); } } 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))); + throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got 0.'))); } if (!strlen($actobj->title)) {