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