private function _fromAtomEntry($element) { $this->type = $this->_childContent($element, Activity::OBJECTTYPE, Activity::SPEC); if (empty($this->type)) { $this->type = ActivityObject::NOTE; } $this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY); $this->content = ActivityUtils::getContent($element); // We don't like HTML in our titles, although it's technically allowed $this->title = common_strip_html(ActivityUtils::childHtmlContent($element, self::TITLE)); $this->source = $this->_getSource($element); $this->link = ActivityUtils::getPermalink($element); $this->id = $this->_childContent($element, self::ID); if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID $this->id = $this->link; } }
function _fromAtomEntry($entry, $feed) { $pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM); if (!empty($pubEl)) { $this->time = strtotime($pubEl->textContent); } else { // XXX technically an error; being liberal. Good idea...? $updateEl = $this->_child($entry, self::UPDATED, self::ATOM); if (!empty($updateEl)) { $this->time = strtotime($updateEl->textContent); } else { $this->time = null; } } $this->link = ActivityUtils::getPermalink($entry); $verbEl = $this->_child($entry, self::VERB); if (!empty($verbEl)) { $this->verb = trim($verbEl->textContent); } else { $this->verb = ActivityVerb::POST; // XXX: do other implied stuff here } // get immediate object children $objectEls = ActivityUtils::children($entry, self::OBJECT, self::SPEC); if (count($objectEls) > 0) { foreach ($objectEls as $objectEl) { // Special case for embedded activities $objectType = ActivityUtils::childContent($objectEl, self::OBJECTTYPE, self::SPEC); if (!empty($objectType) && $objectType == ActivityObject::ACTIVITY) { $this->objects[] = new Activity($objectEl); } else { $this->objects[] = new ActivityObject($objectEl); } } } else { // XXX: really? $this->objects[] = new ActivityObject($entry); } $actorEl = $this->_child($entry, self::ACTOR); if (!empty($actorEl)) { // Standalone <activity:actor> elements are a holdover from older // versions of ActivityStreams. Newer feeds should have this data // integrated straight into <atom:author>. $this->actor = new ActivityObject($actorEl); // Cliqset has bad actor IDs (just nickname of user). We // work around it by getting the author data and using its // id instead if (!preg_match('/^\\w+:/', $this->actor->id)) { $authorEl = ActivityUtils::child($entry, 'author'); if (!empty($authorEl)) { $authorObj = new ActivityObject($authorEl); $this->actor->id = $authorObj->id; } } } else { if ($authorEl = $this->_child($entry, self::AUTHOR, self::ATOM)) { // An <atom:author> in the entry overrides any author info on // the surrounding feed. $this->actor = new ActivityObject($authorEl); } else { if (!empty($feed) && ($subjectEl = $this->_child($feed, self::SUBJECT))) { // Feed subject is used for things like groups. // Should actually possibly not be interpreted as an actor...? $this->actor = new ActivityObject($subjectEl); } else { if (!empty($feed) && ($authorEl = $this->_child($feed, self::AUTHOR, self::ATOM))) { // If there's no <atom:author> on the entry, it's safe to assume // the containing feed's authorship info applies. $this->actor = new ActivityObject($authorEl); } } } } $contextEl = $this->_child($entry, self::CONTEXT); if (!empty($contextEl)) { $this->context = new ActivityContext($contextEl); } else { $this->context = new ActivityContext($entry); } $targetEl = $this->_child($entry, self::TARGET); if (!empty($targetEl)) { $this->target = new ActivityObject($targetEl); } elseif (ActivityUtils::compareTypes($this->verb, array(ActivityVerb::FAVORITE))) { // StatusNet didn't send a 'target' for their Favorite atom entries $this->target = clone $this->objects[0]; } $this->summary = ActivityUtils::childContent($entry, 'summary'); $this->id = ActivityUtils::childContent($entry, 'id'); $this->content = ActivityUtils::getContent($entry); $catEls = $entry->getElementsByTagNameNS(self::ATOM, 'category'); if ($catEls) { for ($i = 0; $i < $catEls->length; $i++) { $catEl = $catEls->item($i); $this->categories[] = new AtomCategory($catEl); } } foreach (ActivityUtils::getLinks($entry, 'enclosure') as $link) { $this->enclosures[] = $link->getAttribute('href'); } // From APP. Might be useful. $this->selfLink = ActivityUtils::getLink($entry, 'self', 'application/atom+xml'); $this->editLink = ActivityUtils::getLink($entry, 'edit', 'application/atom+xml'); }
function _fromAtomEntry($entry, $feed) { $pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM); if (!empty($pubEl)) { $this->time = strtotime($pubEl->textContent); } else { // XXX technically an error; being liberal. Good idea...? $updateEl = $this->_child($entry, self::UPDATED, self::ATOM); if (!empty($updateEl)) { $this->time = strtotime($updateEl->textContent); } else { $this->time = null; } } $this->link = ActivityUtils::getPermalink($entry); $verbEl = $this->_child($entry, self::VERB); if (!empty($verbEl)) { $this->verb = trim($verbEl->textContent); } else { $this->verb = ActivityVerb::POST; // XXX: do other implied stuff here } $objectEls = $entry->getElementsByTagNameNS(self::SPEC, self::OBJECT); if ($objectEls->length > 0) { for ($i = 0; $i < $objectEls->length; $i++) { $objectEl = $objectEls->item($i); $this->objects[] = new ActivityObject($objectEl); } } else { $this->objects[] = new ActivityObject($entry); } $actorEl = $this->_child($entry, self::ACTOR); if (!empty($actorEl)) { $this->actor = new ActivityObject($actorEl); // Cliqset has bad actor IDs (just nickname of user). We // work around it by getting the author data and using its // id instead if (!preg_match('/^\\w+:/', $this->actor->id)) { $authorEl = ActivityUtils::child($entry, 'author'); if (!empty($authorEl)) { $authorObj = new ActivityObject($authorEl); $this->actor->id = $authorObj->id; } } } else { if (!empty($feed) && ($subjectEl = $this->_child($feed, self::SUBJECT))) { $this->actor = new ActivityObject($subjectEl); } else { if ($authorEl = $this->_child($entry, self::AUTHOR, self::ATOM)) { $this->actor = new ActivityObject($authorEl); } else { if (!empty($feed) && ($authorEl = $this->_child($feed, self::AUTHOR, self::ATOM))) { $this->actor = new ActivityObject($authorEl); } } } } $contextEl = $this->_child($entry, self::CONTEXT); if (!empty($contextEl)) { $this->context = new ActivityContext($contextEl); } else { $this->context = new ActivityContext($entry); } $targetEl = $this->_child($entry, self::TARGET); if (!empty($targetEl)) { $this->target = new ActivityObject($targetEl); } $this->summary = ActivityUtils::childContent($entry, 'summary'); $this->id = ActivityUtils::childContent($entry, 'id'); $this->content = ActivityUtils::getContent($entry); $catEls = $entry->getElementsByTagNameNS(self::ATOM, 'category'); if ($catEls) { for ($i = 0; $i < $catEls->length; $i++) { $catEl = $catEls->item($i); $this->categories[] = new AtomCategory($catEl); } } foreach (ActivityUtils::getLinks($entry, 'enclosure') as $link) { $this->enclosures[] = $link->getAttribute('href'); } }