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('.well-known/host-meta',
54 array('action' => 'hostmeta'));
55 $m->connect('main/xrd',
56 array('action' => 'userxrd'));
57 $m->connect('main/ownerxrd',
58 array('action' => 'ownerxrd'));
59 $m->connect('main/ostatus',
60 array('action' => 'ostatusinit'));
61 $m->connect('main/ostatus?nickname=:nickname',
62 array('action' => 'ostatusinit'), array('nickname' => '[A-Za-z0-9_-]+'));
63 $m->connect('main/ostatus?group=:group',
64 array('action' => 'ostatusinit'), array('group' => '[A-Za-z0-9_-]+'));
65 $m->connect('main/ostatussub',
66 array('action' => 'ostatussub'));
67 $m->connect('main/ostatusgroup',
68 array('action' => 'ostatusgroup'));
71 $m->connect('main/push/hub', array('action' => 'pushhub'));
73 $m->connect('main/push/callback/:feed',
74 array('action' => 'pushcallback'),
75 array('feed' => '[0-9]+'));
78 $m->connect('main/salmon/user/:id',
79 array('action' => 'usersalmon'),
80 array('id' => '[0-9]+'));
81 $m->connect('main/salmon/group/:id',
82 array('action' => 'groupsalmon'),
83 array('id' => '[0-9]+'));
88 * Set up queue handlers for outgoing hub pushes
89 * @param QueueManager $qm
90 * @return boolean hook return
92 function onEndInitializeQueueManager(QueueManager $qm)
94 // Prepare outgoing distributions after notice save.
95 $qm->connect('ostatus', 'OStatusQueueHandler');
97 // Outgoing from our internal PuSH hub
98 $qm->connect('hubconf', 'HubConfQueueHandler');
99 $qm->connect('hubprep', 'HubPrepQueueHandler');
101 $qm->connect('hubout', 'HubOutQueueHandler');
103 // Outgoing Salmon replies (when we don't need a return value)
104 $qm->connect('salmon', 'SalmonQueueHandler');
106 // Incoming from a foreign PuSH hub
107 $qm->connect('pushin', 'PushInQueueHandler');
112 * Put saved notices into the queue for pubsub distribution.
114 function onStartEnqueueNotice($notice, &$transports)
116 if ($notice->isLocal()) {
117 // put our transport first, in case there's any conflict (like OMB)
118 array_unshift($transports, 'ostatus');
124 * Add a link header for LRDD Discovery
126 function onStartShowHTML($action)
128 if ($action instanceof ShowstreamAction) {
129 $acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
130 $url = common_local_url('userxrd');
131 $url.= '?uri='. $acct;
133 header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="application/xrd+xml"');
138 * Set up a PuSH hub link to our internal link for canonical timeline
139 * Atom feeds for users and groups.
141 function onStartApiAtom($feed)
145 if ($feed instanceof AtomUserNoticeFeed) {
146 $salmonAction = 'usersalmon';
147 $user = $feed->getUser();
149 $profile = $user->getProfile();
150 $feed->setActivitySubject($profile->asActivityNoun('subject'));
151 } else if ($feed instanceof AtomGroupNoticeFeed) {
152 $salmonAction = 'groupsalmon';
153 $group = $feed->getGroup();
155 $feed->setActivitySubject($group->asActivitySubject());
161 $hub = common_config('ostatus', 'hub');
163 // Updates will be handled through our internal PuSH hub.
164 $hub = common_local_url('pushhub');
166 $feed->addLink($hub, array('rel' => 'hub'));
168 // Also, we'll add in the salmon link
169 $salmon = common_local_url($salmonAction, array('id' => $id));
170 $feed->addLink($salmon, array('rel' => Salmon::REL_SALMON));
172 // XXX: these are deprecated
173 $feed->addLink($salmon, array('rel' => Salmon::NS_REPLIES));
174 $feed->addLink($salmon, array('rel' => Salmon::NS_MENTIONS));
181 * Automatically load the actions and libraries used by the plugin
183 * @param Class $cls the class
185 * @return boolean hook return
188 function onAutoload($cls)
190 $base = dirname(__FILE__);
191 $lower = strtolower($cls);
192 $map = array('activityverb' => 'activity',
193 'activityobject' => 'activity',
194 'activityutils' => 'activity');
195 if (isset($map[$lower])) {
196 $lower = $map[$lower];
198 $files = array("$base/classes/$cls.php",
199 "$base/lib/$lower.php");
200 if (substr($lower, -6) == 'action') {
201 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
203 foreach ($files as $file) {
204 if (file_exists($file)) {
213 * Add in an OStatus subscribe button
215 function onStartProfileRemoteSubscribe($output, $profile)
217 $cur = common_current_user();
220 // Add an OStatus subscribe
221 $output->elementStart('li', 'entity_subscribe');
222 $url = common_local_url('ostatusinit',
223 array('nickname' => $profile->nickname));
224 $output->element('a', array('href' => $url,
225 'class' => 'entity_remote_subscribe'),
228 $output->elementEnd('li');
234 function onStartGroupSubscribe($output, $group)
236 $cur = common_current_user();
239 // Add an OStatus subscribe
240 $url = common_local_url('ostatusinit',
241 array('group' => $group->nickname));
242 $output->element('a', array('href' => $url,
243 'class' => 'entity_remote_subscribe'),
251 * Find any explicit remote mentions. Accepted forms:
252 * Webfinger: @user@example.com
253 * Profile link: @example.com/mublog/user
254 * @param Profile $sender (os user?)
255 * @param string $text input markup text
256 * @param array &$mention in/out param: set of found mentions
257 * @return boolean hook return value
260 function onEndFindMentions($sender, $text, &$mentions)
264 // Webfinger matches: @user@example.com
265 if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\-?\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
268 PREG_OFFSET_CAPTURE)) {
269 foreach ($wmatches[1] as $wmatch) {
270 list($target, $pos) = $wmatch;
271 $this->log(LOG_INFO, "Checking webfinger '$target'");
273 $oprofile = Ostatus_profile::ensureWebfinger($target);
274 if ($oprofile && !$oprofile->isGroup()) {
275 $profile = $oprofile->localProfile();
276 $matches[$pos] = array('mentioned' => array($profile),
279 'url' => $profile->profileurl);
281 } catch (Exception $e) {
282 $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
287 // Profile matches: @example.com/mublog/user
288 if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)!',
291 PREG_OFFSET_CAPTURE)) {
292 foreach ($wmatches[1] as $wmatch) {
293 list($target, $pos) = $wmatch;
294 $schemes = array('http', 'https');
295 foreach ($schemes as $scheme) {
296 $url = "$scheme://$target";
297 $this->log(LOG_INFO, "Checking profile address '$url'");
299 $oprofile = Ostatus_profile::ensureProfileURL($url);
300 if ($oprofile && !$oprofile->isGroup()) {
301 $profile = $oprofile->localProfile();
302 $matches[$pos] = array('mentioned' => array($profile),
305 'url' => $profile->profileurl);
308 } catch (Exception $e) {
309 $this->log(LOG_ERR, "Profile check failed: " . $e->getMessage());
315 foreach ($mentions as $i => $other) {
316 // If we share a common prefix with a local user, override it!
317 $pos = $other['position'];
318 if (isset($matches[$pos])) {
319 $mentions[$i] = $matches[$pos];
320 unset($matches[$pos]);
323 foreach ($matches as $mention) {
324 $mentions[] = $mention;
331 * Allow remote profile references to be used in commands:
332 * sub update@status.net
333 * whois evan@identi.ca
334 * reply http://identi.ca/evan hey what's up
336 * @param Command $command
338 * @param Profile &$profile
339 * @return hook return code
341 function onStartCommandGetProfile($command, $arg, &$profile)
343 $oprofile = $this->pullRemoteProfile($arg);
344 if ($oprofile && !$oprofile->isGroup()) {
345 $profile = $oprofile->localProfile();
353 * Allow remote group references to be used in commands:
354 * join group+statusnet@identi.ca
355 * join http://identi.ca/group/statusnet
356 * drop identi.ca/group/statusnet
358 * @param Command $command
360 * @param User_group &$group
361 * @return hook return code
363 function onStartCommandGetGroup($command, $arg, &$group)
365 $oprofile = $this->pullRemoteProfile($arg);
366 if ($oprofile && $oprofile->isGroup()) {
367 $group = $oprofile->localGroup();
374 protected function pullRemoteProfile($arg)
377 if (preg_match('!^((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)$!', $arg)) {
380 return Ostatus_profile::ensureWebfinger($arg);
381 } catch (Exception $e) {
382 common_log(LOG_ERR, 'Webfinger lookup failed for ' .
383 $arg . ': ' . $e->getMessage());
387 // Look for profile URLs, with or without scheme:
389 if (preg_match('!^https?://((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
392 if (preg_match('!^((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
393 $schemes = array('http', 'https');
394 foreach ($schemes as $scheme) {
395 $urls[] = "$scheme://$arg";
399 foreach ($urls as $url) {
401 return Ostatus_profile::ensureProfileURL($url);
402 } catch (Exception $e) {
403 common_log(LOG_ERR, 'Profile lookup failed for ' .
404 $arg . ': ' . $e->getMessage());
411 * Make sure necessary tables are filled out.
413 function onCheckSchema() {
414 $schema = Schema::get();
415 $schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef());
416 $schema->ensureTable('ostatus_source', Ostatus_source::schemaDef());
417 $schema->ensureTable('feedsub', FeedSub::schemaDef());
418 $schema->ensureTable('hubsub', HubSub::schemaDef());
419 $schema->ensureTable('magicsig', Magicsig::schemaDef());
423 function onEndShowStatusNetStyles($action) {
424 $action->cssLink('plugins/OStatus/theme/base/css/ostatus.css');
428 function onEndShowStatusNetScripts($action) {
429 $action->script('plugins/OStatus/js/ostatus.js');
434 * Override the "from ostatus" bit in notice lists to link to the
435 * original post and show the domain it came from.
437 * @param Notice in $notice
438 * @param string out &$name
439 * @param string out &$url
440 * @param string out &$title
441 * @return mixed hook return code
443 function onStartNoticeSourceLink($notice, &$name, &$url, &$title)
445 if ($notice->source == 'ostatus') {
447 $bits = parse_url($notice->url);
448 $domain = $bits['host'];
449 if (substr($domain, 0, 4) == 'www.') {
450 $name = substr($domain, 4);
456 $title = sprintf(_m("Sent from %s via OStatus"), $domain);
464 * Send incoming PuSH feeds for OStatus endpoints in for processing.
466 * @param FeedSub $feedsub
467 * @param DOMDocument $feed
468 * @return mixed hook return code
470 function onStartFeedSubReceive($feedsub, $feed)
472 $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
474 $oprofile->processFeed($feed, 'push');
476 common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
481 * Tell the FeedSub infrastructure whether we have any active OStatus
482 * usage for the feed; if not it'll be able to garbage-collect the
485 * @param FeedSub $feedsub
486 * @param integer $count in/out
487 * @return mixed hook return code
489 function onFeedSubSubscriberCount($feedsub, &$count)
491 $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
493 $count += $oprofile->subscriberCount();
499 * When about to subscribe to a remote user, start a server-to-server
500 * PuSH subscription if needed. If we can't establish that, abort.
502 * @fixme If something else aborts later, we could end up with a stray
503 * PuSH subscription. This is relatively harmless, though.
505 * @param Profile $subscriber
506 * @param Profile $other
508 * @return hook return code
512 function onStartSubscribe($subscriber, $other)
514 $user = User::staticGet('id', $subscriber->id);
520 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
522 if (empty($oprofile)) {
526 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 $act = new Activity();
558 $act->verb = ActivityVerb::FOLLOW;
560 $act->id = TagURI::mint('follow:%d:%d:%s',
563 common_date_iso8601(time()));
566 $act->title = _("Follow");
567 // TRANS: Success message for subscribe to user attempt through OStatus.
568 // TRANS: %1$s is the subscriber name, %2$s is the subscribed user's name.
569 $act->content = sprintf(_("%1$s is now following %2$s."),
570 $subscriber->getBestName(),
571 $other->getBestName());
573 $act->actor = ActivityObject::fromProfile($subscriber);
574 $act->object = ActivityObject::fromProfile($other);
576 $oprofile->notifyActivity($act, $subscriber);
582 * Notify remote server and garbage collect unused feeds on unsubscribe.
583 * @fixme send these operations to background queues
586 * @param Profile $other
587 * @return hook return value
589 function onEndUnsubscribe($profile, $other)
591 $user = User::staticGet('id', $profile->id);
597 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
599 if (empty($oprofile)) {
603 // Drop the PuSH subscription if there are no other subscribers.
604 $oprofile->garbageCollect();
606 $act = new Activity();
608 $act->verb = ActivityVerb::UNFOLLOW;
610 $act->id = TagURI::mint('unfollow:%d:%d:%s',
613 common_date_iso8601(time()));
616 $act->title = _("Unfollow");
617 // TRANS: Success message for unsubscribe from user attempt through OStatus.
618 // TRANS: %1$s is the unsubscriber's name, %2$s is the unsubscribed user's name.
619 $act->content = sprintf(_("%1$s stopped following %2$s."),
620 $profile->getBestName(),
621 $other->getBestName());
623 $act->actor = ActivityObject::fromProfile($profile);
624 $act->object = ActivityObject::fromProfile($other);
626 $oprofile->notifyActivity($act, $profile);
632 * When one of our local users tries to join a remote group,
633 * notify the remote server. If the notification is rejected,
636 * @param User_group $group
639 * @return mixed hook return value
642 function onStartJoinGroup($group, $user)
644 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
646 if (!$oprofile->subscribe()) {
647 throw new Exception(_m('Could not set up remote group membership.'));
650 $member = Profile::staticGet($user->id);
652 $act = new Activity();
653 $act->id = TagURI::mint('join:%d:%d:%s',
656 common_date_iso8601(time()));
658 $act->actor = ActivityObject::fromProfile($member);
659 $act->verb = ActivityVerb::JOIN;
660 $act->object = $oprofile->asActivityObject();
663 $act->title = _m("Join");
664 // TRANS: Success message for subscribe to group attempt through OStatus.
665 // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
666 $act->content = sprintf(_m("%1$s has joined group %2$s."),
667 $member->getBestName(),
668 $oprofile->getBestName());
670 if ($oprofile->notifyActivity($act, $member)) {
673 $oprofile->garbageCollect();
674 throw new Exception(_m("Failed joining remote group."));
680 * When one of our local users leaves a remote group, notify the remote
683 * @fixme Might be good to schedule a resend of the leave notification
684 * if it failed due to a transitory error. We've canceled the local
685 * membership already anyway, but if the remote server comes back up
686 * it'll be left with a stray membership record.
688 * @param User_group $group
691 * @return mixed hook return value
694 function onEndLeaveGroup($group, $user)
696 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
698 // Drop the PuSH subscription if there are no other subscribers.
699 $oprofile->garbageCollect();
701 $member = Profile::staticGet($user->id);
703 $act = new Activity();
704 $act->id = TagURI::mint('leave:%d:%d:%s',
707 common_date_iso8601(time()));
709 $act->actor = ActivityObject::fromProfile($member);
710 $act->verb = ActivityVerb::LEAVE;
711 $act->object = $oprofile->asActivityObject();
714 $act->title = _m("Leave");
715 // TRANS: Success message for unsubscribe from group attempt through OStatus.
716 // TRANS: %1$s is the member name, %2$s is the unsubscribed group's name.
717 $act->content = sprintf(_m("%1$s has left group %2$s."),
718 $member->getBestName(),
719 $oprofile->getBestName());
721 $oprofile->notifyActivity($act, $member);
726 * Notify remote users when their notices get favorited.
728 * @param Profile or User $profile of local user doing the faving
729 * @param Notice $notice being favored
730 * @return hook return value
733 function onEndFavorNotice(Profile $profile, Notice $notice)
735 $user = User::staticGet('id', $profile->id);
741 $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
743 if (empty($oprofile)) {
747 $act = new Activity();
749 $act->verb = ActivityVerb::FAVORITE;
750 $act->id = TagURI::mint('favor:%d:%d:%s',
753 common_date_iso8601(time()));
756 $act->title = _("Favor");
757 // TRANS: Success message for adding a favorite notice through OStatus.
758 // TRANS: %1$s is the favoring user's name, %2$s is URI to the favored notice.
759 $act->content = sprintf(_("%1$s marked notice %2$s as a favorite."),
760 $profile->getBestName(),
763 $act->actor = ActivityObject::fromProfile($profile);
764 $act->object = ActivityObject::fromNotice($notice);
766 $oprofile->notifyActivity($act, $profile);
772 * Notify remote users when their notices get de-favorited.
774 * @param Profile $profile Profile person doing the de-faving
775 * @param Notice $notice Notice being favored
777 * @return hook return value
780 function onEndDisfavorNotice(Profile $profile, Notice $notice)
782 $user = User::staticGet('id', $profile->id);
788 $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
790 if (empty($oprofile)) {
794 $act = new Activity();
796 $act->verb = ActivityVerb::UNFAVORITE;
797 $act->id = TagURI::mint('disfavor:%d:%d:%s',
800 common_date_iso8601(time()));
802 $act->title = _("Disfavor");
803 // TRANS: Success message for remove a favorite notice through OStatus.
804 // TRANS: %1$s is the unfavoring user's name, %2$s is URI to the no longer favored notice.
805 $act->content = sprintf(_("%1$s marked notice %2$s as no longer a favorite."),
806 $profile->getBestName(),
809 $act->actor = ActivityObject::fromProfile($profile);
810 $act->object = ActivityObject::fromNotice($notice);
812 $oprofile->notifyActivity($act, $profile);
817 function onStartGetProfileUri($profile, &$uri)
819 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
820 if (!empty($oprofile)) {
821 $uri = $oprofile->uri;
827 function onStartUserGroupHomeUrl($group, &$url)
829 return $this->onStartUserGroupPermalink($group, $url);
832 function onStartUserGroupPermalink($group, &$url)
834 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
836 // @fixme this should probably be in the user_group table
837 // @fixme this uri not guaranteed to be a profile page
838 $url = $oprofile->uri;
843 function onStartShowSubscriptionsContent($action)
845 $this->showEntityRemoteSubscribe($action);
850 function onStartShowUserGroupsContent($action)
852 $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
857 function onEndShowSubscriptionsMiniList($action)
859 $this->showEntityRemoteSubscribe($action);
864 function onEndShowGroupsMiniList($action)
866 $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
871 function showEntityRemoteSubscribe($action, $target='ostatussub')
873 $user = common_current_user();
874 if ($user && ($user->id == $action->profile->id)) {
875 $action->elementStart('div', 'entity_actions');
876 $action->elementStart('p', array('id' => 'entity_remote_subscribe',
877 'class' => 'entity_subscribe'));
878 $action->element('a', array('href' => common_local_url($target),
879 'class' => 'entity_remote_subscribe')
880 , _m('Remote')); // @todo: i18n: Add translator hint for this text.
881 $action->elementEnd('p');
882 $action->elementEnd('div');
887 * Ping remote profiles with updates to this profile.
888 * Salmon pings are queued for background processing.
890 function onEndBroadcastProfile(Profile $profile)
892 $user = User::staticGet('id', $profile->id);
894 // Find foreign accounts I'm subscribed to that support Salmon pings.
896 // @fixme we could run updates through the PuSH feed too,
897 // in which case we can skip Salmon pings to folks who
898 // are also subscribed to me.
899 $sql = "SELECT * FROM ostatus_profile " .
900 "WHERE profile_id IN " .
901 "(SELECT subscribed FROM subscription WHERE subscriber=%d) " .
903 "(SELECT group_id FROM group_member WHERE profile_id=%d)";
904 $oprofile = new Ostatus_profile();
905 $oprofile->query(sprintf($sql, $profile->id, $profile->id));
907 if ($oprofile->N == 0) {
908 common_log(LOG_DEBUG, "No OStatus remote subscribees for $profile->nickname");
912 $act = new Activity();
914 $act->verb = ActivityVerb::UPDATE_PROFILE;
915 $act->id = TagURI::mint('update-profile:%d:%s',
917 common_date_iso8601(time()));
919 $act->title = _m("Profile update");
920 // TRANS: Ping text for remote profile update through OStatus.
921 // TRANS: %s is user that updated their profile.
922 $act->content = sprintf(_m("%s has updated their profile page."),
923 $profile->getBestName());
925 $act->actor = ActivityObject::fromProfile($profile);
926 $act->object = $act->actor;
928 while ($oprofile->fetch()) {
929 $oprofile->notifyDeferred($act, $profile);
935 function onStartProfileListItemActionElements($item)
937 if (!common_logged_in()) {
939 $profileUser = User::staticGet('id', $item->profile->id);
941 if (!empty($profileUser)) {
943 $output = $item->out;
945 // Add an OStatus subscribe
946 $output->elementStart('li', 'entity_subscribe');
947 $url = common_local_url('ostatusinit',
948 array('nickname' => $profileUser->nickname));
949 $output->element('a', array('href' => $url,
950 'class' => 'entity_remote_subscribe'),
951 _m('Subscribe')); // @todo: i18n: Add context.
952 $output->elementEnd('li');
959 function onPluginVersion(&$versions)
961 $versions[] = array('name' => 'OStatus',
962 'version' => STATUSNET_VERSION,
963 'author' => 'Evan Prodromou, James Walker, Brion Vibber, Zach Copley',
964 'homepage' => 'http://status.net/wiki/Plugin:OStatus',
966 _m('Follow people across social networks that implement '.
967 '<a href="http://ostatus.org/">OStatus</a>.')); // @todo i18n: Add translator hint.
973 * Utility function to check if the given URL is a canonical group profile
974 * page, and if so return the ID number.
977 * @return mixed int or false
979 public static function localGroupFromUrl($url)
981 $template = common_local_url('groupbyid', array('id' => '31337'));
982 $template = preg_quote($template, '/');
983 $template = str_replace('31337', '(\d+)', $template);
984 if (preg_match("/$template/", $url, $matches)) {
985 return intval($matches[1]);
990 public function onStartProfileGetAtomFeed($profile, &$feed)
992 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
994 if (empty($oprofile)) {
998 $feed = $oprofile->feeduri;
1002 function onStartGetProfileFromURI($uri, &$profile) {
1004 // XXX: do discovery here instead (OStatus_profile::ensureProfileURI($uri))
1006 $oprofile = Ostatus_profile::staticGet('uri', $uri);
1008 if (!empty($oprofile) && !$oprofile->isGroup()) {
1009 $profile = $oprofile->localProfile();