Exemplo n.º 1
0
 /**
  * Convert a notice into an activity for export.
  *
  * @param User $cur Current user
  *
  * @return Activity activity object representing this Notice.
  */
 function asActivity($cur)
 {
     $act = self::cacheGet(Cache::codeKey('notice:as-activity:' . $this->id));
     if (!empty($act)) {
         return $act;
     }
     $act = new Activity();
     if (Event::handle('StartNoticeAsActivity', array($this, &$act))) {
         $act->id = TagURI::mint("post:" . $this->id);
         $act->time = strtotime($this->created);
         $act->content = common_xml_safe_str($this->rendered);
         $profile = $this->getProfile();
         $act->actor = ActivityObject::fromProfile($profile);
         $act->actor->extra[] = $profile->profileInfo($cur);
         $act->verb = $this->verb;
         if ($this->repeat_of) {
             $repeated = Notice::staticGet('id', $this->repeat_of);
             if (!empty($repeated)) {
                 $act->objects[] = $repeated->asActivity($cur);
             }
         } else {
             $act->objects[] = ActivityObject::fromNotice($this);
         }
         // XXX: should this be handled by default processing for object entry?
         // Categories
         $tags = $this->getTags();
         foreach ($tags as $tag) {
             $cat = new AtomCategory();
             $cat->term = $tag;
             $act->categories[] = $cat;
         }
         // Enclosures
         // XXX: use Atom Media and/or File activity objects instead
         $attachments = $this->attachments();
         foreach ($attachments as $attachment) {
             // Save local attachments
             if (!empty($attachment->filename)) {
                 $act->attachments[] = ActivityObject::fromFile($attachment);
             }
         }
         $ctx = new ActivityContext();
         if (!empty($this->reply_to)) {
             $reply = Notice::staticGet('id', $this->reply_to);
             if (!empty($reply)) {
                 $ctx->replyToID = $reply->uri;
                 $ctx->replyToUrl = $reply->bestUrl();
             }
         }
         $ctx->location = $this->getLocation();
         $conv = null;
         if (!empty($this->conversation)) {
             $conv = Conversation::staticGet('id', $this->conversation);
             if (!empty($conv)) {
                 $ctx->conversation = $conv->uri;
             }
         }
         $reply_ids = $this->getReplies();
         foreach ($reply_ids as $id) {
             $rprofile = Profile::staticGet('id', $id);
             if (!empty($rprofile)) {
                 $ctx->attention[] = $rprofile->getUri();
                 $ctx->attentionType[$rprofile->getUri()] = ActivityObject::PERSON;
             }
         }
         $groups = $this->getGroups();
         foreach ($groups as $group) {
             $ctx->attention[] = $group->getUri();
             $ctx->attentionType[$group->getUri()] = ActivityObject::GROUP;
         }
         switch ($this->scope) {
             case Notice::PUBLIC_SCOPE:
                 $ctx->attention[] = "http://activityschema.org/collection/public";
                 $ctx->attentionType["http://activityschema.org/collection/public"] = ActivityObject::COLLECTION;
                 break;
             case Notice::FOLLOWER_SCOPE:
                 $surl = common_local_url("subscribers", array('nickname' => $profile->nickname));
                 $ctx->attention[] = $surl;
                 $ctx->attentionType[$surl] = ActivityObject::COLLECTION;
                 break;
         }
         // XXX: deprecated; use ActivityVerb::SHARE instead
         $repeat = null;
         if (!empty($this->repeat_of)) {
             $repeat = Notice::staticGet('id', $this->repeat_of);
             if (!empty($repeat)) {
                 $ctx->forwardID = $repeat->uri;
                 $ctx->forwardUrl = $repeat->bestUrl();
             }
         }
         $act->context = $ctx;
         $source = $this->getSource();
         if ($source) {
             $act->generator = ActivityObject::fromNoticeSource($source);
         }
         // Source
         $atom_feed = $profile->getAtomFeed();
         if (!empty($atom_feed)) {
             $act->source = new ActivitySource();
             // XXX: we should store the actual feed ID
             $act->source->id = $atom_feed;
             // XXX: we should store the actual feed title
             $act->source->title = $profile->getBestName();
             $act->source->links['alternate'] = $profile->profileurl;
             $act->source->links['self'] = $atom_feed;
             $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
             $notice = $profile->getCurrentNotice();
             if (!empty($notice)) {
                 $act->source->updated = self::utcDate($notice->created);
             }
             $user = User::staticGet('id', $profile->id);
             if (!empty($user)) {
                 $act->source->links['license'] = common_config('license', 'url');
             }
         }
         if ($this->isLocal()) {
             $act->selfLink = common_local_url('ApiStatusesShow', array('id' => $this->id, 'format' => 'atom'));
             $act->editLink = $act->selfLink;
         }
         Event::handle('EndNoticeAsActivity', array($this, &$act));
     }
     self::cacheSet(Cache::codeKey('notice:as-activity:' . $this->id), $act);
     return $act;
 }
