]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/activity.php
7546e2cd432c2fc6f8f82c6ab0402d3cab8e95ef
[quix0rs-gnu-social.git] / lib / activity.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  * An activity in the ActivityStrea.ms world
37  *
38  * An activity is kind of like a sentence: someone did something
39  * to something else.
40  *
41  * 'someone' is the 'actor'; 'did something' is the verb;
42  * 'something else' is the object.
43  *
44  * @category  OStatus
45  * @package   StatusNet
46  * @author    Evan Prodromou <evan@status.net>
47  * @copyright 2010 StatusNet, Inc.
48  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
49  * @link      http://status.net/
50  */
51 class Activity
52 {
53     const SPEC   = 'http://activitystrea.ms/spec/1.0/';
54     const SCHEMA = 'http://activitystrea.ms/schema/1.0/';
55     const MEDIA  = 'http://purl.org/syndication/atommedia';
56
57     const VERB       = 'verb';
58     const OBJECT     = 'object';
59     const ACTOR      = 'actor';
60     const SUBJECT    = 'subject';
61     const OBJECTTYPE = 'object-type';
62     const CONTEXT    = 'context';
63     const TARGET     = 'target';
64
65     const ATOM = 'http://www.w3.org/2005/Atom';
66
67     const AUTHOR    = 'author';
68     const PUBLISHED = 'published';
69     const UPDATED   = 'updated';
70
71     const RSS = null; // no namespace!
72
73     const PUBDATE     = 'pubDate';
74     const DESCRIPTION = 'description';
75     const GUID        = 'guid';
76     const SELF        = 'self';
77     const IMAGE       = 'image';
78     const URL         = 'url';
79
80     const DC = 'http://purl.org/dc/elements/1.1/';
81
82     const CREATOR = 'creator';
83
84     const CONTENTNS = 'http://purl.org/rss/1.0/modules/content/';
85     const ENCODED = 'encoded';
86
87     public $actor;   // an ActivityObject
88     public $verb;    // a string (the URL)
89     public $objects = array();  // an array of ActivityObjects
90     public $target;  // an ActivityObject
91     public $context; // an ActivityObject
92     public $time;    // Time of the activity
93     public $link;    // an ActivityObject
94     public $entry;   // the source entry
95     public $feed;    // the source feed
96
97     public $summary; // summary of activity
98     public $content; // HTML content of activity
99     public $id;      // ID of the activity
100     public $title;   // title of the activity
101     public $categories = array(); // list of AtomCategory objects
102     public $enclosures = array(); // list of enclosure URL references
103     public $attachments = array(); // list of attachments
104
105     public $extra = array(); // extra elements as array(tag, attrs, content)
106     public $source;  // ActivitySource object representing 'home feed'
107     public $selfLink; // <link rel='self' type='application/atom+xml'>
108     public $editLink; // <link rel='edit' type='application/atom+xml'>
109     public $generator; // ActivityObject representing the generating application
110     /**
111      * Turns a regular old Atom <entry> into a magical activity
112      *
113      * @param DOMElement $entry Atom entry to poke at
114      * @param DOMElement $feed  Atom feed, for context
115      */
116     function __construct($entry = null, $feed = null)
117     {
118         if (is_null($entry)) {
119             return;
120         }
121
122         // Insist on a feed's root DOMElement; don't allow a DOMDocument
123         if ($feed instanceof DOMDocument) {
124             throw new ClientException(
125                 // TRANS: Client exception thrown when a feed instance is a DOMDocument.
126                 _('Expecting a root feed element but got a whole XML document.')
127             );
128         }
129
130         $this->entry = $entry;
131         $this->feed  = $feed;
132
133         if ($entry->namespaceURI == Activity::ATOM &&
134             $entry->localName == 'entry') {
135             $this->_fromAtomEntry($entry, $feed);
136         } else if ($entry->namespaceURI == Activity::RSS &&
137                    $entry->localName == 'item') {
138             $this->_fromRssItem($entry, $feed);
139         } else if ($entry->namespaceURI == Activity::SPEC &&
140                    $entry->localName == 'object') {
141             $this->_fromAtomEntry($entry, $feed);
142         } else {
143             // Low level exception. No need for i18n.
144             throw new Exception("Unknown DOM element: {$entry->namespaceURI} {$entry->localName}");
145         }
146     }
147
148     function _fromAtomEntry($entry, $feed)
149     {
150         $pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM);
151
152         if (!empty($pubEl)) {
153             $this->time = strtotime($pubEl->textContent);
154         } else {
155             // XXX technically an error; being liberal. Good idea...?
156             $updateEl = $this->_child($entry, self::UPDATED, self::ATOM);
157             if (!empty($updateEl)) {
158                 $this->time = strtotime($updateEl->textContent);
159             } else {
160                 $this->time = null;
161             }
162         }
163
164         $this->link = ActivityUtils::getPermalink($entry);
165
166         $verbEl = $this->_child($entry, self::VERB);
167
168         if (!empty($verbEl)) {
169             $this->verb = trim($verbEl->textContent);
170         } else {
171             $this->verb = ActivityVerb::POST;
172             // XXX: do other implied stuff here
173         }
174
175         // get immediate object children
176
177         $objectEls = ActivityUtils::children($entry, self::OBJECT, self::SPEC);
178
179         if (count($objectEls) > 0) {
180             foreach ($objectEls as $objectEl) {
181                 // Special case for embedded activities
182                 $objectType = ActivityUtils::childContent($objectEl, self::OBJECTTYPE, self::SPEC);
183                 if (!empty($objectType) && $objectType == ActivityObject::ACTIVITY) {
184                     $this->objects[] = new Activity($objectEl);
185                 } else {
186                     $this->objects[] = new ActivityObject($objectEl);
187                 }
188             }
189         } else {
190             // XXX: really?
191             $this->objects[] = new ActivityObject($entry);
192         }
193
194         $actorEl = $this->_child($entry, self::ACTOR);
195
196         if (!empty($actorEl)) {
197             // Standalone <activity:actor> elements are a holdover from older
198             // versions of ActivityStreams. Newer feeds should have this data
199             // integrated straight into <atom:author>.
200
201             $this->actor = new ActivityObject($actorEl);
202
203             // Cliqset has bad actor IDs (just nickname of user). We
204             // work around it by getting the author data and using its
205             // id instead
206
207             if (!preg_match('/^\w+:/', $this->actor->id)) {
208                 $authorEl = ActivityUtils::child($entry, 'author');
209                 if (!empty($authorEl)) {
210                     $authorObj = new ActivityObject($authorEl);
211                     $this->actor->id = $authorObj->id;
212                 }
213             }
214         } else if ($authorEl = $this->_child($entry, self::AUTHOR, self::ATOM)) {
215
216             // An <atom:author> in the entry overrides any author info on
217             // the surrounding feed.
218             $this->actor = new ActivityObject($authorEl);
219
220         } else if (!empty($feed) &&
221                    $subjectEl = $this->_child($feed, self::SUBJECT)) {
222
223             // Feed subject is used for things like groups.
224             // Should actually possibly not be interpreted as an actor...?
225             $this->actor = new ActivityObject($subjectEl);
226
227         } else if (!empty($feed) && $authorEl = $this->_child($feed, self::AUTHOR,
228                                                               self::ATOM)) {
229
230             // If there's no <atom:author> on the entry, it's safe to assume
231             // the containing feed's authorship info applies.
232             $this->actor = new ActivityObject($authorEl);
233         }
234
235         $contextEl = $this->_child($entry, self::CONTEXT);
236
237         if (!empty($contextEl)) {
238             $this->context = new ActivityContext($contextEl);
239         } else {
240             $this->context = new ActivityContext($entry);
241         }
242
243         $targetEl = $this->_child($entry, self::TARGET);
244
245         if (!empty($targetEl)) {
246             $this->target = new ActivityObject($targetEl);
247         }
248
249         $this->summary = ActivityUtils::childContent($entry, 'summary');
250         $this->id      = ActivityUtils::childContent($entry, 'id');
251         $this->content = ActivityUtils::getContent($entry);
252
253         $catEls = $entry->getElementsByTagNameNS(self::ATOM, 'category');
254         if ($catEls) {
255             for ($i = 0; $i < $catEls->length; $i++) {
256                 $catEl = $catEls->item($i);
257                 $this->categories[] = new AtomCategory($catEl);
258             }
259         }
260
261         foreach (ActivityUtils::getLinks($entry, 'enclosure') as $link) {
262             $this->enclosures[] = $link->getAttribute('href');
263         }
264
265         // From APP. Might be useful.
266
267         $this->selfLink = ActivityUtils::getLink($entry, 'self', 'application/atom+xml');
268         $this->editLink = ActivityUtils::getLink($entry, 'edit', 'application/atom+xml');
269     }
270
271     function _fromRssItem($item, $channel)
272     {
273         $verbEl = $this->_child($item, self::VERB);
274
275         if (!empty($verbEl)) {
276             $this->verb = trim($verbEl->textContent);
277         } else {
278             $this->verb = ActivityVerb::POST;
279             // XXX: do other implied stuff here
280         }
281
282         $pubDateEl = $this->_child($item, self::PUBDATE, self::RSS);
283
284         if (!empty($pubDateEl)) {
285             $this->time = strtotime($pubDateEl->textContent);
286         }
287
288         if ($authorEl = $this->_child($item, self::AUTHOR, self::RSS)) {
289             $this->actor = ActivityObject::fromRssAuthor($authorEl);
290         } else if ($dcCreatorEl = $this->_child($item, self::CREATOR, self::DC)) {
291             $this->actor = ActivityObject::fromDcCreator($dcCreatorEl);
292         } else if ($posterousEl = $this->_child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS)) {
293             // Special case for Posterous.com
294             $this->actor = ActivityObject::fromPosterousAuthor($posterousEl);
295         } else if (!empty($channel)) {
296             $this->actor = ActivityObject::fromRssChannel($channel);
297         } else {
298             // No actor!
299         }
300
301         $this->title = ActivityUtils::childContent($item, ActivityObject::TITLE, self::RSS);
302
303         $contentEl = ActivityUtils::child($item, self::ENCODED, self::CONTENTNS);
304
305         if (!empty($contentEl)) {
306             // <content:encoded> XML node's text content is HTML; no further processing needed.
307             $this->content = $contentEl->textContent;
308         } else {
309             $descriptionEl = ActivityUtils::child($item, self::DESCRIPTION, self::RSS);
310             if (!empty($descriptionEl)) {
311                 // Per spec, <description> must be plaintext.
312                 // In practice, often there's HTML... but these days good
313                 // feeds are using <content:encoded> which is explicitly
314                 // real HTML.
315                 // We'll treat this following spec, and do HTML escaping
316                 // to convert from plaintext to HTML.
317                 $this->content = htmlspecialchars($descriptionEl->textContent);
318             }
319         }
320
321         $this->link = ActivityUtils::childContent($item, ActivityUtils::LINK, self::RSS);
322
323         // @fixme enclosures
324         // @fixme thumbnails... maybe
325
326         $guidEl = ActivityUtils::child($item, self::GUID, self::RSS);
327
328         if (!empty($guidEl)) {
329             $this->id = $guidEl->textContent;
330
331             if ($guidEl->hasAttribute('isPermaLink') && $guidEl->getAttribute('isPermaLink') != 'false') {
332                 // overwrites <link>
333                 $this->link = $this->id;
334             }
335         }
336
337         $this->objects[] = new ActivityObject($item);
338         $this->context   = new ActivityContext($item);
339     }
340
341     /**
342      * Returns an Atom <entry> based on this activity
343      *
344      * @return DOMElement Atom entry
345      */
346
347     function toAtomEntry()
348     {
349         return null;
350     }
351
352     /**
353      * Returns an array based on this activity suitable
354      * for encoding as a JSON object
355      *
356      * @return array $activity
357      */
358
359     function asArray()
360     {
361         $activity = array();
362
363         // actor
364         $activity['actor'] = $this->actor->asArray();
365
366         // content
367         $activity['content'] = $this->content;
368
369         // generator
370
371         if (!empty($this->generator)) {
372             $activity['generator'] = $this->generator->asArray();
373         }
374
375         // icon <-- possibly a mini object representing verb?
376
377         // id
378         $activity['id'] = $this->id;
379
380         // object
381
382         if (count($this->objects) == 0) {
383             common_log(LOG_ERR, "Can't save " . $this->id);
384         } else {
385             if (count($this->objects) > 1) {
386                 common_log(LOG_WARNING, "Ignoring " . (count($this->objects) - 1) . " extra objects in JSON output for activity " . $this->id);
387             }
388             $object = $this->objects[0];
389
390             if ($object instanceof Activity) {
391                 // Sharing a post activity is more like sharing the original object
392                 if (ActivityVerb::canonical($this->verb) == ActivityVerb::canonical(ActivityVerb::SHARE) &&
393                     ActivityVerb::canonical($object->verb) == ActivityVerb::canonical(ActivityVerb::POST)) {
394                     // XXX: Here's one for the obfuscation record books
395                     $object = $object->objects[0];
396                 }
397             }
398
399             $activity['object'] = $object->asArray();
400
401             if ($object instanceof Activity) {
402                 $activity['object']['objectType'] = 'activity';
403             }
404
405             foreach ($this->attachments as $attachment) {
406                 if (empty($activity['object']['attachments'])) {
407                     $activity['object']['attachments'] = array();
408                 }
409                 $activity['object']['attachments'][] = $attachment->asArray();
410             }
411         }
412         
413         // Context stuff.
414
415         if (!empty($this->context)) {
416
417             if (!empty($this->context->location)) {
418                 $loc = $this->context->location;
419
420                 $activity['location'] = array(
421                     'objectType' => 'place',
422                     'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon),
423                     'lat' => $loc->lat,
424                     'lon' => $loc->lon
425                 );
426
427                 $name = $loc->getName();
428
429                 if ($name) {
430                     $activity['location']['displayName'] = $name;
431                 }
432                     
433                 $url = $loc->getURL();
434
435                 if ($url) {
436                     $activity['location']['url'] = $url;
437                 }
438             }
439
440             $activity['to']      = $this->context->getToArray();
441
442             $ctxarr = $this->context->asArray();
443
444             if (array_key_exists('inReplyTo', $ctxarr)) {
445                 $activity['object']['inReplyTo'] = $ctxarr['inReplyTo'];
446                 unset($ctxarr['inReplyTo']);
447             }
448
449             if (!array_key_exists('status_net', $activity)) {
450                 $activity['status_net'] = array();
451             }
452
453             foreach ($ctxarr as $key => $value) {
454                 $activity['status_net'][$key] = $value;
455             }
456         }
457
458         // published
459         $activity['published'] = self::iso8601Date($this->time);
460
461         // provider
462         $provider = array(
463             'objectType' => 'service',
464             'displayName' => common_config('site', 'name'),
465             'url' => common_root_url()
466         );
467
468         $activity['provider'] = $provider;
469
470         // target
471         if (!empty($this->target)) {
472             $activity['target'] = $this->target->asArray();
473         }
474
475         // title
476         $activity['title'] = $this->title;
477
478         // updated <-- Optional. Should we use this to indicate the time we r
479         //             eceived a remote notice? Probably not.
480
481         // verb
482
483         $activity['verb'] = ActivityVerb::canonical($this->verb);
484
485         // url
486         if ($this->link) {
487             $activity['url'] = $this->link;
488         }
489
490         /* Purely extensions hereafter */
491
492         if ($activity['verb'] == 'post') {
493             $tags = array();
494             foreach ($this->categories as $cat) {
495                 if (mb_strlen($cat->term) > 0) {
496                     // Couldn't figure out which object type to use, so...
497                     $tags[] = array('objectType' => 'http://activityschema.org/object/hashtag',
498                                     'displayName' => $cat->term);
499                 }
500             }
501             if (count($tags) > 0) {
502                 $activity['object']['tags'] = $tags;
503             }
504         }
505
506         // XXX: a bit of a hack... Since JSON isn't namespaced we probably
507         // shouldn't be using 'statusnet:notice_info', but this will work
508         // for the moment.
509
510         foreach ($this->extra as $e) {
511             list($objectName, $props, $txt) = $e;
512             if (!empty($objectName)) {
513                 $parts = explode(":", $objectName);
514                 if (count($parts) == 2 && $parts[0] == "statusnet") {
515                     if (!array_key_exists('status_net', $activity)) {
516                         $activity['status_net'] = array();
517                     }
518                     $activity['status_net'][$parts[1]] = $props;
519                 } else {
520                     $activity[$objectName] = $props;
521                 }
522             }
523         }
524
525         return array_filter($activity);
526     }
527
528     function asString($namespace=false, $author=true, $source=false)
529     {
530         $xs = new XMLStringer(true);
531         $this->outputTo($xs, $namespace, $author, $source);
532         return $xs->getString();
533     }
534
535     function outputTo($xs, $namespace=false, $author=true, $source=false, $tag='entry')
536     {
537         if ($namespace) {
538             $attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
539                            'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
540                            'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
541                            'xmlns:georss' => 'http://www.georss.org/georss',
542                            'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
543                            'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
544                            'xmlns:media' => 'http://purl.org/syndication/atommedia',
545                            'xmlns:statusnet' => 'http://status.net/schema/api/1/');
546         } else {
547             $attrs = array();
548         }
549
550         $xs->elementStart($tag, $attrs);
551
552         if ($tag != 'entry') {
553             $xs->element('activity:object-type', null, ActivityObject::ACTIVITY);
554         }
555
556         if ($this->verb == ActivityVerb::POST && count($this->objects) == 1 && $tag == 'entry') {
557
558             $obj = $this->objects[0];
559                         $obj->outputTo($xs, null);
560
561         } else {
562             $xs->element('id', null, $this->id);
563
564             if ($this->title) {
565                 $xs->element('title', null, $this->title);
566             } else {
567                 // Require element
568                 $xs->element('title', null, "");
569             }
570
571             $xs->element('content', array('type' => 'html'), $this->content);
572
573             if (!empty($this->summary)) {
574                 $xs->element('summary', null, $this->summary);
575             }
576
577             if (!empty($this->link)) {
578                 $xs->element('link', array('rel' => 'alternate',
579                                            'type' => 'text/html'),
580                              $this->link);
581             }
582
583         }
584
585         $xs->element('activity:verb', null, $this->verb);
586
587         $published = self::iso8601Date($this->time);
588
589         $xs->element('published', null, $published);
590         $xs->element('updated', null, $published);
591
592         if ($author) {
593             $this->actor->outputTo($xs, 'author');
594         }
595
596         if ($this->verb != ActivityVerb::POST || count($this->objects) != 1 || $tag != 'entry') {
597             foreach($this->objects as $object) {
598                 if ($object instanceof Activity) {
599                     $object->outputTo($xs, false, true, true, 'activity:object');
600                 } else {
601                     $object->outputTo($xs, 'activity:object');
602                 }
603             }
604         }
605
606         if (!empty($this->context)) {
607
608             if (!empty($this->context->replyToID)) {
609                 if (!empty($this->context->replyToUrl)) {
610                     $xs->element('thr:in-reply-to',
611                                  array('ref' => $this->context->replyToID,
612                                        'href' => $this->context->replyToUrl));
613                 } else {
614                     $xs->element('thr:in-reply-to',
615                                  array('ref' => $this->context->replyToID));
616                 }
617             }
618
619             if (!empty($this->context->replyToUrl)) {
620                 $xs->element('link', array('rel' => 'related',
621                                            'href' => $this->context->replyToUrl));
622             }
623
624             if (!empty($this->context->conversation)) {
625                 $xs->element('link', array('rel' => 'ostatus:conversation',
626                                            'href' => $this->context->conversation));
627             }
628
629             foreach ($this->context->attention as $attnURI) {
630                 $xs->element('link', array('rel' => 'ostatus:attention',
631                                            'href' => $attnURI));
632                 $xs->element('link', array('rel' => 'mentioned',
633                                            'href' => $attnURI));
634             }
635
636             // XXX: shoulda used ActivityVerb::SHARE
637
638             if (!empty($this->context->forwardID)) {
639                 if (!empty($this->context->forwardUrl)) {
640                     $xs->element('ostatus:forward',
641                                  array('ref' => $this->context->forwardID,
642                                        'href' => $this->context->forwardUrl));
643                 } else {
644                     $xs->element('ostatus:forward',
645                                  array('ref' => $this->context->forwardID));
646                 }
647             }
648
649             if (!empty($this->context->location)) {
650                 $loc = $this->context->location;
651                 $xs->element('georss:point', null, $loc->lat . ' ' . $loc->lon);
652             }
653         }
654
655         if ($this->target) {
656             $this->target->outputTo($xs, 'activity:target');
657         }
658
659         foreach ($this->categories as $cat) {
660             $cat->outputTo($xs);
661         }
662
663         // can be either URLs or enclosure objects
664
665         foreach ($this->enclosures as $enclosure) {
666             if (is_string($enclosure)) {
667                 $xs->element('link', array('rel' => 'enclosure',
668                                            'href' => $enclosure));
669             } else {
670                 $attributes = array('rel' => 'enclosure',
671                                     'href' => $enclosure->url,
672                                     'type' => $enclosure->mimetype,
673                                     'length' => $enclosure->size);
674                 if ($enclosure->title) {
675                     $attributes['title'] = $enclosure->title;
676                 }
677                 $xs->element('link', $attributes);
678             }
679         }
680
681         // Info on the source feed
682
683         if ($source && !empty($this->source)) {
684             $xs->elementStart('source');
685
686             $xs->element('id', null, $this->source->id);
687             $xs->element('title', null, $this->source->title);
688
689             if (array_key_exists('alternate', $this->source->links)) {
690                 $xs->element('link', array('rel' => 'alternate',
691                                            'type' => 'text/html',
692                                            'href' => $this->source->links['alternate']));
693             }
694
695             if (array_key_exists('self', $this->source->links)) {
696                 $xs->element('link', array('rel' => 'self',
697                                            'type' => 'application/atom+xml',
698                                            'href' => $this->source->links['self']));
699             }
700
701             if (array_key_exists('license', $this->source->links)) {
702                 $xs->element('link', array('rel' => 'license',
703                                            'href' => $this->source->links['license']));
704             }
705
706             if (!empty($this->source->icon)) {
707                 $xs->element('icon', null, $this->source->icon);
708             }
709
710             if (!empty($this->source->updated)) {
711                 $xs->element('updated', null, $this->source->updated);
712             }
713
714             $xs->elementEnd('source');
715         }
716
717         if (!empty($this->selfLink)) {
718             $xs->element('link', array('rel' => 'self',
719                                        'type' => 'application/atom+xml',
720                                        'href' => $this->selfLink));
721         }
722
723         if (!empty($this->editLink)) {
724             $xs->element('link', array('rel' => 'edit',
725                                        'type' => 'application/atom+xml',
726                                        'href' => $this->editLink));
727         }
728
729         // For throwing in extra elements; used for statusnet:notice_info
730
731         foreach ($this->extra as $el) {
732             list($tag, $attrs, $content) = $el;
733             $xs->element($tag, $attrs, $content);
734         }
735
736         $xs->elementEnd($tag);
737
738         return;
739     }
740
741     private function _child($element, $tag, $namespace=self::SPEC)
742     {
743         return ActivityUtils::child($element, $tag, $namespace);
744     }
745
746     /**
747      * For consistency, we'll always output UTC rather than local time.
748      * Note that clients *should* accept any timezone we give them as long
749      * as it's properly formatted.
750      *
751      * @param int $tm Unix timestamp
752      * @return string
753      */
754     static function iso8601Date($tm)
755     {
756         $dateStr = date('d F Y H:i:s', $tm);
757         $d = new DateTime($dateStr, new DateTimeZone('UTC'));
758         return $d->format('c');
759     }
760 }