3 * StatusNet, the distributed open-source microblogging tool
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.
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.
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/>.
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/
31 if (!defined('STATUSNET')) {
39 const VALUE = 'value';
40 const PRIMARY = 'primary';
46 function __construct($type, $value, $primary = false)
49 $this->value = $value;
50 $this->primary = $primary;
55 $xs = new XMLStringer(true);
56 $xs->elementStart('poco:urls');
57 $xs->element('poco:type', null, $this->type);
58 $xs->element('poco:value', null, $this->value);
59 if (!empty($this->primary)) {
60 $xs->element('poco:primary', null, 'true');
62 $xs->elementEnd('poco:urls');
63 return $xs->getString();
69 const ADDRESS = 'address';
70 const FORMATTED = 'formatted';
74 // @todo Other address fields
78 if (!empty($this->formatted)) {
79 $xs = new XMLStringer(true);
80 $xs->elementStart('poco:address');
81 $xs->element('poco:formatted', null, $this->formatted);
82 $xs->elementEnd('poco:address');
83 return $xs->getString();
92 const NS = 'http://portablecontacts.net/spec/1.0';
94 const USERNAME = 'preferredUsername';
95 const DISPLAYNAME = 'displayName';
98 public $preferredUsername;
102 public $urls = array();
104 function __construct($element = null)
106 if (empty($element)) {
110 $this->preferredUsername = ActivityUtils::childContent(
116 $this->displayName = ActivityUtils::childContent(
122 $this->note = ActivityUtils::childContent(
128 $this->address = $this->_getAddress($element);
129 $this->urls = $this->_getURLs($element);
132 private function _getURLs($element)
134 $urlEls = $element->getElementsByTagnameNS(self::NS, PoCoURL::URLS);
137 foreach ($urlEls as $urlEl) {
139 $type = ActivityUtils::childContent(
145 $value = ActivityUtils::childContent(
151 $primary = ActivityUtils::childContent(
159 if (isset($primary) && $primary == 'true') {
163 // @todo check to make sure a primary hasn't already been added
165 array_push($urls, new PoCoURL($type, $value, $isPrimary));
170 private function _getAddress($element)
172 $addressEl = ActivityUtils::child(
174 PoCoAddress::ADDRESS,
178 if (!empty($addressEl)) {
179 $formatted = ActivityUtils::childContent(
181 PoCoAddress::FORMATTED,
185 if (!empty($formatted)) {
186 $address = new PoCoAddress();
187 $address->formatted = $formatted;
195 function fromProfile($profile)
197 if (empty($profile)) {
203 $poco->preferredUsername = $profile->nickname;
204 $poco->displayName = $profile->getBestName();
206 $poco->note = $profile->bio;
208 $paddy = new PoCoAddress();
209 $paddy->formatted = $profile->location;
210 $poco->address = $paddy;
212 if (!empty($profile->homepage)) {
226 function fromGroup($group)
234 $poco->preferredUsername = $group->nickname;
235 $poco->displayName = $group->getBestName();
237 $poco->note = $group->description;
239 $paddy = new PoCoAddress();
240 $paddy->formatted = $group->location;
241 $poco->address = $paddy;
243 if (!empty($group->homepage)) {
257 function getPrimaryURL()
259 foreach ($this->urls as $url) {
268 $xs = new XMLStringer(true);
270 'poco:preferredUsername',
272 $this->preferredUsername
281 if (!empty($this->note)) {
282 $xs->element('poco:note', null, $this->note);
285 if (!empty($this->address)) {
286 $xs->raw($this->address->asString());
289 foreach ($this->urls as $url) {
290 $xs->raw($url->asString());
293 return $xs->getString();
298 * Utilities for turning DOMish things into Activityish things
300 * Some common functions that I didn't have the bandwidth to try to factor
301 * into some kind of reasonable superclass, so just dumped here. Might
302 * be useful to have an ActivityObject parent class or something.
306 * @author Evan Prodromou <evan@status.net>
307 * @copyright 2010 StatusNet, Inc.
308 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
309 * @link http://status.net/
314 const ATOM = 'http://www.w3.org/2005/Atom';
321 const CONTENT = 'content';
325 * Get the permalink for an Activity object
327 * @param DOMElement $element A DOM element
329 * @return string related link, if any
332 static function getPermalink($element)
334 return self::getLink($element, 'alternate', 'text/html');
338 * Get the permalink for an Activity object
340 * @param DOMElement $element A DOM element
342 * @return string related link, if any
345 static function getLink(DOMNode $element, $rel, $type=null)
347 $links = $element->getElementsByTagnameNS(self::ATOM, self::LINK);
349 foreach ($links as $link) {
351 $linkRel = $link->getAttribute(self::REL);
352 $linkType = $link->getAttribute(self::TYPE);
354 if ($linkRel == $rel &&
355 (is_null($type) || $linkType == $type)) {
356 return $link->getAttribute(self::HREF);
364 * Gets the first child element with the given tag
366 * @param DOMElement $element element to pick at
367 * @param string $tag tag to look for
368 * @param string $namespace Namespace to look under
370 * @return DOMElement found element or null
373 static function child(DOMNode $element, $tag, $namespace=self::ATOM)
375 $els = $element->childNodes;
376 if (empty($els) || $els->length == 0) {
379 for ($i = 0; $i < $els->length; $i++) {
380 $el = $els->item($i);
381 if ($el->localName == $tag && $el->namespaceURI == $namespace) {
389 * Grab the text content of a DOM element child of the current element
391 * @param DOMElement $element Element whose children we examine
392 * @param string $tag Tag to look up
393 * @param string $namespace Namespace to use, defaults to Atom
395 * @return string content of the child
398 static function childContent(DOMNode $element, $tag, $namespace=self::ATOM)
400 $el = self::child($element, $tag, $namespace);
405 return $el->textContent;
410 * Get the content of an atom:entry-like object
412 * @param DOMElement $element The element to examine.
414 * @return string unencoded HTML content of the element, like "This -< is <b>HTML</b>."
416 * @todo handle remote content
417 * @todo handle embedded XML mime types
418 * @todo handle base64-encoded non-XML and non-text mime types
421 static function getContent($element)
423 $contentEl = ActivityUtils::child($element, self::CONTENT);
425 if (!empty($contentEl)) {
427 $src = $contentEl->getAttribute(self::SRC);
430 throw new ClientException(_("Can't handle remote content yet."));
433 $type = $contentEl->getAttribute(self::TYPE);
435 // slavishly following http://atompub.org/rfc4287.html#rfc.section.4.1.3.3
437 if ($type == 'text') {
438 return $contentEl->textContent;
439 } else if ($type == 'html') {
440 $text = $contentEl->textContent;
441 return htmlspecialchars_decode($text, ENT_QUOTES);
442 } else if ($type == 'xhtml') {
443 $divEl = ActivityUtils::child($contentEl, 'div');
447 $doc = $divEl->ownerDocument;
449 $children = $divEl->childNodes;
451 for ($i = 0; $i < $children->length; $i++) {
452 $child = $children->item($i);
453 $text .= $doc->saveXML($child);
456 } else if (in_array(array('text/xml', 'application/xml'), $type) ||
457 preg_match('#(+|/)xml$#', $type)) {
458 throw new ClientException(_("Can't handle embedded XML content yet."));
459 } else if (strncasecmp($type, 'text/', 5)) {
460 return $contentEl->textContent;
462 throw new ClientException(_("Can't handle embedded Base64 content yet."));
468 // XXX: Arg! This wouldn't be necessary if we used Avatars conistently
476 static function fromAvatar($avatar)
478 if (empty($avatar)) {
481 $alink = new AvatarLink();
482 $alink->type = $avatar->mediatype;
483 $alink->height = $avatar->mediatype;
484 $alink->width = $avatar->width;
485 $alink->url = $avatar->displayUrl();
489 static function fromFilename($filename, $size)
491 $alink = new AvatarLink();
492 $alink->url = $filename;
493 $alink->height = $size;
494 if (!empty($filename)) {
495 $alink->width = $size;
496 $alink->type = self::mediatype($filename);
498 $alink->url = User_group::defaultLogo($size);
499 $alink->type = 'image/png';
505 static function mediatype($filename) {
506 $ext = strtolower(end(explode('.', $filename)));
507 if ($ext == 'jpeg') {
510 // hope we don't support any others
511 $types = array('png', 'gif', 'jpg', 'jpeg');
512 if (in_array($ext, $types)) {
513 return 'image/' . $ext;
520 * A noun-ish thing in the activity universe
522 * The activity streams spec talks about activity objects, while also having
523 * a tag activity:object, which is in fact an activity object. Aaaaaah!
525 * This is just a thing in the activity universe. Can be the subject, object,
526 * or indirect object (target!) of an activity verb. Rotten name, and I'm
527 * propagating it. *sigh*
531 * @author Evan Prodromou <evan@status.net>
532 * @copyright 2010 StatusNet, Inc.
533 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
534 * @link http://status.net/
539 const ARTICLE = 'http://activitystrea.ms/schema/1.0/article';
540 const BLOGENTRY = 'http://activitystrea.ms/schema/1.0/blog-entry';
541 const NOTE = 'http://activitystrea.ms/schema/1.0/note';
542 const STATUS = 'http://activitystrea.ms/schema/1.0/status';
543 const FILE = 'http://activitystrea.ms/schema/1.0/file';
544 const PHOTO = 'http://activitystrea.ms/schema/1.0/photo';
545 const ALBUM = 'http://activitystrea.ms/schema/1.0/photo-album';
546 const PLAYLIST = 'http://activitystrea.ms/schema/1.0/playlist';
547 const VIDEO = 'http://activitystrea.ms/schema/1.0/video';
548 const AUDIO = 'http://activitystrea.ms/schema/1.0/audio';
549 const BOOKMARK = 'http://activitystrea.ms/schema/1.0/bookmark';
550 const PERSON = 'http://activitystrea.ms/schema/1.0/person';
551 const GROUP = 'http://activitystrea.ms/schema/1.0/group';
552 const PLACE = 'http://activitystrea.ms/schema/1.0/place';
553 const COMMENT = 'http://activitystrea.ms/schema/1.0/comment';
556 // Atom elements we snarf
558 const TITLE = 'title';
559 const SUMMARY = 'summary';
561 const SOURCE = 'source';
565 const EMAIL = 'email';
575 public $avatarLinks = array();
583 * This probably needs to be refactored
584 * to generate a local class (ActivityPerson, ActivityFile, ...)
585 * based on the object type.
587 * @param DOMElement $element DOM thing to turn into an Activity thing
590 function __construct($element = null)
592 if (empty($element)) {
596 $this->element = $element;
598 $this->geopoint = $this->_childContent(
600 ActivityContext::POINT,
601 ActivityContext::GEORSS
604 if ($element->tagName == 'author') {
606 $this->type = self::PERSON; // XXX: is this fair?
607 $this->title = $this->_childContent($element, self::NAME);
608 $this->id = $this->_childContent($element, self::URI);
610 if (empty($this->id)) {
611 $email = $this->_childContent($element, self::EMAIL);
612 if (!empty($email)) {
614 $this->id = 'mailto:'.$email;
620 $this->type = $this->_childContent($element, Activity::OBJECTTYPE,
623 if (empty($this->type)) {
624 $this->type = ActivityObject::NOTE;
627 $this->id = $this->_childContent($element, self::ID);
628 $this->title = $this->_childContent($element, self::TITLE);
629 $this->summary = $this->_childContent($element, self::SUMMARY);
631 $this->source = $this->_getSource($element);
633 $this->content = ActivityUtils::getContent($element);
635 $this->link = ActivityUtils::getPermalink($element);
639 // Some per-type attributes...
640 if ($this->type == self::PERSON || $this->type == self::GROUP) {
641 $this->displayName = $this->title;
643 // @fixme we may have multiple avatars with different resolutions specified
644 $this->avatar = ActivityUtils::getLink($element, 'avatar');
646 $this->poco = new PoCo($element);
650 private function _childContent($element, $tag, $namespace=ActivityUtils::ATOM)
652 return ActivityUtils::childContent($element, $tag, $namespace);
655 // Try to get a unique id for the source feed
657 private function _getSource($element)
659 $sourceEl = ActivityUtils::child($element, 'source');
661 if (empty($sourceEl)) {
664 $href = ActivityUtils::getLink($sourceEl, 'self');
668 return ActivityUtils::childContent($sourceEl, 'id');
673 static function fromNotice($notice)
675 $object = new ActivityObject();
677 $object->type = ActivityObject::NOTE;
679 $object->id = $notice->uri;
680 $object->title = $notice->content;
681 $object->content = $notice->rendered;
682 $object->link = $notice->bestUrl();
687 static function fromProfile($profile)
689 $object = new ActivityObject();
691 $object->type = ActivityObject::PERSON;
692 $object->id = $profile->getUri();
693 $object->title = $profile->getBestName();
694 $object->link = $profile->profileurl;
696 $orig = $profile->getOriginalAvatar();
699 $object->avatarLinks[] = AvatarLink::fromAvatar($orig);
708 foreach ($sizes as $size) {
711 $avatar = $profile->getAvatar($size);
713 if (!empty($avatar)) {
714 $alink = AvatarLink::fromAvatar($avatar);
716 $alink = new AvatarLink();
717 $alink->type = 'image/png';
718 $alink->height = $size;
719 $alink->width = $size;
720 $alink->url = Avatar::defaultImage($size);
723 $object->avatarLinks[] = $alink;
726 if (isset($profile->lat) && isset($profile->lon)) {
727 $object->geopoint = (float)$profile->lat
728 . ' ' . (float)$profile->lon;
731 $object->poco = PoCo::fromProfile($profile);
736 static function fromGroup($group)
738 $object = new ActivityObject();
740 $object->type = ActivityObject::GROUP;
741 $object->id = $group->getUri();
742 $object->title = $group->getBestName();
743 $object->link = $group->getUri();
745 $object->avatarLinks[] = AvatarLink::fromFilename(
746 $group->homepage_logo,
750 $object->avatarLinks[] = AvatarLink::fromFilename(
755 $object->avatarLinks[] = AvatarLink::fromFilename(
760 $object->poco = PoCo::fromGroup($group);
766 function asString($tag='activity:object')
768 $xs = new XMLStringer(true);
770 $xs->elementStart($tag);
772 $xs->element('activity:object-type', null, $this->type);
774 $xs->element(self::ID, null, $this->id);
776 if (!empty($this->title)) {
777 $xs->element(self::TITLE, null, $this->title);
780 if (!empty($this->summary)) {
781 $xs->element(self::SUMMARY, null, $this->summary);
784 if (!empty($this->content)) {
785 // XXX: assuming HTML content here
786 $xs->element(ActivityUtils::CONTENT, array('type' => 'html'), $this->content);
789 if (!empty($this->link)) {
793 'rel' => 'alternate',
794 'type' => 'text/html',
795 'href' => $this->link
801 if ($this->type == ActivityObject::PERSON
802 || $this->type == ActivityObject::GROUP) {
804 foreach ($this->avatarLinks as $avatar) {
808 'type' => $avatar->type,
809 'media:width' => $avatar->width,
810 'media:height' => $avatar->height,
811 'href' => $avatar->url
818 if (!empty($this->geopoint)) {
826 if (!empty($this->poco)) {
827 $xs->raw($this->poco->asString());
830 $xs->elementEnd($tag);
832 return $xs->getString();
837 * Utility class to hold a bunch of constant defining default verb types
841 * @author Evan Prodromou <evan@status.net>
842 * @copyright 2010 StatusNet, Inc.
843 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
844 * @link http://status.net/
849 const POST = 'http://activitystrea.ms/schema/1.0/post';
850 const SHARE = 'http://activitystrea.ms/schema/1.0/share';
851 const SAVE = 'http://activitystrea.ms/schema/1.0/save';
852 const FAVORITE = 'http://activitystrea.ms/schema/1.0/favorite';
853 const PLAY = 'http://activitystrea.ms/schema/1.0/play';
854 const FOLLOW = 'http://activitystrea.ms/schema/1.0/follow';
855 const FRIEND = 'http://activitystrea.ms/schema/1.0/make-friend';
856 const JOIN = 'http://activitystrea.ms/schema/1.0/join';
857 const TAG = 'http://activitystrea.ms/schema/1.0/tag';
859 // Custom OStatus verbs for the flipside until they're standardized
860 const DELETE = 'http://ostatus.org/schema/1.0/unfollow';
861 const UNFAVORITE = 'http://ostatus.org/schema/1.0/unfavorite';
862 const UNFOLLOW = 'http://ostatus.org/schema/1.0/unfollow';
863 const LEAVE = 'http://ostatus.org/schema/1.0/leave';
865 // For simple profile-update pings; no content to share.
866 const UPDATE_PROFILE = 'http://ostatus.org/schema/1.0/update-profile';
869 class ActivityContext
874 public $attention = array();
875 public $conversation;
877 const THR = 'http://purl.org/syndication/thread/1.0';
878 const GEORSS = 'http://www.georss.org/georss';
879 const OSTATUS = 'http://ostatus.org/schema/1.0';
881 const INREPLYTO = 'in-reply-to';
885 const POINT = 'point';
887 const ATTENTION = 'ostatus:attention';
888 const CONVERSATION = 'ostatus:conversation';
890 function __construct($element)
892 $replyToEl = ActivityUtils::child($element, self::INREPLYTO, self::THR);
894 if (!empty($replyToEl)) {
895 $this->replyToID = $replyToEl->getAttribute(self::REF);
896 $this->replyToUrl = $replyToEl->getAttribute(self::HREF);
899 $this->location = $this->getLocation($element);
901 $this->conversation = ActivityUtils::getLink($element, self::CONVERSATION);
903 // Multiple attention links allowed
905 $links = $element->getElementsByTagNameNS(ActivityUtils::ATOM, ActivityUtils::LINK);
907 for ($i = 0; $i < $links->length; $i++) {
909 $link = $links->item($i);
911 $linkRel = $link->getAttribute(ActivityUtils::REL);
913 if ($linkRel == self::ATTENTION) {
914 $this->attention[] = $link->getAttribute(self::HREF);
920 * Parse location given as a GeoRSS-simple point, if provided.
921 * http://www.georss.org/simple
923 * @param feed item $entry
924 * @return mixed Location or false
926 function getLocation($dom)
928 $points = $dom->getElementsByTagNameNS(self::GEORSS, self::POINT);
930 for ($i = 0; $i < $points->length; $i++) {
931 $point = $points->item($i)->textContent;
932 return self::locationFromPoint($point);
938 // XXX: Move to ActivityUtils or Location?
939 static function locationFromPoint($point)
941 $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
942 $point = preg_replace('/\s+/', ' ', $point);
943 $point = trim($point);
944 $coords = explode(' ', $point);
945 if (count($coords) == 2) {
946 list($lat, $lon) = $coords;
947 if (is_numeric($lat) && is_numeric($lon)) {
948 common_log(LOG_INFO, "Looking up location for $lat $lon from georss point");
949 return Location::fromLatLon($lat, $lon);
952 common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
958 * An activity in the ActivityStrea.ms world
960 * An activity is kind of like a sentence: someone did something
963 * 'someone' is the 'actor'; 'did something' is the verb;
964 * 'something else' is the object.
968 * @author Evan Prodromou <evan@status.net>
969 * @copyright 2010 StatusNet, Inc.
970 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
971 * @link http://status.net/
976 const SPEC = 'http://activitystrea.ms/spec/1.0/';
977 const SCHEMA = 'http://activitystrea.ms/schema/1.0/';
980 const OBJECT = 'object';
981 const ACTOR = 'actor';
982 const SUBJECT = 'subject';
983 const OBJECTTYPE = 'object-type';
984 const CONTEXT = 'context';
985 const TARGET = 'target';
987 const ATOM = 'http://www.w3.org/2005/Atom';
989 const AUTHOR = 'author';
990 const PUBLISHED = 'published';
991 const UPDATED = 'updated';
993 public $actor; // an ActivityObject
994 public $verb; // a string (the URL)
995 public $object; // an ActivityObject
996 public $target; // an ActivityObject
997 public $context; // an ActivityObject
998 public $time; // Time of the activity
999 public $link; // an ActivityObject
1000 public $entry; // the source entry
1001 public $feed; // the source feed
1003 public $summary; // summary of activity
1004 public $content; // HTML content of activity
1005 public $id; // ID of the activity
1006 public $title; // title of the activity
1007 public $categories = array(); // list of AtomCategory objects
1010 * Turns a regular old Atom <entry> into a magical activity
1012 * @param DOMElement $entry Atom entry to poke at
1013 * @param DOMElement $feed Atom feed, for context
1016 function __construct($entry = null, $feed = null)
1018 if (is_null($entry)) {
1022 $this->entry = $entry;
1023 $this->feed = $feed;
1025 $pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM);
1027 if (!empty($pubEl)) {
1028 $this->time = strtotime($pubEl->textContent);
1030 // XXX technically an error; being liberal. Good idea...?
1031 $updateEl = $this->_child($entry, self::UPDATED, self::ATOM);
1032 if (!empty($updateEl)) {
1033 $this->time = strtotime($updateEl->textContent);
1039 $this->link = ActivityUtils::getPermalink($entry);
1041 $verbEl = $this->_child($entry, self::VERB);
1043 if (!empty($verbEl)) {
1044 $this->verb = trim($verbEl->textContent);
1046 $this->verb = ActivityVerb::POST;
1047 // XXX: do other implied stuff here
1050 $objectEl = $this->_child($entry, self::OBJECT);
1052 if (!empty($objectEl)) {
1053 $this->object = new ActivityObject($objectEl);
1055 $this->object = new ActivityObject($entry);
1058 $actorEl = $this->_child($entry, self::ACTOR);
1060 if (!empty($actorEl)) {
1062 $this->actor = new ActivityObject($actorEl);
1064 } else if (!empty($feed) &&
1065 $subjectEl = $this->_child($feed, self::SUBJECT)) {
1067 $this->actor = new ActivityObject($subjectEl);
1069 } else if ($authorEl = $this->_child($entry, self::AUTHOR, self::ATOM)) {
1071 $this->actor = new ActivityObject($authorEl);
1073 } else if (!empty($feed) && $authorEl = $this->_child($feed, self::AUTHOR,
1076 $this->actor = new ActivityObject($authorEl);
1079 $contextEl = $this->_child($entry, self::CONTEXT);
1081 if (!empty($contextEl)) {
1082 $this->context = new ActivityContext($contextEl);
1084 $this->context = new ActivityContext($entry);
1087 $targetEl = $this->_child($entry, self::TARGET);
1089 if (!empty($targetEl)) {
1090 $this->target = new ActivityObject($targetEl);
1093 $this->summary = ActivityUtils::childContent($entry, 'summary');
1094 $this->id = ActivityUtils::childContent($entry, 'id');
1095 $this->content = ActivityUtils::getContent($entry);
1097 $catEls = $entry->getElementsByTagNameNS(self::ATOM, 'category');
1099 for ($i = 0; $i < $catEls->length; $i++) {
1100 $catEl = $catEls->item($i);
1101 $this->categories[] = new AtomCategory($catEl);
1107 * Returns an Atom <entry> based on this activity
1109 * @return DOMElement Atom entry
1112 function toAtomEntry()
1117 function asString($namespace=false)
1119 $xs = new XMLStringer(true);
1122 $attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
1123 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
1124 'xmlns:georss' => 'http://www.georss.org/georss',
1125 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
1126 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
1127 'xmlns:media' => 'http://purl.org/syndication/atommedia');
1132 $xs->elementStart('entry', $attrs);
1134 $xs->element('id', null, $this->id);
1135 $xs->element('title', null, $this->title);
1136 $xs->element('published', null, common_date_iso8601($this->time));
1137 $xs->element('content', array('type' => 'html'), $this->content);
1139 if (!empty($this->summary)) {
1140 $xs->element('summary', null, $this->summary);
1143 if (!empty($this->link)) {
1144 $xs->element('link', array('rel' => 'alternate',
1145 'type' => 'text/html'),
1151 $xs->elementStart('author');
1152 $xs->element('uri', array(), $this->actor->id);
1153 if ($this->actor->title) {
1154 $xs->element('name', array(), $this->actor->title);
1156 $xs->elementEnd('author');
1157 $xs->raw($this->actor->asString('activity:actor'));
1159 $xs->element('activity:verb', null, $this->verb);
1161 if ($this->object) {
1162 $xs->raw($this->object->asString());
1165 if ($this->target) {
1166 $xs->raw($this->target->asString('activity:target'));
1169 foreach ($this->categories as $cat) {
1170 $xs->raw($cat->asString());
1173 $xs->elementEnd('entry');
1175 return $xs->getString();
1178 private function _child($element, $tag, $namespace=self::SPEC)
1180 return ActivityUtils::child($element, $tag, $namespace);
1190 function __construct($element=null)
1192 if ($element && $element->attributes) {
1193 $this->term = $this->extract($element, 'term');
1194 $this->scheme = $this->extract($element, 'scheme');
1195 $this->label = $this->extract($element, 'label');
1199 protected function extract($element, $attrib)
1201 $node = $element->attributes->getNamedItemNS(Activity::ATOM, $attrib);
1203 return trim($node->textContent);
1205 $node = $element->attributes->getNamedItem($attrib);
1207 return trim($node->textContent);
1215 if ($this->term !== null) {
1216 $attribs['term'] = $this->term;
1218 if ($this->scheme !== null) {
1219 $attribs['scheme'] = $this->scheme;
1221 if ($this->label !== null) {
1222 $attribs['label'] = $this->label;
1224 $xs = new XMLStringer();
1225 $xs->element('category', $attribs);
1226 return $xs->asString();