function __construct($element = null) { if (empty($element)) { return; } $replyToEl = ActivityUtils::child($element, self::INREPLYTO, self::THR); if (!empty($replyToEl)) { $this->replyToID = $replyToEl->getAttribute(self::REF); $this->replyToUrl = $replyToEl->getAttribute(self::HREF); } $this->location = $this->getLocation($element); $this->conversation = ActivityUtils::getLink($element, self::CONVERSATION); // Multiple attention links allowed $links = $element->getElementsByTagNameNS(ActivityUtils::ATOM, ActivityUtils::LINK); $attention = array(); for ($i = 0; $i < $links->length; $i++) { $link = $links->item($i); $linkRel = $link->getAttribute(ActivityUtils::REL); // XXX: Deprecate this in favour of "mentioned" from Salmon spec // http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-salmon-00.html#SALR if ($linkRel == self::ATTENTION) { $attention[] = $link->getAttribute(self::HREF); } elseif ($linkRel == self::MENTIONED) { $attention[] = $link->getAttribute(self::HREF); } } $this->attention = array_unique($attention); }
function __construct($element = null) { if (empty($element)) { return; } $replyToEl = ActivityUtils::child($element, self::INREPLYTO, self::THR); if (!empty($replyToEl)) { $this->replyToID = $replyToEl->getAttribute(self::REF); $this->replyToUrl = $replyToEl->getAttribute(self::HREF); } $this->location = $this->getLocation($element); $convs = $element->getElementsByTagNameNS(self::OSTATUS, self::CONVERSATION); foreach ($convs as $conv) { $this->conversation = $conv->textContent; } if (empty($this->conversation)) { // fallback to the atom:link rel="ostatus:conversation" element $this->conversation = ActivityUtils::getLink($element, self::CONVERSATION); } // Multiple attention links allowed $links = $element->getElementsByTagNameNS(ActivityUtils::ATOM, ActivityUtils::LINK); for ($i = 0; $i < $links->length; $i++) { $link = $links->item($i); $linkRel = $link->getAttribute(ActivityUtils::REL); $linkHref = $link->getAttribute(self::HREF); if ($linkRel == self::MENTIONED && $linkHref !== '') { $this->attention[$linkHref] = $link->getAttribute(ActivityContext::OBJECTTYPE); } } }
private function _getAddress($element) { $addressEl = ActivityUtils::child($element, PoCoAddress::ADDRESS, PoCo::NS); if (!empty($addressEl)) { $formatted = ActivityUtils::childContent($addressEl, PoCoAddress::FORMATTED, self::NS); if (!empty($formatted)) { $address = new PoCoAddress(); $address->formatted = $formatted; return $address; } } return null; }
function __construct($element) { $replyToEl = ActivityUtils::child($element, self::INREPLYTO, self::THR); if (!empty($replyToEl)) { $this->replyToID = $replyToEl->getAttribute(self::REF); $this->replyToUrl = $replyToEl->getAttribute(self::HREF); } $this->location = $this->getLocation($element); $this->conversation = ActivityUtils::getLink($element, self::CONVERSATION); // Multiple attention links allowed $links = $element->getElementsByTagNameNS(ActivityUtils::ATOM, ActivityUtils::LINK); for ($i = 0; $i < $links->length; $i++) { $link = $links->item($i); $linkRel = $link->getAttribute(ActivityUtils::REL); if ($linkRel == self::ATTENTION) { $this->attention[] = $link->getAttribute(self::HREF); } } }
function importActivityStream($user, $doc) { $feed = $doc->documentElement; $subjectEl = ActivityUtils::child($feed, Activity::SUBJECT, Activity::SPEC); if (!empty($subjectEl)) { $subject = new ActivityObject($subjectEl); printfv(_("Backup file for user %s (%s)") . "\n", $subject->id, Ostatus_profile::getActivityObjectNickname($subject)); } else { throw new Exception("Feed doesn't have an <activity:subject> element."); } if (is_null($user)) { printfv(_("No user specified; using backup user.") . "\n"); $user = userFromSubject($subject); } $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); printfv(_("%d entries in backup.") . "\n", $entries->length); for ($i = $entries->length - 1; $i >= 0; $i--) { try { $entry = $entries->item($i); $activity = new Activity($entry, $feed); switch ($activity->verb) { case ActivityVerb::FOLLOW: subscribeProfile($user, $subject, $activity); break; case ActivityVerb::JOIN: joinGroup($user, $activity); break; case ActivityVerb::POST: postNote($user, $activity); break; default: throw new Exception("Unknown verb: {$activity->verb}"); } } catch (Exception $e) { print $e->getMessage() . "\n"; continue; } } }
private function _child($element, $tag, $namespace = self::SPEC) { return ActivityUtils::child($element, $tag, $namespace); }
/** * Look up and, if necessary, create an Ostatus_profile for the remote * profile with the given RSS feed - actually loaded from the feed. * This should never return null -- you will either get an object or * an exception will be thrown. * * @param DOMElement $feedEl root element of a loaded RSS feed * @param array $hints additional discovery information passed from higher levels * @todo FIXME: Should this be marked public? * @return Ostatus_profile * @throws Exception */ public static function ensureRssChannel(DOMElement $feedEl, array $hints) { // Special-case for Posterous. They have some nice metadata in their // posterous:author elements. We should use them instead of the channel. $items = $feedEl->getElementsByTagName('item'); if ($items->length > 0) { $item = $items->item(0); $authorEl = ActivityUtils::child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS); if (!empty($authorEl)) { $obj = ActivityObject::fromPosterousAuthor($authorEl); // Posterous has multiple authors per feed, and multiple feeds // per author. We check if this is the "main" feed for this author. if (array_key_exists('profileurl', $hints) && !empty($obj->poco) && common_url_to_nickname($hints['profileurl']) == $obj->poco->preferredUsername) { return self::ensureActivityObjectProfile($obj, $hints); } } } $obj = ActivityUtils::getFeedAuthor($feedEl); // @todo FIXME: We should check whether this feed has elements // with different <author> or <dc:creator> elements, and... I dunno. // Do something about that. if (empty($obj)) { $obj = ActivityObject::fromRssChannel($feedEl); } return self::ensureActivityObjectProfile($obj, $hints); }
static function textConstruct($el) { $src = $el->getAttribute(self::SRC); if (!empty($src)) { // TRANS: Client exception thrown when there is no source attribute. throw new ClientException(_("Can't handle remote content yet.")); } $type = $el->getAttribute(self::TYPE); // slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3 if (empty($type) || $type == 'text') { // We have plaintext saved as the XML text content. // Since we want HTML, we need to escape any special chars. return htmlspecialchars($el->textContent); } else { if ($type == 'html') { // We have HTML saved as the XML text content. // No additional processing required once we've got it. $text = $el->textContent; return $text; } else { if ($type == 'xhtml') { // Per spec, the <content type="xhtml"> contains a single // HTML <div> with XHTML namespace on it as a child node. // We need to pull all of that <div>'s child nodes and // serialize them back to an (X)HTML source fragment. $divEl = ActivityUtils::child($el, 'div', 'http://www.w3.org/1999/xhtml'); if (empty($divEl)) { return null; } $doc = $divEl->ownerDocument; $text = ''; $children = $divEl->childNodes; for ($i = 0; $i < $children->length; $i++) { $child = $children->item($i); $text .= $doc->saveXML($child); } return trim($text); } else { if (in_array($type, array('text/xml', 'application/xml')) || preg_match('#(+|/)xml$#', $type)) { // TRANS: Client exception thrown when there embedded XML content is found that cannot be processed yet. throw new ClientException(_("Can't handle embedded XML content yet.")); } else { if (strncasecmp($type, 'text/', 5)) { return $el->textContent; } else { // TRANS: Client exception thrown when base64 encoded content is found that cannot be processed yet. throw new ClientException(_("Can't handle embedded Base64 content yet.")); } } } } } }
private function _getSource($element) { $sourceEl = ActivityUtils::child($element, 'source'); if (empty($sourceEl)) { return null; } else { $href = ActivityUtils::getLink($sourceEl, 'self'); if (!empty($href)) { return $href; } else { return ActivityUtils::childContent($sourceEl, 'id'); } } }
public function testNoticeInfoFave() { $notice = $this->_fakeNotice(); $fave = Fave::addNew($this->author2->getProfile(), $notice); // Should be set if user has faved $entry = $notice->asAtomEntry(false, false, false, $this->author2); $element = $this->_entryToElement($entry, true); $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); $this->assertEquals('true', $noticeInfo->getAttribute('favorite')); // Shouldn't be set if user has not faved $entry = $notice->asAtomEntry(false, false, false, $this->targetUser1); $element = $this->_entryToElement($entry, true); $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); $this->assertEquals('false', $noticeInfo->getAttribute('favorite')); }
static function getFeedAuthor($feedEl) { // Try old and deprecated activity:subject $subject = ActivityUtils::child($feedEl, Activity::SUBJECT, Activity::SPEC); if (!empty($subject)) { return new ActivityObject($subject); } // Try the feed author $author = ActivityUtils::child($feedEl, Activity::AUTHOR, Activity::ATOM); if (!empty($author)) { return new ActivityObject($author); } // Sheesh. Not a very nice feed! Let's try fingerpoken in the // entries. $entries = $feedEl->getElementsByTagNameNS(Activity::ATOM, 'entry'); if (!empty($entries) && $entries->length > 0) { $entry = $entries->item(0); // Try the (deprecated) activity:actor $actor = ActivityUtils::child($entry, Activity::ACTOR, Activity::SPEC); if (!empty($actor)) { return new ActivityObject($actor); } // Try the author $author = ActivityUtils::child($entry, Activity::AUTHOR, Activity::ATOM); if (!empty($author)) { return new ActivityObject($author); } } return null; }
public function testNoticeInfoRepeated() { $notice = $this->_fakeNotice(); $repeat = $notice->repeat($this->author2->getProfile(), 'test'); $entry = $notice->asAtomEntry(false, false, false, $this->author2); $element = $this->_entryToElement($entry, true); $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); $this->assertEquals('true', $noticeInfo->getAttribute('repeated')); $entry = $notice->asAtomEntry(false, false, false, $this->targetUser1); $element = $this->_entryToElement($entry, true); $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); $this->assertEquals('false', $noticeInfo->getAttribute('repeated')); }