/**
  * Constructor
  *
  * @param Group   $group   the group for the feed
  * @param User    $cur     the current authenticated user, if any
  * @param boolean $indent  flag to turn indenting on or off
  *
  * @return void
  */
 function __construct($group, $cur = null, $indent = true)
 {
     parent::__construct($cur, $indent);
     $this->group = $group;
     // TRANS: Title in atom group notice feed. %s is a group name.
     $title = sprintf(_("%s timeline"), $group->nickname);
     $this->setTitle($title);
     $sitename = common_config('site', 'name');
     $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $group->nickname, $sitename);
     $this->setSubtitle($subtitle);
     $avatar = $group->homepage_logo;
     $logo = $avatar ? $avatar : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
     $this->setLogo($logo);
     $this->setUpdated('now');
     $self = common_local_url('ApiTimelineGroup', array('id' => $group->id, 'format' => 'atom'));
     $this->setId($self);
     $this->setSelfLink($self);
     // For groups, we generate an author _AND_ an <activity:subject>
     // Versions of StatusNet under 0.9.7 treat <author> as a person
     // XXX: remove this workaround in future versions
     $ao = ActivityObject::fromGroup($group);
     $this->addAuthorRaw($ao->asString('author'));
     $depMsg = 'Deprecation warning: activity:subject is present ' . 'only for backward compatibility. It will be ' . 'removed in the next version of StatusNet.';
     $this->addAuthorRaw("<!--{$depMsg}-->\n" . $ao->asString('activity:subject'));
     $this->addLink($group->homeUrl());
 }
 /**
  * Constructor
  *
  * @param User    $user    the user for the feed
  * @param User    $cur     the current authenticated user, if any
  * @param boolean $indent  flag to turn indenting on or off
  *
  * @return void
  */
 function __construct($user, $cur = null, $indent = true)
 {
     parent::__construct($cur, $indent);
     $this->user = $user;
     if (!empty($user)) {
         $profile = $user->getProfile();
         $ao = ActivityObject::fromProfile($profile);
         array_push($ao->extra, $profile->profileInfo($cur));
         // XXX: For users, we generate an author _AND_ an <activity:subject>
         // This is for backward compatibility with clients (especially
         // StatusNet's clients) that assume the Atom will conform to an
         // older version of the Activity Streams API. Subject should be
         // removed in future versions of StatusNet.
         $this->addAuthorRaw($ao->asString('author'));
         $depMsg = 'Deprecation warning: activity:subject is present ' . 'only for backward compatibility. It will be ' . 'removed in the next version of StatusNet.';
         $this->addAuthorRaw("<!--{$depMsg}-->\n" . $ao->asString('activity:subject'));
     }
     // TRANS: Title in atom user notice feed. %s is a user name.
     $title = sprintf(_("%s timeline"), $user->nickname);
     $this->setTitle($title);
     $sitename = common_config('site', 'name');
     $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $user->nickname, $sitename);
     $this->setSubtitle($subtitle);
     $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
     $logo = $avatar ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE);
     $this->setLogo($logo);
     $this->setUpdated('now');
     $this->addLink(common_local_url('showstream', array('nickname' => $user->nickname)));
     $self = common_local_url('ApiTimelineUser', array('id' => $user->id, 'format' => 'atom'));
     $this->setId($self);
     $this->setSelfLink($self);
     $this->addLink(common_local_url('sup', null, null, $user->id), array('rel' => 'http://api.friendfeed.com/2008/03#sup', 'type' => 'application/json'));
 }
 public function activityObjectFromNotice(Notice $notice)
 {
     $object = new ActivityObject();
     $object->type = $notice->object_type ?: ActivityObject::NOTE;
     $object->id = $notice->getUri();
     $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
     $object->content = $notice->getRendered();
     $object->link = $notice->getUrl();
     $object->extra[] = array('status_net', array('notice_id' => $notice->getID()));
     return $object;
 }
 /**
  * Constructor
  *
  * @param Group   $group   the group for the feed
  * @param User    $cur     the current authenticated user, if any
  * @param boolean $indent  flag to turn indenting on or off
  *
  * @return void
  */
 function __construct($group, $cur = null, $indent = true)
 {
     parent::__construct($cur, $indent);
     $this->group = $group;
     // TRANS: Title in atom group notice feed. %s is a group name.
     $title = sprintf(_("%s timeline"), $group->nickname);
     $this->setTitle($title);
     $sitename = common_config('site', 'name');
     $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $group->nickname, $sitename);
     $this->setSubtitle($subtitle);
     $avatar = $group->homepage_logo;
     $logo = $avatar ? $avatar : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
     $this->setLogo($logo);
     $this->setUpdated('now');
     $self = common_local_url('ApiTimelineGroup', array('id' => $group->id, 'format' => 'atom'));
     $this->setId($self);
     $this->setSelfLink($self);
     $ao = ActivityObject::fromGroup($group);
     $this->addAuthorRaw($ao->asString('author'));
     $this->addLink($group->homeUrl());
 }
 /**
  * Constructor
  *
  * @param List    $list    the list for the feed
  * @param User    $cur     the current authenticated user, if any
  * @param boolean $indent  flag to turn indenting on or off
  *
  * @return void
  */
 function __construct($list, $cur = null, $indent = true)
 {
     parent::__construct($cur, $indent);
     $this->list = $list;
     $this->tagger = Profile::getKV('id', $list->tagger);
     // TRANS: Title in atom list notice feed. %1$s is a list name, %2$s is a tagger's nickname.
     $title = sprintf(_('Timeline for people in list %1$s by %2$s'), $list->tag, $this->tagger->nickname);
     $this->setTitle($title);
     $sitename = common_config('site', 'name');
     $subtitle = sprintf(_('Updates from %1$s\'s list %2$s on %3$s!'), $this->tagger->nickname, $list->tag, $sitename);
     $this->setSubtitle($subtitle);
     $avatar = $this->tagger->avatarUrl(AVATAR_PROFILE_SIZE);
     $this->setLogo($avatar);
     $this->setUpdated('now');
     $self = common_local_url('ApiTimelineList', array('user' => $this->tagger->nickname, 'id' => $list->tag, 'format' => 'atom'));
     $this->setId($self);
     $this->setSelfLink($self);
     $ao = ActivityObject::fromPeopletag($this->list);
     $this->addAuthorRaw($ao->asString('author'));
     $this->addLink($this->list->getUri());
 }
