+ static function fromFile(File $file)
+ {
+ $object = new ActivityObject();
+
+ if (Event::handle('StartActivityObjectFromFile', array($file, &$object))) {
+
+ $object->type = self::mimeTypeToObjectType($file->mimetype);
+ $object->id = TagURI::mint(sprintf("file:%d", $file->id));
+ $object->link = common_local_url('attachment', array('attachment' => $file->id));
+
+ if ($file->title) {
+ $object->title = $file->title;
+ }
+
+ if ($file->date) {
+ $object->date = $file->date;
+ }
+
+ try {
+ $thumbnail = $file->getThumbnail();
+ $object->thumbnail = $thumbnail;
+ } catch (UnsupportedMediaException $e) {
+ $object->thumbnail = null;
+ }
+
+ switch (ActivityObject::canonicalType($object->type)) {
+ case 'image':
+ $object->largerImage = $file->url;
+ break;
+ case 'video':
+ case 'audio':
+ $object->stream = $file->url;
+ break;
+ }
+
+ Event::handle('EndActivityObjectFromFile', array($file, &$object));
+ }
+
+ return $object;
+ }
+
+ static function fromNoticeSource(Notice_source $source)
+ {
+ $object = new ActivityObject();
+ $wellKnown = array('web', 'xmpp', 'mail', 'omb', 'system', 'api', 'ostatus',
+ 'activity', 'feed', 'mirror', 'twitter', 'facebook');
+
+ if (Event::handle('StartActivityObjectFromNoticeSource', array($source, &$object))) {
+ $object->type = ActivityObject::APPLICATION;
+
+ if (in_array($source->code, $wellKnown)) {
+ // We use one ID for all well-known StatusNet sources
+ $object->id = "tag:status.net,2009:notice-source:".$source->code;
+ } else if ($source->url) {
+ // They registered with an URL
+ $object->id = $source->url;
+ } else {
+ // Locally-registered, no URL
+ $object->id = TagURI::mint("notice-source:".$source->code);
+ }
+
+ if ($source->url) {
+ $object->link = $source->url;
+ }
+
+ if ($source->name) {
+ $object->title = $source->name;
+ } else {
+ $object->title = $source->code;
+ }
+
+ if ($source->created) {
+ $object->date = $source->created;
+ }
+
+ $object->extra[] = array('status_net', array('source_code' => $source->code));
+
+ Event::handle('EndActivityObjectFromNoticeSource', array($source, &$object));
+ }
+
+ return $object;
+ }
+
+ static function fromMessage(Message $message)
+ {
+ $object = new ActivityObject();
+
+ if (Event::handle('StartActivityObjectFromMessage', array($message, &$object))) {
+
+ $object->type = ActivityObject::NOTE;
+ $object->id = ($message->uri) ? $message->uri : (($message->url) ? $message->url : TagURI::mint(sprintf("message:%d", $message->id)));
+ $object->content = $message->rendered;
+ $object->date = $message->created;
+
+ if ($message->url) {
+ $object->link = $message->url;
+ } else {
+ $object->link = common_local_url('showmessage', array('message' => $message->id));
+ }
+
+ $object->extra[] = array('status_net', array('message_id' => $message->id));
+
+ Event::handle('EndActivityObjectFromMessage', array($message, &$object));
+ }
+
+ return $object;
+ }
+