Exemplo n.º 2
0
 /**
  * Convert a notice into an activity for export.
  *
  * @param Profile $scoped   The currently logged in/scoped profile
  *
  * @return Activity activity object representing this Notice.
  */
 function asActivity(Profile $scoped = null)
 {
     $act = self::cacheGet(Cache::codeKey('notice:as-activity:' . $this->id));
     if ($act instanceof Activity) {
         return $act;
     }
     $act = new Activity();
     if (Event::handle('StartNoticeAsActivity', array($this, $act, $scoped))) {
         $act->id = $this->uri;
         $act->time = strtotime($this->created);
         try {
             $act->link = $this->getUrl();
         } catch (InvalidUrlException $e) {
             // The notice is probably a share or similar, which don't
             // have a representational URL of their own.
         }
         $act->content = common_xml_safe_str($this->getRendered());
         $profile = $this->getProfile();
         $act->actor = $profile->asActivityObject();
         $act->actor->extra[] = $profile->profileInfo($scoped);
         $act->verb = $this->verb;
         if (!$this->repeat_of) {
             $act->objects[] = $this->asActivityObject();
         }
         // XXX: should this be handled by default processing for object entry?
         // Categories
         $tags = $this->getTags();
         foreach ($tags as $tag) {
             $cat = new AtomCategory();
             $cat->term = $tag;
             $act->categories[] = $cat;
         }
         // Enclosures
         // XXX: use Atom Media and/or File activity objects instead
         $attachments = $this->attachments();
         foreach ($attachments as $attachment) {
             // Include local attachments in Activity
             if (!empty($attachment->filename)) {
                 $act->enclosures[] = $attachment->getEnclosure();
             }
         }
         $ctx = new ActivityContext();
         try {
             $reply = $this->getParent();
             $ctx->replyToID = $reply->getUri();
             $ctx->replyToUrl = $reply->getUrl(true);
             // true for fallback to local URL, less messy
         } catch (NoParentNoticeException $e) {
             // This is not a reply to something
         } catch (NoResultException $e) {
             // Parent notice was probably deleted
         }
         try {
             $ctx->location = Notice_location::locFromStored($this);
         } catch (ServerException $e) {
             $ctx->location = null;
         }
         $conv = null;
         if (!empty($this->conversation)) {
             $conv = Conversation::getKV('id', $this->conversation);
             if ($conv instanceof Conversation) {
                 $ctx->conversation = $conv->uri;
             }
         }
         // This covers the legacy getReplies and getGroups too which get their data
         // from entries stored via Notice::saveNew (which we want to move away from)...
         foreach ($this->getAttentionProfiles() as $target) {
             // User and group profiles which get the attention of this notice
             $ctx->attention[$target->getUri()] = $target->getObjectType();
         }
         switch ($this->scope) {
             case Notice::PUBLIC_SCOPE:
                 $ctx->attention[ActivityContext::ATTN_PUBLIC] = ActivityObject::COLLECTION;
                 break;
             case Notice::FOLLOWER_SCOPE:
                 $surl = common_local_url("subscribers", array('nickname' => $profile->nickname));
                 $ctx->attention[$surl] = ActivityObject::COLLECTION;
                 break;
         }
         $act->context = $ctx;
         $source = $this->getSource();
         if ($source instanceof Notice_source) {
             $act->generator = ActivityObject::fromNoticeSource($source);
         }
         // Source
         $atom_feed = $profile->getAtomFeed();
         if (!empty($atom_feed)) {
             $act->source = new ActivitySource();
             // XXX: we should store the actual feed ID
             $act->source->id = $atom_feed;
             // XXX: we should store the actual feed title
             $act->source->title = $profile->getBestName();
             $act->source->links['alternate'] = $profile->profileurl;
             $act->source->links['self'] = $atom_feed;
             $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
             $notice = $profile->getCurrentNotice();
             if ($notice instanceof Notice) {
                 $act->source->updated = self::utcDate($notice->created);
             }
             $user = User::getKV('id', $profile->id);
             if ($user instanceof User) {
                 $act->source->links['license'] = common_config('license', 'url');
             }
         }
         if ($this->isLocal()) {
             $act->selfLink = common_local_url('ApiStatusesShow', array('id' => $this->id, 'format' => 'atom'));
             $act->editLink = $act->selfLink;
         }
         Event::handle('EndNoticeAsActivity', array($this, $act, $scoped));
     }
     self::cacheSet(Cache::codeKey('notice:as-activity:' . $this->id), $act);
     return $act;
 }
Exemplo n.º 3
0
 function asActivity()
 {
     $act = new Activity();
     if (Event::handle('StartMessageAsActivity', array($this, &$act))) {
         $act->id = TagURI::mint(sprintf('activity:message:%d', $this->id));
         $act->time = strtotime($this->created);
         $act->link = $this->url;
         $profile = Profile::getKV('id', $this->from_profile);
         if (empty($profile)) {
             throw new Exception(sprintf("Sender profile not found: %d", $this->from_profile));
         }
         $act->actor = $profile->asActivityObject();
         $act->actor->extra[] = $profile->profileInfo();
         $act->verb = ActivityVerb::POST;
         $act->objects[] = ActivityObject::fromMessage($this);
         $ctx = new ActivityContext();
         $rprofile = Profile::getKV('id', $this->to_profile);
         if (empty($rprofile)) {
             throw new Exception(sprintf("Receiver profile not found: %d", $this->to_profile));
         }
         $ctx->attention[$rprofile->getUri()] = ActivityObject::PERSON;
         $act->context = $ctx;
         $source = $this->getSource();
         if ($source instanceof Notice_source) {
             $act->generator = ActivityObject::fromNoticeSource($source);
         }
         Event::handle('EndMessageAsActivity', array($this, &$act));
     }
     return $act;
 }