Example #6
0
 function asActivity()
 {
     $notice = Notice::staticGet('id', $this->notice_id);
     if (!$notice) {
         throw new Exception("Fave for non-existent notice: " . $this->notice_id);
     }
     $profile = Profile::staticGet('id', $this->user_id);
     if (!$profile) {
         throw new Exception("Fave by non-existent profile: " . $this->user_id);
     }
     $act = new Activity();
     $act->verb = ActivityVerb::FAVORITE;
     // FIXME: rationalize this with URL below
     $act->id = $this->getURI();
     $act->time = strtotime($this->modified);
     // TRANS: Activity title when marking a notice as favorite.
     $act->title = _("Favor");
     // TRANS: Ntofication given when a user marks a notice as favorite.
     // TRANS: %1$s is a user nickname or full name, %2$s is a notice URI.
     $act->content = sprintf(_('%1$s marked notice %2$s as a favorite.'), $profile->getBestName(), $notice->uri);
     $act->actor = ActivityObject::fromProfile($profile);
     $act->objects[] = ActivityObject::fromNotice($notice);
     $url = common_local_url('AtomPubShowFavorite', array('profile' => $this->user_id, 'notice' => $this->notice_id));
     $act->selfLink = $url;
     $act->editLink = $url;
     return $act;
 }
