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