public function activityObjectFromNotice(Notice $notice) { $object = new ActivityObject(); $object->type = $notice->object_type ?: ActivityObject::NOTE; $object->id = $notice->getUri(); $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname()); $object->content = $notice->getRendered(); $object->link = $notice->getUrl(); $object->extra[] = array('status_net', array('notice_id' => $notice->getID())); return $object; }
public function asActivityObject() { $object = new ActivityObject(); if (Event::handle('StartActivityObjectFromNotice', array($this, &$object))) { $object->type = $this->object_type ?: ActivityObject::NOTE; $object->id = $this->getUri(); //FIXME: = $object->title ?: sprintf(... because we might get a title from StartActivityObjectFromNotice $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $this->getProfile()->getNickname()); $object->content = $this->getRendered(); $object->link = $this->getUrl(); $object->extra[] = array('status_net', array('notice_id' => $this->id)); Event::handle('EndActivityObjectFromNotice', array($this, &$object)); } return $object; }
/** * Returns an array of arrays representing Activity Objects (intended to be * serialized in JSON) that represent WHO the Activity is supposed to * be received by. This is not really specified but appears in an example * of the current spec as an extension. We might want to figure out a JSON * serialization for OStatus and use that to express mentions instead. * * XXX: People's ideas on how to do this are all over the place * * @return array the array of recipients */ function getToArray() { $tos = array(); foreach ($this->attention as $attnUrl) { if (array_key_exists($attnUrl, $this->attentionType)) { $type = ActivityObject::canonicalType($this->attentionType[$attnUrl]); } else { $type = ActivityObject::canonicalType(ActivityObject::PERSON); } $to = array('objectType' => $type, 'id' => $attnUrl); $tos[] = $to; } return $tos; }
function asArray() { $object = array(); if (Event::handle('StartActivityObjectOutputJson', array($this, &$object))) { // XXX: attachments are added by Activity // author (Add object for author? Could be useful for repeats.) // content (Add rendered version of the notice?) // displayName if ($this->title) { $object['displayName'] = $this->title; } // downstreamDuplicates // id if ($this->id) { $object['id'] = $this->id; } else { if ($this->link) { $object['id'] = $this->link; } } if ($this->type == ActivityObject::PERSON || $this->type == ActivityObject::GROUP) { // XXX: Not sure what the best avatar is to use for the // author's "image". For now, I'm using the large size. $imgLink = null; $avatarMediaLinks = array(); foreach ($this->avatarLinks as $a) { // Make a MediaLink for every other Avatar $avatar = new ActivityStreamsMediaLink($a->url, $a->width, $a->height, $a->type, 'avatar'); // Find the big avatar to use as the "image" if ($a->height == AVATAR_PROFILE_SIZE) { $imgLink = $avatar; } $avatarMediaLinks[] = $avatar->asArray(); } if (!array_key_exists('status_net', $object)) { $object['status_net'] = array(); } $object['status_net']['avatarLinks'] = $avatarMediaLinks; // extension // image if (!empty($imgLink)) { $object['image'] = $imgLink->asArray(); } } // objectType // // We can probably use the whole schema URL here but probably the // relative simple name is easier to parse $object['objectType'] = ActivityObject::canonicalType($this->type); // summary $object['summary'] = $this->summary; // content $object['content'] = $this->content; // published (probably don't need. Might be useful for repeats.) // updated (probably don't need this) // TODO: upstreamDuplicates if ($this->link) { $object['url'] = $this->link; } /* Extensions */ // @fixme these may collide with XML extensions // @fixme multiple tags of same name will overwrite each other // @fixme text content from XML extensions will be lost foreach ($this->extra as $e) { list($objectName, $props, $txt) = $e; if (!empty($objectName)) { $parts = explode(":", $objectName); if (count($parts) == 2 && $parts[0] == "statusnet") { if (!array_key_exists('status_net', $object)) { $object['status_net'] = array(); } $object['status_net'][$parts[1]] = $props; } else { $object[$objectName] = $props; } } } if (!empty($this->geopoint)) { list($lat, $lon) = explode(' ', $this->geopoint); $object['location'] = array('objectType' => 'place', 'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon), 'lat' => $lat, 'lon' => $lon); $loc = Location::fromLatLon($lat, $lon); if ($loc) { $name = $loc->getName(); if ($name) { $object['location']['displayName'] = $name; } $url = $loc->getURL(); if ($url) { $object['location']['url'] = $url; } } } if (!empty($this->poco)) { $object['portablecontacts_net'] = array_filter($this->poco->asArray()); } if (!empty($this->thumbnail)) { if (is_string($this->thumbnail)) { $object['image'] = array('url' => $this->thumbnail); } else { $object['image'] = array('url' => $this->thumbnail->url); if ($this->thumbnail->width) { $object['image']['width'] = $this->thumbnail->width; } if ($this->thumbnail->height) { $object['image']['height'] = $this->thumbnail->height; } } } switch (ActivityObject::canonicalType($this->type)) { case 'image': if (!empty($this->largerImage)) { $object['fullImage'] = array('url' => $this->largerImage); } break; case 'audio': case 'video': if (!empty($this->stream)) { $object['stream'] = array('url' => $this->stream); } break; } Event::handle('EndActivityObjectOutputJson', array($this, &$object)); } return array_filter($object); }