]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/OStatusPlugin.php
add remote subscribe button for not-logged-in users looking a profile list with local...
[quix0rs-gnu-social.git] / plugins / OStatus / OStatusPlugin.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009-2010, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 /**
21  * @package OStatusPlugin
22  * @maintainer Brion Vibber <brion@status.net>
23  */
24
25 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
26
27 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/');
28
29 class FeedSubException extends Exception
30 {
31 }
32
33 class OStatusPlugin extends Plugin
34 {
35     /**
36      * Hook for RouterInitialized event.
37      *
38      * @param Net_URL_Mapper $m path-to-action mapper
39      * @return boolean hook return
40      */
41     function onRouterInitialized($m)
42     {
43         // Discovery actions
44         $m->connect('.well-known/host-meta',
45                     array('action' => 'hostmeta'));
46         $m->connect('main/xrd',
47                     array('action' => 'xrd'));
48         $m->connect('main/ostatus',
49                     array('action' => 'ostatusinit'));
50         $m->connect('main/ostatus?nickname=:nickname',
51                   array('action' => 'ostatusinit'), array('nickname' => '[A-Za-z0-9_-]+'));
52         $m->connect('main/ostatussub',
53                     array('action' => 'ostatussub'));
54         $m->connect('main/ostatussub',
55                     array('action' => 'ostatussub'), array('feed' => '[A-Za-z0-9\.\/\:]+'));
56
57         // PuSH actions
58         $m->connect('main/push/hub', array('action' => 'pushhub'));
59
60         $m->connect('main/push/callback/:feed',
61                     array('action' => 'pushcallback'),
62                     array('feed' => '[0-9]+'));
63
64         // Salmon endpoint
65         $m->connect('main/salmon/user/:id',
66                     array('action' => 'usersalmon'),
67                     array('id' => '[0-9]+'));
68         $m->connect('main/salmon/group/:id',
69                     array('action' => 'groupsalmon'),
70                     array('id' => '[0-9]+'));
71         return true;
72     }
73
74     /**
75      * Set up queue handlers for outgoing hub pushes
76      * @param QueueManager $qm
77      * @return boolean hook return
78      */
79     function onEndInitializeQueueManager(QueueManager $qm)
80     {
81         // Prepare outgoing distributions after notice save.
82         $qm->connect('ostatus', 'OStatusQueueHandler');
83
84         // Outgoing from our internal PuSH hub
85         $qm->connect('hubconf', 'HubConfQueueHandler');
86         $qm->connect('hubout', 'HubOutQueueHandler');
87
88         // Outgoing Salmon replies (when we don't need a return value)
89         $qm->connect('salmon', 'SalmonQueueHandler');
90
91         // Incoming from a foreign PuSH hub
92         $qm->connect('pushin', 'PushInQueueHandler');
93         return true;
94     }
95
96     /**
97      * Put saved notices into the queue for pubsub distribution.
98      */
99     function onStartEnqueueNotice($notice, &$transports)
100     {
101         $transports[] = 'ostatus';
102         return true;
103     }
104
105     /**
106      * Add a link header for LRDD Discovery
107      */
108     function onStartShowHTML($action)
109     {
110         if ($action instanceof ShowstreamAction) {
111             $acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
112             $url = common_local_url('xrd');
113             $url.= '?uri='. $acct;
114
115             header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="application/xrd+xml"');
116         }
117     }
118
119     /**
120      * Set up a PuSH hub link to our internal link for canonical timeline
121      * Atom feeds for users and groups.
122      */
123     function onStartApiAtom($feed)
124     {
125         $id = null;
126
127         if ($feed instanceof AtomUserNoticeFeed) {
128             $salmonAction = 'usersalmon';
129             $user = $feed->getUser();
130             $id   = $user->id;
131             $profile = $user->getProfile();
132             $feed->setActivitySubject($profile->asActivityNoun('subject'));
133         } else if ($feed instanceof AtomGroupNoticeFeed) {
134             $salmonAction = 'groupsalmon';
135             $group = $feed->getGroup();
136             $id = $group->id;
137             $feed->setActivitySubject($group->asActivitySubject());
138         } else {
139             return true;
140         }
141
142         if (!empty($id)) {
143             $hub = common_config('ostatus', 'hub');
144             if (empty($hub)) {
145                 // Updates will be handled through our internal PuSH hub.
146                 $hub = common_local_url('pushhub');
147             }
148             $feed->addLink($hub, array('rel' => 'hub'));
149
150             // Also, we'll add in the salmon link
151             $salmon = common_local_url($salmonAction, array('id' => $id));
152             $feed->addLink($salmon, array('rel' => Salmon::NS_REPLIES));
153             $feed->addLink($salmon, array('rel' => Salmon::NS_MENTIONS));
154         }
155
156         return true;
157     }
158
159     /**
160      * Automatically load the actions and libraries used by the plugin
161      *
162      * @param Class $cls the class
163      *
164      * @return boolean hook return
165      *
166      */
167     function onAutoload($cls)
168     {
169         $base = dirname(__FILE__);
170         $lower = strtolower($cls);
171         $map = array('activityverb' => 'activity',
172                      'activityobject' => 'activity',
173                      'activityutils' => 'activity');
174         if (isset($map[$lower])) {
175             $lower = $map[$lower];
176         }
177         $files = array("$base/classes/$cls.php",
178                        "$base/lib/$lower.php");
179         if (substr($lower, -6) == 'action') {
180             $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
181         }
182         foreach ($files as $file) {
183             if (file_exists($file)) {
184                 include_once $file;
185                 return false;
186             }
187         }
188         return true;
189     }
190
191     /**
192      * Add in an OStatus subscribe button
193      */
194     function onStartProfileRemoteSubscribe($output, $profile)
195     {
196         $cur = common_current_user();
197
198         if (empty($cur)) {
199             // Add an OStatus subscribe
200             $output->elementStart('li', 'entity_subscribe');
201             $url = common_local_url('ostatusinit',
202                                     array('nickname' => $profile->nickname));
203             $output->element('a', array('href' => $url,
204                                         'class' => 'entity_remote_subscribe'),
205                                 _m('Subscribe'));
206
207             $output->elementEnd('li');
208         }
209
210         return false;
211     }
212
213     function onStartGroupSubscribe($output, $group)
214     {
215         $cur = common_current_user();
216
217         if (empty($cur)) {
218             // Add an OStatus subscribe
219             $output->elementStart('li', 'entity_subscribe');
220             $url = common_local_url('ostatusinit',
221                                     array('nickname' => $group->nickname));
222             $output->element('a', array('href' => $url,
223                                         'class' => 'entity_remote_subscribe'),
224                                 _m('Join'));
225
226             $output->elementEnd('li');
227         }
228
229         return false;
230     }
231
232     /**
233      * Check if we've got remote replies to send via Salmon.
234      *
235      * @fixme push webfinger lookup & sending to a background queue
236      * @fixme also detect short-form name for remote subscribees where not ambiguous
237      */
238
239     function onEndNoticeSave($notice)
240     {
241     }
242
243     /**
244      * Find any explicit remote mentions. Accepted forms:
245      *   Webfinger: @user@example.com
246      *   Profile link: @example.com/mublog/user
247      * @param Profile $sender (os user?)
248      * @param string $text input markup text
249      * @param array &$mention in/out param: set of found mentions
250      * @return boolean hook return value
251      */
252
253     function onEndFindMentions($sender, $text, &$mentions)
254     {
255         $matches = array();
256
257         // Webfinger matches: @user@example.com
258         if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+@(?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+)!',
259                        $text,
260                        $wmatches,
261                        PREG_OFFSET_CAPTURE)) {
262             foreach ($wmatches[1] as $wmatch) {
263                 list($target, $pos) = $wmatch;
264                 $this->log(LOG_INFO, "Checking webfinger '$target'");
265                 try {
266                     $oprofile = Ostatus_profile::ensureWebfinger($target);
267                     if ($oprofile && !$oprofile->isGroup()) {
268                         $profile = $oprofile->localProfile();
269                         $matches[$pos] = array('mentioned' => array($profile),
270                                                'text' => $target,
271                                                'position' => $pos,
272                                                'url' => $profile->profileurl);
273                     }
274                 } catch (Exception $e) {
275                     $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
276                 }
277             }
278         }
279
280         // Profile matches: @example.com/mublog/user
281         if (preg_match_all('!(?:^|\s+)@((?:\w+\.)*\w+(?:\w+\-\w+)*\.\w+(?:/\w+)+)!',
282                        $text,
283                        $wmatches,
284                        PREG_OFFSET_CAPTURE)) {
285             foreach ($wmatches[1] as $wmatch) {
286                 list($target, $pos) = $wmatch;
287                 $schemes = array('http', 'https');
288                 foreach ($schemes as $scheme) {
289                     $url = "$scheme://$target";
290                     $this->log(LOG_INFO, "Checking profile address '$url'");
291                     try {
292                         $oprofile = Ostatus_profile::ensureProfile($url);
293                         if ($oprofile && !$oprofile->isGroup()) {
294                             $profile = $oprofile->localProfile();
295                             $matches[$pos] = array('mentioned' => array($profile),
296                                                    'text' => $target,
297                                                    'position' => $pos,
298                                                    'url' => $profile->profileurl);
299                             break;
300                         }
301                     } catch (Exception $e) {
302                         $this->log(LOG_ERR, "Profile check failed: " . $e->getMessage());
303                     }
304                 }
305             }
306         }
307
308         foreach ($mentions as $i => $other) {
309             // If we share a common prefix with a local user, override it!
310             $pos = $other['position'];
311             if (isset($matches[$pos])) {
312                 $mentions[$i] = $matches[$pos];
313                 unset($matches[$pos]);
314             }
315         }
316         foreach ($matches as $mention) {
317             $mentions[] = $mention;
318         }
319
320         return true;
321     }
322
323     /**
324      * Make sure necessary tables are filled out.
325      */
326     function onCheckSchema() {
327         $schema = Schema::get();
328         $schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef());
329         $schema->ensureTable('ostatus_source', Ostatus_source::schemaDef());
330         $schema->ensureTable('feedsub', FeedSub::schemaDef());
331         $schema->ensureTable('hubsub', HubSub::schemaDef());
332         $schema->ensureTable('magicsig', Magicsig::schemaDef());
333         return true;
334     }
335
336     function onEndShowStatusNetStyles($action) {
337         $action->cssLink(common_path('plugins/OStatus/theme/base/css/ostatus.css'));
338         return true;
339     }
340
341     function onEndShowStatusNetScripts($action) {
342         $action->script(common_path('plugins/OStatus/js/ostatus.js'));
343         return true;
344     }
345
346     /**
347      * Override the "from ostatus" bit in notice lists to link to the
348      * original post and show the domain it came from.
349      *
350      * @param Notice in $notice
351      * @param string out &$name
352      * @param string out &$url
353      * @param string out &$title
354      * @return mixed hook return code
355      */
356     function onStartNoticeSourceLink($notice, &$name, &$url, &$title)
357     {
358         if ($notice->source == 'ostatus') {
359             if ($notice->url) {
360                 $bits = parse_url($notice->url);
361                 $domain = $bits['host'];
362                 if (substr($domain, 0, 4) == 'www.') {
363                     $name = substr($domain, 4);
364                 } else {
365                     $name = $domain;
366                 }
367
368                 $url = $notice->url;
369                 $title = sprintf(_m("Sent from %s via OStatus"), $domain);
370                 return false;
371             }
372         }
373     }
374
375     /**
376      * Send incoming PuSH feeds for OStatus endpoints in for processing.
377      *
378      * @param FeedSub $feedsub
379      * @param DOMDocument $feed
380      * @return mixed hook return code
381      */
382     function onStartFeedSubReceive($feedsub, $feed)
383     {
384         $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
385         if ($oprofile) {
386             $oprofile->processFeed($feed, 'push');
387         } else {
388             common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
389         }
390     }
391
392     /**
393      * When about to subscribe to a remote user, start a server-to-server
394      * PuSH subscription if needed. If we can't establish that, abort.
395      *
396      * @fixme If something else aborts later, we could end up with a stray
397      *        PuSH subscription. This is relatively harmless, though.
398      *
399      * @param Profile $subscriber
400      * @param Profile $other
401      *
402      * @return hook return code
403      *
404      * @throws Exception
405      */
406     function onStartSubscribe($subscriber, $other)
407     {
408         $user = User::staticGet('id', $subscriber->id);
409
410         if (empty($user)) {
411             return true;
412         }
413
414         $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
415
416         if (empty($oprofile)) {
417             return true;
418         }
419
420         if (!$oprofile->subscribe()) {
421             throw new Exception(_m('Could not set up remote subscription.'));
422         }
423     }
424
425     /**
426      * Having established a remote subscription, send a notification to the
427      * remote OStatus profile's endpoint.
428      *
429      * @param Profile $subscriber
430      * @param Profile $other
431      *
432      * @return hook return code
433      *
434      * @throws Exception
435      */
436     function onEndSubscribe($subscriber, $other)
437     {
438         $user = User::staticGet('id', $subscriber->id);
439
440         if (empty($user)) {
441             return true;
442         }
443
444         $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
445
446         if (empty($oprofile)) {
447             return true;
448         }
449
450         $act = new Activity();
451
452         $act->verb = ActivityVerb::FOLLOW;
453
454         $act->id   = TagURI::mint('follow:%d:%d:%s',
455                                   $subscriber->id,
456                                   $other->id,
457                                   common_date_iso8601(time()));
458
459         $act->time    = time();
460         $act->title   = _("Follow");
461         $act->content = sprintf(_("%s is now following %s."),
462                                $subscriber->getBestName(),
463                                $other->getBestName());
464
465         $act->actor   = ActivityObject::fromProfile($subscriber);
466         $act->object  = ActivityObject::fromProfile($other);
467
468         $oprofile->notifyActivity($act, $subscriber);
469
470         return true;
471     }
472
473     /**
474      * Notify remote server and garbage collect unused feeds on unsubscribe.
475      * @fixme send these operations to background queues
476      *
477      * @param User $user
478      * @param Profile $other
479      * @return hook return value
480      */
481     function onEndUnsubscribe($profile, $other)
482     {
483         $user = User::staticGet('id', $profile->id);
484
485         if (empty($user)) {
486             return true;
487         }
488
489         $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
490
491         if (empty($oprofile)) {
492             return true;
493         }
494
495         // Drop the PuSH subscription if there are no other subscribers.
496         $oprofile->garbageCollect();
497
498         $act = new Activity();
499
500         $act->verb = ActivityVerb::UNFOLLOW;
501
502         $act->id   = TagURI::mint('unfollow:%d:%d:%s',
503                                   $profile->id,
504                                   $other->id,
505                                   common_date_iso8601(time()));
506
507         $act->time    = time();
508         $act->title   = _("Unfollow");
509         $act->content = sprintf(_("%s stopped following %s."),
510                                $profile->getBestName(),
511                                $other->getBestName());
512
513         $act->actor   = ActivityObject::fromProfile($profile);
514         $act->object  = ActivityObject::fromProfile($other);
515
516         $oprofile->notifyActivity($act, $profile);
517
518         return true;
519     }
520
521     /**
522      * When one of our local users tries to join a remote group,
523      * notify the remote server. If the notification is rejected,
524      * deny the join.
525      *
526      * @param User_group $group
527      * @param User $user
528      *
529      * @return mixed hook return value
530      */
531
532     function onStartJoinGroup($group, $user)
533     {
534         $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
535         if ($oprofile) {
536             if (!$oprofile->subscribe()) {
537                 throw new Exception(_m('Could not set up remote group membership.'));
538             }
539
540             $member = Profile::staticGet($user->id);
541
542             $act = new Activity();
543             $act->id = TagURI::mint('join:%d:%d:%s',
544                                     $member->id,
545                                     $group->id,
546                                     common_date_iso8601(time()));
547
548             $act->actor = ActivityObject::fromProfile($member);
549             $act->verb = ActivityVerb::JOIN;
550             $act->object = $oprofile->asActivityObject();
551
552             $act->time = time();
553             $act->title = _m("Join");
554             $act->content = sprintf(_m("%s has joined group %s."),
555                                     $member->getBestName(),
556                                     $oprofile->getBestName());
557
558             if ($oprofile->notifyActivity($act, $member)) {
559                 return true;
560             } else {
561                 $oprofile->garbageCollect();
562                 throw new Exception(_m("Failed joining remote group."));
563             }
564         }
565     }
566
567     /**
568      * When one of our local users leaves a remote group, notify the remote
569      * server.
570      *
571      * @fixme Might be good to schedule a resend of the leave notification
572      * if it failed due to a transitory error. We've canceled the local
573      * membership already anyway, but if the remote server comes back up
574      * it'll be left with a stray membership record.
575      *
576      * @param User_group $group
577      * @param User $user
578      *
579      * @return mixed hook return value
580      */
581
582     function onEndLeaveGroup($group, $user)
583     {
584         $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
585         if ($oprofile) {
586             // Drop the PuSH subscription if there are no other subscribers.
587             $oprofile->garbageCollect();
588
589             $member = Profile::staticGet($user->id);
590
591             $act = new Activity();
592             $act->id = TagURI::mint('leave:%d:%d:%s',
593                                     $member->id,
594                                     $group->id,
595                                     common_date_iso8601(time()));
596
597             $act->actor = ActivityObject::fromProfile($member);
598             $act->verb = ActivityVerb::LEAVE;
599             $act->object = $oprofile->asActivityObject();
600
601             $act->time = time();
602             $act->title = _m("Leave");
603             $act->content = sprintf(_m("%s has left group %s."),
604                                     $member->getBestName(),
605                                     $oprofile->getBestName());
606
607             $oprofile->notifyActivity($act, $member);
608         }
609     }
610
611     /**
612      * Notify remote users when their notices get favorited.
613      *
614      * @param Profile or User $profile of local user doing the faving
615      * @param Notice $notice being favored
616      * @return hook return value
617      */
618
619     function onEndFavorNotice(Profile $profile, Notice $notice)
620     {
621         $user = User::staticGet('id', $profile->id);
622
623         if (empty($user)) {
624             return true;
625         }
626
627         $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
628
629         if (empty($oprofile)) {
630             return true;
631         }
632
633         $act = new Activity();
634
635         $act->verb = ActivityVerb::FAVORITE;
636         $act->id   = TagURI::mint('favor:%d:%d:%s',
637                                   $profile->id,
638                                   $notice->id,
639                                   common_date_iso8601(time()));
640
641         $act->time    = time();
642         $act->title   = _("Favor");
643         $act->content = sprintf(_("%s marked notice %s as a favorite."),
644                                $profile->getBestName(),
645                                $notice->uri);
646
647         $act->actor   = ActivityObject::fromProfile($profile);
648         $act->object  = ActivityObject::fromNotice($notice);
649
650         $oprofile->notifyActivity($act, $profile);
651
652         return true;
653     }
654
655     /**
656      * Notify remote users when their notices get de-favorited.
657      *
658      * @param Profile $profile Profile person doing the de-faving
659      * @param Notice  $notice  Notice being favored
660      *
661      * @return hook return value
662      */
663
664     function onEndDisfavorNotice(Profile $profile, Notice $notice)
665     {
666         $user = User::staticGet('id', $profile->id);
667
668         if (empty($user)) {
669             return true;
670         }
671
672         $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
673
674         if (empty($oprofile)) {
675             return true;
676         }
677
678         $act = new Activity();
679
680         $act->verb = ActivityVerb::UNFAVORITE;
681         $act->id   = TagURI::mint('disfavor:%d:%d:%s',
682                                   $profile->id,
683                                   $notice->id,
684                                   common_date_iso8601(time()));
685         $act->time    = time();
686         $act->title   = _("Disfavor");
687         $act->content = sprintf(_("%s marked notice %s as no longer a favorite."),
688                                $profile->getBestName(),
689                                $notice->uri);
690
691         $act->actor   = ActivityObject::fromProfile($profile);
692         $act->object  = ActivityObject::fromNotice($notice);
693
694         $oprofile->notifyActivity($act, $profile);
695
696         return true;
697     }
698
699     function onStartGetProfileUri($profile, &$uri)
700     {
701         $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
702         if (!empty($oprofile)) {
703             $uri = $oprofile->uri;
704             return false;
705         }
706         return true;
707     }
708
709     function onStartUserGroupHomeUrl($group, &$url)
710     {
711         return $this->onStartUserGroupPermalink($group, $url);
712     }
713
714     function onStartUserGroupPermalink($group, &$url)
715     {
716         $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
717         if ($oprofile) {
718             // @fixme this should probably be in the user_group table
719             // @fixme this uri not guaranteed to be a profile page
720             $url = $oprofile->uri;
721             return false;
722         }
723     }
724
725     function onStartShowSubscriptionsContent($action)
726     {
727         $this->showEntityRemoteSubscribe($action);
728
729         return true;
730     }
731
732     function onEndShowSubscriptionsMiniList($action)
733     {
734         $this->showEntityRemoteSubscribe($action);
735
736         return true;
737     }
738
739     function onEndShowGroupsMiniList($action)
740     {
741         $this->showEntityRemoteSubscribe($action);
742
743         return true;
744     }
745
746     function showEntityRemoteSubscribe($action)
747     {
748         $user = common_current_user();
749         if ($user && ($user->id == $action->profile->id)) {
750             $action->elementStart('div', 'entity_actions');
751             $action->elementStart('p', array('id' => 'entity_remote_subscribe',
752                                              'class' => 'entity_subscribe'));
753             $action->element('a', array('href' => common_local_url('ostatussub'),
754                                         'class' => 'entity_remote_subscribe')
755                                 , _m('Remote'));
756             $action->elementEnd('p');
757             $action->elementEnd('div');
758         }
759     }
760
761     /**
762      * Ping remote profiles with updates to this profile.
763      * Salmon pings are queued for background processing.
764      */
765     function onEndBroadcastProfile(Profile $profile)
766     {
767         $user = User::staticGet('id', $profile->id);
768
769         // Find foreign accounts I'm subscribed to that support Salmon pings.
770         //
771         // @fixme we could run updates through the PuSH feed too,
772         // in which case we can skip Salmon pings to folks who
773         // are also subscribed to me.
774         $sql = "SELECT * FROM ostatus_profile " .
775                "WHERE profile_id IN " .
776                "(SELECT subscribed FROM subscription WHERE subscriber=%d) " .
777                "OR group_id IN " .
778                "(SELECT group_id FROM group_member WHERE profile_id=%d)";
779         $oprofile = new Ostatus_profile();
780         $oprofile->query(sprintf($sql, $profile->id, $profile->id));
781
782         if ($oprofile->N == 0) {
783             common_log(LOG_DEBUG, "No OStatus remote subscribees for $profile->nickname");
784             return true;
785         }
786
787         $act = new Activity();
788
789         $act->verb = ActivityVerb::UPDATE_PROFILE;
790         $act->id   = TagURI::mint('update-profile:%d:%s',
791                                   $profile->id,
792                                   common_date_iso8601(time()));
793         $act->time    = time();
794         $act->title   = _m("Profile update");
795         $act->content = sprintf(_m("%s has updated their profile page."),
796                                $profile->getBestName());
797
798         $act->actor   = ActivityObject::fromProfile($profile);
799         $act->object  = $act->actor;
800
801         while ($oprofile->fetch()) {
802             $oprofile->notifyDeferred($act, $profile);
803         }
804
805         return true;
806     }
807
808     function onStartProfileListItemActionElements($item)
809     {
810         if (!common_logged_in()) {
811
812             $profileUser = User::staticGet('id', $item->profile->id);
813
814             if (!empty($profileUser)) {
815
816                 $output = $item->out;
817
818                 // Add an OStatus subscribe
819                 $output->elementStart('li', 'entity_subscribe');
820                 $url = common_local_url('ostatusinit',
821                                         array('nickname' => $profileUser->nickname));
822                 $output->element('a', array('href' => $url,
823                                             'class' => 'entity_remote_subscribe'),
824                                  _m('Subscribe'));
825                 $output->elementEnd('li');
826             }
827         }
828
829         return true;
830     }
831 }