Example #7
0
 public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped = null)
 {
     switch ($stored->verb) {
         case ActivityVerb::UNFAVORITE:
             // FIXME: do something here
             break;
         case ActivityVerb::JOIN:
             $mem = Group_member::getKV('uri', $stored->getUri());
             if ($mem instanceof Group_member) {
                 $group = $mem->getGroup();
                 $act->title = $stored->getTitle();
                 $act->objects = array(ActivityObject::fromGroup($group));
             }
             break;
         case ActivityVerb::LEAVE:
             // FIXME: ????
             break;
         case ActivityVerb::FOLLOW:
             $sub = Subscription::getKV('uri', $stored->uri);
             if ($sub instanceof Subscription) {
                 $profile = Profile::getKV('id', $sub->subscribed);
                 if ($profile instanceof Profile) {
                     $act->title = $stored->getTitle();
                     $act->objects = array($profile->asActivityObject());
                 }
             }
             break;
         case ActivityVerb::UNFOLLOW:
             // FIXME: ????
             break;
     }
     return true;
 }
 /**
  * Ping remote profiles with updates to this profile.
  * Salmon pings are queued for background processing.
  */
 function onEndBroadcastProfile(Profile $profile)
 {
     $user = User::staticGet('id', $profile->id);
     // Find foreign accounts I'm subscribed to that support Salmon pings.
     //
     // @fixme we could run updates through the PuSH feed too,
     // in which case we can skip Salmon pings to folks who
     // are also subscribed to me.
     $sql = "SELECT * FROM ostatus_profile " . "WHERE profile_id IN " . "(SELECT subscribed FROM subscription WHERE subscriber=%d) " . "OR group_id IN " . "(SELECT group_id FROM group_member WHERE profile_id=%d)";
     $oprofile = new Ostatus_profile();
     $oprofile->query(sprintf($sql, $profile->id, $profile->id));
     if ($oprofile->N == 0) {
         common_log(LOG_DEBUG, "No OStatus remote subscribees for {$profile->nickname}");
         return true;
     }
     $act = new Activity();
     $act->verb = ActivityVerb::UPDATE_PROFILE;
     $act->id = TagURI::mint('update-profile:%d:%s', $profile->id, common_date_iso8601(time()));
     $act->time = time();
     // TRANS: Title for activity.
     $act->title = _m('Profile update');
     // TRANS: Ping text for remote profile update through OStatus.
     // TRANS: %s is user that updated their profile.
     $act->content = sprintf(_m('%s has updated their profile page.'), $profile->getBestName());
     $act->actor = ActivityObject::fromProfile($profile);
     $act->object = $act->actor;
     while ($oprofile->fetch()) {
         $oprofile->notifyDeferred($act, $profile);
     }
     return true;
 }
 function asActivity()
 {
     $subscriber = Profile::staticGet('id', $this->subscriber);
     $subscribed = Profile::staticGet('id', $this->subscribed);
     $act = new Activity();
     $act->verb = ActivityVerb::FOLLOW;
     // XXX: rationalize this with the URL
     $act->id = TagURI::mint('follow:%d:%d:%s', $subscriber->id, $subscribed->id, common_date_iso8601($this->created));
     $act->time = strtotime($this->created);
     // TRANS: Activity title when subscribing to another person.
     $act->title = _m('TITLE', 'Follow');
     // TRANS: Notification given when one person starts following another.
     // TRANS: %1$s is the subscriber, %2$s is the subscribed.
     $act->content = sprintf(_('%1$s is now following %2$s.'), $subscriber->getBestName(), $subscribed->getBestName());
     $act->actor = ActivityObject::fromProfile($subscriber);
     $act->objects[] = ActivityObject::fromProfile($subscribed);
     $url = common_local_url('AtomPubShowSubscription', array('subscriber' => $subscriber->id, 'subscribed' => $subscribed->id));
     $act->selfLink = $url;
     $act->editLink = $url;
     return $act;
 }
