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