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') && !defined('LACONICA')) { exit(1); }
27 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/');
29 class FeedSubException extends Exception
31 function __construct($msg=null)
33 $type = get_class($this);
35 parent::__construct("$type: $msg");
37 parent::__construct($type);
42 class OStatusPlugin extends Plugin
45 * Hook for RouterInitialized event.
47 * @param Net_URL_Mapper $m path-to-action mapper
48 * @return boolean hook return
50 function onRouterInitialized($m)
53 $m->connect('main/xrd',
54 array('action' => 'userxrd'));
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 $feed->setActivitySubject($profile->asActivityNoun('subject'));
149 } else if ($feed instanceof AtomGroupNoticeFeed) {
150 $salmonAction = 'groupsalmon';
151 $group = $feed->getGroup();
153 $feed->setActivitySubject($group->asActivitySubject());
159 $hub = common_config('ostatus', 'hub');
161 // Updates will be handled through our internal PuSH hub.
162 $hub = common_local_url('pushhub');
164 $feed->addLink($hub, array('rel' => 'hub'));
166 // Also, we'll add in the salmon link
167 $salmon = common_local_url($salmonAction, array('id' => $id));
168 $feed->addLink($salmon, array('rel' => Salmon::REL_SALMON));
170 // XXX: these are deprecated
171 $feed->addLink($salmon, array('rel' => Salmon::NS_REPLIES));
172 $feed->addLink($salmon, array('rel' => Salmon::NS_MENTIONS));
179 * Automatically load the actions and libraries used by the plugin
181 * @param Class $cls the class
183 * @return boolean hook return
186 function onAutoload($cls)
188 $base = dirname(__FILE__);
189 $lower = strtolower($cls);
190 $map = array('activityverb' => 'activity',
191 'activityobject' => 'activity',
192 'activityutils' => 'activity');
193 if (isset($map[$lower])) {
194 $lower = $map[$lower];
196 $files = array("$base/classes/$cls.php",
197 "$base/lib/$lower.php");
198 if (substr($lower, -6) == 'action') {
199 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
201 foreach ($files as $file) {
202 if (file_exists($file)) {
211 * Add in an OStatus subscribe button
213 function onStartProfileRemoteSubscribe($output, $profile)
215 $cur = common_current_user();
218 // Add an OStatus subscribe
219 $output->elementStart('li', 'entity_subscribe');
220 $url = common_local_url('ostatusinit',
221 array('nickname' => $profile->nickname));
222 $output->element('a', array('href' => $url,
223 'class' => 'entity_remote_subscribe'),
226 $output->elementEnd('li');
232 function onStartGroupSubscribe($output, $group)
234 $cur = common_current_user();
237 // Add an OStatus subscribe
238 $url = common_local_url('ostatusinit',
239 array('group' => $group->nickname));
240 $output->element('a', array('href' => $url,
241 'class' => 'entity_remote_subscribe'),
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 $title = sprintf(_m("Sent from %s via OStatus"), $domain);
462 * Send incoming PuSH feeds for OStatus endpoints in for processing.
464 * @param FeedSub $feedsub
465 * @param DOMDocument $feed
466 * @return mixed hook return code
468 function onStartFeedSubReceive($feedsub, $feed)
470 $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
472 $oprofile->processFeed($feed, 'push');
474 common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
479 * Tell the FeedSub infrastructure whether we have any active OStatus
480 * usage for the feed; if not it'll be able to garbage-collect the
483 * @param FeedSub $feedsub
484 * @param integer $count in/out
485 * @return mixed hook return code
487 function onFeedSubSubscriberCount($feedsub, &$count)
489 $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
491 $count += $oprofile->subscriberCount();
497 * When about to subscribe to a remote user, start a server-to-server
498 * PuSH subscription if needed. If we can't establish that, abort.
500 * @fixme If something else aborts later, we could end up with a stray
501 * PuSH subscription. This is relatively harmless, though.
503 * @param Profile $subscriber
504 * @param Profile $other
506 * @return hook return code
510 function onStartSubscribe($subscriber, $other)
512 $user = User::staticGet('id', $subscriber->id);
518 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
520 if (empty($oprofile)) {
524 if (!$oprofile->subscribe()) {
525 throw new Exception(_m('Could not set up remote subscription.'));
530 * Having established a remote subscription, send a notification to the
531 * remote OStatus profile's endpoint.
533 * @param Profile $subscriber
534 * @param Profile $other
536 * @return hook return code
540 function onEndSubscribe($subscriber, $other)
542 $user = User::staticGet('id', $subscriber->id);
548 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
550 if (empty($oprofile)) {
554 $act = new Activity();
556 $act->verb = ActivityVerb::FOLLOW;
558 $act->id = TagURI::mint('follow:%d:%d:%s',
561 common_date_iso8601(time()));
564 $act->title = _("Follow");
565 // TRANS: Success message for subscribe to user attempt through OStatus.
566 // TRANS: %1$s is the subscriber name, %2$s is the subscribed user's name.
567 $act->content = sprintf(_("%1$s is now following %2$s."),
568 $subscriber->getBestName(),
569 $other->getBestName());
571 $act->actor = ActivityObject::fromProfile($subscriber);
572 $act->object = ActivityObject::fromProfile($other);
574 $oprofile->notifyActivity($act, $subscriber);
580 * Notify remote server and garbage collect unused feeds on unsubscribe.
581 * @fixme send these operations to background queues
584 * @param Profile $other
585 * @return hook return value
587 function onEndUnsubscribe($profile, $other)
589 $user = User::staticGet('id', $profile->id);
595 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
597 if (empty($oprofile)) {
601 // Drop the PuSH subscription if there are no other subscribers.
602 $oprofile->garbageCollect();
604 $act = new Activity();
606 $act->verb = ActivityVerb::UNFOLLOW;
608 $act->id = TagURI::mint('unfollow:%d:%d:%s',
611 common_date_iso8601(time()));
614 $act->title = _("Unfollow");
615 // TRANS: Success message for unsubscribe from user attempt through OStatus.
616 // TRANS: %1$s is the unsubscriber's name, %2$s is the unsubscribed user's name.
617 $act->content = sprintf(_("%1$s stopped following %2$s."),
618 $profile->getBestName(),
619 $other->getBestName());
621 $act->actor = ActivityObject::fromProfile($profile);
622 $act->object = ActivityObject::fromProfile($other);
624 $oprofile->notifyActivity($act, $profile);
630 * When one of our local users tries to join a remote group,
631 * notify the remote server. If the notification is rejected,
634 * @param User_group $group
637 * @return mixed hook return value
640 function onStartJoinGroup($group, $user)
642 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
644 if (!$oprofile->subscribe()) {
645 throw new Exception(_m('Could not set up remote group membership.'));
648 $member = Profile::staticGet($user->id);
650 $act = new Activity();
651 $act->id = TagURI::mint('join:%d:%d:%s',
654 common_date_iso8601(time()));
656 $act->actor = ActivityObject::fromProfile($member);
657 $act->verb = ActivityVerb::JOIN;
658 $act->object = $oprofile->asActivityObject();
661 $act->title = _m("Join");
662 // TRANS: Success message for subscribe to group attempt through OStatus.
663 // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
664 $act->content = sprintf(_m("%1$s has joined group %2$s."),
665 $member->getBestName(),
666 $oprofile->getBestName());
668 if ($oprofile->notifyActivity($act, $member)) {
671 $oprofile->garbageCollect();
672 throw new Exception(_m("Failed joining remote group."));
678 * When one of our local users leaves a remote group, notify the remote
681 * @fixme Might be good to schedule a resend of the leave notification
682 * if it failed due to a transitory error. We've canceled the local
683 * membership already anyway, but if the remote server comes back up
684 * it'll be left with a stray membership record.
686 * @param User_group $group
689 * @return mixed hook return value
692 function onEndLeaveGroup($group, $user)
694 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
696 // Drop the PuSH subscription if there are no other subscribers.
697 $oprofile->garbageCollect();
699 $member = Profile::staticGet($user->id);
701 $act = new Activity();
702 $act->id = TagURI::mint('leave:%d:%d:%s',
705 common_date_iso8601(time()));
707 $act->actor = ActivityObject::fromProfile($member);
708 $act->verb = ActivityVerb::LEAVE;
709 $act->object = $oprofile->asActivityObject();
712 $act->title = _m("Leave");
713 // TRANS: Success message for unsubscribe from group attempt through OStatus.
714 // TRANS: %1$s is the member name, %2$s is the unsubscribed group's name.
715 $act->content = sprintf(_m("%1$s has left group %2$s."),
716 $member->getBestName(),
717 $oprofile->getBestName());
719 $oprofile->notifyActivity($act, $member);
724 * Notify remote users when their notices get favorited.
726 * @param Profile or User $profile of local user doing the faving
727 * @param Notice $notice being favored
728 * @return hook return value
731 function onEndFavorNotice(Profile $profile, Notice $notice)
733 $user = User::staticGet('id', $profile->id);
739 $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
741 if (empty($oprofile)) {
745 $act = new Activity();
747 $act->verb = ActivityVerb::FAVORITE;
748 $act->id = TagURI::mint('favor:%d:%d:%s',
751 common_date_iso8601(time()));
754 $act->title = _("Favor");
755 // TRANS: Success message for adding a favorite notice through OStatus.
756 // TRANS: %1$s is the favoring user's name, %2$s is URI to the favored notice.
757 $act->content = sprintf(_("%1$s marked notice %2$s as a favorite."),
758 $profile->getBestName(),
761 $act->actor = ActivityObject::fromProfile($profile);
762 $act->object = ActivityObject::fromNotice($notice);
764 $oprofile->notifyActivity($act, $profile);
770 * Notify remote users when their notices get de-favorited.
772 * @param Profile $profile Profile person doing the de-faving
773 * @param Notice $notice Notice being favored
775 * @return hook return value
778 function onEndDisfavorNotice(Profile $profile, Notice $notice)
780 $user = User::staticGet('id', $profile->id);
786 $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
788 if (empty($oprofile)) {
792 $act = new Activity();
794 $act->verb = ActivityVerb::UNFAVORITE;
795 $act->id = TagURI::mint('disfavor:%d:%d:%s',
798 common_date_iso8601(time()));
800 $act->title = _("Disfavor");
801 // TRANS: Success message for remove a favorite notice through OStatus.
802 // TRANS: %1$s is the unfavoring user's name, %2$s is URI to the no longer favored notice.
803 $act->content = sprintf(_("%1$s marked notice %2$s as no longer a favorite."),
804 $profile->getBestName(),
807 $act->actor = ActivityObject::fromProfile($profile);
808 $act->object = ActivityObject::fromNotice($notice);
810 $oprofile->notifyActivity($act, $profile);
815 function onStartGetProfileUri($profile, &$uri)
817 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
818 if (!empty($oprofile)) {
819 $uri = $oprofile->uri;
825 function onStartUserGroupHomeUrl($group, &$url)
827 return $this->onStartUserGroupPermalink($group, $url);
830 function onStartUserGroupPermalink($group, &$url)
832 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
834 // @fixme this should probably be in the user_group table
835 // @fixme this uri not guaranteed to be a profile page
836 $url = $oprofile->uri;
841 function onStartShowSubscriptionsContent($action)
843 $this->showEntityRemoteSubscribe($action);
848 function onStartShowUserGroupsContent($action)
850 $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
855 function onEndShowSubscriptionsMiniList($action)
857 $this->showEntityRemoteSubscribe($action);
862 function onEndShowGroupsMiniList($action)
864 $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
869 function showEntityRemoteSubscribe($action, $target='ostatussub')
871 $user = common_current_user();
872 if ($user && ($user->id == $action->profile->id)) {
873 $action->elementStart('div', 'entity_actions');
874 $action->elementStart('p', array('id' => 'entity_remote_subscribe',
875 'class' => 'entity_subscribe'));
876 $action->element('a', array('href' => common_local_url($target),
877 'class' => 'entity_remote_subscribe')
878 , _m('Remote')); // @todo: i18n: Add translator hint for this text.
879 $action->elementEnd('p');
880 $action->elementEnd('div');
885 * Ping remote profiles with updates to this profile.
886 * Salmon pings are queued for background processing.
888 function onEndBroadcastProfile(Profile $profile)
890 $user = User::staticGet('id', $profile->id);
892 // Find foreign accounts I'm subscribed to that support Salmon pings.
894 // @fixme we could run updates through the PuSH feed too,
895 // in which case we can skip Salmon pings to folks who
896 // are also subscribed to me.
897 $sql = "SELECT * FROM ostatus_profile " .
898 "WHERE profile_id IN " .
899 "(SELECT subscribed FROM subscription WHERE subscriber=%d) " .
901 "(SELECT group_id FROM group_member WHERE profile_id=%d)";
902 $oprofile = new Ostatus_profile();
903 $oprofile->query(sprintf($sql, $profile->id, $profile->id));
905 if ($oprofile->N == 0) {
906 common_log(LOG_DEBUG, "No OStatus remote subscribees for $profile->nickname");
910 $act = new Activity();
912 $act->verb = ActivityVerb::UPDATE_PROFILE;
913 $act->id = TagURI::mint('update-profile:%d:%s',
915 common_date_iso8601(time()));
917 $act->title = _m("Profile update");
918 // TRANS: Ping text for remote profile update through OStatus.
919 // TRANS: %s is user that updated their profile.
920 $act->content = sprintf(_m("%s has updated their profile page."),
921 $profile->getBestName());
923 $act->actor = ActivityObject::fromProfile($profile);
924 $act->object = $act->actor;
926 while ($oprofile->fetch()) {
927 $oprofile->notifyDeferred($act, $profile);
933 function onStartProfileListItemActionElements($item)
935 if (!common_logged_in()) {
937 $profileUser = User::staticGet('id', $item->profile->id);
939 if (!empty($profileUser)) {
941 $output = $item->out;
943 // Add an OStatus subscribe
944 $output->elementStart('li', 'entity_subscribe');
945 $url = common_local_url('ostatusinit',
946 array('nickname' => $profileUser->nickname));
947 $output->element('a', array('href' => $url,
948 'class' => 'entity_remote_subscribe'),
949 _m('Subscribe')); // @todo: i18n: Add context.
950 $output->elementEnd('li');
957 function onPluginVersion(&$versions)
959 $versions[] = array('name' => 'OStatus',
960 'version' => STATUSNET_VERSION,
961 'author' => 'Evan Prodromou, James Walker, Brion Vibber, Zach Copley',
962 'homepage' => 'http://status.net/wiki/Plugin:OStatus',
964 _m('Follow people across social networks that implement '.
965 '<a href="http://ostatus.org/">OStatus</a>.')); // @todo i18n: Add translator hint.
971 * Utility function to check if the given URL is a canonical group profile
972 * page, and if so return the ID number.
975 * @return mixed int or false
977 public static function localGroupFromUrl($url)
979 $template = common_local_url('groupbyid', array('id' => '31337'));
980 $template = preg_quote($template, '/');
981 $template = str_replace('31337', '(\d+)', $template);
982 if (preg_match("/$template/", $url, $matches)) {
983 return intval($matches[1]);
988 public function onStartProfileGetAtomFeed($profile, &$feed)
990 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
992 if (empty($oprofile)) {
996 $feed = $oprofile->feeduri;
1000 function onStartGetProfileFromURI($uri, &$profile) {
1002 // XXX: do discovery here instead (OStatus_profile::ensureProfileURI($uri))
1004 $oprofile = Ostatus_profile::staticGet('uri', $uri);
1006 if (!empty($oprofile) && !$oprofile->isGroup()) {
1007 $profile = $oprofile->localProfile();
1014 function onStartHostMetaLinks(&$links) {
1015 $url = common_local_url('userxrd');
1016 $url.= '?uri={uri}';
1017 $links[] = array('rel' => Discovery::LRDD_REL,
1019 'title' => array('Resource Descriptor'));