Example #10
0
 function asArray()
 {
     $object = array();
     if (Event::handle('StartActivityObjectOutputJson', array($this, &$object))) {
         // XXX: attachments are added by Activity
         // author (Add object for author? Could be useful for repeats.)
         // content (Add rendered version of the notice?)
         // displayName
         if ($this->title) {
             $object['displayName'] = $this->title;
         }
         // downstreamDuplicates
         // id
         if ($this->id) {
             $object['id'] = $this->id;
         } else {
             if ($this->link) {
                 $object['id'] = $this->link;
             }
         }
         if ($this->type == ActivityObject::PERSON || $this->type == ActivityObject::GROUP) {
             // XXX: Not sure what the best avatar is to use for the
             // author's "image". For now, I'm using the large size.
             $imgLink = null;
             $avatarMediaLinks = array();
             foreach ($this->avatarLinks as $a) {
                 // Make a MediaLink for every other Avatar
                 $avatar = new ActivityStreamsMediaLink($a->url, $a->width, $a->height, $a->type, 'avatar');
                 // Find the big avatar to use as the "image"
                 if ($a->height == AVATAR_PROFILE_SIZE) {
                     $imgLink = $avatar;
                 }
                 $avatarMediaLinks[] = $avatar->asArray();
             }
             if (!array_key_exists('status_net', $object)) {
                 $object['status_net'] = array();
             }
             $object['status_net']['avatarLinks'] = $avatarMediaLinks;
             // extension
             // image
             if (!empty($imgLink)) {
                 $object['image'] = $imgLink->asArray();
             }
         }
         // objectType
         //
         // We can probably use the whole schema URL here but probably the
         // relative simple name is easier to parse
         $object['objectType'] = ActivityObject::canonicalType($this->type);
         // summary
         $object['summary'] = $this->summary;
         // content
         $object['content'] = $this->content;
         // published (probably don't need. Might be useful for repeats.)
         // updated (probably don't need this)
         // TODO: upstreamDuplicates
         if ($this->link) {
             $object['url'] = $this->link;
         }
         /* Extensions */
         // @fixme these may collide with XML extensions
         // @fixme multiple tags of same name will overwrite each other
         // @fixme text content from XML extensions will be lost
         foreach ($this->extra as $e) {
             list($objectName, $props, $txt) = $e;
             if (!empty($objectName)) {
                 $parts = explode(":", $objectName);
                 if (count($parts) == 2 && $parts[0] == "statusnet") {
                     if (!array_key_exists('status_net', $object)) {
                         $object['status_net'] = array();
                     }
                     $object['status_net'][$parts[1]] = $props;
                 } else {
                     $object[$objectName] = $props;
                 }
             }
         }
         if (!empty($this->geopoint)) {
             list($lat, $lon) = explode(' ', $this->geopoint);
             $object['location'] = array('objectType' => 'place', 'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon), 'lat' => $lat, 'lon' => $lon);
             $loc = Location::fromLatLon($lat, $lon);
             if ($loc) {
                 $name = $loc->getName();
                 if ($name) {
                     $object['location']['displayName'] = $name;
                 }
                 $url = $loc->getURL();
                 if ($url) {
                     $object['location']['url'] = $url;
                 }
             }
         }
         if (!empty($this->poco)) {
             $object['portablecontacts_net'] = array_filter($this->poco->asArray());
         }
         if (!empty($this->thumbnail)) {
             if (is_string($this->thumbnail)) {
                 $object['image'] = array('url' => $this->thumbnail);
             } else {
                 $object['image'] = array('url' => $this->thumbnail->url);
                 if ($this->thumbnail->width) {
                     $object['image']['width'] = $this->thumbnail->width;
                 }
                 if ($this->thumbnail->height) {
                     $object['image']['height'] = $this->thumbnail->height;
                 }
             }
         }
         switch (ActivityObject::canonicalType($this->type)) {
             case 'image':
                 if (!empty($this->largerImage)) {
                     $object['fullImage'] = array('url' => $this->largerImage);
                 }
                 break;
             case 'audio':
             case 'video':
                 if (!empty($this->stream)) {
                     $object['stream'] = array('url' => $this->stream);
                 }
                 break;
         }
         Event::handle('EndActivityObjectOutputJson', array($this, &$object));
     }
     return array_filter($object);
 }
Example #11
0
 /**
  * Look up and, if necessary, create an Ostatus_profile for the remote
  * profile with the given RSS feed - actually loaded from the feed.
  * This should never return null -- you will either get an object or
  * an exception will be thrown.
  *
  * @param DOMElement $feedEl root element of a loaded RSS feed
  * @param array $hints additional discovery information passed from higher levels
  * @todo FIXME: Should this be marked public?
  * @return Ostatus_profile
  * @throws Exception
  */
 public static function ensureRssChannel(DOMElement $feedEl, array $hints)
 {
     // Special-case for Posterous. They have some nice metadata in their
     // posterous:author elements. We should use them instead of the channel.
     $items = $feedEl->getElementsByTagName('item');
     if ($items->length > 0) {
         $item = $items->item(0);
         $authorEl = ActivityUtils::child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS);
         if (!empty($authorEl)) {
             $obj = ActivityObject::fromPosterousAuthor($authorEl);
             // Posterous has multiple authors per feed, and multiple feeds
             // per author. We check if this is the "main" feed for this author.
             if (array_key_exists('profileurl', $hints) && !empty($obj->poco) && common_url_to_nickname($hints['profileurl']) == $obj->poco->preferredUsername) {
                 return self::ensureActivityObjectProfile($obj, $hints);
             }
         }
     }
     $obj = ActivityUtils::getFeedAuthor($feedEl);
     // @todo FIXME: We should check whether this feed has elements
     // with different <author> or <dc:creator> elements, and... I dunno.
     // Do something about that.
     if (empty($obj)) {
         $obj = ActivityObject::fromRssChannel($feedEl);
     }
     return self::ensureActivityObjectProfile($obj, $hints);
 }
