]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/activityobject.php
Use status_net, portablecontacts_net namespaces
[quix0rs-gnu-social.git] / lib / activityobject.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * An activity
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Feed
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Zach Copley <zach@status.net>
26  * @copyright 2010 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /**
36  * A noun-ish thing in the activity universe
37  *
38  * The activity streams spec talks about activity objects, while also having
39  * a tag activity:object, which is in fact an activity object. Aaaaaah!
40  *
41  * This is just a thing in the activity universe. Can be the subject, object,
42  * or indirect object (target!) of an activity verb. Rotten name, and I'm
43  * propagating it. *sigh*
44  *
45  * @category  OStatus
46  * @package   StatusNet
47  * @author    Evan Prodromou <evan@status.net>
48  * @copyright 2010 StatusNet, Inc.
49  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
50  * @link      http://status.net/
51  */
52 class ActivityObject
53 {
54     const ARTICLE   = 'http://activitystrea.ms/schema/1.0/article';
55     const BLOGENTRY = 'http://activitystrea.ms/schema/1.0/blog-entry';
56     const NOTE      = 'http://activitystrea.ms/schema/1.0/note';
57     const STATUS    = 'http://activitystrea.ms/schema/1.0/status';
58     const FILE      = 'http://activitystrea.ms/schema/1.0/file';
59     const PHOTO     = 'http://activitystrea.ms/schema/1.0/photo';
60     const ALBUM     = 'http://activitystrea.ms/schema/1.0/photo-album';
61     const PLAYLIST  = 'http://activitystrea.ms/schema/1.0/playlist';
62     const VIDEO     = 'http://activitystrea.ms/schema/1.0/video';
63     const AUDIO     = 'http://activitystrea.ms/schema/1.0/audio';
64     const BOOKMARK  = 'http://activitystrea.ms/schema/1.0/bookmark';
65     const PERSON    = 'http://activitystrea.ms/schema/1.0/person';
66     const GROUP     = 'http://activitystrea.ms/schema/1.0/group';
67     const _LIST     = 'http://activitystrea.ms/schema/1.0/list'; // LIST is reserved
68     const PLACE     = 'http://activitystrea.ms/schema/1.0/place';
69     const COMMENT   = 'http://activitystrea.ms/schema/1.0/comment';
70     // ^^^^^^^^^^ tea!
71     const ACTIVITY = 'http://activitystrea.ms/schema/1.0/activity';
72     const SERVICE   = 'http://activitystrea.ms/schema/1.0/service';
73
74     // Atom elements we snarf
75
76     const TITLE   = 'title';
77     const SUMMARY = 'summary';
78     const ID      = 'id';
79     const SOURCE  = 'source';
80
81     const NAME  = 'name';
82     const URI   = 'uri';
83     const EMAIL = 'email';
84
85     const POSTEROUS   = 'http://posterous.com/help/rss/1.0';
86     const AUTHOR      = 'author';
87     const USERIMAGE   = 'userImage';
88     const PROFILEURL  = 'profileUrl';
89     const NICKNAME    = 'nickName';
90     const DISPLAYNAME = 'displayName';
91
92     public $element;
93     public $type;
94     public $id;
95     public $title;
96     public $summary;
97     public $content;
98     public $owner;
99     public $link;
100     public $source;
101     public $avatarLinks = array();
102     public $geopoint;
103     public $poco;
104     public $displayName;
105
106     // @todo move this stuff to it's own PHOTO activity object
107     const MEDIA_DESCRIPTION = 'description';
108
109     public $thumbnail;
110     public $largerImage;
111     public $description;
112     public $extra = array();
113
114     /**
115      * Constructor
116      *
117      * This probably needs to be refactored
118      * to generate a local class (ActivityPerson, ActivityFile, ...)
119      * based on the object type.
120      *
121      * @param DOMElement $element DOM thing to turn into an Activity thing
122      */
123     function __construct($element = null)
124     {
125         if (empty($element)) {
126             return;
127         }
128
129         $this->element = $element;
130
131         $this->geopoint = $this->_childContent(
132             $element,
133             ActivityContext::POINT,
134             ActivityContext::GEORSS
135         );
136
137         if ($element->tagName == 'author') {
138             $this->_fromAuthor($element);
139         } else if ($element->tagName == 'item') {
140             $this->_fromRssItem($element);
141         } else {
142             $this->_fromAtomEntry($element);
143         }
144
145         // Some per-type attributes...
146         if ($this->type == self::PERSON || $this->type == self::GROUP) {
147             $this->displayName = $this->title;
148
149             $photos = ActivityUtils::getLinks($element, 'photo');
150             if (count($photos)) {
151                 foreach ($photos as $link) {
152                     $this->avatarLinks[] = new AvatarLink($link);
153                 }
154             } else {
155                 $avatars = ActivityUtils::getLinks($element, 'avatar');
156                 foreach ($avatars as $link) {
157                     $this->avatarLinks[] = new AvatarLink($link);
158                 }
159             }
160
161             $this->poco = new PoCo($element);
162         }
163
164         if ($this->type == self::PHOTO) {
165
166             $this->thumbnail   = ActivityUtils::getLink($element, 'preview');
167             $this->largerImage = ActivityUtils::getLink($element, 'enclosure');
168
169             $this->description = ActivityUtils::childContent(
170                 $element,
171                 ActivityObject::MEDIA_DESCRIPTION,
172                 Activity::MEDIA
173             );
174         }
175         if ($this->type == self::_LIST) {
176             $owner = ActivityUtils::child($this->element, Activity::AUTHOR, Activity::SPEC);
177             $this->owner = new ActivityObject($owner);
178         }
179     }
180
181     private function _fromAuthor($element)
182     {
183         $this->type = $this->_childContent($element,
184                                            Activity::OBJECTTYPE,
185                                            Activity::SPEC);
186
187         if (empty($this->type)) {
188             $this->type = self::PERSON; // XXX: is this fair?
189         }
190
191         // start with <atom:title>
192
193         $title = ActivityUtils::childHtmlContent($element, self::TITLE);
194
195         if (!empty($title)) {
196             $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8');
197         }
198
199         // fall back to <atom:name>
200
201         if (empty($this->title)) {
202             $this->title = $this->_childContent($element, self::NAME);
203         }
204
205         // start with <atom:id>
206
207         $this->id = $this->_childContent($element, self::ID);
208
209         // fall back to <atom:uri>
210
211         if (empty($this->id)) {
212             $this->id = $this->_childContent($element, self::URI);
213         }
214
215         // fall further back to <atom:email>
216
217         if (empty($this->id)) {
218             $email = $this->_childContent($element, self::EMAIL);
219             if (!empty($email)) {
220                 // XXX: acct: ?
221                 $this->id = 'mailto:'.$email;
222             }
223         }
224
225         $this->link = ActivityUtils::getPermalink($element);
226
227         // fall finally back to <link rel=alternate>
228
229         if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
230             $this->id = $this->link;
231         }
232     }
233
234     private function _fromAtomEntry($element)
235     {
236         $this->type = $this->_childContent($element, Activity::OBJECTTYPE,
237                                            Activity::SPEC);
238
239         if (empty($this->type)) {
240             $this->type = ActivityObject::NOTE;
241         }
242
243         $this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY);
244         $this->content = ActivityUtils::getContent($element);
245
246         // We don't like HTML in our titles, although it's technically allowed
247
248         $title = ActivityUtils::childHtmlContent($element, self::TITLE);
249
250         $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8');
251
252         $this->source  = $this->_getSource($element);
253
254         $this->link = ActivityUtils::getPermalink($element);
255
256         $this->id = $this->_childContent($element, self::ID);
257
258         if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
259             $this->id = $this->link;
260         }
261     }
262
263     // @todo FIXME: rationalize with Activity::_fromRssItem()
264     private function _fromRssItem($item)
265     {
266         $this->title = ActivityUtils::childContent($item, ActivityObject::TITLE, Activity::RSS);
267
268         $contentEl = ActivityUtils::child($item, ActivityUtils::CONTENT, Activity::CONTENTNS);
269
270         if (!empty($contentEl)) {
271             $this->content = htmlspecialchars_decode($contentEl->textContent, ENT_QUOTES);
272         } else {
273             $descriptionEl = ActivityUtils::child($item, Activity::DESCRIPTION, Activity::RSS);
274             if (!empty($descriptionEl)) {
275                 $this->content = htmlspecialchars_decode($descriptionEl->textContent, ENT_QUOTES);
276             }
277         }
278
279         $this->link = ActivityUtils::childContent($item, ActivityUtils::LINK, Activity::RSS);
280
281         $guidEl = ActivityUtils::child($item, Activity::GUID, Activity::RSS);
282
283         if (!empty($guidEl)) {
284             $this->id = $guidEl->textContent;
285
286             if ($guidEl->hasAttribute('isPermaLink')) {
287                 // overwrites <link>
288                 $this->link = $this->id;
289             }
290         }
291     }
292
293     public static function fromRssAuthor($el)
294     {
295         $text = $el->textContent;
296
297         if (preg_match('/^(.*?) \((.*)\)$/', $text, $match)) {
298             $email = $match[1];
299             $name = $match[2];
300         } else if (preg_match('/^(.*?) <(.*)>$/', $text, $match)) {
301             $name = $match[1];
302             $email = $match[2];
303         } else if (preg_match('/.*@.*/', $text)) {
304             $email = $text;
305             $name = null;
306         } else {
307             $name = $text;
308             $email = null;
309         }
310
311         // Not really enough info
312
313         $obj = new ActivityObject();
314
315         $obj->element = $el;
316
317         $obj->type  = ActivityObject::PERSON;
318         $obj->title = $name;
319
320         if (!empty($email)) {
321             $obj->id = 'mailto:'.$email;
322         }
323
324         return $obj;
325     }
326
327     public static function fromDcCreator($el)
328     {
329         // Not really enough info
330
331         $text = $el->textContent;
332
333         $obj = new ActivityObject();
334
335         $obj->element = $el;
336
337         $obj->title = $text;
338         $obj->type  = ActivityObject::PERSON;
339
340         return $obj;
341     }
342
343     public static function fromRssChannel($el)
344     {
345         $obj = new ActivityObject();
346
347         $obj->element = $el;
348
349         $obj->type = ActivityObject::PERSON; // @fixme guess better
350
351         $obj->title = ActivityUtils::childContent($el, ActivityObject::TITLE, Activity::RSS);
352         $obj->link  = ActivityUtils::childContent($el, ActivityUtils::LINK, Activity::RSS);
353         $obj->id    = ActivityUtils::getLink($el, Activity::SELF);
354
355         if (empty($obj->id)) {
356             $obj->id = $obj->link;
357         }
358
359         $desc = ActivityUtils::childContent($el, Activity::DESCRIPTION, Activity::RSS);
360
361         if (!empty($desc)) {
362             $obj->content = htmlspecialchars_decode($desc, ENT_QUOTES);
363         }
364
365         $imageEl = ActivityUtils::child($el, Activity::IMAGE, Activity::RSS);
366
367         if (!empty($imageEl)) {
368             $url = ActivityUtils::childContent($imageEl, Activity::URL, Activity::RSS);
369             $al = new AvatarLink();
370             $al->url = $url;
371             $obj->avatarLinks[] = $al;
372         }
373
374         return $obj;
375     }
376
377     public static function fromPosterousAuthor($el)
378     {
379         $obj = new ActivityObject();
380
381         $obj->type = ActivityObject::PERSON; // @fixme any others...?
382
383         $userImage = ActivityUtils::childContent($el, self::USERIMAGE, self::POSTEROUS);
384
385         if (!empty($userImage)) {
386             $al = new AvatarLink();
387             $al->url = $userImage;
388             $obj->avatarLinks[] = $al;
389         }
390
391         $obj->link = ActivityUtils::childContent($el, self::PROFILEURL, self::POSTEROUS);
392         $obj->id   = $obj->link;
393
394         $obj->poco = new PoCo();
395
396         $obj->poco->preferredUsername = ActivityUtils::childContent($el, self::NICKNAME, self::POSTEROUS);
397         $obj->poco->displayName       = ActivityUtils::childContent($el, self::DISPLAYNAME, self::POSTEROUS);
398
399         $obj->title = $obj->poco->displayName;
400
401         return $obj;
402     }
403
404     private function _childContent($element, $tag, $namespace=ActivityUtils::ATOM)
405     {
406         return ActivityUtils::childContent($element, $tag, $namespace);
407     }
408
409     // Try to get a unique id for the source feed
410
411     private function _getSource($element)
412     {
413         $sourceEl = ActivityUtils::child($element, 'source');
414
415         if (empty($sourceEl)) {
416             return null;
417         } else {
418             $href = ActivityUtils::getLink($sourceEl, 'self');
419             if (!empty($href)) {
420                 return $href;
421             } else {
422                 return ActivityUtils::childContent($sourceEl, 'id');
423             }
424         }
425     }
426
427     static function fromNotice(Notice $notice)
428     {
429         $object = new ActivityObject();
430
431         if (Event::handle('StartActivityObjectFromNotice', array($notice, &$object))) {
432
433             $object->type    = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type;
434
435             $object->id      = $notice->uri;
436             $object->title   = $notice->content;
437             $object->content = $notice->rendered;
438             $object->link    = $notice->bestUrl();
439
440             Event::handle('EndActivityObjectFromNotice', array($notice, &$object));
441         }
442
443         return $object;
444     }
445
446     static function fromProfile(Profile $profile)
447     {
448         $object = new ActivityObject();
449
450         if (Event::handle('StartActivityObjectFromProfile', array($profile, &$object))) {
451             $object->type   = ActivityObject::PERSON;
452             $object->id     = $profile->getUri();
453             $object->title  = $profile->getBestName();
454             $object->link   = $profile->profileurl;
455
456             $orig = $profile->getOriginalAvatar();
457
458             if (!empty($orig)) {
459                 $object->avatarLinks[] = AvatarLink::fromAvatar($orig);
460             }
461
462             $sizes = array(
463                 AVATAR_PROFILE_SIZE,
464                 AVATAR_STREAM_SIZE,
465                 AVATAR_MINI_SIZE
466             );
467
468             foreach ($sizes as $size) {
469                 $alink  = null;
470                 $avatar = $profile->getAvatar($size);
471
472                 if (!empty($avatar)) {
473                     $alink = AvatarLink::fromAvatar($avatar);
474                 } else {
475                     $alink = new AvatarLink();
476                     $alink->type   = 'image/png';
477                     $alink->height = $size;
478                     $alink->width  = $size;
479                     $alink->url    = Avatar::defaultImage($size);
480
481                     if ($size == AVATAR_PROFILE_SIZE) {
482                         // Hack for Twitter import: we don't have a 96x96 image,
483                         // but we do have a 73x73 image. For now, fake it with that.
484                         $avatar = $profile->getAvatar(73);
485                         if ($avatar) {
486                             $alink = AvatarLink::fromAvatar($avatar);
487                             $alink->height= $size;
488                             $alink->width = $size;
489                         }
490                     }
491                 }
492
493                 $object->avatarLinks[] = $alink;
494             }
495
496             if (isset($profile->lat) && isset($profile->lon)) {
497                 $object->geopoint = (float)$profile->lat
498                     . ' ' . (float)$profile->lon;
499             }
500
501             $object->poco = PoCo::fromProfile($profile);
502
503             Event::handle('EndActivityObjectFromProfile', array($profile, &$object));
504         }
505
506         return $object;
507     }
508
509     static function fromGroup($group)
510     {
511         $object = new ActivityObject();
512
513         if (Event::handle('StartActivityObjectFromGroup', array($group, &$object))) {
514
515             $object->type   = ActivityObject::GROUP;
516             $object->id     = $group->getUri();
517             $object->title  = $group->getBestName();
518             $object->link   = $group->getUri();
519
520             $object->avatarLinks[] = AvatarLink::fromFilename($group->homepage_logo,
521                                                               AVATAR_PROFILE_SIZE);
522
523             $object->avatarLinks[] = AvatarLink::fromFilename($group->stream_logo,
524                                                               AVATAR_STREAM_SIZE);
525
526             $object->avatarLinks[] = AvatarLink::fromFilename($group->mini_logo,
527                                                               AVATAR_MINI_SIZE);
528
529             $object->poco = PoCo::fromGroup($group);
530             Event::handle('EndActivityObjectFromGroup', array($group, &$object));
531         }
532
533         return $object;
534     }
535
536     static function fromPeopletag($ptag)
537     {
538         $object = new ActivityObject();
539         if (Event::handle('StartActivityObjectFromPeopletag', array($ptag, &$object))) {
540             $object->type    = ActivityObject::_LIST;
541
542             $object->id      = $ptag->getUri();
543             $object->title   = $ptag->tag;
544             $object->summary = $ptag->description;
545             $object->link    = $ptag->homeUrl();
546             $object->owner   = Profile::staticGet('id', $ptag->tagger);
547             $object->poco    = PoCo::fromProfile($object->owner);
548             Event::handle('EndActivityObjectFromPeopletag', array($ptag, &$object));
549         }
550         return $object;
551     }
552
553     function outputTo($xo, $tag='activity:object')
554     {
555         if (!empty($tag)) {
556             $xo->elementStart($tag);
557         }
558
559         if (Event::handle('StartActivityObjectOutputAtom', array($this, $xo))) {
560             $xo->element('activity:object-type', null, $this->type);
561
562             // <author> uses URI
563
564             if ($tag == 'author') {
565                 $xo->element(self::URI, null, $this->id);
566             } else {
567                 $xo->element(self::ID, null, $this->id);
568             }
569
570             if (!empty($this->title)) {
571                 $name = common_xml_safe_str($this->title);
572                 if ($tag == 'author') {
573                     // XXX: Backward compatibility hack -- atom:name should contain
574                     // full name here, instead of nickname, i.e.: $name. Change
575                     // this in the next version.
576                     $xo->element(self::NAME, null, $this->poco->preferredUsername);
577                 } else {
578                     $xo->element(self::TITLE, null, $name);
579                 }
580             }
581
582             if (!empty($this->summary)) {
583                 $xo->element(
584                     self::SUMMARY,
585                     null,
586                     common_xml_safe_str($this->summary)
587                 );
588             }
589
590             if (!empty($this->content)) {
591                 // XXX: assuming HTML content here
592                 $xo->element(
593                     ActivityUtils::CONTENT,
594                     array('type' => 'html'),
595                     common_xml_safe_str($this->content)
596                 );
597             }
598
599             if (!empty($this->link)) {
600                 $xo->element(
601                     'link',
602                     array(
603                         'rel' => 'alternate',
604                         'type' => 'text/html',
605                         'href' => $this->link
606                     ),
607                     null
608                 );
609             }
610
611             if(!empty($this->owner)) {
612                 $owner = $this->owner->asActivityNoun(self::AUTHOR);
613                 $xo->raw($owner);
614             }
615
616             if ($this->type == ActivityObject::PERSON
617                 || $this->type == ActivityObject::GROUP) {
618
619                 foreach ($this->avatarLinks as $avatar) {
620                     $xo->element(
621                         'link', array(
622                             'rel'  => 'avatar',
623                             'type'         => $avatar->type,
624                             'media:width'  => $avatar->width,
625                             'media:height' => $avatar->height,
626                             'href' => $avatar->url
627                         ),
628                         null
629                     );
630                 }
631             }
632
633             if (!empty($this->geopoint)) {
634                 $xo->element(
635                     'georss:point',
636                     null,
637                     $this->geopoint
638                 );
639             }
640
641             if (!empty($this->poco)) {
642                 $this->poco->outputTo($xo);
643             }
644
645             // @fixme there's no way here to make a tree; elements can only contain plaintext
646             // @fixme these may collide with JSON extensions
647             foreach ($this->extra as $el) {
648                 list($extraTag, $attrs, $content) = $el;
649                 $xo->element($extraTag, $attrs, $content);
650             }
651
652             Event::handle('EndActivityObjectOutputAtom', array($this, $xo));
653         }
654
655         if (!empty($tag)) {
656             $xo->elementEnd($tag);
657         }
658
659         return;
660     }
661
662     function asString($tag='activity:object')
663     {
664         $xs = new XMLStringer(true);
665
666         $this->outputTo($xs, $tag);
667
668         return $xs->getString();
669     }
670
671     /*
672      * Returns an array based on this Activity Object suitable for
673      * encoding as JSON.
674      *
675      * @return array $object the activity object array
676      */
677
678     function asArray()
679     {
680         $object = array();
681
682         if (Event::handle('StartActivityObjectOutputJson', array($this, &$object))) {
683             // XXX: attachments are added by Activity
684
685             // author (Add object for author? Could be useful for repeats.)
686
687             // content (Add rendered version of the notice?)
688
689             // displayName
690             $object['displayName'] = $this->title;
691
692             // downstreamDuplicates
693
694             // id
695             $object['id'] = $this->id;
696
697             if ($this->type == ActivityObject::PERSON
698                 || $this->type == ActivityObject::GROUP) {
699
700                 // XXX: Not sure what the best avatar is to use for the
701                 // author's "image". For now, I'm using the large size.
702
703                 $imgLink          = null;
704                 $avatarMediaLinks = array();
705
706                 foreach ($this->avatarLinks as $a) {
707
708                     // Make a MediaLink for every other Avatar
709                     $avatar = new ActivityStreamsMediaLink(
710                         $a->url,
711                         $a->width,
712                         $a->height,
713                         $a->type,
714                         'avatar'
715                     );
716
717                     // Find the big avatar to use as the "image"
718                     if ($a->height == AVATAR_PROFILE_SIZE) {
719                         $imgLink = $avatar;
720                     }
721
722                     $avatarMediaLinks[] = $avatar->asArray();
723                 }
724
725                 if (!array_key_exists('status_net', $object)) {
726                     $object['status_net'] = array();
727                 }
728
729                 $object['status_net']['avatarLinks'] = $avatarMediaLinks; // extension
730
731                 // image
732                 if (!empty($imgLink)) {
733                     $object['image']  = $imgLink->asArray();
734                 }
735             }
736
737             // objectType
738             //
739             // We can probably use the whole schema URL here but probably the
740             // relative simple name is easier to parse
741
742             $object['objectType'] = ActivityObject::canonicalType($this->type);
743
744             // summary
745             $object['summary'] = $this->summary;
746
747             // summary
748             $object['content'] = $this->content;
749
750             // published (probably don't need. Might be useful for repeats.)
751
752             // updated (probably don't need this)
753
754             // TODO: upstreamDuplicates
755
756             // url (XXX: need to put the right thing here...)
757             $object['url'] = $this->id;
758
759             /* Extensions */
760             // @fixme these may collide with XML extensions
761             // @fixme multiple tags of same name will overwrite each other
762             // @fixme text content from XML extensions will be lost
763
764             foreach ($this->extra as $e) {
765                 list($objectName, $props, $txt) = $e;
766                 if (!empty($objectName)) {
767                     $parts = explode(":", $objectName);
768                     if (count($parts) == 2 && $parts[0] == "statusnet") {
769                         if (!array_key_exists('status_net', $object)) {
770                             $object['status_net'] = array();
771                         }
772                         $object['status_net'][$parts[1]] = $props;
773                     } else {
774                         $object[$objectName] = $props;
775                     }
776                     $object[$objectName] = $props;
777                 }
778             }
779
780             if (!empty($this->geopoint)) {
781
782                 list($lat, $long) = explode(' ', $this->geopoint);
783
784                 $object['geopoint'] = array(
785                     'type'        => 'Point',
786                     'coordinates' => array($lat, $long)
787                 );
788             }
789
790             if (!empty($this->poco)) {
791                 $object['portablecontacts_net'] = array_filter($this->poco->asArray());
792             }
793
794             Event::handle('EndActivityObjectOutputJson', array($this, &$object));
795         }
796         return array_filter($object);
797     }
798
799     static function canonicalType($type) {
800         $ns = 'http://activitystrea.ms/schema/1.0/';
801         if (substr($type, 0, mb_strlen($ns)) == $ns) {
802             return substr($type, mb_strlen($ns));
803         } else {
804             return $type;
805         }
806     }
807 }