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);
         }
     }
 }
 function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options = array())
 {
     if (count($activity->objects) != 1) {
         throw new Exception('Too many activity objects.');
     }
     $videoObj = $activity->objects[0];
     if ($videoObj->type != Video::OBJECT_TYPE) {
         throw new Exception('Wrong type for object.');
     }
     // For now we read straight from the xml tree, no other way to get this information.
     // When there's a better API for this, we should change to it.
     $uri = ActivityUtils::getLink($activity->entry, 'enclosure');
     $options['object_type'] = Video::OBJECT_TYPE;
     Video::saveNew($actor, $uri, $options);
 }
Exemple #4
0
 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);
         }
     }
 }
Exemple #5
0
 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');
 }
Exemple #6
0
 public function getAtomLink($rel, $type = null)
 {
     return ActivityUtils::getLink($this->root, $rel, $type);
 }
 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 testConversationLink()
 {
     $orig = $this->_fakeNotice($this->targetUser1);
     $text = "@" . $this->targetUser1->nickname . " reply text " . common_good_rand(4);
     $reply = Notice::saveNew($this->author1->id, $text, 'test', array('uri' => null, 'reply_to' => $orig->id));
     $conv = Conversation::staticGet('id', $reply->conversation);
     $entry = $reply->asAtomEntry();
     $element = $this->_entryToElement($entry, true);
     $this->assertEquals($conv->uri, ActivityUtils::getLink($element, 'ostatus:conversation'));
 }