Example #12
0
 public function asActivityObject()
 {
     $object = new ActivityObject();
     if (Event::handle('StartActivityObjectFromNotice', array($this, &$object))) {
         $object->type = $this->object_type ?: ActivityObject::NOTE;
         $object->id = $this->getUri();
         //FIXME: = $object->title ?: sprintf(... because we might get a title from StartActivityObjectFromNotice
         $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $this->getProfile()->getNickname());
         $object->content = $this->getRendered();
         $object->link = $this->getUrl();
         $object->extra[] = array('status_net', array('notice_id' => $this->id));
         Event::handle('EndActivityObjectFromNotice', array($this, &$object));
     }
     return $object;
 }
Example #13
0
 /**
  * Returns an array of arrays representing Activity Objects (intended to be
  * serialized in JSON) that represent WHO the Activity is supposed to
  * be received by. This is not really specified but appears in an example
  * of the current spec as an extension. We might want to figure out a JSON
  * serialization for OStatus and use that to express mentions instead.
  *
  * XXX: People's ideas on how to do this are all over the place
  *
  * @return array the array of recipients
  */
 function getToArray()
 {
     $tos = array();
     foreach ($this->attention as $attnUrl) {
         if (array_key_exists($attnUrl, $this->attentionType)) {
             $type = ActivityObject::canonicalType($this->attentionType[$attnUrl]);
         } else {
             $type = ActivityObject::canonicalType(ActivityObject::PERSON);
         }
         $to = array('objectType' => $type, 'id' => $attnUrl);
         $tos[] = $to;
     }
     return $tos;
 }
Example #14
0
 /**
  * Notify remote user that a people tag has been removed
  *   - untag verb is queued
  *   - the subscription is undone immediately if not required
  *     i.e garbageCollect()'d
  *
  * @param Profile_tag $ptag the people tag that was deleted
  * @return hook return value
  */
 function onEndUntagProfile($ptag)
 {
     $oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
     if (!$oprofile instanceof Ostatus_profile) {
         return true;
     }
     $plist = $ptag->getMeta();
     if ($plist->private) {
         return true;
     }
     $act = new Activity();
     $tagger = $plist->getTagger();
     $tagged = Profile::getKV('id', $ptag->tagged);
     $act->verb = ActivityVerb::UNTAG;
     $act->id = TagURI::mint('untag_profile:%d:%d:%s', $plist->tagger, $plist->id, common_date_iso8601(time()));
     $act->time = time();
     // TRANS: Title for unlisting a remote profile.
     $act->title = _m('TITLE', 'Unlist');
     // TRANS: Success message for remote list removal through OStatus.
     // TRANS: %1$s is the list creator's name, %2$s is the removed list member, %3$s is the list name.
     $act->content = sprintf(_m('%1$s removed %2$s from the list %3$s.'), $tagger->getBestName(), $tagged->getBestName(), $plist->getBestName());
     $act->actor = $tagger->asActivityObject();
     $act->objects = array($tagged->asActivityObject());
     $act->target = ActivityObject::fromPeopletag($plist);
     $oprofile->notifyDeferred($act, $tagger);
     // unsubscribe to PuSH feed if no more required
     $oprofile->garbageCollect();
     return true;
 }
<?php
session_start();

require_once "../src/apiClient.php";

$apiClient = new apiClient();
$client->setApplicationName("BuzzDiscoveryCreatePost_Example_App");
$apiClient->discover('buzz');
$apiClient->authenticate();

if (isset($_SESSION['oauth_access_token'])) {
  $apiClient->setAccessToken($_SESSION['oauth_access_token']);
} else {
  $token = $apiClient->authenticate();
  $_SESSION['oauth_access_token'] = $token;
}

$activityObj = new ActivityObject();
$activityObj->setContent('Testing the Google API PHP Client library');
$activityObj->setType('note');

