X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Factivity.php;h=d84eabf7c4ad5d3cfa892195dafceb913c39429c;hb=67f2f01c5e1cad743e849cdaaaf11deb6e435844;hp=b2015321386ae454df53ce32587c3d26f8fe2e0c;hpb=2fa953da22fe932f758882a93106672ab22c1c6d;p=quix0rs-gnu-social.git diff --git a/lib/activity.php b/lib/activity.php index b201532138..d84eabf7c4 100644 --- a/lib/activity.php +++ b/lib/activity.php @@ -78,7 +78,7 @@ class PoCoAddress if (!empty($this->formatted)) { $xs = new XMLStringer(true); $xs->elementStart('poco:address'); - $xs->element('poco:formatted', null, $this->formatted); + $xs->element('poco:formatted', null, common_xml_safe_str($this->formatted)); $xs->elementEnd('poco:address'); return $xs->getString(); } @@ -279,7 +279,7 @@ class PoCo ); if (!empty($this->note)) { - $xs->element('poco:note', null, $this->note); + $xs->element('poco:note', null, common_xml_safe_str($this->note)); } if (!empty($this->address)) { @@ -344,16 +344,18 @@ class ActivityUtils static function getLink(DOMNode $element, $rel, $type=null) { - $links = $element->getElementsByTagnameNS(self::ATOM, self::LINK); + $els = $element->childNodes; - foreach ($links as $link) { + foreach ($els as $link) { + if ($link->localName == self::LINK && $link->namespaceURI == self::ATOM) { - $linkRel = $link->getAttribute(self::REL); - $linkType = $link->getAttribute(self::TYPE); + $linkRel = $link->getAttribute(self::REL); + $linkType = $link->getAttribute(self::TYPE); - if ($linkRel == $rel && - (is_null($type) || $linkType == $type)) { - return $link->getAttribute(self::HREF); + if ($linkRel == $rel && + (is_null($type) || $linkType == $type)) { + return $link->getAttribute(self::HREF); + } } } @@ -362,17 +364,19 @@ class ActivityUtils static function getLinks(DOMNode $element, $rel, $type=null) { - $links = $element->getElementsByTagnameNS(self::ATOM, self::LINK); + $els = $element->childNodes; $out = array(); - foreach ($links as $link) { + foreach ($els as $link) { + if ($link->localName == self::LINK && $link->namespaceURI == self::ATOM) { - $linkRel = $link->getAttribute(self::REL); - $linkType = $link->getAttribute(self::TYPE); + $linkRel = $link->getAttribute(self::REL); + $linkType = $link->getAttribute(self::TYPE); - if ($linkRel == $rel && - (is_null($type) || $linkType == $type)) { - $out[] = $link; + if ($linkRel == $rel && + (is_null($type) || $linkType == $type)) { + $out[] = $link; + } } } @@ -453,13 +457,13 @@ class ActivityUtils // slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3 - if ($type == 'text') { + if (empty($type) || $type == 'text') { return $contentEl->textContent; } else if ($type == 'html') { $text = $contentEl->textContent; return htmlspecialchars_decode($text, ENT_QUOTES); } else if ($type == 'xhtml') { - $divEl = ActivityUtils::child($contentEl, 'div'); + $divEl = ActivityUtils::child($contentEl, 'div', 'http://www.w3.org/1999/xhtml'); if (empty($divEl)) { return null; } @@ -472,7 +476,7 @@ class ActivityUtils $text .= $doc->saveXML($child); } return trim($text); - } else if (in_array(array('text/xml', 'application/xml'), $type) || + } else if (in_array($type, array('text/xml', 'application/xml')) || preg_match('#(+|/)xml$#', $type)) { throw new ClientException(_("Can't handle embedded XML content yet.")); } else if (strncasecmp($type, 'text/', 5)) { @@ -677,9 +681,16 @@ class ActivityObject if ($this->type == self::PERSON || $this->type == self::GROUP) { $this->displayName = $this->title; - $avatars = ActivityUtils::getLinks($element, 'avatar'); - foreach ($avatars as $link) { - $this->avatarLinks[] = new AvatarLink($link); + $photos = ActivityUtils::getLinks($element, 'photo'); + if (count($photos)) { + foreach ($photos as $link) { + $this->avatarLinks[] = new AvatarLink($link); + } + } else { + $avatars = ActivityUtils::getLinks($element, 'avatar'); + foreach ($avatars as $link) { + $this->avatarLinks[] = new AvatarLink($link); + } } $this->poco = new PoCo($element); @@ -801,7 +812,6 @@ class ActivityObject return $object; } - function asString($tag='activity:object') { $xs = new XMLStringer(true); @@ -813,16 +823,28 @@ class ActivityObject $xs->element(self::ID, null, $this->id); if (!empty($this->title)) { - $xs->element(self::TITLE, null, $this->title); + $xs->element( + self::TITLE, + null, + common_xml_safe_str($this->title) + ); } if (!empty($this->summary)) { - $xs->element(self::SUMMARY, null, $this->summary); + $xs->element( + self::SUMMARY, + null, + common_xml_safe_str($this->summary) + ); } if (!empty($this->content)) { // XXX: assuming HTML content here - $xs->element(ActivityUtils::CONTENT, array('type' => 'html'), $this->content); + $xs->element( + ActivityUtils::CONTENT, + array('type' => 'html'), + common_xml_safe_str($this->content) + ); } if (!empty($this->link)) { @@ -1044,6 +1066,7 @@ class Activity public $id; // ID of the activity public $title; // title of the activity public $categories = array(); // list of AtomCategory objects + public $enclosures = array(); // list of enclosure URL references /** * Turns a regular old Atom into a magical activity @@ -1059,6 +1082,14 @@ class Activity } $this->entry = $entry; + + // Insist on a feed's root DOMElement; don't allow a DOMDocument + if ($feed instanceof DOMDocument) { + throw new ClientException( + _("Expecting a root feed element but got a whole XML document.") + ); + } + $this->feed = $feed; $pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM); @@ -1140,6 +1171,10 @@ class Activity $this->categories[] = new AtomCategory($catEl); } } + + foreach (ActivityUtils::getLinks($entry, 'enclosure') as $link) { + $this->enclosures[] = $link->getAttribute('href'); + } } /**