3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2009-2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @package OStatusPlugin
22 * @maintainer Brion Vibber <brion@status.net>
25 if (!defined('STATUSNET')) {
29 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/');
31 class FeedSubException extends Exception
33 function __construct($msg=null)
35 $type = get_class($this);
37 parent::__construct("$type: $msg");
39 parent::__construct($type);
44 class OStatusPlugin extends Plugin
47 * Hook for RouterInitialized event.
49 * @param Net_URL_Mapper $m path-to-action mapper
50 * @return boolean hook return
52 function onRouterInitialized($m)
55 $m->connect('main/ownerxrd',
56 array('action' => 'ownerxrd'));
57 $m->connect('main/ostatus',
58 array('action' => 'ostatusinit'));
59 $m->connect('main/ostatus?nickname=:nickname',
60 array('action' => 'ostatusinit'), array('nickname' => '[A-Za-z0-9_-]+'));
61 $m->connect('main/ostatus?group=:group',
62 array('action' => 'ostatusinit'), array('group' => '[A-Za-z0-9_-]+'));
63 $m->connect('main/ostatussub',
64 array('action' => 'ostatussub'));
65 $m->connect('main/ostatusgroup',
66 array('action' => 'ostatusgroup'));
69 $m->connect('main/push/hub', array('action' => 'pushhub'));
71 $m->connect('main/push/callback/:feed',
72 array('action' => 'pushcallback'),
73 array('feed' => '[0-9]+'));
76 $m->connect('main/salmon/user/:id',
77 array('action' => 'usersalmon'),
78 array('id' => '[0-9]+'));
79 $m->connect('main/salmon/group/:id',
80 array('action' => 'groupsalmon'),
81 array('id' => '[0-9]+'));
86 * Set up queue handlers for outgoing hub pushes
87 * @param QueueManager $qm
88 * @return boolean hook return
90 function onEndInitializeQueueManager(QueueManager $qm)
92 // Prepare outgoing distributions after notice save.
93 $qm->connect('ostatus', 'OStatusQueueHandler');
95 // Outgoing from our internal PuSH hub
96 $qm->connect('hubconf', 'HubConfQueueHandler');
97 $qm->connect('hubprep', 'HubPrepQueueHandler');
99 $qm->connect('hubout', 'HubOutQueueHandler');
101 // Outgoing Salmon replies (when we don't need a return value)
102 $qm->connect('salmon', 'SalmonQueueHandler');
104 // Incoming from a foreign PuSH hub
105 $qm->connect('pushin', 'PushInQueueHandler');
110 * Put saved notices into the queue for pubsub distribution.
112 function onStartEnqueueNotice($notice, &$transports)
114 if ($notice->isLocal()) {
115 // put our transport first, in case there's any conflict (like OMB)
116 array_unshift($transports, 'ostatus');
122 * Add a link header for LRDD Discovery
124 function onStartShowHTML($action)
126 if ($action instanceof ShowstreamAction) {
127 $acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
128 $url = common_local_url('userxrd');
129 $url.= '?uri='. $acct;
131 header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="application/xrd+xml"');
136 * Set up a PuSH hub link to our internal link for canonical timeline
137 * Atom feeds for users and groups.
139 function onStartApiAtom($feed)
143 if ($feed instanceof AtomUserNoticeFeed) {
144 $salmonAction = 'usersalmon';
145 $user = $feed->getUser();
147 $profile = $user->getProfile();
148 } else if ($feed instanceof AtomGroupNoticeFeed) {
149 $salmonAction = 'groupsalmon';
150 $group = $feed->getGroup();
157 $hub = common_config('ostatus', 'hub');
159 // Updates will be handled through our internal PuSH hub.
160 $hub = common_local_url('pushhub');
162 $feed->addLink($hub, array('rel' => 'hub'));
164 // Also, we'll add in the salmon link
165 $salmon = common_local_url($salmonAction, array('id' => $id));
166 $feed->addLink($salmon, array('rel' => Salmon::REL_SALMON));
168 // XXX: these are deprecated
169 $feed->addLink($salmon, array('rel' => Salmon::NS_REPLIES));
170 $feed->addLink($salmon, array('rel' => Salmon::NS_MENTIONS));
177 * Automatically load the actions and libraries used by the plugin
179 * @param Class $cls the class
181 * @return boolean hook return
184 function onAutoload($cls)
186 $base = dirname(__FILE__);
187 $lower = strtolower($cls);
188 $map = array('activityverb' => 'activity',
189 'activityobject' => 'activity',
190 'activityutils' => 'activity');
191 if (isset($map[$lower])) {
192 $lower = $map[$lower];
194 $files = array("$base/classes/$cls.php",
195 "$base/lib/$lower.php");
196 if (substr($lower, -6) == 'action') {
197 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
199 foreach ($files as $file) {
200 if (file_exists($file)) {
209 * Add in an OStatus subscribe button
211 function onStartProfileRemoteSubscribe($output, $profile)
213 $cur = common_current_user();
216 // Add an OStatus subscribe
217 $output->elementStart('li', 'entity_subscribe');
218 $url = common_local_url('ostatusinit',
219 array('nickname' => $profile->nickname));
220 $output->element('a', array('href' => $url,
221 'class' => 'entity_remote_subscribe'),
222 // TRANS: Link description for link to subscribe to a remote user.
225 $output->elementEnd('li');
231 function onStartGroupSubscribe($output, $group)
233 $cur = common_current_user();
236 // Add an OStatus subscribe
237 $url = common_local_url('ostatusinit',
238 array('group' => $group->nickname));
239 $output->element('a', array('href' => $url,
240 'class' => 'entity_remote_subscribe'),
241 // TRANS: Link description for link to join a remote group.
249 * Find any explicit remote mentions. Accepted forms:
250 * Webfinger: @user@example.com
251 * Profile link: @example.com/mublog/user
252 * @param Profile $sender (os user?)
253 * @param string $text input markup text
254 * @param array &$mention in/out param: set of found mentions
255 * @return boolean hook return value
258 function onEndFindMentions($sender, $text, &$mentions)
262 // Webfinger matches: @user@example.com
263 if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\-?\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
266 PREG_OFFSET_CAPTURE)) {
267 foreach ($wmatches[1] as $wmatch) {
268 list($target, $pos) = $wmatch;
269 $this->log(LOG_INFO, "Checking webfinger '$target'");
271 $oprofile = Ostatus_profile::ensureWebfinger($target);
272 if ($oprofile && !$oprofile->isGroup()) {
273 $profile = $oprofile->localProfile();
274 $matches[$pos] = array('mentioned' => array($profile),
277 'url' => $profile->profileurl);
279 } catch (Exception $e) {
280 $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
285 // Profile matches: @example.com/mublog/user
286 if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)!',
289 PREG_OFFSET_CAPTURE)) {
290 foreach ($wmatches[1] as $wmatch) {
291 list($target, $pos) = $wmatch;
292 $schemes = array('http', 'https');
293 foreach ($schemes as $scheme) {
294 $url = "$scheme://$target";
295 $this->log(LOG_INFO, "Checking profile address '$url'");
297 $oprofile = Ostatus_profile::ensureProfileURL($url);
298 if ($oprofile && !$oprofile->isGroup()) {
299 $profile = $oprofile->localProfile();
300 $matches[$pos] = array('mentioned' => array($profile),
303 'url' => $profile->profileurl);
306 } catch (Exception $e) {
307 $this->log(LOG_ERR, "Profile check failed: " . $e->getMessage());
313 foreach ($mentions as $i => $other) {
314 // If we share a common prefix with a local user, override it!
315 $pos = $other['position'];
316 if (isset($matches[$pos])) {
317 $mentions[$i] = $matches[$pos];
318 unset($matches[$pos]);
321 foreach ($matches as $mention) {
322 $mentions[] = $mention;
329 * Allow remote profile references to be used in commands:
330 * sub update@status.net
331 * whois evan@identi.ca
332 * reply http://identi.ca/evan hey what's up
334 * @param Command $command
336 * @param Profile &$profile
337 * @return hook return code
339 function onStartCommandGetProfile($command, $arg, &$profile)
341 $oprofile = $this->pullRemoteProfile($arg);
342 if ($oprofile && !$oprofile->isGroup()) {
343 $profile = $oprofile->localProfile();
351 * Allow remote group references to be used in commands:
352 * join group+statusnet@identi.ca
353 * join http://identi.ca/group/statusnet
354 * drop identi.ca/group/statusnet
356 * @param Command $command
358 * @param User_group &$group
359 * @return hook return code
361 function onStartCommandGetGroup($command, $arg, &$group)
363 $oprofile = $this->pullRemoteProfile($arg);
364 if ($oprofile && $oprofile->isGroup()) {
365 $group = $oprofile->localGroup();
372 protected function pullRemoteProfile($arg)
375 if (preg_match('!^((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)$!', $arg)) {
378 return Ostatus_profile::ensureWebfinger($arg);
379 } catch (Exception $e) {
380 common_log(LOG_ERR, 'Webfinger lookup failed for ' .
381 $arg . ': ' . $e->getMessage());
385 // Look for profile URLs, with or without scheme:
387 if (preg_match('!^https?://((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
390 if (preg_match('!^((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
391 $schemes = array('http', 'https');
392 foreach ($schemes as $scheme) {
393 $urls[] = "$scheme://$arg";
397 foreach ($urls as $url) {
399 return Ostatus_profile::ensureProfileURL($url);
400 } catch (Exception $e) {
401 common_log(LOG_ERR, 'Profile lookup failed for ' .
402 $arg . ': ' . $e->getMessage());
409 * Make sure necessary tables are filled out.
411 function onCheckSchema() {
412 $schema = Schema::get();
413 $schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef());
414 $schema->ensureTable('ostatus_source', Ostatus_source::schemaDef());
415 $schema->ensureTable('feedsub', FeedSub::schemaDef());
416 $schema->ensureTable('hubsub', HubSub::schemaDef());
417 $schema->ensureTable('magicsig', Magicsig::schemaDef());
421 function onEndShowStatusNetStyles($action) {
422 $action->cssLink('plugins/OStatus/theme/base/css/ostatus.css');
426 function onEndShowStatusNetScripts($action) {
427 $action->script('plugins/OStatus/js/ostatus.js');
432 * Override the "from ostatus" bit in notice lists to link to the
433 * original post and show the domain it came from.
435 * @param Notice in $notice
436 * @param string out &$name
437 * @param string out &$url
438 * @param string out &$title
439 * @return mixed hook return code
441 function onStartNoticeSourceLink($notice, &$name, &$url, &$title)
443 if ($notice->source == 'ostatus') {
445 $bits = parse_url($notice->url);
446 $domain = $bits['host'];
447 if (substr($domain, 0, 4) == 'www.') {
448 $name = substr($domain, 4);
454 // TRANSLATE: %s is a domain.
455 $title = sprintf(_m("Sent from %s via OStatus"), $domain);
463 * Send incoming PuSH feeds for OStatus endpoints in for processing.
465 * @param FeedSub $feedsub
466 * @param DOMDocument $feed
467 * @return mixed hook return code
469 function onStartFeedSubReceive($feedsub, $feed)
471 $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
473 $oprofile->processFeed($feed, 'push');
475 common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
480 * Tell the FeedSub infrastructure whether we have any active OStatus
481 * usage for the feed; if not it'll be able to garbage-collect the
484 * @param FeedSub $feedsub
485 * @param integer $count in/out
486 * @return mixed hook return code
488 function onFeedSubSubscriberCount($feedsub, &$count)
490 $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
492 $count += $oprofile->subscriberCount();
498 * When about to subscribe to a remote user, start a server-to-server
499 * PuSH subscription if needed. If we can't establish that, abort.
501 * @fixme If something else aborts later, we could end up with a stray
502 * PuSH subscription. This is relatively harmless, though.
504 * @param Profile $subscriber
505 * @param Profile $other
507 * @return hook return code
511 function onStartSubscribe($subscriber, $other)
513 $user = User::staticGet('id', $subscriber->id);
519 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
521 if (empty($oprofile)) {
525 if (!$oprofile->subscribe()) {
527 throw new Exception(_m('Could not set up remote subscription.'));
532 * Having established a remote subscription, send a notification to the
533 * remote OStatus profile's endpoint.
535 * @param Profile $subscriber
536 * @param Profile $other
538 * @return hook return code
542 function onEndSubscribe($subscriber, $other)
544 $user = User::staticGet('id', $subscriber->id);
550 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
552 if (empty($oprofile)) {
556 $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
557 'subscribed' => $other->id));
559 $act = $sub->asActivity();
561 $oprofile->notifyActivity($act, $subscriber);
567 * Notify remote server and garbage collect unused feeds on unsubscribe.
568 * @fixme send these operations to background queues
571 * @param Profile $other
572 * @return hook return value
574 function onEndUnsubscribe($profile, $other)
576 $user = User::staticGet('id', $profile->id);
582 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
584 if (empty($oprofile)) {
588 // Drop the PuSH subscription if there are no other subscribers.
589 $oprofile->garbageCollect();
591 $act = new Activity();
593 $act->verb = ActivityVerb::UNFOLLOW;
595 $act->id = TagURI::mint('unfollow:%d:%d:%s',
598 common_date_iso8601(time()));
601 $act->title = _m('Unfollow');
602 // TRANS: Success message for unsubscribe from user attempt through OStatus.
603 // TRANS: %1$s is the unsubscriber's name, %2$s is the unsubscribed user's name.
604 $act->content = sprintf(_m('%1$s stopped following %2$s.'),
605 $profile->getBestName(),
606 $other->getBestName());
608 $act->actor = ActivityObject::fromProfile($profile);
609 $act->object = ActivityObject::fromProfile($other);
611 $oprofile->notifyActivity($act, $profile);
617 * When one of our local users tries to join a remote group,
618 * notify the remote server. If the notification is rejected,
621 * @param User_group $group
624 * @return mixed hook return value
627 function onStartJoinGroup($group, $user)
629 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
631 if (!$oprofile->subscribe()) {
632 throw new Exception(_m('Could not set up remote group membership.'));
635 // NOTE: we don't use Group_member::asActivity() since that record
636 // has not yet been created.
638 $member = Profile::staticGet($user->id);
640 $act = new Activity();
641 $act->id = TagURI::mint('join:%d:%d:%s',
644 common_date_iso8601(time()));
646 $act->actor = ActivityObject::fromProfile($member);
647 $act->verb = ActivityVerb::JOIN;
648 $act->object = $oprofile->asActivityObject();
651 $act->title = _m("Join");
652 // TRANS: Success message for subscribe to group attempt through OStatus.
653 // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
654 $act->content = sprintf(_m('%1$s has joined group %2$s.'),
655 $member->getBestName(),
656 $oprofile->getBestName());
658 if ($oprofile->notifyActivity($act, $member)) {
661 $oprofile->garbageCollect();
663 throw new Exception(_m("Failed joining remote group."));
669 * When one of our local users leaves a remote group, notify the remote
672 * @fixme Might be good to schedule a resend of the leave notification
673 * if it failed due to a transitory error. We've canceled the local
674 * membership already anyway, but if the remote server comes back up
675 * it'll be left with a stray membership record.
677 * @param User_group $group
680 * @return mixed hook return value
683 function onEndLeaveGroup($group, $user)
685 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
687 // Drop the PuSH subscription if there are no other subscribers.
688 $oprofile->garbageCollect();
690 $member = Profile::staticGet($user->id);
692 $act = new Activity();
693 $act->id = TagURI::mint('leave:%d:%d:%s',
696 common_date_iso8601(time()));
698 $act->actor = ActivityObject::fromProfile($member);
699 $act->verb = ActivityVerb::LEAVE;
700 $act->object = $oprofile->asActivityObject();
703 $act->title = _m("Leave");
704 // TRANS: Success message for unsubscribe from group attempt through OStatus.
705 // TRANS: %1$s is the member name, %2$s is the unsubscribed group's name.
706 $act->content = sprintf(_m('%1$s has left group %2$s.'),
707 $member->getBestName(),
708 $oprofile->getBestName());
710 $oprofile->notifyActivity($act, $member);
715 * Notify remote users when their notices get favorited.
717 * @param Profile or User $profile of local user doing the faving
718 * @param Notice $notice being favored
719 * @return hook return value
721 function onEndFavorNotice(Profile $profile, Notice $notice)
723 $user = User::staticGet('id', $profile->id);
729 $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
731 if (empty($oprofile)) {
735 $fav = Fave::pkeyGet(array('user_id' => $user->id,
736 'notice_id' => $notice->id));
743 $act = $fav->asActivity();
745 $oprofile->notifyActivity($act, $profile);
751 * Notify remote users when their notices get de-favorited.
753 * @param Profile $profile Profile person doing the de-faving
754 * @param Notice $notice Notice being favored
756 * @return hook return value
759 function onEndDisfavorNotice(Profile $profile, Notice $notice)
761 $user = User::staticGet('id', $profile->id);
767 $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
769 if (empty($oprofile)) {
773 $act = new Activity();
775 $act->verb = ActivityVerb::UNFAVORITE;
776 $act->id = TagURI::mint('disfavor:%d:%d:%s',
779 common_date_iso8601(time()));
781 $act->title = _m('Disfavor');
782 // TRANS: Success message for remove a favorite notice through OStatus.
783 // TRANS: %1$s is the unfavoring user's name, %2$s is URI to the no longer favored notice.
784 $act->content = sprintf(_m('%1$s marked notice %2$s as no longer a favorite.'),
785 $profile->getBestName(),
788 $act->actor = ActivityObject::fromProfile($profile);
789 $act->object = ActivityObject::fromNotice($notice);
791 $oprofile->notifyActivity($act, $profile);
796 function onStartGetProfileUri($profile, &$uri)
798 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
799 if (!empty($oprofile)) {
800 $uri = $oprofile->uri;
806 function onStartUserGroupHomeUrl($group, &$url)
808 return $this->onStartUserGroupPermalink($group, $url);
811 function onStartUserGroupPermalink($group, &$url)
813 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
815 // @fixme this should probably be in the user_group table
816 // @fixme this uri not guaranteed to be a profile page
817 $url = $oprofile->uri;
822 function onStartShowSubscriptionsContent($action)
824 $this->showEntityRemoteSubscribe($action);
829 function onStartShowUserGroupsContent($action)
831 $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
836 function onEndShowSubscriptionsMiniList($action)
838 $this->showEntityRemoteSubscribe($action);
843 function onEndShowGroupsMiniList($action)
845 $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
850 function showEntityRemoteSubscribe($action, $target='ostatussub')
852 $user = common_current_user();
853 if ($user && ($user->id == $action->profile->id)) {
854 $action->elementStart('div', 'entity_actions');
855 $action->elementStart('p', array('id' => 'entity_remote_subscribe',
856 'class' => 'entity_subscribe'));
857 $action->element('a', array('href' => common_local_url($target),
858 'class' => 'entity_remote_subscribe'),
859 // TRANS: Link text for link to remote subscribe.
861 $action->elementEnd('p');
862 $action->elementEnd('div');
867 * Ping remote profiles with updates to this profile.
868 * Salmon pings are queued for background processing.
870 function onEndBroadcastProfile(Profile $profile)
872 $user = User::staticGet('id', $profile->id);
874 // Find foreign accounts I'm subscribed to that support Salmon pings.
876 // @fixme we could run updates through the PuSH feed too,
877 // in which case we can skip Salmon pings to folks who
878 // are also subscribed to me.
879 $sql = "SELECT * FROM ostatus_profile " .
880 "WHERE profile_id IN " .
881 "(SELECT subscribed FROM subscription WHERE subscriber=%d) " .
883 "(SELECT group_id FROM group_member WHERE profile_id=%d)";
884 $oprofile = new Ostatus_profile();
885 $oprofile->query(sprintf($sql, $profile->id, $profile->id));
887 if ($oprofile->N == 0) {
888 common_log(LOG_DEBUG, "No OStatus remote subscribees for $profile->nickname");
892 $act = new Activity();
894 $act->verb = ActivityVerb::UPDATE_PROFILE;
895 $act->id = TagURI::mint('update-profile:%d:%s',
897 common_date_iso8601(time()));
899 // TRANS: Title for activity.
900 $act->title = _m("Profile update");
901 // TRANS: Ping text for remote profile update through OStatus.
902 // TRANS: %s is user that updated their profile.
903 $act->content = sprintf(_m("%s has updated their profile page."),
904 $profile->getBestName());
906 $act->actor = ActivityObject::fromProfile($profile);
907 $act->object = $act->actor;
909 while ($oprofile->fetch()) {
910 $oprofile->notifyDeferred($act, $profile);
916 function onStartProfileListItemActionElements($item)
918 if (!common_logged_in()) {
920 $profileUser = User::staticGet('id', $item->profile->id);
922 if (!empty($profileUser)) {
924 $output = $item->out;
926 // Add an OStatus subscribe
927 $output->elementStart('li', 'entity_subscribe');
928 $url = common_local_url('ostatusinit',
929 array('nickname' => $profileUser->nickname));
930 $output->element('a', array('href' => $url,
931 'class' => 'entity_remote_subscribe'),
932 // TRANS: Link text for a user to subscribe to an OStatus user.
934 $output->elementEnd('li');
941 function onPluginVersion(&$versions)
943 $versions[] = array('name' => 'OStatus',
944 'version' => STATUSNET_VERSION,
945 'author' => 'Evan Prodromou, James Walker, Brion Vibber, Zach Copley',
946 'homepage' => 'http://status.net/wiki/Plugin:OStatus',
947 // TRANS: Plugin description.
948 'rawdescription' => _m('Follow people across social networks that implement '.
949 '<a href="http://ostatus.org/">OStatus</a>.'));
955 * Utility function to check if the given URI is a canonical group profile
956 * page, and if so return the ID number.
959 * @return mixed int or false
961 public static function localGroupFromUrl($url)
963 $group = User_group::staticGet('uri', $url);
965 $local = Local_group::staticGet('group_id', $group->id);
970 // To find local groups which haven't had their uri fields filled out...
971 // If the domain has changed since a subscriber got the URI, it'll
973 $template = common_local_url('groupbyid', array('id' => '31337'));
974 $template = preg_quote($template, '/');
975 $template = str_replace('31337', '(\d+)', $template);
976 if (preg_match("/$template/", $url, $matches)) {
977 return intval($matches[1]);
983 public function onStartProfileGetAtomFeed($profile, &$feed)
985 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
987 if (empty($oprofile)) {
991 $feed = $oprofile->feeduri;
995 function onStartGetProfileFromURI($uri, &$profile)
997 // Don't want to do Web-based discovery on our own server,
998 // so we check locally first.
1000 $user = User::staticGet('uri', $uri);
1002 if (!empty($user)) {
1003 $profile = $user->getProfile();
1007 // Now, check remotely
1009 $oprofile = Ostatus_profile::ensureProfileURI($uri);
1011 if (!empty($oprofile)) {
1012 $profile = $oprofile->localProfile();
1016 // Still not a hit, so give up.
1021 function onEndXrdActionLinks(&$xrd, $user)
1023 $xrd->links[] = array('rel' => Discovery::UPDATESFROM,
1024 'href' => common_local_url('ApiTimelineUser',
1025 array('id' => $user->id,
1026 'format' => 'atom')),
1027 'type' => 'application/atom+xml');
1030 $salmon_url = common_local_url('usersalmon',
1031 array('id' => $user->id));
1033 $xrd->links[] = array('rel' => Salmon::REL_SALMON,
1034 'href' => $salmon_url);
1035 // XXX : Deprecated - to be removed.
1036 $xrd->links[] = array('rel' => Salmon::NS_REPLIES,
1037 'href' => $salmon_url);
1039 $xrd->links[] = array('rel' => Salmon::NS_MENTIONS,
1040 'href' => $salmon_url);
1042 // Get this user's keypair
1043 $magickey = Magicsig::staticGet('user_id', $user->id);
1045 // No keypair yet, let's generate one.
1046 $magickey = new Magicsig();
1047 $magickey->generate($user->id);
1050 $xrd->links[] = array('rel' => Magicsig::PUBLICKEYREL,
1051 'href' => 'data:application/magic-public-key,'. $magickey->toString(false));
1053 // TODO - finalize where the redirect should go on the publisher
1054 $url = common_local_url('ostatussub') . '?profile={uri}';
1055 $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
1056 'template' => $url );