$activity = new Activity();
$activity->setObject($activityObj);

$newPost = $buzz->activities->insert('@me', $activity);

echo "<pre>post created:\n".print_r($newPost, true)."\n</pre>";
 function onEndNoticeAsActivity($notice, &$activity)
 {
     switch ($notice->verb) {
         case ActivityVerb::FAVORITE:
             $fave = Fave::staticGet('uri', $notice->uri);
             if (!empty($fave)) {
                 $notice = Notice::staticGet('id', $fave->notice_id);
                 if (!empty($notice)) {
                     $cur = common_current_user();
                     $target = $notice->asActivity($cur);
                     if ($target->verb == ActivityVerb::POST) {
                         // "I like the thing you posted"
                         $activity->objects = $target->objects;
                     } else {
                         // "I like that you did whatever you did"
                         $activity->objects = array($target);
                     }
                 }
             }
             break;
         case ActivityVerb::UNFAVORITE:
             // FIXME: do something here
             break;
         case ActivityVerb::JOIN:
             $mem = Group_member::staticGet('uri', $notice->uri);
             if (!empty($mem)) {
                 $group = $mem->getGroup();
                 $activity->objects = array(ActivityObject::fromGroup($group));
             }
             break;
         case ActivityVerb::LEAVE:
             // FIXME: ????
             break;
         case ActivityVerb::FOLLOW:
             $sub = Subscription::staticGet('uri', $notice->uri);
             if (!empty($sub)) {
                 $profile = Profile::staticGet('id', $sub->subscribed);
                 if (!empty($profile)) {
                     $activity->objects = array(ActivityObject::fromProfile($profile));
                 }
             }
             break;
         case ActivityVerb::UNFOLLOW:
             // FIXME: ????
             break;
     }
     return true;
 }
Example #17
0
 function asActivity()
 {
     $act = new Activity();
     if (Event::handle('StartMessageAsActivity', array($this, &$act))) {
         $act->id = TagURI::mint(sprintf('activity:message:%d', $this->id));
         $act->time = strtotime($this->created);
         $act->link = $this->url;
         $profile = Profile::getKV('id', $this->from_profile);
         if (empty($profile)) {
             throw new Exception(sprintf("Sender profile not found: %d", $this->from_profile));
         }
         $act->actor = $profile->asActivityObject();
         $act->actor->extra[] = $profile->profileInfo();
         $act->verb = ActivityVerb::POST;
         $act->objects[] = ActivityObject::fromMessage($this);
         $ctx = new ActivityContext();
         $rprofile = Profile::getKV('id', $this->to_profile);
         if (empty($rprofile)) {
             throw new Exception(sprintf("Receiver profile not found: %d", $this->to_profile));
         }
         $ctx->attention[$rprofile->getUri()] = ActivityObject::PERSON;
         $act->context = $ctx;
         $source = $this->getSource();
         if ($source instanceof Notice_source) {
             $act->generator = ActivityObject::fromNoticeSource($source);
         }
         Event::handle('EndMessageAsActivity', array($this, &$act));
     }
     return $act;
 }
Example #18
0
 function asActivity()
 {
     $subscriber = Profile::staticGet('id', $this->subscriber);
     $subscribed = Profile::staticGet('id', $this->subscribed);
     $act = new Activity();
     $act->verb = ActivityVerb::FOLLOW;
     $act->id = TagURI::mint('follow:%d:%d:%s', $subscriber->id, $subscribed->id, common_date_iso8601($this->created));
     $act->time = strtotime($this->created);
     // TRANS: Activity tile when subscribing to another person.
     $act->title = _("Follow");
     // TRANS: Notification given when one person starts following another.
     // TRANS: %1$s is the subscriber, %2$s is the subscribed.
     $act->content = sprintf(_('%1$s is now following %2$s.'), $subscriber->getBestName(), $subscribed->getBestName());
     $act->actor = ActivityObject::fromProfile($subscriber);
     $act->objects[] = ActivityObject::fromProfile($subscribed);
     return $act;
 }
