X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2FNotice.php;h=4f23e35007f4cac4f099832fa6df805185082d2f;hb=61fde6c8fff5201393db4496918fe193fe960c01;hp=13b322828bade789c9c45a3c083d0123b1a8d439;hpb=78ed0348b0eaaebf7a51d55adc7e746cc5b43bbf;p=quix0rs-gnu-social.git diff --git a/classes/Notice.php b/classes/Notice.php index 13b322828b..4f23e35007 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1219,6 +1219,64 @@ class Notice extends Memcached_DataObject return $groups; } + function asActivity() + { + $profile = $this->getProfile(); + + $act = new Activity(); + + $act->actor = ActivityObject::fromProfile($profile); + $act->verb = ActivityVerb::POST; + $act->objects[] = ActivityObject::fromNotice($this); + + $act->time = strtotime($this->created); + $act->link = $this->bestUrl(); + + $act->content = common_xml_safe_str($this->rendered); + $act->id = $this->uri; + $act->title = common_xml_safe_str($this->content); + + $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) { + $profile = Profile::staticGet('id', $id); + if (!empty($profile)) { + $ctx->attention[] = $profile->getUri(); + } + } + + $groups = $this->getGroups(); + + foreach ($groups as $group) { + $ctx->attention[] = $group->uri; + } + + $act->context = $ctx; + + return $act; + } + // This has gotten way too long. Needs to be sliced up into functional bits // or ideally exported to a utility class.