PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/activity.php

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