Example #19
0
 function _fromRssItem($item, $channel)
 {
     $verbEl = $this->_child($item, self::VERB);
     if (!empty($verbEl)) {
         $this->verb = trim($verbEl->textContent);
     } else {
         $this->verb = ActivityVerb::POST;
         // XXX: do other implied stuff here
     }
     $pubDateEl = $this->_child($item, self::PUBDATE, self::RSS);
     if (!empty($pubDateEl)) {
         $this->time = strtotime($pubDateEl->textContent);
     }
     if ($authorEl = $this->_child($item, self::AUTHOR, self::RSS)) {
         $this->actor = ActivityObject::fromRssAuthor($authorEl);
     } else {
         if ($dcCreatorEl = $this->_child($item, self::CREATOR, self::DC)) {
             $this->actor = ActivityObject::fromDcCreator($dcCreatorEl);
         } else {
             if ($posterousEl = $this->_child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS)) {
                 // Special case for Posterous.com
                 $this->actor = ActivityObject::fromPosterousAuthor($posterousEl);
             } else {
                 if (!empty($channel)) {
                     $this->actor = ActivityObject::fromRssChannel($channel);
                 } else {
                     // No actor!
                 }
             }
         }
     }
     $this->title = ActivityUtils::childContent($item, ActivityObject::TITLE, self::RSS);
     $contentEl = ActivityUtils::child($item, self::ENCODED, self::CONTENTNS);
     if (!empty($contentEl)) {
         // <content:encoded> XML node's text content is HTML; no further processing needed.
         $this->content = $contentEl->textContent;
     } else {
         $descriptionEl = ActivityUtils::child($item, self::DESCRIPTION, self::RSS);
         if (!empty($descriptionEl)) {
             // Per spec, <description> must be plaintext.
             // In practice, often there's HTML... but these days good
             // feeds are using <content:encoded> which is explicitly
             // real HTML.
             // We'll treat this following spec, and do HTML escaping
             // to convert from plaintext to HTML.
             $this->content = htmlspecialchars($descriptionEl->textContent);
         }
     }
     $this->link = ActivityUtils::childContent($item, ActivityUtils::LINK, self::RSS);
     // @fixme enclosures
     // @fixme thumbnails... maybe
     $guidEl = ActivityUtils::child($item, self::GUID, self::RSS);
     if (!empty($guidEl)) {
         $this->id = $guidEl->textContent;
         if ($guidEl->hasAttribute('isPermaLink') && $guidEl->getAttribute('isPermaLink') != 'false') {
             // overwrites <link>
             $this->link = $this->id;
         }
     }
     $this->objects[] = new ActivityObject($item);
     $this->context = new ActivityContext($item);
 }
Example #20
0
 function asActivity()
 {
     $member = $this->getMember();
     if (!$member) {
         throw new Exception("No such member: " . $this->profile_id);
     }
     $group = $this->getGroup();
     if (!$group) {
         throw new Exception("No such group: " . $this->group_id);
     }
     $act = new Activity();
     $act->id = $this->getURI();
     $act->actor = $member->asActivityObject();
     $act->verb = ActivityVerb::JOIN;
     $act->objects[] = ActivityObject::fromGroup($group);
     $act->time = strtotime($this->created);
     // TRANS: Activity title.
     $act->title = _("Join");
     // TRANS: Success message for subscribe to group attempt through OStatus.
     // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
     $act->content = sprintf(_('%1$s has joined group %2$s.'), $member->getBestName(), $group->getBestName());
     $url = common_local_url('AtomPubShowMembership', array('profile' => $member->id, 'group' => $group->id));
     $act->selfLink = $url;
     $act->editLink = $url;
     return $act;
 }
Example #21
0
 /**
  * @param ActivityObject $actobj The _favored_ notice (which we're "in-reply-to")
  * @param Notice         $stored The _activity_ notice, i.e. the favor itself.
  */
 public static function parseActivityObject(ActivityObject $actobj, Notice $stored)
 {
     // throws exception if nothing was found, but it could also be a non-Notice...
     // FIXME: This should only test _one_ URI (and not the links etc.) though a function like this could be useful in other cases
     $local = ActivityUtils::findLocalObject($actobj->getIdentifiers());
     if (!$local instanceof Notice) {
         // $local always returns something, but this was not what we expected. Something is wrong.
         throw new Exception('Something other than a Notice was returned from findLocalObject');
     }
     $actor = $stored->getProfile();
     $object = new Fave();
     $object->user_id = $stored->getProfile()->id;
     $object->notice_id = $local->id;
     $object->uri = $stored->uri;
     $object->created = $stored->created;
     $object->modified = $stored->modified;
     return $object;
 }
