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'),
226 // TRANS: Link description for link to subscribe to a remote user.
229 $output->elementEnd('li');
235 function onStartGroupSubscribe($output, $group)
237 $cur = common_current_user();
240 // Add an OStatus subscribe
241 $url = common_local_url('ostatusinit',
242 array('group' => $group->nickname));
243 $output->element('a', array('href' => $url,
244 'class' => 'entity_remote_subscribe'),
245 // TRANS: Link description for link to join a remote group.
253 * Find any explicit remote mentions. Accepted forms:
254 * Webfinger: @user@example.com
255 * Profile link: @example.com/mublog/user
256 * @param Profile $sender (os user?)
257 * @param string $text input markup text
258 * @param array &$mention in/out param: set of found mentions
259 * @return boolean hook return value
262 function onEndFindMentions($sender, $text, &$mentions)
266 // Webfinger matches: @user@example.com
267 if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\-?\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
270 PREG_OFFSET_CAPTURE)) {
271 foreach ($wmatches[1] as $wmatch) {
272 list($target, $pos) = $wmatch;
273 $this->log(LOG_INFO, "Checking webfinger '$target'");
275 $oprofile = Ostatus_profile::ensureWebfinger($target);
276 if ($oprofile && !$oprofile->isGroup()) {
277 $profile = $oprofile->localProfile();
278 $matches[$pos] = array('mentioned' => array($profile),
281 'url' => $profile->profileurl);
283 } catch (Exception $e) {
284 $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
289 // Profile matches: @example.com/mublog/user
290 if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)!',
293 PREG_OFFSET_CAPTURE)) {
294 foreach ($wmatches[1] as $wmatch) {
295 list($target, $pos) = $wmatch;
296 $schemes = array('http', 'https');
297 foreach ($schemes as $scheme) {
298 $url = "$scheme://$target";
299 $this->log(LOG_INFO, "Checking profile address '$url'");
301 $oprofile = Ostatus_profile::ensureProfileURL($url);
302 if ($oprofile && !$oprofile->isGroup()) {
303 $profile = $oprofile->localProfile();
304 $matches[$pos] = array('mentioned' => array($profile),
307 'url' => $profile->profileurl);
310 } catch (Exception $e) {
311 $this->log(LOG_ERR, "Profile check failed: " . $e->getMessage());
317 foreach ($mentions as $i => $other) {
318 // If we share a common prefix with a local user, override it!
319 $pos = $other['position'];
320 if (isset($matches[$pos])) {
321 $mentions[$i] = $matches[$pos];
322 unset($matches[$pos]);
325 foreach ($matches as $mention) {
326 $mentions[] = $mention;
333 * Allow remote profile references to be used in commands:
334 * sub update@status.net
335 * whois evan@identi.ca
336 * reply http://identi.ca/evan hey what's up
338 * @param Command $command
340 * @param Profile &$profile
341 * @return hook return code
343 function onStartCommandGetProfile($command, $arg, &$profile)
345 $oprofile = $this->pullRemoteProfile($arg);
346 if ($oprofile && !$oprofile->isGroup()) {
347 $profile = $oprofile->localProfile();
355 * Allow remote group references to be used in commands:
356 * join group+statusnet@identi.ca
357 * join http://identi.ca/group/statusnet
358 * drop identi.ca/group/statusnet
360 * @param Command $command
362 * @param User_group &$group
363 * @return hook return code
365 function onStartCommandGetGroup($command, $arg, &$group)
367 $oprofile = $this->pullRemoteProfile($arg);
368 if ($oprofile && $oprofile->isGroup()) {
369 $group = $oprofile->localGroup();
376 protected function pullRemoteProfile($arg)
379 if (preg_match('!^((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)$!', $arg)) {
382 return Ostatus_profile::ensureWebfinger($arg);
383 } catch (Exception $e) {
384 common_log(LOG_ERR, 'Webfinger lookup failed for ' .
385 $arg . ': ' . $e->getMessage());
389 // Look for profile URLs, with or without scheme:
391 if (preg_match('!^https?://((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
394 if (preg_match('!^((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)$!', $arg)) {
395 $schemes = array('http', 'https');
396 foreach ($schemes as $scheme) {
397 $urls[] = "$scheme://$arg";
401 foreach ($urls as $url) {
403 return Ostatus_profile::ensureProfileURL($url);
404 } catch (Exception $e) {
405 common_log(LOG_ERR, 'Profile lookup failed for ' .
406 $arg . ': ' . $e->getMessage());
413 * Make sure necessary tables are filled out.
415 function onCheckSchema() {
416 $schema = Schema::get();
417 $schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef());
418 $schema->ensureTable('ostatus_source', Ostatus_source::schemaDef());
419 $schema->ensureTable('feedsub', FeedSub::schemaDef());
420 $schema->ensureTable('hubsub', HubSub::schemaDef());
421 $schema->ensureTable('magicsig', Magicsig::schemaDef());
425 function onEndShowStatusNetStyles($action) {
426 $action->cssLink('plugins/OStatus/theme/base/css/ostatus.css');
430 function onEndShowStatusNetScripts($action) {
431 $action->script('plugins/OStatus/js/ostatus.js');
436 * Override the "from ostatus" bit in notice lists to link to the
437 * original post and show the domain it came from.
439 * @param Notice in $notice
440 * @param string out &$name
441 * @param string out &$url
442 * @param string out &$title
443 * @return mixed hook return code
445 function onStartNoticeSourceLink($notice, &$name, &$url, &$title)
447 if ($notice->source == 'ostatus') {
449 $bits = parse_url($notice->url);
450 $domain = $bits['host'];
451 if (substr($domain, 0, 4) == 'www.') {
452 $name = substr($domain, 4);
458 // TRANSLATE: %s is a domain.
459 $title = sprintf(_m("Sent from %s via OStatus"), $domain);
467 * Send incoming PuSH feeds for OStatus endpoints in for processing.
469 * @param FeedSub $feedsub
470 * @param DOMDocument $feed
471 * @return mixed hook return code
473 function onStartFeedSubReceive($feedsub, $feed)
475 $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
477 $oprofile->processFeed($feed, 'push');
479 common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
484 * Tell the FeedSub infrastructure whether we have any active OStatus
485 * usage for the feed; if not it'll be able to garbage-collect the
488 * @param FeedSub $feedsub
489 * @param integer $count in/out
490 * @return mixed hook return code
492 function onFeedSubSubscriberCount($feedsub, &$count)
494 $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
496 $count += $oprofile->subscriberCount();
502 * When about to subscribe to a remote user, start a server-to-server
503 * PuSH subscription if needed. If we can't establish that, abort.
505 * @fixme If something else aborts later, we could end up with a stray
506 * PuSH subscription. This is relatively harmless, though.
508 * @param Profile $subscriber
509 * @param Profile $other
511 * @return hook return code
515 function onStartSubscribe($subscriber, $other)
517 $user = User::staticGet('id', $subscriber->id);
523 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
525 if (empty($oprofile)) {
529 if (!$oprofile->subscribe()) {
531 throw new Exception(_m('Could not set up remote subscription.'));
536 * Having established a remote subscription, send a notification to the
537 * remote OStatus profile's endpoint.
539 * @param Profile $subscriber
540 * @param Profile $other
542 * @return hook return code
546 function onEndSubscribe($subscriber, $other)
548 $user = User::staticGet('id', $subscriber->id);
554 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
556 if (empty($oprofile)) {
560 $act = new Activity();
562 $act->verb = ActivityVerb::FOLLOW;
564 $act->id = TagURI::mint('follow:%d:%d:%s',
567 common_date_iso8601(time()));
570 $act->title = _m("Follow");
571 // TRANS: Success message for subscribe to user attempt through OStatus.
572 // TRANS: %1$s is the subscriber name, %2$s is the subscribed user's name.
573 $act->content = sprintf(_m('%1$s is now following %2$s.'),
574 $subscriber->getBestName(),
575 $other->getBestName());
577 $act->actor = ActivityObject::fromProfile($subscriber);
578 $act->object = ActivityObject::fromProfile($other);
580 $oprofile->notifyActivity($act, $subscriber);
586 * Notify remote server and garbage collect unused feeds on unsubscribe.
587 * @fixme send these operations to background queues
590 * @param Profile $other
591 * @return hook return value
593 function onEndUnsubscribe($profile, $other)
595 $user = User::staticGet('id', $profile->id);
601 $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
603 if (empty($oprofile)) {
607 // Drop the PuSH subscription if there are no other subscribers.
608 $oprofile->garbageCollect();
610 $act = new Activity();
612 $act->verb = ActivityVerb::UNFOLLOW;
614 $act->id = TagURI::mint('unfollow:%d:%d:%s',
617 common_date_iso8601(time()));
620 $act->title = _m('Unfollow');
621 // TRANS: Success message for unsubscribe from user attempt through OStatus.
622 // TRANS: %1$s is the unsubscriber's name, %2$s is the unsubscribed user's name.
623 $act->content = sprintf(_m('%1$s stopped following %2$s.'),
624 $profile->getBestName(),
625 $other->getBestName());
627 $act->actor = ActivityObject::fromProfile($profile);
628 $act->object = ActivityObject::fromProfile($other);
630 $oprofile->notifyActivity($act, $profile);
636 * When one of our local users tries to join a remote group,
637 * notify the remote server. If the notification is rejected,
640 * @param User_group $group
643 * @return mixed hook return value
646 function onStartJoinGroup($group, $user)
648 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
650 if (!$oprofile->subscribe()) {
651 throw new Exception(_m('Could not set up remote group membership.'));
654 $member = Profile::staticGet($user->id);
656 $act = new Activity();
657 $act->id = TagURI::mint('join:%d:%d:%s',
660 common_date_iso8601(time()));
662 $act->actor = ActivityObject::fromProfile($member);
663 $act->verb = ActivityVerb::JOIN;
664 $act->object = $oprofile->asActivityObject();
667 $act->title = _m("Join");
668 // TRANS: Success message for subscribe to group attempt through OStatus.
669 // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
670 $act->content = sprintf(_m("%1$s has joined group %2$s."),
671 $member->getBestName(),
672 $oprofile->getBestName());
674 if ($oprofile->notifyActivity($act, $member)) {
677 $oprofile->garbageCollect();
679 throw new Exception(_m("Failed joining remote group."));
685 * When one of our local users leaves a remote group, notify the remote
688 * @fixme Might be good to schedule a resend of the leave notification
689 * if it failed due to a transitory error. We've canceled the local
690 * membership already anyway, but if the remote server comes back up
691 * it'll be left with a stray membership record.
693 * @param User_group $group
696 * @return mixed hook return value
699 function onEndLeaveGroup($group, $user)
701 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
703 // Drop the PuSH subscription if there are no other subscribers.
704 $oprofile->garbageCollect();
706 $member = Profile::staticGet($user->id);
708 $act = new Activity();
709 $act->id = TagURI::mint('leave:%d:%d:%s',
712 common_date_iso8601(time()));
714 $act->actor = ActivityObject::fromProfile($member);
715 $act->verb = ActivityVerb::LEAVE;
716 $act->object = $oprofile->asActivityObject();
719 $act->title = _m("Leave");
720 // TRANS: Success message for unsubscribe from group attempt through OStatus.
721 // TRANS: %1$s is the member name, %2$s is the unsubscribed group's name.
722 $act->content = sprintf(_m("%1$s has left group %2$s."),
723 $member->getBestName(),
724 $oprofile->getBestName());
726 $oprofile->notifyActivity($act, $member);
731 * Notify remote users when their notices get favorited.
733 * @param Profile or User $profile of local user doing the faving
734 * @param Notice $notice being favored
735 * @return hook return value
737 function onEndFavorNotice(Profile $profile, Notice $notice)
739 $user = User::staticGet('id', $profile->id);
745 $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
747 if (empty($oprofile)) {
751 $act = new Activity();
753 $act->verb = ActivityVerb::FAVORITE;
754 $act->id = TagURI::mint('favor:%d:%d:%s',
757 common_date_iso8601(time()));
760 $act->title = _m('Favor');
761 // TRANS: Success message for adding a favorite notice through OStatus.
762 // TRANS: %1$s is the favoring user's name, %2$s is URI to the favored notice.
763 $act->content = sprintf(_m('%1$s marked notice %2$s as a favorite.'),
764 $profile->getBestName(),
767 $act->actor = ActivityObject::fromProfile($profile);
768 $act->object = ActivityObject::fromNotice($notice);
770 $oprofile->notifyActivity($act, $profile);
776 * Notify remote users when their notices get de-favorited.
778 * @param Profile $profile Profile person doing the de-faving
779 * @param Notice $notice Notice being favored
781 * @return hook return value
784 function onEndDisfavorNotice(Profile $profile, Notice $notice)
786 $user = User::staticGet('id', $profile->id);
792 $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
794 if (empty($oprofile)) {
798 $act = new Activity();
800 $act->verb = ActivityVerb::UNFAVORITE;
801 $act->id = TagURI::mint('disfavor:%d:%d:%s',
804 common_date_iso8601(time()));
806 $act->title = _m('Disfavor');
807 // TRANS: Success message for remove a favorite notice through OStatus.
808 // TRANS: %1$s is the unfavoring user's name, %2$s is URI to the no longer favored notice.
809 $act->content = sprintf(_m('%1$s marked notice %2$s as no longer a favorite.'),
810 $profile->getBestName(),
813 $act->actor = ActivityObject::fromProfile($profile);
814 $act->object = ActivityObject::fromNotice($notice);
816 $oprofile->notifyActivity($act, $profile);
821 function onStartGetProfileUri($profile, &$uri)
823 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
824 if (!empty($oprofile)) {
825 $uri = $oprofile->uri;
831 function onStartUserGroupHomeUrl($group, &$url)
833 return $this->onStartUserGroupPermalink($group, $url);
836 function onStartUserGroupPermalink($group, &$url)
838 $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
840 // @fixme this should probably be in the user_group table
841 // @fixme this uri not guaranteed to be a profile page
842 $url = $oprofile->uri;
847 function onStartShowSubscriptionsContent($action)
849 $this->showEntityRemoteSubscribe($action);
854 function onStartShowUserGroupsContent($action)
856 $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
861 function onEndShowSubscriptionsMiniList($action)
863 $this->showEntityRemoteSubscribe($action);
868 function onEndShowGroupsMiniList($action)
870 $this->showEntityRemoteSubscribe($action, 'ostatusgroup');
875 function showEntityRemoteSubscribe($action, $target='ostatussub')
877 $user = common_current_user();
878 if ($user && ($user->id == $action->profile->id)) {
879 $action->elementStart('div', 'entity_actions');
880 $action->elementStart('p', array('id' => 'entity_remote_subscribe',
881 'class' => 'entity_subscribe'));
882 $action->element('a', array('href' => common_local_url($target),
883 'class' => 'entity_remote_subscribe'),
884 // TRANS: Link text for link to remote subscribe.
886 $action->elementEnd('p');
887 $action->elementEnd('div');
892 * Ping remote profiles with updates to this profile.
893 * Salmon pings are queued for background processing.
895 function onEndBroadcastProfile(Profile $profile)
897 $user = User::staticGet('id', $profile->id);
899 // Find foreign accounts I'm subscribed to that support Salmon pings.
901 // @fixme we could run updates through the PuSH feed too,
902 // in which case we can skip Salmon pings to folks who
903 // are also subscribed to me.
904 $sql = "SELECT * FROM ostatus_profile " .
905 "WHERE profile_id IN " .
906 "(SELECT subscribed FROM subscription WHERE subscriber=%d) " .
908 "(SELECT group_id FROM group_member WHERE profile_id=%d)";
909 $oprofile = new Ostatus_profile();
910 $oprofile->query(sprintf($sql, $profile->id, $profile->id));
912 if ($oprofile->N == 0) {
913 common_log(LOG_DEBUG, "No OStatus remote subscribees for $profile->nickname");
917 $act = new Activity();
919 $act->verb = ActivityVerb::UPDATE_PROFILE;
920 $act->id = TagURI::mint('update-profile:%d:%s',
922 common_date_iso8601(time()));
924 // TRANS: Title for activity.
925 $act->title = _m("Profile update");
926 // TRANS: Ping text for remote profile update through OStatus.
927 // TRANS: %s is user that updated their profile.
928 $act->content = sprintf(_m("%s has updated their profile page."),
929 $profile->getBestName());
931 $act->actor = ActivityObject::fromProfile($profile);
932 $act->object = $act->actor;
934 while ($oprofile->fetch()) {
935 $oprofile->notifyDeferred($act, $profile);
941 function onStartProfileListItemActionElements($item)
943 if (!common_logged_in()) {
945 $profileUser = User::staticGet('id', $item->profile->id);
947 if (!empty($profileUser)) {
949 $output = $item->out;
951 // Add an OStatus subscribe
952 $output->elementStart('li', 'entity_subscribe');
953 $url = common_local_url('ostatusinit',
954 array('nickname' => $profileUser->nickname));
955 $output->element('a', array('href' => $url,
956 'class' => 'entity_remote_subscribe'),
957 // TRANS: Link text for a user to subscribe to an OStatus user.
959 $output->elementEnd('li');
966 function onPluginVersion(&$versions)
968 $versions[] = array('name' => 'OStatus',
969 'version' => STATUSNET_VERSION,
970 'author' => 'Evan Prodromou, James Walker, Brion Vibber, Zach Copley',
971 'homepage' => 'http://status.net/wiki/Plugin:OStatus',
972 // TRANS: Plugin description.
973 'rawdescription' => _m('Follow people across social networks that implement '.
974 '<a href="http://ostatus.org/">OStatus</a>.'));
980 * Utility function to check if the given URL is a canonical group profile
981 * page, and if so return the ID number.
984 * @return mixed int or false
986 public static function localGroupFromUrl($url)
988 $template = common_local_url('groupbyid', array('id' => '31337'));
989 $template = preg_quote($template, '/');
990 $template = str_replace('31337', '(\d+)', $template);
991 if (preg_match("/$template/", $url, $matches)) {
992 return intval($matches[1]);
997 public function onStartProfileGetAtomFeed($profile, &$feed)
999 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
1001 if (empty($oprofile)) {
1005 $feed = $oprofile->feeduri;
1009 function onStartGetProfileFromURI($uri, &$profile) {
1011 // XXX: do discovery here instead (OStatus_profile::ensureProfileURI($uri))
1013 $oprofile = Ostatus_profile::staticGet('uri', $uri);
1015 if (!empty($oprofile) && !$oprofile->isGroup()) {
1016 $profile = $oprofile->localProfile();