/** * 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')); }
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; }
/** * 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; }
/** * Returns an XML string fragment with profile 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::fromProfile($this); return $noun->asString('activity:' . $element); }
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 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; }
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; }
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; }
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; }
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::staticGet('id', $this->from_profile); if (empty($profile)) { throw new Exception(sprintf("Sender profile not found: %d", $this->from_profile)); } $act->actor = ActivityObject::fromProfile($profile); $act->actor->extra[] = $profile->profileInfo(); $act->verb = ActivityVerb::POST; $act->objects[] = ActivityObject::fromMessage($this); $ctx = new ActivityContext(); $rprofile = Profile::staticGet('id', $this->to_profile); if (empty($rprofile)) { throw new Exception(sprintf("Receiver profile not found: %d", $this->to_profile)); } $ctx->attention[] = $rprofile->getUri(); $ctx->attentionType[$rprofile->getUri()] = ActivityObject::PERSON; $act->context = $ctx; $source = $this->getSource(); if ($source) { $act->generator = ActivityObject::fromNoticeSource($source); } Event::handle('EndMessageAsActivity', array($this, &$act)); } return $act; }
function asActivity() { $member = $this->getMember(); $group = $this->getGroup(); $act = new Activity(); $act->id = $this->getURI(); $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()); $url = common_local_url('AtomPubShowMembership', array('profile' => $member->id, 'group' => $group->id)); $act->selfLink = $url; $act->editLink = $url; return $act; }
function asActivity() { $profile = $this->getProfile(); $act = new Activity(); $act->actor = ActivityObject::fromProfile($profile); $act->verb = ActivityVerb::POST; $act->objects[] = ActivityObject::fromNotice($this); $act->time = strtotime($this->created); $act->link = $this->bestUrl(); $act->content = common_xml_safe_str($this->rendered); $act->id = $this->uri; $act->title = common_xml_safe_str($this->content); $ctx = new ActivityContext(); if (!empty($this->reply_to)) { $reply = Notice::staticGet('id', $this->reply_to); if (!empty($reply)) { $ctx->replyToID = $reply->uri; $ctx->replyToUrl = $reply->bestUrl(); } } $ctx->location = $this->getLocation(); $conv = null; if (!empty($this->conversation)) { $conv = Conversation::staticGet('id', $this->conversation); if (!empty($conv)) { $ctx->conversation = $conv->uri; } } $reply_ids = $this->getReplies(); foreach ($reply_ids as $id) { $profile = Profile::staticGet('id', $id); if (!empty($profile)) { $ctx->attention[] = $profile->getUri(); } } $groups = $this->getGroups(); foreach ($groups as $group) { $ctx->attention[] = $group->uri; } $act->context = $ctx; return $act; }
/** * Convert a notice into an activity for export. * * @param User $cur Current user * * @return Activity activity object representing this Notice. */ function asActivity($cur) { $act = self::cacheGet(Cache::codeKey('notice:as-activity:' . $this->id)); if (!empty($act)) { return $act; } $act = new Activity(); if (Event::handle('StartNoticeAsActivity', array($this, &$act))) { $profile = $this->getProfile(); $act->actor = ActivityObject::fromProfile($profile); $act->actor->extra[] = $profile->profileInfo($cur); $act->verb = ActivityVerb::POST; $act->objects[] = ActivityObject::fromNotice($this); // XXX: should this be handled by default processing for object entry? $act->time = strtotime($this->created); $act->link = $this->bestUrl(); $act->content = common_xml_safe_str($this->rendered); $act->id = $this->uri; $act->title = common_xml_safe_str($this->content); // Categories $tags = $this->getTags(); foreach ($tags as $tag) { $cat = new AtomCategory(); $cat->term = $tag; $act->categories[] = $cat; } // Enclosures // XXX: use Atom Media and/or File activity objects instead $attachments = $this->attachments(); foreach ($attachments as $attachment) { $enclosure = $attachment->getEnclosure(); if ($enclosure) { $act->enclosures[] = $enclosure; } } $ctx = new ActivityContext(); if (!empty($this->reply_to)) { $reply = Notice::staticGet('id', $this->reply_to); if (!empty($reply)) { $ctx->replyToID = $reply->uri; $ctx->replyToUrl = $reply->bestUrl(); } } $ctx->location = $this->getLocation(); $conv = null; if (!empty($this->conversation)) { $conv = Conversation::staticGet('id', $this->conversation); if (!empty($conv)) { $ctx->conversation = $conv->uri; } } $reply_ids = $this->getReplies(); foreach ($reply_ids as $id) { $profile = Profile::staticGet('id', $id); if (!empty($profile)) { $ctx->attention[] = $profile->getUri(); } } $groups = $this->getGroups(); foreach ($groups as $group) { $ctx->attention[] = $group->getUri(); } // XXX: deprecated; use ActivityVerb::SHARE instead $repeat = null; if (!empty($this->repeat_of)) { $repeat = Notice::staticGet('id', $this->repeat_of); $ctx->forwardID = $repeat->uri; $ctx->forwardUrl = $repeat->bestUrl(); } $act->context = $ctx; // Source $atom_feed = $profile->getAtomFeed(); if (!empty($atom_feed)) { $act->source = new ActivitySource(); // XXX: we should store the actual feed ID $act->source->id = $atom_feed; // XXX: we should store the actual feed title $act->source->title = $profile->getBestName(); $act->source->links['alternate'] = $profile->profileurl; $act->source->links['self'] = $atom_feed; $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE); $notice = $profile->getCurrentNotice(); if (!empty($notice)) { $act->source->updated = self::utcDate($notice->created); } $user = User::staticGet('id', $profile->id); if (!empty($user)) { $act->source->links['license'] = common_config('license', 'url'); } } if ($this->isLocal()) { $act->selfLink = common_local_url('ApiStatusesShow', array('id' => $this->id, 'format' => 'atom')); $act->editLink = $act->selfLink; } Event::handle('EndNoticeAsActivity', array($this, &$act)); } self::cacheSet(Cache::codeKey('notice:as-activity:' . $this->id), $act); return $act; }
/** * Returns an XML string fragment with profile information as an * Activity Streams noun object with the given element type. * * Assumes that 'activity' namespace has been previously defined. * * @todo FIXME: Replace with wrappers on asActivityObject when it's got everything. * * @param string $element one of 'actor', 'subject', 'object', 'target' * @return string */ function asActivityNoun($element) { if ($this->isGroup()) { $noun = ActivityObject::fromGroup($this->localGroup()); return $noun->asString('activity:' . $element); } else { if ($this->isPeopletag()) { $noun = ActivityObject::fromPeopletag($this->localPeopletag()); return $noun->asString('activity:' . $element); } else { $noun = ActivityObject::fromProfile($this->localProfile()); return $noun->asString('activity:' . $element); } } }
/** * Convert a notice into an activity for export. * * @param User $cur Current user * * @return Activity activity object representing this Notice. */ function asActivity($cur) { $act = self::cacheGet(Cache::codeKey('notice:as-activity:' . $this->id)); if (!empty($act)) { return $act; } $act = new Activity(); if (Event::handle('StartNoticeAsActivity', array($this, &$act))) { $act->id = TagURI::mint("post:" . $this->id); $act->time = strtotime($this->created); $act->content = common_xml_safe_str($this->rendered); $profile = $this->getProfile(); $act->actor = ActivityObject::fromProfile($profile); $act->actor->extra[] = $profile->profileInfo($cur); $act->verb = $this->verb; if ($this->repeat_of) { $repeated = Notice::staticGet('id', $this->repeat_of); if (!empty($repeated)) { $act->objects[] = $repeated->asActivity($cur); } } else { $act->objects[] = ActivityObject::fromNotice($this); } // XXX: should this be handled by default processing for object entry? // Categories $tags = $this->getTags(); foreach ($tags as $tag) { $cat = new AtomCategory(); $cat->term = $tag; $act->categories[] = $cat; } // Enclosures // XXX: use Atom Media and/or File activity objects instead $attachments = $this->attachments(); foreach ($attachments as $attachment) { // Save local attachments if (!empty($attachment->filename)) { $act->attachments[] = ActivityObject::fromFile($attachment); } } $ctx = new ActivityContext(); if (!empty($this->reply_to)) { $reply = Notice::staticGet('id', $this->reply_to); if (!empty($reply)) { $ctx->replyToID = $reply->uri; $ctx->replyToUrl = $reply->bestUrl(); } } $ctx->location = $this->getLocation(); $conv = null; if (!empty($this->conversation)) { $conv = Conversation::staticGet('id', $this->conversation); if (!empty($conv)) { $ctx->conversation = $conv->uri; } } $reply_ids = $this->getReplies(); foreach ($reply_ids as $id) { $rprofile = Profile::staticGet('id', $id); if (!empty($rprofile)) { $ctx->attention[] = $rprofile->getUri(); $ctx->attentionType[$rprofile->getUri()] = ActivityObject::PERSON; } } $groups = $this->getGroups(); foreach ($groups as $group) { $ctx->attention[] = $group->getUri(); $ctx->attentionType[$group->getUri()] = ActivityObject::GROUP; } switch ($this->scope) { case Notice::PUBLIC_SCOPE: $ctx->attention[] = "http://activityschema.org/collection/public"; $ctx->attentionType["http://activityschema.org/collection/public"] = ActivityObject::COLLECTION; break; case Notice::FOLLOWER_SCOPE: $surl = common_local_url("subscribers", array('nickname' => $profile->nickname)); $ctx->attention[] = $surl; $ctx->attentionType[$surl] = ActivityObject::COLLECTION; break; } // XXX: deprecated; use ActivityVerb::SHARE instead $repeat = null; if (!empty($this->repeat_of)) { $repeat = Notice::staticGet('id', $this->repeat_of); if (!empty($repeat)) { $ctx->forwardID = $repeat->uri; $ctx->forwardUrl = $repeat->bestUrl(); } } $act->context = $ctx; $source = $this->getSource(); if ($source) { $act->generator = ActivityObject::fromNoticeSource($source); } // Source $atom_feed = $profile->getAtomFeed(); if (!empty($atom_feed)) { $act->source = new ActivitySource(); // XXX: we should store the actual feed ID $act->source->id = $atom_feed; // XXX: we should store the actual feed title $act->source->title = $profile->getBestName(); $act->source->links['alternate'] = $profile->profileurl; $act->source->links['self'] = $atom_feed; $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE); $notice = $profile->getCurrentNotice(); if (!empty($notice)) { $act->source->updated = self::utcDate($notice->created); } $user = User::staticGet('id', $profile->id); if (!empty($user)) { $act->source->links['license'] = common_config('license', 'url'); } } if ($this->isLocal()) { $act->selfLink = common_local_url('ApiStatusesShow', array('id' => $this->id, 'format' => 'atom')); $act->editLink = $act->selfLink; } Event::handle('EndNoticeAsActivity', array($this, &$act)); } self::cacheSet(Cache::codeKey('notice:as-activity:' . $this->id), $act); 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"); }