Example #22
0
 function asActivity()
 {
     $notice = Notice::staticGet('id', $this->notice_id);
     $profile = Profile::staticGet('id', $this->user_id);
     $act = new Activity();
     $act->verb = ActivityVerb::FAVORITE;
     $act->id = TagURI::mint('favor:%d:%d:%s', $profile->id, $notice->id, common_date_iso8601($this->modified));
     $act->time = strtotime($this->modified);
     // TRANS: Activity title when marking a notice as favorite.
     $act->title = _("Favor");
     // TRANS: Ntofication given when a user marks a notice as favorite.
     // TRANS: %1$s is a user nickname or full name, %2$s is a notice URI.
     $act->content = sprintf(_('%1$s marked notice %2$s as a favorite.'), $profile->getBestName(), $notice->uri);
     $act->actor = ActivityObject::fromProfile($profile);
     $act->objects[] = ActivityObject::fromNotice($notice);
     return $act;
 }
Example #23
0
 /**
  * @param ActivityObject $actobj The _favored_ notice (which we're "in-reply-to")
  * @param Notice         $stored The _activity_ notice, i.e. the favor itself.
  */
 public static function parseActivityObject(ActivityObject $actobj, Notice $stored)
 {
     $local = ActivityUtils::findLocalObject($actobj->getIdentifiers());
     if (!$local instanceof Notice) {
         // $local always returns something, but this was not what we expected. Something is wrong.
         throw new Exception('Something other than a Notice was returned from findLocalObject');
     }
     $actor = $stored->getProfile();
     $object = new Fave();
     $object->user_id = $stored->getProfile()->id;
     $object->notice_id = $local->id;
     $object->uri = $stored->uri;
     $object->created = $stored->created;
     $object->modified = $stored->modified;
     return $object;
 }
Example #24
0
 /**
  * Returns an XML string fragment with group information as an
  * Activity Streams noun object with the given element type.
  *
  * Assumes that 'activity', 'georss', and 'poco' namespace has been
  * previously defined.
  *
  * @param string $element one of 'actor', 'subject', 'object', 'target'
  *
  * @return string
  */
 function asActivityNoun($element)
 {
     $noun = ActivityObject::fromGroup($this);
     return $noun->asString('activity:' . $element);
 }
Example #25
0
 function asActivity()
 {
     $member = $this->getMember();
     $group = $this->getGroup();
     $act = new Activity();
     $act->id = TagURI::mint('join:%d:%d:%s', $member->id, $group->id, common_date_iso8601($this->created));
     $act->actor = ActivityObject::fromProfile($member);
     $act->verb = ActivityVerb::JOIN;
     $act->objects[] = ActivityObject::fromGroup($group);
     $act->time = strtotime($this->created);
     // TRANS: Activity title.
     $act->title = _("Join");
     // TRANS: Success message for subscribe to group attempt through OStatus.
     // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
     $act->content = sprintf(_('%1$s has joined group %2$s.'), $member->getBestName(), $group->getBestName());
     return $act;
 }
Example #26
0
 function registrationActivity()
 {
     $profile = $this->getProfile();
     $service = new ActivityObject();
     $service->type = ActivityObject::SERVICE;
     $service->title = common_config('site', 'name');
     $service->link = common_root_url();
     $service->id = $service->link;
     $act = new Activity();
     $act->actor = ActivityObject::fromProfile($profile);
     $act->verb = ActivityVerb::JOIN;
     $act->objects[] = $service;
     $act->id = TagURI::mint('user:register:%d', $this->id);
     $act->time = strtotime($this->created);
     $act->title = _("Register");
     $act->content = sprintf(_('%1$s joined %2$s.'), $profile->getBestName(), $service->title);
     return $act;
 }
 function writeFeedHeader($user, $handle)
 {
     fwrite($handle, '<?xml version="1.0" encoding="UTF-8"?>');
     fwrite($handle, "\n");
     fwrite($handle, '<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">');
     fwrite($handle, "\n");
     $profile = $user->getProfile();
     $author = ActivityObject::fromProfile($profile);
     $xs = new XMLStringer();
     $author->outputTo($xs, 'author');
     fwrite($handle, $xs->getString());
     fwrite($handle, "\n");
 }