/** * 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; }